LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

Roller

Description
Specialization for roller used for removing fields/terrainDetailLayer
Functions

doCheckSpeedLimit

Description
Definition
doCheckSpeedLimit()
Code
235function Roller:doCheckSpeedLimit(superFunc)
236 local spec = self.spec_roller
237
238 return superFunc(self) or spec.isWorking
239end

getDefaultSpeedLimit

Description
Definition
getDefaultSpeedLimit()
Code
343function Roller.getDefaultSpeedLimit()
344 return 15
345end

getDirtMultiplier

Description
Definition
getDirtMultiplier()
Code
250function Roller:getDirtMultiplier(superFunc)
251 local spec = self.spec_roller
252 local multiplier = superFunc(self)
253
254 if spec.isWorking then
255 multiplier = multiplier + self:getWorkDirtMultiplier()
256 end
257
258 return multiplier
259end

getDoGroundManipulation

Description
Definition
getDoGroundManipulation()
Code
243function Roller:getDoGroundManipulation(superFunc)
244 local spec = self.spec_roller
245 return superFunc(self) and spec.isWorking
246end

getIsWorkAreaActive

Description
Definition
getIsWorkAreaActive()
Code
277function Roller:getIsWorkAreaActive(superFunc, workArea)
278 if workArea.type == WorkAreaType.ROLLER then
279 local spec = self.spec_roller
280 if spec.startActivationTime > g_currentMission.time then
281 return false
282 end
283
284 if spec.onlyActiveWhenLowered and not self:getIsLowered() then
285 return false
286 end
287 end
288
289 return superFunc(self, workArea)
290end

getWearMultiplier

Description
Returns current wear multiplier
Definition
getWearMultiplier()
Return Values
floatdirtMultipliercurrent wear multiplier
Code
264function Roller:getWearMultiplier(superFunc)
265 local spec = self.spec_roller
266 local multiplier = superFunc(self)
267
268 if spec.isWorking then
269 multiplier = multiplier + self:getWorkWearMultiplier()
270 end
271
272 return multiplier
273end

initSpecialization

Description
Definition
initSpecialization()
Code
28function Roller.initSpecialization()
29 g_configurationManager:addConfigurationType("roller", g_i18n:getText("configuration_design"), "roller", nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
30 g_workAreaTypeManager:addWorkAreaType("roller", false)
31
32 local schema = Vehicle.xmlSchema
33 schema:setXMLSpecializationType("Roller")
34
35 Roller.registerRollerXMLPaths(schema, "vehicle.roller")
36 Roller.registerRollerXMLPaths(schema, "vehicle.roller.rollerConfigurations.rollerConfiguration(?).roller")
37
38 ObjectChangeUtil.registerObjectChangeXMLPaths(schema, "vehicle.roller.rollerConfigurations.rollerConfiguration(?)")
39
40 schema:setXMLSpecializationType()
41end

onDeactivate

Description
Definition
onDeactivate()
Code
335function Roller:onDeactivate()
336 local spec = self.spec_roller
337 g_soundManager:stopSample(spec.samples.work)
338 spec.isWorkSamplePlaying = false
339end

onDelete

Description
Definition
onDelete()
Code
142function Roller:onDelete()
143 local spec = self.spec_roller
144 g_soundManager:deleteSamples(spec.samples)
145end

onEndWorkAreaProcessing

Description
Definition
onEndWorkAreaProcessing()
Code
305function Roller:onEndWorkAreaProcessing(dt, hasProcessed)
306 local spec = self.spec_roller
307
308 if self.isClient then
309 if spec.isWorking then
310 if not spec.isWorkSamplePlaying then
311 g_soundManager:playSample(spec.samples.work)
312 spec.isWorkSamplePlaying = true
313 end
314 else
315 if spec.isWorkSamplePlaying then
316 g_soundManager:stopSample(spec.samples.work)
317 spec.isWorkSamplePlaying = false
318 end
319 end
320 end
321end

onLoad

Description
Definition
onLoad()
Code
90function Roller:onLoad(savegame)
91 local spec = self.spec_roller
92
93 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.rollerSound", "vehicle.roller.sounds.work") --FS17 to FS19
94 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.onlyActiveWhenLowered#value", "vehicle.roller#onlyActiveWhenLowered") --FS17 to FS19
95
96 local rollerConfigurationId = Utils.getNoNil(self.configurations["roller"], 1)
97 local configKey = string.format("vehicle.roller.rollerConfigurations.rollerConfiguration(%d).roller", rollerConfigurationId - 1)
98 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.roller.rollerConfigurations.rollerConfiguration", rollerConfigurationId, self.components, self)
99
100 if not self.xmlFile:hasProperty(configKey) then
101 configKey = "vehicle.roller"
102 end
103
104 spec.directionNode = self.xmlFile:getValue(configKey .. ".directionNode#node", self.components[1].node, self.components, self.i3dMappings)
105
106 if self.isClient then
107 spec.samples = {}
108 spec.isWorkSamplePlaying = false
109 spec.samples.work = g_soundManager:loadSampleFromXML(self.xmlFile, configKey .. ".sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
110 end
111
112 spec.isSoilRoller = self.xmlFile:getValue(configKey .. "#isSoilRoller")
113 spec.isGrassRoller = self.xmlFile:getValue(configKey .. "#isGrassRoller")
114 if spec.isSoilRoller == nil and spec.isGrassRoller == nil then
115 spec.isSoilRoller = true
116 spec.isGrassRoller = false
117 else
118 if spec.isGrassRoller == nil then
119 spec.isGrassRoller = false
120 end
121 if spec.isSoilRoller == nil then
122 spec.isSoilRoller = false
123 end
124 end
125
126 spec.grassFruitTypes = {FruitType.GRASS, FruitType.MEADOW}
127
128 spec.usingAIRequirements = self.xmlFile:getValue(configKey .. "#usingAIRequirements", true)
129 spec.onlyActiveWhenLowered = self.xmlFile:getValue(configKey .. "#onlyActiveWhenLowered", true)
130 spec.startActivationTimeout = 2000
131 spec.startActivationTime = 0
132 spec.isWorking = false
133 spec.angle = 0
134
135 self:updateRollerAIRequirements()
136
137 spec.dirtyFlag = self:getNextDirtyFlag()
138end

onPostAttach

Description
Called after vehicle gets attached
Definition
onPostAttach(table attacherVehicle, integer inputJointDescIndex, integer jointDescIndex)
Arguments
tableattacherVehicleattacher vehicle
integerinputJointDescIndexindex of input attacher joint
integerjointDescIndexindex of attacher joint it gets attached to
Code
328function Roller:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex)
329 local spec = self.spec_roller
330 spec.startActivationTime = g_currentMission.time + spec.startActivationTimeout
331end

onStartWorkAreaProcessing

Description
Definition
onStartWorkAreaProcessing()
Code
294function Roller:onStartWorkAreaProcessing(dt)
295 local spec = self.spec_roller
296
297 local dx,_,dz = localDirectionToWorld(spec.directionNode, 0, 0, 1)
298
299 spec.angle = FSDensityMapUtil.convertToDensityMapAngle(MathUtil.getYRotationFromDirection(dx, dz), g_currentMission.fieldGroundSystem:getGroundAngleMaxValue())
300 spec.isWorking = false
301end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
56function Roller.prerequisitesPresent(specializations)
57 return SpecializationUtil.hasSpecialization(WorkArea, specializations)
58end

processRollerArea

Description
Definition
processRollerArea()
Code
149function Roller:processRollerArea(workArea, dt)
150 local spec = self.spec_roller
151
152 local xs,_,zs = getWorldTranslation(workArea.start)
153 local xw,_,zw = getWorldTranslation(workArea.width)
154 local xh,_,zh = getWorldTranslation(workArea.height)
155
156 local realArea
157 if spec.isGrassRoller then
158 realArea, _ = FSDensityMapUtil.updateGrassRollerArea(xs, zs, xw, zw, xh, zh, not spec.isSoilRoller)
159 end
160 if spec.isSoilRoller then
161 realArea, _ = FSDensityMapUtil.updateRollerArea(xs, zs, xw, zw, xh, zh, spec.angle)
162 end
163
164 FSDensityMapUtil.eraseTireTrack(xs, zs, xw, zw, xh, zh)
165
166 spec.isWorking = self:getLastSpeed() > 0.5
167
168 return realArea
169end

registerEventListeners

Description
Definition
registerEventListeners()
Code
79function Roller.registerEventListeners(vehicleType)
80 SpecializationUtil.registerEventListener(vehicleType, "onLoad", Roller)
81 SpecializationUtil.registerEventListener(vehicleType, "onDelete", Roller)
82 SpecializationUtil.registerEventListener(vehicleType, "onPostAttach", Roller)
83 SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", Roller)
84 SpecializationUtil.registerEventListener(vehicleType, "onStartWorkAreaProcessing", Roller)
85 SpecializationUtil.registerEventListener(vehicleType, "onEndWorkAreaProcessing", Roller)
86end

registerFunctions

Description
Definition
registerFunctions()
Code
62function Roller.registerFunctions(vehicleType)
63 SpecializationUtil.registerFunction(vehicleType, "processRollerArea", Roller.processRollerArea)
64 SpecializationUtil.registerFunction(vehicleType, "updateRollerAIRequirements", Roller.updateRollerAIRequirements)
65end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
69function Roller.registerOverwrittenFunctions(vehicleType)
70 SpecializationUtil.registerOverwrittenFunction(vehicleType, "doCheckSpeedLimit", Roller.doCheckSpeedLimit)
71 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDoGroundManipulation", Roller.getDoGroundManipulation)
72 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDirtMultiplier", Roller.getDirtMultiplier)
73 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getWearMultiplier", Roller.getWearMultiplier)
74 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsWorkAreaActive", Roller.getIsWorkAreaActive)
75end

registerRollerXMLPaths

Description
Definition
registerRollerXMLPaths()
Code
45function Roller.registerRollerXMLPaths(schema, basePath)
46 schema:register(XMLValueType.NODE_INDEX, basePath .. ".directionNode#node", "Roller direction node")
47 schema:register(XMLValueType.BOOL, basePath .. "#onlyActiveWhenLowered", "Only active when lowered", true)
48 schema:register(XMLValueType.BOOL, basePath .. "#isSoilRoller", "If roller is for soil", true)
49 schema:register(XMLValueType.BOOL, basePath .. "#isGrassRoller", "If roller is for grassland", false)
50 schema:register(XMLValueType.BOOL, basePath .. "#usingAIRequirements", "Tool using roller ai requirements", true)
51 SoundManager.registerSampleXMLPaths(schema, basePath .. ".sounds", "work")
52end

updateRollerAIRequirements

Description
Definition
updateRollerAIRequirements()
Code
173function Roller:updateRollerAIRequirements()
174 if self.clearAITerrainDetailRequiredRange ~= nil then
175 local spec = self.spec_roller
176
177 if not spec.usingAIRequirements then
178 return
179 end
180
181 local hasSowingMachine = false
182 if SpecializationUtil.hasSpecialization(SowingMachine, self.specializations) then
183 if self:getUseSowingMachineAIRequirements() then
184 hasSowingMachine = true
185 end
186 end
187
188 self:clearAIFruitRequirements()
189 self:clearAIFruitProhibitions()
190 self:clearAITerrainDetailRequiredRange()
191
192 -- if we also have a active sowing machine attached the sowingMachine is fully handling it
193 if not hasSowingMachine then
194 if spec.isGrassRoller and not spec.isSoilRoller then
195 self:addAIGroundTypeRequirements(Roller.AI_REQUIRED_GROUND_TYPES_GRASS)
196
197 for i=1, #spec.grassFruitTypes do
198 local fruitTypeDesc = g_fruitTypeManager:getFruitTypeByIndex(spec.grassFruitTypes[i])
199 if fruitTypeDesc.terrainDataPlaneId ~= nil then
200 self:addAIFruitRequirement(fruitTypeDesc.index, 2, fruitTypeDesc.cutState + 1)
201 end
202 end
203 end
204
205 if spec.isSoilRoller then
206 self:addAIGroundTypeRequirements(Roller.AI_REQUIRED_GROUND_TYPES)
207
208 for fruitTypeIndex, fruitType in pairs(g_fruitTypeManager:getFruitTypes()) do
209 if fruitType.terrainDataPlaneId ~= nil then
210 if not spec.isGrassRoller or fruitTypeIndex ~= FruitType.GRASS then
211 -- rolling only allowed in first growth state
212 self:addAIFruitProhibitions(fruitType.index, 2, 15)
213 end
214 end
215 end
216
217 -- for combined tools we allow working on all grass states
218 if spec.isGrassRoller then
219 self:addAIGroundTypeRequirements(Roller.AI_REQUIRED_GROUND_TYPES_GRASS)
220
221 for i=1, #spec.grassFruitTypes do
222 local fruitTypeDesc = g_fruitTypeManager:getFruitTypeByIndex(spec.grassFruitTypes[i])
223 if fruitTypeDesc.terrainDataPlaneId ~= nil then
224 self:addAIFruitProhibitions(fruitTypeDesc.index, 1, 1)
225 end
226 end
227 end
228 end
229 end
230 end
231end