LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

FertilizingSowingMachine

Description
Specialization for sowing machines which also have a fertilizing function
Functions

getAreEffectsVisible

Description
Definition
getAreEffectsVisible()
Code
159function FertilizingSowingMachine:getAreEffectsVisible(superFunc)
160 return superFunc(self) and self:getFillUnitFillType(self:getSprayerFillUnitIndex()) ~= FillType.UNKNOWN
161end

getUseSprayerAIRequirements

Description
Definition
getUseSprayerAIRequirements()
Code
153function FertilizingSowingMachine:getUseSprayerAIRequirements(superFunc)
154 return false
155end

initSpecialization

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

onLoad

Description
Definition
onLoad()
Code
48function FertilizingSowingMachine:onLoad(savegame)
49 local spec = self.spec_fertilizingSowingMachine
50 spec.needsSetIsTurnedOn = self.xmlFile:getValue("vehicle.fertilizingSowingMachine#needsSetIsTurnedOn", false)
51
52 self.spec_sprayer.needsToBeFilledToTurnOn = false
53 self.spec_sprayer.useSpeedLimit = false
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 FertilizingSowingMachine.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(SowingMachine, specializations) and SpecializationUtil.hasSpecialization(Sprayer, specializations)
19end

processSowingMachineArea

Description
Definition
processSowingMachineArea()
Code
58function FertilizingSowingMachine:processSowingMachineArea(superFunc, workArea, dt)
59 local spec = self.spec_fertilizingSowingMachine
60 local specSowingMachine = self.spec_sowingMachine
61 local specSpray = self.spec_sprayer
62
63 local sprayerParams = specSpray.workAreaParameters
64 local sowingParams = specSowingMachine.workAreaParameters
65 local changedArea, totalArea
66
67 self.spec_sowingMachine.isWorking = self:getLastSpeed() > 0.5
68
69 if not sowingParams.isActive then
70 return 0, 0
71 end
72
73 if not self:getIsAIActive() or not g_currentMission.missionInfo.helperBuySeeds then
74 if sowingParams.seedsVehicle == nil then
75 if self:getIsAIActive() then
76 local rootVehicle = self.rootVehicle
77 rootVehicle:stopCurrentAIJob(AIMessageErrorOutOfFill.new())
78 end
79
80 return 0, 0
81 end
82 end
83
84 -- stop the sowing machine if the fertilizer tank was filled and got empty
85 -- do not stop if the tank was all the time empty
86 if not g_currentMission.missionInfo.helperBuyFertilizer then
87 if self:getIsAIActive() then
88 if sprayerParams.sprayFillType == nil or sprayerParams.sprayFillType == FillType.UNKNOWN then
89 if sprayerParams.lastAIHasSprayed ~= nil then
90 local rootVehicle = self.rootVehicle
91 rootVehicle:stopCurrentAIJob(AIMessageErrorOutOfFill.new())
92 sprayerParams.lastAIHasSprayed = nil
93 end
94 else
95 sprayerParams.lastAIHasSprayed = true
96 end
97 end
98 end
99
100 if not sowingParams.canFruitBePlanted then
101 return 0, 0
102 end
103
104 -- we need to use fertilizer as spraying type because fertilizer is the final blocking value
105 local sprayTypeIndex = SprayType.FERTILIZER
106 if sprayerParams.sprayFillLevel <= 0 or (spec.needsSetIsTurnedOn and not self:getIsTurnedOn()) then
107 sprayTypeIndex = nil
108 end
109
110 local startX,_,startZ = getWorldTranslation(workArea.start)
111 local widthX,_,widthZ = getWorldTranslation(workArea.width)
112 local heightX,_,heightZ = getWorldTranslation(workArea.height)
113
114 if not specSowingMachine.useDirectPlanting then
115 changedArea, totalArea = FSDensityMapUtil.updateSowingArea(sowingParams.seedsFruitType, startX, startZ, widthX, widthZ, heightX, heightZ, sowingParams.fieldGroundType, sowingParams.angle, nil, sprayTypeIndex)
116 else
117 changedArea, totalArea = FSDensityMapUtil.updateDirectSowingArea(sowingParams.seedsFruitType, startX, startZ, widthX, widthZ, heightX, heightZ, sowingParams.fieldGroundType, sowingParams.angle, nil, sprayTypeIndex)
118 end
119
120 self.spec_sowingMachine.isProcessing = self.spec_sowingMachine.isWorking
121
122 if sprayTypeIndex ~= nil then
123 local sprayAmount = specSpray.doubledAmountIsActive and 2 or 1
124 local sprayChangedArea, sprayTotalArea = FSDensityMapUtil.updateSprayArea(startX, startZ, widthX, widthZ, heightX, heightZ, sprayTypeIndex, sprayAmount)
125
126 sprayerParams.lastChangedArea = sprayerParams.lastChangedArea + sprayChangedArea
127 sprayerParams.lastTotalArea = sprayerParams.lastTotalArea + sprayTotalArea
128 sprayerParams.lastStatsArea = 0
129 sprayerParams.isActive = true
130 sprayerParams.lastSprayTime = g_time
131
132 local stats = g_currentMission:farmStats(self:getLastTouchedFarmlandFarmId())
133 local ha = MathUtil.areaToHa(sprayerParams.lastChangedArea, g_currentMission:getFruitPixelsToSqm())
134 stats:updateStats("sprayedHectares", ha)
135 stats:updateStats("sprayedTime", dt/(1000*60))
136 stats:updateStats("sprayUsage", sprayerParams.usage)
137 end
138
139 sowingParams.lastChangedArea = sowingParams.lastChangedArea + changedArea
140 sowingParams.lastStatsArea = sowingParams.lastStatsArea + changedArea
141 sowingParams.lastTotalArea = sowingParams.lastTotalArea + totalArea
142
143 -- remove tireTracks
144 FSDensityMapUtil.eraseTireTrack(startX, startZ, widthX, widthZ, heightX, heightZ)
145
146 self:updateMissionSowingWarning(startX, startZ)
147
148 return changedArea, totalArea
149end

registerEventListeners

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

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
34function FertilizingSowingMachine.registerOverwrittenFunctions(vehicleType)
35 SpecializationUtil.registerOverwrittenFunction(vehicleType, "processSowingMachineArea", FertilizingSowingMachine.processSowingMachineArea)
36 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getUseSprayerAIRequirements", FertilizingSowingMachine.getUseSprayerAIRequirements)
37 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAreEffectsVisible", FertilizingSowingMachine.getAreEffectsVisible)
38end