LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

FertilizingCultivator

Description
Specialization for cultivators which also have a fertilizing function
Functions

initSpecialization

Description
Definition
initSpecialization()
Code
23function FertilizingCultivator.initSpecialization()
24 local schema = Vehicle.xmlSchema
25 schema:setXMLSpecializationType("FertilizingCultivator")
26
27 schema:register(XMLValueType.BOOL, "vehicle.fertilizingCultivator#needsSetIsTurnedOn", "Needs to be turned on to spray", false)
28
29 schema:setXMLSpecializationType()
30end

onLoad

Description
Definition
onLoad()
Code
47function FertilizingCultivator:onLoad(savegame)
48 local spec = self.spec_fertilizingCultivator
49 spec.needsSetIsTurnedOn = self.xmlFile:getValue("vehicle.fertilizingCultivator#needsSetIsTurnedOn", false)
50 self.spec_sprayer.useSpeedLimit = false
51
52 self:clearAITerrainDetailRequiredRange()
53 self:updateCultivatorAIRequirements()
54end

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
58function FertilizingCultivator:processCultivatorArea(superFunc, workArea, dt)
59 local spec = self.spec_fertilizingCultivator
60 local specCultivator = self.spec_cultivator
61 local specSpray = self.spec_sprayer
62
63 local xs,_,zs = getWorldTranslation(workArea.start)
64 local xw,_,zw = getWorldTranslation(workArea.width)
65 local xh,_,zh = getWorldTranslation(workArea.height)
66
67 local cultivatorParams = specCultivator.workAreaParameters
68 local sprayerParams = specSpray.workAreaParameters
69
70 -- we need to use fertilizer as spraying type because fertilizer is the final blocking value
71 local sprayTypeIndex = SprayType.FERTILIZER
72
73 if sprayerParams.sprayFillLevel <= 0 or (spec.needsSetIsTurnedOn and not self:getIsTurnedOn()) then
74 sprayTypeIndex = nil
75 end
76
77 local cultivatorChangedArea, cultivatorTotalArea
78 if specCultivator.useDeepMode then
79 cultivatorChangedArea, cultivatorTotalArea = FSDensityMapUtil.updateCultivatorArea(xs, zs, xw, zw, xh, zh, not cultivatorParams.limitToField, cultivatorParams.limitFruitDestructionToField, cultivatorParams.angle, sprayTypeIndex)
80 cultivatorChangedArea = cultivatorChangedArea + FSDensityMapUtil.updateVineCultivatorArea(xs, zs, xw, zw, xh, zh)
81 else
82 cultivatorChangedArea, cultivatorTotalArea = FSDensityMapUtil.updateDiscHarrowArea(xs, zs, xw, zw, xh, zh, not cultivatorParams.limitToField, cultivatorParams.limitFruitDestructionToField, cultivatorParams.angle, sprayTypeIndex)
83 cultivatorChangedArea = cultivatorChangedArea + FSDensityMapUtil.updateVineCultivatorArea(xs, zs, xw, zw, xh, zh)
84 end
85
86 cultivatorParams.lastChangedArea = cultivatorParams.lastChangedArea + cultivatorChangedArea
87 cultivatorParams.lastTotalArea = cultivatorParams.lastTotalArea + cultivatorTotalArea
88 cultivatorParams.lastStatsArea = cultivatorParams.lastStatsArea + cultivatorChangedArea
89
90 if specCultivator.isSubsoiler then
91 FSDensityMapUtil.updateSubsoilerArea(xs, zs, xw, zw, xh, zh)
92 end
93
94 FSDensityMapUtil.eraseTireTrack(xs, zs, xw, zw, xh, zh)
95
96 if sprayTypeIndex ~= nil then
97 local sprayAmount = specSpray.doubledAmountIsActive and 2 or 1
98 local sprayChangedArea, sprayTotalArea = FSDensityMapUtil.updateSprayArea(xs, zs, xw, zw, xh, zh, sprayTypeIndex, sprayAmount)
99
100 sprayerParams.lastChangedArea = sprayerParams.lastChangedArea + sprayChangedArea
101 sprayerParams.lastTotalArea = sprayerParams.lastTotalArea + sprayTotalArea
102 sprayerParams.lastStatsArea = 0
103 sprayerParams.isActive = true
104 end
105
106 specCultivator.isWorking = true
107
108 return cultivatorChangedArea, cultivatorTotalArea
109end

registerEventListeners

Description
Definition
registerEventListeners()
Code
41function FertilizingCultivator.registerEventListeners(vehicleType)
42 SpecializationUtil.registerEventListener(vehicleType, "onLoad", FertilizingCultivator)
43end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
34function FertilizingCultivator.registerOverwrittenFunctions(vehicleType)
35 SpecializationUtil.registerOverwrittenFunction(vehicleType, "processCultivatorArea", FertilizingCultivator.processCultivatorArea)
36 SpecializationUtil.registerOverwrittenFunction(vehicleType, "setSprayerAITerrainDetailProhibitedRange", FertilizingCultivator.setSprayerAITerrainDetailProhibitedRange)
37end

setSprayerAITerrainDetailProhibitedRange

Description
Definition
setSprayerAITerrainDetailProhibitedRange()
Code
113function FertilizingCultivator:setSprayerAITerrainDetailProhibitedRange(superFunc, fillType)
114 if self.addAITerrainDetailProhibitedRange ~= nil then
115 self:clearAITerrainDetailProhibitedRange()
116
117 local sprayTypeDesc = g_sprayTypeManager:getSprayTypeByFillTypeIndex(fillType)
118 if sprayTypeDesc ~= nil then
119 local mission = g_currentMission
120 local sprayTypeMapId, sprayTypeFirstChannel, sprayTypeNumChannels = mission.fieldGroundSystem:getDensityMapData(FieldDensityMap.SPRAY_TYPE)
121 local sprayLevelMapId, sprayLevelFirstChannel, sprayLevelNumChannels = mission.fieldGroundSystem:getDensityMapData(FieldDensityMap.SPRAY_LEVEL)
122 local sprayLevelMaxValue = mission.fieldGroundSystem:getMaxValue(FieldDensityMap.SPRAY_LEVEL)
123 self:addAITerrainDetailProhibitedRange(sprayTypeDesc.sprayGroundType, sprayTypeDesc.sprayGroundType, sprayTypeFirstChannel, sprayTypeNumChannels)
124 -- TODO enable after field crops query support bitVectorMaps
125 --self:addAIFruitProhibitions(0, sprayTypeDesc.sprayGroundType, sprayTypeDesc.sprayGroundType, sprayTypeMapId, sprayTypeFirstChannel, sprayTypeNumChannels)
126 --self:addAIFruitProhibitions(0, sprayLevelMaxValue, sprayLevelMaxValue, sprayLevelMapId, sprayLevelFirstChannel, sprayLevelNumChannels)
127 end
128 end
129end