@@ -45,7 +45,6 @@ function SprayerSectionControl.registerEventListeners(vehicleType)
4545 SpecializationUtil .registerEventListener (vehicleType , " onDraw" , SprayerSectionControl )
4646 SpecializationUtil .registerEventListener (vehicleType , " onTurnedOn" , SprayerSectionControl )
4747 SpecializationUtil .registerEventListener (vehicleType , " onTurnedOff" , SprayerSectionControl )
48- SpecializationUtil .registerEventListener (vehicleType , " onAIImplementStart" , SprayerSectionControl )
4948end
5049
5150function SprayerSectionControl .registerOverwrittenFunctions (vehicleType )
@@ -102,7 +101,6 @@ function SprayerSectionControl:onLoad(savegame)
102101 end
103102 i = i + 1
104103 local workAreaId = getXMLInt (self .xmlFile , key .. " #workAreaId" )
105- -- local effectNodes = StringUtil.splitString(" ", StringUtil.trim(getXMLString(self.xmlFile, key.."#effectNodeId")))
106104 local effectNodes = StringUtil .getVectorNFromString (getXMLString (self .xmlFile , key .. " #effectNodeId" ))
107105 local testAreaStart = I3DUtil .indexToObject (self .components , getXMLString (self .xmlFile , key .. " #testAreaStartNode" ), self .i3dMappings )
108106 local testAreaWidth = I3DUtil .indexToObject (self .components , getXMLString (self .xmlFile , key .. " #testAreaWidthNode" ), self .i3dMappings )
@@ -143,12 +141,33 @@ function SprayerSectionControl:onLoad(savegame)
143141 end
144142 end
145143
144+ spec .herbicideQuery = FieldCropsQuery :new (g_currentMission .terrainDetailId )
145+ local desc = g_fruitTypeManager :getWeedFruitType ()
146+ spec .herbicideQuery :addRequiredCropType (g_currentMission .fruits [desc .index ].id , 1 , 3 , desc .startStateChannel , desc .numStateChannels , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
147+
148+ spec .fertilizerQuery = FieldCropsQuery :new (g_currentMission .terrainDetailId )
149+ spec .fertilizerQuery :addRequiredGroundValue (g_currentMission .cultivatorValue , g_currentMission .plowValue , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
150+ spec .fertilizerQuery :addRequiredGroundValue (g_currentMission .sowingValue , g_currentMission .sowingWidthValue , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
151+ spec .fertilizerQuery :addRequiredGroundValue (g_currentMission .grassValue , g_currentMission .grassValue , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
152+ local fillType = self :getFillUnitLastValidFillType (self :getSprayerFillUnitIndex ())
153+ if fillType == FillType .UNKNOWN then
154+ fillType = self :getFillUnitFirstSupportedFillType (self :getSprayerFillUnitIndex ())
155+ end
156+ local sprayTypeDesc = g_sprayTypeManager :getSprayTypeByFillTypeIndex (fillType )
157+ spec .fertilizerQuery :addProhibitedGroundValue (sprayTypeDesc .groundType , sprayTypeDesc .groundType , g_currentMission .sprayFirstChannel , g_currentMission .sprayNumChannels )
158+ spec .fertilizerQuery :addProhibitedGroundValue (g_currentMission .sprayLevelMaxValue , g_currentMission .sprayLevelMaxValue , g_currentMission .sprayLevelFirstChannel , g_currentMission .sprayLevelNumChannels )
159+
146160 spec .isAutomaticMode = true
147161 spec .hudActive = true
148162 spec .hud = {}
149163
150164 local sections = math.min (# spec .groups , 13 )
151165 local midSection = math.ceil (sections / 2 )
166+ local even = false
167+ if midSection == sections / 2 then -- section count even --> no middle part in HUD
168+ midSection = midSection + 1
169+ even = true
170+ end
152171 local image = SprayerSectionControl .modDirectory .. " sschud.dds"
153172 local uiScale = g_gameSettings .uiScale
154173 local hudScale = 0.33
@@ -162,14 +181,18 @@ function SprayerSectionControl:onLoad(savegame)
162181 if midSection > 4 then
163182 wpx = wpx + ((midSection - 4 ) * SprayerSectionControl .HUDUVs .SECTION_LEFT_1 [3 ])
164183 end
165- wpx = SprayerSectionControl .HUDUVs .SECTION_MID [3 ] + 2 * wpx
184+ if even then
185+ wpx = 2 * wpx
186+ midSection = midSection - 0.5
187+ else
188+ wpx = SprayerSectionControl .HUDUVs .SECTION_MID [3 ] + 2 * wpx
189+ end
166190
167191 local w ,h = getNormalizedScreenValues (wpx * uiScale * hudScale , 350 * uiScale * hudScale )
168192 local w2 ,h2 = getNormalizedScreenValues ((wpx + 80 ) * uiScale * hudScale , 350 * uiScale * hudScale )
169193 local baseX = 1 - g_safeFrameOffsetX - w
170194 local baseY = 0.6
171195
172- spec .hud .midSection = midSection
173196 spec .hud .sections = {}
174197 spec .hud .buttons = {}
175198 local lastW , lastH
@@ -196,8 +219,9 @@ function SprayerSectionControl:onLoad(savegame)
196219 offsetX = offsetX + lastW
197220 end
198221 end
222+ spec .hud .midSection = math.ceil (midSection )
199223 spec .hud .autoModeButton ,_ ,_ = self :createSSCHUDElement (image , baseX + lastW / 2 , baseY + lastH , hudScale * uiScale * 1.75 , SprayerSectionControl .HUDUVs .SECTION_ONOFF , Overlay .ALIGN_VERTICAL_BOTTOM , self .toggleAutomaticMode )
200- spec .hud .bg = Overlay :new (image , self .spec_ssc .hud .sections [midSection ].x , baseY + h / 5 , w2 , h )
224+ spec .hud .bg = Overlay :new (image , self .spec_ssc .hud .sections [spec . hud . midSection ].x + ( even and self . spec_ssc . hud . sections [ spec . hud . midSection ]. offsetX or 0 ) , baseY + h / 5 , w2 , h )
201225 spec .hud .bg :setUVs (getNormalizedUVs (SprayerSectionControl .HUDUVs .BACKGROUND , { 1024 , 256 }))
202226 spec .hud .bg :setAlignment (Overlay .ALIGN_VERTICAL_MIDDLE , Overlay .ALIGN_HORIZONTAL_CENTER )
203227 spec .hud .bg :setColor (0.015 , 0.015 , 0.015 , 0.9 )
@@ -208,7 +232,6 @@ function SprayerSectionControl:onPostLoad(savegame)
208232 if g_client .serverStreamId ~= 0 then
209233 local spec = self .spec_ssc -- multiplayer --> make testAreas bigger
210234 if spec .isSSCReady then
211- -- print("adjusting section testAreas for online usage")
212235 for k ,section in pairs (spec .sections ) do
213236 local x , y , z = getTranslation (section .testAreaStart )
214237 setTranslation (section .testAreaStart , x , y , z + 0.8 )
@@ -230,11 +253,7 @@ function SprayerSectionControl:createSSCHUDElement(image, x, y, hudScale, uvs, a
230253 if sectionId ~= nil then
231254 overlay .sectionId = sectionId
232255 if self .spec_ssc .sections [sectionId ].active then
233- -- if self:getIsTurnedOn() then
234- -- overlay:setColor(unpack(SprayerSectionControl.COLOR.GREEN))
235- -- else
236- overlay :setColor (unpack (SprayerSectionControl .COLOR .YELLOW ))
237- -- end
256+ overlay :setColor (unpack (SprayerSectionControl .COLOR .YELLOW ))
238257 else
239258 overlay :setColor (unpack (SprayerSectionControl .COLOR .RED ))
240259 end
248267function SprayerSectionControl :onUpdate (dt )
249268 if self .spec_ssc .isSSCReady then
250269 local spec = self .spec_ssc
251- if spec .isAutomaticMode and self :getIsTurnedOn () and not self : getIsAIActive () then
270+ if spec .isAutomaticMode and self :getIsTurnedOn () then
252271 if # spec .sections > 0 then
253- local fillType = self :getFillUnitLastValidFillType (self :getSprayerFillUnitIndex ())
254- if fillType == FillType .UNKNOWN then
255- fillType = self :getFillUnitFirstSupportedFillType (self :getSprayerFillUnitIndex ())
256- end
257- local sprayTypeDesc = g_sprayTypeManager :getSprayTypeByFillTypeIndex (fillType )
258- if sprayTypeDesc ~= nil then
259- if sprayTypeDesc .isHerbicide then
260- self :setAIFruitRequirements (g_fruitTypeManager :getFruitTypeByName (" weed" ).index , 0 , 2 )
261- elseif sprayTypeDesc .isFertilizer then
262- self :clearAITerrainDetailRequiredRange ()
263- self :clearAITerrainDetailProhibitedRange ()
264- self :addAITerrainDetailRequiredRange (g_currentMission .plowValue , g_currentMission .plowValue , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
265- self :addAITerrainDetailRequiredRange (g_currentMission .cultivatorValue , g_currentMission .cultivatorValue , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
266- self :addAITerrainDetailRequiredRange (g_currentMission .sowingValue , g_currentMission .sowingValue , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
267- self :addAITerrainDetailRequiredRange (g_currentMission .sowingWidthValue , g_currentMission .sowingWidthValue , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
268- self :addAITerrainDetailRequiredRange (g_currentMission .grassValue , g_currentMission .grassValue , g_currentMission .terrainDetailTypeFirstChannel , g_currentMission .terrainDetailTypeNumChannels )
269- self :addAITerrainDetailProhibitedRange (sprayTypeDesc .groundType , sprayTypeDesc .groundType , g_currentMission .sprayFirstChannel , g_currentMission .sprayNumChannels )
270- self :addAITerrainDetailProhibitedRange (g_currentMission .sprayLevelMaxValue , g_currentMission .sprayLevelMaxValue , g_currentMission .sprayLevelFirstChannel , g_currentMission .sprayLevelNumChannels )
271- end
272- end
273272 for k ,section in pairs (spec .sections ) do
274273 local sActive = true
275274 if section .sprayType ~= nil then
@@ -279,10 +278,19 @@ function SprayerSectionControl:onUpdate(dt)
279278 end
280279 end
281280 if sActive then
281+ local fillType = self :getFillUnitLastValidFillType (self :getSprayerFillUnitIndex ())
282+ if fillType == FillType .UNKNOWN then
283+ fillType = self :getFillUnitFirstSupportedFillType (self :getSprayerFillUnitIndex ())
284+ end
285+ local sprayTypeDesc = g_sprayTypeManager :getSprayTypeByFillTypeIndex (fillType )
286+ local query = spec .fertilizerQuery
287+ if sprayTypeDesc ~= nil and sprayTypeDesc .isHerbicide then
288+ query = spec .herbicideQuery
289+ end
282290 local sx ,_ ,sz = getWorldTranslation (section .testAreaStart )
283291 local wx ,_ ,wz = getWorldTranslation (section .testAreaWidth )
284292 local hx ,_ ,hz = getWorldTranslation (section .testAreaHeight )
285- local area , totalArea = AIVehicleUtil .getAIFruitArea (sx , sz , wx , wz , hx , hz , self : getFieldCropsQuery () )
293+ local area , totalArea = AIVehicleUtil .getAIFruitArea (sx , sz , wx , wz , hx , hz , query )
286294 local newState = area > 0 and self :getLastSpeed () > 1
287295 if section .active ~= newState then
288296 self :changeSectionState (section , newState )
@@ -333,7 +341,6 @@ function SprayerSectionControl:changeSectionState(section, newState)
333341 if newState == nil then
334342 newState = not section .active
335343 end
336- -- print(string.format("Changed section %d state to %s", section.workAreaId, newState and "true" or "false"))
337344 section .active = newState
338345 if newState then
339346 if self :getIsTurnedOn () then
@@ -392,14 +399,6 @@ function SprayerSectionControl:onTurnedOff()
392399 end
393400end
394401
395- function SprayerSectionControl :onAIImplementStart () -- turn on every section at AI hire
396- if self .spec_ssc .isSSCReady then
397- for k ,section in pairs (self .spec_ssc .sections ) do
398- self :changeSectionState (section , true )
399- end
400- end
401- end
402-
403402function SprayerSectionControl :getSprayerUsage (superFunc , fillType , dt )
404403 local origUsage = superFunc (self , fillType , dt )
405404 if self .spec_ssc .isSSCReady then
@@ -453,22 +452,6 @@ function SprayerSectionControl.processActionEvent(self, actionName, inputValue,
453452 if actionName == " SHOW_SSC_MOUSE" then
454453 if self .spec_ssc .hudActive then
455454 g_inputBinding :setShowMouseCursor (not g_inputBinding :getShowMouseCursor ())
456- --[[ if g_inputBinding:getShowMouseCursor() then
457- if self.spec_enterable ~= nil and self.spec_enterable.cameras ~= nil then
458- for _, camera in pairs(self.spec_enterable.cameras) do
459- camera.allowTranslation = false
460- camera.isRotatable = false
461- end
462- end
463- else
464- if self.spec_enterable ~= nil and self.spec_enterable.cameras ~= nil then
465- for _, camera in pairs(self.spec_enterable.cameras) do
466- camera.allowTranslation = true
467- camera.isRotatable = true
468- end
469- end
470- end]]
471-
472455 if g_inputBinding :getShowMouseCursor () then
473456 g_inputBinding :setContext (" SSC_HUD" , true , false )
474457
0 commit comments