LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

StrawBlower

Description
Specialization for straw blowers providing functionality to dissipate a bale to lose straw
Functions

addFillUnitFillLevel

Description
Definition
addFillUnitFillLevel()
Code
131function 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)
138end

getAllowDynamicMountFillLevelInfo

Description
Definition
getAllowDynamicMountFillLevelInfo()
Code
193function StrawBlower:getAllowDynamicMountFillLevelInfo(superFunc)
194 return false
195end

getDrawFirstFillText

Description
Definition
getDrawFirstFillText()
Code
186function StrawBlower:getDrawFirstFillText(superFunc)
187 local spec = self.spec_strawBlower
188 return superFunc(self) or self:getFillUnitFillLevel(spec.fillUnitIndex) <= 0
189end

onDelete

Description
Called on deleting
Definition
onDelete()
Code
87function 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
106end

onDischargeStateChanged

Description
Called on discharge state change
Definition
onDischargeStateChanged()
Code
239function 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
256end

onFillUnitFillLevelChanged

Description
Set unit fill level
Definition
onFillUnitFillLevelChanged(integer fillUnitIndex, float fillLevel, integer fillType, boolean force, table fillInfo)
Arguments
integerfillUnitIndexindex of fill unit
floatfillLevelnew fill level
integerfillTypefill type
booleanforceforce action
tablefillInfofill info for fill volume
Code
204function 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
235end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
49function 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
83end

onUpdateTick

Description
Called on update tick
Definition
onUpdateTick(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
113function 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
127end

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
17function StrawBlower.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(FillUnit, specializations)
19 and SpecializationUtil.hasSpecialization(Trailer, specializations)
20end

registerEventListeners

Description
Definition
registerEventListeners()
Code
38function StrawBlower.registerEventListeners(vehicleType)
39 SpecializationUtil.registerEventListener(vehicleType, "onLoad", StrawBlower)
40 SpecializationUtil.registerEventListener(vehicleType, "onDelete", StrawBlower)
41 SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", StrawBlower)
42 SpecializationUtil.registerEventListener(vehicleType, "onFillUnitFillLevelChanged", StrawBlower)
43 SpecializationUtil.registerEventListener(vehicleType, "onDischargeStateChanged", StrawBlower)
44end

registerFunctions

Description
Definition
registerFunctions()
Code
24function StrawBlower.registerFunctions(vehicleType)
25 SpecializationUtil.registerFunction(vehicleType, "strawBlowerBaleTriggerCallback", StrawBlower.strawBlowerBaleTriggerCallback)
26end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
30function StrawBlower.registerOverwrittenFunctions(vehicleType)
31 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDrawFirstFillText", StrawBlower.getDrawFirstFillText)
32 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAllowDynamicMountFillLevelInfo", StrawBlower.getAllowDynamicMountFillLevelInfo)
33 SpecializationUtil.registerOverwrittenFunction(vehicleType, "addFillUnitFillLevel", StrawBlower.addFillUnitFillLevel)
34end

strawBlowerBaleTriggerCallback

Description
Trigger callback
Definition
strawBlowerBaleTriggerCallback(integer triggerId, integer otherActorId, boolean onEnter, boolean onLeave, boolean onStay, integer otherShapeId)
Arguments
integertriggerIdid of trigger
integerotherActorIdid of other actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
integerotherShapeIdid of other shape
Code
148function 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
182end