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
Roller
DescriptionClass for all rollersFunctions
- initSpecialization
- prerequisitesPresent
- preLoad
- load
- delete
- readUpdateStream
- writeUpdateStream
- updateTick
- draw
- onAttach
- onDeactivate
- onDeactivateSounds
- doCheckSpeedLimit
- getDoGroundManipulation
- getDirtMultiplier
- loadWorkAreaFromXML
- getDefaultSpeedLimit
- processRollerAreas
initSpecialization
DescriptionCalled on specialization initializingDefinition
initSpecialization()Code
15 | function Roller.initSpecialization() |
16 | WorkArea.registerAreaType("roller"); |
17 | end; |
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
23 | function Roller.prerequisitesPresent(specializations) |
24 | return SpecializationUtil.hasSpecialization(WorkArea, specializations); |
25 | end; |
preLoad
DescriptionCalled before loadingDefinition
preLoad(table savegame)Arguments
table | savegame | savegame |
30 | function Roller:preLoad(savegame) |
31 | self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, Roller.loadWorkAreaFromXML); |
32 | end |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
37 | function 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(); |
62 | end; |
delete
DescriptionCalled on deletingDefinition
delete()Code
66 | function Roller:delete() |
67 | if self.isClient then |
68 | SoundUtil.deleteSample(self.sampleRoller); |
69 | end; |
70 | end; |
readUpdateStream
DescriptionCalled on on updateDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
77 | function Roller:readUpdateStream(streamId, timestamp, connection) |
78 | if connection:getIsServer() then |
79 | self.rollerHasGroundContact = streamReadBool(streamId); |
80 | self.showFieldNotOwnedWarning = streamReadBool(streamId); |
81 | end; |
82 | end; |
writeUpdateStream
DescriptionCalled on on updateDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
89 | function Roller:writeUpdateStream(streamId, connection, dirtyMask) |
90 | if not connection:getIsServer() then |
91 | streamWriteBool(streamId, self.rollerHasGroundContact); |
92 | streamWriteBool(streamId, self.showFieldNotOwnedWarning); |
93 | end; |
94 | end; |
updateTick
DescriptionCalled on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
108 | function 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 | |
161 | end; |
draw
DescriptionCalled on drawDefinition
draw()Code
165 | function Roller:draw() |
166 | if self.showFieldNotOwnedWarning then |
167 | g_currentMission:showBlinkingWarning(g_i18n:getText("warning_youDontOwnThisField")); |
168 | end; |
169 | end; |
onAttach
DescriptionCalled if vehicle gets attachedDefinition
onAttach(table attacherVehicle)Arguments
table | attacherVehicle | attacher vehicle |
174 | function Roller:onAttach(attacherVehicle) |
175 | self.startActivationTime = g_currentMission.time + self.startActivationTimeout; |
176 | end; |
onDeactivate
DescriptionCalled on deactivateDefinition
onDeactivate()Code
180 | function Roller:onDeactivate() |
181 | self.showFieldNotOwnedWarning = false; |
182 | end; |
onDeactivateSounds
DescriptionCalled on deactivating soundsDefinition
onDeactivateSounds()Code
186 | function Roller:onDeactivateSounds() |
187 | if self.isClient then |
188 | SoundUtil.stopSample(self.sampleRoller, true); |
189 | end; |
190 | end; |
doCheckSpeedLimit
DescriptionReturns if speed limit should be checkedDefinition
doCheckSpeedLimit()Return Values
boolean | checkSpeedlimit | check speed limit |
195 | function 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; |
202 | end; |
getDoGroundManipulation
DescriptionReturns if tool does ground manipulationDefinition
getDoGroundManipulation()Return Values
boolean | doGroundManipulation | do ground manipulation |
207 | function 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; |
216 | end; |
getDirtMultiplier
DescriptionReturns current dirt multiplierDefinition
getDirtMultiplier()Return Values
float | dirtMultiplier | current dirt multiplier |
221 | function 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; |
232 | 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 |
240 | function 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; |
251 | end; |
getDefaultSpeedLimit
DescriptionReturns default speed limitDefinition
getDefaultSpeedLimit()Return Values
float | speedLimit | speed limit |
256 | function Roller.getDefaultSpeedLimit() |
257 | return 15; |
258 | end; |
processRollerAreas
DescriptionProcess roller areaDefinition
processRollerAreas(table workAreas)Arguments
table | workAreas | work areas |
float | areaSum | sum of processed area |
264 | function 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; |
277 | end; |