LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

TurnOnVehicle

Description
Specialization for vehicles which can be switched on and off
Functions

actionEventTurnOn

Description
Definition
actionEventTurnOn()
Code
727function TurnOnVehicle.actionEventTurnOn(self, actionName, inputValue, callbackState, isAnalog)
728 if self:getCanToggleTurnedOn() and self:getCanBeTurnedOn() then
729 self:setIsTurnedOn(not self:getIsTurnedOn())
730 else
731 if not self:getIsTurnedOn() then
732 local warning = self:getTurnedOnNotAllowedWarning()
733 if warning ~= nil then
734 g_currentMission:showBlinkingWarning(warning, 2000)
735 end
736 end
737 end
738end

getAIRequiresTurnOffOnHeadland

Description
Definition
getAIRequiresTurnOffOnHeadland()
Code
456function TurnOnVehicle:getAIRequiresTurnOffOnHeadland()
457 return false
458end

getAIRequiresTurnOn

Description
Definition
getAIRequiresTurnOn()
Code
450function TurnOnVehicle:getAIRequiresTurnOn()
451 return self.spec_turnOnVehicle.aiRequiresTurnOn
452end

getAlarmTriggerIsActive

Description
Definition
getAlarmTriggerIsActive()
Code
534function TurnOnVehicle:getAlarmTriggerIsActive(superFunc, alarmTrigger)
535 local ret = superFunc(self, alarmTrigger)
536
537 if alarmTrigger.needsTurnOn then
538 if not self:getIsTurnedOn() then
539 ret = false
540 end
541 end;
542
543 return ret
544end

getCanAIImplementContinueWork

Description
Returns true if vehicle is ready for ai work
Definition
getCanAIImplementContinueWork()
Return Values
booleanisReadyis ready for ai work
Code
501function TurnOnVehicle:getCanAIImplementContinueWork(superFunc)
502 local ret = false
503 if self:getCanBeTurnedOn() then
504 if self:getIsTurnedOn() then
505 ret = true
506 end
507 end
508
509 if not self:getAIRequiresTurnOn() then
510 ret = true
511 end
512
513 -- on headland the tool can be turned off
514 if not self:getIsAIImplementInLine() then
515 ret = true
516 end
517
518 return superFunc(self) and ret
519end

getCanBeSelected

Description
Definition
getCanBeSelected()
Code
599function TurnOnVehicle:getCanBeSelected(superFunc)
600 return true
601end

getCanBeTurnedOn

Description
Returns if vehicle can be turned on
Definition
getCanBeTurnedOn()
Return Values
booleancanBeTurnedOnvehicle can be turned on
Code
376function TurnOnVehicle:getCanBeTurnedOn()
377 local spec = self.spec_turnOnVehicle
378
379 if spec.isAlwaysTurnedOn then
380 return false
381 end
382
383 if self.getInputAttacherJoint ~= nil then
384 local inputAttacherJoint = self:getInputAttacherJoint()
385
386 if inputAttacherJoint ~= nil and inputAttacherJoint.canBeTurnedOn ~= nil and not inputAttacherJoint.canBeTurnedOn then
387 return false
388 end
389 end
390
391 if spec.requiresMotorTurnOn then
392 if self.getIsMotorStarted ~= nil then
393 return self:getIsMotorStarted()
394 else
395 local rootAttacherVehicle = self:getRootVehicle()
396 if rootAttacherVehicle ~= self then
397 if rootAttacherVehicle.getIsMotorStarted ~= nil then
398 return rootAttacherVehicle:getIsMotorStarted()
399 end
400 end
401 end
402 end
403
404 return true
405end

getCanToggleTurnedOn

Description
Returns if user is allowed to turn on the vehicle
Definition
getCanToggleTurnedOn()
Return Values
booleanallowallow turn on
Code
410function TurnOnVehicle:getCanToggleTurnedOn()
411 local spec = self.spec_turnOnVehicle
412
413 if spec.isAlwaysTurnedOn then
414 return false
415 end
416
417 if spec.turnedOnByAttacherVehicle then
418 return false
419 end
420
421 return true
422end

getIsFillUnitActive

Description
Definition
getIsFillUnitActive()
Code
558function TurnOnVehicle:getIsFillUnitActive(superFunc, fillUnitIndex)
559 local spec = self.spec_turnOnVehicle
560 if spec.activatableFillUnits[fillUnitIndex] == true then
561 if not self:getIsTurnedOn() then
562 return false
563 end
564 end
565
566 return superFunc(self, fillUnitIndex)
567end

getIsOperating

Description
Returns if vehicle is operating
Definition
getIsOperating()
Return Values
booleanisOperatingis operating
Code
524function TurnOnVehicle:getIsOperating(superFunc)
525 if self:getIsTurnedOn() then
526 return true
527 end
528
529 return superFunc(self)
530end

getIsPowerTakeOffActive

Description
Definition
getIsPowerTakeOffActive()
Code
605function TurnOnVehicle:getIsPowerTakeOffActive(superFunc)
606 return self:getIsTurnedOn() or superFunc(self)
607end

getIsSeedChangeAllowed

Description
Definition
getIsSeedChangeAllowed()
Code
593function TurnOnVehicle:getIsSeedChangeAllowed(superFunc)
594 return superFunc(self) and not self:getIsTurnedOn()
595end

getIsTurnedOn

Description
Returns if vehicle is turned on
Definition
getIsTurnedOn()
Return Values
booleanisTurnedOnvehicle is turned on
Code
367function TurnOnVehicle:getIsTurnedOn()
368 local spec = self.spec_turnOnVehicle
369
370 return spec.isAlwaysTurnedOn or spec.isTurnedOn
371end

getIsWorkAreaActive

Description
Returns true if work area is active
Definition
getIsWorkAreaActive(table workArea)
Arguments
tableworkAreaworkArea
Return Values
booleanisActivework area is active
Code
490function TurnOnVehicle:getIsWorkAreaActive(superFunc, workArea)
491 if not self:getIsTurnedOn() and workArea.needsSetIsTurnedOn then
492 return false
493 end
494
495 return superFunc(self, workArea)
496end

getShovelNodeIsActive

Description
Definition
getShovelNodeIsActive()
Code
581function TurnOnVehicle:getShovelNodeIsActive(superFunc, shovelNode)
582 if shovelNode.needsActiveVehicle then
583 if not self:getIsTurnedOn() then
584 return false
585 end
586 end
587
588 return superFunc(self, shovelNode)
589end

getTurnedOnNotAllowedWarning

Description
Returns turn on not allowed warning text
Definition
getTurnedOnNotAllowedWarning()
Return Values
stringwarningTextturn on not allowed warning text
Code
427function TurnOnVehicle:getTurnedOnNotAllowedWarning()
428 local spec = self.spec_turnOnVehicle
429
430 if spec.requiresMotorTurnOn then
431 if self.getIsMotorStarted ~= nil then
432 if not self:getIsMotorStarted() then
433 return spec.motorNotStartedWarning
434 end
435 else
436 local rootAttacherVehicle = self:getRootVehicle()
437 if rootAttacherVehicle.getIsMotorStarted ~= nil then
438 if not rootAttacherVehicle:getIsMotorStarted() then
439 return spec.motorNotStartedWarning
440 end
441 end
442 end
443 end
444
445 return nil
446end

loadAlarmTrigger

Description
Definition
loadAlarmTrigger()
Code
548function TurnOnVehicle:loadAlarmTrigger(superFunc, xmlFile, key, alarmTrigger, fillUnit)
549 local ret = superFunc(self, xmlFile, key, alarmTrigger, fillUnit)
550 alarmTrigger.needsTurnOn = Utils.getNoNil(getXMLBool(xmlFile, key .. "#needsTurnOn"), false)
551 alarmTrigger.turnOffInTrigger = Utils.getNoNil(getXMLBool(xmlFile, key .. "#turnOffInTrigger"), false)
552
553 return ret
554end

loadInputAttacherJoint

Description
Called on loading
Definition
loadInputAttacherJoint(table savegame)
Arguments
tablesavegamesavegame
Code
463function TurnOnVehicle:loadInputAttacherJoint(superFunc, xmlFile, key, inputAttacherJoint, i)
464 if not superFunc(self, xmlFile, key, inputAttacherJoint, i) then
465 return false
466 end
467
468 inputAttacherJoint.canBeTurnedOn = Utils.getNoNil(getXMLBool(xmlFile, key.. "#canBeTurnedOn"), true)
469
470 return true
471end

loadShovelNode

Description
Definition
loadShovelNode()
Code
571function TurnOnVehicle:loadShovelNode(superFunc, xmlFile, key, shovelNode)
572 superFunc(self, xmlFile, key, shovelNode)
573
574 shovelNode.needsActiveVehicle = Utils.getNoNil(getXMLBool(xmlFile, key .. "#needsActivation"), false)
575
576 return true
577end

loadWorkAreaFromXML

Description
Loads work areas from xml
Definition
loadWorkAreaFromXML(table workArea, integer xmlFile, string key)
Arguments
tableworkAreaworkArea
integerxmlFileid of xml object
stringkeykey
Code
478function TurnOnVehicle:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key)
479 local retValue = superFunc(self, workArea, xmlFile, key)
480
481 workArea.needsSetIsTurnedOn = Utils.getNoNil( getXMLBool(xmlFile, key.."#needsSetIsTurnedOn"), true )
482
483 return retValue
484end

onAIImplementBlock

Description
Definition
onAIImplementBlock()
Code
667function TurnOnVehicle:onAIImplementBlock()
668 if self:getAIRequiresTurnOn() then
669 self:setIsTurnedOn(false, true)
670 end
671end

onAIImplementContinue

Description
Definition
onAIImplementContinue()
Code
675function TurnOnVehicle:onAIImplementContinue()
676 if self:getAIRequiresTurnOn() then
677 self:getRootVehicle():registerSecureAITask(self, "getCanBeTurnedOn", {}, self, "setIsTurnedOn", {true})
678 end
679end

onAIImplementEnd

Description
Definition
onAIImplementEnd()
Code
661function TurnOnVehicle:onAIImplementEnd()
662 self:setIsTurnedOn(false, true)
663end

onAIImplementEndLine

Description
Definition
onAIImplementEndLine()
Code
651function TurnOnVehicle:onAIImplementEndLine()
652 if self:getAIRequiresTurnOffOnHeadland() then
653 if self:getAIRequiresTurnOn() then
654 self:getRootVehicle():registerAITask(self, "setIsTurnedOn", {false})
655 end
656 end
657end

onAIImplementStart

Description
Definition
onAIImplementStart()
Code
634function TurnOnVehicle:onAIImplementStart()
635 if self:getAIRequiresTurnOn() then
636 self:getRootVehicle():registerSecureAITask(self, "getCanBeTurnedOn", {}, self, "setIsTurnedOn", {true})
637 end
638end

onAIImplementStartLine

Description
Definition
onAIImplementStartLine()
Code
642function TurnOnVehicle:onAIImplementStartLine()
643 if self:getAIRequiresTurnOn() then
644 -- if vehicle could not be turned on on ai start we try it again on start line
645 self:getRootVehicle():registerSecureAITask(self, "getCanBeTurnedOn", {}, self, "setIsTurnedOn", {true})
646 end
647end

onAlarmTriggerChanged

Description
Definition
onAlarmTriggerChanged()
Code
624function TurnOnVehicle:onAlarmTriggerChanged(alarmTrigger, state)
625 if state then
626 if alarmTrigger.turnOffInTrigger then
627 self:setIsTurnedOn(false, true)
628 end
629 end
630end

onDeactivate

Description
Called on deactivate
Definition
onDeactivate()
Code
699function TurnOnVehicle:onDeactivate()
700 local spec = self.spec_turnOnVehicle
701 if spec.turnOffOnDeactivate then
702 self:setIsTurnedOn(false, true)
703 end
704end

onDelete

Description
Called on deleting
Definition
onDelete()
Code
180function TurnOnVehicle:onDelete()
181 if self.isClient then
182 local spec = self.spec_turnOnVehicle
183 g_soundManager:deleteSamples(spec.samples)
184 g_animationManager:deleteAnimations(spec.animationNodes)
185 end
186end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
87function TurnOnVehicle:onLoad(savegame)
88
89 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnSettings#turnOffText", "vehicle.turnOnVehicle#turnOffText") --FS15 to FS17
90 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnSettings#turnOnText", "vehicle.turnOnVehicle#turnOnText") --FS15 to FS17
91 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnSettings#needsSelection") --FS15 to FS17
92 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnSettings#isAlwaysTurnedOn", "vehicle.turnOnVehicle#isAlwaysTurnedOn") --FS15 to FS17
93 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnSettings#toggleButton", "vehicle.turnOnVehicle#toggleButton") --FS15 to FS17
94 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnSettings#animationName", "vehicle.turnOnVehicle.turnedAnimation#name") --FS15 to FS17
95 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnSettings#turnOnSpeedScale", "vehicle.turnOnVehicle.turnedAnimation#turnOnSpeedScale") --FS15 to FS17
96 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnSettings#turnOffSpeedScale", "vehicle.turnOnVehicle.turnedAnimation#turnOffSpeedScale") --FS15 to FS17
97 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnedOnRotationNodes.turnedOnRotationNode#type", "vehicle.turnOnVehicle.animationNodes.animationNode", "turnOn") --FS17 to FS19
98 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.foldable.foldingParts#turnOffOnFold", "vehicle.turnOnVehicle#turnOffIfNotAllowed") --FS17 to FS19
99
100 local spec = self.spec_turnOnVehicle
101
102 local turnOnButtonStr = getXMLString(self.xmlFile, "vehicle.turnOnVehicle#toggleButton")
103 if turnOnButtonStr ~= nil then
104 spec.toggleTurnOnInputBinding = InputAction[turnOnButtonStr]
105 end
106 spec.toggleTurnOnInputBinding = Utils.getNoNil(spec.toggleTurnOnInputBinding, InputAction.IMPLEMENT_EXTRA)
107
108 spec.turnOffText = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.turnOnVehicle#turnOffText"), "action_turnOffOBJECT")
109 spec.turnOnText = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.turnOnVehicle#turnOnText"), "action_turnOnOBJECT")
110 spec.isTurnedOn = false
111 spec.isAlwaysTurnedOn = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.turnOnVehicle#isAlwaysTurnedOn"), false)
112 spec.turnedOnByAttacherVehicle = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.turnOnVehicle#turnedOnByAttacherVehicle"), false)
113 spec.turnOffIfNotAllowed = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.turnOnVehicle#turnOffIfNotAllowed"), false)
114 spec.turnOffOnDeactivate = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.turnOnVehicle#turnOffOnDeactivate"), true)
115 spec.requiresMotorTurnOn = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.turnOnVehicle#requiresMotorTurnOn"), true)
116 spec.motorNotStartedWarning = string.format(g_i18n:getText(Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.turnOnVehicle#motorNotStartedWarning"), "warning_motorNotStarted"), self.customEnvironment), self.typeDesc)
117
118 spec.aiRequiresTurnOn = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.turnOnVehicle#aiRequiresTurnOn"), true)
119
120 if self.isClient then
121 spec.animationNodes = g_animationManager:loadAnimations(self.xmlFile, "vehicle.turnOnVehicle.animationNodes", self.components, self, self.i3dMappings)
122
123 local turnOnAnimation = getXMLString(self.xmlFile, "vehicle.turnOnVehicle.turnedAnimation#name")
124 if turnOnAnimation ~= nil then
125 spec.turnOnAnimation = {}
126 spec.turnOnAnimation.name = turnOnAnimation
127 spec.turnOnAnimation.turnOnSpeedScale = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.turnOnVehicle.turnedAnimation#turnOnSpeedScale"), 1)
128 spec.turnOnAnimation.turnOffSpeedScale = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.turnOnVehicle.turnedAnimation#turnOffSpeedScale"), -spec.turnOnAnimation.turnOnSpeedScale)
129 end
130
131 spec.turnedOnAnimations = {}
132 local i = 0
133 while true do
134 local baseKey = string.format("vehicle.turnOnVehicle.turnedOnAnimation(%d)", i)
135 if not hasXMLProperty(self.xmlFile, baseKey) then
136 break
137 end
138
139 local entry = {}
140 local name = getXMLString(self.xmlFile, baseKey.."#name")
141 if name ~= nil then
142 entry.name = name
143 entry.turnOnFadeTime = Utils.getNoNil(getXMLFloat(self.xmlFile, baseKey.."#turnOnFadeTime"), 1) * 1000
144 entry.turnOffFadeTime = Utils.getNoNil(getXMLFloat(self.xmlFile, baseKey.."#turnOffFadeTime"), 1) * 1000
145 entry.speedScale = Utils.getNoNil(getXMLFloat(self.xmlFile, baseKey.."#speedScale"), 1)
146 entry.speedDirection = 0
147 entry.currentSpeed = 0
148
149 table.insert(spec.turnedOnAnimations, entry)
150 end
151
152 i = i + 1
153 end
154
155 spec.activatableFillUnits = {}
156 local i = 0
157 while true do
158 local key = string.format("vehicle.turnOnVehicle.activatableFillUnits.activatableFillUnit(%d)", i)
159 if not hasXMLProperty(self.xmlFile, key) then
160 break
161 end
162
163 local fillUnitIndex = getXMLInt(self.xmlFile, key.."#index")
164 if fillUnitIndex ~= nil then
165 spec.activatableFillUnits[fillUnitIndex] = true
166 end
167
168 i = i + 1
169 end
170
171 spec.samples = {}
172 spec.samples.start = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.turnOnVehicle.sounds", "start", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
173 spec.samples.stop = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.turnOnVehicle.sounds", "stop", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
174 spec.samples.work = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.turnOnVehicle.sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
175 end
176end

onPostAttach

Description
Definition
onPostAttach()
Code
708function TurnOnVehicle:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex)
709 local spec = self.spec_turnOnVehicle
710 if spec.turnedOnByAttacherVehicle then
711 if attacherVehicle.getIsTurnedOn ~= nil then
712 self:setIsTurnedOn(attacherVehicle:getIsTurnedOn(), true)
713 end
714 end
715end

onPreDetach

Description
Called if vehicle gets detached
Definition
onPreDetach(table attacherVehicle, table implement)
Arguments
tableattacherVehicleattacher vehicle
tableimplementimplement
Code
721function TurnOnVehicle:onPreDetach(attacherVehicle, implement)
722 self:setIsTurnedOn(false, true)
723end

onReadStream

Description
Called on client side on join
Definition
onReadStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
192function TurnOnVehicle:onReadStream(streamId, connection)
193 local turnedOn = streamReadBool(streamId)
194 self:setIsTurnedOn(turnedOn, true)
195end

onRegisterActionEvents

Description
Definition
onRegisterActionEvents()
Code
611function TurnOnVehicle:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
612 if self.isClient then
613 local spec = self.spec_turnOnVehicle
614 self:clearActionEventsTable(spec.actionEvents)
615 if isActiveForInputIgnoreSelection and self:getCanToggleTurnedOn() then
616 local _, actionEventId = self:addActionEvent(spec.actionEvents, spec.toggleTurnOnInputBinding, self, TurnOnVehicle.actionEventTurnOn, false, true, false, true, nil)
617 g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH)
618 end
619 end
620end

onSetBroken

Description
Definition
onSetBroken()
Code
683function TurnOnVehicle:onSetBroken()
684 self:setIsTurnedOn(false, true)
685end

onStateChange

Description
Definition
onStateChange()
Code
689function TurnOnVehicle:onStateChange(state, data)
690 if state == Vehicle.STATE_CHANGE_MOTOR_TURN_OFF then
691 if not self:getCanBeTurnedOn() then
692 self:setIsTurnedOn(false, true)
693 end
694 end
695end

onTurnedOff

Description
Definition
onTurnedOff()
Code
345function TurnOnVehicle:onTurnedOff()
346 if self.isClient then
347 local spec = self.spec_turnOnVehicle
348
349 if self.playAnimation ~= nil then
350 if spec.turnOnAnimation ~= nil then
351 self:playAnimation(spec.turnOnAnimation.name, spec.turnOnAnimation.turnOffSpeedScale, self:getAnimationTime(spec.turnOnAnimation.name), true)
352 end
353
354 for _, animation in ipairs(spec.turnedOnAnimations) do
355 animation.speedDirection = -1
356 end
357 end
358 g_soundManager:stopSamples(spec.samples)
359 g_soundManager:playSample(spec.samples.stop)
360 g_animationManager:stopAnimations(spec.animationNodes)
361 end
362end

onTurnedOn

Description
Definition
onTurnedOn()
Code
320function TurnOnVehicle:onTurnedOn()
321 if self.isClient then
322 local spec = self.spec_turnOnVehicle
323
324 if self.playAnimation ~= nil then
325 if spec.turnOnAnimation ~= nil then
326 self:playAnimation(spec.turnOnAnimation.name, spec.turnOnAnimation.turnOnSpeedScale, self:getAnimationTime(spec.turnOnAnimation.name), true)
327 end
328
329 for _, animation in ipairs(spec.turnedOnAnimations) do
330 animation.speedDirection = 1
331 self:playAnimation(animation.name, math.max(animation.currentSpeed*animation.speedScale, 0.001), self:getAnimationTime(animation.name), true)
332 end
333 end
334
335 g_soundManager:stopSamples(spec.samples)
336 g_soundManager:playSample(spec.samples.start)
337 g_soundManager:playSample(spec.samples.work, 0, spec.samples.start)
338
339 g_animationManager:startAnimations(spec.animationNodes)
340 end
341end

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
211function TurnOnVehicle:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
212 local spec = self.spec_turnOnVehicle
213
214 local isTurnedOn = self:getIsTurnedOn()
215
216 if self.isClient then
217 if not spec.isAlwaysTurnedOn and not spec.turnedOnByAttacherVehicle then
218 -- update activity of actionEvent
219 if spec.actionEvents ~= nil then
220 local actionEvent = spec.actionEvents[spec.toggleTurnOnInputBinding]
221 if actionEvent ~= nil and actionEvent.actionEventId ~= nil then
222 local state = self:getCanToggleTurnedOn()
223
224 if state then
225 local text
226 if isTurnedOn then
227 text = string.format(g_i18n:getText("action_turnOffOBJECT"), self.typeDesc)
228 else
229 text = string.format(g_i18n:getText("action_turnOnOBJECT"), self.typeDesc)
230 end
231 g_inputBinding:setActionEventText(actionEvent.actionEventId, text)
232 end
233
234 g_inputBinding:setActionEventActive(actionEvent.actionEventId, state)
235 end
236 end
237 end
238 end
239
240 if self.isClient then
241 if self.playAnimation ~= nil then
242 for _, animation in ipairs(spec.turnedOnAnimations) do
243 if animation.speedDirection ~= 0 then
244 local duration = animation.turnOnFadeTime
245 if animation.speedDirection == -1 then
246 duration = animation.turnOffFadeTime
247 end
248 animation.currentSpeed = MathUtil.clamp(animation.currentSpeed + animation.speedDirection * dt/duration, 0, 1)
249 self:setAnimationSpeed(animation.name, animation.currentSpeed*animation.speedScale)
250 if animation.speedDirection == -1 and animation.currentSpeed == 0 then
251 self:stopAnimation(animation.name, true)
252 end
253
254 if animation.currentSpeed == 1 or animation.currentSpeed == 0 then
255 animation.speedDirection = 0
256 end
257 end
258 end
259 end
260 end
261end

onUpdateTick

Description
Called on update tick
Definition
onUpdateTick(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
268function TurnOnVehicle:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
269 if self.isServer then
270 local spec = self.spec_turnOnVehicle
271 if spec.turnOffIfNotAllowed then
272 if not self:getCanBeTurnedOn() then
273 if self:getIsTurnedOn() then
274 self:setIsTurnedOn(false)
275 else
276 if self.getAttacherVehicle ~= nil then
277 local attacherVehicle = self:getAttacherVehicle()
278 if attacherVehicle ~= nil then
279 if attacherVehicle.setIsTurnedOn ~= nil and attacherVehicle:getIsTurnedOn() then
280 attacherVehicle:setIsTurnedOn(false)
281 end
282 end
283 end
284 end
285 end
286 end
287 end
288end

onWriteStream

Description
Called on server side on join
Definition
onWriteStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
201function TurnOnVehicle:onWriteStream(streamId, connection)
202 local spec = self.spec_turnOnVehicle
203 streamWriteBool(streamId, spec.isTurnedOn)
204end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
17function TurnOnVehicle.prerequisitesPresent(specializations)
18 return true
19end

registerEventListeners

Description
Definition
registerEventListeners()
Code
60function TurnOnVehicle.registerEventListeners(vehicleType)
61 SpecializationUtil.registerEventListener(vehicleType, "onLoad", TurnOnVehicle)
62 SpecializationUtil.registerEventListener(vehicleType, "onDelete", TurnOnVehicle)
63 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", TurnOnVehicle)
64 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", TurnOnVehicle)
65 SpecializationUtil.registerEventListener(vehicleType, "onUpdate", TurnOnVehicle)
66 SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", TurnOnVehicle)
67 SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", TurnOnVehicle)
68 SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", TurnOnVehicle)
69 SpecializationUtil.registerEventListener(vehicleType, "onPostAttach", TurnOnVehicle)
70 SpecializationUtil.registerEventListener(vehicleType, "onPreDetach", TurnOnVehicle)
71 SpecializationUtil.registerEventListener(vehicleType, "onTurnedOn", TurnOnVehicle)
72 SpecializationUtil.registerEventListener(vehicleType, "onTurnedOff", TurnOnVehicle)
73 SpecializationUtil.registerEventListener(vehicleType, "onAlarmTriggerChanged", TurnOnVehicle)
74 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStart", TurnOnVehicle)
75 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStartLine", TurnOnVehicle)
76 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementEndLine", TurnOnVehicle)
77 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementEnd", TurnOnVehicle)
78 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementBlock", TurnOnVehicle)
79 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementContinue", TurnOnVehicle)
80 SpecializationUtil.registerEventListener(vehicleType, "onSetBroken", TurnOnVehicle)
81 SpecializationUtil.registerEventListener(vehicleType, "onStateChange", TurnOnVehicle)
82end

registerEvents

Description
Definition
registerEvents()
Code
23function TurnOnVehicle.registerEvents(vehicleType)
24 SpecializationUtil.registerEvent(vehicleType, "onTurnedOn")
25 SpecializationUtil.registerEvent(vehicleType, "onTurnedOff")
26end

registerFunctions

Description
Definition
registerFunctions()
Code
30function TurnOnVehicle.registerFunctions(vehicleType)
31 SpecializationUtil.registerFunction(vehicleType, "setIsTurnedOn", TurnOnVehicle.setIsTurnedOn)
32 SpecializationUtil.registerFunction(vehicleType, "getIsTurnedOn", TurnOnVehicle.getIsTurnedOn)
33 SpecializationUtil.registerFunction(vehicleType, "getCanBeTurnedOn", TurnOnVehicle.getCanBeTurnedOn)
34 SpecializationUtil.registerFunction(vehicleType, "getCanToggleTurnedOn", TurnOnVehicle.getCanToggleTurnedOn)
35 SpecializationUtil.registerFunction(vehicleType, "getTurnedOnNotAllowedWarning", TurnOnVehicle.getTurnedOnNotAllowedWarning)
36 SpecializationUtil.registerFunction(vehicleType, "getAIRequiresTurnOn", TurnOnVehicle.getAIRequiresTurnOn)
37 SpecializationUtil.registerFunction(vehicleType, "getAIRequiresTurnOffOnHeadland", TurnOnVehicle.getAIRequiresTurnOffOnHeadland)
38end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
42function TurnOnVehicle.registerOverwrittenFunctions(vehicleType)
43 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadInputAttacherJoint", TurnOnVehicle.loadInputAttacherJoint)
44 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadWorkAreaFromXML", TurnOnVehicle.loadWorkAreaFromXML)
45 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsWorkAreaActive", TurnOnVehicle.getIsWorkAreaActive)
46 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanAIImplementContinueWork", TurnOnVehicle.getCanAIImplementContinueWork)
47 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsOperating", TurnOnVehicle.getIsOperating)
48 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAlarmTriggerIsActive", TurnOnVehicle.getAlarmTriggerIsActive)
49 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadAlarmTrigger", TurnOnVehicle.loadAlarmTrigger)
50 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsFillUnitActive", TurnOnVehicle.getIsFillUnitActive)
51 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadShovelNode", TurnOnVehicle.loadShovelNode)
52 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getShovelNodeIsActive", TurnOnVehicle.getShovelNodeIsActive)
53 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSeedChangeAllowed", TurnOnVehicle.getIsSeedChangeAllowed)
54 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", TurnOnVehicle.getCanBeSelected)
55 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsPowerTakeOffActive", TurnOnVehicle.getIsPowerTakeOffActive)
56end

setIsTurnedOn

Description
Set is turned on state
Definition
setIsTurnedOn(boolean isTurnedOn, boolean noEventSend)
Arguments
booleanisTurnedOnnew is is turned on state
booleannoEventSendno event send
Code
294function TurnOnVehicle:setIsTurnedOn(isTurnedOn, noEventSend)
295 local spec = self.spec_turnOnVehicle
296
297 if isTurnedOn ~= spec.isTurnedOn then
298 SetTurnedOnEvent.sendEvent(self, isTurnedOn, noEventSend)
299 spec.isTurnedOn = isTurnedOn
300
301 local actionEvent = spec.actionEvents[InputAction.TOGGLE_COVER]
302 local text
303
304 if spec.isTurnedOn then
305 SpecializationUtil.raiseEvent(self, "onTurnedOn")
306 text = string.format(g_i18n:getText(spec.turnOffText, self.customEnvironment), self.typeDesc)
307 else
308 SpecializationUtil.raiseEvent(self, "onTurnedOff")
309 text = string.format(g_i18n:getText(spec.turnOnText, self.customEnvironment), self.typeDesc)
310 end
311
312 if actionEvent ~= nil then
313 g_inputBinding:setActionEventText(actionEvent.actionEventId, text)
314 end
315 end
316end