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
FruitPreparer
DescriptionThis is the specialization for tool that prepare the fruits for harvesting. E.g. potato haulm toppers and sugar beet defoliatorsFunctions
- initSpecialization
- prerequisitesPresent
- preLoad
- load
- delete
- update
- updateTick
- onDeactivateSounds
- getIsTurnedOnAllowed
- onTurnedOff
- onAiTurnOn
- onAiLower
- onAiRaise
- doCheckSpeedLimit
- loadWorkAreaFromXML
- getDoGroundManipulation
- getDefaultSpeedLimit
- processFruitPreparerAreas
- onStartReel
- onStopReel
initSpecialization
DescriptionCalled on specialization initializingDefinition
initSpecialization()Code
17 | function FruitPreparer.initSpecialization() |
18 | WorkArea.registerAreaType("fruitPreparer") |
19 | 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 |
25 | function FruitPreparer.prerequisitesPresent(specializations) |
26 | return SpecializationUtil.hasSpecialization(WorkArea, specializations) and SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations) |
27 | end |
preLoad
DescriptionCalled before loadingDefinition
preLoad(table savegame)Arguments
table | savegame | savegame |
32 | function FruitPreparer:preLoad(savegame) |
33 | self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, FruitPreparer.loadWorkAreaFromXML) |
34 | end |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
39 | function 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 |
73 | end |
delete
DescriptionCalled on deletingDefinition
delete()Code
77 | function FruitPreparer:delete() |
78 | if self.isClient then |
79 | SoundUtil.deleteSample(self.fruitPreparer.sampleFruitPreparer) |
80 | end |
81 | end |
update
DescriptionCalled on updateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
92 | function FruitPreparer:update(dt) |
93 | if self.isClient then |
94 | Utils.updateRotationNodes(self, self.fruitPreparer.turnedOnRotationNodes, dt, self:getIsActive() and self:getIsTurnedOn() ) |
95 | end |
96 | end |
updateTick
DescriptionCalled on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
101 | function 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 |
143 | end |
onDeactivateSounds
DescriptionCalled on deactivating soundsDefinition
onDeactivateSounds()Code
150 | function FruitPreparer:onDeactivateSounds() |
151 | if self.isClient then |
152 | SoundUtil.stopSample(self.fruitPreparer.sampleFruitPreparer, true) |
153 | end |
154 | end |
getIsTurnedOnAllowed
DescriptionReturns if turn on is allowedDefinition
getIsTurnedOnAllowed(boolean isTurnedOn)Arguments
boolean | isTurnedOn | is turned on |
boolean | allow | allow turn on |
160 | function 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 |
170 | end |
onTurnedOff
DescriptionCalled on turn offDefinition
onTurnedOff(boolean noEventSend)Arguments
boolean | noEventSend | no event send |
175 | function FruitPreparer:onTurnedOff(noEventSend) |
176 | FruitPreparer.onDeactivateSounds(self) |
177 | end |
onAiTurnOn
DescriptionCalled on ai turn onDefinition
onAiTurnOn()Code
181 | function FruitPreparer:onAiTurnOn() |
182 | if self:getIsTurnedOnAllowed(true) then |
183 | self:setIsTurnedOn(true, true) |
184 | end |
185 | end |
onAiLower
DescriptionCalled on ai lowerDefinition
onAiLower()Code
189 | function FruitPreparer:onAiLower() |
190 | if self:getIsTurnedOnAllowed(true) then |
191 | self:setIsTurnedOn(true, true) |
192 | end |
193 | end |
onAiRaise
DescriptionCalled on ai raiseDefinition
onAiRaise()Code
197 | function FruitPreparer:onAiRaise() |
198 | self:setIsTurnedOn(false, true) |
199 | end |
doCheckSpeedLimit
DescriptionReturns if speed limit should be checkedDefinition
doCheckSpeedLimit()Return Values
boolean | checkSpeedlimit | check speed limit |
204 | function 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 |
211 | 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 |
219 | function 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 |
243 | end |
getDoGroundManipulation
DescriptionReturns if tool does ground manipulationDefinition
getDoGroundManipulation()Return Values
boolean | doGroundManipulation | do ground manipulation |
248 | function 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 |
257 | end |
getDefaultSpeedLimit
DescriptionReturns default speed limitDefinition
getDefaultSpeedLimit()Return Values
float | speedLimit | speed limit |
262 | function FruitPreparer.getDefaultSpeedLimit() |
263 | return 15 |
264 | end |
processFruitPreparerAreas
DescriptionProcess preparer areasDefinition
processFruitPreparerAreas(table workAreas, integer numWorkAreas, integer fruitType)Arguments
table | workAreas | work areas |
integer | numWorkAreas | number of work areas |
integer | fruitType | fruit type |
float | numAreasUsed | number of areas used |
272 | function 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 |
302 | end |
onStartReel
DescriptionStart reelDefinition
onStartReel()Code
306 | function FruitPreparer:onStartReel() |
307 | if self.fruitPreparer.useReelStateToTurnOn then |
308 | self:setIsTurnedOn(true, true) |
309 | end |
310 | end |
onStopReel
DescriptionStop reelDefinition
onStopReel()Code
314 | function FruitPreparer:onStopReel() |
315 | if self.fruitPreparer.useReelStateToTurnOn then |
316 | self:setIsTurnedOn(false, true) |
317 | end |
318 | end |