LUADOC - Farming Simulator 22

LoadTrigger

Parent
Object
Functions

delete

Description
Definition
delete()
Code
194function LoadTrigger:delete()
195 if self.triggerNode ~= nil then
196 removeTrigger(self.triggerNode)
197 g_currentMission:removeNodeObject(self.triggerNode)
198 end
199 if self.isClient then
200 g_soundManager:deleteSamples(self.samples)
201 g_effectManager:deleteEffects(self.effects)
202 end
203
204 g_currentMission.activatableObjectsSystem:removeActivatable(self.activatable)
205
206 LoadTrigger:superClass().delete(self)
207end

farmIdForFillableObject

Description
Get the farm id for given object. If none can be found, SPECTATOR is used.
Definition
farmIdForFillableObject()
Code
310function LoadTrigger:farmIdForFillableObject(fillableObject)
311 local objectFarmId = fillableObject:getOwnerFarmId()
312 if fillableObject.getActiveFarm ~= nil then
313 objectFarmId = fillableObject:getActiveFarm()
314 end
315
316 if objectFarmId == nil then
317 objectFarmId = FarmManager.SPECTATOR_FARM_ID
318 end
319
320 return objectFarmId
321end

getAITargetPositionAndDirection

Description
Definition
getAITargetPositionAndDirection()
Code
620function LoadTrigger:getAITargetPositionAndDirection()
621 local x, _, z = getWorldTranslation(self.aiNode)
622 local xDir, _, zDir = localDirectionToWorld(self.aiNode, 0, 0, 1)
623 return x, z, xDir, zDir
624end

getAllowsActivation

Description
Definition
getAllowsActivation()
Code
458function LoadTrigger:getAllowsActivation(fillableObject)
459 if not self.requiresActiveVehicle then
460 return true
461 end
462
463 if fillableObject.getAllowLoadTriggerActivation ~= nil and fillableObject:getAllowLoadTriggerActivation(fillableObject) then
464 return true
465 end
466
467 return false
468end

getCurrentFillType

Description
Definition
getCurrentFillType()
Code
560function LoadTrigger:getCurrentFillType()
561 return self.selectedFillType
562end

getFillTargetNode

Description
Definition
getFillTargetNode()
Code
566function LoadTrigger:getFillTargetNode()
567 if self.currentFillableObject ~= nil then
568 return self.currentFillableObject:getFillUnitRootNode(self.fillUnitIndex)
569 end
570end

getIsFillableObjectAvailable

Description
Definition
getIsFillableObjectAvailable()
Code
325function LoadTrigger:getIsFillableObjectAvailable()
326 if next(self.fillableObjects) == nil then
327 return false
328 else
329 if self.isLoading then
330 if self.currentFillableObject ~= nil and self:getAllowsActivation(self.currentFillableObject) then
331 return true
332 end
333 else
334 self.validFillableObject = nil
335 self.validFillableFillUnitIndex = nil
336
337 -- last object that was filled has lower prio than the other objects in the trigger
338 -- so we can guarantee that all objects will be filled
339 local hasLowPrioObject = false
340 local numOfObjects = 0
341 for _, fillableObject in pairs(self.fillableObjects) do
342 if fillableObject.lastWasFilled then
343 hasLowPrioObject = true
344 end
345 numOfObjects = numOfObjects + 1
346 end
347 hasLowPrioObject = hasLowPrioObject and (numOfObjects > 1)
348
349 for _, fillableObject in pairs(self.fillableObjects) do
350 if not fillableObject.lastWasFilled or not hasLowPrioObject then
351 if self:getAllowsActivation(fillableObject.object) then
352 if fillableObject.object:getFillUnitSupportsToolType(fillableObject.fillUnitIndex, ToolType.TRIGGER) then
353 if not self.source:getIsFillAllowedToFarm(self:farmIdForFillableObject(fillableObject.object)) then
354 return false
355 end
356
357 self.validFillableObject = fillableObject.object
358 self.validFillableFillUnitIndex = fillableObject.fillUnitIndex
359
360 return true
361 end
362 end
363 end
364 end
365 end
366 end
367
368 return false
369end

getIsFillTypeSupported

Description
Definition
getIsFillTypeSupported()
Code
608function LoadTrigger:getIsFillTypeSupported(fillType)
609 return self.fillTypes[fillType] ~= nil
610end

getSupportAILoading

Description
Definition
getSupportAILoading()
Code
614function LoadTrigger:getSupportAILoading()
615 return self.supportsAILoading
616end

load

Description
Definition
load()
Code
58function LoadTrigger:load(components, xmlFile, xmlNode, i3dMappings, rootNode)
59 self.rootNode = rootNode or xmlFile:getValue(xmlNode .. "#node", nil, components, i3dMappings)
60 if self.rootNode == nil then
61 Logging.xmlError(xmlFile, "Missing node '%s#node'", xmlNode)
62 return false
63 end
64
65 -- load triggers
66 self.objectsInTriggers = {}
67
68 XMLUtil.checkDeprecatedXMLElements(xmlFile, xmlNode .. "#scrollerIndex", xmlNode .. "#scrollerNode")
69
70 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "triggerNode", xmlFile, xmlNode .. "#triggerNode")
71 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "triggerIndex", xmlFile, xmlNode .. "#triggerNode")
72 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "fillLitersPerSecond", xmlFile, xmlNode .. "#fillLitersPerSecond")
73 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "dischargeNode", xmlFile, xmlNode .. "#dischargeNode")
74 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "fillSoundIdentifier", xmlFile, xmlNode .. "#fillSoundIdentifier")
75 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "fillSoundNode", xmlFile, xmlNode .. "#fillSoundNode")
76 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "scrollerIndex", xmlFile, xmlNode .. "#scrollerNode")
77 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "shaderParameterName", xmlFile, xmlNode .. "#shaderParameterName")
78 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "scrollerScrollSpeed", xmlFile, xmlNode .. "#scrollerScrollSpeed")
79 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "fillTypeCategories", xmlFile, xmlNode .. "#fillTypeCategories")
80 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "fillTypes", xmlFile, xmlNode .. "#fillTypes")
81 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "autoStart", xmlFile, xmlNode .. "#autoStart")
82 XMLUtil.checkDeprecatedUserAttribute(self.rootNode, "infiniteCapacity", xmlFile, xmlNode .. "#infiniteCapacity")
83
84 local triggerNode = xmlFile:getValue(xmlNode .. "#triggerNode", nil, components, i3dMappings)
85 if triggerNode == nil then
86 Logging.xmlError(xmlFile, "Missing triggerNode defined in '%s'", xmlNode)
87 return false
88 end
89
90 self.triggerNode = triggerNode
91 addTrigger(triggerNode, "loadTriggerCallback", self)
92 g_currentMission:addNodeObject(triggerNode, self)
93
94 self.fillLitersPerMS = xmlFile:getValue(xmlNode .. "#fillLitersPerSecond", 1000) / 1000
95
96
97 self.aiNode = xmlFile:getValue(xmlNode .. "#aiNode", nil, components, i3dMappings)
98 self.supportsAILoading = self.aiNode ~= nil
99
100 local dischargeNode = xmlFile:getValue(xmlNode .. "#dischargeNode", nil, components, i3dMappings)
101 if dischargeNode ~= nil then
102 XMLUtil.checkDeprecatedUserAttribute(dischargeNode, "width", xmlFile, xmlNode .. "#dischargeWidth")
103 XMLUtil.checkDeprecatedUserAttribute(dischargeNode, "length", xmlFile, xmlNode .. "#dischargeLength")
104
105 self.dischargeInfo = {}
106 self.dischargeInfo.name = "fillVolumeDischargeInfo"
107 self.dischargeInfo.nodes = {}
108 local width = xmlFile:getValue(xmlNode .. "#dischargeWidth", 0.5)
109 local length = xmlFile:getValue(xmlNode .. "#dischargeLength", 0.5)
110 table.insert(self.dischargeInfo.nodes, {node=dischargeNode, width=width, length=length, priority=1})
111 end
112
113 -- place sound at the same position as the trigger or the discharge node
114 self.soundNode = createTransformGroup("loadTriggerSoundNode")
115 link(dischargeNode or self.triggerNode, self.soundNode)
116
117 if self.isClient then
118 self.effects = g_effectManager:loadEffect(xmlFile, xmlNode, components, self, i3dMappings)
119
120 self.samples = {}
121
122 local fillSoundIdentifier = xmlFile:getValue(xmlNode .. "#fillSoundIdentifier")
123 local fillSoundNode = xmlFile:getValue(xmlNode .. "#fillSoundNode", nil, components, i3dMappings)
124
125 if fillSoundNode == nil then
126 fillSoundNode = self.rootNode
127 end
128
129 local xmlSoundFile = loadXMLFile("mapXML", g_currentMission.missionInfo.mapSoundXmlFilename)
130 if xmlSoundFile ~= nil and xmlSoundFile ~= 0 then
131 local directory = g_currentMission.baseDirectory
132 local modName, baseDirectory = Utils.getModNameAndBaseDirectory(g_currentMission.missionInfo.mapSoundXmlFilename)
133 if modName ~= nil then
134 directory = baseDirectory .. modName
135 end
136 if fillSoundIdentifier ~= nil then
137 self.samples.load = g_soundManager:loadSampleFromXML(xmlSoundFile, "sound.object", fillSoundIdentifier, directory, getRootNode(), 0, AudioGroup.ENVIRONMENT, nil, nil)
138 if self.samples.load ~= nil then
139 link(fillSoundNode, self.samples.load.soundNode)
140 setTranslation(self.samples.load.soundNode, 0,0,0)
141 end
142 end
143 delete(xmlSoundFile)
144 end
145
146 self.scroller = xmlFile:getValue(xmlNode .. "#scrollerNode", nil, components, i3dMappings)
147 if self.scroller ~= nil then
148 self.scrollerShaderParameterName = xmlFile:getValue(xmlNode .. "#shaderParameterName", "uvScrollSpeed")
149 self.scrollerSpeedX, self.scrollerSpeedY = xmlFile:getValue(xmlNode .. "#scrollerScrollSpeed", "0 -0.75")
150
151 setShaderParameter(self.scroller, self.scrollerShaderParameterName, 0, 0, 0, 0, false)
152 end
153 end
154
155 self.fillTypes = {}
156 local fillTypeCategories = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "fillTypeCategories", self.rootNode)
157 local fillTypeNames = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "fillTypes", self.rootNode)
158
159 local fillTypes = nil
160 if fillTypeCategories ~= nil and fillTypeNames == nil then
161 fillTypes = g_fillTypeManager:getFillTypesByCategoryNames(fillTypeCategories, "Warning: UnloadTrigger has invalid fillTypeCategory '%s'.")
162 elseif fillTypeCategories == nil and fillTypeNames ~= nil then
163 fillTypes = g_fillTypeManager:getFillTypesByNames(fillTypeNames, "Warning: UnloadTrigger has invalid fillType '%s'.")
164 end
165 if fillTypes ~= nil then
166 for _,fillType in pairs(fillTypes) do
167 self.fillTypes[fillType] = true
168 end
169 else
170 self.fillTypes = nil
171 end
172
173 self.autoStart = xmlFile:getValue(xmlNode .. "#autoStart", false)
174 self.hasInfiniteCapacity = xmlFile:getValue(xmlNode .. "#infiniteCapacity", false)
175
176 self.startFillText = g_i18n:convertText(xmlFile:getValue(xmlNode .. "#startFillText", "$l10n_action_siloStartFilling"))
177 self.stopFillText = g_i18n:convertText(xmlFile:getValue(xmlNode .. "#stopFillText", "$l10n_action_siloStopFilling" ))
178
179 self.activatable = LoadTriggerActivatable.new(self)
180 self.activatable:setText(self.startFillText)
181
182 self.isLoading = false
183 self.selectedFillType = FillType.UNKNOWN
184
185 self.automaticFilling = Platform.gameplay.automaticFilling
186 self.requiresActiveVehicle = not self.automaticFilling
187 self.automaticFillingTimer = 0
188
189 return true
190end

loadTriggerCallback

Description
Definition
loadTriggerCallback()
Code
222function LoadTrigger:loadTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId)
223 local fillableObject = g_currentMission:getNodeObject(otherId)
224 if fillableObject ~= nil then
225 if fillableObject ~= self.source and fillableObject.getRootVehicle ~= nil and fillableObject.getFillUnitIndexFromNode ~= nil then
226 local fillTypes = self.source:getSupportedFillTypes()
227
228 if fillTypes ~= nil then
229 local foundFillUnitIndex = fillableObject:getFillUnitIndexFromNode(otherId)
230
231 if foundFillUnitIndex ~= nil then
232 local found = false
233 for fillTypeIndex, state in pairs(fillTypes) do
234 if state and (self.fillTypes == nil or self.fillTypes[fillTypeIndex]) then
235 if fillableObject:getFillUnitSupportsFillType(foundFillUnitIndex, fillTypeIndex) then
236 if fillableObject:getFillUnitAllowsFillType(foundFillUnitIndex, fillTypeIndex) then
237 found = true
238 break
239 end
240 end
241 end
242 end
243
244 -- ignore fillUnitIndex if does not support or allow one of the provided filltypes
245 if not found then
246 foundFillUnitIndex = nil
247 end
248 end
249
250 if foundFillUnitIndex == nil then
251 for fillTypeIndex, state in pairs(fillTypes) do
252 if state and (self.fillTypes == nil or self.fillTypes[fillTypeIndex]) then
253 local fillUnits = fillableObject:getFillUnits()
254 for fillUnitIndex, fillUnit in ipairs(fillUnits) do
255 -- only check fill units without exactFillRootNodes
256 if fillUnit.exactFillRootNode == nil then
257 if fillableObject:getFillUnitSupportsFillType(fillUnitIndex, fillTypeIndex) then
258 if fillableObject:getFillUnitAllowsFillType(fillUnitIndex, fillTypeIndex) then
259 foundFillUnitIndex = fillUnitIndex
260 break
261 end
262 end
263 end
264 end
265 end
266 end
267 end
268
269 if foundFillUnitIndex ~= nil then
270 if onEnter then
271 self.fillableObjects[otherId] = {object=fillableObject, fillUnitIndex=foundFillUnitIndex}
272 fillableObject:addDeleteListener(self)
273 elseif onLeave then
274 self.fillableObjects[otherId] = nil
275 fillableObject:removeDeleteListener(self)
276
277 if self.isLoading and self.currentFillableObject == fillableObject then
278 self:setIsLoading(false)
279 end
280
281 if fillableObject == self.validFillableObject then
282 self.validFillableObject = nil
283 self.validFillableFillUnitIndex = nil
284 end
285 end
286
287 if self.automaticFilling then
288 if not self.isLoading then
289 if next(self.fillableObjects) ~= nil then
290 if self:getIsFillableObjectAvailable() then
291 self:toggleLoading()
292 end
293 end
294 end
295 else
296 if next(self.fillableObjects) ~= nil then
297 g_currentMission.activatableObjectsSystem:addActivatable(self.activatable)
298 else
299 g_currentMission.activatableObjectsSystem:removeActivatable(self.activatable)
300 end
301 end
302 end
303 end
304 end
305 end
306end

new

Description
Definition
new()
Code
48function LoadTrigger.new(isServer, isClient, customMt)
49 local self = Object.new(isServer, isClient, customMt or LoadTrigger_mt)
50
51 self.fillableObjects = {}
52
53 return self
54end

onDeleteObject

Description
Definition
onDeleteObject()
Code
591function LoadTrigger:onDeleteObject(vehicle)
592 for k, fillableObject in pairs(self.fillableObjects) do
593 if fillableObject.object == vehicle then
594 self.fillableObjects[k] = nil
595
596 if self.isLoading then
597 if self.currentFillableObject == vehicle then
598 self:stopLoading()
599 self.currentFillableObject = nil
600 end
601 end
602 end
603 end
604end

onFillTypeSelection

Description
Definition
onFillTypeSelection()
Code
427function LoadTrigger:onFillTypeSelection(fillType)
428 if fillType ~= nil and fillType ~= FillType.UNKNOWN then
429 local validFillableObject = self.validFillableObject
430 if validFillableObject ~= nil and self:getAllowsActivation(validFillableObject) then
431 local fillUnitIndex = self.validFillableFillUnitIndex
432 self:setIsLoading(true, validFillableObject, fillUnitIndex, fillType)
433 end
434 end
435end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
19function LoadTrigger.registerXMLPaths(schema, basePath)
20 schema:register(XMLValueType.NODE_INDEX, basePath .. "#triggerNode", "Trigger node")
21 schema:register(XMLValueType.FLOAT, basePath .. "#fillLitersPerSecond", "Fill liters per second")
22 schema:register(XMLValueType.NODE_INDEX, basePath .. "#dischargeNode", "Discharge node")
23 schema:register(XMLValueType.FLOAT, basePath .. "#dischargeWidth", "Discharge width", 0.5)
24 schema:register(XMLValueType.FLOAT, basePath .. "#dischargeLength", "Discharge length", 0.5)
25
26 schema:register(XMLValueType.STRING, basePath .. "#fillSoundIdentifier", "Fill sound identifier in map sound xml")
27 schema:register(XMLValueType.NODE_INDEX, basePath .. "#fillSoundNode", "Fill sound link node")
28
29 EffectManager.registerEffectXMLPaths(schema, basePath)
30
31 schema:register(XMLValueType.NODE_INDEX, basePath .. "#scrollerNode", "Scroller node")
32 schema:register(XMLValueType.STRING, basePath .. "#shaderParameterName", "Scroller shader parameter name", "uvScrollSpeed")
33 schema:register(XMLValueType.VECTOR_2, basePath .. "#scrollerScrollSpeed", "Scroller speed scale", "0 -0.75")
34
35 schema:register(XMLValueType.STRING, basePath .. "#fillTypeCategories", "Supported fill type categories")
36 schema:register(XMLValueType.STRING, basePath .. "#fillTypes", "Supported fill types")
37
38 schema:register(XMLValueType.BOOL, basePath .. "#autoStart", "Auto start loading", false)
39 schema:register(XMLValueType.BOOL, basePath .. "#infiniteCapacity", "Has infinite capacity", false)
40 schema:register(XMLValueType.STRING, basePath .. "#startFillText", "Start fill text")
41 schema:register(XMLValueType.STRING, basePath .. "#stopFillText", "Stop fill text")
42
43 schema:register(XMLValueType.NODE_INDEX, basePath .. "#aiNode", "AI target node, required for the station to support AI. AI drives to the node in positive Z direction. Height is not relevant.")
44end

setFillSoundIsPlaying

Description
Definition
setFillSoundIsPlaying()
Code
574function LoadTrigger:setFillSoundIsPlaying(state)
575 if self.dischargeInfo == nil and state then
576 local target = self:getFillTargetNode()
577 if target ~= nil then
578 local x, y, z = getWorldTranslation(target)
579 setWorldTranslation(self.soundNode, x, y, z)
580 end
581 end
582
583 -- if we don't have a custom loading sample defined we play the fill trigger fillType based sound
584 if self.samples.load == nil then
585 FillTrigger.setFillSoundIsPlaying(self, state)
586 end
587end

setIsLoading

Description
Definition
setIsLoading()
Code
439function LoadTrigger:setIsLoading(isLoading, targetObject, fillUnitIndex, fillType, noEventSend)
440 LoadTriggerSetIsLoadingEvent.sendEvent(self, isLoading, targetObject, fillUnitIndex, fillType, noEventSend)
441 if isLoading then
442 self:startLoading(fillType, targetObject, fillUnitIndex)
443 else
444 self:stopLoading()
445 end
446
447 self:setFillSoundIsPlaying(isLoading)
448
449 if self.currentFillableObject ~= nil then
450 if self.currentFillableObject.setFillSoundIsPlaying ~= nil then
451 self.currentFillableObject:setFillSoundIsPlaying(isLoading)
452 end
453 end
454end

setSource

Description
Definition
setSource()
Code
211function LoadTrigger:setSource(object)
212 assert(object.getSupportedFillTypes ~= nil)
213 assert(object.getAllFillLevels ~= nil)
214 assert(object.addFillLevelToFillableObject ~= nil)
215 assert(object.getIsFillAllowedToFarm ~= nil)
216
217 self.source = object
218end

startLoading

Description
Definition
startLoading()
Code
472function LoadTrigger:startLoading(fillType, fillableObject, fillUnitIndex)
473 if not self.isLoading then
474 self:raiseActive()
475 self.isLoading = true
476 self.selectedFillType = fillType
477 self.currentFillableObject = fillableObject
478 self.fillUnitIndex = fillUnitIndex
479 self.activatable:setText(self.stopFillText)
480
481 if self.isClient then
482 g_effectManager:setFillType(self.effects, self.selectedFillType)
483 g_effectManager:startEffects(self.effects)
484 g_soundManager:playSample(self.samples.load)
485
486 if self.scroller ~= nil then
487 setShaderParameter(self.scroller, self.scrollerShaderParameterName, self.scrollerSpeedX, self.scrollerSpeedY, 0, 0, false)
488 end
489 end
490 end
491end

stopLoading

Description
Definition
stopLoading()
Code
495function LoadTrigger:stopLoading()
496 if self.isLoading then
497 self:raiseActive()
498 self.isLoading = false
499 self.selectedFillType = FillType.UNKNOWN
500 self.activatable:setText(self.startFillText)
501 if self.currentFillableObject.aiStoppedLoadingFromTrigger ~= nil then
502 self.currentFillableObject:aiStoppedLoadingFromTrigger()
503 end
504
505 for _, fillableObject in pairs(self.fillableObjects) do
506 fillableObject.lastWasFilled = fillableObject.object == self.validFillableObject
507 end
508
509 if self.isClient then
510 g_effectManager:stopEffects(self.effects)
511 g_soundManager:stopSample(self.samples.load)
512
513 if self.scroller ~= nil then
514 setShaderParameter(self.scroller, self.scrollerShaderParameterName, 0, 0, 0, 0, false)
515 end
516 end
517 end
518end

toggleLoading

Description
Definition
toggleLoading()
Code
373function LoadTrigger:toggleLoading()
374 if not self.isLoading then
375 local fillLevels = self.source:getAllFillLevels(g_currentMission:getFarmId())
376
377 local fillableObject = self.validFillableObject
378 local fillUnitIndex = self.validFillableFillUnitIndex
379
380 local firstFillType = nil
381 local validFillLevels = {}
382 local numFillTypes = 0
383 for fillTypeIndex, fillLevel in pairs(fillLevels) do
384 if self.fillTypes == nil or self.fillTypes[fillTypeIndex] then
385 if fillableObject:getFillUnitAllowsFillType(fillUnitIndex, fillTypeIndex) then
386 validFillLevels[fillTypeIndex] = fillLevel
387
388 if firstFillType == nil then
389 firstFillType = fillTypeIndex
390 end
391
392 numFillTypes = numFillTypes + 1
393 end
394 end
395 end
396
397 if not self.autoStart and numFillTypes > 1 then
398 local startAllowed = true
399 local controlledVehicle = g_currentMission.controlledVehicle
400 if controlledVehicle.getIsActiveForInput ~= nil then
401 startAllowed = controlledVehicle:getIsActiveForInput(true)
402 end
403
404 -- allow popup only for the vehicle that controlled by the player
405 if startAllowed then
406 local text = string.format("%s", self.source:getName())
407
408 g_gui:showSiloDialog({title=text, fillLevels=validFillLevels, callback=self.onFillTypeSelection, target=self, hasInfiniteCapacity = self.hasInfiniteCapacity})
409
410 if GS_IS_MOBILE_VERSION then
411 local rootVehicle = fillableObject.rootVehicle
412 if rootVehicle.brakeToStop ~= nil then
413 rootVehicle:brakeToStop()
414 end
415 end
416 end
417 else
418 self:onFillTypeSelection(firstFillType)
419 end
420 else
421 self:setIsLoading(false)
422 end
423end

update

Description
Definition
update()
Code
522function LoadTrigger:update(dt)
523 if self.isServer then
524 if self.isLoading then
525 if self.currentFillableObject ~= nil then
526 local fillSpeed = self.fillLitersPerMS
527 if self.currentFillableObject.getLoadTriggerMaxFillSpeed ~= nil then
528 fillSpeed = math.min(fillSpeed, self.currentFillableObject:getLoadTriggerMaxFillSpeed())
529 end
530
531 local fillDelta = self.source:addFillLevelToFillableObject(self.currentFillableObject, self.fillUnitIndex, self.selectedFillType, fillSpeed * dt, self.dischargeInfo, ToolType.TRIGGER)
532 if fillDelta == nil or math.abs(fillDelta) < 0.001 then
533 self:setIsLoading(false)
534 end
535 elseif self.isLoading then
536 self:setIsLoading(false)
537 end
538 self:raiseActive()
539 else
540 -- automatic fill every 10 seconds if a object is in trigger
541 if self.automaticFilling then
542 if next(self.fillableObjects) ~= nil then
543 self.automaticFillingTimer = math.max(self.automaticFillingTimer - dt, 0)
544 if self.automaticFillingTimer == 0 then
545 if self:getIsFillableObjectAvailable() then
546 self:toggleLoading()
547 self.automaticFillingTimer = 10000
548 end
549 end
550
551 self:raiseActive()
552 end
553 end
554 end
555 end
556end