LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

HookLiftTrailer

Description
Specialization for hooklift trailers providing separate load-up and tipping animations
Functions

getCanDetachContainer

Description
Definition
getCanDetachContainer()
Code
188function HookLiftTrailer:getCanDetachContainer()
189 local spec = self.spec_hookLiftTrailer
190 return self:getAnimationTime(spec.refAnimation) == 1
191end

getDoConsumePtoPower

Description
Returns if should consume pto power
Definition
getDoConsumePtoPower()
Return Values
booleanconsumeconsumePtoPower
Code
219function HookLiftTrailer:getDoConsumePtoPower(superFunc)
220 local spec = self.spec_hookLiftTrailer
221 local doConsume = superFunc(self)
222
223 return doConsume or self:getIsAnimationPlaying(spec.refAnimation) or self:getIsAnimationPlaying(spec.unloadingAnimation)
224end

getIsFoldAllowed

Description
Returns if fold is allowed
Definition
getIsFoldAllowed()
Return Values
booleanallowsFoldallows folding
Code
196function HookLiftTrailer:getIsFoldAllowed(superFunc, direction, onAiTurnOn)
197 local spec = self.spec_hookLiftTrailer
198 if self:getAnimationTime(spec.unloadingAnimation) > 0 then
199 return false
200 end
201
202 return superFunc(self, direction, onAiTurnOn)
203end

getIsTippingAllowed

Description
Returns if tipping is allowed
Definition
getIsTippingAllowed()
Return Values
booleantippingAllowedtipping is allowed
Code
181function HookLiftTrailer:getIsTippingAllowed()
182 local spec = self.spec_hookLiftTrailer
183 return self:getAnimationTime(spec.refAnimation) == 0
184end

getPtoRpm

Description
Returns rpm of pto
Definition
getPtoRpm()
Return Values
floatrpmrpm of pto
Code
229function HookLiftTrailer:getPtoRpm(superFunc)
230 local spec = self.spec_hookLiftTrailer
231 local rpm = superFunc(self)
232
233 if self:getIsAnimationPlaying(spec.refAnimation) or self:getIsAnimationPlaying(spec.unloadingAnimation) then
234 return self.spec_powerConsumer.ptoRpm
235 else
236 return rpm
237 end
238end

isDetachAllowed

Description
Returns true if detach is allowed
Definition
isDetachAllowed()
Return Values
booleandetachAlloweddetach is allowed
Code
208function HookLiftTrailer:isDetachAllowed(superFunc)
209 if self:getAnimationTime(self.spec_hookLiftTrailer.unloadingAnimation) == 0 then
210 return superFunc(self)
211 else
212 return false, nil
213 end
214end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
52function HookLiftTrailer:onLoad(savegame)
53 local spec = self.spec_hookLiftTrailer
54
55 spec.jointLimits = AnimCurve:new(linearInterpolatorN)
56 local i = 0
57 while true do
58 local key = string.format("vehicle.hookLiftTrailer.jointLimits.key(%d)", i)
59 if not hasXMLProperty(self.xmlFile, key) then
60 if i == 0 then
61 spec.jointLimits = nil
62 end
63 break
64 end
65 local t = getXMLFloat(self.xmlFile, key.."#time")
66 local rx,ry,rz = StringUtil.getVectorFromString(getXMLString(self.xmlFile, key.."#rotLimit"))
67 local tx,ty,tz = StringUtil.getVectorFromString(getXMLString(self.xmlFile, key.."#transLimit"))
68 rx = math.rad(Utils.getNoNil(rx, 0))
69 ry = math.rad(Utils.getNoNil(ry, 0))
70 rz = math.rad(Utils.getNoNil(rz, 0))
71 tx = Utils.getNoNil(tx, 0)
72 ty = Utils.getNoNil(ty, 0)
73 tz = Utils.getNoNil(tz, 0)
74 spec.jointLimits:addKeyframe({rx, ry, rz, tx, ty, tz, time = t})
75 i = i +1
76 end
77
78 spec.refAnimation = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.jointLimits#refAnimation"), "unfoldHand")
79 spec.unloadingAnimation = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#name"), "unloading")
80 spec.unloadingAnimationSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#speed"), 1)
81 spec.unloadingAnimationReverseSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#reverseSpeed"), -1)
82
83 spec.texts = {}
84 spec.texts.unloadContainer = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#unloadContainer"), "unload_container")
85 spec.texts.loadContainer = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#loadContainer"), "load_container")
86 spec.texts.unloadArm = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#unloadArm"), "unload_arm")
87 spec.texts.loadArm = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#loadArm"), "load_arm")
88end

onPostAttachImplement

Description
Called on attaching a implement
Definition
onPostAttachImplement(table implement)
Arguments
tableimplementimplement to attach
Code
129function HookLiftTrailer:onPostAttachImplement(attachable, inputJointDescIndex, jointDescIndex)
130 local spec = self.spec_hookLiftTrailer
131
132 local attacherJoint = attachable:getActiveInputAttacherJoint()
133 if attacherJoint ~= nil then
134 if attacherJoint.jointType == AttacherJoints.JOINTTYPE_HOOKLIFT then
135 local jointDesc = self:getAttacherJointByJointDescIndex(jointDescIndex)
136 spec.attachedContainer = {}
137 spec.attachedContainer.jointIndex = jointDesc.jointIndex
138 spec.attachedContainer.implement = self:getImplementByObject(attachable)
139 spec.attachedContainer.object = attachable
140 spec.attachedContainer.limitLocked = false
141
142 local foldableSpec = self.spec_foldable
143 foldableSpec.posDirectionText = spec.texts.unloadContainer
144 foldableSpec.negDirectionText = spec.texts.loadContainer
145 end
146 end
147end

onPostLoad

Description
Called after loading
Definition
onPostLoad(table savegame)
Arguments
tablesavegamesavegame
Code
93function HookLiftTrailer:onPostLoad(savegame)
94 local spec = self.spec_hookLiftTrailer
95 local foldableSpec = self.spec_foldable
96 foldableSpec.posDirectionText = spec.texts.unloadArm
97 foldableSpec.negDirectionText = spec.texts.loadArm
98end

onPreDetachImplement

Description
Called on detaching a implement
Definition
onPreDetachImplement(integer implementIndex)
Arguments
integerimplementIndexindex of implement to detach
Code
152function HookLiftTrailer:onPreDetachImplement(implement)
153 local spec = self.spec_hookLiftTrailer
154 if spec.attachedContainer ~= nil then
155 if implement == spec.attachedContainer.implement then
156 local foldableSpec = self.spec_foldable
157 foldableSpec.posDirectionText = spec.texts.unloadArm
158 foldableSpec.negDirectionText = spec.texts.loadArm
159 spec.attachedContainer = nil
160 end
161 end
162end

onUpdateTick

Description
Called on update tick
Definition
onUpdateTick(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
105function HookLiftTrailer:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
106 local spec = self.spec_hookLiftTrailer
107
108 if spec.attachedContainer ~= nil then
109 local animTime = self:getAnimationTime(spec.refAnimation)
110 spec.attachedContainer.object.allowsDetaching = animTime > 0.95
111
112 if (self:getIsAnimationPlaying(spec.refAnimation) or not spec.attachedContainer.limitLocked) and spec.jointLimits ~= nil and not spec.attachedContainer.implement.attachingIsInProgress then
113 local v = spec.jointLimits:get(animTime)
114 for i=1,3 do
115 setJointRotationLimit(spec.attachedContainer.jointIndex, i-1, true, -v[i], v[i])
116 setJointTranslationLimit(spec.attachedContainer.jointIndex, i+2, true, -v[i+3], v[i+3])
117 end
118
119 if animTime >= 0.99 then
120 spec.attachedContainer.limitLocked = true
121 end
122 end
123 end
124end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
17function HookLiftTrailer.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations) and SpecializationUtil.hasSpecialization(Foldable, specializations)
19end

registerEventListeners

Description
Definition
registerEventListeners()
Code
41function HookLiftTrailer.registerEventListeners(vehicleType)
42 SpecializationUtil.registerEventListener(vehicleType, "onLoad", HookLiftTrailer)
43 SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", HookLiftTrailer)
44 SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", HookLiftTrailer)
45 SpecializationUtil.registerEventListener(vehicleType, "onPostAttachImplement", HookLiftTrailer)
46 SpecializationUtil.registerEventListener(vehicleType, "onPreDetachImplement", HookLiftTrailer)
47end

registerFunctions

Description
Definition
registerFunctions()
Code
23function HookLiftTrailer.registerFunctions(vehicleType)
24 SpecializationUtil.registerFunction(vehicleType, "startTipping", HookLiftTrailer.startTipping)
25 SpecializationUtil.registerFunction(vehicleType, "stopTipping", HookLiftTrailer.stopTipping)
26 SpecializationUtil.registerFunction(vehicleType, "getIsTippingAllowed", HookLiftTrailer.getIsTippingAllowed)
27 SpecializationUtil.registerFunction(vehicleType, "getCanDetachContainer", HookLiftTrailer.getCanDetachContainer)
28end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
32function HookLiftTrailer.registerOverwrittenFunctions(vehicleType)
33 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsFoldAllowed", HookLiftTrailer.getIsFoldAllowed)
34 SpecializationUtil.registerOverwrittenFunction(vehicleType, "isDetachAllowed", HookLiftTrailer.isDetachAllowed)
35 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDoConsumePtoPower", HookLiftTrailer.getDoConsumePtoPower)
36 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getPtoRpm", HookLiftTrailer.getPtoRpm)
37end

startTipping

Description
Called on start tipping
Definition
startTipping()
Code
166function HookLiftTrailer:startTipping()
167 local spec = self.spec_hookLiftTrailer
168 self:playAnimation(spec.unloadingAnimation, spec.unloadingAnimationSpeed, self:getAnimationTime(spec.unloadingAnimation), true)
169end

stopTipping

Description
Called on stop tipping
Definition
stopTipping()
Code
173function HookLiftTrailer:stopTipping()
174 local spec = self.spec_hookLiftTrailer
175 self:playAnimation(spec.unloadingAnimation, spec.unloadingAnimationReverseSpeed, self:getAnimationTime(spec.unloadingAnimation), true)
176end