LUADOC - Farming Simulator 17

Printable Version

Script v1.4.4.0

Engine v7.0.0.2

Foundation Reference

FruitPreparer

Description
This is the specialization for tool that prepare the fruits for harvesting. E.g. potato haulm toppers and sugar beet defoliators
Functions

initSpecialization

Description
Called on specialization initializing
Definition
initSpecialization()
Code
17function FruitPreparer.initSpecialization()
18 WorkArea.registerAreaType("fruitPreparer")
19end

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
25function FruitPreparer.prerequisitesPresent(specializations)
26 return SpecializationUtil.hasSpecialization(WorkArea, specializations) and SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations)
27end

preLoad

Description
Called before loading
Definition
preLoad(table savegame)
Arguments
tablesavegamesavegame
Code
32function FruitPreparer:preLoad(savegame)
33 self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, FruitPreparer.loadWorkAreaFromXML)
34end

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
39function FruitPreparer:load(savegame)
40
41 Utils.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnAnimation#name", "vehicle.turnOnVehicle.turnedAnimation#name")
42 Utils.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.turnOnAnimation#speed", "vehicle.turnOnVehicle.turnedAnimation#turnOnSpeedScale")
43 Utils.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.fruitPreparerOnlyActiveWhenLowered#value", "vehicle.fruitPreparer#onlyActiveWhenLowered")
44
45 self.getDoGroundManipulation = Utils.overwrittenFunction(self.getDoGroundManipulation, FruitPreparer.getDoGroundManipulation)
46 self.doCheckSpeedLimit = Utils.overwrittenFunction(self.doCheckSpeedLimit, FruitPreparer.doCheckSpeedLimit)
47 self.getIsTurnedOnAllowed = Utils.overwrittenFunction(self.getIsTurnedOnAllowed, FruitPreparer.getIsTurnedOnAllowed)
48 self.processFruitPreparerAreas = FruitPreparer.processFruitPreparerAreas
49
50 self.fruitPreparer = {}
51
52 if self.isClient then
53 self.fruitPreparer.sampleFruitPreparer = SoundUtil.loadSample(self.xmlFile, {}, "vehicle.fruitPreparerSound", nil, self.baseDirectory)
54 self.fruitPreparer.turnedOnRotationNodes = Utils.loadRotationNodes(self.xmlFile, {}, "vehicle.turnedOnRotationNodes.turnedOnRotationNode", "fruitPreparer", self.components)
55 end
56
57 self.fruitPreparer.fruitType = FruitUtil.FRUITTYPE_UNKNOWN
58 local fruitType = getXMLString(self.xmlFile, "vehicle.fruitPreparer#fruitType")
59 if fruitType ~= nil then
60 local desc = FruitUtil.fruitTypes[fruitType]
61 if desc ~= nil then
62 self.fruitPreparer.fruitType = desc.index
63 self.aiRequiredFruitType = desc.index
64 self.aiRequiredMinGrowthState = desc.minPreparingGrowthState
65 self.aiRequiredMaxGrowthState = desc.maxPreparingGrowthState
66 end
67 end
68
69 self.fruitPreparer.onlyActiveWhenLowered = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.fruitPreparer#onlyActiveWhenLowered"), true)
70 self.fruitPreparer.useReelStateToTurnOn = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.fruitPreparer#useReelStateToTurnOn"), false)
71 self.fruitPreparer.isSpeedLimitActive = false
72 self.fruitPreparer.areParticlesActive = false
73end

delete

Description
Called on deleting
Definition
delete()
Code
77function FruitPreparer:delete()
78 if self.isClient then
79 SoundUtil.deleteSample(self.fruitPreparer.sampleFruitPreparer)
80 end
81end

update

Description
Called on update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
92function FruitPreparer:update(dt)
93 if self.isClient then
94 Utils.updateRotationNodes(self, self.fruitPreparer.turnedOnRotationNodes, dt, self:getIsActive() and self:getIsTurnedOn() )
95 end
96end

updateTick

Description
Called on update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
101function FruitPreparer:updateTick(dt)
102 self.fruitPreparer.isSpeedLimitActive = false
103 self.fruitPreparer.areParticlesActive = false
104 if self.isActive then
105 if (self.isThreshing or self:getIsTurnedOn()) and self.fruitPreparer.fruitType ~= FruitUtil.FRUITTYPE_UNKNOWN then
106 local isTypedWorkAreaActive, typedWorkAreas = self:getIsTypedWorkAreaActive(WorkArea.AREATYPE_FRUITPREPARER)
107 local fruitPreparerDoGroundManipulation = (not self.fruitPreparer.onlyActiveWhenLowered or self:isLowered(true))
108 if fruitPreparerDoGroundManipulation then
109 fruitPreparerDoGroundManipulation = isTypedWorkAreaActive
110 end
111 if fruitPreparerDoGroundManipulation then
112 self.fruitPreparer.isSpeedLimitActive = true
113 if self.isServer then
114 local numWorkAreas = 0
115 local workAreas = self.fruitPreparerAreas
116 for _,area in pairs(typedWorkAreas) do
117 if self:getIsWorkAreaActive(area) then
118 numWorkAreas = numWorkAreas + 1
119 workAreas[numWorkAreas].x, _, workAreas[numWorkAreas].z = getWorldTranslation(area.start)
120 workAreas[numWorkAreas].x1, _, workAreas[numWorkAreas].z1 = getWorldTranslation(area.width)
121 workAreas[numWorkAreas].x2, _, workAreas[numWorkAreas].z2 = getWorldTranslation(area.height)
122 workAreas[numWorkAreas].hasSeparateDropArea = (area.dropStart ~= nil)
123 if workAreas[numWorkAreas].hasSeparateDropArea then
124 workAreas[numWorkAreas].dx, _, workAreas[numWorkAreas].dz = getWorldTranslation(area.dropStart)
125 workAreas[numWorkAreas].dx1, _, workAreas[numWorkAreas].dz1 = getWorldTranslation(area.dropWidth)
126 workAreas[numWorkAreas].dx2, _, workAreas[numWorkAreas].dz2 = getWorldTranslation(area.dropHeight)
127 end
128 end
129 end
130 if numWorkAreas > 0 then
131 numWorkAreas = self:processFruitPreparerAreas(workAreas, numWorkAreas, self.fruitPreparer.fruitType)
132 if numWorkAreas > 0 then
133 self.fruitPreparer.areParticlesActive = true
134 end
135 end
136 end
137 end
138 if self.isClient and self:getIsActiveForSound() then
139 SoundUtil.playSample(self.fruitPreparer.sampleFruitPreparer, 0, 0, nil)
140 end
141 end
142 end
143end

onDeactivateSounds

Description
Called on deactivating sounds
Definition
onDeactivateSounds()
Code
150function FruitPreparer:onDeactivateSounds()
151 if self.isClient then
152 SoundUtil.stopSample(self.fruitPreparer.sampleFruitPreparer, true)
153 end
154end

getIsTurnedOnAllowed

Description
Returns if turn on is allowed
Definition
getIsTurnedOnAllowed(boolean isTurnedOn)
Arguments
booleanisTurnedOnis turned on
Return Values
booleanallowallow turn on
Code
160function FruitPreparer:getIsTurnedOnAllowed(superFunc, isTurnedOn)
161 if isTurnedOn and self.isThreshing ~= nil then
162 return false
163 end
164
165 if superFunc ~= nil then
166 return superFunc(self, isTurnedOn)
167 end
168
169 return true
170end

onTurnedOff

Description
Called on turn off
Definition
onTurnedOff(boolean noEventSend)
Arguments
booleannoEventSendno event send
Code
175function FruitPreparer:onTurnedOff(noEventSend)
176 FruitPreparer.onDeactivateSounds(self)
177end

onAiTurnOn

Description
Called on ai turn on
Definition
onAiTurnOn()
Code
181function FruitPreparer:onAiTurnOn()
182 if self:getIsTurnedOnAllowed(true) then
183 self:setIsTurnedOn(true, true)
184 end
185end

onAiLower

Description
Called on ai lower
Definition
onAiLower()
Code
189function FruitPreparer:onAiLower()
190 if self:getIsTurnedOnAllowed(true) then
191 self:setIsTurnedOn(true, true)
192 end
193end

onAiRaise

Description
Called on ai raise
Definition
onAiRaise()
Code
197function FruitPreparer:onAiRaise()
198 self:setIsTurnedOn(false, true)
199end

doCheckSpeedLimit

Description
Returns if speed limit should be checked
Definition
doCheckSpeedLimit()
Return Values
booleancheckSpeedlimitcheck speed limit
Code
204function FruitPreparer:doCheckSpeedLimit(superFunc)
205 local parent = false
206 if superFunc ~= nil then
207 parent = superFunc(self)
208 end
209
210 return parent or self.fruitPreparer.isSpeedLimitActive
211end

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
219function FruitPreparer:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key)
220 local retValue = true
221 if superFunc ~= nil then
222 retValue = superFunc(self, workArea, xmlFile, key)
223 end
224
225 if workArea.type == WorkArea.AREATYPE_FRUITPREPARER then
226 local dropStart = Utils.indexToObject(self.components, getXMLString(xmlFile, key .. "#dropStartIndex"))
227 local dropWidth = Utils.indexToObject(self.components, getXMLString(xmlFile, key .. "#dropWidthIndex"))
228 local dropHeight = Utils.indexToObject(self.components, getXMLString(xmlFile, key .. "#dropHeightIndex"))
229
230 if dropStart ~= nil and dropWidth ~= nil and dropHeight ~= nil then
231 workArea.dropStart = dropStart
232 workArea.dropWidth = dropWidth
233 workArea.dropHeight = dropHeight
234 end
235
236 if self.fruitPreparerAreas == nil then
237 self.fruitPreparerAreas = {}
238 end
239 table.insert(self.fruitPreparerAreas, {})
240 end
241
242 return retValue
243end

getDoGroundManipulation

Description
Returns if tool does ground manipulation
Definition
getDoGroundManipulation()
Return Values
booleandoGroundManipulationdo ground manipulation
Code
248function FruitPreparer:getDoGroundManipulation(superFunc)
249 if not self.fruitPreparer.areParticlesActive then
250 return false
251 end
252
253 if superFunc ~= nil then
254 return superFunc(self)
255 end
256 return true
257end

getDefaultSpeedLimit

Description
Returns default speed limit
Definition
getDefaultSpeedLimit()
Return Values
floatspeedLimitspeed limit
Code
262function FruitPreparer.getDefaultSpeedLimit()
263 return 15
264end

processFruitPreparerAreas

Description
Process preparer areas
Definition
processFruitPreparerAreas(table workAreas, integer numWorkAreas, integer fruitType)
Arguments
tableworkAreaswork areas
integernumWorkAreasnumber of work areas
integerfruitTypefruit type
Return Values
floatnumAreasUsednumber of areas used
Code
272function FruitPreparer:processFruitPreparerAreas(workAreas, numWorkAreas, fruitType)
273
274 local numAreasUsed = 0
275 for i=1, numWorkAreas do
276 local x = workAreas[i].x
277 local z = workAreas[i].z
278 local x1 = workAreas[i].x1
279 local z1 = workAreas[i].z1
280 local x2 = workAreas[i].x2
281 local z2 = workAreas[i].z2
282
283 local areaChanged = 0
284 if workAreas[i].hasSeparateDropArea then
285 local dx = workAreas[i].dx
286 local dz = workAreas[i].dz
287 local dx1 = workAreas[i].dx1
288 local dz1 = workAreas[i].dz1
289 local dx2 = workAreas[i].dx2
290 local dz2 = workAreas[i].dz2
291
292 areaChanged = Utils.updateFruitPreparerArea(fruitType, x, z, x1, z1, x2, z2, dx, dz, dx1, dz1, dx2, dz2)
293 else
294 areaChanged = Utils.updateFruitPreparerArea(fruitType, x, z, x1, z1, x2, z2, x, z, x1, z1, x2, z2)
295 end
296
297 if areaChanged > 0 then
298 numAreasUsed = numAreasUsed + 1
299 end
300 end
301 return numAreasUsed
302end

onStartReel

Description
Start reel
Definition
onStartReel()
Code
306function FruitPreparer:onStartReel()
307 if self.fruitPreparer.useReelStateToTurnOn then
308 self:setIsTurnedOn(true, true)
309 end
310end

onStopReel

Description
Stop reel
Definition
onStopReel()
Code
314function FruitPreparer:onStopReel()
315 if self.fruitPreparer.useReelStateToTurnOn then
316 self:setIsTurnedOn(false, true)
317 end
318end