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
Foldable
DescriptionClass for vehicles which have folding partsFunctions
- prerequisitesPresent
- preLoad
- load
- postLoad
- applyInitialAnimation
- readStream
- writeStream
- getSaveAttributesAndNodes
- setRelativePosition
- keyEvent
- update
- updateTick
- draw
- onDeactivate
- onAiTurnOn
- onAiTurnOff
- onAiLower
- onAiRaise
- getIsAIReadyForWork
- startThreshing
- stopThreshing
- setFoldDirection
- setFoldState
- loadSpeedRotatingPartFromXML
- getIsSpeedRotatingPartActive
- loadDynamicWheelDataFromXML
- getIsVersatileYRotActive
- loadWorkAreaFromXML
- getIsWorkAreaActive
- loadLevelerNodeFromXML
- getIsLevelerPickupNodeActive
- getIsTurnedOnAllowed
- getIsToggleCoverAllowed
- getIsUnfolded
- getIsInWorkPosition
- getTurnedOnNotAllowedWarning
- isDetachAllowed
- isLowered
- getIsFoldAllowed
- getIsFoldMiddleAllowed
- getToggledFoldDirection
- getToggledFoldMiddleDirection
- onLowerAll
- setAnimTime
- allowLoadMovingToolStates
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
19 | function Foldable.prerequisitesPresent(specializations) |
20 | return true; |
21 | end |
preLoad
DescriptionCalled before loadingDefinition
preLoad(table savegame)Arguments
table | savegame | savegame |
26 | function Foldable:preLoad(savegame) |
27 | self.loadSpeedRotatingPartFromXML = Utils.overwrittenFunction(self.loadSpeedRotatingPartFromXML, Foldable.loadSpeedRotatingPartFromXML); |
28 | self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, Foldable.loadWorkAreaFromXML); |
29 | self.loadLevelerNodeFromXML = Utils.overwrittenFunction(self.loadLevelerNodeFromXML, Foldable.loadLevelerNodeFromXML); |
30 | self.loadDynamicWheelDataFromXML = Utils.overwrittenFunction(self.loadDynamicWheelDataFromXML, Foldable.loadDynamicWheelDataFromXML); |
31 | end |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
36 | function Foldable:load(savegame) |
37 | |
38 | self.setFoldDirection = SpecializationUtil.callSpecializationsFunction("setFoldDirection"); |
39 | self.setFoldState = SpecializationUtil.callSpecializationsFunction("setFoldState"); |
40 | self.getToggledFoldDirection = Foldable.getToggledFoldDirection; |
41 | self.getToggledFoldMiddleDirection = Foldable.getToggledFoldMiddleDirection; |
42 | |
43 | self.getIsFoldAllowed = Utils.overwrittenFunction(self.getIsFoldAllowed, Foldable.getIsFoldAllowed); |
44 | self.getIsFoldMiddleAllowed = Utils.overwrittenFunction(self.getIsFoldMiddleAllowed, Foldable.getIsFoldMiddleAllowed); |
45 | self.getIsSpeedRotatingPartActive = Utils.overwrittenFunction(self.getIsSpeedRotatingPartActive, Foldable.getIsSpeedRotatingPartActive); |
46 | self.getIsVersatileYRotActive = Utils.overwrittenFunction(self.getIsVersatileYRotActive, Foldable.getIsVersatileYRotActive); |
47 | self.getIsLevelerPickupNodeActive = Utils.overwrittenFunction(self.getIsLevelerPickupNodeActive, Foldable.getIsLevelerPickupNodeActive); |
48 | self.getIsWorkAreaActive = Utils.overwrittenFunction(self.getIsWorkAreaActive, Foldable.getIsWorkAreaActive); |
49 | self.getIsTurnedOnAllowed = Utils.overwrittenFunction(self.getIsTurnedOnAllowed, Foldable.getIsTurnedOnAllowed); |
50 | self.getIsToggleCoverAllowed = Utils.overwrittenFunction(self.getIsToggleCoverAllowed, Foldable.getIsToggleCoverAllowed); |
51 | self.getIsUnfolded = Utils.overwrittenFunction(self.getIsUnfolded, Foldable.getIsUnfolded); |
52 | self.getIsInWorkPosition = Utils.overwrittenFunction(self.getIsInWorkPosition, Foldable.getIsInWorkPosition); |
53 | self.isLowered = Utils.overwrittenFunction(self.isLowered, Foldable.isLowered); |
54 | self.getTurnedOnNotAllowedWarning = Utils.overwrittenFunction(self.getTurnedOnNotAllowedWarning, Foldable.getTurnedOnNotAllowedWarning); |
55 | self.isDetachAllowed = Utils.overwrittenFunction(self.isDetachAllowed, Foldable.isDetachAllowed); |
56 | self.applyInitialAnimation = Utils.overwrittenFunction(self.applyInitialAnimation, Foldable.applyInitialAnimation); |
57 | self.allowLoadMovingToolStates = Utils.overwrittenFunction(self.allowLoadMovingToolStates, Foldable.allowLoadMovingToolStates); |
58 | |
59 | self.posDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.foldingParts#posDirectionText"), "action_foldOBJECT"); |
60 | self.negDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.foldingParts#negDirectionText"), "action_unfoldOBJECT"); |
61 | self.middlePosDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.foldingParts#middlePosDirectionText"), "action_liftOBJECT"); |
62 | self.middleNegDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.foldingParts#middleNegDirectionText"), "action_lowerOBJECT"); |
63 | self.startAnimTime = getXMLFloat(self.xmlFile, "vehicle.foldingParts#startAnimTime"); |
64 | self.foldMoveDirection = 0; |
65 | self.moveToMiddle = false; |
66 | if self.startAnimTime == nil then |
67 | self.startAnimTime = 0; |
68 | local startMoveDirection = Utils.getNoNil(getXMLInt(self.xmlFile, "vehicle.foldingParts#startMoveDirection"), 0); |
69 | if startMoveDirection > 0.1 then |
70 | self.startAnimTime = 1; |
71 | end |
72 | end |
73 | self.turnOnFoldDirection = 1; |
74 | if self.startAnimTime > 0.5 then |
75 | self.turnOnFoldDirection = -1; |
76 | end |
77 | |
78 | self.turnOnFoldDirection = Utils.sign(Utils.getNoNil(getXMLInt(self.xmlFile, "vehicle.foldingParts#turnOnFoldDirection"), self.turnOnFoldDirection)); |
79 | |
80 | local foldInputButtonStr = getXMLString(self.xmlFile, "vehicle.foldingParts#foldInputButton"); |
81 | if foldInputButtonStr ~= nil then |
82 | self.foldInputButton = InputBinding[foldInputButtonStr]; |
83 | end |
84 | self.foldInputButton = Utils.getNoNil(self.foldInputButton, InputBinding.IMPLEMENT_EXTRA2); |
85 | |
86 | local foldMiddleInputButtonStr = getXMLString(self.xmlFile, "vehicle.foldingParts#foldMiddleInputButton"); |
87 | if foldMiddleInputButtonStr ~= nil then |
88 | self.foldMiddleInputButton = InputBinding[foldMiddleInputButtonStr]; |
89 | end |
90 | self.foldMiddleInputButton = Utils.getNoNil(self.foldMiddleInputButton, InputBinding.LOWER_IMPLEMENT); |
91 | |
92 | self.foldMiddleAnimTime = getXMLFloat(self.xmlFile, "vehicle.foldingParts#foldMiddleAnimTime"); |
93 | self.foldMiddleDirection = Utils.getNoNil(getXMLInt(self.xmlFile, "vehicle.foldingParts#foldMiddleDirection"), 1); |
94 | self.foldMiddleAIRaiseDirection = Utils.getNoNil(getXMLInt(self.xmlFile, "vehicle.foldingParts#foldMiddleAIRaiseDirection"), self.foldMiddleDirection); |
95 | |
96 | self.turnOnFoldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.foldingParts#turnOnFoldMaxLimit"), 1); |
97 | self.turnOnFoldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.foldingParts#turnOnFoldMinLimit"), 0); |
98 | self.toggleCoverMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.foldingParts#toggleCoverMaxLimit"), 1); |
99 | self.toggleCoverMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.foldingParts#toggleCoverMinLimit"), 0); |
100 | self.detachingMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.foldingParts#detachingMaxLimit"), 1); |
101 | self.detachingMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.foldingParts#detachingMinLimit"), 0); |
102 | self.loadMovingToolStatesMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.foldingParts#loadMovingToolStatesMaxLimit"), 1); |
103 | self.loadMovingToolStatesMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.foldingParts#loadMovingToolStatesMinLimit"), 0); |
104 | self.turnOffOnFold = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.foldingParts#turnOffOnFold"), false); |
105 | self.closeCoverOnFold = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.foldingParts#closeCoverOnFold"), false); |
106 | self.onlyFoldOnDetach = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.foldingParts#onlyFoldOnDetach"), false); |
107 | self.onlyFoldOnEmpty = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.foldingParts#onlyFoldOnEmpty"), false); |
108 | self.unfoldWarning = string.format(g_i18n:getText(Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.foldingParts#unfoldWarning"), "warning_firstUnfoldTheTool")), self.typeDesc); |
109 | |
110 | self.foldAnimTime = 0; |
111 | self.maxFoldAnimDuration = 0.0001; |
112 | |
113 | self.foldingParts = {}; |
114 | local i=0; |
115 | while true do |
116 | local baseName = string.format("vehicle.foldingParts.foldingPart(%d)", i); |
117 | if not hasXMLProperty(self.xmlFile, baseName) then |
118 | break; |
119 | end |
120 | |
121 | local isValid = false; |
122 | local entry = {}; |
123 | entry.speedScale = Utils.getNoNil(getXMLFloat(self.xmlFile, baseName.."#speedScale"), 1); |
124 | local componentJointIndex = getXMLInt(self.xmlFile, baseName.. "#componentJointIndex"); |
125 | local componentJoint = nil; |
126 | if componentJointIndex ~= nil then |
127 | componentJoint = self.componentJoints[componentJointIndex+1]; |
128 | entry.componentJoint = componentJoint; |
129 | end |
130 | entry.anchorActor = Utils.getNoNil(getXMLInt(self.xmlFile, baseName.."#anchorActor"), 0); |
131 | |
132 | entry.animCharSet = 0; |
133 | |
134 | local rootNode = Utils.indexToObject(self.components, getXMLString(self.xmlFile, baseName.."#rootNode")); |
135 | if rootNode ~= nil then |
136 | local animCharSet = getAnimCharacterSet(rootNode); |
137 | if animCharSet ~= 0 then |
138 | local clip = getAnimClipIndex(animCharSet, getXMLString(self.xmlFile, baseName.."#animationClip")); |
139 | if clip >= 0 then |
140 | isValid = true; |
141 | |
142 | entry.animCharSet = animCharSet; |
143 | assignAnimTrackClip(entry.animCharSet, 0, clip); |
144 | setAnimTrackLoopState(entry.animCharSet, 0, false); |
145 | entry.animDuration = getAnimClipDuration(entry.animCharSet, clip); |
146 | |
147 | end |
148 | end |
149 | end |
150 | -- try AnimatedVehicle specialization support |
151 | if not isValid and self.playAnimation ~= nil and self.animations ~= nil then |
152 | local animationName = getXMLString(self.xmlFile, baseName.."#animationName"); |
153 | if animationName ~= nil then |
154 | if self.animations[animationName] ~= nil then |
155 | isValid = true; |
156 | entry.animDuration = self:getAnimationDuration(animationName); |
157 | entry.animationName = animationName; |
158 | end |
159 | end |
160 | end |
161 | |
162 | if isValid then |
163 | self.maxFoldAnimDuration = math.max(self.maxFoldAnimDuration, entry.animDuration); |
164 | if componentJoint ~= nil then |
165 | local node = self.components[componentJoint.componentIndices[((entry.anchorActor+1)%2)+1] ].node; |
166 | entry.x,entry.y,entry.z = worldToLocal(componentJoint.jointNode, getWorldTranslation(node)); |
167 | entry.upX,entry.upY,entry.upZ = worldDirectionToLocal(componentJoint.jointNode, localDirectionToWorld(node, 0, 1, 0)); |
168 | entry.dirX,entry.dirY,entry.dirZ = worldDirectionToLocal(componentJoint.jointNode, localDirectionToWorld(node, 0, 0, 1)); |
169 | end |
170 | |
171 | table.insert(self.foldingParts, entry); |
172 | end |
173 | i = i+1; |
174 | end |
175 | |
176 | if table.getn(self.foldingParts) > 0 then |
177 | self.isSelectable = true; |
178 | end |
179 | end |
postLoad
DescriptionCalled after loadingDefinition
postLoad(table savegame)Arguments
table | savegame | savegame |
184 | function Foldable:postLoad(savegame) |
185 | local animTime = nil |
186 | if savegame ~= nil and not savegame.resetVehicles then |
187 | animTime = getXMLFloat(savegame.xmlFile, savegame.key.."#foldAnimTime"); |
188 | end |
189 | if animTime == nil then |
190 | animTime = self.startAnimTime; |
191 | end |
192 | |
193 | Foldable.setAnimTime(self, animTime, false) |
194 | end |
applyInitialAnimation
DescriptionCalled at the end of loading to apply an initial animation stateDefinition
applyInitialAnimation()Code
198 | function Foldable:applyInitialAnimation(superFunc) |
199 | self.foldAnimTime = 1-self.startAnimTime; -- make sure that foldAnimTime ~= startAnimTime |
200 | Foldable.setAnimTime(self, self.startAnimTime) |
201 | if superFunc ~= nil then |
202 | superFunc(self); |
203 | end |
204 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
213 | function Foldable:readStream(streamId, connection) |
214 | local direction = streamReadUIntN(streamId, 2)-1; |
215 | local moveToMiddle = streamReadBool(streamId); |
216 | local animTime = streamReadFloat32(streamId); |
217 | Foldable.setAnimTime(self, animTime, false); |
218 | self:setFoldState(direction, moveToMiddle, true); |
219 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
225 | function Foldable:writeStream(streamId, connection) |
226 | local direction = Utils.sign(self.foldMoveDirection)+1; |
227 | streamWriteUIntN(streamId, direction, 2); |
228 | streamWriteBool(streamId, self.moveToMiddle); |
229 | streamWriteFloat32(streamId, self.foldAnimTime); |
230 | end |
getSaveAttributesAndNodes
DescriptionReturns attributes and nodes to saveDefinition
getSaveAttributesAndNodes(table nodeIdent)Arguments
table | nodeIdent | node ident |
string | attributes | attributes |
string | nodes | nodes |
243 | function Foldable:getSaveAttributesAndNodes(nodeIdent) |
244 | local attributes = 'foldAnimTime="'..self.foldAnimTime..'"'; |
245 | return attributes, nil; |
246 | end |
setRelativePosition
DescriptionCalled on setting position of vehicle (e. g. loading or reseting vehicle)Definition
setRelativePosition(float positionX, float offsetY, float positionZ, float yRot)Arguments
float | positionX | x position |
float | offsetY | y offset |
float | positionZ | z position |
float | yRot | y rotation |
254 | function Foldable:setRelativePosition(positionX, offsetY, positionZ, yRot) |
255 | if self.startAnimTime ~= nil then |
256 | self.foldAnimTime = 1-self.startAnimTime; -- make sure that foldAnimTime ~= startAnimTime |
257 | Foldable.setAnimTime(self, self.startAnimTime); |
258 | end |
259 | end |
keyEvent
DescriptionCalled on key eventDefinition
keyEvent(integer unicode, integer sym, integer modifier, boolean isDown)Arguments
integer | unicode | unicode |
integer | sym | sym |
integer | modifier | modifier |
boolean | isDown | is button down |
270 | function Foldable:keyEvent(unicode, sym, modifier, isDown) |
271 | end |
update
DescriptionCalled on updateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
276 | function Foldable:update(dt) |
277 | |
278 | if self:getIsActive() then |
279 | |
280 | if math.abs(self.foldMoveDirection) > 0.1 then |
281 | local isInvalid = false; |
282 | local foldAnimTime = 0; |
283 | if self.foldMoveDirection < -0.1 then |
284 | foldAnimTime = 1; |
285 | end |
286 | for _,foldingPart in pairs(self.foldingParts) do |
287 | local charSet = foldingPart.animCharSet; |
288 | if self.foldMoveDirection > 0 then |
289 | local animTime = 0; |
290 | if charSet ~= 0 then |
291 | animTime = getAnimTrackTime(charSet, 0); |
292 | else |
293 | animTime = self:getRealAnimationTime(foldingPart.animationName); |
294 | end |
295 | if animTime < foldingPart.animDuration then |
296 | isInvalid = true; |
297 | end |
298 | foldAnimTime = math.max(foldAnimTime, animTime / self.maxFoldAnimDuration); |
299 | elseif self.foldMoveDirection < 0 then |
300 | local animTime = 0; |
301 | if charSet ~= 0 then |
302 | animTime = getAnimTrackTime(charSet, 0); |
303 | else |
304 | animTime = self:getRealAnimationTime(foldingPart.animationName); |
305 | end |
306 | if animTime > 0 then |
307 | isInvalid = true; |
308 | end |
309 | foldAnimTime = math.min(foldAnimTime, animTime / self.maxFoldAnimDuration); |
310 | end |
311 | end |
312 | self.foldAnimTime = Utils.clamp(foldAnimTime, 0, 1); |
313 | |
314 | if isInvalid and self.isServer then |
315 | for _,foldingPart in pairs(self.foldingParts) do |
316 | if foldingPart.componentJoint ~= nil then |
317 | self:setComponentJointFrame(foldingPart.componentJoint, foldingPart.anchorActor) |
318 | end |
319 | end |
320 | end |
321 | end |
322 | end |
323 | |
324 | if self.isClient and table.getn(self.foldingParts) > 0 and self:getIsActiveForInput(true) then |
325 | if InputBinding.hasEvent(self.foldInputButton) then |
326 | if self:getIsFoldAllowed() then |
327 | if self:getToggledFoldDirection() == self.turnOnFoldDirection then |
328 | self:setFoldState(self:getToggledFoldDirection(), true); |
329 | else |
330 | self:setFoldState(self:getToggledFoldDirection(), false); |
331 | end |
332 | end |
333 | end |
334 | if self.foldMiddleAnimTime ~= nil and self.foldMiddleInputButton ~= nil then |
335 | if InputBinding.hasEvent(self.foldMiddleInputButton) then |
336 | if self:getIsFoldMiddleAllowed() then |
337 | local direction = self:getToggledFoldMiddleDirection(); |
338 | if direction ~= 0 then |
339 | if direction == self.turnOnFoldDirection then |
340 | self:setFoldState(direction, false) |
341 | else |
342 | self:setFoldState(direction, true) |
343 | end |
344 | end |
345 | end |
346 | end |
347 | end |
348 | end |
349 | end |
updateTick
DescriptionCalled on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
354 | function Foldable:updateTick(dt) |
355 | if self:getIsActive() then |
356 | if self.turnOffOnFold then |
357 | if not self:getIsTurnedOnAllowed(true) then |
358 | if self.setIsTurnedOn ~= nil and self:getIsTurnedOn() then |
359 | self:setIsTurnedOn(false, true); |
360 | elseif self.attacherVehicle ~= nil and self.attacherVehicle.setIsTurnedOn ~= nil and self.attacherVehicle:getIsTurnedOn() then |
361 | self.attacherVehicle:setIsTurnedOn(false, true); |
362 | end |
363 | end |
364 | end |
365 | if self.closeCoverOnFold then |
366 | if not self:getIsToggleCoverAllowed(true) then |
367 | if self.setCoverState ~= nil and self.isCoverOpen then |
368 | self:setCoverState(false, true); |
369 | end; |
370 | end; |
371 | end; |
372 | if self.onlyFoldOnEmpty then |
373 | if self:getFillLevel() > 0 and self.foldAnimTime == 1 then |
374 | self:setFoldState(self:getToggledFoldDirection(), false, true); |
375 | end; |
376 | end; |
377 | end |
378 | end |
draw
DescriptionCalled on drawDefinition
draw()Code
382 | function Foldable:draw() |
383 | if self.isClient then |
384 | if table.getn(self.foldingParts) > 0 and self:getIsActiveForInput(true) then |
385 | local i18n = g_i18n; |
386 | if self.customEnvironment ~= nil then |
387 | i18n = _G[self.customEnvironment].g_i18n; |
388 | end |
389 | if self:getIsFoldAllowed() then |
390 | if self.foldMiddleAnimTime == nil or self.foldMiddleAnimTime ~= 1 then |
391 | if self:getToggledFoldDirection() > 0 then |
392 | g_currentMission:addHelpButtonText(string.format(i18n:getText(self.posDirectionText), self.typeDesc), self.foldInputButton, nil, GS_PRIO_HIGH); |
393 | else |
394 | g_currentMission:addHelpButtonText(string.format(i18n:getText(self.negDirectionText), self.typeDesc), self.foldInputButton, nil, GS_PRIO_HIGH); |
395 | end |
396 | end |
397 | end |
398 | if self:getIsFoldMiddleAllowed() then |
399 | if self.foldMiddleAnimTime ~= nil and self.foldMiddleInputButton ~= nil then |
400 | local direction = self:getToggledFoldMiddleDirection(); |
401 | if direction > 0 then |
402 | g_currentMission:addHelpButtonText(string.format(i18n:getText(self.middlePosDirectionText), self.typeDesc), self.foldMiddleInputButton, nil, GS_PRIO_HIGH); |
403 | elseif direction < 0 then |
404 | g_currentMission:addHelpButtonText(string.format(i18n:getText(self.middleNegDirectionText), self.typeDesc), self.foldMiddleInputButton, nil, GS_PRIO_HIGH); |
405 | end |
406 | end |
407 | end |
408 | end |
409 | end |
410 | end |
onDeactivate
DescriptionCalled on deactivateDefinition
onDeactivate()Code
414 | function Foldable:onDeactivate() |
415 | self:setFoldDirection(0, true); |
416 | end |
onAiTurnOn
DescriptionCalled on ai turn onDefinition
onAiTurnOn()Code
420 | function Foldable:onAiTurnOn() |
421 | if self:getIsFoldAllowed(true) then |
422 | if self.turnOnFoldDirection ~= 0 then |
423 | --if self.foldMiddleAnimTime ~= nil then |
424 | -- self:setFoldState(-self.foldMiddleAIRaiseDirection, true, false); |
425 | --else |
426 | self:setFoldState(self.turnOnFoldDirection, false, false); |
427 | --end |
428 | end |
429 | end |
430 | end |
onAiTurnOff
DescriptionCalled on ai turn offDefinition
onAiTurnOff()Code
434 | function Foldable:onAiTurnOff() |
435 | if self.foldMiddleAnimTime ~= nil and self.foldMiddleAIRaiseDirection ~= 0 then |
436 | if self.foldMiddleAIRaiseDirection > 0 then |
437 | if self.foldAnimTime > self.foldMiddleAnimTime then |
438 | self:setFoldState(self.foldMiddleAIRaiseDirection, false, true); |
439 | else |
440 | self:setFoldState(self.foldMiddleAIRaiseDirection, true, true); |
441 | end |
442 | else |
443 | if self.foldAnimTime < self.foldMiddleAnimTime then |
444 | self:setFoldState(self.foldMiddleAIRaiseDirection, false, true); |
445 | else |
446 | self:setFoldState(self.foldMiddleAIRaiseDirection, true, true); |
447 | end |
448 | end |
449 | end |
450 | end |
onAiLower
DescriptionCalled on ai lowerDefinition
onAiLower()Code
454 | function Foldable:onAiLower() |
455 | if self.foldMiddleAnimTime ~= nil and self.foldMiddleAIRaiseDirection ~= 0 then |
456 | self:setFoldState(-self.foldMiddleAIRaiseDirection, false, false); |
457 | end |
458 | end |
onAiRaise
DescriptionCalled on ai raiseDefinition
onAiRaise()Code
462 | function Foldable:onAiRaise() |
463 | if self.foldMiddleAnimTime ~= nil and self.foldMiddleAIRaiseDirection ~= 0 then |
464 | if self.foldMiddleAIRaiseDirection > 0 then |
465 | if self.foldAnimTime < self.foldMiddleAnimTime then |
466 | self:setFoldState(1, true, false); |
467 | end |
468 | else |
469 | if self.foldAnimTime > self.foldMiddleAnimTime then |
470 | self:setFoldState(-1, true, false); |
471 | end |
472 | end |
473 | end |
474 | end |
getIsAIReadyForWork
DescriptionReturns true if vehicle is ready for ai workDefinition
getIsAIReadyForWork()Return Values
boolean | isReady | is ready for ai work |
479 | function Foldable:getIsAIReadyForWork() |
480 | if table.getn(self.foldingParts) > 0 then |
481 | if self.turnOnFoldDirection == -1 then |
482 | if self.foldAnimTime > 0 then |
483 | if self.foldMoveDirection ~= -1 or (self.foldMiddleAnimTime ~= nil and self.moveToMiddle == true) then |
484 | self:setFoldState(-1, false); |
485 | end |
486 | return false; |
487 | else |
488 | return true; |
489 | end |
490 | else |
491 | if self.foldAnimTime < 1 then |
492 | if self.foldMoveDirection ~= 1 or (self.foldMiddleAnimTime ~= nil and self.moveToMiddle == true) then |
493 | self:setFoldState(1, false); |
494 | end |
495 | return false; |
496 | else |
497 | return true; |
498 | end |
499 | end |
500 | else |
501 | return true; |
502 | end |
503 | end |
startThreshing
DescriptionStart threshingDefinition
startThreshing()Code
507 | function Foldable:startThreshing() |
508 | if self.foldMiddleAnimTime ~= nil and self.foldMiddleAIRaiseDirection ~= 0 then |
509 | self:setFoldState(-self.foldMiddleAIRaiseDirection, false, true); |
510 | end |
511 | end |
stopThreshing
DescriptionStop threshingDefinition
stopThreshing()Code
515 | function Foldable:stopThreshing() |
516 | if self.foldMiddleAnimTime ~= nil and self.foldMiddleAIRaiseDirection ~= 0 then |
517 | self:setFoldState(self.foldMiddleAIRaiseDirection, true, true); |
518 | end |
519 | end |
setFoldDirection
DescriptionSet fold directionDefinition
setFoldDirection(integer direction, boolean noEventSend)Arguments
integer | direction | new direction |
boolean | noEventSend | no event send |
525 | function Foldable:setFoldDirection(direction, noEventSend) |
526 | self:setFoldState(direction, false, noEventSend); |
527 | end |
setFoldState
DescriptionSet fold stateDefinition
setFoldState(integer direction, boolean moveToMiddle, boolean noEventSend)Arguments
integer | direction | direction |
boolean | moveToMiddle | move to middle position |
boolean | noEventSend | no event send |
534 | function Foldable:setFoldState(direction, moveToMiddle, noEventSend) |
535 | if self.foldMiddleAnimTime == nil then |
536 | moveToMiddle = false; |
537 | end |
538 | if self.foldMoveDirection ~= direction or self.moveToMiddle ~= moveToMiddle then |
539 | if noEventSend == nil or noEventSend == false then |
540 | if g_server ~= nil then |
541 | g_server:broadcastEvent(FoldableSetFoldDirectionEvent:new(self, direction, moveToMiddle), nil, nil, self); |
542 | else |
543 | g_client:getServerConnection():sendEvent(FoldableSetFoldDirectionEvent:new(self, direction, moveToMiddle)); |
544 | end |
545 | end |
546 | self.foldMoveDirection = direction; |
547 | self.moveToMiddle = moveToMiddle; |
548 | |
549 | for _,foldingPart in pairs(self.foldingParts) do |
550 | local speedScale = nil; |
551 | -- We don't do any animations if we are already past the middle time |
552 | if self.foldMoveDirection > 0.1 then |
553 | if not self.moveToMiddle or self.foldAnimTime < self.foldMiddleAnimTime then |
554 | speedScale = foldingPart.speedScale; |
555 | end |
556 | elseif self.foldMoveDirection < -0.1 then |
557 | if not self.moveToMiddle or self.foldAnimTime > self.foldMiddleAnimTime then |
558 | speedScale = -foldingPart.speedScale; |
559 | end |
560 | end |
561 | |
562 | local charSet = foldingPart.animCharSet; |
563 | if charSet ~= 0 then |
564 | if speedScale ~= nil then |
565 | if speedScale > 0 then |
566 | if getAnimTrackTime(charSet, 0) < 0.0 then |
567 | setAnimTrackTime(charSet, 0, 0.0); |
568 | end |
569 | else |
570 | if getAnimTrackTime(charSet, 0) > foldingPart.animDuration then |
571 | setAnimTrackTime(charSet, 0, foldingPart.animDuration); |
572 | end |
573 | end |
574 | setAnimTrackSpeedScale(charSet, 0, speedScale); |
575 | enableAnimTrack(charSet, 0); |
576 | else |
577 | disableAnimTrack(charSet, 0); |
578 | end |
579 | else |
580 | -- always stop to make sure the animation state is reset |
581 | local animTime; |
582 | if self:getIsAnimationPlaying(foldingPart.animationName) then |
583 | animTime = self:getAnimationTime(foldingPart.animationName); |
584 | else |
585 | animTime = (self.foldAnimTime*self.maxFoldAnimDuration)/self:getAnimationDuration(foldingPart.animationName); |
586 | end |
587 | self:stopAnimation(foldingPart.animationName, true); |
588 | if speedScale ~= nil then |
589 | self:playAnimation(foldingPart.animationName, speedScale, animTime, true); |
590 | |
591 | if moveToMiddle then |
592 | local stopAnimTime = (self.foldMiddleAnimTime*self.maxFoldAnimDuration)/self:getAnimationDuration(foldingPart.animationName); |
593 | self:setAnimationStopTime(foldingPart.animationName, stopAnimTime); |
594 | end |
595 | end |
596 | end |
597 | end |
598 | -- slightly move fold anim time, so that fold limits can trigger for different actions |
599 | if self.foldMoveDirection > 0.1 then |
600 | self.foldAnimTime = math.min(self.foldAnimTime + 0.0001, math.max(self.foldAnimTime, 1)); |
601 | elseif self.foldMoveDirection < -0.1 then |
602 | self.foldAnimTime = math.max(self.foldAnimTime - 0.0001, math.min(self.foldAnimTime, 0)); |
603 | end |
604 | end |
605 | end |
loadSpeedRotatingPartFromXML
DescriptionLoads speed rotating parts from xmlDefinition
loadSpeedRotatingPartFromXML(table speedRotatingPart, integer xmlFile, string key)Arguments
table | speedRotatingPart | speedRotatingPart |
integer | xmlFile | id of xml object |
string | key | key |
boolean | success | success |
613 | function Foldable:loadSpeedRotatingPartFromXML(superFunc, speedRotatingPart, xmlFile, key) |
614 | if superFunc ~= nil then |
615 | if not superFunc(self, speedRotatingPart, xmlFile, key) then |
616 | return false; |
617 | end |
618 | end |
619 | speedRotatingPart.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false); |
620 | local minFoldLimit = 0; |
621 | local maxFoldLimit = 1; |
622 | if speedRotatingPart.foldLimitedOuterRange then |
623 | minFoldLimit = 0.5; |
624 | maxFoldLimit = 0.5; |
625 | end |
626 | speedRotatingPart.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMinLimit"), minFoldLimit); |
627 | speedRotatingPart.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMaxLimit"), maxFoldLimit); |
628 | |
629 | return true; |
630 | end |
getIsSpeedRotatingPartActive
DescriptionReturns true if speed rotating part is activeDefinition
getIsSpeedRotatingPartActive(table speedRotatingPart)Arguments
table | speedRotatingPart | speedRotatingPart |
boolean | isActive | speed rotating part is active |
636 | function Foldable:getIsSpeedRotatingPartActive(superFunc, speedRotatingPart) |
637 | if not speedRotatingPart.foldLimitedOuterRange then |
638 | if self.foldAnimTime > speedRotatingPart.foldMaxLimit or self.foldAnimTime < speedRotatingPart.foldMinLimit then |
639 | return false; |
640 | end |
641 | else |
642 | if self.foldAnimTime <= speedRotatingPart.foldMaxLimit and self.foldAnimTime > speedRotatingPart.foldMinLimit then |
643 | return false; |
644 | end |
645 | end |
646 | |
647 | if superFunc ~= nil then |
648 | return superFunc(self, speedRotatingPart); |
649 | end |
650 | return true; |
651 | end |
loadDynamicWheelDataFromXML
DescriptionLoading dynamic wheel data from xmlDefinition
loadDynamicWheelDataFromXML(integer xmlFile, string key, string wheelnamei, table wheel)Arguments
integer | xmlFile | id of xml object |
string | key | key to load |
string | wheelnamei | wheel name with index |
table | wheel | wheel table to write in |
boolean | success | success |
660 | function Foldable:loadDynamicWheelDataFromXML(superFunc, xmlFile, key, wheelnamei, wheel) |
661 | local fallbackOldKey = "vehicle.wheels"; |
662 | wheel.versatileFoldMinLimit = Vehicle.getConfigurationValue(xmlFile, key, wheelnamei, "#versatileFoldMinLimit", getXMLFloat, 0, nil, fallbackOldKey); |
663 | wheel.versatileFoldMaxLimit = Vehicle.getConfigurationValue(xmlFile, key, wheelnamei, "#versatileFoldMaxLimit", getXMLFloat, 1, nil, fallbackOldKey); |
664 | |
665 | if superFunc ~= nil then |
666 | return superFunc(self, xmlFile, key, wheelnamei, wheel); |
667 | end |
668 | return true; |
669 | end |
getIsVersatileYRotActive
DescriptionReturns of versatile y rot is activeDefinition
getIsVersatileYRotActive(table wheel)Arguments
table | wheel | wheel to check |
boolean | isActive | is active |
675 | function Foldable:getIsVersatileYRotActive(superFunc, wheel) |
676 | if self.foldAnimTime > wheel.versatileFoldMaxLimit or self.foldAnimTime < wheel.versatileFoldMinLimit then |
677 | return false; |
678 | end |
679 | |
680 | if superFunc ~= nil then |
681 | return superFunc(self, wheel); |
682 | end |
683 | return true; |
684 | end |
loadWorkAreaFromXML
DescriptionLoads work areas from xmlDefinition
loadWorkAreaFromXML(table workArea, integer xmlFile, string key)Arguments
table | workArea | workArea |
integer | xmlFile | id of xml object |
string | key | key |
boolean | success | success |
692 | function Foldable:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
693 | workArea.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false); |
694 | local minFoldLimit = 0; |
695 | local maxFoldLimit = 1; |
696 | if workArea.foldLimitedOuterRange then |
697 | minFoldLimit = 0.5; |
698 | maxFoldLimit = 0.5; |
699 | end |
700 | workArea.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMinLimit"), minFoldLimit); |
701 | workArea.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMaxLimit"), maxFoldLimit); |
702 | |
703 | |
704 | if superFunc ~= nil then |
705 | return superFunc(self, workArea, xmlFile, key); |
706 | end |
707 | return true; |
708 | end |
getIsWorkAreaActive
DescriptionReturns true if work area is activeDefinition
getIsWorkAreaActive(table workArea)Arguments
table | workArea | workArea |
boolean | isActive | work area is active |
714 | function Foldable:getIsWorkAreaActive(superFunc, workArea) |
715 | if not workArea.foldLimitedOuterRange then |
716 | if self.foldAnimTime > workArea.foldMaxLimit or self.foldAnimTime < workArea.foldMinLimit then |
717 | return false; |
718 | end |
719 | else |
720 | if self.foldAnimTime <= workArea.foldMaxLimit and self.foldAnimTime > workArea.foldMinLimit then |
721 | return false; |
722 | end |
723 | end |
724 | if superFunc ~= nil then |
725 | return superFunc(self, workArea); |
726 | end |
727 | return true; |
728 | end |
loadLevelerNodeFromXML
DescriptionLoads leveler node from xmlDefinition
loadLevelerNodeFromXML(table entry, integer xmlFile, string key)Arguments
table | entry | leveler node data |
integer | xmlFile | id of xml object |
string | key | key |
boolean | success | success |
737 | function Foldable:loadLevelerNodeFromXML(superFunc, levelerNode, xmlFile, key) |
738 | levelerNode.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false); |
739 | local minFoldLimit = 0; |
740 | local maxFoldLimit = 1; |
741 | if levelerNode.foldLimitedOuterRange then |
742 | minFoldLimit = 0.5; |
743 | maxFoldLimit = 0.5; |
744 | end |
745 | levelerNode.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMinLimit"), minFoldLimit); |
746 | levelerNode.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMaxLimit"), maxFoldLimit); |
747 | |
748 | |
749 | if superFunc ~= nil then |
750 | return superFunc(self, levelerNode, xmlFile, key); |
751 | end |
752 | return true; |
753 | end |
getIsLevelerPickupNodeActive
DescriptionReturns true if leveler pickup node is activeDefinition
getIsLevelerPickupNodeActive(table levelerNode)Arguments
table | levelerNode | pickup node data |
boolean | isActive | pickup node is active |
759 | function Foldable:getIsLevelerPickupNodeActive(superFunc, levelerNode) |
760 | if not levelerNode.foldLimitedOuterRange then |
761 | if self.foldAnimTime > levelerNode.foldMaxLimit or self.foldAnimTime < levelerNode.foldMinLimit then |
762 | return false; |
763 | end |
764 | else |
765 | if self.foldAnimTime <= levelerNode.foldMaxLimit and self.foldAnimTime > levelerNode.foldMinLimit then |
766 | return false; |
767 | end |
768 | end |
769 | if superFunc ~= nil then |
770 | return superFunc(self, levelerNode); |
771 | end |
772 | return true; |
773 | end |
getIsTurnedOnAllowed
DescriptionReturns if turn on is allowedDefinition
getIsTurnedOnAllowed(boolean isTurnedOn)Arguments
boolean | isTurnedOn | is turned on |
boolean | allow | allow turn on |
779 | function Foldable:getIsTurnedOnAllowed(superFunc, isTurnOn) |
780 | if isTurnOn then |
781 | if self.foldAnimTime > self.turnOnFoldMaxLimit or self.foldAnimTime < self.turnOnFoldMinLimit then |
782 | return false; |
783 | end |
784 | end |
785 | |
786 | if superFunc ~= nil then |
787 | return superFunc(self, isTurnOn); |
788 | end |
789 | return true; |
790 | end |
getIsToggleCoverAllowed
DescriptionReturns if toggle cover is allowedDefinition
getIsToggleCoverAllowed(boolean isCoverOpen)Arguments
boolean | isCoverOpen | is cover open |
boolean | allow | allows cover toggle |
796 | function Foldable:getIsToggleCoverAllowed(superFunc, isCoverOpen) |
797 | if isCoverOpen then |
798 | if self.foldAnimTime > self.toggleCoverMaxLimit or self.foldAnimTime < self.toggleCoverMinLimit then |
799 | return false; |
800 | end |
801 | end |
802 | |
803 | if superFunc ~= nil then |
804 | return superFunc(self, isCoverOpen); |
805 | end |
806 | return true; |
807 | end |
getIsUnfolded
DescriptionReturns if vehicle is unfoldedDefinition
getIsUnfolded()Return Values
boolean | isUnfolded | is unfolded |
812 | function Foldable:getIsUnfolded() |
813 | if table.getn(self.foldingParts) > 0 then |
814 | if self.foldMiddleAnimTime ~= nil then |
815 | if (self.turnOnFoldDirection == -1 and self.foldAnimTime < self.foldMiddleAnimTime + 0.01) or |
816 | (self.turnOnFoldDirection == 1 and self.foldAnimTime > self.foldMiddleAnimTime - 0.01) |
817 | then |
818 | return true; |
819 | else |
820 | return false; |
821 | end |
822 | else |
823 | if (self.turnOnFoldDirection == -1 and self.foldAnimTime == 0) or (self.turnOnFoldDirection == 1 and self.foldAnimTime == 1) then |
824 | return true; |
825 | else |
826 | return false; |
827 | end |
828 | end |
829 | else |
830 | return true; |
831 | end |
832 | end |
getIsInWorkPosition
DescriptionReturns true if it is in work positionDefinition
getIsInWorkPosition()Return Values
boolean | inWorkPosition | is in work position |
837 | function Foldable:getIsInWorkPosition(superFunc) |
838 | if self.turnOnFoldDirection ~= 0 and not (table.getn(self.foldingParts) == 0 or (self.turnOnFoldDirection == -1 and self.foldAnimTime == 0) or (self.turnOnFoldDirection == 1 and self.foldAnimTime == 1)) then |
839 | return false; |
840 | end |
841 | |
842 | if superFunc ~= nil then |
843 | return superFunc(self); |
844 | end |
845 | return true; |
846 | end |
getTurnedOnNotAllowedWarning
DescriptionReturns turn on not allowed warning textDefinition
getTurnedOnNotAllowedWarning()Return Values
string | warningText | turn on not allowed warning text |
851 | function Foldable:getTurnedOnNotAllowedWarning(superFunc) |
852 | if self.foldAnimTime > self.turnOnFoldMaxLimit or self.foldAnimTime < self.turnOnFoldMinLimit then |
853 | return self.unfoldWarning; |
854 | end |
855 | |
856 | if superFunc ~= nil then |
857 | return superFunc(self); |
858 | end |
859 | return nil; |
860 | end |
isDetachAllowed
DescriptionReturns true if detach is allowedDefinition
isDetachAllowed()Return Values
boolean | detachAllowed | detach is allowed |
865 | function Foldable:isDetachAllowed(superFunc) |
866 | if self.foldAnimTime > self.detachingMaxLimit or self.foldAnimTime < self.detachingMinLimit then |
867 | return false; |
868 | end |
869 | |
870 | |
871 | if superFunc ~= nil then |
872 | return superFunc(self); |
873 | end |
874 | return true; |
875 | end |
isLowered
DescriptionReturns if vehicle is loweredDefinition
isLowered(boolean default)Arguments
boolean | default | default value |
boolean | isLowered | vehicle is lowered |
881 | function Foldable:isLowered(superFunc, default) |
882 | |
883 | if self:getIsFoldMiddleAllowed() then |
884 | if self.foldMiddleAnimTime ~= nil and self.foldMiddleInputButton ~= nil then |
885 | |
886 | if self.foldMoveDirection ~= 0 then |
887 | if self.foldMiddleDirection > 0 then |
888 | if self.foldAnimTime < self.foldMiddleAnimTime + 0.01 then |
889 | return self.foldMoveDirection < 0 and self.moveToMiddle ~= true; |
890 | end |
891 | else |
892 | if self.foldAnimTime > self.foldMiddleAnimTime - 0.01 then |
893 | return self.foldMoveDirection > 0 and self.moveToMiddle ~= true; |
894 | end |
895 | end |
896 | else |
897 | if self.foldMiddleDirection > 0 and self.foldAnimTime < 0.01 then |
898 | return true; |
899 | elseif self.foldMiddleDirection < 0 and math.abs(1.0 - self.foldAnimTime) < 0.01 then |
900 | return true; |
901 | end |
902 | end |
903 | |
904 | return false; |
905 | |
906 | end |
907 | end |
908 | |
909 | if superFunc ~= nil then |
910 | return superFunc(self, default); |
911 | end |
912 | return default; |
913 | end |
getIsFoldAllowed
DescriptionReturns if fold is allowedDefinition
getIsFoldAllowed(boolean onAiTurnOn)Arguments
boolean | onAiTurnOn | called on ai turn on |
boolean | allowsFold | allows folding |
919 | function Foldable:getIsFoldAllowed(superFunc, onAiTurnOn) |
920 | if self.onlyFoldOnDetach and self.attacherVehicle ~= nil then |
921 | return false; |
922 | end; |
923 | if self.onlyFoldOnEmpty and self:getFillLevel() > 0 then |
924 | return false; |
925 | end; |
926 | |
927 | if superFunc ~= nil then |
928 | return superFunc(self); |
929 | end |
930 | return true; |
931 | end |
getIsFoldMiddleAllowed
DescriptionReturns if fold middle is allowedDefinition
getIsFoldMiddleAllowed()Return Values
boolean | allowsFoldMiddle | allows folding to middle position |
936 | function Foldable:getIsFoldMiddleAllowed(superFunc) |
937 | if superFunc ~= nil then |
938 | return superFunc(self); |
939 | end |
940 | return true; |
941 | end |
getToggledFoldDirection
DescriptionReturns toggled fold directionDefinition
getToggledFoldDirection()Return Values
integer | direction | direction |
946 | function Foldable:getToggledFoldDirection() |
947 | local foldMidTime = 0.5; |
948 | if self.foldMiddleAnimTime ~= nil then |
949 | if self.foldMiddleDirection > 0 then |
950 | foldMidTime = (1+self.foldMiddleAnimTime) * 0.5; |
951 | else |
952 | foldMidTime = self.foldMiddleAnimTime * 0.5; |
953 | end |
954 | end |
955 | if self.moveToMiddle then |
956 | return self.foldMiddleDirection; |
957 | elseif self.foldMoveDirection > 0.1 or (self.foldMoveDirection == 0 and self.foldAnimTime > foldMidTime) then |
958 | return -1; |
959 | else |
960 | return 1; |
961 | end |
962 | end |
getToggledFoldMiddleDirection
DescriptionReturns toggled fold middle directionDefinition
getToggledFoldMiddleDirection()Return Values
integer | direction | direction |
967 | function Foldable:getToggledFoldMiddleDirection() |
968 | local ret = 0; |
969 | if self.foldMiddleAnimTime ~= nil then |
970 | if self.foldMoveDirection > 0.1 then |
971 | ret = -1; |
972 | else |
973 | ret = 1; |
974 | end |
975 | if self.foldMiddleDirection > 0 then |
976 | if self.foldAnimTime >= self.foldMiddleAnimTime - 0.01 then |
977 | ret = -1; |
978 | end |
979 | else |
980 | if self.foldAnimTime <= self.foldMiddleAnimTime + 0.01 then |
981 | ret = 1; |
982 | end |
983 | end |
984 | end |
985 | return ret; |
986 | end |
onLowerAll
DescriptionCalled on lowerDefinition
onLowerAll(boolean doLowering, integer jointIndex)Arguments
boolean | doLowering | do lowering |
integer | jointIndex | index of attacher joint |
992 | function Foldable:onLowerAll(doLowering, jointIndex) |
993 | if self.foldMiddleAnimTime ~= nil then |
994 | if self:getIsFoldMiddleAllowed() then |
995 | if doLowering then |
996 | self:setFoldState(-self.foldMiddleAIRaiseDirection, false, true); |
997 | else |
998 | self:setFoldState(self.foldMiddleAIRaiseDirection, true, true); |
999 | end |
1000 | end |
1001 | end |
1002 | end |
setAnimTime
DescriptionSets animation timeDefinition
setAnimTime(float animTime, boolean placeComponents)Arguments
float | animTime | new animation time |
boolean | placeComponents | place components |
1008 | function Foldable.setAnimTime(self, animTime, placeComponents) |
1009 | local currentTime = self.foldAnimTime; |
1010 | self.foldAnimTime = animTime; |
1011 | for _,foldingPart in pairs(self.foldingParts) do |
1012 | if foldingPart.animCharSet ~= 0 then |
1013 | enableAnimTrack(foldingPart.animCharSet, 0); |
1014 | setAnimTrackTime(foldingPart.animCharSet, 0, self.foldAnimTime*foldingPart.animDuration, true); |
1015 | disableAnimTrack(foldingPart.animCharSet, 0); |
1016 | else |
1017 | local speed = 1; |
1018 | if self.foldAnimTime < currentTime then |
1019 | speed = -1; |
1020 | end |
1021 | local stopAnimTime = (self.foldAnimTime*self.maxFoldAnimDuration)/self:getAnimationDuration(foldingPart.animationName); |
1022 | self:playAnimation(foldingPart.animationName, speed, nil, true); |
1023 | self:setAnimationStopTime(foldingPart.animationName, stopAnimTime); |
1024 | AnimatedVehicle.updateAnimationByName(self, foldingPart.animationName, 99999999); |
1025 | end |
1026 | end |
1027 | |
1028 | if placeComponents == nil then |
1029 | placeComponents = true; |
1030 | end |
1031 | |
1032 | if self.updateCylinderedInitial ~= nil then |
1033 | self:updateCylinderedInitial(placeComponents); |
1034 | end |
1035 | |
1036 | if placeComponents then |
1037 | if self.isServer then |
1038 | for _,foldingPart in pairs(self.foldingParts) do |
1039 | if foldingPart.componentJoint ~= nil then |
1040 | local componentJoint = foldingPart.componentJoint; |
1041 | |
1042 | local jointNode = componentJoint.jointNode; |
1043 | if foldingPart.anchorActor == 1 then |
1044 | jointNode = componentJoint.jointNodeActor1; |
1045 | end |
1046 | |
1047 | local node = self.components[componentJoint.componentIndices[((foldingPart.anchorActor+1)%2)+1] ].node; |
1048 | local x,y,z = localToWorld(jointNode, foldingPart.x, foldingPart.y, foldingPart.z); |
1049 | local upX,upY,upZ = localDirectionToWorld(jointNode, foldingPart.upX,foldingPart.upY,foldingPart.upZ); |
1050 | local dirX,dirY,dirZ = localDirectionToWorld(jointNode, foldingPart.dirX,foldingPart.dirY,foldingPart.dirZ); |
1051 | Utils.setWorldTranslation(node, x,y,z); |
1052 | Utils.setWorldDirection(node, dirX,dirY,dirZ, upX,upY,upZ); |
1053 | |
1054 | self:setComponentJointFrame(componentJoint, foldingPart.anchorActor) |
1055 | end |
1056 | end |
1057 | end |
1058 | end |
1059 | end |
allowLoadMovingToolStates
DescriptionReturns if loading of moving tool stats from savegame is allowedDefinition
allowLoadMovingToolStates()Return Values
boolean | isAllowed | is allowed |
1064 | function Foldable:allowLoadMovingToolStates(superFunc) |
1065 | if self.foldAnimTime > self.loadMovingToolStatesMaxLimit or self.foldAnimTime < self.loadMovingToolStatesMinLimit then |
1066 | return false; |
1067 | end |
1068 | |
1069 | if superFunc ~= nil then |
1070 | return superFunc(self); |
1071 | end |
1072 | return true; |
1073 | end |