Script v1.4.4.0
- Handtools
- Events
- Objects
- Placeables
- Triggers
- Utils
- Vehicles
- Specializations
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BuiltInCutterTrailer
- BunkerSiloCompacter
- Combine
- ConveyorBelt
- Cover
- CrabSteering
- Crawler
- Cultivator
- Cutter
- Cylindered
- Drivable
- DynamicMountAttacher
- Fillable
- FillActivatable
- FillVolume
- Foldable
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- FuelTrailer
- Honk
- HookLiftContainer
- HookLiftTrailer
- Leveler
- Lights
- LivestockTrailer
- ManureBarrel
- ManureSpreader
- MixerWagon
- Motorized
- Mountable
- Mower
- NonTabbable
- Overloading
- Pickup
- Pipe
- Plough
- PowerConsumer
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- RidgeMarker
- Roller
- Ropes
- RotorSpreader
- SemiTrailerFront
- Shovel
- SowingMachine
- SpeedRotatingParts
- Sprayer
- Steerable
- StrawBlower
- StumpCutter
- Tedder
- TensionBelts
- Trailer
- TreePlanter
- TreePlanterActivatable
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Weeder
- WheelRotations
- Windrower
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkParticles
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
ManureBarrel
DescriptionClass for all manure barrelsFunctions
- prerequisitesPresent
- load
- update
- updateTick
- draw
- onAttachImplement
- onDetachImplement
- getIsReadyToSpray
- getAreEffectsVisible
- getIsWorkAreaActive
- getLitersPerSecond
- getIsInWorkPosition
- getCanBeTurnedOn
- getIsTurnedOnAllowed
- setIsTurnedOn
- onAiTurnOn
- onAiTurnOff
- onAiLower
- onAiRaise
- getIsAIReadyForWork
- groundAdjustRaycastCallback
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
17 | function ManureBarrel.prerequisitesPresent(specializations) |
18 | return SpecializationUtil.hasSpecialization(Sprayer, specializations) and |
19 | SpecializationUtil.hasSpecialization(AttacherJoints, specializations); |
20 | end; |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
25 | function ManureBarrel:load(savegame) |
26 | |
27 | self.groundAdjustRaycastCallback = ManureBarrel.groundAdjustRaycastCallback; |
28 | self.getIsInWorkPosition = Utils.overwrittenFunction(self.getIsInWorkPosition, ManureBarrel.getIsInWorkPosition); |
29 | self.getCanBeTurnedOn = Utils.overwrittenFunction(self.getCanBeTurnedOn, ManureBarrel.getCanBeTurnedOn); |
30 | self.getIsTurnedOnAllowed = Utils.overwrittenFunction(self.getIsTurnedOnAllowed, ManureBarrel.getIsTurnedOnAllowed); |
31 | self.setIsTurnedOn = Utils.overwrittenFunction(self.setIsTurnedOn, ManureBarrel.setIsTurnedOn); |
32 | self.getIsReadyToSpray = Utils.overwrittenFunction(self.getIsReadyToSpray, ManureBarrel.getIsReadyToSpray); |
33 | self.getAreEffectsVisible = Utils.overwrittenFunction(self.getAreEffectsVisible, ManureBarrel.getAreEffectsVisible); |
34 | self.getIsWorkAreaActive = Utils.overwrittenFunction(self.getIsWorkAreaActive, ManureBarrel.getIsWorkAreaActive); |
35 | |
36 | self.manureBarrelFoldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.manureBarrel#foldMinLimit"), 0); |
37 | self.manureBarrelFoldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.manureBarrel#foldMaxLimit"), 1); |
38 | |
39 | self.attachToolAnimation = getXMLString(self.xmlFile, "vehicle.manureBarrel#toolAttachAnimName"); |
40 | self.attachToolJointIndex = getXMLInt(self.xmlFile, "vehicle.manureBarrel#attacherJointIndex"); |
41 | |
42 | self.groundAdjustedNodes = {}; |
43 | local i = 0; |
44 | while true do |
45 | local key = string.format("vehicle.groundAdjustedNodes.groundAdjustedNode(%d)", i); |
46 | if not hasXMLProperty(self.xmlFile, key) then |
47 | break; |
48 | end; |
49 | local node = Utils.indexToObject(self.components, getXMLString(self.xmlFile, key.."#index")); |
50 | if node ~= nil then |
51 | |
52 | local x,y,z = getTranslation(node); |
53 | local raycastNodes = {}; |
54 | |
55 | local j = 0; |
56 | while true do |
57 | local raycastKey = key..string.format(".raycastNode(%d)", j); |
58 | if not hasXMLProperty(self.xmlFile, raycastKey) then |
59 | break; |
60 | end; |
61 | local raycastNode = Utils.indexToObject(self.components, getXMLString(self.xmlFile, raycastKey.."#index")); |
62 | if raycastNode ~= nil then |
63 | assert(getParent(node) == getParent(raycastNode)); |
64 | |
65 | local _,y1,_ = getTranslation(raycastNode); |
66 | table.insert(raycastNodes, {node=raycastNode, yDiff=y1-y}); |
67 | end; |
68 | j = j+1; |
69 | end; |
70 | if table.getn(raycastNodes) > 0 then |
71 | |
72 | |
73 | local minY = Utils.getNoNil(getXMLFloat(self.xmlFile, key.."#minY"), y-1); |
74 | local maxY = Utils.getNoNil(getXMLFloat(self.xmlFile, key.."#maxY"), minY+1); |
75 | local yOffset = Utils.getNoNil(getXMLFloat(self.xmlFile, key.."#yOffset"), 0); |
76 | local moveSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, key.."#moveSpeed"), 1)/1000; |
77 | |
78 | local adjustedNode = {node=node, raycastNodes=raycastNodes, x=x, y=y, z=z, curY=y, targetY=y, minY=minY, maxY=maxY, yOffset=yOffset, moveSpeed=moveSpeed} |
79 | |
80 | adjustedNode.foldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, key.."#foldMinLimit"), 0); |
81 | adjustedNode.foldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, key.."#foldMaxLimit"), 1); |
82 | |
83 | local translationNode = Utils.indexToObject(self.components, getXMLString(self.xmlFile, key.."#translationNode")); |
84 | if translationNode ~= nil then |
85 | local tx, ty, tz = getWorldTranslation(translationNode); |
86 | local tx, ty, tz = worldToLocal(node, tx, ty, tz); |
87 | |
88 | adjustedNode.translationNode=translationNode; |
89 | adjustedNode.tx=tx; |
90 | adjustedNode.ty=ty; |
91 | adjustedNode.tz=tz; |
92 | end; |
93 | table.insert(self.groundAdjustedNodes, adjustedNode); |
94 | end; |
95 | end; |
96 | i = i + 1; |
97 | end; |
98 | end; |
update
DescriptionCalled on updateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
112 | function ManureBarrel:update(dt) |
113 | if self:getIsActive() then |
114 | if self.isClient then |
115 | for _, node in pairs(self.groundAdjustedNodes) do |
116 | if node.targetY ~= node.curY then |
117 | if node.targetY > node.curY then |
118 | node.curY = math.min(node.curY + node.moveSpeed*dt, node.targetY); |
119 | else |
120 | node.curY = math.max(node.curY - node.moveSpeed*dt, node.targetY); |
121 | end; |
122 | setTranslation(node.node, node.x, node.curY, node.z); |
123 | |
124 | |
125 | if node.translationNode ~= nil then |
126 | local tx, ty, tz = localToWorld(node.node, node.tx, node.ty, node.tz); |
127 | local tx, ty, tz = worldToLocal(getParent(node.translationNode), tx, ty, tz); |
128 | setTranslation(node.translationNode, tx, ty, tz); |
129 | end; |
130 | end; |
131 | end; |
132 | end; |
133 | end; |
134 | end; |
updateTick
DescriptionCalled on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
139 | function ManureBarrel:updateTick(dt) |
140 | if self:getIsActive() then |
141 | |
142 | if self.isClient then |
143 | |
144 | local foldAnimTime = self.foldAnimTime; |
145 | |
146 | for _, node in pairs(self.groundAdjustedNodes) do |
147 | if foldAnimTime == nil or (foldAnimTime <= node.foldMaxLimit and foldAnimTime >= node.foldMinLimit) then |
148 | |
149 | local newY = node.minY; |
150 | |
151 | for _, raycastNode in pairs(node.raycastNodes) do |
152 | local x,y,z = getWorldTranslation(raycastNode.node); |
153 | local dx,dy,dz = localDirectionToWorld(raycastNode.node, 0, -1, 0); |
154 | |
155 | self.lastRaycastDistance = 0; |
156 | raycastClosest(x, y, z, dx, dy, dz, "groundAdjustRaycastCallback", 4, self); |
157 | if self.lastRaycastDistance ~= 0 then |
158 | newY = math.max(newY, node.y - self.lastRaycastDistance + raycastNode.yDiff - node.yOffset); |
159 | end; |
160 | end; |
161 | newY = Utils.clamp(newY, node.minY, node.maxY); |
162 | node.targetY = newY; |
163 | _, node.curY, _ = getTranslation(node.node); |
164 | end; |
165 | end; |
166 | end; |
167 | end; |
168 | end; |
draw
DescriptionCalled on drawDefinition
draw()Code
172 | function ManureBarrel:draw() |
173 | end; |
onAttachImplement
DescriptionCalled on attaching a implementDefinition
onAttachImplement(table implement)Arguments
table | implement | implement to attach |
178 | function ManureBarrel:onAttachImplement(implement) |
179 | local object = implement.object; |
180 | if self.attachToolJointIndex ~= nil and implement.jointDescIndex then |
181 | self.attachedTool = object; |
182 | if self.attachToolAnimation ~= nil and self.playAnimation ~= nil then |
183 | self:playAnimation(self.attachToolAnimation, 1, self:getAnimationTime(self.attachToolAnimation), true); |
184 | end; |
185 | if self.attachedTool.aiLeftMarker ~= nil and self.attachedTool.aiRightMarker ~= nil and self.attachedTool.aiBackMarker ~= nil then |
186 | self.aiLeftMarkerBackup, self.aiRightMarkerBackup, self.aiBackMarkerBackup = self.aiLeftMarker, self.aiRightMarker, self.aiBackMarker; |
187 | |
188 | self.aiLeftMarker, self.aiRightMarker, self.aiBackMarker = self.attachedTool.aiLeftMarker, self.attachedTool.aiRightMarker, self.attachedTool.aiBackMarker; |
189 | self.attachedTool.aiLeftMarker, self.attachedTool.aiRightMarker, self.attachedTool.aiBackMarker = nil, nil, nil; |
190 | |
191 | self.terrainDetailRequiredValueRangesBackUp = {}; |
192 | for _,range in pairs(self.terrainDetailRequiredValueRanges) do |
193 | table.insert(self.terrainDetailRequiredValueRangesBackUp, {range[1], range[2], range[3], range[4]}); |
194 | end |
195 | self.terrainDetailProhibitValueRangesBackUp = {}; |
196 | for _,range in pairs(self.terrainDetailProhibitValueRanges) do |
197 | table.insert(self.terrainDetailProhibitValueRangesBackUp, {range[1], range[2], range[3], range[4]}); |
198 | end |
199 | |
200 | self.terrainDetailRequiredValueRanges = self.attachedTool.terrainDetailRequiredValueRanges; |
201 | self.terrainDetailProhibitValueRanges = self.attachedTool.terrainDetailProhibitValueRanges; |
202 | end; |
203 | end; |
204 | end; |
onDetachImplement
DescriptionCalled on detaching a implementDefinition
onDetachImplement(integer implementIndex)Arguments
integer | implementIndex | index of implement to detach |
209 | function ManureBarrel:onDetachImplement(implementIndex) |
210 | local object = self.attachedImplements[implementIndex].object; |
211 | if object ~= nil then |
212 | if self.attachedImplements[implementIndex].jointDescIndex == self.attachToolJointIndex then |
213 | if self.attachToolAnimation ~= nil and self.playAnimation ~= nil then |
214 | self:playAnimation(self.attachToolAnimation, -1, self:getAnimationTime(self.attachToolAnimation), true); |
215 | end; |
216 | if self.aiLeftMarkerBackup ~= nil and self.aiRightMarkerBackup ~= nil and self.aiBackMarkerBackup ~= nil then |
217 | self.attachedTool.aiLeftMarker, self.attachedTool.aiRightMarker, self.attachedTool.aiBackMarker = self.aiLeftMarker, self.aiRightMarker, self.aiBackMarker; |
218 | self.aiLeftMarker, self.aiRightMarker, self.aiBackMarker = self.aiLeftMarkerBackup, self.aiRightMarkerBackup, self.aiBackMarkerBackup; |
219 | |
220 | self.terrainDetailRequiredValueRanges = {}; |
221 | for _,range in pairs(self.terrainDetailRequiredValueRangesBackUp) do |
222 | table.insert(self.terrainDetailRequiredValueRanges, {range[1], range[2], range[3], range[4]}); |
223 | end |
224 | self.terrainDetailProhibitValueRanges = {}; |
225 | for _,range in pairs(self.terrainDetailProhibitValueRangesBackUp) do |
226 | table.insert(self.terrainDetailProhibitValueRanges, {range[1], range[2], range[3], range[4]}); |
227 | end |
228 | end; |
229 | self.attachedTool = nil; |
230 | end; |
231 | end; |
232 | end; |
getIsReadyToSpray
DescriptionReturns if tool is ready to sprayDefinition
getIsReadyToSpray()Return Values
boolean | isReady | is ready to spray |
237 | function ManureBarrel:getIsReadyToSpray(superFunc) |
238 | if self.attachedTool ~= nil then |
239 | return false; |
240 | end; |
241 | |
242 | if superFunc ~= nil then |
243 | superFunc(self); |
244 | end; |
245 | return true; |
246 | end; |
getAreEffectsVisible
DescriptionReturns if effects are visibleDefinition
getAreEffectsVisible()Return Values
boolean | areVisible | effects are visible |
251 | function ManureBarrel:getAreEffectsVisible(superFunc) |
252 | if self.attachedTool ~= nil then |
253 | return false; |
254 | end; |
255 | |
256 | if superFunc ~= nil then |
257 | return superFunc(self); |
258 | end; |
259 | return true; |
260 | end; |
getIsWorkAreaActive
DescriptionReturns true if work area is activeDefinition
getIsWorkAreaActive(table workArea)Arguments
table | workArea | workArea |
boolean | isActive | work area is active |
266 | function ManureBarrel:getIsWorkAreaActive(superFunc, workArea) |
267 | if self.attachedTool ~= nil then |
268 | return false; |
269 | end; |
270 | |
271 | if superFunc ~= nil then |
272 | return superFunc(self, workArea); |
273 | end; |
274 | return true; |
275 | end; |
getLitersPerSecond
DescriptionReturns usage in liter per secondDefinition
getLitersPerSecond(integer fillType)Arguments
integer | fillType | fill type |
float | usage | usage in liter per second |
281 | function ManureBarrel:getLitersPerSecond(superFunc, fillType) |
282 | if self.attachedTool ~= nil and self.attachedTool.getLitersPerSecond ~= nil then |
283 | return self.attachedTool:getLitersPerSecond(fillType); |
284 | end; |
285 | |
286 | if superFunc ~= nil then |
287 | return superFunc(self, fillType); |
288 | end; |
289 | return self.defaultSprayLitersPerSecond; |
290 | end; |
getIsInWorkPosition
DescriptionReturns true if it is in work positionDefinition
getIsInWorkPosition()Return Values
boolean | inWorkPosition | is in work position |
295 | function ManureBarrel:getIsInWorkPosition() |
296 | if self.attachedTool == nil then |
297 | if foldAnimTime ~= nil and (foldAnimTime > self.manureBarrelFoldMaxLimit or foldAnimTime < self.manureBarrelFoldMinLimit) then |
298 | return false; |
299 | end; |
300 | else |
301 | --return self.attachedTool:getIsInWorkPosition(); |
302 | if self.attachedTool:getIsInWorkPosition() then |
303 | local implement = self:getImplementByObject(self.attachedTool); |
304 | if implement ~= nil then |
305 | local jointDesc = self.attacherJoints[implement.jointDescIndex]; |
306 | if jointDesc.allowsLowering and self.attachedTool.aiNeedsLowering then |
307 | if jointDesc.moveAlpha == jointDesc.lowerAlpha then |
308 | return true; |
309 | else |
310 | self:setJointMoveDown(implement.jointDescIndex, true, true); |
311 | return false; |
312 | end |
313 | end; |
314 | end; |
315 | else |
316 | return false; |
317 | end; |
318 | end; |
319 | |
320 | if superFunc ~= nil then |
321 | return superFunc(self); |
322 | end |
323 | |
324 | return true; |
325 | end; |
getCanBeTurnedOn
DescriptionReturns if can be turned onDefinition
getCanBeTurnedOn()Return Values
boolean | canBeTurnedOn | vehicle can be turned on |
330 | function ManureBarrel:getCanBeTurnedOn(superFunc) |
331 | if self.attachedTool ~= nil then |
332 | if self.attachedTool.isAlwaysTurnedOn and self.attachedTool.needsTankActivation and self.attachedTool.activateTankOnLowering then |
333 | return false; |
334 | end; |
335 | end; |
336 | |
337 | if superFunc ~= nil then |
338 | return superFunc(self); |
339 | end |
340 | return true; |
341 | end; |
getIsTurnedOnAllowed
DescriptionReturns if turn on is allowedDefinition
getIsTurnedOnAllowed(boolean isTurnedOn)Arguments
boolean | isTurnedOn | is turned on |
boolean | allow | allow turn on |
347 | function ManureBarrel:getIsTurnedOnAllowed(superFunc, isTurnedOn) |
348 | if isTurnedOn then |
349 | if self.attachedTool == nil then |
350 | local foldAnimTime = self.foldAnimTime; |
351 | if foldAnimTime ~= nil and (foldAnimTime > self.manureBarrelFoldMaxLimit or foldAnimTime < self.manureBarrelFoldMinLimit) then |
352 | return false; |
353 | end; |
354 | else |
355 | if self.attachedTool:getIsInWorkPosition() then |
356 | local implement = self:getImplementByObject(self.attachedTool); |
357 | if implement ~= nil then |
358 | local jointDesc = self.attacherJoints[implement.jointDescIndex]; |
359 | if jointDesc.allowsLowering and self.attachedTool.aiNeedsLowering then |
360 | return jointDesc.moveDown; |
361 | end; |
362 | end; |
363 | else |
364 | return false; |
365 | end; |
366 | end; |
367 | end; |
368 | |
369 | if superFunc ~= nil then |
370 | return superFunc(self, isTurnedOn); |
371 | end |
372 | |
373 | return true; |
374 | end; |
setIsTurnedOn
DescriptionSet is turned on stateDefinition
setIsTurnedOn(boolean isTurnedOn, boolean noEventSend)Arguments
boolean | isTurnedOn | new is is turned on state |
boolean | noEventSend | no event send |
380 | function ManureBarrel:setIsTurnedOn(superFunc, isTurnedOn, noEventSend) |
381 | superFunc(self, isTurnedOn, noEventSend); |
382 | end; |
onAiTurnOn
DescriptionCalled on ai turn onDefinition
onAiTurnOn()Code
386 | function ManureBarrel:onAiTurnOn() |
387 | if self.attachedTool ~= nil then |
388 | self.attachedTool:onAiTurnOn(); |
389 | end; |
390 | end; |
onAiTurnOff
DescriptionCalled on ai turn offDefinition
onAiTurnOff()Code
394 | function ManureBarrel:onAiTurnOff() |
395 | if self.attachedTool ~= nil then |
396 | self.attachedTool:onAiTurnOff(); |
397 | end; |
398 | end; |
onAiLower
DescriptionCalled on ai lowerDefinition
onAiLower()Code
402 | function ManureBarrel:onAiLower() |
403 | if self.attachedTool ~= nil then |
404 | local implement = self:getImplementByObject(self.attachedTool); |
405 | if implement ~= nil then |
406 | local jointDesc = self.attacherJoints[implement.jointDescIndex]; |
407 | if jointDesc.allowsLowering and self.attachedTool.aiNeedsLowering then |
408 | if jointDesc.moveAlpha ~= jointDesc.lowerAlpha then |
409 | self:setJointMoveDown(implement.jointDescIndex, true, true); |
410 | end; |
411 | end; |
412 | end; |
413 | end; |
414 | end; |
onAiRaise
DescriptionCalled on ai raiseDefinition
onAiRaise()Code
418 | function ManureBarrel:onAiRaise() |
419 | if self.attachedTool ~= nil then |
420 | local implement = self:getImplementByObject(self.attachedTool); |
421 | if implement ~= nil then |
422 | local jointDesc = self.attacherJoints[implement.jointDescIndex]; |
423 | if jointDesc.allowsLowering and self.attachedTool.aiNeedsLowering then |
424 | self:setJointMoveDown(implement.jointDescIndex, false, true); |
425 | end; |
426 | end; |
427 | end; |
428 | end; |
getIsAIReadyForWork
DescriptionReturns true if vehicle is ready for ai workDefinition
getIsAIReadyForWork()Return Values
boolean | isReady | is ready for ai work |
433 | function ManureBarrel:getIsAIReadyForWork() |
434 | local isReady = true; |
435 | if self.attachedTool ~= nil then |
436 | local implement = self:getImplementByObject(self.attachedTool); |
437 | local jointDesc = self.attacherJoints[implement.jointDescIndex]; |
438 | local isAttachedToolReady = self.attachedTool:getIsAIReadyForWork(); |
439 | if jointDesc.allowsLowering and self.attachedTool.aiNeedsLowering then |
440 | if jointDesc.moveDown then |
441 | return jointDesc.moveAlpha == jointDesc.lowerAlpha and isAttachedToolReady; |
442 | else |
443 | self:setJointMoveDown(implement.jointDescIndex, true, false); |
444 | return false; |
445 | end |
446 | else |
447 | return isReady and isAttachedToolReady; |
448 | end |
449 | end |
450 | return isReady; |
451 | end |
groundAdjustRaycastCallback
DescriptionRaycast callbackDefinition
groundAdjustRaycastCallback(integer transformId, float x, float y, float z, float distance)Arguments
integer | transformId | id raycasted object |
float | x | x raycast position |
float | y | y raycast position |
float | z | z raycast position |
float | distance | distance to raycast position |
460 | function ManureBarrel:groundAdjustRaycastCallback(transformId, x, y, z, distance) |
461 | self.lastRaycastDistance = distance; |
462 | end; |