Script v1.4.4.0
- Handtools
- Events
- Objects
- Placeables
- Triggers
- Utils
- Vehicles
- Specializations
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BuiltInCutterTrailer
- BunkerSiloCompacter
- Combine
- ConveyorBelt
- Cover
- CrabSteering
- Crawler
- Cultivator
- Cutter
- Cylindered
- Drivable
- DynamicMountAttacher
- Fillable
- FillActivatable
- FillVolume
- Foldable
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- FuelTrailer
- Honk
- HookLiftContainer
- HookLiftTrailer
- Leveler
- Lights
- LivestockTrailer
- ManureBarrel
- ManureSpreader
- MixerWagon
- Motorized
- Mountable
- Mower
- NonTabbable
- Overloading
- Pickup
- Pipe
- Plough
- PowerConsumer
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- RidgeMarker
- Roller
- Ropes
- RotorSpreader
- SemiTrailerFront
- Shovel
- SowingMachine
- SpeedRotatingParts
- Sprayer
- Steerable
- StrawBlower
- StumpCutter
- Tedder
- TensionBelts
- Trailer
- TreePlanter
- TreePlanterActivatable
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Weeder
- WheelRotations
- Windrower
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkParticles
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
Plough
DescriptionThis is the specialization for ploughsFunctions
- initSpecialization
- prerequisitesPresent
- preLoad
- load
- postLoad
- delete
- readStream
- writeStream
- readUpdateStream
- writeUpdateStream
- getSaveAttributesAndNodes
- update
- updateTick
- draw
- onAttach
- onDetach
- onDeactivate
- onDeactivateSounds
- onAiRotateCenter
- onAiRotateLeft
- onAiRotateRight
- onAiTurnOn
- getAiInvertsMarkerOnTurn
- getIsAIReadyForWork
- setRotationMax
- setPloughLimitToField
- getIsPloughRotationAllowed
- getIsFoldAllowed
- getIsFoldMiddleAllowed
- getDirtMultiplier
- loadSpeedRotatingPartFromXML
- getIsSpeedRotatingPartActive
- getSpeedRotatingPartDirection
- doCheckSpeedLimit
- loadWorkAreaFromXML
- getDefaultSpeedLimit
- processPloughAreas
initSpecialization
DescriptionCalled on specialization initializingDefinition
initSpecialization()Code
18 | function Plough.initSpecialization() |
19 | WorkArea.registerAreaType("plough"); |
20 | end |
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
26 | function Plough.prerequisitesPresent(specializations) |
27 | return SpecializationUtil.hasSpecialization(WorkArea, specializations); |
28 | end |
preLoad
DescriptionCalled before loadingDefinition
preLoad(table savegame)Arguments
table | savegame | savegame |
33 | function Plough:preLoad(savegame) |
34 | self.loadSpeedRotatingPartFromXML = Utils.overwrittenFunction(self.loadSpeedRotatingPartFromXML, Plough.loadSpeedRotatingPartFromXML); |
35 | self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, Plough.loadWorkAreaFromXML); |
36 | end |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
41 | function Plough:load(savegame) |
42 | self.setRotationMax = SpecializationUtil.callSpecializationsFunction("setRotationMax"); |
43 | self.setPloughLimitToField = Plough.setPloughLimitToField; |
44 | self.getIsPloughRotationAllowed = Plough.getIsPloughRotationAllowed; |
45 | self.getIsFoldAllowed = Utils.overwrittenFunction(self.getIsFoldAllowed, Plough.getIsFoldAllowed); |
46 | self.getIsFoldMiddleAllowed = Utils.overwrittenFunction(self.getIsFoldMiddleAllowed, Plough.getIsFoldMiddleAllowed); |
47 | self.getDirtMultiplier = Utils.overwrittenFunction(self.getDirtMultiplier, Plough.getDirtMultiplier); |
48 | self.getIsSpeedRotatingPartActive = Utils.overwrittenFunction(self.getIsSpeedRotatingPartActive, Plough.getIsSpeedRotatingPartActive); |
49 | self.getSpeedRotatingPartDirection = Utils.overwrittenFunction(self.getSpeedRotatingPartDirection, Plough.getSpeedRotatingPartDirection); |
50 | self.doCheckSpeedLimit = Utils.overwrittenFunction(self.doCheckSpeedLimit, Plough.doCheckSpeedLimit); |
51 | |
52 | self.processPloughAreas = Plough.processPloughAreas; |
53 | |
54 | if next(self.groundReferenceNodes) == nil then |
55 | print("Warning: No ground reference nodes in "..self.configFileName); |
56 | end |
57 | |
58 | self.rotationPart = {}; |
59 | self.rotationPart.turnAnimation = getXMLString(self.xmlFile, "vehicle.rotationPart#turnAnimationName"); |
60 | self.rotationPart.foldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.rotationPart#foldMinLimit"), 0); |
61 | self.rotationPart.foldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.rotationPart#foldMaxLimit"), 1); |
62 | self.rotationPart.limitFoldRotationMax = getXMLBool(self.xmlFile, "vehicle.rotationPart#limitFoldRotationMax"); |
63 | self.rotationPart.foldRotationMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.rotationPart#foldRotationMinLimit"), 0); |
64 | self.rotationPart.foldRotationMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.rotationPart#foldRotationMaxLimit"), 1); |
65 | self.rotationPart.rotationFoldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.rotationPart#rotationFoldMinLimit"), 0); |
66 | self.rotationPart.rotationFoldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.rotationPart#rotationFoldMaxLimit"), 1); |
67 | self.rotationPart.rotationAllowedIfLowered = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.rotationPart#rotationAllowedIfLowered"), true); |
68 | |
69 | self.ploughDirectionNode = Utils.getNoNil(Utils.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.ploughDirectionNode#index")), self.components[1].node); |
70 | |
71 | if self.isClient then |
72 | self.samplePloughTurn = SoundUtil.loadSample(self.xmlFile, {}, "vehicle.ploughTurnSound", nil, self.baseDirectory); |
73 | self.samplePlough = SoundUtil.loadSample(self.xmlFile, {}, "vehicle.ploughSound", nil, self.baseDirectory); |
74 | end |
75 | |
76 | table.insert(self.terrainDetailRequiredValueRanges, {g_currentMission.cultivatorValue, g_currentMission.cultivatorValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels}); |
77 | table.insert(self.terrainDetailRequiredValueRanges, {g_currentMission.sowingValue, g_currentMission.sowingValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels}); |
78 | table.insert(self.terrainDetailRequiredValueRanges, {g_currentMission.sowingWidthValue, g_currentMission.sowingWidthValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels}); |
79 | table.insert(self.terrainDetailRequiredValueRanges, {g_currentMission.grassValue, g_currentMission.grassValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels}); |
80 | |
81 | self.rotateLeftToMax = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.rotateLeftToMax#value"), true); |
82 | |
83 | self.aiPlough = {}; |
84 | self.aiPlough.animTimeCenterPosition = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.animTimeCenterPosition#value"), 0.5); |
85 | self.aiPlough.rotateEarly = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.aiPlough#rotateEarly"), true); |
86 | |
87 | self.onlyActiveWhenLowered = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.onlyActiveWhenLowered#value"), true); |
88 | |
89 | self.ploughHasGroundContact = false; |
90 | self.rotationMax = false; |
91 | self.ploughContactReportsActive = false; |
92 | self.startActivationTimeout = 2000; |
93 | self.startActivationTime = 0; |
94 | self.lastPloughArea = 0; |
95 | |
96 | self.ploughLimitToField = true; |
97 | self.forcePloughLimitToField = false; |
98 | |
99 | self.showFieldNotOwnedWarning = false; |
100 | self.isPloughSpeedLimitActive = false; |
101 | self.wasTurnAnimationStopped = false; |
102 | |
103 | self.isPloughLowered = false; |
104 | |
105 | self.ploughGroundContactFlag = self:getNextDirtyFlag(); |
106 | end |
postLoad
DescriptionCalled after loadingDefinition
postLoad(table savegame)Arguments
table | savegame | savegame |
111 | function Plough:postLoad(savegame) |
112 | if savegame ~= nil and not savegame.resetVehicles then |
113 | local rotationMax = getXMLBool(savegame.xmlFile, savegame.key.."#ploughRotationMax"); |
114 | if rotationMax ~= nil then |
115 | if self:getIsPloughRotationAllowed() then |
116 | self:setRotationMax(rotationMax, true); |
117 | if self.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then |
118 | local turnAnimTime = getXMLFloat(savegame.xmlFile, savegame.key.."#ploughTurnAnimTime"); |
119 | if turnAnimTime ~= nil then |
120 | self:setAnimationTime(self.rotationPart.turnAnimation, turnAnimTime); |
121 | |
122 | if self.updateCylinderedInitial ~= nil then |
123 | self:updateCylinderedInitial(false); |
124 | end |
125 | end |
126 | end |
127 | end |
128 | end |
129 | end |
130 | end |
delete
DescriptionCalled on deletingDefinition
delete()Code
134 | function Plough:delete() |
135 | if self.isClient then |
136 | SoundUtil.deleteSample(self.samplePlough); |
137 | SoundUtil.deleteSample(self.samplePloughTurn); |
138 | end |
139 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
145 | function Plough:readStream(streamId, connection) |
146 | local rotationMax = streamReadBool(streamId); |
147 | local rotationAllowed = streamReadBool(streamId); |
148 | if rotationAllowed then |
149 | self:setRotationMax(rotationMax, true); |
150 | if self.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then |
151 | local turnAnimTime = streamReadFloat32(streamId); |
152 | self:setAnimationTime(self.rotationPart.turnAnimation, turnAnimTime); |
153 | |
154 | if self.updateCylinderedInitial ~= nil then |
155 | self:updateCylinderedInitial(false); |
156 | end |
157 | end |
158 | else |
159 | self.rotationMax = rotationMax; |
160 | end |
161 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
167 | function Plough:writeStream(streamId, connection) |
168 | streamWriteBool(streamId, self.rotationMax); |
169 | if streamWriteBool(streamId, self:getIsPloughRotationAllowed()) then |
170 | if self.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then |
171 | local turnAnimTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
172 | streamWriteFloat32(streamId, turnAnimTime); |
173 | end |
174 | end |
175 | end |
readUpdateStream
DescriptionCalled on on updateDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
182 | function Plough:readUpdateStream(streamId, timestamp, connection) |
183 | if connection:getIsServer() then |
184 | self.ploughHasGroundContact = streamReadBool(streamId); |
185 | self.showFieldNotOwnedWarning = streamReadBool(streamId); |
186 | end |
187 | end |
writeUpdateStream
DescriptionCalled on on updateDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
194 | function Plough:writeUpdateStream(streamId, connection, dirtyMask) |
195 | if not connection:getIsServer() then |
196 | streamWriteBool(streamId, self.ploughHasGroundContact); |
197 | streamWriteBool(streamId, self.showFieldNotOwnedWarning); |
198 | end |
199 | end |
getSaveAttributesAndNodes
DescriptionReturns attributes and nodes to saveDefinition
getSaveAttributesAndNodes(table nodeIdent)Arguments
table | nodeIdent | node ident |
string | attributes | attributes |
string | nodes | nodes |
206 | function Plough:getSaveAttributesAndNodes(nodeIdent) |
207 | local attributes = 'ploughRotationMax="'..tostring(self.rotationMax)..'"'; |
208 | if self.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then |
209 | local turnAnimTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
210 | attributes = attributes..' ploughTurnAnimTime="'..turnAnimTime..'"'; |
211 | end |
212 | local nodes = ""; |
213 | return attributes, nodes; |
214 | end |
update
DescriptionCalled on updateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
225 | function Plough:update(dt) |
226 | if self:getIsActiveForInput() then |
227 | if self.rotationPart.turnAnimation ~= nil then |
228 | if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA) then |
229 | if self:getIsPloughRotationAllowed() then |
230 | self:setRotationMax(not self.rotationMax); |
231 | end |
232 | end |
233 | end |
234 | if not self.forcePloughLimitToField then |
235 | if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA3) then |
236 | self:setPloughLimitToField(not self.ploughLimitToField); |
237 | end |
238 | end |
239 | end |
240 | end |
updateTick
DescriptionCalled on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
245 | function Plough:updateTick(dt) |
246 | self.isPloughSpeedLimitActive = false; |
247 | if self:getIsActive() then |
248 | self.lastPloughArea = 0; |
249 | local showFieldNotOwnedWarning = false; |
250 | |
251 | if self.isServer then |
252 | local hasGroundContact = self:getIsTypedWorkAreaActive(WorkArea.AREATYPE_PLOUGH); |
253 | if self.ploughHasGroundContact ~= hasGroundContact then |
254 | self:raiseDirtyFlags(self.ploughGroundContactFlag); |
255 | end |
256 | self.ploughHasGroundContact = hasGroundContact; |
257 | end |
258 | local hasGroundContact = self.ploughHasGroundContact; |
259 | |
260 | if hasGroundContact then |
261 | if self.startActivationTime <= g_currentMission.time then |
262 | self.isPloughSpeedLimitActive = true; |
263 | if not self.onlyActiveWhenLowered or self:isLowered(false) then |
264 | local workAreas, showWarning, _ = self:getTypedNetworkAreas(WorkArea.AREATYPE_PLOUGH, true); |
265 | if self.isServer then |
266 | showFieldNotOwnedWarning = showWarning; |
267 | |
268 | if (table.getn(workAreas) > 0) then |
269 | local limitToField = self.ploughLimitToField or self.forcePloughLimitToField; |
270 | local limitGrassDestructionToField = self.ploughLimitToField or self.forcePloughLimitToField; |
271 | if not g_currentMission:getHasPermission("createFields", self:getOwner()) or g_currentMission.fieldJobManager:isFieldJobActive() then |
272 | limitToField = true; |
273 | limitGrassDestructionToField = true; |
274 | end |
275 | |
276 | local dx,_,dz = localDirectionToWorld(self.ploughDirectionNode, 0, 0, 1); |
277 | local angle = Utils.convertToDensityMapAngle(Utils.getYRotationFromDirection(dx, dz), g_currentMission.terrainDetailAngleMaxValue); |
278 | |
279 | local realArea = self:processPloughAreas(workAreas, limitToField, limitGrassDestructionToField, angle); |
280 | |
281 | self.lastPloughArea = Utils.areaToHa(realArea, g_currentMission:getFruitPixelsToSqm()); -- 4096px are mapped to 2048m |
282 | g_currentMission.missionStats:updateStats("workedHectares", self.lastPloughArea); |
283 | end |
284 | end |
285 | |
286 | -- remove tireTracks |
287 | for _, workArea in pairs(workAreas) do |
288 | Utils.eraseTireTrack(workArea[1], workArea[2], workArea[3], workArea[4], workArea[5], workArea[6]) |
289 | end |
290 | end |
291 | g_currentMission.missionStats:updateStats("workedTime", dt/(1000*60)); |
292 | end |
293 | |
294 | if self.isClient and self:getLastSpeed() > 3 and self:getIsActiveForSound() then |
295 | SoundUtil.playSample(self.samplePlough, 0, 0, nil); |
296 | else |
297 | SoundUtil.stopSample(self.samplePlough); |
298 | end |
299 | else |
300 | if self.isClient then |
301 | SoundUtil.stopSample(self.samplePlough); |
302 | end |
303 | end |
304 | |
305 | if self.rotationPart.turnAnimation ~= nil then |
306 | if self.isClient then |
307 | if self:getIsAnimationPlaying(self.rotationPart.turnAnimation) and self:getIsActiveForSound() then |
308 | SoundUtil.playSample(self.samplePloughTurn, 0, 0, nil); |
309 | else |
310 | SoundUtil.stopSample(self.samplePloughTurn); |
311 | end |
312 | end |
313 | end |
314 | |
315 | if self.isServer then |
316 | if showFieldNotOwnedWarning ~= self.showFieldNotOwnedWarning then |
317 | self.showFieldNotOwnedWarning = showFieldNotOwnedWarning; |
318 | self:raiseDirtyFlags(self.ploughGroundContactFlag); |
319 | end |
320 | end |
321 | end |
322 | end |
draw
DescriptionCalled on drawDefinition
draw()Code
326 | function Plough:draw() |
327 | if self:getIsActiveForInput(true) then |
328 | if self.rotationPart.turnAnimation ~= nil then |
329 | if self:getIsPloughRotationAllowed() then |
330 | g_currentMission:addHelpButtonText(g_i18n:getText("action_turnPlough"), InputBinding.IMPLEMENT_EXTRA, nil, GS_PRIO_HIGH); |
331 | end |
332 | end |
333 | |
334 | if g_currentMission:getHasPermission("createFields", self:getOwner()) and not g_currentMission.fieldJobManager:isFieldJobActive() then |
335 | if not self.forcePloughLimitToField then |
336 | if self.ploughLimitToField then |
337 | g_currentMission:addHelpButtonText(g_i18n:getText("action_allowCreateFields"), InputBinding.IMPLEMENT_EXTRA3, nil, GS_PRIO_NORMAL); |
338 | else |
339 | g_currentMission:addHelpButtonText(g_i18n:getText("action_limitToFields"), InputBinding.IMPLEMENT_EXTRA3, nil, GS_PRIO_NORMAL); |
340 | end |
341 | end |
342 | end |
343 | end |
344 | |
345 | if self.showFieldNotOwnedWarning then |
346 | g_currentMission:showBlinkingWarning(g_i18n:getText("warning_youDontOwnThisField")); |
347 | end |
348 | end |
onAttach
DescriptionCalled if vehicle gets attachedDefinition
onAttach(table attacherVehicle)Arguments
table | attacherVehicle | attacher vehicle |
353 | function Plough:onAttach(attacherVehicle) |
354 | Plough.onActivate(self); |
355 | self.startActivationTime = g_currentMission.time + self.startActivationTimeout; |
356 | if self.wasTurnAnimationStopped then |
357 | local dir = 1; |
358 | if not self.rotationMax then |
359 | dir = -1; |
360 | end |
361 | self:playAnimation(self.rotationPart.turnAnimation, dir, self:getAnimationTime(self.rotationPart.turnAnimation), true); |
362 | self.wasTurnAnimationStopped = false; |
363 | end |
364 | end |
onDetach
DescriptionCalled if vehicle gets detachedDefinition
onDetach()Code
368 | function Plough:onDetach() |
369 | self.ploughLimitToField = true; |
370 | if self:getIsAnimationPlaying(self.rotationPart.turnAnimation) then |
371 | self:stopAnimation(self.rotationPart.turnAnimation, true); |
372 | self.wasTurnAnimationStopped = true; |
373 | end |
374 | end |
onDeactivate
DescriptionCalled on deactivateDefinition
onDeactivate()Code
381 | function Plough:onDeactivate() |
382 | self.showFieldNotOwnedWarning = false; |
383 | end |
onDeactivateSounds
DescriptionCalled on deactivating soundsDefinition
onDeactivateSounds()Code
387 | function Plough:onDeactivateSounds() |
388 | if self.isClient then |
389 | SoundUtil.stopSample(self.samplePlough, true); |
390 | SoundUtil.stopSample(self.samplePloughTurn, true); |
391 | end |
392 | end |
onAiRotateCenter
DescriptionCalled on ai rotate centerDefinition
onAiRotateCenter(boolean force)Arguments
boolean | force | force action |
397 | function Plough:onAiRotateCenter(force) |
398 | if self:getIsPloughRotationAllowed() or force then |
399 | if self.rotationPart.turnAnimation ~= nil then |
400 | |
401 | self:setAnimationStopTime(self.rotationPart.turnAnimation, self.aiPlough.animTimeCenterPosition); |
402 | |
403 | local animTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
404 | if animTime < self.aiPlough.animTimeCenterPosition then |
405 | self:playAnimation(self.rotationPart.turnAnimation, 1, animTime, false); |
406 | else |
407 | self:playAnimation(self.rotationPart.turnAnimation, -1, animTime, false); |
408 | end |
409 | end |
410 | end |
411 | end |
onAiRotateLeft
DescriptionCalled on ai rotate leftDefinition
onAiRotateLeft(boolean force)Arguments
boolean | force | force action |
416 | function Plough:onAiRotateLeft(force) |
417 | if self:getIsPloughRotationAllowed() or force then |
418 | self:setRotationMax(self.rotateLeftToMax, true); |
419 | end |
420 | end |
onAiRotateRight
DescriptionCalled on ai rotate rightDefinition
onAiRotateRight(boolean force)Arguments
boolean | force | force action |
425 | function Plough:onAiRotateRight(force) |
426 | if self:getIsPloughRotationAllowed() or force then |
427 | self:setRotationMax(not self.rotateLeftToMax, true); |
428 | end |
429 | end |
onAiTurnOn
DescriptionCalled on ai turn onDefinition
onAiTurnOn()Code
433 | function Plough:onAiTurnOn() |
434 | self.ploughLimitToField = true; |
435 | end |
getAiInvertsMarkerOnTurn
DescriptionReturns if ai inverts markers on turnDefinition
getAiInvertsMarkerOnTurn(boolean turnLeft)Arguments
boolean | turnLeft | turn left |
443 | function Plough:getAiInvertsMarkerOnTurn(turnLeft) |
444 | if self.rotationPart.turnAnimation ~= nil then |
445 | if turnLeft then |
446 | return self.rotationMax ~= self.rotateLeftToMax; |
447 | else |
448 | return self.rotationMax == self.rotateLeftToMax; |
449 | end |
450 | else |
451 | return false; |
452 | end |
453 | end |
getIsAIReadyForWork
DescriptionReturns true if vehicle is ready for ai workDefinition
getIsAIReadyForWork()Return Values
boolean | isReady | is ready for ai work |
458 | function Plough:getIsAIReadyForWork() |
459 | if self.rotationPart.turnAnimation ~= nil then |
460 | local animTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
461 | if animTime == 0 or animTime == 1 then |
462 | return true; |
463 | else |
464 | if not self:getIsAnimationPlaying(self.rotationPart.turnAnimation) then |
465 | self:setRotationMax(self.rotationMax); |
466 | end |
467 | end |
468 | else |
469 | return true; |
470 | end |
471 | end |
setRotationMax
DescriptionSet rotation of ploughDefinition
setRotationMax(boolean rotationMax)Arguments
boolean | rotationMax | rotate to max |
476 | function Plough:setRotationMax(rotationMax, noEventSend) |
477 | if noEventSend == nil or noEventSend == false then |
478 | if g_server ~= nil then |
479 | g_server:broadcastEvent(PloughRotationEvent:new(self, rotationMax), nil, nil, self); |
480 | else |
481 | g_client:getServerConnection():sendEvent(PloughRotationEvent:new(self, rotationMax)); |
482 | end |
483 | end |
484 | self.rotationMax = rotationMax; |
485 | |
486 | if self.rotationPart.turnAnimation ~= nil then |
487 | local animTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
488 | if self.rotationMax then |
489 | self:playAnimation(self.rotationPart.turnAnimation, 1, animTime, true); |
490 | else |
491 | self:playAnimation(self.rotationPart.turnAnimation, -1, animTime, true); |
492 | end |
493 | end |
494 | end |
setPloughLimitToField
DescriptionSet plough is limited to fieldDefinition
setPloughLimitToField(boolean ploughLimitToField, boolean noEventSend)Arguments
boolean | ploughLimitToField | new plough limited to field state |
boolean | noEventSend | no event send |
500 | function Plough:setPloughLimitToField(ploughLimitToField, noEventSend) |
501 | if self.ploughLimitToField ~= ploughLimitToField then |
502 | if noEventSend == nil or noEventSend == false then |
503 | if g_server ~= nil then |
504 | g_server:broadcastEvent(PloughLimitToFieldEvent:new(self, ploughLimitToField), nil, nil, self); |
505 | else |
506 | g_client:getServerConnection():sendEvent(PloughLimitToFieldEvent:new(self, ploughLimitToField)); |
507 | end |
508 | end |
509 | self.ploughLimitToField = ploughLimitToField; |
510 | end |
511 | end |
getIsPloughRotationAllowed
DescriptionReturns if plough rotation is allowedDefinition
getIsPloughRotationAllowed()Return Values
boolean | isAllowed | plough rotation is allowed |
516 | function Plough:getIsPloughRotationAllowed() |
517 | --if self.isPloughLowered then |
518 | -- return false; |
519 | --end |
520 | local foldAnimTime = self.foldAnimTime; |
521 | if foldAnimTime ~= nil and (foldAnimTime > self.rotationPart.rotationFoldMaxLimit or foldAnimTime < self.rotationPart.rotationFoldMinLimit) then |
522 | return false; |
523 | end |
524 | if not self.rotationPart.rotationAllowedIfLowered and self:isLowered() then |
525 | return false |
526 | end |
527 | |
528 | if superFunc ~= nil then |
529 | return superFunc(self); |
530 | end |
531 | return true; |
532 | end |
getIsFoldAllowed
DescriptionReturns if fold is allowedDefinition
getIsFoldAllowed(boolean onAiTurnOn)Arguments
boolean | onAiTurnOn | called on ai turn on |
boolean | allowsFold | allows folding |
538 | function Plough:getIsFoldAllowed(superFunc, onAiTurnOn) |
539 | if self.rotationPart.limitFoldRotationMax ~= nil and self.rotationPart.limitFoldRotationMax == self.rotationMax then |
540 | return false; |
541 | end |
542 | if self.rotationPart.turnAnimation ~= nil and self.getAnimationTime ~= nil then |
543 | local rotationTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
544 | if rotationTime > self.rotationPart.foldRotationMaxLimit or rotationTime < self.rotationPart.foldRotationMinLimit then |
545 | return false; |
546 | end |
547 | end |
548 | if superFunc ~= nil then |
549 | return superFunc(self, onAiTurnOn); |
550 | end |
551 | return true; |
552 | end |
getIsFoldMiddleAllowed
DescriptionReturns if fold middle is allowedDefinition
getIsFoldMiddleAllowed()Return Values
boolean | allowsFoldMiddle | allows folding to middle position |
557 | function Plough:getIsFoldMiddleAllowed(superFunc) |
558 | if self.rotationPart.limitFoldRotationMax ~= nil and self.rotationPart.limitFoldRotationMax == self.rotationMax then |
559 | return false; |
560 | end |
561 | if self.rotationPart.turnAnimation ~= nil and self.getAnimationTime ~= nil then |
562 | local rotationTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
563 | if rotationTime > self.rotationPart.foldRotationMaxLimit or rotationTime < self.rotationPart.foldRotationMinLimit then |
564 | return false; |
565 | end |
566 | end |
567 | if superFunc ~= nil then |
568 | return superFunc(self); |
569 | end |
570 | return true; |
571 | end |
getDirtMultiplier
DescriptionReturns current dirt multiplierDefinition
getDirtMultiplier()Return Values
float | dirtMultiplier | current dirt multiplier |
576 | function Plough:getDirtMultiplier(superFunc) |
577 | local multiplier = 0; |
578 | if superFunc ~= nil then |
579 | multiplier = multiplier + superFunc(self); |
580 | end |
581 | |
582 | if self.ploughHasGroundContact then |
583 | multiplier = multiplier + self.workMultiplier * self:getLastSpeed() / self.speedLimit; |
584 | end |
585 | |
586 | return multiplier; |
587 | end |
loadSpeedRotatingPartFromXML
DescriptionLoads speed rotating parts from xmlDefinition
loadSpeedRotatingPartFromXML(table speedRotatingPart, integer xmlFile, string key)Arguments
table | speedRotatingPart | speedRotatingPart |
integer | xmlFile | id of xml object |
string | key | key |
boolean | success | success |
595 | function Plough:loadSpeedRotatingPartFromXML(superFunc, speedRotatingPart, xmlFile, key) |
596 | if superFunc ~= nil then |
597 | if not superFunc(self, speedRotatingPart, xmlFile, key) then |
598 | return false; |
599 | end |
600 | end |
601 | |
602 | speedRotatingPart.disableOnTurn = Utils.getNoNil(getXMLBool(xmlFile, key .. "#disableOnTurn"), true); |
603 | speedRotatingPart.turnAnimLimit = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#turnAnimLimit"), 0); |
604 | speedRotatingPart.turnAnimLimitSide = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#turnAnimLimitSide"), 0); |
605 | speedRotatingPart.invertDirectionOnRotation = Utils.getNoNil(getXMLBool(xmlFile, key .. "#invertDirectionOnRotation"), true); |
606 | |
607 | return true; |
608 | end |
getIsSpeedRotatingPartActive
DescriptionReturns true if speed rotating part is activeDefinition
getIsSpeedRotatingPartActive(table speedRotatingPart)Arguments
table | speedRotatingPart | speedRotatingPart |
boolean | isActive | speed rotating part is active |
614 | function Plough:getIsSpeedRotatingPartActive(superFunc, speedRotatingPart) |
615 | if self.rotationPart.turnAnimation ~= nil and speedRotatingPart.disableOnTurn then |
616 | local turnAnimTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
617 | if turnAnimTime ~= nil then |
618 | local enabled = true; |
619 | if speedRotatingPart.turnAnimLimitSide < 0 then |
620 | enabled = (turnAnimTime <= speedRotatingPart.turnAnimLimit); |
621 | elseif speedRotatingPart.turnAnimLimitSide > 0 then |
622 | enabled = (1-turnAnimTime <= speedRotatingPart.turnAnimLimit); |
623 | else |
624 | enabled = (turnAnimTime <= speedRotatingPart.turnAnimLimit or 1-turnAnimTime <= speedRotatingPart.turnAnimLimit); |
625 | end |
626 | if not enabled then |
627 | return false; |
628 | end |
629 | end |
630 | end |
631 | |
632 | if superFunc ~= nil then |
633 | return superFunc(self, speedRotatingPart); |
634 | end |
635 | return true; |
636 | end |
getSpeedRotatingPartDirection
DescriptionReturn direction of speed rotating partDefinition
getSpeedRotatingPartDirection(table speedRotatingPart)Arguments
table | speedRotatingPart | speed rotating part |
integer | direction | direction |
642 | function Plough:getSpeedRotatingPartDirection(superFunc, speedRotatingPart) |
643 | if self.rotationPart.turnAnimation ~= nil then |
644 | local turnAnimTime = self:getAnimationTime(self.rotationPart.turnAnimation); |
645 | if turnAnimTime > 0.5 and speedRotatingPart.invertDirectionOnRotation then |
646 | return -1; |
647 | end |
648 | end |
649 | |
650 | if superFunc ~= nil then |
651 | return superFunc(self, speedRotatingPart); |
652 | end |
653 | return 1; |
654 | end |
doCheckSpeedLimit
DescriptionReturns if speed limit should be checkedDefinition
doCheckSpeedLimit()Return Values
boolean | checkSpeedlimit | check speed limit |
659 | function Plough:doCheckSpeedLimit(superFunc) |
660 | local parent = false; |
661 | if superFunc ~= nil then |
662 | parent = superFunc(self); |
663 | end |
664 | |
665 | return parent or self.isPloughSpeedLimitActive; |
666 | end |
loadWorkAreaFromXML
DescriptionLoads work areas from xmlDefinition
loadWorkAreaFromXML(table workArea, integer xmlFile, string key)Arguments
table | workArea | workArea |
integer | xmlFile | id of xml object |
string | key | key |
boolean | success | success |
674 | function Plough:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
675 | local retValue = true; |
676 | if superFunc ~= nil then |
677 | retValue = superFunc(self, workArea, xmlFile, key) |
678 | end |
679 | |
680 | if workArea.type == WorkArea.AREATYPE_DEFAULT then |
681 | workArea.type = WorkArea.AREATYPE_PLOUGH; |
682 | end |
683 | |
684 | return retValue; |
685 | end |
getDefaultSpeedLimit
DescriptionReturns default speed limitDefinition
getDefaultSpeedLimit()Return Values
float | speedLimit | speed limit |
690 | function Plough.getDefaultSpeedLimit() |
691 | return 15; |
692 | end |
processPloughAreas
DescriptionProcess plough areasDefinition
processPloughAreas(table workAreas, boolean limitToField, boolean limitGrassDestructionToField, float angle)Arguments
table | workAreas | work areas to process |
boolean | limitToField | is limited to field |
boolean | limitGrassDestructionToField | is grass destruction is limited to field |
float | angle | current angle |
float | areaSum | sum of worked area |
701 | function Plough:processPloughAreas(workAreas, limitToField, limitGrassDestructionToField, angle) |
702 | local areaSum = 0; |
703 | for _, area in pairs(workAreas) do |
704 | areaSum = areaSum + Utils.updatePloughArea(area[1], area[2], area[3], area[4], area[5], area[6], not limitToField, not limitGrassDestructionToField, angle); |
705 | end; |
706 | return areaSum; |
707 | end; |