Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- |
2 | -- Combine |
3 | -- This is the specialization for combines |
4 | -- |
5 | -- @author Stefan Geiger |
6 | -- @date 30/11/08 |
7 | -- |
8 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
9 | |
10 | Combine = {}; |
11 | source("dataS/scripts/vehicles/specializations/CombineAreaEvent.lua"); |
12 | source("dataS/scripts/vehicles/specializations/CombineStrawEnableEvent.lua"); |
13 | |
14 | function Combine.initSpecialization() |
15 | Vehicle.registerJointType("cutter"); |
16 | Vehicle.registerJointType("cutterHarvester"); |
17 | WorkArea.registerAreaType("combine"); |
18 | end; |
19 | |
20 | function Combine.prerequisitesPresent(specializations) |
21 | return (SpecializationUtil.hasSpecialization(Drivable, specializations) or SpecializationUtil.hasSpecialization(Attachable, specializations)) and |
22 | SpecializationUtil.hasSpecialization(WorkArea, specializations) and |
23 | SpecializationUtil.hasSpecialization(Overloading, specializations) and |
24 | SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations); |
25 | end; |
26 | |
27 | function Combine:preLoad(xmlFile) |
28 | self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, Combine.loadWorkAreaFromXML); |
29 | end |
30 | |
31 | function Combine:load(xmlFile) |
32 | self.getIsCutterFruitTypeAllowed = Combine.getIsCutterFruitTypeAllowed; |
33 | self.startThreshing = SpecializationUtil.callSpecializationsFunction("startThreshing"); |
34 | self.stopThreshing = SpecializationUtil.callSpecializationsFunction("stopThreshing"); |
35 | |
36 | self.addCutterArea = SpecializationUtil.callSpecializationsFunction("addCutterArea"); |
37 | self.getIsThreshingAllowed = Combine.getIsThreshingAllowed; |
38 | self.getIsFoldAllowed = Utils.overwrittenFunction(self.getIsFoldAllowed, Combine.getIsFoldAllowed); |
39 | self.getTurnedOnNotAllowedWarning = Utils.overwrittenFunction(self.getTurnedOnNotAllowedWarning, Combine.getTurnedOnNotAllowedWarning); |
40 | self.applyInitialAnimation = Utils.overwrittenFunction(self.applyInitialAnimation, Combine.applyInitialAnimation); |
41 | self.setIsStrawEnabled = Combine.setIsStrawEnabled; |
42 | |
43 | self.getDoRenderFillType = Utils.overwrittenFunction(self.getDoRenderFillType, Combine.getDoRenderFillType); |
44 | self.getOverlayFillType = Utils.overwrittenFunction(self.getOverlayFillType, Combine.getOverlayFillType); |
45 | self.getIsTurnedOnAllowed = Utils.overwrittenFunction(self.getIsTurnedOnAllowed, Combine.getIsTurnedOnAllowed); |
46 | self.getNeedsCutterFolding = Combine.getNeedsCutterFolding; |
47 | |
48 | -- state change helpers |
49 | self.setCombineIsFilling = SpecializationUtil.callSpecializationsFunction("setCombineIsFilling"); |
50 | self.setChopperPSEnabled = SpecializationUtil.callSpecializationsFunction("setChopperPSEnabled"); |
51 | self.setStrawPSEnabled = SpecializationUtil.callSpecializationsFunction("setStrawPSEnabled"); |
52 | |
53 | if self.isClient then |
54 | self.sampleThreshingStart = Utils.loadSample(xmlFile, {}, "vehicle.threshingStartSound", nil, self.baseDirectory); |
55 | self.sampleThreshing = Utils.loadSample(xmlFile, {}, "vehicle.threshingSound", nil, self.baseDirectory, self.components[1].node); |
56 | self.sampleThreshingStop = Utils.loadSample(xmlFile, {}, "vehicle.threshingStopSound", nil, self.baseDirectory); |
57 | end; |
58 | |
59 | self.convertedFruits = {}; |
60 | local i = 0; |
61 | while true do |
62 | local key = string.format("vehicle.convertedFruits.convertedFruit(%d)", i); |
63 | if not hasXMLProperty(xmlFile, key) then |
64 | break; |
65 | end; |
66 | local inputType = getXMLString(xmlFile, key .. "#input"); |
67 | local outputType = getXMLString(xmlFile, key .. "#output"); |
68 | |
69 | if inputType ~= nil and outputType ~= nil then |
70 | local inputDesc = FruitUtil.fruitTypes[inputType]; |
71 | local outputDesc = FruitUtil.fruitTypes[outputType]; |
72 | if inputDesc ~= nil and outputDesc ~= nil then |
73 | self.convertedFruits[inputDesc.index] = outputDesc.index; |
74 | end; |
75 | end; |
76 | |
77 | i = i + 1; |
78 | end; |
79 | |
80 | self.allowsThreshing = true; |
81 | |
82 | self.combineTurnedOnRotationNodes = Utils.loadRotationNodes(xmlFile, {}, "vehicle.turnedOnRotationNodes.turnedOnRotationNode", "combine", self.components); |
83 | |
84 | self.allowThreshingDuringRain = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.allowThreshingDuringRain"), false); |
85 | |
86 | self.combineIsFilling = false; |
87 | |
88 | if self.isClient then |
89 | -- chopper particle systems |
90 | self.chopperParticleSystems = {}; |
91 | local i = 0; |
92 | while true do |
93 | local key = string.format("vehicle.chopperParticleSystems.chopperParticleSystem(%d)", i); |
94 | local t = getXMLString(xmlFile, key .. "#type"); |
95 | if t == nil then |
96 | break; |
97 | end; |
98 | local desc = FruitUtil.fruitTypes[t]; |
99 | if desc ~= nil then |
100 | local currentPS = Utils.getNoNil(self.chopperParticleSystems[desc.index], {}); |
101 | |
102 | Utils.loadParticleSystem(xmlFile, currentPS, key, self.components, false, nil, self.baseDirectory); |
103 | self.chopperParticleSystems[desc.index] = currentPS; |
104 | if self.defaultChopperParticleSystem == nil then |
105 | self.defaultChopperParticleSystem = currentPS; |
106 | end; |
107 | end; |
108 | i = i + 1; |
109 | end; |
110 | |
111 | -- straw particle systems |
112 | self.strawParticleSystems = {}; |
113 | local i = 0; |
114 | while true do |
115 | local key = string.format("vehicle.strawParticleSystems.strawParticleSystem(%d)", i); |
116 | local t = getXMLString(xmlFile, key .. "#type"); |
117 | if t == nil then |
118 | break; |
119 | end; |
120 | local desc = FruitUtil.fruitTypes[t]; |
121 | if desc ~= nil then |
122 | local currentPS = Utils.getNoNil(self.strawParticleSystems[desc.index], {}); |
123 | |
124 | Utils.loadParticleSystem(xmlFile, currentPS, key, self.components, false, nil, self.baseDirectory); |
125 | self.strawParticleSystems[desc.index] = currentPS; |
126 | if self.defaultStrawParticleSystem == nil then |
127 | self.defaultStrawParticleSystem = currentPS; |
128 | end; |
129 | end; |
130 | i = i + 1; |
131 | end; |
132 | |
133 | -- fill particle systems |
134 | self.combineThreshingFillParticleSystems = {}; |
135 | local i = 0; |
136 | while true do |
137 | local key = string.format("vehicle.combineThreshingFillParticleSystems.combineThreshingFillParticleSystem(%d)", i); |
138 | local t = getXMLString(xmlFile, key .. "#type"); |
139 | if t == nil then |
140 | break; |
141 | end; |
142 | local desc = FruitUtil.fruitTypes[t]; |
143 | if desc ~= nil then |
144 | local currentPS = Utils.getNoNil(self.combineThreshingFillParticleSystems[desc.index], {}); |
145 | Utils.loadParticleSystem(xmlFile, currentPS, key, self.components, false, nil, self.baseDirectory); |
146 | self.combineThreshingFillParticleSystems[desc.index] = currentPS; |
147 | end; |
148 | i = i + 1; |
149 | end; |
150 | |
151 | self.chopperEffect = EffectManager:loadEffect(xmlFile, "vehicle.chopperEffect", self.components, self); |
152 | self.strawEffect = EffectManager:loadEffect(xmlFile, "vehicle.strawEffect", self.components, self); |
153 | self.fillEffect = EffectManager:loadEffect(xmlFile, "vehicle.fillEffect", self.components, self); |
154 | |
155 | self.combineThreshingScrollers = Utils.loadScrollers(self.components, xmlFile, "vehicle.combineThreshingScrollers.combineThreshingScroller", {}, false); |
156 | self.combineThreshingFillScrollers = Utils.loadScrollers(self.components, xmlFile, "vehicle.combineThreshingFillScrollers.combineThreshingFillScroller", {}, true); |
157 | end; |
158 | |
159 | self.chopperToggleTime = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.chopperParticleSystems#toggleTime"), 2500); |
160 | self.chopperEnableTime = nil; |
161 | self.chopperDisableTime = nil; |
162 | self.combineFillToggleTime = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.combineThreshingFillParticleSystems#toggleTime"), Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.combineThreshingFillScrollers#toggleTime"), 2500)); |
163 | self.combineFillEnableTime = nil; |
164 | self.combineFillDisableTime = nil; |
165 | self.strawToggleTime = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.strawParticleSystems#toggleTime"), 2500); |
166 | self.strawEnableTime = nil; |
167 | self.strawDisableTime = nil; |
168 | |
169 | self.combineSize = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.combineSize"), 1); |
170 | self.strawAreaToDrop = 0; |
171 | |
172 | self.strawPSenabled = false; |
173 | self.chopperPSenabled = false; |
174 | self.threshingScale = 1; |
175 | |
176 | self.isStrawEnabled = true; |
177 | self.chopperSwitchAvailable = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.chopperSwitch#available"), false); |
178 | if self.chopperSwitchAvailable then |
179 | self.toggleChopperAnimName = Utils.getNoNil(getXMLString(xmlFile, "vehicle.chopperSwitch#animName"), "toggleChopper"); |
180 | self.toggleChopperWarningTime = 0; |
181 | self:setIsStrawEnabled(true, true, true); |
182 | end; |
183 | |
184 | self.lastLostFillLevel = 0; |
185 | |
186 | self.threshingStartAnimation = getXMLString(xmlFile, "vehicle.threshingStartAnimation#name"); |
187 | self.threshingStartAnimationSpeedScale = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.threshingStartAnimation#speedScale"), 1); |
188 | self.threshingStartAnimationInitialIsStarted = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.threshingStartAnimation#initialIsStarted"), false); |
189 | |
190 | --[[ |
191 | self.threshingFoldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.threshingFold#foldMinLimit"), 0); |
192 | self.threshingFoldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.threshingFold#foldMaxLimit"), 1);]] |
193 | |
194 | self.foldMinFillLevel = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.threshingFold#foldMinFillLevel"), 0); |
195 | self.foldMaxFillLevel = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.threshingFold#foldMaxFillLevel"), 0); |
196 | self.allowFoldWhileThreshing = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.threshingFold#allowFoldWhileThreshing"), false); |
197 | |
198 | self.attachedCutters = {}; |
199 | self.numAttachedCutters = 0; |
200 | |
201 | self.updateShaderParticleTime = 0; |
202 | |
203 | self.lastArea = 0; |
204 | self.lastAreaZeroTime = 0; |
205 | self.lastAreaNonZeroTime = -1000000; |
206 | self.lastCuttersArea = 0; |
207 | self.lastCuttersAreaTime = -10000; |
208 | self.lastInputFruitType = FruitUtil.FRUITTYPE_UNKNOWN; |
209 | self.lastValidInputFruitType = FruitUtil.FRUITTYPE_UNKNOWN; |
210 | self.lastCuttersFruitType = FruitUtil.FRUITTYPE_UNKNOWN; |
211 | self.lastCuttersInputFruitType = FruitUtil.FRUITTYPE_UNKNOWN; |
212 | |
213 | self.workedHectars = 0; |
214 | |
215 | self.combineDirtyFlag = self:getNextDirtyFlag(); |
216 | end; |
217 | |
218 | function Combine:postLoad(xmlFile) |
219 | if self.onStartReel ~= nil and self.onStopReel ~= nil then |
220 | self.attachedCutters[self] = {}; |
221 | self.numAttachedCutters = self.numAttachedCutters+1; |
222 | end |
223 | end |
224 | |
225 | function Combine:applyInitialAnimation(superFunc) |
226 | if self.threshingStartAnimation ~= nil and self.playAnimation ~= nil and self.threshingStartAnimationInitialIsStarted then |
227 | self:playAnimation(self.threshingStartAnimation, -self.threshingStartAnimationSpeedScale, nil, true); |
228 | AnimatedVehicle.updateAnimations(self, 99999999); |
229 | end |
230 | if superFunc ~= nil then |
231 | superFunc(self); |
232 | end |
233 | end |
234 | |
235 | function Combine:delete() |
236 | if self.isClient then |
237 | EffectManager:deleteEffect(self.fillEffect); |
238 | EffectManager:deleteEffect(self.strawEffect); |
239 | EffectManager:deleteEffect(self.chopperEffect); |
240 | |
241 | for _,v in pairs(self.chopperParticleSystems) do |
242 | Utils.deleteParticleSystem(v); |
243 | end; |
244 | for _,v in pairs(self.strawParticleSystems) do |
245 | Utils.deleteParticleSystem(v); |
246 | end; |
247 | for _,v in pairs(self.combineThreshingFillParticleSystems) do |
248 | Utils.deleteParticleSystem(v); |
249 | end; |
250 | |
251 | Utils.deleteSample(self.sampleThreshingStart); |
252 | Utils.deleteSample(self.sampleThreshingStop); |
253 | Utils.deleteSample(self.sampleThreshing); |
254 | end; |
255 | end; |
256 | |
257 | function Combine:readStream(streamId, connection) |
258 | self.lastValidInputFruitType = streamReadUIntN(streamId, FruitUtil.sendNumBits); |
259 | local combineIsFilling = streamReadBool(streamId); |
260 | local chopperPSenabled = streamReadBool(streamId); |
261 | local strawPSenabled = streamReadBool(streamId); |
262 | |
263 | self:setCombineIsFilling(combineIsFilling, false, true); |
264 | self:setChopperPSEnabled(chopperPSenabled, false, true); |
265 | self:setStrawPSEnabled(strawPSenabled, false, true); |
266 | |
267 | if self.chopperSwitchAvailable then |
268 | local isStrawEnabled = streamReadBool(streamId); |
269 | self:setIsStrawEnabled(isStrawEnabled, true); |
270 | else |
271 | if self.lastValidFillType ~= Fillable.FILLTYPE_UNKNOWN then |
272 | local fruitType = FruitUtil.fillTypeToFruitType[self.lastValidFillType]; |
273 | local fruitDesc = FruitUtil.fruitIndexToDesc[fruitType]; |
274 | self.isStrawEnabled = not fruitDesc.hasWindrow; |
275 | else |
276 | self.isStrawEnabled = false; |
277 | end; |
278 | end; |
279 | |
280 | self.workedHectars = streamReadFloat32(streamId); |
281 | end; |
282 | |
283 | function Combine:writeStream(streamId, connection) |
284 | streamWriteUIntN(streamId, self.lastValidInputFruitType, FruitUtil.sendNumBits); |
285 | streamWriteBool(streamId, self.combineIsFilling); |
286 | streamWriteBool(streamId, self.chopperPSenabled); |
287 | streamWriteBool(streamId, self.strawPSenabled); |
288 | |
289 | if self.chopperSwitchAvailable then |
290 | streamWriteBool(streamId, self.isStrawEnabled); |
291 | end; |
292 | |
293 | streamWriteFloat32(streamId, self.workedHectars); |
294 | end; |
295 | |
296 | function Combine:readUpdateStream(streamId, timestamp, connection) |
297 | if connection:getIsServer() then |
298 | if streamReadBool(streamId) then |
299 | self.lastValidInputFruitType = streamReadUIntN(streamId, FruitUtil.sendNumBits); |
300 | |
301 | if not self.chopperSwitchAvailable then |
302 | if self.lastValidFillType ~= Fillable.FILLTYPE_UNKNOWN then |
303 | local fruitType = FruitUtil.fillTypeToFruitType[self.lastValidFillType]; |
304 | local fruitDesc = FruitUtil.fruitIndexToDesc[fruitType]; |
305 | self.isStrawEnabled = not fruitDesc.hasWindrow; |
306 | else |
307 | self.isStrawEnabled = false; |
308 | end; |
309 | end; |
310 | |
311 | local combineIsFilling = streamReadBool(streamId); |
312 | local chopperPSenabled = streamReadBool(streamId); |
313 | local strawPSenabled = streamReadBool(streamId); |
314 | self:setCombineIsFilling(combineIsFilling, false, true); |
315 | self:setChopperPSEnabled(chopperPSenabled, false, true); |
316 | self:setStrawPSEnabled(strawPSenabled, false, true); |
317 | end; |
318 | end; |
319 | end; |
320 | |
321 | function Combine:writeUpdateStream(streamId, connection, dirtyMask) |
322 | if not connection:getIsServer() then |
323 | if streamWriteBool(streamId, bitAND(dirtyMask, self.combineDirtyFlag) ~= 0) then |
324 | streamWriteUIntN(streamId, self.lastValidInputFruitType, FruitUtil.sendNumBits); |
325 | streamWriteBool(streamId, self.combineIsFilling); |
326 | streamWriteBool(streamId, self.chopperPSenabled); |
327 | streamWriteBool(streamId, self.strawPSenabled); |
328 | end; |
329 | end; |
330 | end; |
331 | |
332 | function Combine:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
333 | if self.chopperSwitchAvailable then |
334 | local isStrawEnabled = Utils.getNoNil(getXMLBool(xmlFile, key .. "#isStrawEnabled"), self.isStrawEnabled); |
335 | self:setIsStrawEnabled(isStrawEnabled, true, true); |
336 | end; |
337 | self.workedHectars = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#workedHectars"), self.workedHectars); |
338 | |
339 | if resetVehicles and self.foldAnimTime ~= nil and (self.fillLevel > self.foldMaxFillLevel or self.fillLevel < self.foldMinFillLevel) then |
340 | local animTime = getXMLFloat(xmlFile, key.."#foldAnimTime"); |
341 | if animTime ~= nil then |
342 | Foldable.setAnimTime(self, animTime, false) |
343 | end |
344 | end; |
345 | |
346 | return BaseMission.VEHICLE_LOAD_OK; |
347 | end; |
348 | |
349 | function Combine:getSaveAttributesAndNodes(nodeIdent) |
350 | local attributes = ""; |
351 | if self.chopperSwitchAvailable then |
352 | attributes = 'isStrawEnabled="' .. tostring(self.isStrawEnabled) ..'" workedHectars="' .. tostring(self.workedHectars) ..'"'; |
353 | end; |
354 | |
355 | return attributes, nil; |
356 | end; |
357 | |
358 | function Combine:mouseEvent(posX, posY, isDown, isUp, button) |
359 | end; |
360 | |
361 | function Combine:keyEvent(unicode, sym, modifier, isDown) |
362 | end; |
363 | |
364 | function Combine:update(dt) |
365 | |
366 | if self:getIsActive() then |
367 | if self.isClient then |
368 | if self:getIsTurnedOn() then |
369 | if self:getIsActiveForSound() then |
370 | if not Utils.isSamplePlaying(self.sampleThreshingStart, 1.8*dt) then |
371 | Utils.playSample(self.sampleThreshing, 0, 0, nil); |
372 | end; |
373 | Utils.stop3DSample(self.sampleThreshing); |
374 | else |
375 | Utils.play3DSample(self.sampleThreshing); |
376 | end |
377 | end; |
378 | |
379 | |
380 | if self.chopperSwitchAvailable then |
381 | if self:getIsActiveForInput(false) and not self:hasInputConflictWithSelection() then |
382 | if InputBinding.hasEvent(InputBinding.TOGGLE_CHOPPER) then |
383 | if self.lastValidInputFruitType ~= FruitUtil.FRUITTYPE_UNKNOWN then |
384 | local fruitDesc = FruitUtil.fruitIndexToDesc[self.lastValidInputFruitType]; |
385 | if fruitDesc.hasWindrow then |
386 | self:setIsStrawEnabled(not self.isStrawEnabled); |
387 | else |
388 | self.toggleChopperWarningTime = g_currentMission.time + 2000; |
389 | end; |
390 | else |
391 | self:setIsStrawEnabled(not self.isStrawEnabled); |
392 | end; |
393 | end; |
394 | end; |
395 | |
396 | -- check for changes while threshing, e.g. activated straw swath and then start threshing rape (has no windrow) |
397 | if self.isStrawEnabled and self.lastValidInputFruitType ~= FruitUtil.FRUITTYPE_UNKNOWN then |
398 | local fruitDesc = FruitUtil.fruitIndexToDesc[self.lastValidInputFruitType]; |
399 | if not fruitDesc.hasWindrow then |
400 | self:setIsStrawEnabled(false); |
401 | end; |
402 | end; |
403 | end; |
404 | end; |
405 | |
406 | if self.isServer then |
407 | if self.fillLevel >= self:getCapacity() and self:getCapacity() > 0 then |
408 | self:setIsTurnedOn(false); |
409 | end; |
410 | end; |
411 | end; |
412 | |
413 | if self.isClient then |
414 | Utils.updateRotationNodes(self, self.combineTurnedOnRotationNodes, dt, self:getIsActive() and self:getIsTurnedOn()); |
415 | Utils.updateScrollers(self.combineThreshingScrollers, dt, self:getIsActive() and self:getIsTurnedOn()); |
416 | |
417 | if self:getIsTurnedOn() and self.combineIsFilling then |
418 | local currentCombineThreshingFillScrollers = self.combineThreshingFillScrollers[self.lastValidFillType]; |
419 | if currentCombineThreshingFillScrollers ~= self.currentCombineThreshingFillScrollers and self.currentCombineThreshingFillScrollers ~= nil then |
420 | self.lastCombineThreshingFillScrollers = self.currentCombineThreshingFillScrollers; |
421 | end; |
422 | self.currentCombineThreshingFillScrollers = currentCombineThreshingFillScrollers; |
423 | |
424 | if self.currentCombineThreshingFillScrollers ~= nil then |
425 | Utils.updateScrollers(self.currentCombineThreshingFillScrollers, dt, true, true); |
426 | end; |
427 | else |
428 | if self.currentCombineThreshingFillScrollers ~= nil then |
429 | if self.currentCombineThreshingFillScrollers.isRunning then |
430 | Utils.updateScrollers(self.currentCombineThreshingFillScrollers, dt, false, true); |
431 | else |
432 | Utils.updateScrollers(self.currentCombineThreshingFillScrollers, dt, false, false); |
433 | self.currentCombineThreshingFillScrollers = nil; |
434 | end; |
435 | end; |
436 | end; |
437 | if self.lastCombineThreshingFillScrollers ~= nil then |
438 | Utils.updateScrollers(self.lastCombineThreshingFillScrollers, dt, false, false); |
439 | self.lastCombineThreshingFillScrollers = nil; |
440 | end; |
441 | end; |
442 | end; |
443 | |
444 | function Combine:updateTick(dt) |
445 | if self.isServer then |
446 | self.lastArea = self.lastCuttersArea; |
447 | self.lastAreaZeroTime = self.lastAreaZeroTime + dt; |
448 | if self.lastArea > 0 then |
449 | self.lastAreaZeroTime = 0; |
450 | self.lastAreaNonZeroTime = g_currentMission.time; |
451 | end |
452 | self.lastInputFruitType = self.lastCuttersInputFruitType; |
453 | self.lastCuttersArea = 0; |
454 | self.lastCuttersInputFruitType = FruitUtil.FRUITTYPE_UNKNOWN; |
455 | self.lastCuttersFruitType = FruitUtil.FRUITTYPE_UNKNOWN; |
456 | |
457 | if self.lastInputFruitType ~= FruitUtil.FRUITTYPE_UNKNOWN then |
458 | self.lastValidInputFruitType = self.lastInputFruitType; |
459 | end; |
460 | |
461 | if self:getIsActive() then |
462 | if self.lastAreaZeroTime > 500 or not self.isStrawEnabled then |
463 | if self.strawDisableTime == nil then |
464 | self.strawDisableTime = g_currentMission.time + self.chopperToggleTime; |
465 | end |
466 | end |
467 | if self.lastAreaZeroTime > 500 or self.isStrawEnabled then |
468 | if self.chopperDisableTime == nil then |
469 | self.chopperDisableTime = g_currentMission.time + self.strawToggleTime; |
470 | end |
471 | end |
472 | if self.lastAreaZeroTime > 500 then |
473 | if self.combineFillDisableTime == nil then |
474 | self.combineFillDisableTime = g_currentMission.time + self.combineFillToggleTime; |
475 | end |
476 | end |
477 | |
478 | if self.chopperEnableTime ~= nil and self.chopperEnableTime <= g_currentMission.time then |
479 | self:setChopperPSEnabled(true, false, false); |
480 | self.chopperEnableTime = nil; |
481 | end; |
482 | if self.strawEnableTime ~= nil and self.strawEnableTime <= g_currentMission.time then |
483 | self:setStrawPSEnabled(true, false, false); |
484 | self.strawEnableTime = nil; |
485 | end; |
486 | if self.combineFillEnableTime ~= nil and self.combineFillEnableTime <= g_currentMission.time then |
487 | self:setCombineIsFilling(true, false, false); |
488 | self.combineFillEnableTime = nil; |
489 | end; |
490 | if self.chopperDisableTime ~= nil and self.chopperDisableTime <= g_currentMission.time then |
491 | self:setChopperPSEnabled(false, false, false); |
492 | self.chopperDisableTime = nil; |
493 | end; |
494 | if self.strawDisableTime ~= nil and self.strawDisableTime <= g_currentMission.time then |
495 | self:setStrawPSEnabled(false, false, false); |
496 | self.strawDisableTime = nil; |
497 | end; |
498 | if self.combineFillDisableTime ~= nil and self.combineFillDisableTime <= g_currentMission.time then |
499 | self:setCombineIsFilling(false, false, false); |
500 | self.combineFillDisableTime = nil; |
501 | end; |
502 | |
503 | if self.strawPSenabled and self.lastValidFillType ~= Fillable.FILLTYPE_UNKNOWN then |
504 | local timeUntilDisable = self.strawToggleTime; |
505 | if self.strawDisableTime ~= nil then |
506 | timeUntilDisable = self.strawDisableTime-g_currentMission.time; |
507 | end |
508 | -- drop at as much such that we finish when straw is disabled |
509 | local numToDrop = math.min(dt * self.strawAreaToDrop/timeUntilDisable, self.strawAreaToDrop); |
510 | |
511 | self.strawAreaToDrop = self.strawAreaToDrop - numToDrop; |
512 | local typedWorkAreas = self:getTypedWorkAreas(WorkArea.AREATYPE_COMBINE); |
513 | local workAreasSend = {}; |
514 | for i, workArea in pairs(typedWorkAreas) do |
515 | local x,y,z = getWorldTranslation(workArea.start); |
516 | local x1,y1,z1 = getWorldTranslation(workArea.width); |
517 | local x2,y2,z2 = getWorldTranslation(workArea.height); |
518 | --local old, total = Utils.getFruitWindrowArea(self.strawPSFruitType, x, z, x1, z1, x2, z2); |
519 | --local value = 1+math.floor(old / total + 0.7); -- round, biased to the bigger value |
520 | --value = math.min(value, g_currentMission.maxWindrowValue); |
521 | local value = numToDrop/table.getn(typedWorkAreas); |
522 | self.accumulatedStrawAreaValues[i] = self.accumulatedStrawAreaValues[i] + numToDrop/table.getn(typedWorkAreas); |
523 | value = self.accumulatedStrawAreaValues[i]; |
524 | self.accumulatedStrawAreaValues[i] = 0; |
525 | |
526 | table.insert(workAreasSend, {x,z,x1,z1,x2,z2,value}); |
527 | end; |
528 | |
529 | if (table.getn(workAreasSend) > 0) then |
530 | local workAreasSend, bitType = CombineAreaEvent.runLocally(workAreasSend, self.lastValidFillType, self.accumulatedStrawAreaValues); |
531 | if (table.getn(workAreasSend) > 0) then |
532 | g_server:broadcastEvent(CombineAreaEvent:new(workAreasSend, bitType, self.lastValidFillType)); |
533 | end |
534 | end; |
535 | end; |
536 | |
537 | if self:getIsTurnedOn() then |
538 | g_currentMission.missionStats:updateStats("threshingDuration", dt/(1000*60)); |
539 | end |
540 | end |
541 | |
542 | if self:getCapacity() <= 0 then |
543 | self.lastLostFillLevel = self.fillLevel; |
544 | if self.fillLevel > 0 then |
545 | self:setFillLevel(0, self.currentFillType); |
546 | end |
547 | end |
548 | |
549 | if self.combineIsFilling ~= self.sentCombineIsFilling or |
550 | self.chopperPSenabled ~= self.sentChopperPSenabled or |
551 | self.strawPSenabled ~= self.sentStrawPSenabled |
552 | then |
553 | self:raiseDirtyFlags(self.combineDirtyFlag); |
554 | self.sentCombineIsFilling = self.combineIsFilling; |
555 | self.sentChopperPSenabled = self.chopperPSenabled; |
556 | self.sentStrawPSenabled = self.strawPSenabled; |
557 | end; |
558 | end; |
559 | end; |
560 | |
561 | function Combine:draw() |
562 | if self.isClient then |
563 | local percent = 0; |
564 | if self:getCapacity() > 0 then |
565 | percent = self.fillLevel/self:getCapacity()*100; |
566 | if self.currentPipeState ~= nil and self.currentPipeState == 2 and not self.pipeIsUnloading and self.fillLevel > 0 then |
567 | g_currentMission:addExtraPrintText(g_i18n:getText("Move_the_pipe_over_a_trailer")); |
568 | elseif self.fillLevel == self:getCapacity() then |
569 | g_currentMission:addExtraPrintText(g_i18n:getText("Dump_corn_to_continue_threshing")); |
570 | end; |
571 | end; |
572 | |
573 | if self:getIsTurnedOn() and not self:getIsThreshingAllowed(false) then |
574 | g_currentMission:showBlinkingWarning(g_i18n:getText("Dont_do_threshing_during_rain_or_hail"), 2000); |
575 | end; |
576 | |
577 | if self.chopperSwitchAvailable then |
578 | if self:getIsActiveForInput() then |
579 | local fruitDesc = FruitUtil.fruitIndexToDesc[self.lastValidInputFruitType]; |
580 | if self.lastValidInputFruitType == FruitUtil.FRUITTYPE_UNKNOWN or fruitDesc.hasWindrow then |
581 | if self.isStrawEnabled then |
582 | g_currentMission:addHelpButtonText(g_i18n:getText("DISABLE_STRAW_SWATH"), InputBinding.TOGGLE_CHOPPER); |
583 | else |
584 | g_currentMission:addHelpButtonText(g_i18n:getText("ENABLE_STRAW_SWATH"), InputBinding.TOGGLE_CHOPPER); |
585 | end; |
586 | end; |
587 | end; |
588 | |
589 | if self.toggleChopperWarningTime > g_currentMission.time then |
590 | g_currentMission:showBlinkingWarning(g_i18n:getText("COULD_NOT_TOGGLE_CHOPPER"), 2000); |
591 | end; |
592 | end; |
593 | end; |
594 | end; |
595 | |
596 | function Combine:onDeactivate() |
597 | self:setChopperPSEnabled(false, false, true); |
598 | self:setStrawPSEnabled(false, false, true); |
599 | self:setCombineIsFilling(false, false, true); |
600 | |
601 | self.chopperEnableTime = nil; |
602 | self.chopperDisableTime = nil; |
603 | self.strawEnableTime = nil; |
604 | self.strawDisableTime = nil; |
605 | self.combineFillEnableTime = nil; |
606 | self.combineFillDisableTime = nil; |
607 | end; |
608 | |
609 | function Combine:onDeactivateSounds() |
610 | if self.isClient then |
611 | Utils.stopSample(self.sampleThreshing, true); |
612 | Utils.stopSample(self.sampleThreshingStart, true); |
613 | end; |
614 | end; |
615 | |
616 | function Combine:attachImplement(implement) |
617 | local object = implement.object; |
618 | if object.attacherJoint.jointType == Vehicle.JOINTTYPE_CUTTER or object.attacherJoint.jointType == Vehicle.JOINTTYPE_CUTTERHARVESTER then |
619 | self.attachedCutters[object] = implement; |
620 | self.numAttachedCutters = self.numAttachedCutters+1; |
621 | end; |
622 | end; |
623 | |
624 | function Combine:detachImplement(implementIndex) |
625 | local object = self.attachedImplements[implementIndex].object; |
626 | if object ~= nil then |
627 | if object.attacherJoint.jointType == Vehicle.JOINTTYPE_CUTTER or object.attacherJoint.jointType == Vehicle.JOINTTYPE_CUTTERHARVESTER then |
628 | self.numAttachedCutters = self.numAttachedCutters-1; |
629 | if self.numAttachedCutters == 0 then |
630 | self:setIsTurnedOn(false, true); |
631 | end; |
632 | self.attachedCutters[object] = nil; |
633 | end; |
634 | end |
635 | end; |
636 | |
637 | function Combine:startThreshing() |
638 | if self.numAttachedCutters > 0 then |
639 | for cutter,implement in pairs(self.attachedCutters) do |
640 | if cutter ~= self then |
641 | self:setJointMoveDown(implement.jointDescIndex, true, true); |
642 | end |
643 | cutter:onStartReel(); |
644 | end |
645 | if self.threshingStartAnimation ~= nil and self.playAnimation ~= nil then |
646 | self:playAnimation(self.threshingStartAnimation, self.threshingStartAnimationSpeedScale, self:getAnimationTime(self.threshingStartAnimation), true); |
647 | end |
648 | |
649 | if self.isClient then |
650 | Utils.stopSample(self.sampleThreshingStop, true); |
651 | if self:getIsActiveForSound() then |
652 | Utils.playSample(self.sampleThreshingStart, 1, 0, nil); |
653 | end; |
654 | end; |
655 | end; |
656 | end; |
657 | |
658 | function Combine:stopThreshing() |
659 | if self.isClient then |
660 | Utils.stopSample(self.sampleThreshing, true); |
661 | Utils.stopSample(self.sampleThreshingStart, true); |
662 | Utils.stop3DSample(self.sampleThreshing); |
663 | |
664 | if self:getIsActiveForSound() then |
665 | Utils.playSample(self.sampleThreshingStop, 1, 0, nil); |
666 | end |
667 | end; |
668 | |
669 | self:setCombineIsFilling(false, false, true); |
670 | |
671 | for cutter,implement in pairs(self.attachedCutters) do |
672 | if cutter ~= self then |
673 | self:setJointMoveDown(implement.jointDescIndex, false, true); |
674 | end |
675 | cutter:onStopReel(); |
676 | end; |
677 | if self.threshingStartAnimation ~= nil and self.playAnimation ~= nil then |
678 | self:playAnimation(self.threshingStartAnimation, -self.threshingStartAnimationSpeedScale, self:getAnimationTime(self.threshingStartAnimation), true); |
679 | end |
680 | end; |
681 | |
682 | function Combine:getNeedsCutterFolding() |
683 | if self.attachedCutters[self] == nil then |
684 | for cutter, _ in pairs(self.attachedCutters) do |
685 | if cutter.getIsTurnedOnAllowed ~= nil and not cutter:getIsTurnedOnAllowed(true) then |
686 | if (cutter.foldAnimTime > cutter.turnOnFoldMaxLimit or cutter.foldAnimTime < cutter.turnOnFoldMinLimit) then |
687 | return cutter.unfoldWarning; |
688 | end; |
689 | end; |
690 | end; |
691 | end; |
692 | return nil; |
693 | end; |
694 | |
695 | function Combine:getIsTurnedOnAllowed(superFunc, isTurnedOn) |
696 | if self.numAttachedCutters <= 0 then |
697 | return false; |
698 | else |
699 | if self.attachedCutters[self] == nil then |
700 | for cutter, _ in pairs(self.attachedCutters) do |
701 | if cutter.getIsTurnedOnAllowed ~= nil and not cutter:getIsTurnedOnAllowed(isTurnedOn) then |
702 | return false; |
703 | end; |
704 | end; |
705 | end; |
706 | |
707 | -- dismissed, because helper would stop working and player should be able to start combine whenever he wants |
708 | --if self:getCapacity() > 0 and self.fillLevel == self:getCapacity() then |
709 | -- return false; |
710 | --end; |
711 | end |
712 | |
713 | if superFunc ~= nil then |
714 | return superFunc(self, isTurnedOn); |
715 | end |
716 | |
717 | return true; |
718 | end; |
719 | |
720 | function Combine:onTurnedOn(noEventSend) |
721 | self:startThreshing(); |
722 | end; |
723 | |
724 | function Combine:onTurnedOff(noEventSend) |
725 | self:stopThreshing(); |
726 | end; |
727 | |
728 | function Combine:setLastValidFillType(lastValidFillType, hasChanged) |
729 | if self.chopperPSenabled then |
730 | self:setChopperPSEnabled(true, hasChanged, true); |
731 | end |
732 | if self.strawPSenabled then |
733 | self:setStrawPSEnabled(true, hasChanged, true); |
734 | end |
735 | if self.combineIsFilling then |
736 | self:setCombineIsFilling(true, hasChanged, true); |
737 | end |
738 | end |
739 | |
740 | function Combine:setCombineIsFilling(combineIsFilling, fruitTypeChanged, isSynchronized) |
741 | if self.combineIsFilling ~= combineIsFilling or fruitTypeChanged then |
742 | self.combineIsFilling = combineIsFilling; |
743 | if self.isServer and isSynchronized then |
744 | self.sentCombineIsFilling = combineIsFilling; |
745 | end |
746 | |
747 | if self.currentCombineThreshingFillParticleSystem ~= nil then |
748 | Utils.setEmittingState(self.currentCombineThreshingFillParticleSystem, false); |
749 | self.currentCombineThreshingFillParticleSystem = nil; |
750 | end; |
751 | |
752 | if self.fillEffect ~= nil and (not combineIsFilling or fruitTypeChanged) then |
753 | EffectManager:stopEffect(self.fillEffect) |
754 | end |
755 | |
756 | if combineIsFilling then |
757 | self.currentCombineThreshingFillParticleSystem = self.combineThreshingFillParticleSystems[self.lastValidFillType]; |
758 | Utils.setEmittingState(self.currentCombineThreshingFillParticleSystem, true); |
759 | if self.fillEffect ~= nil then |
760 | self.fillEffect:setFillType(self.lastValidFillType); |
761 | EffectManager:startEffect(self.fillEffect) |
762 | end; |
763 | end |
764 | end |
765 | end |
766 | |
767 | function Combine:setChopperPSEnabled(chopperPSenabled, fruitTypeChanged, isSynchronized) |
768 | if self.chopperPSenabled ~= chopperPSenabled or fruitTypeChanged then |
769 | if self.currentChopperParticleSystem ~= nil then |
770 | Utils.setEmittingState(self.currentChopperParticleSystem, false); |
771 | self.currentChopperParticleSystem = nil; |
772 | end; |
773 | |
774 | if self.chopperEffect ~= nil and (not chopperPSenabled or fruitTypeChanged) then |
775 | EffectManager:stopEffect(self.chopperEffect) |
776 | end |
777 | |
778 | self.chopperPSenabled = chopperPSenabled; |
779 | if self.isServer and isSynchronized then |
780 | self.sentChopperPSenabled = chopperPSenabled; |
781 | end |
782 | if chopperPSenabled and self.isClient then |
783 | self.currentChopperParticleSystem = self.chopperParticleSystems[self.lastValidFillType]; |
784 | if self.currentChopperParticleSystem == nil then |
785 | self.currentChopperParticleSystem = self.defaultChopperParticleSystem; |
786 | end; |
787 | Utils.setEmittingState(self.currentChopperParticleSystem, true); |
788 | |
789 | if self.chopperEffect ~= nil then |
790 | self.chopperEffect:setFillType(self.lastValidFillType); |
791 | EffectManager:startEffect(self.chopperEffect) |
792 | end; |
793 | end; |
794 | end |
795 | end |
796 | |
797 | function Combine:setStrawPSEnabled(strawPSenabled, fruitTypeChanged, isSynchronized) |
798 | if self.strawPSenabled ~= strawPSenabled or fruitTypeChanged then |
799 | if self.currentStrawParticleSystem ~= nil then |
800 | Utils.setEmittingState(self.currentStrawParticleSystem, false); |
801 | self.currentStrawParticleSystem = nil; |
802 | end; |
803 | |
804 | if self.strawEffect ~= nil and (not strawPSenabled or fruitTypeChanged) then |
805 | EffectManager:stopEffect(self.strawEffect) |
806 | end |
807 | |
808 | self.strawPSenabled = strawPSenabled; |
809 | if self.isServer and isSynchronized then |
810 | self.sentStrawPSenabled = strawPSenabled; |
811 | end |
812 | if not strawPSenabled and self.accumulatedStrawAreaValues ~= nil then |
813 | self.strawAreaToDrop = 0; |
814 | for i,_ in pairs(self.accumulatedStrawAreaValues) do |
815 | self.accumulatedStrawAreaValues[i] = 0; |
816 | end |
817 | end |
818 | if strawPSenabled and self.isClient then |
819 | self.currentStrawParticleSystem = self.strawParticleSystems[self.lastValidFillType]; |
820 | if self.currentStrawParticleSystem == nil then |
821 | self.currentStrawParticleSystem = self.defaultStrawParticleSystem; |
822 | end; |
823 | Utils.setEmittingState(self.currentStrawParticleSystem, true); |
824 | |
825 | if self.strawEffect ~= nil then |
826 | self.strawEffect:setFillType(self.lastValidFillType); |
827 | EffectManager:startEffect(self.strawEffect); |
828 | end; |
829 | end; |
830 | end |
831 | end |
832 | |
833 | function Combine:getIsCutterFruitTypeAllowed(fruitType) |
834 | local outputFruitType = fruitType; |
835 | if self.convertedFruits[fruitType] ~= nil then |
836 | outputFruitType = self.convertedFruits[fruitType]; |
837 | end; |
838 | return self:allowFillType(FruitUtil.fruitTypeToFillType[outputFruitType], false); |
839 | end |
840 | |
841 | function Combine:addCutterArea(cutter, area, realArea, inputFruitType, fruitType) |
842 | if area > 0 and (self.lastCuttersFruitType == FruitUtil.FRUITTYPE_UNKNOWN or self.lastCuttersArea == 0 or self.lastCuttersFruitType == fruitType) then |
843 | self.lastCuttersArea = self.lastCuttersArea + area; |
844 | self.lastCuttersFruitType = fruitType; |
845 | self.lastCuttersInputFruitType = inputFruitType; |
846 | self.lastCuttersAreaTime = g_currentMission.time; |
847 | local outputFruitType = fruitType; |
848 | if self.convertedFruits[fruitType] ~= nil then |
849 | outputFruitType = self.convertedFruits[fruitType]; |
850 | end; |
851 | |
852 | if not self.chopperSwitchAvailable then |
853 | local fruitDesc = FruitUtil.fruitIndexToDesc[outputFruitType]; |
854 | self.isStrawEnabled = not fruitDesc.hasWindrow; |
855 | end; |
856 | |
857 | if self.isStrawEnabled then |
858 | self.strawAreaToDrop = self.strawAreaToDrop + realArea; |
859 | if self.strawEnableTime == nil then |
860 | self.strawEnableTime = g_currentMission.time + self.strawToggleTime; |
861 | end |
862 | self.strawDisableTime = nil; |
863 | else |
864 | if self.chopperEnableTime == nil then |
865 | self.chopperEnableTime = g_currentMission.time + self.chopperToggleTime; |
866 | end |
867 | self.chopperDisableTime = nil; |
868 | end |
869 | |
870 | if self.combineFillEnableTime == nil then |
871 | self.combineFillEnableTime = g_currentMission.time + self.combineFillToggleTime; |
872 | end; |
873 | self.combineFillDisableTime = nil; |
874 | |
875 | -- 8000/1200 = 6.66 liter/meter |
876 | -- 8000/1200 / 6 = 1.111 liter/m^2 |
877 | -- 8000/1200 / 6 / 2^2 = 0.277777 liter / density pixel (density is 4096^2, on a area of 2048m^2 |
878 | local pixelToSqm = g_currentMission:getFruitPixelsToSqm(); -- 4096px are mapped to 2048m |
879 | local literPerSqm = 1; |
880 | if (fruitType ~= FruitUtil.FRUITTYPE_UNKNOWN) then |
881 | literPerSqm = FruitUtil.fruitIndexToDesc[fruitType].literPerSqm; -- * (1 + 0.5 * (3 - g_currentMission.missionStats.difficulty)); |
882 | if (inputFruitType ~= fruitType and inputFruitType ~= FruitUtil.FRUITTYPE_UNKNOWN) then |
883 | literPerSqm = literPerSqm * FruitUtil.fruitIndexToDesc[inputFruitType].literPerSqm; |
884 | end; |
885 | if (outputFruitType ~= fruitType and outputFruitType ~= FruitUtil.FRUITTYPE_UNKNOWN) then |
886 | literPerSqm = literPerSqm * FruitUtil.fruitIndexToDesc[outputFruitType].literPerSqm; |
887 | end; |
888 | end; |
889 | |
890 | local sqm = area*pixelToSqm; |
891 | |
892 | local deltaFillLevel = sqm*literPerSqm*self.threshingScale; |
893 | |
894 | local newFillLevel = self.fillLevel+deltaFillLevel; |
895 | |
896 | local fillType = FruitUtil.fruitTypeToFillType[outputFruitType]; |
897 | |
898 | self.workedHectars = self.workedHectars + Utils.areaToHa(realArea, g_currentMission:getFruitPixelsToSqm()); |
899 | |
900 | local x,y,z = getWorldTranslation(self.fillVolumeLoadInfo.node); |
901 | |
902 | local d1x,d1y,d1z = localDirectionToWorld(self.fillVolumeLoadInfo.node, self.fillVolumeLoadInfo.width,0,0); |
903 | local d2x,d2y,d2z = localDirectionToWorld(self.fillVolumeLoadInfo.node, 0,0,self.fillVolumeLoadInfo.length); |
904 | local fillSourceStruct = {x=x,y=y,z=z, d1x=d1x,d1y=d1y,d1z=d1z, d2x=d2x,d2y=d2y,d2z=d2z}; |
905 | |
906 | self:setFillLevel(newFillLevel, fillType, false, fillSourceStruct); |
907 | end; |
908 | end |
909 | |
910 | function Combine:getIsThreshingAllowed(earlyWarning) |
911 | if self.allowThreshingDuringRain then |
912 | return true; |
913 | end; |
914 | if earlyWarning ~= nil and earlyWarning == true then |
915 | if g_currentMission.environment.lastRainScale <= 0.02 and g_currentMission.environment.timeSinceLastRain > 20 then |
916 | return true; |
917 | end; |
918 | else |
919 | if g_currentMission.environment.lastRainScale <= 0.1 and g_currentMission.environment.timeSinceLastRain > 20 then |
920 | return true; |
921 | end; |
922 | end; |
923 | return false; |
924 | end; |
925 | |
926 | function Combine:getIsFoldAllowed(superFunc) |
927 | if (not self.allowFoldWhileThreshing and self:getIsTurnedOn()) then |
928 | return false; |
929 | end |
930 | if self.foldAnimTime ~= nil and (self.fillLevel > self.foldMaxFillLevel or self.fillLevel < self.foldMinFillLevel) then |
931 | return false; |
932 | end |
933 | |
934 | if superFunc ~= nil then |
935 | return superFunc(self); |
936 | end |
937 | return true; |
938 | end |
939 | |
940 | function Combine:getTurnedOnNotAllowedWarning(superFunc) |
941 | if self.isSelectable == nil or self:getIsActiveForInput(true) then |
942 | if not self:getIsTurnedOnAllowed(true) then |
943 | local warning = self:getNeedsCutterFolding(); |
944 | if warning ~= nil then |
945 | return warning; |
946 | end; |
947 | end; |
948 | end; |
949 | |
950 | if superFunc ~= nil then |
951 | return superFunc(self); |
952 | end |
953 | return nil; |
954 | end; |
955 | |
956 | function Combine:setIsStrawEnabled(isStrawEnabled, noEventSend, force) |
957 | if isStrawEnabled ~= self.isStrawEnabled or force then |
958 | CombineStrawEnableEvent.sendEvent(self, isStrawEnabled, noEventSend); |
959 | self.isStrawEnabled = isStrawEnabled; |
960 | |
961 | if self.playAnimation ~= nil and self.toggleChopperAnimName ~= nil then |
962 | local dir = 1; |
963 | if isStrawEnabled then |
964 | dir = -1; |
965 | end; |
966 | self:playAnimation(self.toggleChopperAnimName, dir, self:getAnimationTime(self.toggleChopperAnimName), true); |
967 | end; |
968 | |
969 | -- change ps |
970 | if self.isStrawEnabled then |
971 | self.strawDisableTime = self.chopperDisableTime; |
972 | self.chopperDisableTime = g_currentMission.time; |
973 | if self.chopperPSenabled then |
974 | self.strawEnableTime = g_currentMission.time; |
975 | else |
976 | self.strawEnableTime = self.chopperEnableTime; |
977 | end; |
978 | self.chopperEnableTime = nil; |
979 | else |
980 | self.chopperDisableTime = self.strawDisableTime; |
981 | self.strawDisableTime = g_currentMission.time; |
982 | if self.strawPSenabled then |
983 | self.chopperEnableTime = g_currentMission.time; |
984 | else |
985 | self.chopperEnableTime = self.strawEnableTime; |
986 | end; |
987 | self.strawEnableTime = nil; |
988 | end |
989 | end; |
990 | end; |
991 | |
992 | function Combine:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
993 | local retValue = true; |
994 | if superFunc ~= nil then |
995 | retValue = superFunc(self, workArea, xmlFile, key) |
996 | end |
997 | |
998 | if workArea.type == WorkArea.AREATYPE_DEFAULT then |
999 | workArea.type = WorkArea.AREATYPE_COMBINE; |
1000 | end; |
1001 | |
1002 | if workArea.type == WorkArea.AREATYPE_COMBINE then |
1003 | if self.accumulatedStrawAreaValues == nil then |
1004 | self.accumulatedStrawAreaValues = {}; |
1005 | end; |
1006 | self.accumulatedStrawAreaValues[table.getn(self.accumulatedStrawAreaValues)+1] = 0; |
1007 | end; |
1008 | |
1009 | return retValue; |
1010 | end; |
1011 | |
1012 | function Combine:getDoRenderFillType(superFunc) |
1013 | if self.currentFillType ~= Fillable.FILLTYPE_UNKNOWN then |
1014 | return true; |
1015 | elseif self.lastValidFillType ~= Fillable.FILLTYPE_UNKNOWN and self.lastCuttersAreaTime + 250 > g_currentMission.time then |
1016 | return true; |
1017 | end; |
1018 | |
1019 | if superFunc ~= nil then |
1020 | return superFunc(self); |
1021 | end |
1022 | end; |
1023 | |
1024 | function Combine:getOverlayFillType(superFunc) |
1025 | if self.currentFillType ~= Fillable.FILLTYPE_UNKNOWN then |
1026 | return self.currentFillType; |
1027 | elseif self.lastValidFillType ~= Fillable.FILLTYPE_UNKNOWN and self.lastCuttersAreaTime + 250 > g_currentMission.time then |
1028 | return self.lastValidFillType; |
1029 | end; |
1030 | |
1031 | if superFunc ~= nil then |
1032 | return superFunc(self); |
1033 | end |
1034 | |
1035 | return Fillable.FILLTYPE_UNKNOWN; |
1036 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de