LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

Plow

Description
Specialization for plows providing additional folding/rotating functionality
Functions

actionEventLimitToField

Description
Definition
actionEventLimitToField()
Code
718function Plow.actionEventLimitToField(self, actionName, inputValue, callbackState, isAnalog)
719 local spec = self.spec_plow
720 if not spec.forceLimitToField then
721 self:setPlowLimitToField(not spec.limitToField)
722 end
723end

actionEventTurn

Description
Definition
actionEventTurn()
Code
707function Plow.actionEventTurn(self, actionName, inputValue, callbackState, isAnalog)
708 local spec = self.spec_plow
709 if spec.rotationPart.turnAnimation ~= nil then
710 if self:getIsPlowRotationAllowed() then
711 self:setRotationMax(not spec.rotationMax)
712 end
713 end
714end

doCheckSpeedLimit

Description
Definition
doCheckSpeedLimit()
Code
486function Plow:doCheckSpeedLimit(superFunc)
487 return superFunc(self) or (self.spec_plow.onlyActiveWhenLowered and self:getIsImplementChainLowered())
488end

getAIInvertMarkersOnTurn

Description
Definition
getAIInvertMarkersOnTurn()
Code
538function Plow:getAIInvertMarkersOnTurn(superFunc, turnLeft)
539 local spec = self.spec_plow
540 if spec.rotationPart.turnAnimation ~= nil then
541 if turnLeft then
542 return spec.rotationMax == spec.rotateLeftToMax
543 else
544 return spec.rotationMax ~= spec.rotateLeftToMax
545 end
546 end
547
548 return false
549end

getCanAIImplementContinueWork

Description
Definition
getCanAIImplementContinueWork()
Code
532function Plow:getCanAIImplementContinueWork(superFunc)
533 return not self:getIsAnimationPlaying(self.spec_plow.rotationPart.turnAnimation) and superFunc(self)
534end

getCanBeSelected

Description
Definition
getCanBeSelected()
Code
553function Plow:getCanBeSelected(superFunc)
554 return true
555end

getDefaultSpeedLimit

Description
Definition
getDefaultSpeedLimit()
Code
504function Plow.getDefaultSpeedLimit()
505 return 15
506end

getDirtMultiplier

Description
Definition
getDirtMultiplier()
Code
404function Plow:getDirtMultiplier(superFunc)
405 local multiplier = superFunc(self)
406
407 local spec = self.spec_plow
408 if spec.isWorking then
409 multiplier = multiplier + self:getWorkDirtMultiplier() * self:getLastSpeed() / self.speedLimit
410 end
411
412 return multiplier
413end

getIsFoldAllowed

Description
Definition
getIsFoldAllowed()
Code
364function Plow:getIsFoldAllowed(superFunc, direction, onAiTurnOn)
365 local spec = self.spec_plow
366
367 if spec.rotationPart.limitFoldRotationMax ~= nil and spec.rotationPart.limitFoldRotationMax == spec.rotationMax then
368 return false
369 end
370
371 if spec.rotationPart.turnAnimation ~= nil and self.getAnimationTime ~= nil then
372 local rotationTime = self:getAnimationTime(spec.rotationPart.turnAnimation)
373 if rotationTime > spec.rotationPart.foldRotationMaxLimit or rotationTime < spec.rotationPart.foldRotationMinLimit then
374 return false
375 end
376 end
377
378 if not spec.rotationPart.rotationAllowedIfLowered and self.getIsLowered ~= nil and self:getIsLowered() then
379 return false
380 end
381
382 return superFunc(self, direction, onAiTurnOn)
383end

getIsFoldMiddleAllowed

Description
Definition
getIsFoldMiddleAllowed()
Code
387function Plow:getIsFoldMiddleAllowed(superFunc)
388 local spec = self.spec_plow
389
390 if spec.rotationPart.limitFoldRotationMax ~= nil and spec.rotationPart.limitFoldRotationMax == spec.rotationMax then
391 return false
392 end
393 if spec.rotationPart.turnAnimation ~= nil and self.getAnimationTime ~= nil then
394 local rotationTime = self:getAnimationTime(spec.rotationPart.turnAnimation)
395 if rotationTime > spec.rotationPart.foldRotationMaxLimit or rotationTime < spec.rotationPart.foldRotationMinLimit then
396 return false
397 end
398 end
399 return superFunc(self)
400end

getIsPlowRotationAllowed

Description
Definition
getIsPlowRotationAllowed()
Code
345function Plow:getIsPlowRotationAllowed()
346 local spec = self.spec_plow
347
348 if self.getFoldAnimTime ~= nil then
349 local foldAnimTime = self:getFoldAnimTime()
350 if foldAnimTime > spec.rotationPart.rotationFoldMaxLimit or foldAnimTime < spec.rotationPart.rotationFoldMinLimit then
351 return false
352 end
353 end
354
355 if not spec.rotationPart.rotationAllowedIfLowered and self.getIsLowered ~= nil and self:getIsLowered() then
356 return false
357 end
358
359 return true
360end

getIsSpeedRotatingPartActive

Description
Definition
getIsSpeedRotatingPartActive()
Code
446function Plow:getIsSpeedRotatingPartActive(superFunc, speedRotatingPart)
447 local spec = self.spec_plow
448
449 if spec.rotationPart.turnAnimation ~= nil and speedRotatingPart.disableOnTurn then
450 local turnAnimTime = self:getAnimationTime(spec.rotationPart.turnAnimation)
451 if turnAnimTime ~= nil then
452 local enabled
453 if speedRotatingPart.turnAnimLimitSide < 0 then
454 enabled = (turnAnimTime <= speedRotatingPart.turnAnimLimit)
455 elseif speedRotatingPart.turnAnimLimitSide > 0 then
456 enabled = (1-turnAnimTime <= speedRotatingPart.turnAnimLimit)
457 else
458 enabled = (turnAnimTime <= speedRotatingPart.turnAnimLimit or 1-turnAnimTime <= speedRotatingPart.turnAnimLimit)
459 end
460 if not enabled then
461 return false
462 end
463 end
464 end
465
466 return superFunc(self, speedRotatingPart)
467end

getIsWorkAreaActive

Description
Definition
getIsWorkAreaActive()
Code
510function Plow:getIsWorkAreaActive(superFunc, workArea)
511 if not superFunc(self, workArea) then
512 return false
513 end
514
515 local spec = self.spec_plow
516
517 if spec.startActivationTime > g_currentMission.time then
518 return false
519 end
520
521 if spec.onlyActiveWhenLowered and self.getIsLowered ~= nil then
522 if not self:getIsLowered(false) then
523 return false
524 end
525 end
526
527 return true
528end

getSpeedRotatingPartDirection

Description
Definition
getSpeedRotatingPartDirection()
Code
471function Plow:getSpeedRotatingPartDirection(superFunc, speedRotatingPart)
472 local spec = self.spec_plow
473
474 if spec.rotationPart.turnAnimation ~= nil then
475 local turnAnimTime = self:getAnimationTime(spec.rotationPart.turnAnimation)
476 if turnAnimTime > 0.5 and speedRotatingPart.invertDirectionOnRotation then
477 return -1
478 end
479 end
480
481 return superFunc(self, speedRotatingPart)
482end

getWearMultiplier

Description
Returns current wear multiplier
Definition
getWearMultiplier()
Return Values
floatdirtMultipliercurrent wear multiplier
Code
418function Plow:getWearMultiplier(superFunc)
419 local multiplier = superFunc(self)
420
421 local spec = self.spec_plow
422 if spec.isWorking then
423 multiplier = multiplier + self:getWorkWearMultiplier() * self:getLastSpeed() / self.speedLimit
424 end
425
426 return multiplier
427end

initSpecialization

Description
Definition
initSpecialization()
Code
18function Plow.initSpecialization()
19 g_workAreaTypeManager:addWorkAreaType("plow", true)
20end

loadSpeedRotatingPartFromXML

Description
Definition
loadSpeedRotatingPartFromXML()
Code
431function Plow:loadSpeedRotatingPartFromXML(superFunc, speedRotatingPart, xmlFile, key)
432 if not superFunc(self, speedRotatingPart, xmlFile, key) then
433 return false
434 end
435
436 speedRotatingPart.disableOnTurn = Utils.getNoNil(getXMLBool(xmlFile, key .. "#disableOnTurn"), true)
437 speedRotatingPart.turnAnimLimit = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#turnAnimLimit"), 0)
438 speedRotatingPart.turnAnimLimitSide = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#turnAnimLimitSide"), 0)
439 speedRotatingPart.invertDirectionOnRotation = Utils.getNoNil(getXMLBool(xmlFile, key .. "#invertDirectionOnRotation"), true)
440
441 return true
442end

loadWorkAreaFromXML

Description
Definition
loadWorkAreaFromXML()
Code
492function Plow:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key)
493 local retValue = superFunc(self, workArea, xmlFile, key)
494
495 if workArea.type == WorkAreaType.DEFAULT then
496 workArea.type = WorkAreaType.PLOW
497 end
498
499 return retValue
500end

onAIImplementTurnProgress

Description
Definition
onAIImplementTurnProgress()
Code
681function Plow:onAIImplementTurnProgress(progress, left)
682 local spec = self.spec_plow
683
684 if progress > spec.ai.rotateToCenterHeadlandPos and progress < spec.ai.rotateCompletelyHeadlandPos then
685 self:setRotationCenter()
686 elseif progress > spec.ai.rotateCompletelyHeadlandPos then
687 self:setRotationMax(left)
688 end
689end

onDeactivate

Description
Definition
onDeactivate()
Code
671function Plow:onDeactivate()
672 if self.isClient then
673 local spec = self.spec_plow
674 g_soundManager:stopSamples(spec.samples)
675 spec.isWorkSamplePlaying = false
676 end
677end

onDelete

Description
Definition
onDelete()
Code
165function Plow:onDelete()
166 if self.isClient then
167 local spec = self.spec_plow
168 g_soundManager:deleteSamples(spec.samples)
169 end
170end

onEndWorkAreaProcessing

Description
Definition
onEndWorkAreaProcessing()
Code
604function Plow:onEndWorkAreaProcessing(dt)
605 local spec = self.spec_plow
606
607 if self.isServer then
608 local lastStatsArea = spec.workAreaParameters.lastStatsArea
609
610 if lastStatsArea > 0 then
611 local ha = MathUtil.areaToHa(lastStatsArea, g_currentMission:getFruitPixelsToSqm()) -- 4096px are mapped to 2048m
612 local stats = g_currentMission:farmStats(self:getLastTouchedFarmlandFarmId())
613 stats:updateStats("workedHectares", ha)
614 stats:updateStats("plowedHectares", ha)
615
616 stats:updateStats("workedTime", dt/(1000*60))
617 stats:updateStats("plowedTime", dt/(1000*60))
618 end
619 end
620
621 if self.isClient then
622 if spec.isWorking then
623 if not spec.isWorkSamplePlaying then
624 g_soundManager:playSample(spec.samples.work)
625 spec.isWorkSamplePlaying = true
626 end
627 else
628 if spec.isWorkSamplePlaying then
629 g_soundManager:stopSample(spec.samples.work)
630 spec.isWorkSamplePlaying = false
631 end
632 end
633 end
634end

onFinishAnimation

Description
Definition
onFinishAnimation()
Code
700function Plow:onFinishAnimation(animName)
701 local spec = self.spec_plow
702 g_soundManager:stopSample(spec.samples.turn)
703end

onLoad

Description
Definition
onLoad()
Code
78function Plow:onLoad(savegame)
79
80 if self:getGroundReferenceNodeFromIndex(1) == nil then
81 print("Warning: No ground reference nodes in "..self.configFileName)
82 end
83
84 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.rotationPart", "vehicle.plow.rotationPart") --FS17 to FS19
85 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.ploughDirectionNode#index", "vehicle.plow.directionNode#node") --FS17 to FS19
86 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.rotateLeftToMax#value", "vehicle.plow.rotateLeftToMax#value") --FS17 to FS19
87 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.animTimeCenterPosition#value", "vehicle.plow.ai#centerPosition") --FS17 to FS19
88 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.aiPlough#rotateEarly", "vehicle.plow.ai#rotateCompletelyHeadlandPos") --FS17 to FS19
89 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.onlyActiveWhenLowered#value", "vehicle.plow.onlyActiveWhenLowered#value") --FS17 to FS19
90
91 local spec = self.spec_plow
92
93 spec.rotationPart = {}
94 spec.rotationPart.turnAnimation = getXMLString(self.xmlFile, "vehicle.plow.rotationPart#turnAnimationName")
95 spec.rotationPart.foldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.rotationPart#foldMinLimit"), 0)
96 spec.rotationPart.foldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.rotationPart#foldMaxLimit"), 1)
97 spec.rotationPart.limitFoldRotationMax = getXMLBool(self.xmlFile, "vehicle.plow.rotationPart#limitFoldRotationMax")
98 spec.rotationPart.foldRotationMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.rotationPart#foldRotationMinLimit"), 0)
99 spec.rotationPart.foldRotationMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.rotationPart#foldRotationMaxLimit"), 1)
100 spec.rotationPart.rotationFoldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.rotationPart#rotationFoldMinLimit"), 0)
101 spec.rotationPart.rotationFoldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.rotationPart#rotationFoldMaxLimit"), 1)
102 spec.rotationPart.rotationAllowedIfLowered = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.plow.rotationPart#rotationAllowedIfLowered"), true)
103
104 spec.directionNode = Utils.getNoNil(I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.plow.directionNode#node"), self.i3dMappings), self.components[1].node)
105
106 if self.addAITerrainDetailRequiredRange ~= nil then
107 self:addAITerrainDetailRequiredRange(g_currentMission.cultivatorValue, g_currentMission.cultivatorValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels)
108 self:addAITerrainDetailRequiredRange(g_currentMission.sowingValue, g_currentMission.sowingValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels)
109 self:addAITerrainDetailRequiredRange(g_currentMission.sowingWidthValue, g_currentMission.sowingWidthValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels)
110 self:addAITerrainDetailRequiredRange(g_currentMission.grassValue, g_currentMission.grassValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels)
111 end
112
113 spec.ai = {}
114 spec.ai.centerPosition = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.ai#centerPosition"), 0.5)
115 spec.ai.rotateToCenterHeadlandPos = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.ai#rotateToCenterHeadlandPos"), 0.5)
116 spec.ai.rotateCompletelyHeadlandPos = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.plow.ai#rotateCompletelyHeadlandPos"), 0.5)
117
118 spec.rotateLeftToMax = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.plow.rotateLeftToMax#value"), true)
119 spec.onlyActiveWhenLowered = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.plow.onlyActiveWhenLowered#value"), true)
120 spec.rotationMax = false
121 spec.startActivationTimeout = 2000
122 spec.startActivationTime = 0
123 spec.lastPlowArea = 0
124 spec.limitToField = true
125 spec.forceLimitToField = false
126 spec.wasTurnAnimationStopped = false
127 spec.isWorking = false
128
129 if self.isClient then
130 spec.samples = {}
131 spec.samples.turn = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.plow.sounds", "turn", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
132 spec.samples.work = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.plow.sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
133 spec.isWorkSamplePlaying = false
134 end
135
136 spec.workAreaParameters = {}
137 spec.workAreaParameters.limitToField = spec.limitToField
138 spec.workAreaParameters.forceLimitToField = spec.forceLimitToField
139 spec.workAreaParameters.angle = 0
140 spec.workAreaParameters.lastChangedArea = 0
141 spec.workAreaParameters.lastStatsArea = 0
142 spec.workAreaParameters.lastTotalArea = 0
143end

onPostAttach

Description
Called if vehicle gets attached
Definition
onPostAttach(table attacherVehicle, integer inputJointDescIndex, integer jointDescIndex)
Arguments
tableattacherVehicleattacher vehicle
integerinputJointDescIndexindex of input attacher joint
integerjointDescIndexindex of attacher joint it gets attached to
Code
641function Plow:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex)
642 local spec = self.spec_plow
643
644 spec.startActivationTime = g_currentMission.time + spec.startActivationTimeout
645 if spec.wasTurnAnimationStopped then
646 local dir = 1
647 if not spec.rotationMax then
648 dir = -1
649 end
650 self:playAnimation(spec.rotationPart.turnAnimation, dir, self:getAnimationTime(spec.rotationPart.turnAnimation), true)
651 spec.wasTurnAnimationStopped = false
652 end
653end

onPostLoad

Description
Definition
onPostLoad()
Code
147function Plow:onPostLoad(savegame)
148 if savegame ~= nil and not savegame.resetVehicles then
149 local rotationMax = getXMLBool(savegame.xmlFile, savegame.key..".plow#rotationMax")
150 if rotationMax ~= nil then
151 if self:getIsPlowRotationAllowed() then
152 local plowTurnAnimTime = getXMLFloat(savegame.xmlFile, savegame.key..".plow#turnAnimTime")
153 self:setRotationMax(rotationMax, true, plowTurnAnimTime)
154
155 if self.updateCylinderedInitial ~= nil then
156 self:updateCylinderedInitial(false)
157 end
158 end
159 end
160 end
161end

onPreDetach

Description
Called if vehicle gets detached
Definition
onPreDetach(table attacherVehicle, table implement)
Arguments
tableattacherVehicleattacher vehicle
tableimplementimplement
Code
659function Plow:onPreDetach(attacherVehicle, implement)
660 local spec = self.spec_plow
661
662 spec.limitToField = true
663 if self:getIsAnimationPlaying(spec.rotationPart.turnAnimation) then
664 self:stopAnimation(spec.rotationPart.turnAnimation, true)
665 spec.wasTurnAnimationStopped = true
666 end
667end

onReadStream

Description
Definition
onReadStream()
Code
185function Plow:onReadStream(streamId, connection)
186 local spec = self.spec_plow
187
188 local rotationMax = streamReadBool(streamId)
189 local turnAnimTime
190 if spec.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then
191 turnAnimTime = streamReadFloat32(streamId)
192 end
193
194 self:setRotationMax(rotationMax, true, turnAnimTime)
195
196 if self.updateCylinderedInitial ~= nil then
197 self:updateCylinderedInitial(false)
198 end
199end

onRegisterActionEvents

Description
Definition
onRegisterActionEvents()
Code
559function Plow:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
560 if self.isClient then
561 local spec = self.spec_plow
562 self:clearActionEventsTable(spec.actionEvents)
563
564 if isActiveForInputIgnoreSelection then
565 if spec.rotationPart.turnAnimation ~= nil then
566 local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA, self, Plow.actionEventTurn, false, true, false, true, nil)
567 g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH)
568 g_inputBinding:setActionEventText(actionEventId, g_i18n:getText("action_turnPlow"))
569 end
570
571 local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA3, self, Plow.actionEventLimitToField, false, true, false, true, nil)
572 g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL)
573 end
574 end
575end

onStartAnimation

Description
Definition
onStartAnimation()
Code
693function Plow:onStartAnimation(animName)
694 local spec = self.spec_plow
695 g_soundManager:playSample(spec.samples.turn)
696end

onStartWorkAreaProcessing

Description
Definition
onStartWorkAreaProcessing()
Code
579function Plow:onStartWorkAreaProcessing(dt)
580 local spec = self.spec_plow
581
582 spec.isWorking = false
583
584 local limitToField = spec.limitToField or spec.forceLimitToField
585 local limitGrassDestructionToField = spec.limitToField or spec.forceLimitToField
586 if not g_currentMission:getHasPlayerPermission("createFields", self:getOwner(), nil, true) then
587 limitToField = true
588 limitGrassDestructionToField = true
589 end
590
591 local dx,_,dz = localDirectionToWorld(spec.directionNode, 0, 0, 1)
592 local angle = FSDensityMapUtil.convertToDensityMapAngle(MathUtil.getYRotationFromDirection(dx, dz), g_currentMission.terrainDetailAngleMaxValue)
593
594 spec.workAreaParameters.limitToField = limitToField
595 spec.workAreaParameters.limitGrassDestructionToField = limitGrassDestructionToField
596 spec.workAreaParameters.angle = angle
597 spec.workAreaParameters.lastChangedArea = 0
598 spec.workAreaParameters.lastStatsArea = 0
599 spec.workAreaParameters.lastTotalArea = 0
600end

onUpdate

Description
Definition
onUpdate()
Code
215function Plow:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
216 if self.isClient then
217 local spec = self.spec_plow
218
219 local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA3]
220 if actionEvent ~= nil then
221 if not spec.forceLimitToField and g_currentMission:getHasPlayerPermission("createFields", self:getOwner()) then
222 g_inputBinding:setActionEventActive(actionEvent.actionEventId, true)
223
224 if spec.limitToField then
225 g_inputBinding:setActionEventText(actionEvent.actionEventId, g_i18n:getText("action_allowCreateFields"))
226 else
227 g_inputBinding:setActionEventText(actionEvent.actionEventId, g_i18n:getText("action_limitToFields"))
228 end
229 else
230 g_inputBinding:setActionEventActive(actionEvent.actionEventId, false)
231 end
232 end
233
234 if spec.rotationPart.turnAnimation ~= nil then
235 actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA]
236 if actionEvent ~= nil then
237 g_inputBinding:setActionEventActive(actionEvent.actionEventId, self:getIsPlowRotationAllowed())
238 end
239 end
240 end
241end

onWriteStream

Description
Definition
onWriteStream()
Code
203function Plow:onWriteStream(streamId, connection)
204 local spec = self.spec_plow
205
206 streamWriteBool(streamId, spec.rotationMax)
207 if spec.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then
208 local turnAnimTime = self:getAnimationTime(spec.rotationPart.turnAnimation)
209 streamWriteFloat32(streamId, turnAnimTime)
210 end
211end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
24function Plow.prerequisitesPresent(specializations)
25 return SpecializationUtil.hasSpecialization(WorkArea, specializations)
26end

processPlowArea

Description
Definition
processPlowArea()
Code
245function Plow:processPlowArea(workArea, dt)
246 local spec = self.spec_plow
247
248 local xs,_,zs = getWorldTranslation(workArea.start)
249 local xw,_,zw = getWorldTranslation(workArea.width)
250 local xh,_,zh = getWorldTranslation(workArea.height)
251
252 local params = spec.workAreaParameters
253
254 local changedArea, totalArea = FSDensityMapUtil.updatePlowArea(xs,zs, xw,zw, xh,zh, not params.limitToField, not params.limitGrassDestructionToField, params.angle)
255 params.lastChangedArea = params.lastChangedArea + changedArea
256 params.lastStatsArea = params.lastStatsArea + changedArea
257 params.lastTotalArea = params.lastTotalArea + totalArea
258
259 FSDensityMapUtil.eraseTireTrack(xs,zs, xw,zw, xh,zh)
260
261 spec.isWorking = self:getLastSpeed() > 0.5
262
263 return changedArea, totalArea
264end

registerEventListeners

Description
Definition
registerEventListeners()
Code
58function Plow.registerEventListeners(vehicleType)
59 SpecializationUtil.registerEventListener(vehicleType, "onLoad", Plow)
60 SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", Plow)
61 SpecializationUtil.registerEventListener(vehicleType, "onDelete", Plow)
62 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Plow)
63 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Plow)
64 SpecializationUtil.registerEventListener(vehicleType, "onUpdate", Plow)
65 SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", Plow)
66 SpecializationUtil.registerEventListener(vehicleType, "onStartWorkAreaProcessing", Plow)
67 SpecializationUtil.registerEventListener(vehicleType, "onEndWorkAreaProcessing", Plow)
68 SpecializationUtil.registerEventListener(vehicleType, "onPostAttach", Plow)
69 SpecializationUtil.registerEventListener(vehicleType, "onPreDetach", Plow)
70 SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", Plow)
71 SpecializationUtil.registerEventListener(vehicleType, "onAIImplementTurnProgress", Plow)
72 SpecializationUtil.registerEventListener(vehicleType, "onStartAnimation", Plow)
73 SpecializationUtil.registerEventListener(vehicleType, "onFinishAnimation", Plow)
74end

registerFunctions

Description
Definition
registerFunctions()
Code
30function Plow.registerFunctions(vehicleType)
31 SpecializationUtil.registerFunction(vehicleType, "processPlowArea", Plow.processPlowArea)
32 SpecializationUtil.registerFunction(vehicleType, "setRotationMax", Plow.setRotationMax)
33 SpecializationUtil.registerFunction(vehicleType, "setRotationCenter", Plow.setRotationCenter)
34 SpecializationUtil.registerFunction(vehicleType, "setPlowLimitToField", Plow.setPlowLimitToField)
35 SpecializationUtil.registerFunction(vehicleType, "getIsPlowRotationAllowed", Plow.getIsPlowRotationAllowed)
36end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
40function Plow.registerOverwrittenFunctions(vehicleType)
41 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsFoldAllowed", Plow.getIsFoldAllowed)
42 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsFoldMiddleAllowed", Plow.getIsFoldMiddleAllowed)
43 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDirtMultiplier", Plow.getDirtMultiplier)
44 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getWearMultiplier", Plow.getWearMultiplier)
45 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSpeedRotatingPartFromXML", Plow.loadSpeedRotatingPartFromXML)
46 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSpeedRotatingPartActive", Plow.getIsSpeedRotatingPartActive)
47 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getSpeedRotatingPartDirection", Plow.getSpeedRotatingPartDirection)
48 SpecializationUtil.registerOverwrittenFunction(vehicleType, "doCheckSpeedLimit", Plow.doCheckSpeedLimit)
49 SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadWorkAreaFromXML", Plow.loadWorkAreaFromXML)
50 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsWorkAreaActive", Plow.getIsWorkAreaActive)
51 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanAIImplementContinueWork", Plow.getCanAIImplementContinueWork)
52 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAIInvertMarkersOnTurn", Plow.getAIInvertMarkersOnTurn)
53 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", Plow.getCanBeSelected)
54end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
174function Plow:saveToXMLFile(xmlFile, key, usedModNames)
175 local spec = self.spec_plow
176 setXMLBool(xmlFile, key.."#rotationMax", spec.rotationMax)
177 if spec.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then
178 local turnAnimTime = self:getAnimationTime(spec.rotationPart.turnAnimation)
179 setXMLFloat(xmlFile, key.."#turnAnimTime", turnAnimTime)
180 end
181end

setPlowLimitToField

Description
Definition
setPlowLimitToField()
Code
317function Plow:setPlowLimitToField(plowLimitToField, noEventSend)
318 local spec = self.spec_plow
319
320 if spec.limitToField ~= plowLimitToField then
321 if noEventSend == nil or noEventSend == false then
322 if g_server ~= nil then
323 g_server:broadcastEvent(PlowLimitToFieldEvent:new(self, plowLimitToField), nil, nil, self)
324 else
325 g_client:getServerConnection():sendEvent(PlowLimitToFieldEvent:new(self, plowLimitToField))
326 end
327 end
328 spec.limitToField = plowLimitToField
329
330 local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA3]
331 if actionEvent ~= nil then
332 local text
333 if spec.limitToField then
334 text = g_i18n:getText("action_allowCreateFields")
335 else
336 text = g_i18n:getText("action_limitToFields")
337 end
338 g_inputBinding:setActionEventText(actionEvent.actionEventId, text)
339 end
340 end
341end

setRotationCenter

Description
Definition
setRotationCenter()
Code
300function Plow:setRotationCenter()
301 local spec = self.spec_plow
302
303 if spec.rotationPart.turnAnimation ~= nil then
304 self:setAnimationStopTime(spec.rotationPart.turnAnimation, spec.ai.centerPosition)
305
306 local animTime = self:getAnimationTime(spec.rotationPart.turnAnimation)
307 if animTime < spec.ai.centerPosition then
308 self:playAnimation(spec.rotationPart.turnAnimation, 1, animTime, true)
309 elseif animTime > spec.ai.centerPosition then
310 self:playAnimation(spec.rotationPart.turnAnimation, -1, animTime, true)
311 end
312 end
313end

setRotationMax

Description
Definition
setRotationMax()
Code
268function Plow:setRotationMax(rotationMax, noEventSend, turnAnimationTime)
269 if noEventSend == nil or noEventSend == false then
270 if g_server ~= nil then
271 g_server:broadcastEvent(PlowRotationEvent:new(self, rotationMax), nil, nil, self)
272 else
273 g_client:getServerConnection():sendEvent(PlowRotationEvent:new(self, rotationMax))
274 end
275 end
276 local spec = self.spec_plow
277
278 spec.rotationMax = rotationMax
279
280 if spec.rotationPart.turnAnimation ~= nil then
281 if turnAnimationTime == nil then
282 local animTime = self:getAnimationTime(spec.rotationPart.turnAnimation)
283 if spec.rotationMax then
284 if animTime < 1 then
285 self:playAnimation(spec.rotationPart.turnAnimation, 1, animTime, true)
286 end
287 else
288 if animTime > 0 then
289 self:playAnimation(spec.rotationPart.turnAnimation, -1, animTime, true)
290 end
291 end
292 else
293 self:setAnimationTime(spec.rotationPart.turnAnimation, turnAnimationTime, true)
294 end
295 end
296end