58 | function 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 |
149 | end |