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
HookLiftTrailer
DescriptionClass for hooklift trailersFunctions
- prerequisitesPresent
- preLoad
- load
- updateTick
- onAttachImplement
- onDetachImplement
- startTipping
- stopTipping
- isTippingAllowed
- getIsFoldAllowed
- isDetachAllowed
- aiTurnOn
- aiTurnOff
- aiLower
- aiRaise
- aiRotateLeft
- aiRotateRight
- aiInvertsMarkerOnTurn
- getDoConsumePtoPower
- getPtoRpm
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 HookLiftTrailer.prerequisitesPresent(specializations) |
18 | return SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations) and SpecializationUtil.hasSpecialization(Foldable, specializations); |
19 | end; |
preLoad
DescriptionCalled before loadingDefinition
preLoad(table savegame)Arguments
table | savegame | savegame |
24 | function HookLiftTrailer:preLoad(savegame) |
25 | self.isDetachAllowed = Utils.overwrittenFunction(self.isDetachAllowed, HookLiftTrailer.isDetachAllowed); |
26 | end |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
31 | function HookLiftTrailer:load(savegame) |
32 | self.startTipping = HookLiftTrailer.startTipping; |
33 | self.stopTipping = HookLiftTrailer.stopTipping; |
34 | self.isTippingAllowed = HookLiftTrailer.isTippingAllowed; |
35 | self.getIsFoldAllowed = Utils.overwrittenFunction(self.getIsFoldAllowed, HookLiftTrailer.getIsFoldAllowed); |
36 | self.getDoConsumePtoPower = Utils.overwrittenFunction(self.getDoConsumePtoPower, HookLiftTrailer.getDoConsumePtoPower); |
37 | self.getPtoRpm = Utils.overwrittenFunction(self.getPtoRpm, HookLiftTrailer.getPtoRpm); |
38 | |
39 | self.hookLiftTrailer = {}; |
40 | |
41 | self.hookLiftTrailer.jointLimits = AnimCurve:new(linearInterpolatorN); |
42 | local i = 0; |
43 | while true do |
44 | local key = string.format("vehicle.hookLiftTrailer.jointLimits.key(%d)", i); |
45 | if not hasXMLProperty(self.xmlFile, key) then |
46 | if i == 0 then |
47 | self.hookLiftTrailer.jointLimits = nil; |
48 | end; |
49 | break; |
50 | end; |
51 | local t = getXMLFloat(self.xmlFile, key.."#time"); |
52 | local rx,ry,rz = Utils.getVectorFromString(getXMLString(self.xmlFile, key.."#rotLimit")); |
53 | local tx,ty,tz = Utils.getVectorFromString(getXMLString(self.xmlFile, key.."#transLimit")); |
54 | rx = math.rad(Utils.getNoNil(rx, 0)); |
55 | ry = math.rad(Utils.getNoNil(ry, 0)); |
56 | rz = math.rad(Utils.getNoNil(rz, 0)); |
57 | tx = Utils.getNoNil(tx, 0); |
58 | ty = Utils.getNoNil(ty, 0); |
59 | tz = Utils.getNoNil(tz, 0); |
60 | self.hookLiftTrailer.jointLimits:addKeyframe({ v={rx, ry, rz, tx, ty, tz}, time = t}); |
61 | i = i +1; |
62 | end; |
63 | |
64 | self.hookLiftTrailer.refAnimation = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.jointLimits#refAnimation"), "unfoldHand"); |
65 | self.hookLiftTrailer.unloadingAnimation = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#name"), "unloading"); |
66 | self.hookLiftTrailer.unloadingAnimationSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#speed"), 1); |
67 | self.hookLiftTrailer.unloadingAnimationReverseSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#reverseSpeed"), -1); |
68 | |
69 | self.hookLiftTrailer.texts = {}; |
70 | self.hookLiftTrailer.texts.unloadContainer = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#unloadContainer"), "unload_container"); |
71 | self.hookLiftTrailer.texts.loadContainer = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#loadContainer"), "load_container"); |
72 | self.hookLiftTrailer.texts.unloadArm = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#unloadArm"), "unload_arm"); |
73 | self.hookLiftTrailer.texts.loadArm = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#loadArm"), "load_arm"); |
74 | |
75 | self.hookLiftTrailer.isDirty = true; |
76 | end; |
updateTick
DescriptionCalled on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
93 | function HookLiftTrailer:updateTick(dt) |
94 | if self:getIsActive() then |
95 | if self.attachedContainer ~= nil then |
96 | local animTime = self:getAnimationTime(self.hookLiftTrailer.refAnimation); |
97 | self.attachedContainer.object.allowsDetaching = animTime > 0.95; |
98 | |
99 | if (self:getIsAnimationPlaying(self.hookLiftTrailer.refAnimation) or self.hookLiftTrailer.isDirty) and self.hookLiftTrailer.jointLimits ~= nil and not self.attachedContainer.implement.attachingIsInProgress then |
100 | local v = self.hookLiftTrailer.jointLimits:get(animTime); |
101 | for i=1,3 do |
102 | setJointRotationLimit(self.attachedContainer.jointIndex, i-1, true, -v[i], v[i]); |
103 | setJointTranslationLimit(self.attachedContainer.jointIndex, i+2, true, -v[i+3], v[i+3]); |
104 | end; |
105 | |
106 | self.hookLiftTrailer.isDirty = false; |
107 | end; |
108 | end; |
109 | end; |
110 | end; |
onAttachImplement
DescriptionCalled on attaching a implementDefinition
onAttachImplement(table implement)Arguments
table | implement | implement to attach |
118 | function HookLiftTrailer:onAttachImplement(implement) |
119 | local object = implement.object; |
120 | if object.attacherJoint.jointType == AttacherJoints.JOINTTYPE_HOOKLIFT then |
121 | local jointDesc = self.attacherJoints[implement.jointDescIndex]; |
122 | self.attachedContainer = {}; |
123 | self.attachedContainer.jointIndex = jointDesc.jointIndex; |
124 | self.attachedContainer.implement = implement; |
125 | self.attachedContainer.object = object; |
126 | self.posDirectionText = self.hookLiftTrailer.texts.unloadContainer; |
127 | self.negDirectionText = self.hookLiftTrailer.texts.loadContainer; |
128 | end; |
129 | end; |
onDetachImplement
DescriptionCalled on detaching a implementDefinition
onDetachImplement(integer implementIndex)Arguments
integer | implementIndex | index of implement to detach |
134 | function HookLiftTrailer:onDetachImplement(implementIndex) |
135 | if self.attachedContainer ~= nil then |
136 | local implement = self.attachedImplements[implementIndex]; |
137 | local jointDesc = self.attacherJoints[implement.jointDescIndex]; |
138 | if jointDesc.jointIndex == self.attachedContainer.jointIndex then |
139 | self.posDirectionText = self.hookLiftTrailer.texts.unloadArm; |
140 | self.negDirectionText = self.hookLiftTrailer.texts.loadArm; |
141 | self.attachedContainer = nil; |
142 | end; |
143 | end; |
144 | end; |
startTipping
DescriptionCalled on start tippingDefinition
startTipping()Code
148 | function HookLiftTrailer:startTipping() |
149 | self:playAnimation(self.hookLiftTrailer.unloadingAnimation, self.hookLiftTrailer.unloadingAnimationSpeed, self:getAnimationTime(self.hookLiftTrailer.unloadingAnimation), true); |
150 | end; |
stopTipping
DescriptionCalled on stop tippingDefinition
stopTipping()Code
154 | function HookLiftTrailer:stopTipping() |
155 | self:playAnimation(self.hookLiftTrailer.unloadingAnimation, self.hookLiftTrailer.unloadingAnimationReverseSpeed, self:getAnimationTime(self.hookLiftTrailer.unloadingAnimation), true); |
156 | end; |
isTippingAllowed
DescriptionReturns if tipping is allowedDefinition
isTippingAllowed()Return Values
boolean | tippingAllowed | tipping is allowed |
161 | function HookLiftTrailer:isTippingAllowed() |
162 | return self:getAnimationTime(self.hookLiftTrailer.refAnimation) == 0; |
163 | end; |
getIsFoldAllowed
DescriptionReturns if fold is allowedDefinition
getIsFoldAllowed()Return Values
boolean | allowsFold | allows folding |
168 | function HookLiftTrailer:getIsFoldAllowed(superFunc) |
169 | if self:getAnimationTime(self.hookLiftTrailer.unloadingAnimation) > 0 then |
170 | return false; |
171 | end; |
172 | |
173 | if superFunc ~= nil then |
174 | return superFunc(self); |
175 | end |
176 | return true; |
177 | end |
isDetachAllowed
DescriptionReturns true if detach is allowedDefinition
isDetachAllowed()Return Values
boolean | detachAllowed | detach is allowed |
182 | function HookLiftTrailer:isDetachAllowed(superFunc) |
183 | if self:getAnimationTime(self.hookLiftTrailer.unloadingAnimation) == 0 then |
184 | if superFunc ~= nil then |
185 | return superFunc(self); |
186 | end; |
187 | |
188 | return true; |
189 | else |
190 | return false; |
191 | end; |
192 | end |
aiTurnOn
DescriptionCalled on ai turn onDefinition
aiTurnOn()Code
196 | function HookLiftTrailer:aiTurnOn() |
197 | if self.attachedContainer ~= nil and self.attachedContainer.object.aiTurnOn ~= nil then |
198 | self.attachedContainer.object:aiTurnOn(); |
199 | end; |
200 | end; |
aiTurnOff
DescriptionCalled on ai turn offDefinition
aiTurnOff()Code
204 | function HookLiftTrailer:aiTurnOff() |
205 | if self.attachedContainer ~= nil and self.attachedContainer.object.aiTurnOff ~= nil then |
206 | self.attachedContainer.object:aiTurnOff(); |
207 | end; |
208 | end; |
aiLower
DescriptionCalled on ai lowerDefinition
aiLower()Code
212 | function HookLiftTrailer:aiLower() |
213 | if self.attachedContainer ~= nil and self.attachedContainer.object.aiLower ~= nil then |
214 | self.attachedContainer.object:aiLower(); |
215 | end; |
216 | end; |
aiRaise
DescriptionCalled on ai raiseDefinition
aiRaise()Code
220 | function HookLiftTrailer:aiRaise() |
221 | if self.attachedContainer ~= nil and self.attachedContainer.object.aiRaise ~= nil then |
222 | self.attachedContainer.object:aiRaise(); |
223 | end; |
224 | end; |
aiRotateLeft
DescriptionCalled on ai rotate leftDefinition
aiRotateLeft(boolean force)Arguments
boolean | force | force action |
229 | function HookLiftTrailer:aiRotateLeft(force) |
230 | if self.attachedContainer ~= nil and self.attachedContainer.object.aiRotateLeft ~= nil then |
231 | self.attachedContainer.object:aiRotateLeft(force); |
232 | end; |
233 | end |
aiRotateRight
DescriptionCalled on ai rotate rightDefinition
aiRotateRight(boolean force)Arguments
boolean | force | force action |
238 | function HookLiftTrailer:aiRotateRight(force) |
239 | if self.attachedContainer ~= nil and self.attachedContainer.object.aiRotateRight ~= nil then |
240 | self.attachedContainer.object:aiRotateRight(force); |
241 | end; |
242 | end |
aiInvertsMarkerOnTurn
DescriptionAi inverts marker on turnDefinition
aiInvertsMarkerOnTurn(boolean turnLeft)Arguments
boolean | turnLeft | turn left |
247 | function HookLiftTrailer:aiInvertsMarkerOnTurn(turnLeft) |
248 | if self.attachedContainer ~= nil and self.attachedContainer.object.aiInvertsMarkerOnTurn ~= nil then |
249 | self.attachedContainer.object:aiInvertsMarkerOnTurn(turnLeft); |
250 | end; |
251 | end; |
getDoConsumePtoPower
DescriptionReturns if should consume pto powerDefinition
getDoConsumePtoPower()Return Values
boolean | consume | consumePtoPower |
260 | function HookLiftTrailer:getDoConsumePtoPower(superFunc) |
261 | local doConsume = false; |
262 | |
263 | if superFunc ~= nil then |
264 | doConsume = superFunc(self); |
265 | end; |
266 | |
267 | return doConsume or self:getIsAnimationPlaying(self.hookLiftTrailer.refAnimation) or self:getIsAnimationPlaying(self.hookLiftTrailer.unloadingAnimation); |
268 | end; |
getPtoRpm
DescriptionReturns rpm of ptoDefinition
getPtoRpm()Return Values
float | rpm | rpm of pto |
273 | function HookLiftTrailer:getPtoRpm(superFunc) |
274 | local rpm = 0; |
275 | |
276 | if superFunc ~= nil then |
277 | rpm = superFunc(self); |
278 | end; |
279 | |
280 | if self:getIsAnimationPlaying(self.hookLiftTrailer.refAnimation) or self:getIsAnimationPlaying(self.hookLiftTrailer.unloadingAnimation) then |
281 | return self.powerConsumer.ptoRpm; |
282 | else |
283 | return rpm; |
284 | end; |
285 | end |