116 | function ExtendedSowingMachine:onEndWorkAreaProcessing(dt, hasProcessed) |
117 | local spec = self.spec_sowingMachine |
118 | if self.isServer then |
119 | if spec.workAreaParameters.lastChangedArea > 0 then |
120 | local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(spec.workAreaParameters.seedsFruitType) |
121 | local realHa = MathUtil.areaToHa(self.spec_extendedSowingMachine.lastRealChangedArea, g_currentMission:getFruitPixelsToSqm()) |
122 | local lastHa = MathUtil.areaToHa(spec.workAreaParameters.lastChangedArea, g_currentMission:getFruitPixelsToSqm()) |
123 | local usage = fruitDesc.seedUsagePerSqm * lastHa * 10000 |
124 | local usageRegular = fruitDesc.seedUsagePerSqm * realHa * 10000 |
125 | |
126 | local damage = self:getVehicleDamage() |
127 | if damage > 0 then |
128 | usage = usage * (1 + damage * SowingMachine.DAMAGED_USAGE_INCREASE) |
129 | usageRegular = usageRegular * (1 + damage * SowingMachine.DAMAGED_USAGE_INCREASE) |
130 | end |
131 | |
132 | local farmlandStatistics, _, farmlandId = self:getPFStatisticInfo() |
133 | if farmlandStatistics ~= nil then |
134 | if farmlandId ~= nil then |
135 | farmlandStatistics:updateStatistic(farmlandId, "usedSeeds", usage) |
136 | farmlandStatistics:updateStatistic(farmlandId, "usedSeedsRegular", usageRegular) |
137 | end |
138 | end |
139 | end |
140 | end |
141 | end |
145 | function ExtendedSowingMachine:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
146 | if self.isClient then |
147 | local spec = self.spec_extendedSowingMachine |
148 | self:clearActionEventsTable(spec.actionEvents) |
149 | |
150 | if isActiveForInputIgnoreSelection then |
151 | local _, actionEventId = self:addActionEvent(spec.actionEvents, spec.inputActionToggleAuto, self, ExtendedSowingMachine.actionEventToggleAuto, false, true, false, true, nil) |
152 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH) |
153 | |
154 | _, actionEventId = self:addActionEvent(spec.actionEvents, spec.inputActionToggleRate, self, ExtendedSowingMachine.actionEventChangeSeedRate, false, true, false, true, nil) |
155 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH) |
156 | g_inputBinding:setActionEventText(actionEventId, spec.texts.inputChangeSeedRate) |
157 | |
158 | ExtendedSowingMachine.updateActionEventState(self) |
159 | end |
160 | |
161 | spec.attachStateChanged = true |
162 | end |
163 | end |
78 | function ExtendedSowingMachine:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
79 | local spec = self.spec_extendedSowingMachine |
80 | spec.lastGroundUpdateDistance = spec.lastGroundUpdateDistance + self.lastMovedDistance |
81 | if spec.lastGroundUpdateDistance > spec.groundUpdateDistance then |
82 | spec.lastGroundUpdateDistance = 0 |
83 | |
84 | local workArea = self:getWorkAreaByIndex(1) |
85 | if workArea ~= nil then |
86 | local x, z |
87 | |
88 | -- if the work area starts in the middle of the vehicle we use the start node, otherwise the middle between start and width |
89 | local lx, _, _ = localToLocal(workArea.start, self.rootNode, 0, 0, 0) |
90 | if math.abs(lx) < 0.5 then |
91 | x, _, z = getWorldTranslation(workArea.start) |
92 | else |
93 | local x1, _, z1 = getWorldTranslation(workArea.start) |
94 | local x2, _, z2 = getWorldTranslation(workArea.width) |
95 | x, z = (x1 + x2) * 0.5, (z1 + z2) * 0.5 |
96 | end |
97 | |
98 | local isOnField, _ = FSDensityMapUtil.getFieldDataAtWorldPosition(x, 0, z) |
99 | if isOnField then |
100 | local soilTypeIndex = spec.soilMap:getTypeIndexAtWorldPos(x, z) |
101 | if soilTypeIndex > 0 then |
102 | local fruitTypeIndex = self.spec_sowingMachine.seeds[self.spec_sowingMachine.currentSeed] |
103 | spec.seedRateRecommendation = spec.seedRateMap:getOptimalSeedRateByFruitTypeAndSoiltype(fruitTypeIndex, soilTypeIndex) |
104 | else |
105 | spec.seedRateRecommendation = nil |
106 | end |
107 | else |
108 | spec.seedRateRecommendation = nil |
109 | end |
110 | end |
111 | end |
112 | end |
198 | function ExtendedSowingMachine:processSowingMachineArea(superFunc, workArea, dt) |
199 | local changedArea, totalArea = superFunc(self, workArea, dt) |
200 | if changedArea > 0 then |
201 | local spec = self.spec_extendedSowingMachine |
202 | local specSowingMachine = self.spec_sowingMachine |
203 | local workAreaParameters = specSowingMachine.workAreaParameters |
204 | |
205 | local sx, _, sz = getWorldTranslation(workArea.start) |
206 | local wx, _, wz = getWorldTranslation(workArea.width) |
207 | local hx, _, hz = getWorldTranslation(workArea.height) |
208 | |
209 | local fruitType = workAreaParameters.seedsFruitType |
210 | |
211 | local realUsage, realSeedRate, realSeedRateIndex = spec.seedRateMap:updateSeedArea(sx, sz, wx, wz, hx, hz, fruitType, spec.seedRateAutoMode, spec.manualSeedRate) |
212 | |
213 | if realSeedRateIndex ~= nil then |
214 | local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(fruitType) |
215 | local usageOffset = realUsage / fruitDesc.seedUsagePerSqm |
216 | |
217 | spec.lastRealChangedArea = workAreaParameters.lastChangedArea |
218 | workAreaParameters.lastChangedArea = workAreaParameters.lastChangedArea * usageOffset |
219 | |
220 | spec.lastSeedRate = realSeedRate |
221 | spec.lastSeedRateIndex = realSeedRateIndex |
222 | end |
223 | end |
224 | |
225 | return changedArea, totalArea |
226 | end |
242 | function ExtendedSowingMachine.updateActionEventState(self) |
243 | local spec = self.spec_extendedSowingMachine |
244 | local actionEventToggleAuto = spec.actionEvents[spec.inputActionToggleAuto] |
245 | if actionEventToggleAuto ~= nil then |
246 | g_inputBinding:setActionEventText(actionEventToggleAuto.actionEventId, spec.seedRateAutoMode and spec.texts.inputToggleAutoModeNeg or spec.texts.inputToggleAutoModePos) |
247 | end |
248 | |
249 | local actionEventToggleRate = spec.actionEvents[spec.inputActionToggleRate] |
250 | if actionEventToggleRate ~= nil then |
251 | g_inputBinding:setActionEventActive(actionEventToggleRate.actionEventId, not spec.seedRateAutoMode) |
252 | end |
253 | end |