LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

FertilizingCultivator

Description
Specialization for cultivators which also have a fertilizing function
Functions

onLoad

Description
Definition
onLoad()
Code
36function FertilizingCultivator:onLoad(savegame)
37 local spec = self.spec_fertilizingCultivator
38 spec.needsSetIsTurnedOn = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.fertilizingCultivator#needsSetIsTurnedOn"), false)
39 self.spec_sprayer.useSpeedLimit = false
40end

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 FertilizingCultivator.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(Cultivator, specializations) and SpecializationUtil.hasSpecialization(Sprayer, specializations)
19end

processCultivatorArea

Description
Definition
processCultivatorArea()
Code
44function FertilizingCultivator:processCultivatorArea(superFunc, workArea, dt)
45 local spec = self.spec_fertilizingCultivator
46 local specCultivator = self.spec_cultivator
47 local specSpray = self.spec_sprayer
48
49 local xs,_,zs = getWorldTranslation(workArea.start)
50 local xw,_,zw = getWorldTranslation(workArea.width)
51 local xh,_,zh = getWorldTranslation(workArea.height)
52
53 local cultivatorParams = specCultivator.workAreaParameters
54 local sprayerParams = specSpray.workAreaParameters
55
56 -- we need to use fertilizer as spraying type because fertilizer is the final blocking value
57 local sprayTypeIndex = SprayType.FERTILIZER
58
59 if sprayerParams.sprayFillLevel <= 0 or (spec.needsSetIsTurnedOn and not self:getIsTurnedOn()) then
60 sprayTypeIndex = nil
61 end
62
63 local cultivatorChangedArea, cultivatorTotalArea = FSDensityMapUtil.updateCultivatorArea(xs, zs, xw, zw, xh, zh, not cultivatorParams.limitToField, not cultivatorParams.limitGrassDestructionToField, cultivatorParams.angle, sprayTypeIndex)
64 cultivatorParams.lastChangedArea = cultivatorParams.lastChangedArea + cultivatorChangedArea
65 cultivatorParams.lastTotalArea = cultivatorParams.lastTotalArea + cultivatorTotalArea
66 cultivatorParams.lastStatsArea = cultivatorParams.lastStatsArea + cultivatorChangedArea
67
68 if specCultivator.isSubsoiler then
69 FSDensityMapUtil.updateSubsoilerArea(xs, zs, xw, zw, xh, zh)
70 end
71
72 FSDensityMapUtil.eraseTireTrack(xs, zs, xw, zw, xh, zh)
73
74 if sprayTypeIndex ~= nil then
75 local sprayChangedArea, sprayTotalArea = FSDensityMapUtil.updateSprayArea(xs, zs, xw, zw, xh, zh, sprayTypeIndex)
76
77 sprayerParams.lastChangedArea = sprayerParams.lastChangedArea + sprayChangedArea
78 sprayerParams.lastTotalArea = sprayerParams.lastTotalArea + sprayTotalArea
79 sprayerParams.lastStatsArea = 0
80 sprayerParams.isActive = true
81 end
82
83 specCultivator.isWorking = true
84
85 return cultivatorChangedArea, cultivatorTotalArea
86end

registerEventListeners

Description
Definition
registerEventListeners()
Code
30function FertilizingCultivator.registerEventListeners(vehicleType)
31 SpecializationUtil.registerEventListener(vehicleType, "onLoad", FertilizingCultivator)
32end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
23function FertilizingCultivator.registerOverwrittenFunctions(vehicleType)
24 SpecializationUtil.registerOverwrittenFunction(vehicleType, "processCultivatorArea", FertilizingCultivator.processCultivatorArea)
25 SpecializationUtil.registerOverwrittenFunction(vehicleType, "setSprayerAITerrainDetailProhibitedRange", FertilizingCultivator.setSprayerAITerrainDetailProhibitedRange)
26end

setSprayerAITerrainDetailProhibitedRange

Description
Definition
setSprayerAITerrainDetailProhibitedRange()
Code
90function FertilizingCultivator:setSprayerAITerrainDetailProhibitedRange(superFunc, fillType)
91 if self.addAITerrainDetailProhibitedRange ~= nil then
92 self:clearAITerrainDetailProhibitedRange()
93
94 local sprayTypeDesc = g_sprayTypeManager:getSprayTypeByFillTypeIndex(fillType)
95 if sprayTypeDesc ~= nil then
96 -- we check here for fertilizing bit instead of ground type bit, because we directly cultivate the ground type
97 self:addAITerrainDetailProhibitedRange(1, 2, g_currentMission.sprayFirstChannel, g_currentMission.sprayNumChannels)
98 self:addAITerrainDetailProhibitedRange(g_currentMission.sprayLevelMaxValue, g_currentMission.sprayLevelMaxValue, g_currentMission.sprayLevelFirstChannel, g_currentMission.sprayLevelNumChannels)
99 end
100 end
101end