From a89e3bdc9f359d9613ec9b5952a0441684b487bb Mon Sep 17 00:00:00 2001 From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com> Date: Sun, 4 Jul 2021 11:55:33 +0200 Subject: [PATCH] Div changes - Small global company fix, where the production overlay automatically opens while loading. #7313 - Added DriverModeSetting - Adds more available helpers than 10 #7335 - Drive unload now improvements. --- AIDriver.lua | 9 +- ActionEventsLoader.lua | 10 +- CombineUnloadAIDriver.lua | 13 +- CombineUnloadManager.lua | 8 +- CpManager.lua | 2 +- FieldworkAIDriver.lua | 1 - TriggerHandler.lua | 6 +- base.lua | 31 ++--- button.lua | 6 +- courseplay.lua | 38 +++--- hud.lua | 68 +++++----- reverse.lua | 11 +- settings.lua | 214 +++++++++++++++++++++----------- start_stop.lua | 26 +--- toolManager.lua | 32 ++--- translations/translation_de.xml | 2 +- 16 files changed, 265 insertions(+), 212 deletions(-) diff --git a/AIDriver.lua b/AIDriver.lua index 785fb2d79..62eec0b7d 100644 --- a/AIDriver.lua +++ b/AIDriver.lua @@ -1329,7 +1329,7 @@ function AIDriver:tipIntoBGASiloTipTrigger(dt) local totalTipDuration = ((tipper.cp.fillLevel / dischargeNode.emptySpeed )/ 1000) + 2 --adding 2 sec for the time between setting tipstate and start of real unloading local meterPrSeconds = totalLength / totalTipDuration; self.unloadSpeed = meterPrSeconds*3.6 - courseplay.debugVehicle(courseplay.DBG_LOAD_UNLOAD,self.vehicle,'%s in mode %s: entering BGASilo:',tostring(tipper.getName and tipper:getName() or 'no name'), tostring(self.vehicle.cp.mode)) + courseplay.debugVehicle(courseplay.DBG_LOAD_UNLOAD,self.vehicle,'%s in mode %s: entering BGASilo:',tostring(tipper.getName and tipper:getName() or 'no name'), tostring(self.setting.driverMode:get())) courseplay.debugVehicle(courseplay.DBG_LOAD_UNLOAD,self.vehicle,'emptySpeed: %sl/sek; fillLevel: %0.1fl',tostring(dischargeNode.emptySpeed*1000),tipper.cp.fillLevel) courseplay.debugVehicle(courseplay.DBG_LOAD_UNLOAD,self.vehicle,'Silo length: %sm/Total unload time: %ss *3.6 = unload speed: %.2fkmh',tostring(totalLength) ,tostring(totalTipDuration),self.unloadSpeed) end @@ -1736,10 +1736,6 @@ function AIDriver:onDraw() PathfinderUtil.showNodes(self.pathfinder) end end ---TODO: do we want to continue using this setter/getter for driveUnloadNow?? -function AIDriver:setDriveUnloadNow(driveUnloadNow) - courseplay:setDriveUnloadNow(self.vehicle, driveUnloadNow or false) -end function AIDriver:setDriveNow() if self:isWaitingAtWaitPoint() then @@ -1748,9 +1744,6 @@ function AIDriver:setDriveNow() self.triggerHandler:onDriveNow() end -function AIDriver:getDriveUnloadNow() - return self.settings.driveUnloadNow:get() -end function AIDriver:refreshHUD() courseplay.hud:setReloadPageOrder(self.vehicle, self.vehicle.cp.hud.currentPage, true); diff --git a/ActionEventsLoader.lua b/ActionEventsLoader.lua index ff12fa7bf..418b107cf 100644 --- a/ActionEventsLoader.lua +++ b/ActionEventsLoader.lua @@ -365,17 +365,11 @@ function ActionEventCallbacks.actionEventOpenCloseHud(vehicle, actionName, input end function ActionEventCallbacks.actionEventNextDriverMode(vehicle, actionName, inputValue, callbackState, isAnalog) - local newMode = SettingsUtil.getNextCpMode(vehicle) - if newMode ~= vehicle.cp.mode then - vehicle:setCourseplayFunc('setCpMode', newMode); - end + vehicle.cp.settings.driverMode:setNext() end function ActionEventCallbacks.actionEventPreviousDriverMode(vehicle, actionName, inputValue, callbackState, isAnalog) - local newMode = SettingsUtil.getPrevCpMode(vehicle) - if newMode ~= vehicle.cp.mode then - vehicle:setCourseplayFunc('setCpMode', newMode); - end + vehicle.cp.settings.driverMode:setPrevious() end function ActionEventCallbacks.actionEventNextHudPage(vehicle, actionName, inputValue, callbackState, isAnalog) diff --git a/CombineUnloadAIDriver.lua b/CombineUnloadAIDriver.lua index 5e737252d..9d9c13fce 100644 --- a/CombineUnloadAIDriver.lua +++ b/CombineUnloadAIDriver.lua @@ -171,7 +171,8 @@ function CombineUnloadAIDriver:start(startingPoint) self.unloadCourse = Course(self.vehicle, self.vehicle.Waypoints) self.ppc:setNormalLookaheadDistance() - + self:setDriveUnloadNow(false) + if startingPoint:is(StartingPointSetting.START_WITH_UNLOAD) then if CpManager.isDeveloper then -- automatically select closest combine @@ -180,7 +181,6 @@ function CombineUnloadAIDriver:start(startingPoint) self:info('Start unloading, waiting for a combine to call') self:setNewState(self.states.ON_FIELD) self:disableCollisionDetection() - self:setDriveUnloadNow(false) self:startWaitingForCombine() else -- just to have a course set up in any case for PPC to work with until we find a combine/path @@ -895,6 +895,15 @@ function CombineUnloadAIDriver:shouldDriveOn() return self:getFillLevelPercent() > self:getDriveOnThreshold() end +function CombineUnloadAIDriver:getDriveUnloadNow() + return self.settings.driveUnloadNow:get() +end + +function CombineUnloadAIDriver:setDriveUnloadNow(driveUnloadNow) + self.settings.driveUnloadNow:set(driveUnloadNow) + self:refreshHUD() +end + function CombineUnloadAIDriver:getCombinesFillLevelPercent() return g_combineUnloadManager:getCombinesFillLevelPercent(self.combineToUnload) end diff --git a/CombineUnloadManager.lua b/CombineUnloadManager.lua index 91c716286..cdbb8c9f8 100644 --- a/CombineUnloadManager.lua +++ b/CombineUnloadManager.lua @@ -149,6 +149,7 @@ function CombineUnloadManager:addUnloaderToCombine(unloader,combine,noEventSend) if not noEventSend then UnloaderEvents:sendAddUnloaderToCombine(unloader,combine) end + combine.cp.driver:refreshHUD() else self:debug('%s is already assigned to combine %s as number %d', nameNum(unloader), nameNum(combine), #self.combines[combine].unloaders) end @@ -194,9 +195,10 @@ function CombineUnloadManager:giveMeACombineToUnload(unloader) self:debug('Combine with most fill level is %s', nameNum(combine)) local bestUnloader if combine ~= nil and combine.cp.driver:getFieldworkCourse() then - if combine.cp.settings.combineWantsCourseplayer:is(true) then + if combine.cp.settings.requestUnloader:is(true) then self:addUnloaderToCombine(unloader,combine) - combine.cp.settings.combineWantsCourseplayer:set(false) + combine.cp.settings.requestUnloader:set(false) + combine.cp.driver:refreshHUD() return combine end local num = self:getUnloadersNumber(unloader, combine) @@ -260,7 +262,7 @@ function CombineUnloadManager:getCombineWithMostFillLevel(unloader) self:debug('For unloader %s: %s (fill level %.1f, ready to unload: %s) has %d unloaders, this unloader is # %d', nameNum(unloader), nameNum(combine), fillLevelPct, tostring(combineReadyToUnload), numUnloaders, unloaderIndex or -1) if data and data.isCombine and (numUnloaders == 0 or unloaderIndex == 1) and combineReadyToUnload then - if combine.cp.settings.combineWantsCourseplayer:is(true) then + if combine.cp.settings.requestUnloader:is(true) then return combine end if mostFillLevel < fillLevelPct then diff --git a/CpManager.lua b/CpManager.lua index 358eed1b9..848e56039 100644 --- a/CpManager.lua +++ b/CpManager.lua @@ -637,7 +637,7 @@ function CpManager:loadAIDriver() local result = self:loadFile() if g_currentMission.controlledVehicle then -- re-instantiate the AIDriver after loaded - courseplay:setAIDriver(g_currentMission.controlledVehicle, g_currentMission.controlledVehicle.cp.mode) + g_currentMission.controlledVehicle.cp.settings.driverMode:setAIDriver() g_combineUnloadManager:addNewCombines() end return result diff --git a/FieldworkAIDriver.lua b/FieldworkAIDriver.lua index dbe3cc0ee..e869dec26 100644 --- a/FieldworkAIDriver.lua +++ b/FieldworkAIDriver.lua @@ -564,7 +564,6 @@ function FieldworkAIDriver:changeToFieldwork() self.state = self.states.ON_FIELDWORK_COURSE self.fieldworkState = self.states.WAITING_FOR_LOWER self:startWork() - self:setDriveUnloadNow(false); self:refreshHUD(); end diff --git a/TriggerHandler.lua b/TriggerHandler.lua index 377055fb6..f71923f5a 100644 --- a/TriggerHandler.lua +++ b/TriggerHandler.lua @@ -429,12 +429,16 @@ end --scanning for LoadingTriggers and FillTriggers(checkFillTriggers) function TriggerHandler:activateLoadingTriggerWhenAvailable() for key, object in pairs(g_currentMission.activatableObjects) do - if object:getIsActivatable(self.vehicle) then + if object:getIsActivatable(self.vehicle) and self:isObjectALoadingTrigger(object) then self:activateTriggerForVehicle(object, self.vehicle) end end end +function TriggerHandler:isObjectALoadingTrigger(object) + return object.source and (object.source.getAllFillLevels or object.source.getAllProvidedFillLevels) +end + function TriggerHandler:enableFillTypeLoading() self.validFillTypeLoading = true end diff --git a/base.lua b/base.lua index bc60245ed..d7912477a 100644 --- a/base.lua +++ b/base.lua @@ -72,9 +72,6 @@ function courseplay:onLoad(savegame) --- Adds the vehicle to the global info texts handler g_globalInfoTextHandler:addVehicle(self) - - -- CP mode - self.cp.mode = courseplay.MODE_DEFAULT; --courseplay:setNextPrevModeVars(self); -- for modes 4 and 6, this the index of the waypoint where the work begins self.cp.startWork = nil @@ -286,7 +283,7 @@ function courseplay:onLoad(savegame) courseplay.signs:updateWaypointSigns(self); - courseplay:setAIDriver(self, self.cp.mode) + self.cp.settings.driverMode:setAIDriver() end; function courseplay:onPostLoad(savegame) @@ -334,7 +331,7 @@ function courseplay:onDraw() local isDriving = self:getIsCourseplayDriving(); --WORKWIDTH DISPLAY - if self.cp.mode ~= 7 and self.cp.timers.showWorkWidth and self.cp.timers.showWorkWidth > 0 then + if self.cp.settings.driverMode:get() ~= 7 and self.cp.timers.showWorkWidth and self.cp.timers.showWorkWidth > 0 then if courseplay:timerIsThrough(self, 'showWorkWidth') then -- stop showing, reset timer courseplay:resetCustomTimer(self, 'showWorkWidth'); else -- timer running, show @@ -488,8 +485,7 @@ function courseplay:onUpdate(dt) --- Reset the current mode, as all implements are now attached. --- If the vehicle is new, then cp.loadedMode is nil if g_server then - local mode = self.cp.loadedMode or self.cp.mode - courseplay:setCpMode(self, mode, true) + self.cp.settings.driverMode:postInit() end if self.cp.driver then ---Post init function, as not all giants variables are @@ -777,8 +773,6 @@ function courseplay:onReadStream(streamId, connection) end --Make sure every vehicle has same AIDriver as the Server - courseplay:setAIDriver(self, self.cp.mode) - self.cp.driver:onReadStream(streamId) @@ -942,9 +936,7 @@ function courseplay:loadVehicleCPSettings(xmlFile, key, resetVehicles) if not resetVehicles and g_server ~= nil then -- COURSEPLAY local curKey = key .. '.courseplay.basics'; - --courseplay:setCpMode(self, Utils.getNoNil(getXMLInt(xmlFile, curKey .. '#aiMode'), self.cp.mode), true); - --- Save the loaded mode and set it later after all implements are attached. - self.cp.loadedMode = Utils.getNoNil(getXMLInt(xmlFile, curKey .. '#aiMode'), courseplay.MODE_DEFAULT) + local courses = Utils.getNoNil(getXMLString(xmlFile, curKey .. '#courses'), ''); self.cp.loadedCourses = StringUtil.splitString(",", courses); courseplay:reloadCourses(self, true); @@ -1002,7 +994,6 @@ function courseplay:saveToXMLFile(xmlFile, key, usedModNames) --CP basics - setXMLInt(xmlFile, newKey..".basics #aiMode", self.cp.mode) if #self.cp.loadedCourses == 0 and self.cp.currentCourseId ~= 0 then -- this is the case when a course has been generated and than saved, it is not in loadedCourses (should probably -- fix it there), so make sure it is in the savegame @@ -1183,6 +1174,17 @@ function courseplay.onStartCpAIDriver(vehicle,helperIndex,noEventSend, startedFa else spec.currentHelper = g_helperManager:getRandomHelper() end + --- Add new helpers, if we run out of giants helpers available. + --- TODO: Figure out if this needs tweaks for multiplayer. + while(spec.currentHelper == nil) do + --- Default helpers are index 1-10 + local index = math.random(1,10) + local source = g_helperManager:getHelperByIndex(index) + local name = "C"..tostring(math.random(1,100)) + + spec.currentHelper = g_helperManager:addHelper(name, name, source.filename) + end + g_helperManager:useHelper(spec.currentHelper) ---Make sure the farmId is never: 0 == spectator farm id, ---which could be the case when autodrive starts a CP driver. @@ -1337,7 +1339,8 @@ function CpMapHotSpot.createMapHotSpot(vehicle,text) local rawUvs = courseplay.hud:getModeUvs() local uvsSize = courseplay.hud:getIconSpriteSize() local imagePath = courseplay.hud:getIconSpritePath() - local uvs = courseplay.utils:getUvs(rawUvs[vehicle.cp.mode], uvsSize.x,uvsSize.y) + local mode = vehicle.cp.settings.driverMode:get() + local uvs = courseplay.utils:getUvs(rawUvs[mode], uvsSize.x,uvsSize.y) local hotspotX, _, hotspotZ = getWorldTranslation(vehicle.rootNode) local _, textSize = getNormalizedScreenValues(0, 9) diff --git a/button.lua b/button.lua index 499c57080..04695b29d 100644 --- a/button.lua +++ b/button.lua @@ -91,6 +91,10 @@ end; function courseplay.button:setSetting(setting) self.settingCall = setting + + --- ugly hack to allow the drive mode button overlays, + --- as the settingCall only gets passed after the button was created + self:setSpecialButtonUVs() return self; end; @@ -108,7 +112,7 @@ function courseplay.button:setSpecialButtonUVs() local prm = self.parameter; local txtSizeX, txtSizeY = courseplay.hud.iconSpriteSize.x, courseplay.hud.iconSpriteSize.y; - if fn == 'setCpMode' then + if self.settingCall and self.settingCall == self.vehicle.cp.settings.driverMode then courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.modeButtonsUVsPx[prm], txtSizeX, txtSizeY); elseif fn == 'setHudPage' then diff --git a/courseplay.lua b/courseplay.lua index 72390fe3b..69c45957a 100644 --- a/courseplay.lua +++ b/courseplay.lua @@ -189,7 +189,6 @@ local function setVersionData() end; local function setGlobalData() - -- CP MODES, TODO create a setting for cp.mode ! courseplay.MODE_GRAIN_TRANSPORT = 1; courseplay.MODE_COMBI = 2; courseplay.MODE_OVERLOADER = 3; @@ -251,25 +250,24 @@ local function setGlobalData() courseplay.multiplayerSyncTable = { - [1]={name='self.cp.mode',dataFormat='Int'}, - [2]={name='self.cp.turnDiameterAuto',dataFormat='Float'}, - [3]={name='self.cp.canDrive',dataFormat='Bool'}, - [4]={name='self.cp.drivingDirReverse',dataFormat='Bool'}, - [5]={name='self.cp.fieldEdge.customField.isCreated',dataFormat='Bool'}, - [6]={name='self.cp.fieldEdge.customField.fieldNum',dataFormat='Int'}, - [7]={name='self.cp.fieldEdge.customField.selectedFieldNumExists',dataFormat='Bool'}, - [8]={name='self.cp.fieldEdge.selectedField.fieldNum',dataFormat='Int'}, - [9]={name='self.cp.isDriving',dataFormat='Bool'}, - [10]={name='self.cp.hud.openWithMouse',dataFormat='Bool'}, - [11]={name='self.cp.workWidth',dataFormat='Float'}, - [12]={name='self.cp.turnDiameterAutoMode',dataFormat='Bool'}, - [13]={name='self.cp.turnDiameter',dataFormat='Float'}, - [14]={name='self.cp.coursePlayerNum',dataFormat='Int'}, --?? - [15]={name='self.cp.laneOffset',dataFormat='Float'}, - [16]={name='self.cp.hud.currentPage',dataFormat='Int'}, - [17]={name='self.cp.waypointIndex',dataFormat='Int'}, - [18]={name='self.cp.isRecording',dataFormat='Bool'}, - [19]={name='self.cp.recordingIsPaused',dataFormat='Bool'}, + [1]={name='self.cp.turnDiameterAuto',dataFormat='Float'}, + [2]={name='self.cp.canDrive',dataFormat='Bool'}, + [3]={name='self.cp.drivingDirReverse',dataFormat='Bool'}, + [4]={name='self.cp.fieldEdge.customField.isCreated',dataFormat='Bool'}, + [5]={name='self.cp.fieldEdge.customField.fieldNum',dataFormat='Int'}, + [6]={name='self.cp.fieldEdge.customField.selectedFieldNumExists',dataFormat='Bool'}, + [7]={name='self.cp.fieldEdge.selectedField.fieldNum',dataFormat='Int'}, + [8]={name='self.cp.isDriving',dataFormat='Bool'}, + [9]={name='self.cp.hud.openWithMouse',dataFormat='Bool'}, + [10]={name='self.cp.workWidth',dataFormat='Float'}, + [11]={name='self.cp.turnDiameterAutoMode',dataFormat='Bool'}, + [12]={name='self.cp.turnDiameter',dataFormat='Float'}, + [13]={name='self.cp.coursePlayerNum',dataFormat='Int'}, --?? + [14]={name='self.cp.laneOffset',dataFormat='Float'}, + [15]={name='self.cp.hud.currentPage',dataFormat='Int'}, + [16]={name='self.cp.waypointIndex',dataFormat='Int'}, + [17]={name='self.cp.isRecording',dataFormat='Bool'}, + [18]={name='self.cp.recordingIsPaused',dataFormat='Bool'}, } courseplay.globalSettings = SettingsContainer.createGlobalSettings() diff --git a/hud.lua b/hud.lua index efef6b83d..ea2f0ed1a 100644 --- a/hud.lua +++ b/hud.lua @@ -389,10 +389,8 @@ end -- set the content cyclic function courseplay.hud:setContent(vehicle) -- self = courseplay.hud - -- BOTTOM GLOBAL INFO - -- mode icon - vehicle.cp.hud.content.bottomInfo.showModeIcon = vehicle.cp.mode > 0 and vehicle.cp.mode <= courseplay.NUM_MODES; + -- course name if vehicle.cp.currentCourseName ~= nil then vehicle.cp.hud.content.bottomInfo.courseNameText = vehicle.cp.currentCourseName; @@ -581,9 +579,7 @@ end; function courseplay.hud:renderHudBottomInfo(vehicle) courseplay:setFontSettings('white', false, 'left'); - if vehicle.cp.hud.content.bottomInfo.showModeIcon then - vehicle.cp.hud.currentModeIcon:render(); - end; + vehicle.cp.hud.currentModeIcon:render(); if vehicle.cp.hud.content.bottomInfo.courseNameText ~= nil then renderText(self.bottomInfo.courseNameX, self.bottomInfo.textPosY, self.fontSizes.bottomInfo, vehicle.cp.hud.content.bottomInfo.courseNameText); @@ -950,36 +946,32 @@ function courseplay.hud:updatePageContent(vehicle, page) end end end - elseif entry.functionToCall == 'combineWantsCourseplayer:toggle' then - --CombineWantsCourseplayerSetting + elseif entry.functionToCall == 'requestUnloader:toggle' then + --requestUnloaderSetting if not g_combineUnloadManager:getHasUnloaders(vehicle) then - self:enableButtonWithFunction(vehicle,page, 'toggle',vehicle.cp.settings.combineWantsCourseplayer) - if vehicle.cp.settings.combineWantsCourseplayer:is(true) then - vehicle.cp.hud.content.pages[page][line][1].text = vehicle.cp.settings.combineWantsCourseplayer:getText() - else - vehicle.cp.hud.content.pages[page][line][1].text = vehicle.cp.settings.combineWantsCourseplayer:getText() - end + self:enableButtonWithFunction(vehicle,page, 'toggle',vehicle.cp.settings.requestUnloader) + vehicle.cp.hud.content.pages[page][line][1].text = vehicle.cp.settings.requestUnloader:getText() else - local courseplayer = g_combineUnloadManager:getUnloaderByNumber(1, vehicle) - self:disableButtonWithFunction(vehicle,page, 'toggle',vehicle.cp.settings.combineWantsCourseplayer) - vehicle.cp.hud.content.pages[page][line][1].text = vehicle.cp.settings.combineWantsCourseplayer:getLabel() - vehicle.cp.hud.content.pages[page][line][2].text = courseplayer.name; + local unloader = g_combineUnloadManager:getUnloaderByNumber(1, vehicle) + self:disableButtonWithFunction(vehicle,page, 'toggle',vehicle.cp.settings.requestUnloader) + vehicle.cp.hud.content.pages[page][line][1].text = vehicle.cp.settings.requestUnloader:getLabel() + vehicle.cp.hud.content.pages[page][line][2].text = unloader.name; end - elseif entry.functionToCall == 'startStopCourseplayer' then + elseif entry.functionToCall == 'startStopUnloader' then if g_combineUnloadManager:getHasUnloaders(vehicle) then - self:enableButtonWithFunction(vehicle,page, 'startStopCourseplayer') + self:enableButtonWithFunction(vehicle,page, 'startStopUnloader') local courseplayer = g_combineUnloadManager:getUnloaderByNumber(1, vehicle) vehicle.cp.hud.content.pages[page][line][1].text = courseplayer.cp.settings.forcedToStop:getText() else - self:disableButtonWithFunction(vehicle,page, 'startStopCourseplayer') + self:disableButtonWithFunction(vehicle,page, 'startStopUnloader') end - elseif entry.functionToCall == 'sendCourseplayerHome' then + elseif entry.functionToCall == 'sendUnloaderHome' then print("g_combineUnloadManager:getHasUnloaders(vehicle):"..tostring(g_combineUnloadManager:getHasUnloaders(vehicle))) if g_combineUnloadManager:getHasUnloaders(vehicle) then - self:enableButtonWithFunction(vehicle,page, 'sendCourseplayerHome') + self:enableButtonWithFunction(vehicle,page, 'sendUnloaderHome') vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_UNLOADING_DRIVER_SEND_HOME'); else - self:disableButtonWithFunction(vehicle,page, 'sendCourseplayerHome') + self:disableButtonWithFunction(vehicle,page, 'sendUnloaderHome') end elseif entry.functionToCall == 'driverPriorityUseFillLevel:toggle' then --DriverPriorityUseFillLevelSetting @@ -1210,6 +1202,8 @@ function courseplay.hud:updatePageContent(vehicle, page) self:showShowWaypointsButtons(vehicle, false) end vehicle.cp.hud.changeDrawCourseModeButton:setActive(not vehicle.cp.settings.courseDrawMode:isDeactivated()) + local mode = vehicle.cp.settings.driverMode:get() + courseplay.utils:setOverlayUVsPx(vehicle.cp.hud.currentModeIcon, courseplay.hud.bottomInfo.modeUVsPx[mode], courseplay.hud.iconSpriteSize.x, courseplay.hud.iconSpriteSize.y); -- make sure AutoDrive mode has all options currently available for the vehicle vehicle.cp.settings.autoDriveMode:update() self:setReloadPageOrder(vehicle, page, forceUpdate); @@ -1383,7 +1377,8 @@ function courseplay.hud:setupVehicleHud(vehicle) local sizeX,sizeY = self.iconSpriteSize.x, self.iconSpriteSize.y; -- current mode icon vehicle.cp.hud.currentModeIcon = Overlay:new( self.iconSpritePath, bi.modeIconX, bi.iconPosY, w, h); - courseplay.utils:setOverlayUVsPx(vehicle.cp.hud.currentModeIcon, bi.modeUVsPx[vehicle.cp.mode], sizeX, sizeY); + local mode = vehicle.cp.settings.driverMode:get() + courseplay.utils:setOverlayUVsPx(vehicle.cp.hud.currentModeIcon, bi.modeUVsPx[mode], sizeX, sizeY); -- waypoint icon vehicle.cp.hud.currentWaypointIcon = Overlay:new( self.iconSpritePath, bi.waypointIconX, bi.iconPosY, w, h); @@ -1407,15 +1402,15 @@ end; --setup functions function courseplay.hud:setupCpModeButtons(vehicle) - -- setCpMode buttons local totalWidth = (courseplay.NUM_MODES * self.buttonSize.big.w) + ((courseplay.NUM_MODES - 1) * self.buttonSize.big.margin); local baseX = self.baseCenterPosX - totalWidth/2; local y = self.linesButtonPosY[8] + self:pxToNormal(2, 'y'); + local driverModeSetting = vehicle.cp.settings.driverMode for i=1, courseplay.NUM_MODES do local posX = baseX + ((i - 1) * (self.buttonSize.big.w + self.buttonSize.big.margin)); local toolTip = courseplay:loc(('COURSEPLAY_MODE_%d'):format(i)); - local button = courseplay.button:new(vehicle, 'global', 'iconSprite.png', 'setCpMode', i, posX, y, self.buttonSize.big.w, self.buttonSize.big.h, nil, nil, false, false, false, toolTip); - button:setActive(i == vehicle.cp.mode) + local button = courseplay.button:new(vehicle, 'global', 'iconSprite.png', 'set', i, posX, y, self.buttonSize.big.w, self.buttonSize.big.h, nil, nil, false, false, false, toolTip):setSetting(driverModeSetting); + button:setActive(i == driverModeSetting:get()) end; end @@ -1841,12 +1836,15 @@ end -- Hud content functions function courseplay.hud:showCpModeButtons(vehicle, show) + local driverModeSetting = vehicle.cp.settings.driverMode + local validDriverModes = driverModeSetting:getValidModes() for _,button in pairs(vehicle.cp.buttons.global) do local fn, cpModeToCheck = button.functionToCall, button.parameter; - if fn == 'setCpMode'then + local setting = button.settingCall + if setting == driverModeSetting then button:setShow(show); - button:setDisabled(not courseplay:getIsToolCombiValidForCpMode(vehicle,cpModeToCheck)) - button:setActive(cpModeToCheck == vehicle.cp.mode) + button:setDisabled(not validDriverModes[cpModeToCheck]) + button:setActive(cpModeToCheck == driverModeSetting:get()) end end end @@ -2042,7 +2040,7 @@ function courseplay.hud:setAIDriverContent(vehicle) self:addRowButton(vehicle,vehicle.cp.settings.startingPoint,'next', 1, 2, 2 ) self:addRowButton(vehicle,nil,'setDriveNow', 1, 2, 3 ) ---only enable this button in mode 5 - if vehicle.cp.mode == courseplay.MODE_TRANSPORT then + if vehicle.cp.settings.driverMode:get() == courseplay.MODE_TRANSPORT then self:addRowButton(vehicle,vehicle.cp.settings.stopAtEnd,'toggle', 1, 3, 1 ) end self:addSettingsRowWithArrows(vehicle,nil,'switchDriverCopy', 1, 3, 2 ) @@ -2146,9 +2144,9 @@ function courseplay.hud:setCombineAIDriverContent(vehicle) self:debug(vehicle,"setCombineAIDriverContent") --page 0 self:enablePageButton(vehicle, 0) - self:addRowButton(vehicle,vehicle.cp.settings.combineWantsCourseplayer,'toggle', 0, 1, 1 ) - self:addRowButton(vehicle,nil,'startStopCourseplayer', 0, 2, 1 ) - self:addRowButton(vehicle,nil,'sendCourseplayerHome', 0, 3, 1 ) + self:addRowButton(vehicle,vehicle.cp.settings.requestUnloader,'toggle', 0, 1, 1 ) + self:addRowButton(vehicle,nil,'startStopUnloader', 0, 2, 1 ) + self:addRowButton(vehicle,nil,'sendUnloaderHome', 0, 3, 1 ) if vehicle.cp.isChopper then self:addRowButton(vehicle,nil,'switchCourseplayerSide', 0, 4, 1 ) else diff --git a/reverse.lua b/reverse.lua index cc2ad394e..d93ca7317 100644 --- a/reverse.lua +++ b/reverse.lua @@ -40,8 +40,13 @@ function courseplay:goReverse(vehicle,lx,lz,mode2) end; end; end; + + local mode = vehicle.cp.settings.driverMode:get() + local debugActive = courseplay.debugChannels[courseplay.DBG_REVERSE]; - local isNotValid = vehicle.cp.numWorkTools == 0 or workTool == nil or workTool.cp.isPivot == nil or not workTool.cp.frontNode or vehicle.cp.mode == 9; + local isNotValid = vehicle.cp.numWorkTools == 0 or workTool == nil or workTool.cp.isPivot == nil or not workTool.cp.frontNode or mode == courseplay.MODE_SHOVEL_FILL_AND_EMPTY; + + if isNotValid then -- Simple reversing, no trailer to back up, so set the direction and get out of here, no need for -- all the sophisticated reversing @@ -51,7 +56,7 @@ function courseplay:goReverse(vehicle,lx,lz,mode2) local _, vehicleY, _ = getWorldTranslation(vehicle.cp.directionNode); lx, lz = AIVehicleUtil.getDriveDirection(vehicle.cp.directionNode, newTarget.revPosX, vehicleY, newTarget.revPosZ); end; - elseif vehicle.cp.mode ~= 9 then + elseif mode ~= courseplay.MODE_SHOVEL_FILL_AND_EMPTY then -- Start: Fixes issue #525 local tx, ty, tz = localToWorld(vehicle.cp.directionNode, 0, 1, -3); local nx, ny, nz = localDirectionToWorld(vehicle.cp.directionNode, lx, -0,1, lz); @@ -286,7 +291,7 @@ function courseplay:goReverse(vehicle,lx,lz,mode2) lx, lz = MathUtil.getDirectionFromYRotation(angleDiff); end; - if (vehicle.cp.mode == courseplay.MODE_GRAIN_TRANSPORT or vehicle.cp.mode == courseplay.MODE_COMBI or vehicle.cp.mode == courseplay.MODE_FIELDWORK) and vehicle.cp.currentTipTrigger == nil and (vehicle.cp.totalFillLevel ~= nil and vehicle.cp.totalFillLevel > 0) then + if (mode == courseplay.MODE_GRAIN_TRANSPORT or mode == courseplay.MODE_COMBI or mode == courseplay.MODE_FIELDWORK) and vehicle.cp.currentTipTrigger == nil and (vehicle.cp.totalFillLevel ~= nil and vehicle.cp.totalFillLevel > 0) then local nx, ny, nz = localDirectionToWorld(node, lxTipper, -0.1, lzTipper); courseplay:doTriggerRaycasts(vehicle, 'tipTrigger', 'rev', false, xTipper, yTipper + 1, zTipper, nx, ny, nz); end; diff --git a/settings.lua b/settings.lua index 05d961d63..d4c76feb9 100644 --- a/settings.lua +++ b/settings.lua @@ -11,15 +11,6 @@ function courseplay:openCloseHud(vehicle, open) end; end; -function courseplay:setCpMode(vehicle, modeNum) - if vehicle.cp.mode ~= modeNum then - vehicle.cp.mode = modeNum; - courseplay.utils:setOverlayUVsPx(vehicle.cp.hud.currentModeIcon, courseplay.hud.bottomInfo.modeUVsPx[modeNum], courseplay.hud.iconSpriteSize.x, courseplay.hud.iconSpriteSize.y); - courseplay.infoVehicle(vehicle, 'Setting mode %d', modeNum) - courseplay:setAIDriver(vehicle, modeNum) - end; -end; - function courseplay:setAIDriver(vehicle, mode) local errorHandler = function(err) @@ -59,9 +50,7 @@ function courseplay:setAIDriver(vehicle, mode) else -- give it another try as a fallback level courseplay.infoVehicle(vehicle, 'Retrying initialization in mode 5') - status, result = xpcall(AIDriver, errorHandler, vehicle) - vehicle.cp.driver = status and result or nil - vehicle.cp.mode = courseplay.MODE_DEFAULT + self.cp.settings.resetToDefault()() end end @@ -88,23 +77,19 @@ function courseplay:startStop(vehicle) courseplay.hud:setReloadPageOrder(vehicle, vehicle.cp.hud.currentPage, true); end; -function courseplay:startStopCourseplayer(combine) +function courseplay:startStopUnloader(combine) local tractor = g_combineUnloadManager:getUnloaderByNumber(1, combine) if tractor then tractor.cp.settings.forcedToStop:toggle() end end; -function courseplay:setDriveUnloadNow(vehicle, bool) - if vehicle then - vehicle.cp.settings.driveUnloadNow:set(bool) - courseplay.hud:setReloadPageOrder(vehicle, vehicle.cp.hud.currentPage, true); +function courseplay:sendUnloaderHome(combine) + local unloader = g_combineUnloadManager:getUnloaderByNumber(1, combine) + if unloader then + unloader.cp.driver:setDriveUnloadNow(true) end end - -function courseplay:sendCourseplayerHome(combine) - courseplay:setDriveUnloadNow(g_combineUnloadManager:getUnloaderByNumber(1, combine), true); -end function courseplay:setHudPage(vehicle, pageNum) vehicle.cp.hud.hudPageButtons[vehicle.cp.hud.currentPage]:setActive(false) vehicle.cp.hud.currentPage = pageNum; @@ -1320,7 +1305,7 @@ function SettingList:loadFromXml(xml, parentKey) -- remember the value loaded from XML for those settings which aren't up to date when loading, -- for example the field numbers self.valueFromXml = getXMLInt(xml, self:getKey(parentKey)) - if self.valueFromXml then + if self.valueFromXml then self:set(self.valueFromXml,true) end end @@ -1551,7 +1536,113 @@ function IntSettingScientific:getFixedValue() return self:get()*self.POWER end +---@class DriverModeSetting : SettingList +DriverModeSetting = CpObject(SettingList) +DriverModeSetting.GRAIN_TRANSPORT = 1 +DriverModeSetting.COMBINE_UNLOAD = 2 +DriverModeSetting.OVERLOAD = 3 +DriverModeSetting.FILLABLE_FIELDWORK = 4 +DriverModeSetting.TRANSPORT = 5 +DriverModeSetting.FIELDWORK = 6 +DriverModeSetting.BALE_COLLECTOR = 7 +DriverModeSetting.FIELD_SUPPLY = 8 +DriverModeSetting.SHOVEL = 9 +DriverModeSetting.BUNKER_SILO = 10 +DriverModeSetting.NUM_MODES = 10 + +DriverModeSetting.defaultMode = DriverModeSetting.TRANSPORT + +function DriverModeSetting:init(vehicle) + local values = {} + local texts = {} + for i=1,self.NUM_MODES do + values[i] = i + texts[i] = i + end + SettingList.init(self,"driverMode","driverMode","driverMode",vehicle,values,texts) + self.current = self.defaultMode +end + +function DriverModeSetting:loadFromXml(xml, parentKey) + -- remember the value loaded from XML for those settings which aren't up to date when loading, + -- for example the field numbers + self.valueFromXml = getXMLInt(xml, self:getKey(parentKey)) +end + +function DriverModeSetting:postInit() + if self.valueFromXml then + self:set(self.valueFromXml,true) + end +end + +function DriverModeSetting:validateCurrentValue() + self.validModes = {} + local wasResetToDefault = false + for i=1,self.NUM_MODES do + local valid = courseplay:getIsToolCombiValidForCpMode(self.vehicle,i) + self.validModes[i] = valid or false + if self:get() == i and not valid then + self:resetToDefault() + wasResetToDefault = true + end + end +end + +function DriverModeSetting:onChange() + self:setAIDriver() + self.vehicle.cp.driver:refreshHUD() +end + +function DriverModeSetting:setAIDriver() + courseplay.infoVehicle(self.vehicle, 'Setting mode %d', self:get()) + courseplay:setAIDriver(self.vehicle, self:get()) +end + +function DriverModeSetting:resetToDefault() + self:set(self.defaultMode) +end + +function DriverModeSetting:getDefaultMode() + return self.defaultMode +end + +function DriverModeSetting:getValidModes() + return self.validModes +end + +function DriverModeSetting:checkAndSetValidValue(new) + if courseplay:getIsToolCombiValidForCpMode(self.vehicle,new) then + return SettingList.checkAndSetValidValue(self,new) + else + return self.defaultMode + end +end + +function DriverModeSetting:isDisabled() + return not self.vehicle.cp.canSwitchMode or self.vehicle:getIsCourseplayDriving() +end + +--- Set the next value +function DriverModeSetting:setNext() + if not self:isDisabled() then + local targetMode = self.current + repeat + targetMode = SettingList.checkAndSetValidValue(self, targetMode + 1) + until courseplay:getIsToolCombiValidForCpMode(self.vehicle, self.values[targetMode]) + self:setToIx(targetMode) + end +end +--- Set the previous value +function DriverModeSetting:setPrevious() + if not self:isDisabled() then + local targetMode = self.current + repeat + targetMode = SettingList.checkAndSetValidValue(self, targetMode - 1) + until courseplay:getIsToolCombiValidForCpMode(self.vehicle, self.values[targetMode]) + self:setToIx(targetMode) + end +end --- AutoDrive mode setting ---@class AutoDriveModeSetting : SettingList @@ -1637,8 +1728,9 @@ StartingPointSetting.START_WITH_UNLOAD = 5 -- start with unloading the comb StartingPointSetting.START_COLLECTING_BALES = 6 -- start with unloading the combine (only for CombineUnloadAIDriver) StartingPointSetting.START_AT_LAST_POINT = 7 -- last waypoint for all BunkerSiloAIDrivers (is visible as first wp in the hud) -function StartingPointSetting:init(vehicle) - local values, texts = self:getValuesForMode(vehicle.cp.mode) +function StartingPointSetting:init(vehicle, driverModeSetting) + self.driverModeSetting = driverModeSetting + local values, texts = self:getValuesForMode(driverModeSetting:get()) SettingList.init(self, 'startingPoint', 'COURSEPLAY_START_AT_POINT', 'COURSEPLAY_START_AT_POINT', vehicle, values, texts) end @@ -1705,7 +1797,7 @@ end function StartingPointSetting:checkAndSetValidValue(new) -- make sure we always have a valid set for the current mode - self.values, self.texts = self:getValuesForMode(self.vehicle.cp.mode) + self.values, self.texts = self:getValuesForMode(self.driverModeSetting:get()) return SettingList.checkAndSetValidValue(self, new) end @@ -1793,7 +1885,8 @@ ReturnToFirstPointSetting.DEACTIVATED = 0 ReturnToFirstPointSetting.RETURN_TO_START = 1 ReturnToFirstPointSetting.RELEASE_DRIVER = 2 ReturnToFirstPointSetting.RETURN_TO_START_AND_RELEASE_DRIVER = 3 -function ReturnToFirstPointSetting:init(vehicle) +function ReturnToFirstPointSetting:init(vehicle, driverModeSetting) + self.driverModeSetting = driverModeSetting SettingList.init(self, 'returnToFirstPoint', 'COURSEPLAY_RETURN_TO_FIRST_POINT', 'COURSEPLAY_RETURN_TO_FIRST_POINT', vehicle, { @@ -1811,7 +1904,7 @@ function ReturnToFirstPointSetting:init(vehicle) end function ReturnToFirstPointSetting:isDisabled() - return not self.vehicle.cp.canDrive or self.vehicle.cp.mode == courseplay.MODE_BALE_COLLECTOR + return not self.vehicle.cp.canDrive or self.driverModeSetting:get() == courseplay.MODE_BALE_COLLECTOR end function ReturnToFirstPointSetting:isReturnToStartActive() @@ -2227,13 +2320,14 @@ end ---@class StopAtEndSetting : BooleanSetting StopAtEndSetting = CpObject(BooleanSetting) -function StopAtEndSetting:init(vehicle) +function StopAtEndSetting:init(vehicle, driverModeSetting) + self.driverModeSetting = driverModeSetting BooleanSetting.init(self, 'stopAtEnd', 'COURSEPLAY_STOP_AT_LAST_POINT', 'COURSEPLAY_STOP_AT_LAST_POINT', vehicle) self:set(true) end function StopAtEndSetting:isDisabled() - return not self.vehicle.cp.canDrive or not self.vehicle.cp.mode == courseplay.MODE_TRANSPORT + return not self.vehicle.cp.canDrive or not self.driverModeSetting:get() == courseplay.MODE_TRANSPORT end ---@class AutomaticCoverHandlingSetting : BooleanSetting @@ -2309,10 +2403,10 @@ function DriveUnloadNowSetting:init(vehicle) self:set(false) end ----@class CombineWantsCourseplayerSetting : BooleanSetting -CombineWantsCourseplayerSetting = CpObject(BooleanSetting) -function CombineWantsCourseplayerSetting:init(vehicle) - BooleanSetting.init(self, 'combineWantsCourseplayer', 'COURSEPLAY_DRIVER', 'COURSEPLAY_DRIVER', vehicle, {'COURSEPLAY_REQUEST_UNLOADING_DRIVER','COURSEPLAY_UNLOADING_DRIVER_REQUESTED'}) +---@class RequestUnloaderSetting : BooleanSetting +RequestUnloaderSetting = CpObject(BooleanSetting) +function RequestUnloaderSetting:init(vehicle) + BooleanSetting.init(self, 'requestUnloader', 'COURSEPLAY_DRIVER', 'COURSEPLAY_DRIVER', vehicle, {'COURSEPLAY_REQUEST_UNLOADING_DRIVER','COURSEPLAY_UNLOADING_DRIVER_REQUESTED'}) self:set(false) end @@ -2815,20 +2909,21 @@ end ---@class ShovelModeAIDriverTriggerHandlerIsActive : BooleanSetting ShovelModeAIDriverTriggerHandlerIsActive = CpObject(BooleanSetting) -function ShovelModeAIDriverTriggerHandlerIsActive:init(vehicle) +function ShovelModeAIDriverTriggerHandlerIsActive:init(vehicle, driverModeSetting) + self.driverModeSetting = driverModeSetting BooleanSetting.init(self, 'shovelModeAIDriverTriggerHandlerIsActive','COURSEPLAY_SHOVEL_TRIGGERHANDLER_IS_ACTIVE', 'COURSEPLAY_SHOVEL_TRIGGERHANDLER_IS_ACTIVE', vehicle) self:set(false) end function ShovelModeAIDriverTriggerHandlerIsActive:isDisabled() - if self.vehicle.cp.mode ~= courseplay.MODE_SHOVEL_FILL_AND_EMPTY then + if self.driverModeSetting:get() ~= courseplay.MODE_SHOVEL_FILL_AND_EMPTY then return true end return false end function ShovelModeAIDriverTriggerHandlerIsActive:onChange() - if self.vehicle.cp.mode == courseplay.MODE_SHOVEL_FILL_AND_EMPTY then + if self.driverModeSetting:get() == courseplay.MODE_SHOVEL_FILL_AND_EMPTY then courseplay:setAIDriver(self.vehicle, courseplay.MODE_SHOVEL_FILL_AND_EMPTY) end BooleanSetting.onChange(self) @@ -3616,7 +3711,8 @@ Cylindered.actionEventInput = Utils.overwrittenFunction(Cylindered.actionEventIn ---@class FrontloaderToolPositionsSetting : WorkingToolPositionsSetting FrontloaderToolPositionsSetting = CpObject(WorkingToolPositionsSetting) -function FrontloaderToolPositionsSetting:init(vehicle) +function FrontloaderToolPositionsSetting:init(vehicle, driverModeSetting) + self.driverModeSetting = driverModeSetting local label = "front" local toolTip = "front" WorkingToolPositionsSetting.init(self,"frontloaderToolPositions", label, toolTip, vehicle,4) @@ -3635,7 +3731,7 @@ function FrontloaderToolPositionsSetting:isPlayingPositionDisabled(x) end function FrontloaderToolPositionsSetting:isDisabled() - return self.vehicle.cp.mode ~= courseplay.MODE_SHOVEL_FILL_AND_EMPTY + return self.driverModeSetting:get() ~= courseplay.MODE_SHOVEL_FILL_AND_EMPTY end ---@class AugerPipeToolPositionsSetting : WorkingToolPositionsSetting @@ -3993,9 +4089,10 @@ end function SettingsContainer.createVehicleSpecificSettings(vehicle) ---@type SettingsContainer local container = SettingsContainer("settings") + container:addSetting(DriverModeSetting, vehicle) container:addSetting(SearchCombineOnFieldSetting, vehicle) container:addSetting(SelectedCombineToUnloadSetting) - container:addSetting(ReturnToFirstPointSetting, vehicle) + container:addSetting(ReturnToFirstPointSetting, vehicle,container.driverMode) container:addSetting(UseAITurnsSetting, vehicle) container:addSetting(UsePathfindingInTurnsSetting, vehicle) container:addSetting(AllowReverseForPathfindingInTurnsSetting, vehicle) @@ -4003,7 +4100,7 @@ function SettingsContainer.createVehicleSpecificSettings(vehicle) container:addSetting(ImplementLowerTimeSetting, vehicle) container:addSetting(AutoDriveModeSetting, vehicle) container:addSetting(SelfUnloadSetting, vehicle) - container:addSetting(StartingPointSetting, vehicle) + container:addSetting(StartingPointSetting, vehicle,container.driverMode) container:addSetting(SymmetricLaneChangeSetting, vehicle) container:addSetting(PipeAlwaysUnfoldSetting, vehicle) container:addSetting(RidgeMarkersAutomatic, vehicle) @@ -4014,7 +4111,7 @@ function SettingsContainer.createVehicleSpecificSettings(vehicle) container:addSetting(SowingMachineFertilizerEnabled, vehicle) container:addSetting(EnableOpenHudWithMouseVehicle, vehicle) container:addSetting(EnableVisualWaypointsTemporary, vehicle) - container:addSetting(StopAtEndSetting, vehicle) + container:addSetting(StopAtEndSetting, vehicle,container.driverMode) container:addSetting(AutomaticCoverHandlingSetting, vehicle) container:addSetting(BaleCollectionFieldSetting, vehicle) container:addSetting(DriverPriorityUseFillLevelSetting, vehicle) @@ -4024,13 +4121,13 @@ function SettingsContainer.createVehicleSpecificSettings(vehicle) container:addSetting(AlwaysSearchFuelSetting, vehicle) container:addSetting(RealisticDrivingSetting, vehicle) container:addSetting(DriveUnloadNowSetting, vehicle) - container:addSetting(CombineWantsCourseplayerSetting, vehicle) + container:addSetting(RequestUnloaderSetting, vehicle) container:addSetting(TurnOnFieldSetting, vehicle) container:addSetting(GrainTransportDriver_SiloSelectedFillTypeSetting, vehicle) container:addSetting(FillableFieldWorkDriver_SiloSelectedFillTypeSetting, vehicle) container:addSetting(FieldSupplyDriver_SiloSelectedFillTypeSetting, vehicle) container:addSetting(ShovelModeDriver_SiloSelectedFillTypeSetting, vehicle) - container:addSetting(ShovelModeAIDriverTriggerHandlerIsActive, vehicle) + container:addSetting(ShovelModeAIDriverTriggerHandlerIsActive, vehicle,container.driverMode) container:addSetting(DriveOnAtFillLevelSetting, vehicle) container:addSetting(MoveOnAtFillLevelSetting, vehicle) container:addSetting(RefillUntilPctSetting, vehicle) @@ -4048,7 +4145,7 @@ function SettingsContainer.createVehicleSpecificSettings(vehicle) container:addSetting(ConvoyActiveSetting,vehicle) container:addSetting(ConvoyMinDistanceSetting,vehicle) container:addSetting(ConvoyMaxDistanceSetting,vehicle) -- do we need this one ? - container:addSetting(FrontloaderToolPositionsSetting,vehicle) + container:addSetting(FrontloaderToolPositionsSetting,vehicle,container.driverMode) container:addSetting(AugerPipeToolPositionsSetting,vehicle) container:addSetting(AlwaysWaitForShovelPositionsSetting,vehicle) container:addSetting(LevelCompactModeSetting,vehicle) @@ -4070,36 +4167,7 @@ function SettingsContainer.createVehicleSpecificSettings(vehicle) return container end ----TODO: create a setting for these: -SettingsUtil = {} - -function SettingsUtil.getNextCpMode(vehicle) - if vehicle.cp.canSwitchMode and not vehicle:getIsCourseplayDriving() then - for i=1,courseplay.NUM_MODES do - local targetMode = vehicle.cp.mode + i - if targetMode > courseplay.NUM_MODES then - targetMode = targetMode - courseplay.NUM_MODES - end - if courseplay:getIsToolCombiValidForCpMode(vehicle,targetMode) then - return targetMode - end - end - end -end -function SettingsUtil.getPrevCpMode(vehicle) - if vehicle.cp.canSwitchMode and not vehicle:getIsCourseplayDriving() then - for i=1,courseplay.NUM_MODES do - local targetMode = vehicle.cp.mode - i - if targetMode < 1 then - targetMode = courseplay.NUM_MODES + targetMode - end - if courseplay:getIsToolCombiValidForCpMode(vehicle,targetMode) then - return targetMode - end - end - end -end diff --git a/start_stop.lua b/start_stop.lua index 9af570967..88d392b61 100644 --- a/start_stop.lua +++ b/start_stop.lua @@ -49,8 +49,10 @@ function courseplay:start(self) self.cp.waitPoints = {}; self.cp.unloadPoints = {}; + local mode = self.cp.settings.driverMode:get() + -- modes 4/6 without start and stop point, set them at start and end, for only-on-field-courses - if (self.cp.mode == 4 or self.cp.mode == 6) then + if (mode == courseplay.MODE_SEED_FERTILIZE or mode == courseplay.MODE_FIELDWORK) then if numWaitPoints == 0 or self.cp.startWork == nil then self.cp.startWork = 1; end; @@ -64,24 +66,6 @@ function courseplay:start(self) courseplay:debug(string.format("%s: numWaitPoints=%d, waitPoints[1]=%s, numCrossingPoints=%d", nameNum(self), self.cp.numWaitPoints, tostring(self.cp.waitPoints[1]), numCrossingPoints), courseplay.DBG_COURSES); - if self.cp.waypointIndex > 2 and self.cp.mode ~= 4 and self.cp.mode ~= 6 and self.cp.mode ~= 8 then - courseplay:setDriveUnloadNow(self, true); - elseif self.cp.mode == 4 or self.cp.mode == 6 then - courseplay:setDriveUnloadNow(self, false); - elseif self.cp.mode == 8 then - courseplay:setDriveUnloadNow(self, false); - end - - if self.cp.settings.startingPoint:is(StartingPointSetting.START_AT_FIRST_POINT) then - if self.cp.mode == 2 or self.cp.mode == 3 then - -- TODO: really? 3? - courseplay:setWaypointIndex(self, 3); - courseplay:setDriveUnloadNow(self, true); - else - courseplay:setWaypointIndex(self, 1); - end - end; - courseplay:updateAllTriggers(); ---Do we need to set distanceCheck==true at the beginning of courseplay:start() and set now set it to false 50 lines later ?? @@ -93,10 +77,10 @@ function courseplay:start(self) -- and another ugly hack here as when settings.lua setAIDriver() is called the bale loader does not seem to be -- attached and I don't have the motivation do dig through the legacy code to find out why - if self.cp.mode == courseplay.MODE_FIELDWORK then + if mode == courseplay.MODE_FIELDWORK then self.cp.driver:delete() self.cp.driver = UnloadableFieldworkAIDriver.create(self) - elseif self.cp.mode == courseplay.MODE_BUNKERSILO_COMPACTER then + elseif mode == courseplay.MODE_BUNKERSILO_COMPACTER then --- Not sure if this is needed, might have to check if the AIDriver gets reevaluated after an implement gets attached. self.cp.driver:delete() self.cp.driver = BunkerSiloAIDriver.create(self) diff --git a/toolManager.lua b/toolManager.lua index 3e1562777..1ad00ae56 100644 --- a/toolManager.lua +++ b/toolManager.lua @@ -38,7 +38,7 @@ function courseplay:updateOnAttachOrDetach(vehicle) vehicle.cpTrafficCollisionIgnoreList = {} courseplay:resetTools(vehicle) - courseplay:setAIDriver(vehicle, vehicle.cp.mode) + vehicle.cp.settings:validateCurrentValues() -- reset tool offset to the preconfigured value if exists @@ -57,9 +57,6 @@ function courseplay:resetTools(vehicle) vehicle.cp.hasAugerWagon = false; vehicle.cp.workToolAttached = courseplay:updateWorkTools(vehicle, vehicle); - if not vehicle.cp.workToolAttached and vehicle.cp.mode ~= courseplay.MODE_BUNKERSILO_COMPACTER then - courseplay:setCpMode(vehicle, courseplay.MODE_DEFAULT) - end courseplay.hud:setReloadPageOrder(vehicle, -1, true); @@ -149,16 +146,11 @@ end; -- UPDATE WORKTOOL DATA function courseplay:updateWorkTools(vehicle, workTool, isImplement) - - -- temporary band aid until we figure out what exactly is causing this - if not vehicle.cp.mode then - vehicle.cp.mode = courseplay.MODE_TRANSPORT - courseplay.infoVehicle(vehicle, ' no CP mode set, worktool %s, forcing mode 5', nameNum(workTool)) - end + local mode = vehicle.cp.settings.driverMode:get() if not isImplement then courseplay.debugLine(courseplay.DBG_IMPLEMENTS, 3); - courseplay:debug(('%s: updateWorkTools(%s, %q, isImplement=false) (mode=%d)'):format(nameNum(vehicle),tostring(vehicle.name), nameNum(workTool), vehicle.cp.mode), courseplay.DBG_IMPLEMENTS); + courseplay:debug(('%s: updateWorkTools(%s, %q, isImplement=false) (mode=%d)'):format(nameNum(vehicle),tostring(vehicle.name), nameNum(workTool), mode), courseplay.DBG_IMPLEMENTS); else courseplay.debugLine(courseplay.DBG_IMPLEMENTS); courseplay:debug(('%s: updateWorkTools(%s, %q, isImplement=true)'):format(nameNum(vehicle),tostring(vehicle.name), nameNum(workTool)), courseplay.DBG_IMPLEMENTS); @@ -170,13 +162,13 @@ function courseplay:updateWorkTools(vehicle, workTool, isImplement) end; courseplay:setNameVariable(workTool); - courseplay:setOwnFillLevelsAndCapacities(workTool,vehicle.cp.mode) + courseplay:setOwnFillLevelsAndCapacities(workTool) local hasWorkTool = false; local hasWaterTrailer = false - local isAllowedOkay,isDisallowedOkay = CpManager.validModeSetupHandler:isModeValid(vehicle.cp.mode,workTool) + local isAllowedOkay,isDisallowedOkay = CpManager.validModeSetupHandler:isModeValid(mode,workTool) if isAllowedOkay and isDisallowedOkay then - if vehicle.cp.mode == 5 then + if mode == 5 then -- For reversing purpose ?? still needed ? if isImplement then hasWorkTool = true; @@ -190,7 +182,7 @@ function courseplay:updateWorkTools(vehicle, workTool, isImplement) -- MODE 4: FERTILIZER AND SEEDING - if vehicle.cp.mode == 4 then + if mode == 4 then if isAllowedOkay and isDisallowedOkay then vehicle.cp.hasMachinetoFill = true; end; @@ -391,9 +383,9 @@ function courseplay:setAutoTurnDiameter(vehicle, hasWorkTool) vehicle.cp.turnDiameterAuto = vehicle.cp.vehicleTurnRadius * 2; courseplay:debug(('%s: Set turnDiameterAuto to %.2fm (2 x vehicleTurnRadius)'):format(nameNum(vehicle), vehicle.cp.turnDiameterAuto), courseplay.DBG_IMPLEMENTS); - + local mode = vehicle.cp.settings.driverMode:get() -- Check if we have worktools and if we are in a valid mode - if hasWorkTool and (vehicle.cp.mode == 2 or vehicle.cp.mode == 3 or vehicle.cp.mode == 4 or vehicle.cp.mode == 6) then + if hasWorkTool and (mode == 2 or mode == 3 or mode == 4 or mode == 6) then courseplay:debug(('%s: getHighestToolTurnDiameter(%s)'):format(nameNum(vehicle), vehicle.name), courseplay.DBG_IMPLEMENTS); local toolTurnDiameter = AIDriverUtil.getTurningRadius(vehicle) * 2 @@ -538,7 +530,7 @@ function courseplay:getIsToolValidForCpMode(object, mode, callback) end function courseplay:updateFillLevelsAndCapacities(vehicle) - courseplay:setOwnFillLevelsAndCapacities(vehicle,vehicle.cp.mode) + courseplay:setOwnFillLevelsAndCapacities(vehicle) vehicle.cp.totalFillLevel = vehicle.cp.fillLevel; vehicle.cp.totalCapacity = vehicle.cp.capacity; if vehicle.cp.fillLevel ~= nil and vehicle.cp.capacity ~= nil then @@ -548,7 +540,7 @@ function courseplay:updateFillLevelsAndCapacities(vehicle) --print(string.format("vehicle itself(%s): vehicle.cp.totalCapacity:(%s)",tostring(vehicle:getName()),tostring(vehicle.cp.totalCapacity))) if vehicle.cp.workTools ~= nil then for _,tool in pairs(vehicle.cp.workTools) do - local hasMoreFillUnits = courseplay:setOwnFillLevelsAndCapacities(tool,vehicle.cp.mode) + local hasMoreFillUnits = courseplay:setOwnFillLevelsAndCapacities(tool) if hasMoreFillUnits and tool ~= vehicle then vehicle.cp.totalFillLevel = (vehicle.cp.totalFillLevel or 0) + tool.cp.fillLevel vehicle.cp.totalCapacity = (vehicle.cp.totalCapacity or 0 ) + tool.cp.capacity @@ -561,7 +553,7 @@ function courseplay:updateFillLevelsAndCapacities(vehicle) --print(string.format("End of function: vehicle.cp.totalFillLevel:(%s)",tostring(vehicle.cp.totalFillLevel))) end -function courseplay:setOwnFillLevelsAndCapacities(workTool,mode) +function courseplay:setOwnFillLevelsAndCapacities(workTool) local fillLevel, capacity = 0,0 local fillLevelPercent = 0; local fillType = 0; diff --git a/translations/translation_de.xml b/translations/translation_de.xml index cdea7178c..9a4e98a8c 100644 --- a/translations/translation_de.xml +++ b/translations/translation_de.xml @@ -279,7 +279,7 @@ - +