LUADOC - Farming Simulator 17

Printable Version

Script v1.4.4.0

Engine v7.0.0.2

Foundation Reference

HookLiftTrailer

Description
Class for hooklift trailers
Functions

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;

preLoad

Description
Called before loading
Definition
preLoad(table savegame)
Arguments
tablesavegamesavegame
Code
24function HookLiftTrailer:preLoad(savegame)
25 self.isDetachAllowed = Utils.overwrittenFunction(self.isDetachAllowed, HookLiftTrailer.isDetachAllowed);
26end

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
31function 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;
76end;

updateTick

Description
Called on update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
93function 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;
110end;

onAttachImplement

Description
Called on attaching a implement
Definition
onAttachImplement(table implement)
Arguments
tableimplementimplement to attach
Code
118function 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;
129end;

onDetachImplement

Description
Called on detaching a implement
Definition
onDetachImplement(integer implementIndex)
Arguments
integerimplementIndexindex of implement to detach
Code
134function 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;
144end;

startTipping

Description
Called on start tipping
Definition
startTipping()
Code
148function HookLiftTrailer:startTipping()
149 self:playAnimation(self.hookLiftTrailer.unloadingAnimation, self.hookLiftTrailer.unloadingAnimationSpeed, self:getAnimationTime(self.hookLiftTrailer.unloadingAnimation), true);
150end;

stopTipping

Description
Called on stop tipping
Definition
stopTipping()
Code
154function HookLiftTrailer:stopTipping()
155 self:playAnimation(self.hookLiftTrailer.unloadingAnimation, self.hookLiftTrailer.unloadingAnimationReverseSpeed, self:getAnimationTime(self.hookLiftTrailer.unloadingAnimation), true);
156end;

isTippingAllowed

Description
Returns if tipping is allowed
Definition
isTippingAllowed()
Return Values
booleantippingAllowedtipping is allowed
Code
161function HookLiftTrailer:isTippingAllowed()
162 return self:getAnimationTime(self.hookLiftTrailer.refAnimation) == 0;
163end;

getIsFoldAllowed

Description
Returns if fold is allowed
Definition
getIsFoldAllowed()
Return Values
booleanallowsFoldallows folding
Code
168function 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;
177end

isDetachAllowed

Description
Returns true if detach is allowed
Definition
isDetachAllowed()
Return Values
booleandetachAlloweddetach is allowed
Code
182function 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;
192end

aiTurnOn

Description
Called on ai turn on
Definition
aiTurnOn()
Code
196function HookLiftTrailer:aiTurnOn()
197 if self.attachedContainer ~= nil and self.attachedContainer.object.aiTurnOn ~= nil then
198 self.attachedContainer.object:aiTurnOn();
199 end;
200end;

aiTurnOff

Description
Called on ai turn off
Definition
aiTurnOff()
Code
204function HookLiftTrailer:aiTurnOff()
205 if self.attachedContainer ~= nil and self.attachedContainer.object.aiTurnOff ~= nil then
206 self.attachedContainer.object:aiTurnOff();
207 end;
208end;

aiLower

Description
Called on ai lower
Definition
aiLower()
Code
212function HookLiftTrailer:aiLower()
213 if self.attachedContainer ~= nil and self.attachedContainer.object.aiLower ~= nil then
214 self.attachedContainer.object:aiLower();
215 end;
216end;

aiRaise

Description
Called on ai raise
Definition
aiRaise()
Code
220function HookLiftTrailer:aiRaise()
221 if self.attachedContainer ~= nil and self.attachedContainer.object.aiRaise ~= nil then
222 self.attachedContainer.object:aiRaise();
223 end;
224end;

aiRotateLeft

Description
Called on ai rotate left
Definition
aiRotateLeft(boolean force)
Arguments
booleanforceforce action
Code
229function HookLiftTrailer:aiRotateLeft(force)
230 if self.attachedContainer ~= nil and self.attachedContainer.object.aiRotateLeft ~= nil then
231 self.attachedContainer.object:aiRotateLeft(force);
232 end;
233end

aiRotateRight

Description
Called on ai rotate right
Definition
aiRotateRight(boolean force)
Arguments
booleanforceforce action
Code
238function HookLiftTrailer:aiRotateRight(force)
239 if self.attachedContainer ~= nil and self.attachedContainer.object.aiRotateRight ~= nil then
240 self.attachedContainer.object:aiRotateRight(force);
241 end;
242end

aiInvertsMarkerOnTurn

Description
Ai inverts marker on turn
Definition
aiInvertsMarkerOnTurn(boolean turnLeft)
Arguments
booleanturnLeftturn left
Code
247function HookLiftTrailer:aiInvertsMarkerOnTurn(turnLeft)
248 if self.attachedContainer ~= nil and self.attachedContainer.object.aiInvertsMarkerOnTurn ~= nil then
249 self.attachedContainer.object:aiInvertsMarkerOnTurn(turnLeft);
250 end;
251end;

getDoConsumePtoPower

Description
Returns if should consume pto power
Definition
getDoConsumePtoPower()
Return Values
booleanconsumeconsumePtoPower
Code
260function 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);
268end;

getPtoRpm

Description
Returns rpm of pto
Definition
getPtoRpm()
Return Values
floatrpmrpm of pto
Code
273function 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;
285end