LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

Lights

Description
Specialization providing various types of lights (regular, work, brake, reverse, beacon, turn) to vehicles
Functions

actionEventToggleBeaconLights

Description
Definition
actionEventToggleBeaconLights()
Code
1497function Lights.actionEventToggleBeaconLights(self, actionName, inputValue, callbackState, isAnalog)
1498 local spec = self.spec_lights
1499 if self:getCanToggleLight() then
1500 self:setBeaconLightsVisibility(not spec.beaconLightsActive)
1501 end
1502end

actionEventToggleHighBeamLight

Description
Definition
actionEventToggleHighBeamLight()
Code
1448function Lights.actionEventToggleHighBeamLight(self, actionName, inputValue, callbackState, isAnalog)
1449 local spec = self.spec_lights
1450 if self:getCanToggleLight() then
1451 local lightsTypesMask = bitXOR(spec.lightsTypesMask, 2^3)
1452 self:setLightsTypesMask(lightsTypesMask)
1453 end
1454end

actionEventToggleLightFront

Description
Definition
actionEventToggleLightFront()
Code
1408function Lights.actionEventToggleLightFront(self, actionName, inputValue, callbackState, isAnalog)
1409 local spec = self.spec_lights
1410 if self:getCanToggleLight() then
1411 if spec.numLightTypes >= 1 then
1412 local lightsTypesMask = bitXOR(spec.lightsTypesMask, 2^0)
1413 self:setLightsTypesMask(lightsTypesMask)
1414 end
1415 end
1416end

actionEventToggleLights

Description
Definition
actionEventToggleLights()
Code
1420function Lights.actionEventToggleLights(self, actionName, inputValue, callbackState, isAnalog)
1421 if self:getCanToggleLight() then
1422 self:setNextLightsState(self)
1423 end
1424end

actionEventToggleTurnLightHazard

Description
Definition
actionEventToggleTurnLightHazard()
Code
1458function Lights.actionEventToggleTurnLightHazard(self, actionName, inputValue, callbackState, isAnalog)
1459 local spec = self.spec_lights
1460 if self:getCanToggleLight() then
1461 local state = Lights.TURNLIGHT_OFF
1462 if spec.turnLightState ~= Lights.TURNLIGHT_HAZARD then
1463 state = Lights.TURNLIGHT_HAZARD
1464 end
1465 self:setTurnLightState(state)
1466 end
1467end

actionEventToggleTurnLightLeft

Description
Definition
actionEventToggleTurnLightLeft()
Code
1471function Lights.actionEventToggleTurnLightLeft(self, actionName, inputValue, callbackState, isAnalog)
1472 local spec = self.spec_lights
1473 if self:getCanToggleLight() then
1474 local state = Lights.TURNLIGHT_OFF
1475 if spec.turnLightState ~= Lights.TURNLIGHT_LEFT then
1476 state = Lights.TURNLIGHT_LEFT
1477 end
1478 self:setTurnLightState(state)
1479 end
1480end

actionEventToggleTurnLightRight

Description
Definition
actionEventToggleTurnLightRight()
Code
1484function Lights.actionEventToggleTurnLightRight(self, actionName, inputValue, callbackState, isAnalog)
1485 local spec = self.spec_lights
1486 if self:getCanToggleLight() then
1487 local state = Lights.TURNLIGHT_OFF
1488 if spec.turnLightState ~= Lights.TURNLIGHT_RIGHT then
1489 state = Lights.TURNLIGHT_RIGHT
1490 end
1491 self:setTurnLightState(state)
1492 end
1493end

actionEventToggleWorkLightBack

Description
Definition
actionEventToggleWorkLightBack()
Code
1428function Lights.actionEventToggleWorkLightBack(self, actionName, inputValue, callbackState, isAnalog)
1429 local spec = self.spec_lights
1430 if self:getCanToggleLight() then
1431 local lightsTypesMask = bitXOR(spec.lightsTypesMask, 2^1)
1432 self:setLightsTypesMask(lightsTypesMask)
1433 end
1434end

actionEventToggleWorkLightFront

Description
Definition
actionEventToggleWorkLightFront()
Code
1438function Lights.actionEventToggleWorkLightFront(self, actionName, inputValue, callbackState, isAnalog)
1439 local spec = self.spec_lights
1440 if self:getCanToggleLight() then
1441 local lightsTypesMask = bitXOR(spec.lightsTypesMask, 2^2)
1442 self:setLightsTypesMask(lightsTypesMask)
1443 end
1444end

dashboardLightAttributes

Description
Definition
dashboardLightAttributes()
Code
1506function Lights.dashboardLightAttributes(self, xmlFile, key, dashboard, isActive)
1507 dashboard.lightTypes = {StringUtil.getVectorFromString(getXMLString(xmlFile, key .. "#lightTypes"))}
1508 dashboard.excludedLightTypes = {StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#excludedLightTypes"))}
1509
1510 return true
1511end

dashboardLightState

Description
Definition
dashboardLightState()
Code
1515function Lights.dashboardLightState(self, dashboard, newValue, minValue, maxValue, isActive)
1516 local lightsTypesMask = self.spec_lights.lightsTypesMask
1517
1518 local lightIsActive = false
1519 if dashboard.lightTypes ~= nil then
1520 for _, lightType in pairs(dashboard.lightTypes) do
1521 if bitAND(lightsTypesMask, 2^lightType) ~= 0 then
1522 lightIsActive = true
1523 break
1524 end
1525 end
1526 end
1527
1528 if lightIsActive then
1529 for _, excludedLightType in pairs(dashboard.excludedLightTypes) do
1530 if bitAND(lightsTypesMask, 2^excludedLightType) ~= 0 then
1531 lightIsActive = false
1532 break
1533 end
1534 end
1535 end
1536
1537 Dashboard.defaultDashboardStateFunc(self, dashboard, lightIsActive, minValue, maxValue, isActive)
1538end

deactivateLights

Description
Definition
deactivateLights()
Code
976function Lights:deactivateLights()
977 self:setLightsTypesMask(0, true, true)
978 self:setBeaconLightsVisibility(false, true, true)
979 self:setTurnLightState(Lights.TURNLIGHT_OFF, true, true)
980 self:setBrakeLightsVisibility(false)
981 self:setReverseLightsVisibility(false)
982 self:setInteriorLightsVisibility(false)
983
984 local spec = self.spec_lights
985 spec.currentLightState = 0
986
987 SpecializationUtil.raiseEvent(self, "onDeactivateLights")
988end

getBeaconLightsVisibility

Description
Get beacon light state
Definition
getBeaconLightsVisibility()
Return Values
booleanstatebeacon light state
Code
695function Lights:getBeaconLightsVisibility()
696 return self.spec_lights.beaconLightsActive
697end

getCanToggleLight

Description
Returns if lights can be toggled
Definition
getCanToggleLight()
Return Values
booleancanBeToggledlights can be toggled
Code
485function Lights:getCanToggleLight()
486 local spec = self.spec_lights
487
488 if self:getIsAIActive() then
489 return false
490 end
491
492 if spec.numLightTypes == 0 then
493 return false
494 end
495
496 if g_currentMission.controlledVehicle == self then
497 return true
498 else
499 return false
500 end
501end

getDeactivateLightsOnLeave

Description
Definition
getDeactivateLightsOnLeave()
Code
992function Lights:getDeactivateLightsOnLeave()
993 return true
994end

getIsActiveForInteriorLights

Description
Returns if is active for interior lights
Definition
getIsActiveForInteriorLights()
Return Values
booleanisActiveis active for interior lights
Code
478function Lights:getIsActiveForInteriorLights()
479 return false
480end

getIsActiveForLights

Description
Returns if is active for lights
Definition
getIsActiveForLights()
Return Values
booleanisActiveis active for lights
Code
465function Lights:getIsActiveForLights()
466 if self.getIsEntered ~= nil and self:getIsEntered() and self:getCanToggleLight() then
467 return true
468 end
469 if self.attacherVehicle ~= nil and (self.isSteerable == nil or self.isSteerable == false) then
470 return self.attacherVehicle:getIsActiveForLights()
471 end
472 return false
473end

getLightsTypesMask

Description
Get light type mask
Definition
getLightsTypesMask()
Return Values
integerlightsTypesMasklight types mask
Code
644function Lights:getLightsTypesMask()
645 return self.spec_lights.lightsTypesMask
646end

getTurnLightState

Description
Get turn light state
Definition
getTurnLightState()
Return Values
integerstateturn light state
Code
785function Lights:getTurnLightState()
786 return self.spec_lights.turnLightState
787end

getUseHighProfile

Description
Returns if high profile is used
Definition
getUseHighProfile()
Return Values
booleanhighProfileUsedhigh profile is used
Code
506function Lights:getUseHighProfile()
507 local lightsProfile = g_gameSettings:getValue("lightsProfile")
508
509 return lightsProfile == GS_PROFILE_VERY_HIGH or (lightsProfile == GS_PROFILE_HIGH and self:getIsActiveForLights())
510end

loadRealLights

Description
Definition
loadRealLights()
Code
1306function Lights:loadRealLights(xmlFile, key, targetTable, brakeLightTable)
1307 local i = 0
1308 while true do
1309 local lightKey = string.format("%s(%d)", key, i)
1310 if not hasXMLProperty(xmlFile, lightKey) then
1311 break
1312 end
1313
1314 local index = getXMLString(xmlFile, lightKey .. "#node")
1315 local node = I3DUtil.indexToObject(self.components, index, self.i3dMappings)
1316 if node ~= nil then
1317 if getHasClassId(node, ClassIds.LIGHT_SOURCE) then
1318 local defaultColor = nil
1319 if node ~= nil then
1320 setVisibility(node, false)
1321 defaultColor = {getLightColor(node)}
1322 end
1323
1324 local light = {node=node, defaultColor=defaultColor, isActive=false}
1325 if brakeLightTable ~= nil and brakeLightTable[light.node] ~= nil then
1326 light.backLight = brakeLightTable[light.node]
1327 brakeLightTable[light.node].brakeLight = light
1328 end
1329
1330 table.insert(targetTable, light)
1331 else
1332 print("Warning: '"..getName(node).."' ("..index..") is not a real lightSource in '"..self.configFileName.."'!")
1333 end
1334 else
1335 print("Warning: RealLight node missing for light '" ..lightKey.."' in '"..self.configFileName.."'")
1336 end
1337
1338 i = i + 1
1339 end
1340end

loadRealLightSetup

Description
Definition
loadRealLightSetup()
Code
1263function Lights:loadRealLightSetup(xmlFile, key, lightTable, realLightToLight)
1264 local i = 0
1265 while true do
1266 local lightKey = string.format("%s.light(%d)", key, i)
1267 if not hasXMLProperty(xmlFile, lightKey) then
1268 break
1269 end
1270
1271 local node = I3DUtil.indexToObject(self.components, getXMLString(xmlFile, lightKey .. "#node"), self.i3dMappings)
1272 if node ~= nil then
1273 if getHasClassId(node, ClassIds.LIGHT_SOURCE) then
1274 setVisibility(node, false)
1275
1276 local light = {}
1277 light.node = node
1278 light.defaultColor = {getLightColor(node)}
1279 light.enableDirection = getXMLInt(xmlFile, lightKey .. "#enableDirection")
1280 light.excludedLightTypes = {StringUtil.getVectorFromString(getXMLString(xmlFile, lightKey.."#excludedLightTypes"))}
1281 light.lightTypes = {StringUtil.getVectorFromString(getXMLString(xmlFile, lightKey .. "#lightTypes"))}
1282
1283 if #light.lightTypes >= 0 then
1284 realLightToLight[node] = light
1285 table.insert(lightTable.lightTypes, light)
1286 else
1287 print("Warning: lightType missing for light '" ..lightKey.."' in '"..self.configFileName.."'")
1288 end
1289 end
1290 else
1291 print("Warning: RealLight node missing for light '" ..lightKey.."' in '"..self.configFileName.."'")
1292 end
1293
1294 i = i + 1
1295 end
1296
1297 self:loadRealLights(xmlFile, key..".brakeLight", lightTable.brakeLights, realLightToLight)
1298 self:loadRealLights(xmlFile, key..".reverseLight", lightTable.reverseLights)
1299 self:loadRealLights(xmlFile, key..".turnLightLeft", lightTable.turnLightsLeft)
1300 self:loadRealLights(xmlFile, key..".turnLightRight", lightTable.turnLightsRight)
1301 self:loadRealLights(xmlFile, key..".interiorLight", lightTable.interiorLights)
1302end

loadSharedLight

Description
Definition
loadSharedLight()
Code
998function Lights:loadSharedLight(xmlFile, key, sharedLight)
999 local success = false
1000 local spec = self.spec_lights
1001 local xmlFilename = getXMLString(xmlFile, key .. "#filename")
1002
1003 if xmlFilename ~= nil then
1004 xmlFilename = Utils.getFilename(xmlFilename, self.baseDirectory)
1005 local lightXmlFile = loadXMLFile("sharedLight", xmlFilename)
1006
1007 if lightXmlFile ~= nil and lightXmlFile ~= 0 then
1008 local filename = getXMLString(lightXmlFile, "light.filename")
1009 if filename == nil then
1010 print("Warning: Missing light i3d filename 'light.filename' in '"..tostring(xmlFilename).."'!")
1011 return
1012 end
1013
1014 sharedLight.linkNode = I3DUtil.indexToObject(self.components, Utils.getNoNil(getXMLString(xmlFile, key .. "#linkNode"), "0>"), self.i3dMappings)
1015 if sharedLight.linkNode == nil then
1016 print("Warning: Missing light linkNode in '"..tostring(xmlFilename).."'!")
1017 return
1018 end
1019 sharedLight.lightTypes = {StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#lightTypes"))}
1020 sharedLight.excludedLightTypes = {StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#excludedLightTypes"))}
1021 sharedLight.enableDirection = getXMLInt(xmlFile, key .. "#enableDirection")
1022
1023 local rotations = {}
1024 local i = 0
1025 while true do
1026 local rotKey = string.format("%s.rotationNode(%d)", key, i)
1027 if not hasXMLProperty(xmlFile, rotKey) then
1028 break
1029 end
1030 local name = getXMLString(xmlFile, rotKey.."#name")
1031 local rotation = StringUtil.getRadiansFromString(getXMLString(xmlFile, rotKey.."#rotation"), 3)
1032 if name ~= nil then
1033 rotations[name] = rotation
1034 end
1035 i = i + 1
1036 end
1037
1038 local i3dNode = g_i3DManager:loadSharedI3DFile(filename, self.baseDirectory, false, false, false)
1039 if i3dNode ~= 0 then
1040 sharedLight.filename = filename
1041 sharedLight.node = I3DUtil.indexToObject(i3dNode, Utils.getNoNil(getXMLString(lightXmlFile, "light.rootNode#node"), "0"))
1042
1043 local i = 0
1044 while true do
1045 local lightKey = string.format("light.defaultLight(%d)", i)
1046 if not hasXMLProperty(lightXmlFile, lightKey) then
1047 break
1048 end
1049
1050 local types = sharedLight.lightTypes
1051 if #types == 0 then
1052 types = {StringUtil.getVectorFromString(Utils.getNoNil(getXMLString(lightXmlFile, lightKey.."#lightTypes"), "0"))}
1053 end
1054 local light = {}
1055 light.node = I3DUtil.indexToObject(i3dNode, getXMLString(lightXmlFile, lightKey.."#node"))
1056 if light.node ~= nil then
1057 if getHasShaderParameter(light.node, "lightControl") then
1058 light.intensity = getXMLFloat(lightXmlFile, lightKey.."#intensity") or 25
1059 light.lightTypes = types
1060 light.excludedLightTypes = sharedLight.excludedLightTypes
1061 light.enableDirection = sharedLight.enableDirection
1062
1063 if #light.lightTypes >= 0 then
1064 table.insert(spec.shaderDefaultLights, light)
1065 end
1066 else
1067 print("Warning: Node '"..getName(light.node).."' has no shaderparameter 'lightControl' in '"..xmlFilename.."'. Ignoring node!")
1068 end
1069 else
1070 print("Warning: Could not find node for '"..lightKey.."' in '"..xmlFilename.."'!")
1071 end
1072
1073 i = i + 1
1074 end
1075
1076 local function addLights(xml, key, targetTable)
1077 local i = 0
1078 while true do
1079 local lightKey = string.format("light.%s(%d)", key, i)
1080 if not hasXMLProperty(xml, lightKey) then
1081 break
1082 end
1083
1084 local node = I3DUtil.indexToObject(i3dNode, getXMLString(xml, lightKey.."#node"))
1085 if node ~= nil then
1086 if getHasShaderParameter(node, "lightControl") then
1087 local intensity = getXMLFloat(xml, lightKey.."#intensity") or 25
1088 local toggleVisibility = Utils.getNoNil(getXMLBool(xml, lightKey.."#toggleVisibility"), false)
1089 if toggleVisibility then
1090 setVisibility(node, false)
1091 end
1092
1093 table.insert(targetTable, {node=node, intensity=intensity, toggleVisibility=toggleVisibility})
1094 else
1095 print("Warning: Node '"..getName(node).."' has no shaderparameter 'lightControl'. Ignoring node!")
1096 end
1097 else
1098 print("Warning: Could not find node for '"..key.."' in '"..xmlFilename.."'!")
1099 end
1100
1101 i = i + 1
1102 end
1103 end
1104
1105 for name, rotation in pairs(rotations) do
1106 local node = I3DUtil.indexToObject(i3dNode, getXMLString(lightXmlFile, string.format("light.%s#node", name)))
1107 if node ~= nil then
1108 setRotation(node, unpack(rotation))
1109 end
1110 end
1111
1112 addLights(lightXmlFile, "brakeLight", spec.shaderBrakeLights)
1113 addLights(lightXmlFile, "reverseLight", spec.shaderReverseLights)
1114 addLights(lightXmlFile, "turnLightLeft", spec.shaderLeftTurnLights)
1115 addLights(lightXmlFile, "turnLightRight", spec.shaderRightTurnLights)
1116
1117 link(sharedLight.linkNode, sharedLight.node)
1118 delete(i3dNode)
1119
1120 success = true
1121 end
1122
1123 delete(lightXmlFile)
1124
1125 end
1126 end
1127
1128 return success
1129end

loadVisualLights

Description
Definition
loadVisualLights()
Code
1344function Lights:loadVisualLights(xmlFile, key, isDefaultLight, targetTable, shaderTargetTable)
1345 local i = 0
1346 while true do
1347 local lightKey = string.format("%s(%d)", key, i)
1348 if not hasXMLProperty(xmlFile, lightKey) then
1349 break
1350 end
1351
1352 local node = I3DUtil.indexToObject(self.components, getXMLString(xmlFile, lightKey .. "#node"), self.i3dMappings)
1353 local shaderNode = I3DUtil.indexToObject(self.components, getXMLString(xmlFile, lightKey .. "#shaderNode"), self.i3dMappings)
1354 local intensity = Utils.getNoNil(getXMLFloat(xmlFile, lightKey .. "#intensity"), 25)
1355
1356 if node ~= nil or shaderNode ~= nil then
1357 if node ~= nil then
1358 setVisibility(node, false)
1359 end
1360
1361 if shaderNode ~= nil then
1362 for i=0, getNumOfChildren(shaderNode)-1 do
1363 local node = getChildAt(shaderNode, i)
1364 local _,y,z,w = getShaderParameter(node, "lightControl")
1365 setShaderParameter(node, "lightControl", 0, y, z, w, false)
1366 end
1367 end
1368
1369 local light = {node=node, shaderNode=shaderNode, intensity=intensity}
1370
1371 light.toggleVisibility = Utils.getNoNil(getXMLBool(xmlFile, lightKey .. "#toggleVisibility"), false)
1372 if light.toggleVisibility then
1373 setVisibility(shaderNode, false)
1374 end
1375
1376 if isDefaultLight then
1377 light.enableDirection = getXMLInt(xmlFile, lightKey .. "#enableDirection")
1378 light.excludedLightTypes = {StringUtil.getVectorFromString(getXMLString(xmlFile, lightKey.."#excludedLightTypes"))}
1379 light.lightTypes = {StringUtil.getVectorFromString(getXMLString(xmlFile, lightKey .. "#lightTypes"))}
1380 end
1381
1382 if light.shaderNode ~= nil then
1383 local function addLight(node, light)
1384 if getHasShaderParameter(node, "lightControl") then
1385 local shaderLight = {node=node, enableDirection=light.enableDirection, excludedLightTypes=light.excludedLightTypes, lightTypes=light.lightTypes, intensity=light.intensity, toggleVisibility=light.toggleVisibility}
1386 table.insert(shaderTargetTable, shaderLight)
1387 end
1388 end
1389
1390 addLight(light.shaderNode, light)
1391
1392 for i=0, getNumOfChildren(light.shaderNode)-1 do
1393 local node = getChildAt(light.shaderNode, i)
1394 addLight(node, light)
1395 end
1396 end
1397
1398 if light.node ~= nil then
1399 table.insert(targetTable, light)
1400 end
1401 end
1402 i = i + 1
1403 end
1404end

onAIActive

Description
Definition
onAIActive()
Code
1235function Lights:onAIActive()
1236 self:updateAILights()
1237end

onAIBlock

Description
Definition
onAIBlock()
Code
1241function Lights:onAIBlock()
1242 self:setBeaconLightsVisibility(true, true, true)
1243end

onAIContinue

Description
Definition
onAIContinue()
Code
1247function Lights:onAIContinue()
1248 self:setBeaconLightsVisibility(false, true, true)
1249end

onAIEnd

Description
Definition
onAIEnd()
Code
1253function Lights:onAIEnd()
1254 if self.getIsControlled ~= nil then
1255 if not self:getIsControlled() then
1256 self:setLightsTypesMask(0)
1257 end
1258 end
1259end

onAutomatedTrainTravelActive

Description
Definition
onAutomatedTrainTravelActive()
Code
1229function Lights:onAutomatedTrainTravelActive()
1230 self:updateAILights()
1231end

onDelete

Description
Called on deleting
Definition
onDelete()
Code
315function Lights:onDelete()
316 local spec = self.spec_lights
317 for _, beaconLight in pairs(spec.beaconLights) do
318 if beaconLight.filename ~= nil then
319 g_i3DManager:releaseSharedI3DFile(beaconLight.filename, self.baseDirectory, true)
320 end
321 end
322 for _, sharedLight in pairs(spec.sharedLights) do
323 g_i3DManager:releaseSharedI3DFile(sharedLight.filename, self.baseDirectory, true)
324 end
325 if self.isClient ~= nil then
326 for _,sample in pairs(spec.samples) do
327 g_soundManager:deleteSample(sample)
328 end
329 end
330end

onEnterVehicle

Description
Definition
onEnterVehicle()
Code
1185function Lights:onEnterVehicle(isControlling)
1186 local spec = self.spec_lights
1187
1188 self:setLightsTypesMask(spec.lightsTypesMask, true, true)
1189 self:setBeaconLightsVisibility(spec.beaconLightsActive, true, true)
1190 self:setTurnLightState(spec.turnLightState, true, true)
1191end

onLeaveVehicle

Description
Definition
onLeaveVehicle()
Code
1195function Lights:onLeaveVehicle()
1196 if self:getDeactivateLightsOnLeave() then
1197 self:deactivateLights()
1198 end
1199end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
95function Lights:onLoad(savegame)
96
97 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.lights.low.light#decoration", "vehicle.lights.defaultLights#node") --FS17 to FS19
98 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.lights.high.light#decoration", "vehicle.lights.defaultLights#node") --FS17 to FS19
99 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.lights.low.light#realLight", "vehicle.lights.realLights.low.light#node") --FS17 to FS19
100 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.lights.high.light#realLight", "vehicle.lights.realLights.high.light#node") --FS17 to FS19
101 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.brakeLights.brakeLight#realLight", "vehicle.lights.realLights.high.brakeLight#node") --FS17 to FS19
102 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.brakeLights.brakeLight#decoration", "vehicle.lights.brakeLights.brakeLight#node") --FS17 to FS19
103 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.reverseLights.reverseLight#realLight", "vehicle.lights.realLights.high.reverseLight#node") --FS17 to FS19
104 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.reverseLights.reverseLight#decoration", "vehicle.lights.reverseLights.reverseLight#node") --FS17 to FS19
105 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnLights.turnLightLeft#realLight", "vehicle.lights.realLights.high.turnLightLeft#node") --FS17 to FS19
106 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnLights.turnLightLeft#decoration", "vehicle.lights.turnLights.turnLightLeft#node") --FS17 to FS19
107 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnLights.turnLightRight#realLight", "vehicle.lights.realLights.high.turnLightRight#node") --FS17 to FS19
108 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnLights.turnLightRight#decoration", "vehicle.lights.turnLights.turnLightRight#node") --FS17 to FS19
109 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.reverseLights.reverseLight#realLight", "vehicle.lights.realLights.high.reverseLight#node") --FS17 to FS19
110 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.reverseLights.reverseLight#decoration", "vehicle.lights.reverseLights.reverseLight#node") --FS17 to FS19
111
112 local spec = self.spec_lights
113
114 spec.shaderDefaultLights = {}
115 spec.shaderBrakeLights = {}
116 spec.shaderLeftTurnLights = {}
117 spec.shaderRightTurnLights = {}
118 spec.shaderReverseLights = {}
119
120 spec.realLights = {}
121 spec.realLights.low = {lightTypes={}, turnLightsLeft={}, turnLightsRight={}, brakeLights={}, reverseLights={}, interiorLights={}}
122 spec.realLights.high = {lightTypes={}, turnLightsLeft={}, turnLightsRight={}, brakeLights={}, reverseLights={}, interiorLights={}}
123
124 spec.defaultLights = {}
125 spec.brakeLights = {}
126 spec.reverseLights = {}
127 spec.turnLightsLeft = {}
128 spec.turnLightsRight = {}
129
130 spec.lightsTypesMask = 0
131 spec.currentLightState = 0
132 spec.numLightTypes = 0
133 spec.lightStates = {}
134
135 local registeredLightTypes = {}
136 local i = 0
137 while true do
138 local key = string.format("vehicle.lights.states.state(%d)", i)
139 if not hasXMLProperty(self.xmlFile, key) then
140 break
141 end
142 local lightTypes = {StringUtil.getVectorFromString(getXMLString(self.xmlFile, key.."#lightTypes"))}
143 for _, lightType in pairs(lightTypes) do
144 if registeredLightTypes[lightType] == nil then
145 registeredLightTypes[lightType] = lightType
146 spec.numLightTypes = spec.numLightTypes + 1
147 end
148 end
149
150 table.insert(spec.lightStates, lightTypes)
151 i = i + 1
152 end
153
154 local lightTypesStr = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.lights.states.aiState#lightTypes"), "0 1 2")
155 local lightTypes = {StringUtil.getVectorFromString(lightTypesStr)}
156 local lightsTypesMask = 0
157 for _, lightType in pairs(lightTypes) do
158 lightsTypesMask = bitOR(lightsTypesMask, 2^lightType)
159 end
160 spec.aiLightsTypesMask = lightsTypesMask
161
162 spec.sharedLights = {}
163 local i = 0
164 while true do
165 local key = string.format("vehicle.lights.sharedLight(%d)", i)
166 if not hasXMLProperty(self.xmlFile, key) then
167 break
168 end
169
170 local sharedLight = {}
171 if self:loadSharedLight(self.xmlFile, key, sharedLight) then
172 table.insert(spec.sharedLights, sharedLight)
173 end
174
175 i = i + 1
176 end
177
178 local realLightToLight = {}
179 self:loadRealLightSetup(self.xmlFile, "vehicle.lights.realLights.low", spec.realLights.low, realLightToLight)
180 self:loadRealLightSetup(self.xmlFile, "vehicle.lights.realLights.high", spec.realLights.high, realLightToLight)
181
182 self:loadVisualLights(self.xmlFile, "vehicle.lights.defaultLights.defaultLight", true, spec.defaultLights, spec.shaderDefaultLights)
183 self:loadVisualLights(self.xmlFile, "vehicle.lights.brakeLights.brakeLight", false, spec.brakeLights, spec.shaderBrakeLights)
184 self:loadVisualLights(self.xmlFile, "vehicle.lights.reverseLights.reverseLight", false, spec.reverseLights, spec.shaderReverseLights)
185 self:loadVisualLights(self.xmlFile, "vehicle.lights.turnLights.turnLightLeft", false, spec.turnLightsLeft, spec.shaderLeftTurnLights)
186 self:loadVisualLights(self.xmlFile, "vehicle.lights.turnLights.turnLightRight", false, spec.turnLightsRight, spec.shaderRightTurnLights)
187
188 spec.brakeLightsVisibility = false
189 spec.reverseLightsVisibility = false
190 spec.turnLightState = Lights.TURNLIGHT_OFF
191 spec.hasTurnLights = #spec.turnLightsLeft > 0 or #spec.turnLightsRight > 0
192 spec.turnLightRepetitionCount = 0
193
194 spec.actionEventsActiveChange = {}
195
196 spec.beaconLights = {}
197 local i = 0
198 while true do
199 local key = string.format("vehicle.lights.beaconLights.beaconLight(%d)", i)
200 if not hasXMLProperty(self.xmlFile, key) then
201 break
202 end
203
204 local node = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, key.."#node"), self.i3dMappings)
205 if node ~= nil then
206 local lightXmlFilename = getXMLString(self.xmlFile, key.."#filename")
207 if lightXmlFilename ~= nil then
208 lightXmlFilename = Utils.getFilename(lightXmlFilename, self.baseDirectory)
209 local lightXmlFile = loadXMLFile("beaconLightXML", lightXmlFilename)
210
211 if lightXmlFile ~= nil and lightXmlFile ~= 0 then
212 local i3dFilename = getXMLString(lightXmlFile, "beaconLight.filename")
213 if i3dFilename ~= nil then
214 local i3dNode = g_i3DManager:loadSharedI3DFile(i3dFilename, self.baseDirectory, false, false, false)
215 if i3dNode ~= nil and i3dNode ~= 0 then
216 local rootNode = I3DUtil.indexToObject(i3dNode, getXMLString(lightXmlFile, "beaconLight.rootNode#node"))
217 local rotatorNode = I3DUtil.indexToObject(i3dNode, getXMLString(lightXmlFile, "beaconLight.rotator#node"))
218 local speed = getXMLFloat(lightXmlFile, "beaconLight.rotator#speed") or 0.015
219 local lightNode = I3DUtil.indexToObject(i3dNode, getXMLString(lightXmlFile, "beaconLight.light#node"))
220 local lightShaderNode = I3DUtil.indexToObject(i3dNode, getXMLString(lightXmlFile, "beaconLight.light#shaderNode"))
221 local intensity = getXMLFloat(lightXmlFile, "beaconLight.light#intensity") or 1000
222 local realLightNode = I3DUtil.indexToObject(i3dNode, getXMLString(lightXmlFile, "beaconLight.realLight#node"))
223
224 if rootNode ~= nil and (lightNode ~= nil or lightShaderNode ~= nil) then
225 link(node, rootNode)
226 setTranslation(rootNode, 0,0,0)
227
228 local light = {}
229 light.filename = i3dFilename
230 light.rootNode = rootNode
231 light.rotatorNode = rotatorNode
232 light.lightNode = lightNode
233 light.lightShaderNode = lightShaderNode
234 light.realLightNode = realLightNode
235 light.speed = speed
236 light.intensity = intensity
237
238 if realLightNode ~= nil then
239 light.defaultColor = {getLightColor(realLightNode)}
240 setVisibility(realLightNode, false)
241 end
242
243 if lightNode ~= nil then
244 setVisibility(lightNode, false)
245 end
246 if lightShaderNode ~= nil then
247 local _,y,z,w = getShaderParameter(lightShaderNode, "lightControl")
248 setShaderParameter(lightShaderNode, "lightControl", 0, y, z, w, false)
249 end
250
251 if light.speed > 0 then
252 local rot = math.random(0, math.pi*2)
253 if light.rotatorNode ~= nil then
254 setRotation(light.rotatorNode, 0, rot, 0)
255 end
256 end
257
258 table.insert(spec.beaconLights, light)
259 end
260
261 delete(i3dNode)
262 end
263 end
264
265 delete(lightXmlFile)
266 end
267 end
268 end
269
270 i = i + 1
271 end
272 spec.beaconLightsActive = false
273
274 if self.isClient ~= nil then
275 spec.samples = {}
276 spec.samples.toggleLights = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.lights.sounds", "toggleLights", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
277 spec.samples.turnLight = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.lights.sounds", "turnLight", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
278 end
279
280 if self.loadDashboardsFromXML ~= nil then
281 self:loadDashboardsFromXML(self.xmlFile, "vehicle.lights.dashboards", {valueTypeToLoad = "lightState",
282 valueObject = spec,
283 valueFunc = "lightsTypesMask",
284 additionalAttributesFunc = Lights.dashboardLightAttributes,
285 stateFunc = Lights.dashboardLightState})
286
287 self:loadDashboardsFromXML(self.xmlFile, "vehicle.lights.dashboards", {valueTypeToLoad = "turnLightLeft",
288 valueObject = spec,
289 valueFunc = "turnLightState",
290 valueCompare = {Lights.TURNLIGHT_LEFT, Lights.TURNLIGHT_HAZARD}})
291
292 self:loadDashboardsFromXML(self.xmlFile, "vehicle.lights.dashboards", {valueTypeToLoad = "turnLightRight",
293 valueObject = spec,
294 valueFunc = "turnLightState",
295 valueCompare = {Lights.TURNLIGHT_RIGHT, Lights.TURNLIGHT_HAZARD}})
296
297 self:loadDashboardsFromXML(self.xmlFile, "vehicle.lights.dashboards", {valueTypeToLoad = "turnLightHazard",
298 valueObject = spec,
299 valueFunc = "turnLightState",
300 valueCompare = {Lights.TURNLIGHT_HAZARD}})
301
302 self:loadDashboardsFromXML(self.xmlFile, "vehicle.lights.dashboards", {valueTypeToLoad = "turnLightAny",
303 valueObject = spec,
304 valueFunc = "turnLightState",
305 valueCompare = {Lights.TURNLIGHT_LEFT, Lights.TURNLIGHT_RIGHT, Lights.TURNLIGHT_HAZARD}})
306
307 self:loadDashboardsFromXML(self.xmlFile, "vehicle.lights.dashboards", {valueTypeToLoad = "beaconLight",
308 valueObject = spec,
309 valueFunc = "beaconLightsActive"})
310 end
311end

onPostAttach

Description
Definition
onPostAttach()
Code
1213function Lights:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex)
1214 if attacherVehicle.getLightsTypesMask ~= nil then
1215 self:setLightsTypesMask(attacherVehicle:getLightsTypesMask(), true, true)
1216 self:setBeaconLightsVisibility(attacherVehicle:getBeaconLightsVisibility(), true, true)
1217 self:setTurnLightState(attacherVehicle:getTurnLightState(), true, true)
1218 end
1219end

onPostDetach

Description
Definition
onPostDetach()
Code
1223function Lights:onPostDetach()
1224 self:deactivateLights()
1225end

onReadStream

Description
Called on client side on join
Definition
onReadStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
336function Lights:onReadStream(streamId, connection)
337
338 local lightsTypesMask = streamReadInt32(streamId)
339 self:setLightsTypesMask(lightsTypesMask, true, true)
340
341 local beaconLightsActive = streamReadBool(streamId)
342 self:setBeaconLightsVisibility(beaconLightsActive, true, true)
343
344 local turnLightState = streamReadUIntN(streamId, Lights.turnLightSendNumBits)
345 self:setTurnLightState(turnLightState, true, true)
346end

onReadUpdateStream

Description
Definition
onReadUpdateStream()
Code
362function Lights:onReadUpdateStream(streamId, timestamp, connection)
363
364 if connection:getIsServer() then -- client side
365 local isRootAttacherVehicle = streamReadBool(streamId)
366 if isRootAttacherVehicle then
367 local brakeLightsVisibility = streamReadBool(streamId)
368 local reverseLightsVisibility = streamReadBool(streamId)
369 self:setBrakeLightsVisibility(brakeLightsVisibility)
370 self:setReverseLightsVisibility(reverseLightsVisibility)
371 end
372 end
373end

onRegisterActionEvents

Description
Definition
onRegisterActionEvents()
Code
1152function Lights:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
1153 if self.isClient then
1154 if self.getIsEntered ~= nil and self:getIsEntered() then
1155 local spec = self.spec_lights
1156 self:clearActionEventsTable(spec.actionEvents)
1157
1158 if isActiveForInputIgnoreSelection then
1159 _, spec.actionEventIdLight = self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_LIGHTS, self, Lights.actionEventToggleLights, false, true, false, true, nil)
1160 local _, actionEventIdFront = self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_LIGHT_FRONT, self, Lights.actionEventToggleLightFront, false, true, false, true, nil)
1161 local _, actionEventIdWorkBack = self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_WORK_LIGHT_BACK, self, Lights.actionEventToggleWorkLightBack, false, true, false, true, nil)
1162 local _, actionEventIdWorkFront = self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_WORK_LIGHT_FRONT, self, Lights.actionEventToggleWorkLightFront, false, true, false, true, nil)
1163 local _, actionEventIdHighBeam = self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_HIGH_BEAM_LIGHT, self, Lights.actionEventToggleHighBeamLight, false, true, false, true, nil)
1164 self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_TURNLIGHT_HAZARD, self, Lights.actionEventToggleTurnLightHazard, false, true, false, true, nil)
1165 self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_TURNLIGHT_LEFT, self, Lights.actionEventToggleTurnLightLeft, false, true, false, true, nil)
1166 self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_TURNLIGHT_RIGHT, self, Lights.actionEventToggleTurnLightRight, false, true, false, true, nil)
1167 local _, actionEventIdBeacon = self:addActionEvent(spec.actionEvents, InputAction.TOGGLE_BEACON_LIGHTS, self, Lights.actionEventToggleBeaconLights, false, true, false, true, nil)
1168
1169 -- action events that are only active if getIsActiveForLights
1170 spec.actionEventsActiveChange = {actionEventIdFront, actionEventIdWorkBack, actionEventIdWorkFront, actionEventIdHighBeam, actionEventIdBeacon}
1171
1172 for _,actionEvent in pairs(spec.actionEvents) do
1173 if actionEvent.actionEventId ~= nil then
1174 g_inputBinding:setActionEventTextVisibility(actionEvent.actionEventId, false)
1175 g_inputBinding:setActionEventTextPriority(actionEvent.actionEventId, GS_PRIO_LOW)
1176 end
1177 end
1178 end
1179 end
1180 end
1181end

onStartReverseDirectionChange

Description
Definition
onStartReverseDirectionChange()
Code
1203function Lights:onStartReverseDirectionChange()
1204 local spec = self.spec_lights
1205
1206 if spec.lightsTypesMask > 0 then
1207 self:setLightsTypesMask(spec.lightsTypesMask, true, true)
1208 end
1209end

onUpdate

Description
Called on update
Definition
onUpdate(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
398function Lights:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
399 local spec = self.spec_lights
400
401 if spec.beaconLightsActive then
402 for _, beaconLight in pairs(spec.beaconLights) do
403 if beaconLight.rotatorNode ~= nil then
404 rotate(beaconLight.rotatorNode, 0, beaconLight.speed*dt, 0)
405 end
406 end
407
408 self:raiseActive()
409 end
410
411 if spec.turnLightState ~= Lights.TURNLIGHT_OFF then
412 local alpha = MathUtil.clamp((math.cos(7*getShaderTimeSec()) + 0.2), 0, 1)
413
414 if spec.turnLightState == Lights.TURNLIGHT_LEFT or spec.turnLightState == Lights.TURNLIGHT_HAZARD then
415 for _, light in pairs(spec.activeTurnLightSetup.turnLightsLeft) do
416 setLightColor(light.node, light.defaultColor[1]*alpha, light.defaultColor[2]*alpha, light.defaultColor[3]*alpha)
417 for i=0, getNumOfChildren(light.node)-1 do
418 setLightColor(getChildAt(light.node, i), light.defaultColor[1]*alpha, light.defaultColor[2]*alpha, light.defaultColor[3]*alpha)
419 end
420 end
421 end
422 if spec.turnLightState == Lights.TURNLIGHT_RIGHT or spec.turnLightState == Lights.TURNLIGHT_HAZARD then
423 for _, light in pairs(spec.activeTurnLightSetup.turnLightsRight) do
424 setLightColor(light.node, light.defaultColor[1]*alpha, light.defaultColor[2]*alpha, light.defaultColor[3]*alpha)
425 for i=0, getNumOfChildren(light.node)-1 do
426 setLightColor(getChildAt(light.node, i), light.defaultColor[1]*alpha, light.defaultColor[2]*alpha, light.defaultColor[3]*alpha)
427 end
428 end
429 end
430
431 self:raiseActive()
432 end
433
434 if self.isClient and spec.samples.turnLight ~= nil then
435 if spec.turnLightState > Lights.TURNLIGHT_OFF then
436 local turnLightRepetitionCount = math.floor((getShaderTimeSec()*7 + math.acos(-0.2)) / (math.pi*2))
437 if spec.turnLightRepetitionCount ~= nil and turnLightRepetitionCount ~= spec.turnLightRepetitionCount then
438 g_soundManager:playSample(spec.samples.turnLight)
439 end
440 spec.turnLightRepetitionCount = turnLightRepetitionCount
441 end
442 end
443end

onUpdateTick

Description
Definition
onUpdateTick()
Code
447function Lights:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
448 local spec = self.spec_lights
449 local isDark = g_currentMission.environment.currentHour > 20 or g_currentMission.environment.currentHour < 7
450 g_inputBinding:setActionEventTextVisibility(spec.actionEventIdLight, isDark)
451
452 if self.isClient then
453 self:setInteriorLightsVisibility(self:getIsActiveForInteriorLights())
454
455 for _, v in ipairs(spec.actionEventsActiveChange) do
456 g_inputBinding:setActionEventActive(v, self:getIsActiveForLights())
457 end
458 g_inputBinding:setActionEventActive(spec.actionEventIdLight, self:getIsActiveForLights())
459 end
460end

onWriteStream

Description
Called on server side on join
Definition
onWriteStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
352function Lights:onWriteStream(streamId, connection)
353 local spec = self.spec_lights
354
355 streamWriteInt32(streamId, spec.lightsTypesMask)
356 streamWriteBool(streamId, spec.beaconLightsActive)
357 streamWriteUIntN(streamId, spec.turnLightState, Lights.turnLightSendNumBits)
358end

onWriteUpdateStream

Description
Definition
onWriteUpdateStream()
Code
377function Lights:onWriteUpdateStream(streamId, connection, dirtyMask)
378 local spec = self.spec_lights
379
380 if not connection:getIsServer() then -- server side
381 local rootAttacherVehicle = self:getRootVehicle()
382 if rootAttacherVehicle == self then -- only if this is the rootAttacherVehicle
383 streamWriteBool(streamId, true)
384 streamWriteBool(streamId, spec.brakeLightsVisibility)
385 streamWriteBool(streamId, spec.reverseLightsVisibility)
386 else
387 streamWriteBool(streamId, false)
388 end
389 end
390end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
27function Lights.prerequisitesPresent(specializations)
28 return true
29end

registerEventListeners

Description
Definition
registerEventListeners()
Code
70function Lights.registerEventListeners(vehicleType)
71 SpecializationUtil.registerEventListener(vehicleType, "onLoad", Lights)
72 SpecializationUtil.registerEventListener(vehicleType, "onDelete", Lights)
73 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Lights)
74 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Lights)
75 SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", Lights)
76 SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", Lights)
77 SpecializationUtil.registerEventListener(vehicleType, "onUpdate", Lights)
78 SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", Lights)
79 SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", Lights)
80 SpecializationUtil.registerEventListener(vehicleType, "onEnterVehicle", Lights)
81 SpecializationUtil.registerEventListener(vehicleType, "onLeaveVehicle", Lights)
82 SpecializationUtil.registerEventListener(vehicleType, "onStartReverseDirectionChange", Lights)
83 SpecializationUtil.registerEventListener(vehicleType, "onPostAttach", Lights)
84 SpecializationUtil.registerEventListener(vehicleType, "onPostDetach", Lights)
85 SpecializationUtil.registerEventListener(vehicleType, "onAutomatedTrainTravelActive", Lights)
86 SpecializationUtil.registerEventListener(vehicleType, "onAIActive", Lights)
87 SpecializationUtil.registerEventListener(vehicleType, "onAIBlock", Lights)
88 SpecializationUtil.registerEventListener(vehicleType, "onAIContinue", Lights)
89 SpecializationUtil.registerEventListener(vehicleType, "onAIEnd", Lights)
90end

registerEvents

Description
Definition
registerEvents()
Code
33function Lights.registerEvents(vehicleType)
34 SpecializationUtil.registerEvent(vehicleType, "onTurnLightStateChanged")
35 SpecializationUtil.registerEvent(vehicleType, "onBrakeLightsVisibilityChanged")
36 SpecializationUtil.registerEvent(vehicleType, "onReverseLightsVisibilityChanged")
37 SpecializationUtil.registerEvent(vehicleType, "onLightsTypesMaskChanged")
38 SpecializationUtil.registerEvent(vehicleType, "onBeaconLightsVisibilityChanged")
39 SpecializationUtil.registerEvent(vehicleType, "onDeactivateLights")
40end

registerFunctions

Description
Definition
registerFunctions()
Code
44function Lights.registerFunctions(vehicleType)
45 SpecializationUtil.registerFunction(vehicleType, "loadRealLightSetup", Lights.loadRealLightSetup)
46 SpecializationUtil.registerFunction(vehicleType, "loadRealLights", Lights.loadRealLights)
47 SpecializationUtil.registerFunction(vehicleType, "loadVisualLights", Lights.loadVisualLights)
48 SpecializationUtil.registerFunction(vehicleType, "getIsActiveForLights", Lights.getIsActiveForLights)
49 SpecializationUtil.registerFunction(vehicleType, "getIsActiveForInteriorLights", Lights.getIsActiveForInteriorLights)
50 SpecializationUtil.registerFunction(vehicleType, "getCanToggleLight", Lights.getCanToggleLight)
51 SpecializationUtil.registerFunction(vehicleType, "getUseHighProfile", Lights.getUseHighProfile)
52 SpecializationUtil.registerFunction(vehicleType, "setNextLightsState", Lights.setNextLightsState)
53 SpecializationUtil.registerFunction(vehicleType, "setLightsTypesMask", Lights.setLightsTypesMask)
54 SpecializationUtil.registerFunction(vehicleType, "getLightsTypesMask", Lights.getLightsTypesMask)
55 SpecializationUtil.registerFunction(vehicleType, "setTurnLightState", Lights.setTurnLightState)
56 SpecializationUtil.registerFunction(vehicleType, "getTurnLightState", Lights.getTurnLightState)
57 SpecializationUtil.registerFunction(vehicleType, "setBrakeLightsVisibility", Lights.setBrakeLightsVisibility)
58 SpecializationUtil.registerFunction(vehicleType, "setBeaconLightsVisibility", Lights.setBeaconLightsVisibility)
59 SpecializationUtil.registerFunction(vehicleType, "getBeaconLightsVisibility", Lights.getBeaconLightsVisibility)
60 SpecializationUtil.registerFunction(vehicleType, "setReverseLightsVisibility", Lights.setReverseLightsVisibility)
61 SpecializationUtil.registerFunction(vehicleType, "setInteriorLightsVisibility", Lights.setInteriorLightsVisibility)
62 SpecializationUtil.registerFunction(vehicleType, "deactivateLights", Lights.deactivateLights)
63 SpecializationUtil.registerFunction(vehicleType, "getDeactivateLightsOnLeave", Lights.getDeactivateLightsOnLeave)
64 SpecializationUtil.registerFunction(vehicleType, "loadSharedLight", Lights.loadSharedLight)
65 SpecializationUtil.registerFunction(vehicleType, "updateAILights", Lights.updateAILights)
66end

setBeaconLightsVisibility

Description
Toggle beacon light visibility
Definition
setBeaconLightsVisibility(boolean visibility, boolean force, boolean noEventSend)
Arguments
booleanvisibilitynew visibility state
booleanforceforce action
booleannoEventSendno event send
Return Values
booleanchangedvisibility has changed
Code
654function Lights:setBeaconLightsVisibility(visibility, force, noEventSend)
655 local spec = self.spec_lights
656
657 if visibility ~= spec.beaconLightsActive or force then
658 if noEventSend == nil or noEventSend == false then
659 if g_server ~= nil then
660 g_server:broadcastEvent(VehicleSetBeaconLightEvent:new(self, visibility), nil, nil, self)
661 else
662 g_client:getServerConnection():sendEvent(VehicleSetBeaconLightEvent:new(self, visibility))
663 end
664 end
665
666 spec.beaconLightsActive = visibility
667 local realBeaconLights = g_gameSettings:getValue("realBeaconLights")
668 for _, beaconLight in pairs(spec.beaconLights) do
669 if realBeaconLights and beaconLight.realLightNode ~= nil then
670 setVisibility(beaconLight.realLightNode, visibility)
671 end
672 if beaconLight.lightNode ~= nil then
673 setVisibility(beaconLight.lightNode, visibility)
674 end
675 if beaconLight.lightShaderNode ~= nil then
676 local value = 1*beaconLight.intensity
677 if not visibility then
678 value = 0
679 end
680
681 local _,y,z,w = getShaderParameter(beaconLight.lightShaderNode, "lightControl")
682 setShaderParameter(beaconLight.lightShaderNode, "lightControl", value, y, z, w, false)
683 end
684 end
685
686 SpecializationUtil.raiseEvent(self, "onBeaconLightsVisibilityChanged", visibility)
687 end
688
689 return true
690end

setBrakeLightsVisibility

Description
Set brake light visibility
Definition
setBrakeLightsVisibility(boolean visibility)
Arguments
booleanvisibilitynew visibility
Return Values
booleanchangedvisibility has changed
Code
793function Lights:setBrakeLightsVisibility(visibility)
794 local spec = self.spec_lights
795
796 if visibility ~= spec.brakeLightsVisibility then
797
798 local activeLightSetup = spec.realLights.low
799 local inactiveLightSetup = spec.realLights.high
800 if self:getUseHighProfile() then
801 activeLightSetup = spec.realLights.high
802 inactiveLightSetup = spec.realLights.low
803 end
804
805 -- deactivate inactive spec lights
806 for _, light in pairs(inactiveLightSetup.brakeLights) do
807 setVisibility(light.node, false)
808 end
809
810 -- set correct state for active spec lights
811 for _, light in pairs(activeLightSetup.brakeLights) do
812 light.isActive = visibility
813 if visibility then
814 if light.backLight ~= nil then
815 local color = light.backLight.defaultColor
816 setLightColor(light.node, color[1]*2, color[2]*2, color[3]*2)
817 for i=0, getNumOfChildren(light.node)-1 do
818 setLightColor(getChildAt(light.node, i), color[1]*2, color[2]*2, color[3]*2)
819 end
820 end
821 setVisibility(light.node, true)
822 light.isActive = true
823 else
824 local isVisible = false
825 if light.backLight ~= nil then
826 local color = light.backLight.defaultColor
827 setLightColor(light.node, color[1], color[2], color[3])
828 for i=0, getNumOfChildren(light.node)-1 do
829 setLightColor(getChildAt(light.node, i), color[1], color[2], color[3])
830 end
831 if light.backLight.isActive then
832 isVisible = true
833 end
834 end
835 setVisibility(light.node, isVisible)
836 end
837 end
838
839 for _, light in pairs(spec.brakeLights) do
840 setVisibility(light.node, visibility)
841 end
842
843 local dir = 1
844 if not visibility then
845 dir = -1
846 end
847 for _, sharedBrakeLight in ipairs(spec.shaderBrakeLights) do
848 local x,y,z,w = getShaderParameter(sharedBrakeLight.node, "lightControl")
849 setShaderParameter(sharedBrakeLight.node, "lightControl", math.max(x+dir*sharedBrakeLight.intensity, 0), y, z, w, false)
850
851 if sharedBrakeLight.toggleVisibility then
852 setVisibility(sharedBrakeLight.node, visibility)
853 end
854 end
855
856 spec.brakeLightsVisibility = visibility
857
858 SpecializationUtil.raiseEvent(self, "onBrakeLightsVisibilityChanged", visibility)
859 end
860
861 return true
862end

setInteriorLightsVisibility

Description
Set interior light visibility
Definition
setInteriorLightsVisibility(boolean visibility)
Arguments
booleanvisibilitynew visibility
Return Values
booleanchangedvisibility has changed
Code
921function Lights:setInteriorLightsVisibility(visibility)
922 local spec = self.spec_lights
923
924 -- interior lights are turned of between 8am and 10am and turn on between 4pm and 6pm
925 local brightness = 0
926 local hour = g_currentMission.environment.currentHour + g_currentMission.environment.currentMinute / 60
927 if hour < 10 then
928 brightness = 1-(hour - 8) / 2
929 end
930 if hour > 16 then
931 brightness = (hour - 16) / 2
932 end
933
934 brightness = MathUtil.clamp(brightness, 0, 1)
935
936 if brightness == 0 then
937 visibility = false
938 end
939
940 if visibility ~= spec.interiorLightsVisibility or brightness ~= spec.interiorLightsBrightness then
941 local activeLightSetup = spec.realLights.low
942 local inactiveLightSetup = spec.realLights.high
943 if self:getUseHighProfile() then
944 activeLightSetup = spec.realLights.high
945 inactiveLightSetup = spec.realLights.low
946 end
947
948 -- deactivate inactive spec lights
949 for _, light in pairs(inactiveLightSetup.interiorLights) do
950 setVisibility(light.node, false)
951 end
952
953 -- set correct state for active spec lights
954 for _, light in pairs(activeLightSetup.interiorLights) do
955 if visibility then
956 if light.startColor == nil then
957 light.startColor = {getLightColor(light.node)}
958 end
959
960 setLightColor(light.node, light.startColor[1]*brightness, light.startColor[2]*brightness, light.startColor[3]*brightness)
961 end
962
963 light.isActive = visibility
964 setVisibility(light.node, visibility)
965 end
966
967 spec.interiorLightsVisibility = visibility
968 spec.interiorLightsBrightness = brightness
969 end
970
971 return true
972end

setLightsTypesMask

Description
Set light type mask
Definition
setLightsTypesMask(integer lightsTypesMask, boolean force, boolean noEventSend)
Arguments
integerlightsTypesMasknew light types mask
booleanforceforce action
booleannoEventSendno event send
Return Values
booleanchangedmask has changed
Code
541function Lights:setLightsTypesMask(lightsTypesMask, force, noEventSend)
542 local spec = self.spec_lights
543
544 if lightsTypesMask ~= spec.lightsTypesMask or force then
545 if noEventSend == nil or noEventSend == false then
546 if g_server ~= nil then
547 g_server:broadcastEvent(VehicleSetLightEvent:new(self, lightsTypesMask), nil, nil, self)
548 else
549 g_client:getServerConnection():sendEvent(VehicleSetLightEvent:new(self, lightsTypesMask))
550 end
551 end
552
553 if self.isClient then
554 g_soundManager:playSample(spec.samples.toggleLights)
555 end
556
557 local activeLightSetup = spec.realLights.low
558 local inactiveLightSetup = spec.realLights.high
559 if self:getUseHighProfile() then
560 activeLightSetup = spec.realLights.high
561 inactiveLightSetup = spec.realLights.low
562 end
563
564 -- deactivate inactive spec lights
565 for _, light in pairs(inactiveLightSetup.lightTypes) do
566 setVisibility(light.node, false)
567 end
568
569 local function getIsLightActive(light)
570 local lightActive = false
571 for _, lightType in pairs(light.lightTypes) do
572 if bitAND(lightsTypesMask, 2^lightType) ~= 0 then
573 lightActive = true
574 break
575 end
576 end
577 if light.enableDirection ~= nil then
578 local reverserDirection = 1.0
579 if self.getReverserDirection ~= nil then
580 reverserDirection = self:getReverserDirection()
581 end
582 lightActive = lightActive and light.enableDirection == reverserDirection
583 end
584 if lightActive then
585 for _, excludedLightType in pairs(light.excludedLightTypes) do
586 if bitAND(lightsTypesMask, 2^excludedLightType) ~= 0 then
587 lightActive = false
588 break
589 end
590 end
591 end
592
593 return lightActive
594 end
595 -- activate real lights
596 for _,light in pairs(activeLightSetup.lightTypes) do
597 local isActive = getIsLightActive(light)
598 if isActive then
599 setVisibility(light.node, true)
600 else
601 local active = false
602 if light.brakeLight ~= nil then
603 if light.brakeLight.isActive then
604 active = true
605 end
606 end
607 setVisibility(light.node, active)
608 end
609
610 light.isActive = isActive
611 end
612 -- activate old corona lights
613 for _, light in pairs(spec.defaultLights) do
614 local isActive = getIsLightActive(light)
615 setVisibility(light.node, isActive)
616 end
617
618 -- set new lights
619 for _, light in pairs(spec.shaderDefaultLights) do
620 local isActive = getIsLightActive(light)
621 local value = 1
622 if not isActive then
623 value = 0
624 end
625 local _,y,z,w = getShaderParameter(light.node, "lightControl")
626 setShaderParameter(light.node, "lightControl", math.max(value*light.intensity, 0), y, z, w, false)
627
628 if light.toggleVisibility then
629 setVisibility(light.node, isActive)
630 end
631 end
632
633 spec.lightsTypesMask = lightsTypesMask
634
635 SpecializationUtil.raiseEvent(self, "onLightsTypesMaskChanged", lightsTypesMask)
636 end
637
638 return true
639end

setNextLightsState

Description
Definition
setNextLightsState()
Code
514function Lights:setNextLightsState()
515 local spec = self.spec_lights
516
517 if spec.lightStates ~= nil and #spec.lightStates > 0 then
518 local currentLightState = spec.currentLightState + 1
519 if currentLightState > #spec.lightStates or (spec.currentLightState == 0 and spec.lightsTypesMask > 0) then
520 currentLightState = 0
521 end
522
523 local lightsTypesMask = 0
524 if currentLightState > 0 then
525 for _, lightType in pairs(spec.lightStates[currentLightState]) do
526 lightsTypesMask = bitOR(lightsTypesMask, 2^lightType)
527 end
528 end
529 spec.currentLightState = currentLightState
530
531 self:setLightsTypesMask(lightsTypesMask)
532 end
533end

setReverseLightsVisibility

Description
Set reverse light visibility
Definition
setReverseLightsVisibility(boolean visibility)
Arguments
booleanvisibilitynew visibility
Return Values
booleanchangedvisibility has changed
Code
868function Lights:setReverseLightsVisibility(visibility)
869 local spec = self.spec_lights
870
871 if visibility ~= spec.reverseLightsVisibility then
872
873 local activeLightSetup = spec.realLights.low
874 local inactiveLightSetup = spec.realLights.high
875 if self:getUseHighProfile() then
876 activeLightSetup = spec.realLights.high
877 inactiveLightSetup = spec.realLights.low
878 end
879
880 -- deactivate inactive spec lights
881 for _, light in pairs(inactiveLightSetup.reverseLights) do
882 setVisibility(light.node, false)
883 end
884
885 -- set correct state for active spec lights
886 for _, light in pairs(activeLightSetup.reverseLights) do
887 setVisibility(light.node, visibility)
888 end
889
890 -- update old corona light elements
891 for _, light in pairs(spec.reverseLights) do
892 setVisibility(light.node, visibility)
893 end
894
895 -- update shader lights
896 local dir = 1
897 if not visibility then
898 dir = -1
899 end
900 for _, sharedReverseLight in ipairs(spec.shaderReverseLights) do
901 local x,y,z,w = getShaderParameter(sharedReverseLight.node, "lightControl")
902 setShaderParameter(sharedReverseLight.node, "lightControl", math.max(x+dir*sharedReverseLight.intensity), y, z, w, false)
903
904 if sharedReverseLight.toggleVisibility then
905 setVisibility(sharedReverseLight.node, visibility)
906 end
907 end
908
909 spec.reverseLightsVisibility = visibility
910
911 SpecializationUtil.raiseEvent(self, "onReverseLightsVisibilityChanged", visibility)
912 end
913
914 return true
915end

setTurnLightState

Description
Toggle turn light state
Definition
setTurnLightState(boolean state, boolean force, boolean noEventSend)
Arguments
booleanstatenew state
booleanforceforce action
booleannoEventSendno event send
Return Values
booleanchangedstate has changed
Code
705function Lights:setTurnLightState(state, force, noEventSend)
706 local spec = self.spec_lights
707
708 if state ~= spec.turnLightState or force then
709 if noEventSend == nil or noEventSend == false then
710 if g_server ~= nil then
711 g_server:broadcastEvent(VehicleSetTurnLightEvent:new(self, state), nil, nil, self)
712 else
713 g_client:getServerConnection():sendEvent(VehicleSetTurnLightEvent:new(self, state))
714 end
715 end
716
717 local activeLightSetup = spec.realLights.low
718 local inactiveLightSetup = spec.realLights.high
719 if self:getUseHighProfile() then
720 activeLightSetup = spec.realLights.high
721 inactiveLightSetup = spec.realLights.low
722 end
723
724 spec.activeTurnLightSetup = activeLightSetup
725
726 -- deactivate inactive spec lights
727 for _, light in pairs(inactiveLightSetup.turnLightsLeft) do
728 setVisibility(light.node, false)
729 end
730 for _, light in pairs(inactiveLightSetup.turnLightsRight) do
731 setVisibility(light.node, false)
732 end
733 -- set correct state for active spec lights
734 for _, light in pairs(activeLightSetup.turnLightsLeft) do
735 setVisibility(light.node, state == Lights.TURNLIGHT_LEFT or state == Lights.TURNLIGHT_HAZARD)
736 end
737 for _, light in pairs(activeLightSetup.turnLightsRight) do
738 setVisibility(light.node, state == Lights.TURNLIGHT_RIGHT or state == Lights.TURNLIGHT_HAZARD)
739 end
740 -- update old corona light elements
741 for _, light in pairs(spec.turnLightsLeft) do
742 setVisibility(light.node, state == Lights.TURNLIGHT_LEFT or state == Lights.TURNLIGHT_HAZARD)
743 end
744 for _, light in pairs(spec.turnLightsRight) do
745 setVisibility(light.node, state == Lights.TURNLIGHT_RIGHT or state == Lights.TURNLIGHT_HAZARD)
746 end
747
748 -- update shader lights
749 local value = 1
750 if state ~= Lights.TURNLIGHT_LEFT and state ~= Lights.TURNLIGHT_HAZARD then
751 value = 0
752 end
753 for _, sharedTurnLight in ipairs(spec.shaderLeftTurnLights) do
754 local _,y,z,w = getShaderParameter(sharedTurnLight.node, "lightControl")
755 setShaderParameter(sharedTurnLight.node, "lightControl", value*sharedTurnLight.intensity, y, z, w, false)
756
757 if sharedTurnLight.toggleVisibility then
758 setVisibility(sharedTurnLight.node, value == 1)
759 end
760 end
761 value = 1
762 if state ~= Lights.TURNLIGHT_RIGHT and state ~= Lights.TURNLIGHT_HAZARD then
763 value = 0
764 end
765 for _, sharedTurnLight in ipairs(spec.shaderRightTurnLights) do
766 local _,y,z,w = getShaderParameter(sharedTurnLight.node, "lightControl")
767 setShaderParameter(sharedTurnLight.node, "lightControl", value*sharedTurnLight.intensity, y, z, w, false)
768
769 if sharedTurnLight.toggleVisibility then
770 setVisibility(sharedTurnLight.node, value == 1)
771 end
772 end
773
774 spec.turnLightState = state
775
776 SpecializationUtil.raiseEvent(self, "onTurnLightStateChanged", state)
777 end
778
779 return true
780end

updateAILights

Description
Definition
updateAILights()
Code
1133function Lights:updateAILights()
1134 local spec = self.spec_lights
1135
1136 local dayMinutes = g_currentMission.environment.dayTime/(1000*60)
1137 local needLights = (dayMinutes > g_currentMission.environment.nightStartMinutes or dayMinutes < g_currentMission.environment.nightEndMinutes)
1138
1139 if needLights then
1140 if spec.lightsTypesMask ~= spec.aiLightsTypesMask then
1141 self:setLightsTypesMask(spec.aiLightsTypesMask)
1142 end
1143 else
1144 if spec.lightsTypesMask ~= 0 then
1145 self:setLightsTypesMask(0)
1146 end
1147 end
1148end