Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- AIConveyorBelt
- AIImplement
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BunkerSiloCompacter
- BunkerSiloInteractor
- BuyableBale
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- JigglingParts
- Leveler
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- MixerWagon
- Motorized
- Mountable
- Mower
- Pickup
- Pipe
- Plow
- PowerConsumer
- PowerTakeOffs
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StrawBlower
- StumpCutter
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TipOccluder
- Trailer
- TreePlanter
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Wearable
- Weeder
- Wheels
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
WoodCrusher
DescriptionSpecialization for wood crusher allowing to cut and convert tree trunks into wood chipsFunctions
- crushSplitShape
- deleteWoodCrusher
- getCanBeTurnedOn
- getDirtMultiplier
- getWearMultiplier
- loadWoodCrusher
- onCrushedSplitShape
- onDelete
- onLoad
- onReadUpdateStream
- onTurnedOff
- onTurnedOn
- onUpdate
- onUpdateTick
- onWriteUpdateStream
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- turnOffWoodCrusher
- turnOnWoodCrusher
- updateTickWoodCrusher
- updateWoodCrusher
- woodCrusherMoveTriggerCallback
- woodCrusherSplitShapeCallback
crushSplitShape
DescriptionCrush split shapeDefinition
crushSplitShape(integer shape)Arguments
integer | shape | id of shape |
501 | function WoodCrusher.crushSplitShape(self, woodCrusher, shape) |
502 | local splitType = g_splitTypeManager:getSplitTypeByIndex(getSplitType(shape)) |
503 | if splitType ~= nil and splitType.woodChipsPerLiter > 0 then |
504 | local volume = getVolume(shape) |
505 | delete(shape) |
506 | woodCrusher.crushingTime = 1000 |
507 | self:onCrushedSplitShape(splitType, volume) |
508 | end |
509 | end |
deleteWoodCrusher
DescriptionDelete wood crusherDefinition
deleteWoodCrusher()Code
323 | function WoodCrusher.deleteWoodCrusher(self, woodCrusher) |
324 | if self.isServer and woodCrusher.moveTriggers ~= nil then |
325 | for _,node in pairs(woodCrusher.moveTriggers) do |
326 | removeTrigger(node) |
327 | end |
328 | end |
329 | |
330 | if self.isClient then |
331 | g_effectManager:deleteEffects(woodCrusher.crushEffects) |
332 | g_soundManager:deleteSamples(woodCrusher.samples) |
333 | g_animationManager:deleteAnimations(woodCrusher.animationNodes) |
334 | end |
335 | end |
getCanBeTurnedOn
DescriptionReturns if user is allowed to turn on the vehicleDefinition
getCanBeTurnedOn()Return Values
boolean | allow | allow turn on |
187 | function WoodCrusher:getCanBeTurnedOn(superFunc) |
188 | local spec = self.spec_woodCrusher |
189 | if spec.turnOnAutomatically then |
190 | return false |
191 | end |
192 | |
193 | return superFunc(self) |
194 | end |
getDirtMultiplier
DescriptionReturns current dirt multiplierDefinition
getDirtMultiplier()Return Values
float | dirtMultiplier | current dirt multiplier |
199 | function WoodCrusher:getDirtMultiplier(superFunc) |
200 | local multiplier = superFunc(self) |
201 | |
202 | local spec = self.spec_woodCrusher |
203 | if spec.crushingTime > 0 then |
204 | multiplier = multiplier + self:getWorkDirtMultiplier() |
205 | end |
206 | |
207 | return multiplier |
208 | end |
getWearMultiplier
DescriptionReturns current wear multiplierDefinition
getWearMultiplier()Return Values
float | dirtMultiplier | current wear multiplier |
213 | function WoodCrusher:getWearMultiplier(superFunc) |
214 | local multiplier = superFunc(self) |
215 | |
216 | local spec = self.spec_woodCrusher |
217 | if spec.crushingTime > 0 then |
218 | multiplier = multiplier + self:getWorkWearMultiplier() |
219 | end |
220 | |
221 | return multiplier |
222 | end |
loadWoodCrusher
DescriptionLoad wood crusher from xml fileDefinition
loadWoodCrusher(integer xmlFile, integer rootNode)Arguments
integer | xmlFile | id of xml object |
integer | rootNode | id of root node |
237 | function WoodCrusher.loadWoodCrusher(self, woodCrusher, xmlFile, rootNode) |
238 | woodCrusher.vehicle = self |
239 | |
240 | woodCrusher.woodCrusherSplitShapeCallback = WoodCrusher.woodCrusherSplitShapeCallback |
241 | woodCrusher.woodCrusherMoveTriggerCallback = WoodCrusher.woodCrusherMoveTriggerCallback |
242 | |
243 | local xmlRoot = getXMLRootName(xmlFile) |
244 | |
245 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".woodCrusher.moveTrigger(0)#index", xmlRoot .. ".woodCrusher.moveTriggers.trigger#node") --FS17 to FS19 |
246 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".woodCrusher.moveCollision(0)#index", xmlRoot .. ".woodCrusher.moveCollisions.collision#node") --FS17 to FS19 |
247 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".woodCrusher.emitterShape(0)", xmlRoot .. ".woodCrusher.crushEffects with effectClass 'ParticleEffect'") --FS17 to FS19 |
248 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".woodCrusherStartSound", xmlRoot .. ".woodCrusher.sounds.start") --FS17 to FS19 |
249 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".woodCrusherIdleSound", xmlRoot .. ".woodCrusher.sounds.idle") --FS17 to FS19 |
250 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".woodCrusherWorkSound", xmlRoot .. ".woodCrusher.sounds.work") --FS17 to FS19 |
251 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".woodCrusherStopSound", xmlRoot .. ".woodCrusher.sounds.stop") --FS17 to FS19 |
252 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".turnedOnRotationNodes.turnedOnRotationNode#type", xmlRoot .. ".woodCrusher.animationNodes.animationNode", "woodCrusher") --FS17 to FS19 |
253 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, xmlRoot .. ".turnedOnScrollers.turnedOnScroller", xmlRoot .. ".woodCrusher.animationNodes.animationNode") --FS17 to FS19 |
254 | |
255 | local baseKey = xmlRoot .. ".woodCrusher" |
256 | woodCrusher.cutNode = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, baseKey.."#cutNode"), self.i3dMappings) |
257 | woodCrusher.mainDrumRefNode = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, baseKey.."#mainDrumRefNode"), self.i3dMappings) |
258 | |
259 | woodCrusher.moveTriggers = {} |
260 | local i = 0 |
261 | while true do |
262 | local key = string.format("%s.moveTriggers.trigger(%d)", baseKey, i) |
263 | if not hasXMLProperty(xmlFile, key) then |
264 | break |
265 | end |
266 | |
267 | local node = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, key .. "#node"), self.i3dMappings) |
268 | if node ~= nil then |
269 | table.insert(woodCrusher.moveTriggers, node) |
270 | end |
271 | i = i + 1 |
272 | end |
273 | |
274 | woodCrusher.moveColNodes = {} |
275 | i = 0 |
276 | while true do |
277 | local key = string.format("%s.moveCollisions.collision(%d)", baseKey, i) |
278 | if not hasXMLProperty(xmlFile, key) then |
279 | break |
280 | end |
281 | |
282 | local node = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, key .. "#node"), self.i3dMappings) |
283 | if node ~= nil then |
284 | table.insert(woodCrusher.moveColNodes, node) |
285 | end |
286 | i = i + 1 |
287 | end |
288 | |
289 | woodCrusher.moveVelocityZ = Utils.getNoNil(getXMLFloat(xmlFile, baseKey.."#moveVelocityZ"), 0.8) -- m/s |
290 | woodCrusher.moveMaxForce = Utils.getNoNil(getXMLFloat(xmlFile, baseKey.."#moveMaxForce"), 7) -- input is kN |
291 | woodCrusher.downForceNode = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, baseKey.."#downForceNode"), self.i3dMappings) |
292 | woodCrusher.downForce = Utils.getNoNil(getXMLFloat(xmlFile, baseKey.."#downForce"), 2) |
293 | woodCrusher.cutSizeY = Utils.getNoNil(getXMLFloat(xmlFile, baseKey.."#cutSizeY"), 1) |
294 | woodCrusher.cutSizeZ = Utils.getNoNil(getXMLFloat(xmlFile, baseKey.."#cutSizeZ"), 1) |
295 | |
296 | woodCrusher.moveTriggerNodes = {} |
297 | if self.isServer and woodCrusher.moveTriggers ~= nil then |
298 | for _,node in pairs(woodCrusher.moveTriggers) do |
299 | addTrigger(node, "woodCrusherMoveTriggerCallback", woodCrusher) |
300 | end |
301 | end |
302 | |
303 | woodCrusher.crushNodes = {} |
304 | woodCrusher.crushingTime = 0 |
305 | woodCrusher.turnOnAutomatically = Utils.getNoNil(getXMLBool(xmlFile, baseKey .. "#automaticallyTurnOn"), false) |
306 | |
307 | if self.isClient then |
308 | woodCrusher.crushEffects = g_effectManager:loadEffect(xmlFile, baseKey..".crushEffects", rootNode, self, self.i3dMappings) |
309 | |
310 | woodCrusher.animationNodes = g_animationManager:loadAnimations(xmlFile, baseKey..".animationNodes", rootNode, self, self.i3dMappings) |
311 | |
312 | woodCrusher.isWorkSamplePlaying = false |
313 | woodCrusher.samples = {} |
314 | woodCrusher.samples.start = g_soundManager:loadSampleFromXML(xmlFile, baseKey..".sounds", "start", self.baseDirectory, rootNode, 1, AudioGroup.VEHICLE, self.i3dMappings, self) |
315 | woodCrusher.samples.stop = g_soundManager:loadSampleFromXML(xmlFile, baseKey..".sounds", "stop", self.baseDirectory, rootNode, 1, AudioGroup.VEHICLE, self.i3dMappings, self) |
316 | woodCrusher.samples.work = g_soundManager:loadSampleFromXML(xmlFile, baseKey..".sounds", "work", self.baseDirectory, rootNode, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
317 | woodCrusher.samples.idle = g_soundManager:loadSampleFromXML(xmlFile, baseKey..".sounds", "idle", self.baseDirectory, rootNode, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
318 | end |
319 | end |
onCrushedSplitShape
DescriptionCalled on crush split shapeDefinition
onCrushedSplitShape(table splitType, float volume)Arguments
table | splitType | split type |
float | volume | volume |
228 | function WoodCrusher:onCrushedSplitShape(splitType, volume) |
229 | local spec = self.spec_woodCrusher |
230 | self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, volume * 1000 * splitType.woodChipsPerLiter, FillType.WOODCHIPS, ToolType.UNDEFINED) |
231 | end |
onDelete
DescriptionCalled on deletingDefinition
onDelete()Code
70 | function WoodCrusher:onDelete() |
71 | WoodCrusher.deleteWoodCrusher(self, self.spec_woodCrusher) |
72 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
51 | function WoodCrusher:onLoad(savegame) |
52 | local spec = self.spec_woodCrusher |
53 | |
54 | WoodCrusher.loadWoodCrusher(self, spec, self.xmlFile, self.components) |
55 | |
56 | local moveColDisableCollisionPairs = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.woodCrusher#moveColDisableCollisionPairs"), true) |
57 | if moveColDisableCollisionPairs then |
58 | for _, component in pairs(self.components) do |
59 | for _, node in pairs(spec.moveColNodes) do |
60 | setPairCollision(component.node, node, false) |
61 | end |
62 | end |
63 | end |
64 | |
65 | spec.fillUnitIndex = Utils.getNoNil(getXMLInt(self.xmlFile, "vehicle.woodCrusher#fillUnitIndex"), 1) |
66 | end |
onReadUpdateStream
DescriptionCalled on on updateDefinition
onReadUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
79 | function WoodCrusher:onReadUpdateStream(streamId, timestamp, connection) |
80 | if connection:getIsServer() then |
81 | local spec = self.spec_woodCrusher |
82 | if streamReadBool(streamId) then |
83 | spec.crushingTime = 1000 |
84 | else |
85 | spec.crushingTime = 0 |
86 | end |
87 | end |
88 | end |
onTurnedOff
DescriptionCalled on turn offDefinition
onTurnedOff(boolean noEventSend)Arguments
boolean | noEventSend | no event send |
180 | function WoodCrusher:onTurnedOff() |
181 | WoodCrusher.turnOffWoodCrusher(self, self.spec_woodCrusher) |
182 | end |
onTurnedOn
DescriptionCalled on turn onDefinition
onTurnedOn(boolean noEventSend)Arguments
boolean | noEventSend | no event send |
173 | function WoodCrusher:onTurnedOn() |
174 | WoodCrusher.turnOnWoodCrusher(self, self.spec_woodCrusher) |
175 | end |
onUpdate
DescriptionCalled on updateDefinition
onUpdate(float dt, boolean isActiveForInput, boolean isSelected)Arguments
float | dt | time since last call in ms |
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
107 | function WoodCrusher:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
108 | WoodCrusher.updateWoodCrusher(self, self.spec_woodCrusher, dt, self:getIsTurnedOn()) |
109 | end |
onUpdateTick
DescriptionCalled on update tickDefinition
onUpdateTick(float dt, boolean isActiveForInput, boolean isSelected)Arguments
float | dt | time since last call in ms |
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
116 | function WoodCrusher:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
117 | WoodCrusher.updateTickWoodCrusher(self, self.spec_woodCrusher, dt, self:getIsTurnedOn()) |
118 | |
119 | local spec = self.spec_woodCrusher |
120 | -- turn on/off automatically if tree node is in trigger |
121 | if self.isServer then |
122 | if g_currentMission.missionInfo.automaticMotorStartEnabled then |
123 | if spec.turnOnAutomatically and self.setIsTurnedOn ~= nil then |
124 | if next(spec.moveTriggerNodes) ~= nil then |
125 | if self.getIsMotorStarted ~= nil then |
126 | if not self:getIsMotorStarted() then |
127 | self:startMotor() |
128 | end |
129 | else |
130 | if self.attacherVehicle ~= nil then |
131 | if self.attacherVehicle.getIsMotorStarted ~= nil then |
132 | if not self.attacherVehicle:getIsMotorStarted() then |
133 | self.attacherVehicle:startMotor() |
134 | end |
135 | end |
136 | end |
137 | end |
138 | |
139 | if not self.isControlled and not self:getIsTurnedOn() and self:getCanBeTurnedOn() then |
140 | self:setIsTurnedOn(true) |
141 | end |
142 | spec.turnOffTimer = 3000 |
143 | else |
144 | if self:getIsTurnedOn() then |
145 | if spec.turnOffTimer == nil then |
146 | spec.turnOffTimer = 3000 |
147 | end |
148 | spec.turnOffTimer = spec.turnOffTimer - dt |
149 | |
150 | if spec.turnOffTimer < 0 then |
151 | local rootAttacherVehicle = self:getRootVehicle() |
152 | |
153 | if not rootAttacherVehicle.isControlled then |
154 | if self.getIsMotorStarted ~= nil then |
155 | if self:getIsMotorStarted() then |
156 | self:stopMotor() |
157 | end |
158 | end |
159 | |
160 | self:setIsTurnedOn(false) |
161 | end |
162 | end |
163 | end |
164 | end |
165 | end |
166 | end |
167 | end |
168 | end |
onWriteUpdateStream
DescriptionCalled on on updateDefinition
onWriteUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
95 | function WoodCrusher:onWriteUpdateStream(streamId, connection, dirtyMask) |
96 | if not connection:getIsServer() then |
97 | local spec = self.spec_woodCrusher |
98 | streamWriteBool(streamId, spec.crushingTime > 0) |
99 | end |
100 | end |
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 WoodCrusher.prerequisitesPresent(specializations) |
18 | return SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations) and SpecializationUtil.hasSpecialization(FillUnit, specializations) |
19 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
37 | function WoodCrusher.registerEventListeners(vehicleType) |
38 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", WoodCrusher) |
39 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", WoodCrusher) |
40 | SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", WoodCrusher) |
41 | SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", WoodCrusher) |
42 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", WoodCrusher) |
43 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", WoodCrusher) |
44 | SpecializationUtil.registerEventListener(vehicleType, "onTurnedOn", WoodCrusher) |
45 | SpecializationUtil.registerEventListener(vehicleType, "onTurnedOff", WoodCrusher) |
46 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
23 | function WoodCrusher.registerFunctions(vehicleType) |
24 | SpecializationUtil.registerFunction(vehicleType, "onCrushedSplitShape", WoodCrusher.onCrushedSplitShape) |
25 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
29 | function WoodCrusher.registerOverwrittenFunctions(vehicleType) |
30 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDirtMultiplier", WoodCrusher.getDirtMultiplier) |
31 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getWearMultiplier", WoodCrusher.getWearMultiplier) |
32 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeTurnedOn", WoodCrusher.getCanBeTurnedOn) |
33 | end |
turnOffWoodCrusher
DescriptionTurn off wood crusherDefinition
turnOffWoodCrusher()Code
473 | function WoodCrusher.turnOffWoodCrusher(self, woodCrusher) |
474 | if self.isServer then |
475 | for node in pairs(woodCrusher.crushNodes) do |
476 | WoodCrusher.crushSplitShape(self, woodCrusher, node) |
477 | woodCrusher.crushNodes[node] = nil |
478 | end |
479 | if woodCrusher.moveColNodes ~= nil then |
480 | for _,node in pairs(woodCrusher.moveColNodes) do |
481 | setFrictionVelocity(node, 0.0) |
482 | end |
483 | end |
484 | end |
485 | |
486 | if self.isClient then |
487 | g_effectManager:stopEffects(woodCrusher.crushEffects) |
488 | g_soundManager:stopSamples(woodCrusher.samples) |
489 | g_soundManager:playSample(woodCrusher.samples.stop) |
490 | woodCrusher.isWorkSamplePlaying = false |
491 | |
492 | if self.isClient then |
493 | g_animationManager:stopAnimations(woodCrusher.animationNodes) |
494 | end |
495 | end |
496 | end |
turnOnWoodCrusher
DescriptionTurn on wood crusherDefinition
turnOnWoodCrusher()Code
452 | function WoodCrusher.turnOnWoodCrusher(self, woodCrusher) |
453 | if self.isServer and woodCrusher.moveColNodes ~= nil then |
454 | for _,node in pairs(woodCrusher.moveColNodes) do |
455 | setFrictionVelocity(node, woodCrusher.moveVelocityZ) |
456 | end |
457 | end |
458 | |
459 | if self.isClient then |
460 | g_soundManager:stopSamples(woodCrusher.samples) |
461 | woodCrusher.isWorkSamplePlaying = false |
462 | g_soundManager:playSample(woodCrusher.samples.start) |
463 | g_soundManager:playSample(woodCrusher.samples.idle, 0, woodCrusher.samples.start) |
464 | |
465 | if self.isClient then |
466 | g_animationManager:startAnimations(woodCrusher.animationNodes) |
467 | end |
468 | end |
469 | end |
updateTickWoodCrusher
DescriptionUpdate tick wood crusherDefinition
updateTickWoodCrusher(float dt)Arguments
float | dt | time since last call in ms |
397 | function WoodCrusher.updateTickWoodCrusher(self, woodCrusher, dt, isTurnedOn) |
398 | if isTurnedOn then |
399 | if self.isServer then |
400 | if woodCrusher.cutNode ~= nil and next(woodCrusher.moveTriggerNodes) ~= nil then |
401 | local x,y,z = getWorldTranslation(woodCrusher.cutNode) |
402 | local nx,ny,nz = localDirectionToWorld(woodCrusher.cutNode, 1,0,0) |
403 | local yx,yy,yz = localDirectionToWorld(woodCrusher.cutNode, 0,1,0) |
404 | for id in pairs(woodCrusher.moveTriggerNodes) do |
405 | local lenBelow, lenAbove = getSplitShapePlaneExtents(id, x,y,z, nx,ny,nz) |
406 | if lenAbove ~= nil and lenBelow ~= nil then |
407 | if lenBelow <= 0.4 then |
408 | woodCrusher.moveTriggerNodes[id] = nil |
409 | WoodCrusher.crushSplitShape(self, woodCrusher, id) |
410 | elseif lenAbove >= 0.2 then |
411 | local minY = splitShape(id, x,y,z, nx,ny,nz, yx,yy,yz, woodCrusher.cutSizeY, woodCrusher.cutSizeZ, "woodCrusherSplitShapeCallback", woodCrusher) |
412 | if minY ~= nil then |
413 | woodCrusher.moveTriggerNodes[id] = nil |
414 | end |
415 | end |
416 | end |
417 | end |
418 | end |
419 | end |
420 | end |
421 | |
422 | if woodCrusher.crushingTime > 0 then |
423 | woodCrusher.crushingTime = math.max(woodCrusher.crushingTime - dt, 0) |
424 | end |
425 | |
426 | local isCrushing = woodCrusher.crushingTime > 0 |
427 | |
428 | if self.isClient then |
429 | if isCrushing then |
430 | g_effectManager:setFillType(woodCrusher.crushEffects, FillType.WOODCHIPS) |
431 | g_effectManager:startEffects(woodCrusher.crushEffects) |
432 | else |
433 | g_effectManager:stopEffects(woodCrusher.crushEffects) |
434 | end |
435 | |
436 | if isTurnedOn and isCrushing then |
437 | if not woodCrusher.isWorkSamplePlaying then |
438 | g_soundManager:playSample(woodCrusher.samples.work) |
439 | woodCrusher.isWorkSamplePlaying = true |
440 | end |
441 | else |
442 | if woodCrusher.isWorkSamplePlaying then |
443 | g_soundManager:stopSample(woodCrusher.samples.work) |
444 | woodCrusher.isWorkSamplePlaying = false |
445 | end |
446 | end |
447 | end |
448 | end |
updateWoodCrusher
DescriptionUpdate wood crusherDefinition
updateWoodCrusher(float dt)Arguments
float | dt | time since last call in ms |
340 | function WoodCrusher.updateWoodCrusher(self, woodCrusher, dt, isTurnedOn) |
341 | if isTurnedOn then |
342 | if self.isServer then |
343 | for node in pairs(woodCrusher.crushNodes) do |
344 | WoodCrusher.crushSplitShape(self, woodCrusher, node) |
345 | woodCrusher.crushNodes[node] = nil |
346 | woodCrusher.moveTriggerNodes[node] = nil |
347 | end |
348 | |
349 | local x,y,z = getTranslation(woodCrusher.mainDrumRefNode) |
350 | local _, ty, _ = 0, 0, 0 |
351 | local maxTreeSizeY = 0 |
352 | for id in pairs(woodCrusher.moveTriggerNodes) do |
353 | if not entityExists(id) then |
354 | woodCrusher.moveTriggerNodes[id] = nil |
355 | else |
356 | if woodCrusher.downForceNode ~= nil then |
357 | local x,y,z = getWorldTranslation(woodCrusher.downForceNode) |
358 | local nx,ny,nz = localDirectionToWorld(woodCrusher.downForceNode, 1,0,0) |
359 | local yx,yy,yz = localDirectionToWorld(woodCrusher.downForceNode, 0,1,0) |
360 | |
361 | local minY,maxY, minZ,maxZ = testSplitShape(id, x,y,z, nx,ny,nz, yx,yy,yz, woodCrusher.cutSizeY, woodCrusher.cutSizeZ) |
362 | if minY ~= nil then |
363 | local cx,cy,cz = localToWorld(woodCrusher.downForceNode, 0, (minY+maxY)*0.5, (minZ+maxZ)*0.5) |
364 | local downX,downY,downZ = localDirectionToWorld(woodCrusher.downForceNode, 0,-woodCrusher.downForce,0) |
365 | addForce(id, downX, downY, downZ, cx,cy,cz, false) |
366 | if woodCrusher.mainDrumRefNode ~= nil then |
367 | maxTreeSizeY = math.max(maxTreeSizeY, maxY) |
368 | end |
369 | end |
370 | |
371 | end |
372 | end |
373 | end |
374 | if woodCrusher.mainDrumRefNode ~= nil then |
375 | if maxTreeSizeY > 0 then |
376 | local a,b,c = localToWorld(woodCrusher.downForceNode, 0, maxTreeSizeY, 0) |
377 | _, ty, _ = worldToLocal(getParent(woodCrusher.mainDrumRefNode), a,b,c) |
378 | end |
379 | if ty > y then |
380 | y = math.min(y + 0.0003*dt, ty) |
381 | else |
382 | y = math.max(y - 0.0003*dt, ty) |
383 | end |
384 | setTranslation(woodCrusher.mainDrumRefNode, x,y,z) |
385 | end |
386 | |
387 | if next(woodCrusher.moveTriggerNodes) ~= nil or woodCrusher.crushingTime > 0 then |
388 | self:raiseActive() |
389 | end |
390 | end |
391 | end |
392 | end |
woodCrusherMoveTriggerCallback
DescriptionTrigger callbackDefinition
woodCrusherMoveTriggerCallback(integer triggerId, integer otherActorId, boolean onEnter, boolean onLeave, boolean onStay, integer otherShapeId)Arguments
integer | triggerId | id of trigger |
integer | otherActorId | id of other actor |
boolean | onEnter | on enter |
boolean | onLeave | on leave |
boolean | onStay | on stay |
integer | otherShapeId | id of other shape |
534 | function WoodCrusher.woodCrusherMoveTriggerCallback(self, triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
535 | local vehicle = g_currentMission.nodeToObject[otherActorId] |
536 | if vehicle == nil and getRigidBodyType(otherActorId) == "Dynamic" then |
537 | local splitType = g_splitTypeManager:getSplitTypeByIndex(getSplitType(otherActorId)) |
538 | if splitType ~= nil and splitType.woodChipsPerLiter > 0 then |
539 | if onEnter then |
540 | self.moveTriggerNodes[otherActorId] = Utils.getNoNil(self.moveTriggerNodes[otherActorId],0)+1 |
541 | self.vehicle:raiseActive() |
542 | elseif onLeave then |
543 | local c = self.moveTriggerNodes[otherActorId] |
544 | if c ~= nil then |
545 | c = c-1 |
546 | if c == 0 then |
547 | self.moveTriggerNodes[otherActorId] = nil |
548 | else |
549 | self.moveTriggerNodes[otherActorId] = c |
550 | end |
551 | end |
552 | end |
553 | end |
554 | end |
555 | end |
woodCrusherSplitShapeCallback
DescriptionSplit shape callbackDefinition
woodCrusherSplitShapeCallback(integer shape, boolean isBelow, boolean isAbove, float minY, float maxY, float minZ, float maxZ)Arguments
integer | shape | shape |
boolean | isBelow | is below |
boolean | isAbove | is above |
float | minY | min y split position |
float | maxY | max y split position |
float | minZ | min z split position |
float | maxZ | max z split position |
520 | function WoodCrusher.woodCrusherSplitShapeCallback(self, shape, isBelow, isAbove, minY, maxY, minZ, maxZ) |
521 | if not isBelow then |
522 | self.crushNodes[shape] = shape |
523 | end |
524 | end |