47 | function 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 |
136 | end |