LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

Shovel

Description
Specialization for shovels providing functionality to pick up filltypes from the ground
Functions

doCheckSpeedLimit

Description
Returns if speed limit should be checked
Definition
doCheckSpeedLimit()
Return Values
booleancheckSpeedlimitcheck speed limit
Code
545function Shovel:doCheckSpeedLimit(superFunc)
546 return superFunc(self) or (self.spec_shovel.useSpeedLimit and (self.getIsTurnedOn == nil or self:getIsTurnedOn()))
547end

getCanShovelAtPosition

Description
Definition
getCanShovelAtPosition()
Code
551function Shovel:getCanShovelAtPosition(shovelNode)
552 if shovelNode == nil then
553 return false
554 end
555
556 if shovelNode.ignoreFarmlandState then
557 return true
558 end
559
560 local sx,_,sz = localToWorld(shovelNode.node, -shovelNode.width * 0.5, 0, 0)
561 local activeFarm = self:getActiveFarm()
562
563 local ex,_,ez = localToWorld(shovelNode.node, shovelNode.width * 0.5, 0, 0)
564 local isStartOwned = g_currentMission.accessHandler:canFarmAccessLand(activeFarm, sx, sz)
565 if not isStartOwned then
566 return false
567 end
568
569 return g_currentMission.accessHandler:canFarmAccessLand(activeFarm, ex, ez)
570end

getCanToggleDischargeToGround

Description
Definition
getCanToggleDischargeToGround()
Code
495function Shovel:getCanToggleDischargeToGround(superFunc)
496 if self.spec_shovel.shovelDischargeInfo.node ~= nil then
497 return false
498 end
499
500 return superFunc(self)
501end

getCanToggleDischargeToObject

Description
Definition
getCanToggleDischargeToObject()
Code
485function Shovel:getCanToggleDischargeToObject(superFunc)
486 if self.spec_shovel.shovelDischargeInfo.node ~= nil then
487 return false
488 end
489
490 return superFunc(self)
491end

getDischargeNodeEmptyFactor

Description
Definition
getDischargeNodeEmptyFactor()
Code
414function Shovel:getDischargeNodeEmptyFactor(superFunc, dischargeNode)
415 local spec = self.spec_shovel
416
417 local parentFactor = superFunc(self, dischargeNode)
418
419 local info = spec.shovelDischargeInfo
420 if info.node ~= nil then
421 if info.dischargeNodeIndex == dischargeNode.index then
422 return parentFactor * self:getShovelTipFactor()
423 end
424 end
425
426 return parentFactor
427end

getIsDischargeNodeActive

Description
Definition
getIsDischargeNodeActive()
Code
397function Shovel:getIsDischargeNodeActive(superFunc, dischargeNode)
398 local spec = self.spec_shovel
399
400 local info = spec.shovelDischargeInfo
401 if info.node ~= nil then
402 if info.dischargeNodeIndex == dischargeNode.index then
403 if self:getShovelTipFactor() == 0 then
404 return false
405 end
406 end
407 end
408
409 return superFunc(self, dischargeNode)
410end

getIsShovelEffectState

Description
Returns if shovel effect is active
Definition
getIsShovelEffectState()
Return Values
booleanisActiveshovel effect is active
Code
523function Shovel:getIsShovelEffectState()
524 local spec = self.spec_shovel
525 return spec.loadingFillType ~= FillType.UNKNOWN, spec.loadingFillType
526end

getShovelNodeIsActive

Description
Definition
getShovelNodeIsActive()
Code
365function Shovel:getShovelNodeIsActive(shovelNode)
366 local isActive = true
367
368 if shovelNode.needsMovement then
369 local x,y,z = getWorldTranslation(shovelNode.node)
370 local _,_,dz = worldToLocal(shovelNode.node, shovelNode.lastPosition[1], shovelNode.lastPosition[2], shovelNode.lastPosition[3])
371 isActive = isActive and dz < 0
372
373 shovelNode.lastPosition[1] = x
374 shovelNode.lastPosition[2] = y
375 shovelNode.lastPosition[3] = z
376 end
377
378 if shovelNode.maxPickupAngle ~= nil then
379 local _,dy,_ = localDirectionToWorld(shovelNode.node, 0, 0, 1)
380 local angle = math.acos(dy)
381 if angle > shovelNode.maxPickupAngle then
382 return false
383 end
384 end
385
386 if shovelNode.needsAttacherVehicle then
387 if self.getAttacherVehicle ~= nil and self:getAttacherVehicle() == nil then
388 return false
389 end
390 end
391
392 return isActive
393end

getShovelTipFactor

Description
Definition
getShovelTipFactor()
Code
505function Shovel:getShovelTipFactor()
506 local spec = self.spec_shovel
507
508 local info = spec.shovelDischargeInfo
509 if info.node ~= nil then
510 local _,dy,_ = localDirectionToWorld(info.node, 0,0,1)
511 local angle = math.acos(dy)
512 if angle > info.minSpeedAngle then
513 return math.max(0, math.min(1.0, (angle - info.minSpeedAngle) / (info.maxSpeedAngle - info.minSpeedAngle)))
514 end
515 end
516
517 return 0
518end

getWearMultiplier

Description
Returns current wear multiplier
Definition
getWearMultiplier()
Return Values
floatwearMultipliercurrent wear multiplier
Code
531function Shovel:getWearMultiplier(superFunc)
532 local spec = self.spec_shovel
533 local multiplier = superFunc(self)
534
535 if spec.loadingFillType ~= FillType.UNKNOWN then
536 multiplier = multiplier + self:getWorkWearMultiplier()
537 end
538
539 return multiplier
540end

handleDischarge

Description
Definition
handleDischarge()
Code
431function Shovel:handleDischarge(superFunc, dischargeNode, dischargedLiters, minDropReached, hasMinDropFillLevel)
432 local spec = self.spec_shovel
433 -- do nothing if it is shovel dischargenode
434 if dischargeNode.index ~= spec.shovelDischargeInfo.dischargeNodeIndex or spec.shovelDischargeInfo.node == nil then
435 superFunc(self, dischargeNode, dischargedLiters, minDropReached, hasMinDropFillLevel)
436 end
437end

handleDischargeOnEmpty

Description
Definition
handleDischargeOnEmpty()
Code
441function Shovel:handleDischargeOnEmpty(superFunc, dischargedLiters, minDropReached, hasMinDropFillLevel)
442 if self.spec_shovel.shovelDischargeInfo.node == nil then
443 superFunc(self, dischargedLiters, minDropReached, hasMinDropFillLevel)
444 end
445end

handleDischargeRaycast

Description
Definition
handleDischargeRaycast()
Code
449function Shovel:handleDischargeRaycast(superFunc, dischargeNode, hitObject, hitShape, hitDistance, hitFillUnitIndex, hitTerrain)
450 local spec = self.spec_shovel
451 if spec.shovelDischargeInfo.node ~= nil and spec.shovelDischargeInfo.dischargeNodeIndex == dischargeNode.index then
452 if hitObject ~= nil then
453 local fillType = self:getDischargeFillType(dischargeNode)
454 local allowFillType = hitObject:getFillUnitAllowsFillType(hitFillUnitIndex, fillType)
455 if allowFillType and hitObject:getFillUnitFreeCapacity(hitFillUnitIndex, fillType, self:getOwnerFarmId()) > 0 then
456 self:setDischargeState(Dischargeable.DISCHARGE_STATE_OBJECT, true)
457 else
458 if self:getDischargeState() == Dischargeable.DISCHARGE_STATE_OBJECT then
459 self:setDischargeState(Dischargeable.DISCHARGE_STATE_OFF, true)
460 end
461 end
462 else
463 local fillLevel = self:getFillUnitFillLevel(dischargeNode.fillUnitIndex)
464 if fillLevel > 0 and self:getShovelTipFactor() > 0 then
465 if self:getCanDischargeToGround(dischargeNode) then
466 self:setDischargeState(Dischargeable.DISCHARGE_STATE_GROUND, true)
467 else
468 if self:getIsActiveForInput(true) then
469 if not self:getCanDischargeToLand(dischargeNode) then
470 g_currentMission:showBlinkingWarning(g_i18n:getText("warning_youDontHaveAccessToThisLand"), 5000)
471 elseif not self:getCanDischargeAtPosition(dischargeNode) then
472 g_currentMission:showBlinkingWarning(g_i18n:getText("warning_actionNotAllowedHere"), 5000)
473 end
474 end
475 end
476 end
477 end
478 else
479 superFunc(self, dischargeNode, hitObject, hitShape, hitDistance, hitFillUnitIndex, hitTerrain)
480 end
481end

initSpecialization

Description
Definition
initSpecialization()
Code
23function Shovel.initSpecialization()
24 local schema = Vehicle.xmlSchema
25 schema:setXMLSpecializationType("Shovel")
26
27 schema:register(XMLValueType.BOOL, "vehicle.shovel#ignoreFillUnitFillType", "Ignore fill unit fill type", false)
28 schema:register(XMLValueType.BOOL, "vehicle.shovel#useSpeedLimit", "Use speed limit while shovel is turned on", false)
29
30 schema:register(XMLValueType.NODE_INDEX, Shovel.SHOVEL_NODE_XML_KEY .. "#node", "Shovel node")
31 schema:register(XMLValueType.INT, Shovel.SHOVEL_NODE_XML_KEY .. "#fillUnitIndex", "Fill unit index", 1)
32 schema:register(XMLValueType.INT, Shovel.SHOVEL_NODE_XML_KEY .. "#loadInfoIndex", "Load info index", 1)
33 schema:register(XMLValueType.FLOAT, Shovel.SHOVEL_NODE_XML_KEY .. "#width", "Shovel node width", 1)
34 schema:register(XMLValueType.FLOAT, Shovel.SHOVEL_NODE_XML_KEY .. "#length", "Shovel node length", 0.5)
35 schema:register(XMLValueType.FLOAT, Shovel.SHOVEL_NODE_XML_KEY .. "#yOffset", "Shovel node y offset", 0)
36 schema:register(XMLValueType.FLOAT, Shovel.SHOVEL_NODE_XML_KEY .. "#zOffset", "Shovel node z offset", 0)
37 schema:register(XMLValueType.BOOL, Shovel.SHOVEL_NODE_XML_KEY .. "#needsMovement", "Needs movement", true)
38 schema:register(XMLValueType.FLOAT, Shovel.SHOVEL_NODE_XML_KEY .. "#fillLitersPerSecond", "Fill liters per second", "inf.")
39 schema:register(XMLValueType.ANGLE, Shovel.SHOVEL_NODE_XML_KEY .. "#maxPickupAngle", "Max. pickup angle")
40 schema:register(XMLValueType.BOOL, Shovel.SHOVEL_NODE_XML_KEY .. "#needsAttacherVehicle", "Needs attacher vehicle connected", true)
41 schema:register(XMLValueType.BOOL, Shovel.SHOVEL_NODE_XML_KEY .. "#resetFillLevel", "Reset fill level to zero while the shovel node is not active", false)
42 schema:register(XMLValueType.BOOL, Shovel.SHOVEL_NODE_XML_KEY .. "#ignoreFillLevel", "Ignore fill level of the fill unit while filling", false)
43 schema:register(XMLValueType.BOOL, Shovel.SHOVEL_NODE_XML_KEY .. "#ignoreFarmlandState", "Ignore farmland state for pickup", false)
44 schema:register(XMLValueType.BOOL, Shovel.SHOVEL_NODE_XML_KEY .. ".smoothing#allowed", "Leveler smoothes while driving backward", false)
45 schema:register(XMLValueType.FLOAT, Shovel.SHOVEL_NODE_XML_KEY .. ".smoothing#radius", "Smooth ground radius", 0.5)
46 schema:register(XMLValueType.FLOAT, Shovel.SHOVEL_NODE_XML_KEY .. ".smoothing#overlap", "Radius overlap", 1.7)
47
48 schema:register(XMLValueType.INT, "vehicle.shovel.dischargeInfo#dischargeNodeIndex", "Discharge node index", 1)
49 schema:register(XMLValueType.NODE_INDEX, "vehicle.shovel.dischargeInfo#node", "Discharge info node")
50
51 schema:register(XMLValueType.ANGLE, "vehicle.shovel.dischargeInfo#minSpeedAngle", "Discharge info min. speed angle")
52 schema:register(XMLValueType.ANGLE, "vehicle.shovel.dischargeInfo#maxSpeedAngle", "Discharge info max. speed angle")
53
54 EffectManager.registerEffectXMLPaths(schema, "vehicle.shovel.fillEffect")
55
56 schema:setXMLSpecializationType()
57end

loadShovelNode

Description
Definition
loadShovelNode()
Code
329function Shovel:loadShovelNode(xmlFile, key, shovelNode)
330 shovelNode.node = xmlFile:getValue(key .. "#node", nil, self.components, self.i3dMappings)
331 if shovelNode.node == nil then
332 Logging.xmlWarning(self.xmlFile, "Missing 'node' for shovelNode '%s'!", key)
333 return false
334 end
335
336 shovelNode.fillUnitIndex = xmlFile:getValue(key .. "#fillUnitIndex", 1)
337 shovelNode.loadInfoIndex = xmlFile:getValue(key .. "#loadInfoIndex", 1)
338
339 shovelNode.width = xmlFile:getValue(key .. "#width", 1)
340 shovelNode.length = xmlFile:getValue(key .. "#length", 0.5)
341 shovelNode.yOffset = xmlFile:getValue(key .. "#yOffset", 0)
342 shovelNode.zOffset = xmlFile:getValue(key .. "#zOffset", 0)
343
344 shovelNode.needsMovement = xmlFile:getValue(key .. "#needsMovement", true)
345 shovelNode.lastPosition = {0, 0, 0}
346
347 shovelNode.fillLitersPerSecond = xmlFile:getValue(key .. "#fillLitersPerSecond", math.huge) / 1000
348 shovelNode.maxPickupAngle = xmlFile:getValue(key .. "#maxPickupAngle")
349
350 shovelNode.needsAttacherVehicle = xmlFile:getValue(key .. "#needsAttacherVehicle", true)
351
352 shovelNode.resetFillLevel = xmlFile:getValue(key .. "#resetFillLevel", false)
353 shovelNode.ignoreFillLevel = xmlFile:getValue(key .. "#ignoreFillLevel", false)
354 shovelNode.ignoreFarmlandState = xmlFile:getValue(key .. "#ignoreFarmlandState", false)
355
356 shovelNode.allowsSmoothing = xmlFile:getValue(key .. ".smoothing#allowed", false)
357 shovelNode.smoothGroundRadius = xmlFile:getValue(key .. ".smoothing#radius", 0.5)
358 shovelNode.smoothOverlap = xmlFile:getValue(key .. ".smoothing#overlap", 1.7)
359
360 return true
361end

onDelete

Description
Definition
onDelete()
Code
164function Shovel:onDelete()
165 local spec = self.spec_shovel
166 g_effectManager:deleteEffects(spec.fillEffects)
167end

onFillUnitFillLevelChanged

Description
Definition
onFillUnitFillLevelChanged()
Code
309function Shovel:onFillUnitFillLevelChanged(fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData, appliedDelta)
310 if self.isServer then
311 local spec = self.spec_shovel
312 for _,shovelNode in pairs(spec.shovelNodes) do
313 if shovelNode.fillUnitIndex == fillUnitIndex then
314 if shovelNode.capacityChanged then
315 local fillUnit = self:getFillUnitByIndex(fillUnitIndex)
316
317 if fillUnit.fillLevel <= fillUnit.defaultCapacity then
318 self:setFillUnitCapacity(fillUnitIndex, fillUnit.defaultCapacity)
319 shovelNode.capacityChanged = false
320 end
321 end
322 end
323 end
324 end
325end

onLoad

Description
Definition
onLoad()
Code
98function Shovel:onLoad(savegame)
99 local spec = self.spec_shovel
100
101 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.shovel#pickUpNode", "vehicle.shovel.shovelNode#node") --FS17 to FS19
102 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.shovel#pickUpWidth", "vehicle.shovel.shovelNode#width") --FS17 to FS19
103 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.shovel#pickUpLength", "vehicle.shovel.shovelNode#length") --FS17 to FS19
104 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.shovel#pickUpYOffset") --FS17 to FS19
105 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.shovel#pickUpRequiresMovement", "vehicle.shovel.shovelNode#needsMovement") --FS17 to FS19
106 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.shovel#pickUpNeedsToBeTurnedOn", "vehicle.shovel.shovelNode#needsActivation") --FS17 to FS19
107
108 spec.ignoreFillUnitFillType = self.xmlFile:getValue("vehicle.shovel#ignoreFillUnitFillType", false)
109 spec.useSpeedLimit = self.xmlFile:getValue("vehicle.shovel#useSpeedLimit", false)
110
111 spec.shovelNodes = {}
112 local i = 0
113 while true do
114 local key = string.format("vehicle.shovel.shovelNode(%d)", i)
115 if not self.xmlFile:hasProperty(key) then
116 break
117 end
118
119 local shovelNode = {}
120
121 if self:loadShovelNode(self.xmlFile, key, shovelNode) then
122 table.insert(spec.shovelNodes, shovelNode)
123 end
124 i = i + 1
125 end
126
127 spec.shovelDischargeInfo = {}
128 spec.shovelDischargeInfo.dischargeNodeIndex = self.xmlFile:getValue("vehicle.shovel.dischargeInfo#dischargeNodeIndex", 1)
129 spec.shovelDischargeInfo.node = self.xmlFile:getValue("vehicle.shovel.dischargeInfo#node", nil, self.components, self.i3dMappings)
130
131 if spec.shovelDischargeInfo.node ~= nil then
132 local minSpeedAngle = self.xmlFile:getValue("vehicle.shovel.dischargeInfo#minSpeedAngle")
133 local maxSpeedAngle = self.xmlFile:getValue("vehicle.shovel.dischargeInfo#maxSpeedAngle")
134 if minSpeedAngle == nil or maxSpeedAngle == nil then
135 Logging.xmlWarning(self.xmlFile, "Missing 'minSpeedAngle' or 'maxSpeedAngle' for dischargeNode 'vehicle.shovel.dischargeInfo'")
136 return false
137 end
138 spec.shovelDischargeInfo.minSpeedAngle = minSpeedAngle
139 spec.shovelDischargeInfo.maxSpeedAngle = maxSpeedAngle
140 end
141
142 if self.isClient then
143 spec.fillEffects = g_effectManager:loadEffect(self.xmlFile, "vehicle.shovel.fillEffect", self.components, self, self.i3dMappings)
144 spec.fillEffectTime = 0
145 end
146
147 spec.effectDirtyFlag = self:getNextDirtyFlag()
148 spec.loadingFillType = FillType.UNKNOWN
149 spec.lastValidFillType = FillType.UNKNOWN
150 spec.smoothAccumulation = 0
151
152 if #spec.shovelNodes == 0 then
153 SpecializationUtil.removeEventListener(self, "onReadStream", Shovel)
154 SpecializationUtil.removeEventListener(self, "onWriteStream", Shovel)
155 SpecializationUtil.removeEventListener(self, "onReadUpdateStream", Shovel)
156 SpecializationUtil.removeEventListener(self, "onWriteUpdateStream", Shovel)
157 SpecializationUtil.removeEventListener(self, "onUpdateTick", Shovel)
158 SpecializationUtil.removeEventListener(self, "onFillUnitFillLevelChanged", Shovel)
159 end
160end

onReadStream

Description
Definition
onReadStream()
Code
171function Shovel:onReadStream(streamId, connection)
172 local spec = self.spec_shovel
173 spec.loadingFillType = streamReadUIntN(streamId, FillTypeManager.SEND_NUM_BITS)
174end

onReadUpdateStream

Description
Definition
onReadUpdateStream()
Code
185function Shovel:onReadUpdateStream(streamId, timestamp, connection)
186 if connection:getIsServer() then
187 local spec = self.spec_shovel
188
189 if streamReadBool(streamId) then
190 spec.loadingFillType = streamReadUIntN(streamId, FillTypeManager.SEND_NUM_BITS)
191 end
192 end
193end

onUpdateTick

Description
Definition
onUpdateTick()
Code
209function Shovel:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
210 local spec = self.spec_shovel
211
212 if self.isServer then
213 local validPickupFillType = FillType.UNKNOWN
214 for _, shovelNode in pairs(spec.shovelNodes) do
215 if self:getShovelNodeIsActive(shovelNode) then
216 local fillLevel = self:getFillUnitFillLevel(shovelNode.fillUnitIndex)
217 local capacity = self:getFillUnitCapacity(shovelNode.fillUnitIndex)
218 if fillLevel < capacity or shovelNode.ignoreFillLevel then
219 local pickupFillType = self:getFillUnitFillType(shovelNode.fillUnitIndex)
220 if fillLevel / capacity < self:getFillTypeChangeThreshold() then
221 pickupFillType = FillType.UNKNOWN
222 end
223 local minValidLiter = g_densityMapHeightManager:getMinValidLiterValue(pickupFillType) or 0
224 local freeCapacity = math.min(shovelNode.ignoreFillLevel and math.huge or capacity - fillLevel, shovelNode.fillLitersPerSecond * dt)
225 local sx,sy,sz = localToWorld(shovelNode.node, -shovelNode.width * 0.5, shovelNode.yOffset, shovelNode.zOffset)
226 local ex,ey,ez = localToWorld(shovelNode.node, shovelNode.width * 0.5, shovelNode.yOffset, shovelNode.zOffset)
227 local innerRadius = shovelNode.length
228 local radius = nil
229
230 if self:getCanShovelAtPosition(shovelNode) then
231 if pickupFillType == FillType.UNKNOWN or spec.ignoreFillUnitFillType then
232 pickupFillType = DensityMapHeightUtil.getFillTypeAtLine(sx,sy,sz, ex,ey,ez, innerRadius)
233 end
234
235 if pickupFillType ~= FillType.UNKNOWN and self:getFillUnitSupportsFillType(shovelNode.fillUnitIndex, pickupFillType) and self:getFillUnitAllowsFillType(shovelNode.fillUnitIndex, pickupFillType) then
236 local fillDelta, lineOffset = DensityMapHeightUtil.tipToGroundAroundLine(self, -freeCapacity - minValidLiter, pickupFillType, sx,sy,sz, ex,ey,ez, innerRadius, radius, shovelNode.lineOffset, true, nil)
237 shovelNode.lineOffset = lineOffset
238
239 if not shovelNode.ignoreFillLevel and -fillDelta > freeCapacity then
240 self:setFillUnitCapacity(shovelNode.fillUnitIndex, fillLevel - fillDelta)
241 shovelNode.capacityChanged = true
242 end
243
244 if fillDelta < 0 then
245 local loadInfo = self:getFillVolumeLoadInfo(shovelNode.loadInfoIndex)
246 self:addFillUnitFillLevel(self:getOwnerFarmId(), shovelNode.fillUnitIndex, -fillDelta, pickupFillType, ToolType.UNDEFINED, loadInfo)
247 validPickupFillType = pickupFillType
248
249 -- call fill level changed callack to inform bunker silo about change
250 self:notifiyBunkerSilo(fillDelta, pickupFillType, (sx+ex) * 0.5, (sy+ey) * 0.5, (sz+ez) * 0.5)
251 end
252 end
253 end
254 end
255 elseif shovelNode.resetFillLevel then
256 local fillLevel = self:getFillUnitFillLevel(shovelNode.fillUnitIndex)
257 if fillLevel > 0 then
258 self:addFillUnitFillLevel(self:getOwnerFarmId(), shovelNode.fillUnitIndex, -fillLevel, self:getFillUnitFillType(shovelNode.fillUnitIndex), ToolType.UNDEFINED)
259 end
260 end
261
262 if shovelNode.allowsSmoothing then
263 local _,dy,_ = localDirectionToWorld(shovelNode.node, 0, 0, 1)
264 local angle = math.acos(dy)
265 if angle > shovelNode.maxPickupAngle then
266 local smoothAmount = 0
267 if self.lastSpeedReal > 0.0002 then -- start smoothing if driving faster than 0.7km/h
268 smoothAmount = spec.smoothAccumulation + math.max(self.lastMovedDistance * 0.5, 0.0003*dt) -- smooth 1.2m per meter driving or at least 0.3m/s
269 local rounded = DensityMapHeightUtil.getRoundedHeightValue(smoothAmount)
270 spec.smoothAccumulation = smoothAmount - rounded
271 else
272 spec.smoothAccumulation = 0
273 end
274
275 if smoothAmount > 0 then
276 DensityMapHeightUtil.smoothAroundLine(shovelNode.node, shovelNode.width, shovelNode.smoothGroundRadius, shovelNode.smoothOverlap, smoothAmount)
277 end
278 end
279 end
280 end
281
282 if validPickupFillType == FillType.UNKNOWN then
283 spec.fillEffectTime = spec.fillEffectTime - dt
284 if spec.fillEffectTime > 0 then
285 validPickupFillType = spec.loadingFillType
286 end
287 else
288 spec.fillEffectTime = 500
289 end
290
291 if spec.loadingFillType ~= validPickupFillType then
292 spec.loadingFillType = validPickupFillType
293 self:raiseDirtyFlags(spec.effectDirtyFlag)
294 end
295 end
296
297 if self.isClient then
298 if spec.loadingFillType ~= FillType.UNKNOWN then
299 g_effectManager:setFillType(spec.fillEffects, spec.loadingFillType)
300 g_effectManager:startEffects(spec.fillEffects)
301 else
302 g_effectManager:stopEffects(spec.fillEffects)
303 end
304 end
305end

onWriteStream

Description
Definition
onWriteStream()
Code
178function Shovel:onWriteStream(streamId, connection)
179 local spec = self.spec_shovel
180 streamWriteUIntN(streamId, spec.loadingFillType, FillTypeManager.SEND_NUM_BITS)
181end

onWriteUpdateStream

Description
Definition
onWriteUpdateStream()
Code
197function Shovel:onWriteUpdateStream(streamId, connection, dirtyMask)
198 if not connection:getIsServer() then
199 local spec = self.spec_shovel
200
201 if streamWriteBool(streamId, bitAND(dirtyMask, spec.effectDirtyFlag) ~= 0) then
202 streamWriteUIntN(streamId, spec.loadingFillType, FillTypeManager.SEND_NUM_BITS)
203 end
204 end
205end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
17function Shovel.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(FillUnit, specializations) and SpecializationUtil.hasSpecialization(FillVolume, specializations) and SpecializationUtil.hasSpecialization(Dischargeable, specializations) and SpecializationUtil.hasSpecialization(BunkerSiloInteractor, specializations)
19end

registerEventListeners

Description
Definition
registerEventListeners()
Code
85function Shovel.registerEventListeners(vehicleType)
86 SpecializationUtil.registerEventListener(vehicleType, "onLoad", Shovel)
87 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Shovel)
88 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Shovel)
89 SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", Shovel)
90 SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", Shovel)
91 SpecializationUtil.registerEventListener(vehicleType, "onDelete", Shovel)
92 SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", Shovel)
93 SpecializationUtil.registerEventListener(vehicleType, "onFillUnitFillLevelChanged", Shovel)
94end

registerFunctions

Description
Definition
registerFunctions()
Code
61function Shovel.registerFunctions(vehicleType)
62 SpecializationUtil.registerFunction(vehicleType, "loadShovelNode", Shovel.loadShovelNode)
63 SpecializationUtil.registerFunction(vehicleType, "getShovelNodeIsActive", Shovel.getShovelNodeIsActive)
64 SpecializationUtil.registerFunction(vehicleType, "getCanShovelAtPosition", Shovel.getCanShovelAtPosition)
65 SpecializationUtil.registerFunction(vehicleType, "getShovelTipFactor", Shovel.getShovelTipFactor)
66 SpecializationUtil.registerFunction(vehicleType, "getIsShovelEffectState", Shovel.getIsShovelEffectState)
67end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
71function Shovel.registerOverwrittenFunctions(vehicleType)
72 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsDischargeNodeActive", Shovel.getIsDischargeNodeActive)
73 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDischargeNodeEmptyFactor", Shovel.getDischargeNodeEmptyFactor)
74 SpecializationUtil.registerOverwrittenFunction(vehicleType, "handleDischarge", Shovel.handleDischarge)
75 SpecializationUtil.registerOverwrittenFunction(vehicleType, "handleDischargeOnEmpty", Shovel.handleDischargeOnEmpty)
76 SpecializationUtil.registerOverwrittenFunction(vehicleType, "handleDischargeRaycast", Shovel.handleDischargeRaycast)
77 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanToggleDischargeToObject", Shovel.getCanToggleDischargeToObject)
78 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanToggleDischargeToGround", Shovel.getCanToggleDischargeToGround)
79 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getWearMultiplier", Shovel.getWearMultiplier)
80 SpecializationUtil.registerOverwrittenFunction(vehicleType, "doCheckSpeedLimit", Shovel.doCheckSpeedLimit)
81end

updateDebugValues

Description
Definition
updateDebugValues()
Code
574function Shovel:updateDebugValues(values)
575 local spec = self.spec_shovel
576
577 local info = spec.shovelDischargeInfo
578 if info.node ~= nil then
579 local _,dy,_ = localDirectionToWorld(info.node, 0,0,1)
580 local angle = math.acos(dy)
581 table.insert(values, {name="angle", value=math.deg(angle)})
582 table.insert(values, {name="minSpeedAngle", value=math.deg(info.minSpeedAngle)})
583 table.insert(values, {name="maxSpeedAngle", value=math.deg(info.maxSpeedAngle)})
584
585 if angle > info.minSpeedAngle then
586 local factor = math.max(0, math.min(1.0, (angle - info.minSpeedAngle) / (info.maxSpeedAngle - info.minSpeedAngle)))
587 table.insert(values, {name="factor", value=factor})
588 else
589 table.insert(values, {name="factor", value="Out of Range - 0"})
590 end
591 end
592end