LUADOC - Farming Simulator 17

Printable Version

Roller

Description
Class for all rollers
Functions

initSpecialization

Description
Called on specialization initializing
Definition
initSpecialization()
Code
15function Roller.initSpecialization()
16 WorkArea.registerAreaType("roller");
17end;

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
23function Roller.prerequisitesPresent(specializations)
24 return SpecializationUtil.hasSpecialization(WorkArea, specializations);
25end;

preLoad

Description
Called before loading
Definition
preLoad(table savegame)
Arguments
tablesavegamesavegame
Code
30function Roller:preLoad(savegame)
31 self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, Roller.loadWorkAreaFromXML);
32end

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
37function Roller:load(savegame)
38
39 self.getDoGroundManipulation = Utils.overwrittenFunction(self.getDoGroundManipulation, Roller.getDoGroundManipulation);
40 self.doCheckSpeedLimit = Utils.overwrittenFunction(self.doCheckSpeedLimit, Roller.doCheckSpeedLimit);
41 self.getDirtMultiplier = Utils.overwrittenFunction(self.getDirtMultiplier, Roller.getDirtMultiplier);
42 self.processRollerAreas = Roller.processRollerAreas;
43
44 if next(self.groundReferenceNodes) == nil then
45 print("Warning: No ground reference nodes in "..self.configFileName);
46 end;
47
48 if self.isClient then
49 self.sampleRoller = SoundUtil.loadSample(self.xmlFile, {}, "vehicle.rollerSound", nil, self.baseDirectory);
50 end;
51
52 self.onlyActiveWhenLowered = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.onlyActiveWhenLowered#value"), true);
53
54 self.startActivationTimeout = 2000;
55 self.startActivationTime = 0;
56 self.rollerHasGroundContact = false;
57 self.doGroundManipulation = false;
58 self.isRollerSpeedLimitActive = false;
59 self.showFieldNotOwnedWarning = false;
60
61 self.rollerGroundContactFlag = self:getNextDirtyFlag();
62end;

delete

Description
Called on deleting
Definition
delete()
Code
66function Roller:delete()
67 if self.isClient then
68 SoundUtil.deleteSample(self.sampleRoller);
69 end;
70end;

readUpdateStream

Description
Called on on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
77function Roller:readUpdateStream(streamId, timestamp, connection)
78 if connection:getIsServer() then
79 self.rollerHasGroundContact = streamReadBool(streamId);
80 self.showFieldNotOwnedWarning = streamReadBool(streamId);
81 end;
82end;

writeUpdateStream

Description
Called on on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
89function Roller:writeUpdateStream(streamId, connection, dirtyMask)
90 if not connection:getIsServer() then
91 streamWriteBool(streamId, self.rollerHasGroundContact);
92 streamWriteBool(streamId, self.showFieldNotOwnedWarning);
93 end;
94end;

updateTick

Description
Called on update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
108function Roller:updateTick(dt)
109 self.isRollerSpeedLimitActive = false;
110 if self:getIsActive() then
111 local showFieldNotOwnedWarning = false;
112
113 if self.isServer then
114 local hasGroundContact = self:getIsTypedWorkAreaActive(WorkArea.AREATYPE_ROLLER);
115 if self.rollerHasGroundContact ~= hasGroundContact then
116 self:raiseDirtyFlags(self.rollerGroundContactFlag);
117 self.rollerHasGroundContact = hasGroundContact;
118 end;
119 end;
120 local hasGroundContact = self.rollerHasGroundContact;
121
122 self.doGroundManipulation = (hasGroundContact and (not self.onlyActiveWhenLowered or self:isLowered(false)) and self.startActivationTime <= g_currentMission.time);
123
124 if self.doGroundManipulation then
125 self.isRollerSpeedLimitActive = true;
126 local workAreas, showWarning, _ = self:getTypedNetworkAreas(WorkArea.AREATYPE_ROLLER, true);
127
128 if self.isServer then
129 showFieldNotOwnedWarning = showWarning;
130
131 if table.getn(workAreas) > 0 then
132 self:processRollerAreas(workAreas);
133 end;
134 g_currentMission.missionStats:updateStats("workedTime", dt/(1000*60));
135 end;
136
137 -- remove tireTracks
138 for _, workArea in pairs(workAreas) do
139 Utils.eraseTireTrack(workArea[1], workArea[2], workArea[3], workArea[4], workArea[5], workArea[6])
140 end
141 end
142
143 if self.isClient then
144 if self.doGroundManipulation and self:getLastSpeed() > 3 then
145 if self:getIsActiveForSound() then
146 SoundUtil.playSample(self.sampleRoller, 0, 0, nil);
147 end;
148 else
149 SoundUtil.stopSample(self.sampleRoller);
150 end;
151 end;
152
153 if self.isServer then
154 if showFieldNotOwnedWarning ~= self.showFieldNotOwnedWarning then
155 self.showFieldNotOwnedWarning = showFieldNotOwnedWarning;
156 self:raiseDirtyFlags(self.rollerGroundContactFlag);
157 end
158 end
159 end;
160
161end;

draw

Description
Called on draw
Definition
draw()
Code
165function Roller:draw()
166 if self.showFieldNotOwnedWarning then
167 g_currentMission:showBlinkingWarning(g_i18n:getText("warning_youDontOwnThisField"));
168 end;
169end;

onAttach

Description
Called if vehicle gets attached
Definition
onAttach(table attacherVehicle)
Arguments
tableattacherVehicleattacher vehicle
Code
174function Roller:onAttach(attacherVehicle)
175 self.startActivationTime = g_currentMission.time + self.startActivationTimeout;
176end;

onDeactivate

Description
Called on deactivate
Definition
onDeactivate()
Code
180function Roller:onDeactivate()
181 self.showFieldNotOwnedWarning = false;
182end;

onDeactivateSounds

Description
Called on deactivating sounds
Definition
onDeactivateSounds()
Code
186function Roller:onDeactivateSounds()
187 if self.isClient then
188 SoundUtil.stopSample(self.sampleRoller, true);
189 end;
190end;

doCheckSpeedLimit

Description
Returns if speed limit should be checked
Definition
doCheckSpeedLimit()
Return Values
booleancheckSpeedlimitcheck speed limit
Code
195function Roller:doCheckSpeedLimit(superFunc)
196 local parent = false;
197 if superFunc ~= nil then
198 parent = superFunc(self);
199 end
200
201 return parent or self.isRollerSpeedLimitActive;
202end;

getDoGroundManipulation

Description
Returns if tool does ground manipulation
Definition
getDoGroundManipulation()
Return Values
booleandoGroundManipulationdo ground manipulation
Code
207function Roller:getDoGroundManipulation(superFunc)
208 if not self.doGroundManipulation then
209 return false;
210 end;
211
212 if superFunc ~= nil then
213 return superFunc(self);
214 end
215 return true;
216end;

getDirtMultiplier

Description
Returns current dirt multiplier
Definition
getDirtMultiplier()
Return Values
floatdirtMultipliercurrent dirt multiplier
Code
221function Roller:getDirtMultiplier(superFunc)
222 local multiplier = 0;
223 if superFunc ~= nil then
224 multiplier = multiplier + superFunc(self);
225 end;
226
227 if self.doGroundManipulation then
228 multiplier = multiplier + self.workMultiplier * self:getLastSpeed() / self.speedLimit;
229 end;
230
231 return multiplier;
232end;

loadWorkAreaFromXML

Description
Loads work areas from xml
Definition
loadWorkAreaFromXML(table workArea, integer xmlFile, string key)
Arguments
tableworkAreaworkArea
integerxmlFileid of xml object
stringkeykey
Return Values
booleansuccesssuccess
Code
240function Roller:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key)
241 local retValue = true;
242 if superFunc ~= nil then
243 retValue = superFunc(self, workArea, xmlFile, key)
244 end
245
246 if workArea.type == WorkArea.AREATYPE_DEFAULT then
247 workArea.type = WorkArea.AREATYPE_ROLLER;
248 end;
249
250 return retValue;
251end;

getDefaultSpeedLimit

Description
Returns default speed limit
Definition
getDefaultSpeedLimit()
Return Values
floatspeedLimitspeed limit
Code
256function Roller.getDefaultSpeedLimit()
257 return 15;
258end;

processRollerAreas

Description
Process roller area
Definition
processRollerAreas(table workAreas)
Arguments
tableworkAreaswork areas
Return Values
floatareaSumsum of processed area
Code
264function Roller:processRollerAreas(workAreas)
265 local numAreas = table.getn(workAreas);
266 local areaSum = 0;
267 for i=1, numAreas do
268 local x = workAreas[i][1];
269 local z = workAreas[i][2];
270 local x1 = workAreas[i][3];
271 local z1 = workAreas[i][4];
272 local x2 = workAreas[i][5];
273 local z2 = workAreas[i][6];
274 areaSum = areaSum + Utils.updateRollerArea(x, z, x1, z1, x2, z2)
275 end;
276 return areaSum;
277end;