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 |
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 |
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 |
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 |