LUADOC - Farming Simulator 17

Printable Version

Script v1.4.4.0

Engine v7.0.0.2

Foundation Reference

Plough

Description
This is the specialization for ploughs
Functions

initSpecialization

Description
Called on specialization initializing
Definition
initSpecialization()
Code
18function Plough.initSpecialization()
19 WorkArea.registerAreaType("plough");
20end

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
26function Plough.prerequisitesPresent(specializations)
27 return SpecializationUtil.hasSpecialization(WorkArea, specializations);
28end

preLoad

Description
Called before loading
Definition
preLoad(table savegame)
Arguments
tablesavegamesavegame
Code
33function Plough:preLoad(savegame)
34 self.loadSpeedRotatingPartFromXML = Utils.overwrittenFunction(self.loadSpeedRotatingPartFromXML, Plough.loadSpeedRotatingPartFromXML);
35 self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, Plough.loadWorkAreaFromXML);
36end

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
41function 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();
106end

postLoad

Description
Called after loading
Definition
postLoad(table savegame)
Arguments
tablesavegamesavegame
Code
111function 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
130end

delete

Description
Called on deleting
Definition
delete()
Code
134function Plough:delete()
135 if self.isClient then
136 SoundUtil.deleteSample(self.samplePlough);
137 SoundUtil.deleteSample(self.samplePloughTurn);
138 end
139end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
145function 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
161end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
167function 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
175end

readUpdateStream

Description
Called on on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
182function Plough:readUpdateStream(streamId, timestamp, connection)
183 if connection:getIsServer() then
184 self.ploughHasGroundContact = streamReadBool(streamId);
185 self.showFieldNotOwnedWarning = streamReadBool(streamId);
186 end
187end

writeUpdateStream

Description
Called on on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
194function Plough:writeUpdateStream(streamId, connection, dirtyMask)
195 if not connection:getIsServer() then
196 streamWriteBool(streamId, self.ploughHasGroundContact);
197 streamWriteBool(streamId, self.showFieldNotOwnedWarning);
198 end
199end

getSaveAttributesAndNodes

Description
Returns attributes and nodes to save
Definition
getSaveAttributesAndNodes(table nodeIdent)
Arguments
tablenodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
206function 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;
214end

update

Description
Called on update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
225function 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
240end

updateTick

Description
Called on update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
245function 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
322end

draw

Description
Called on draw
Definition
draw()
Code
326function 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
348end

onAttach

Description
Called if vehicle gets attached
Definition
onAttach(table attacherVehicle)
Arguments
tableattacherVehicleattacher vehicle
Code
353function 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
364end

onDetach

Description
Called if vehicle gets detached
Definition
onDetach()
Code
368function 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
374end

onDeactivate

Description
Called on deactivate
Definition
onDeactivate()
Code
381function Plough:onDeactivate()
382 self.showFieldNotOwnedWarning = false;
383end

onDeactivateSounds

Description
Called on deactivating sounds
Definition
onDeactivateSounds()
Code
387function Plough:onDeactivateSounds()
388 if self.isClient then
389 SoundUtil.stopSample(self.samplePlough, true);
390 SoundUtil.stopSample(self.samplePloughTurn, true);
391 end
392end

onAiRotateCenter

Description
Called on ai rotate center
Definition
onAiRotateCenter(boolean force)
Arguments
booleanforceforce action
Code
397function 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
411end

onAiRotateLeft

Description
Called on ai rotate left
Definition
onAiRotateLeft(boolean force)
Arguments
booleanforceforce action
Code
416function Plough:onAiRotateLeft(force)
417 if self:getIsPloughRotationAllowed() or force then
418 self:setRotationMax(self.rotateLeftToMax, true);
419 end
420end

onAiRotateRight

Description
Called on ai rotate right
Definition
onAiRotateRight(boolean force)
Arguments
booleanforceforce action
Code
425function Plough:onAiRotateRight(force)
426 if self:getIsPloughRotationAllowed() or force then
427 self:setRotationMax(not self.rotateLeftToMax, true);
428 end
429end

onAiTurnOn

Description
Called on ai turn on
Definition
onAiTurnOn()
Code
433function Plough:onAiTurnOn()
434 self.ploughLimitToField = true;
435end

getAiInvertsMarkerOnTurn

Description
Returns if ai inverts markers on turn
Definition
getAiInvertsMarkerOnTurn(boolean turnLeft)
Arguments
booleanturnLeftturn left
Code
443function 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
453end

getIsAIReadyForWork

Description
Returns true if vehicle is ready for ai work
Definition
getIsAIReadyForWork()
Return Values
booleanisReadyis ready for ai work
Code
458function 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
471end

setRotationMax

Description
Set rotation of plough
Definition
setRotationMax(boolean rotationMax)
Arguments
booleanrotationMaxrotate to max
Code
476function 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
494end

setPloughLimitToField

Description
Set plough is limited to field
Definition
setPloughLimitToField(boolean ploughLimitToField, boolean noEventSend)
Arguments
booleanploughLimitToFieldnew plough limited to field state
booleannoEventSendno event send
Code
500function 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
511end

getIsPloughRotationAllowed

Description
Returns if plough rotation is allowed
Definition
getIsPloughRotationAllowed()
Return Values
booleanisAllowedplough rotation is allowed
Code
516function 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;
532end

getIsFoldAllowed

Description
Returns if fold is allowed
Definition
getIsFoldAllowed(boolean onAiTurnOn)
Arguments
booleanonAiTurnOncalled on ai turn on
Return Values
booleanallowsFoldallows folding
Code
538function 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;
552end

getIsFoldMiddleAllowed

Description
Returns if fold middle is allowed
Definition
getIsFoldMiddleAllowed()
Return Values
booleanallowsFoldMiddleallows folding to middle position
Code
557function 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;
571end

getDirtMultiplier

Description
Returns current dirt multiplier
Definition
getDirtMultiplier()
Return Values
floatdirtMultipliercurrent dirt multiplier
Code
576function 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;
587end

loadSpeedRotatingPartFromXML

Description
Loads speed rotating parts from xml
Definition
loadSpeedRotatingPartFromXML(table speedRotatingPart, integer xmlFile, string key)
Arguments
tablespeedRotatingPartspeedRotatingPart
integerxmlFileid of xml object
stringkeykey
Return Values
booleansuccesssuccess
Code
595function 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;
608end

getIsSpeedRotatingPartActive

Description
Returns true if speed rotating part is active
Definition
getIsSpeedRotatingPartActive(table speedRotatingPart)
Arguments
tablespeedRotatingPartspeedRotatingPart
Return Values
booleanisActivespeed rotating part is active
Code
614function 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;
636end

getSpeedRotatingPartDirection

Description
Return direction of speed rotating part
Definition
getSpeedRotatingPartDirection(table speedRotatingPart)
Arguments
tablespeedRotatingPartspeed rotating part
Return Values
integerdirectiondirection
Code
642function 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;
654end

doCheckSpeedLimit

Description
Returns if speed limit should be checked
Definition
doCheckSpeedLimit()
Return Values
booleancheckSpeedlimitcheck speed limit
Code
659function 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;
666end

loadWorkAreaFromXML

Description
Loads work areas from xml
Definition
loadWorkAreaFromXML(table workArea, integer xmlFile, string key)
Arguments
tableworkAreaworkArea
integerxmlFileid of xml object
stringkeykey
Return Values
booleansuccesssuccess
Code
674function 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;
685end

getDefaultSpeedLimit

Description
Returns default speed limit
Definition
getDefaultSpeedLimit()
Return Values
floatspeedLimitspeed limit
Code
690function Plough.getDefaultSpeedLimit()
691 return 15;
692end

processPloughAreas

Description
Process plough areas
Definition
processPloughAreas(table workAreas, boolean limitToField, boolean limitGrassDestructionToField, float angle)
Arguments
tableworkAreaswork areas to process
booleanlimitToFieldis limited to field
booleanlimitGrassDestructionToFieldis grass destruction is limited to field
floatanglecurrent angle
Return Values
floatareaSumsum of worked area
Code
701function 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;
707end;