LUADOC - Farming Simulator 19

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
146function FertilizingSowingMachine:getAreEffectsVisible(superFunc)
147 return superFunc(self) and self:getFillUnitFillType(self:getSprayerFillUnitIndex()) ~= FillType.UNKNOWN
148end

getUseSprayerAIRequirements

Description
Definition
getUseSprayerAIRequirements()
Code
140function FertilizingSowingMachine:getUseSprayerAIRequirements(superFunc)
141 return false
142end

onLoad

Description
Definition
onLoad()
Code
37function FertilizingSowingMachine:onLoad(savegame)
38 local spec = self.spec_fertilizingSowingMachine
39 spec.needsSetIsTurnedOn = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.fertilizingSowingMachine#needsSetIsTurnedOn"), false)
40
41 self.spec_sprayer.needsToBeFilledToTurnOn = false
42 self.spec_sprayer.useSpeedLimit = false
43end

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

registerEventListeners

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

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
23function FertilizingSowingMachine.registerOverwrittenFunctions(vehicleType)
24 SpecializationUtil.registerOverwrittenFunction(vehicleType, "processSowingMachineArea", FertilizingSowingMachine.processSowingMachineArea)
25 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getUseSprayerAIRequirements", FertilizingSowingMachine.getUseSprayerAIRequirements)
26 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAreEffectsVisible", FertilizingSowingMachine.getAreEffectsVisible)
27end