131 | function StrawBlower:addFillUnitFillLevel(superFunc, farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData) |
132 | local spec = self.spec_strawBlower |
133 | if fillUnitIndex == spec.fillUnitIndex then |
134 | self:setFillUnitCapacity(fillUnitIndex, math.max(self:getFillUnitCapacity(fillUnitIndex), self:getFillUnitFillLevel(fillUnitIndex)+fillLevelDelta)) |
135 | end |
136 | |
137 | return superFunc(self, farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData) |
138 | end |
87 | function StrawBlower:onDelete() |
88 | local spec = self.spec_strawBlower |
89 | |
90 | if self.isServer then |
91 | if spec.triggerId ~= nil then |
92 | removeTrigger(spec.triggerId) |
93 | end |
94 | |
95 | for bale, _ in pairs(spec.triggeredBales) do |
96 | if entityExists(bale.nodeId) then |
97 | I3DUtil.wakeUpObject(bale.nodeId) |
98 | end |
99 | end |
100 | end |
101 | |
102 | if self.isClient then |
103 | g_soundManager:deleteSamples(spec.samples) |
104 | g_animationManager:deleteAnimations(spec.animationNodes) |
105 | end |
106 | end |
239 | function StrawBlower:onDischargeStateChanged(state) |
240 | local spec = self.spec_strawBlower |
241 | local samples = spec.samples |
242 | if self.isClient then |
243 | if state ~= Dischargeable.DISCHARGE_STATE_OFF then |
244 | g_soundManager:stopSample(samples.work) |
245 | g_soundManager:stopSample(samples.stop) |
246 | g_soundManager:playSample(samples.start) |
247 | g_soundManager:playSample(samples.work, 0, samples.start) |
248 | g_animationManager:startAnimations(spec.animationNodes) |
249 | else |
250 | g_soundManager:stopSample(samples.start) |
251 | g_soundManager:stopSample(samples.work) |
252 | g_soundManager:playSample(samples.stop) |
253 | g_animationManager:stopAnimations(spec.animationNodes) |
254 | end |
255 | end |
256 | end |
204 | function StrawBlower:onFillUnitFillLevelChanged(fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData, appliedDelta) |
205 | local spec = self.spec_strawBlower |
206 | if fillUnitIndex == spec.fillUnitIndex then |
207 | local newFillLevel = self:getFillUnitFillLevel(spec.fillUnitIndex) |
208 | |
209 | if self.isServer then |
210 | local bale = spec.currentBale |
211 | if bale ~= nil then |
212 | if newFillLevel <= 0.01 then |
213 | if self.removeDynamicMountedObject ~= nil then |
214 | self:removeDynamicMountedObject(bale) |
215 | end |
216 | |
217 | local baleOwner = bale:getOwnerFarmId() |
218 | |
219 | bale:delete() |
220 | spec.currentBale = nil |
221 | spec.triggeredBales[bale] = nil |
222 | |
223 | self:setFillUnitCapacity(spec.fillUnitIndex, 1) |
224 | self:addFillUnitFillLevel(baleOwner, spec.fillUnitIndex, -math.huge, FillType.UNKNOWN, ToolType.UNDEFINED) |
225 | elseif newFillLevel < bale:getFillLevel() and fillTypeIndex == bale:getFillType() then |
226 | bale:setFillLevel(newFillLevel) |
227 | end |
228 | end |
229 | else |
230 | if newFillLevel <= 0 then |
231 | self:setFillUnitCapacity(spec.fillUnitIndex, 1) |
232 | end |
233 | end |
234 | end |
235 | end |
49 | function StrawBlower:onLoad(savegame) |
50 | local spec = self.spec_strawBlower |
51 | |
52 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.strawBlower.baleTrigger#index", "vehicle.strawBlower.baleTrigger#node") --FS17 to FS19 |
53 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.strawBlower.doorAnimation#name", "vehicle.foldable.foldingParts.foldingPart.animationName") --FS17 to FS19 |
54 | |
55 | spec.triggeredBales = {} |
56 | |
57 | if self.isServer then |
58 | spec.triggerId = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.strawBlower.baleTrigger#node"), self.i3dMappings) |
59 | if spec.triggerId ~= nil then |
60 | addTrigger(spec.triggerId, "strawBlowerBaleTriggerCallback", self) |
61 | end |
62 | end |
63 | |
64 | if self.isClient then |
65 | spec.animationNodes = g_animationManager:loadAnimations(self.xmlFile, "vehicle.strawBlower.animationNodes", self.components, self, self.i3dMappings) |
66 | |
67 | spec.samples = {} |
68 | spec.samples.start = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.strawBlower.sounds", "start", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self) |
69 | spec.samples.stop = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.strawBlower.sounds", "stop", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self) |
70 | spec.samples.work = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.strawBlower.sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
71 | end |
72 | |
73 | spec.fillUnitIndex = Utils.getNoNil(getXMLInt(self.xmlFile, "vehicle.strawBlower#fillUnitIndex"), 1) |
74 | |
75 | -- we need to send the full fill level rather than percentages since we change the capacity |
76 | local fillUnit = self:getFillUnitByIndex(spec.fillUnitIndex) |
77 | fillUnit.synchronizeFullFillLevel = true |
78 | fillUnit.needsSaving = false |
79 | |
80 | if savegame ~= nil and not savegame.resetVehicles then |
81 | self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, -math.huge, FillType.UNKNOWN, ToolType.UNDEFINED) |
82 | end |
83 | end |
113 | function StrawBlower:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
114 | local spec = self.spec_strawBlower |
115 | |
116 | if self.isServer then |
117 | if spec.currentBale == nil and self:getFillUnitSupportsToolType(spec.fillUnitIndex, ToolType.BALE) then |
118 | local bale = next(spec.triggeredBales) |
119 | if bale ~= nil then |
120 | self:setFillUnitCapacity(spec.fillUnitIndex, bale:getFillLevel()) |
121 | self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, -math.huge, FillType.UNKNOWN, ToolType.UNDEFINED) |
122 | self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, bale:getFillLevel(), bale:getFillType(), ToolType.BALE) |
123 | spec.currentBale = bale |
124 | end |
125 | end |
126 | end |
127 | end |
148 | function StrawBlower:strawBlowerBaleTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
149 | local spec = self.spec_strawBlower |
150 | |
151 | if onEnter then |
152 | -- this happens if a compound child of a deleted compound is entering |
153 | if otherActorId ~= 0 then |
154 | local object = g_currentMission:getNodeObject(otherActorId) |
155 | if object ~= nil then |
156 | if object:isa(Bale) and g_currentMission.accessHandler:canFarmAccess(self:getActiveFarm(), object) then |
157 | if self:getFillUnitSupportsFillType(spec.fillUnitIndex, object:getFillType()) then |
158 | spec.triggeredBales[object] = Utils.getNoNil(spec.triggeredBales[object], 0) + 1 |
159 | end |
160 | end |
161 | end |
162 | end |
163 | elseif onLeave then |
164 | if otherActorId ~= 0 then |
165 | local object = g_currentMission:getNodeObject(otherActorId) |
166 | if object ~= nil then |
167 | local triggerCount = spec.triggeredBales[object] |
168 | if triggerCount ~= nil then |
169 | if triggerCount == 1 then |
170 | spec.triggeredBales[object] = nil |
171 | if object == spec.currentBale then |
172 | spec.currentBale = nil |
173 | self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, -math.huge, self:getFillUnitFillType(spec.fillUnitIndex), ToolType.UNDEFINED) |
174 | end |
175 | else |
176 | spec.triggeredBales[object] = triggerCount-1 |
177 | end |
178 | end |
179 | end |
180 | end |
181 | end |
182 | end |