Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 468d8cc

Browse files
authored
Merge pull request #7331 from Courseplay/DriverModeSetting
Diff changes
2 parents 46d4e0e + dc692d3 commit 468d8cc

17 files changed

+266
-213
lines changed

AIDriver.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ function AIDriver:tipIntoBGASiloTipTrigger(dt)
13291329
local totalTipDuration = ((tipper.cp.fillLevel / dischargeNode.emptySpeed )/ 1000) + 2 --adding 2 sec for the time between setting tipstate and start of real unloading
13301330
local meterPrSeconds = totalLength / totalTipDuration;
13311331
self.unloadSpeed = meterPrSeconds*3.6
1332-
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))
1332+
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.settings.driverMode:get()))
13331333
courseplay.debugVehicle(courseplay.DBG_LOAD_UNLOAD,self.vehicle,'emptySpeed: %sl/sek; fillLevel: %0.1fl',tostring(dischargeNode.emptySpeed*1000),tipper.cp.fillLevel)
13341334
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)
13351335
end
@@ -1736,10 +1736,6 @@ function AIDriver:onDraw()
17361736
PathfinderUtil.showNodes(self.pathfinder)
17371737
end
17381738
end
1739-
--TODO: do we want to continue using this setter/getter for driveUnloadNow??
1740-
function AIDriver:setDriveUnloadNow(driveUnloadNow)
1741-
courseplay:setDriveUnloadNow(self.vehicle, driveUnloadNow or false)
1742-
end
17431739

17441740
function AIDriver:setDriveNow()
17451741
if self:isWaitingAtWaitPoint() then
@@ -1748,9 +1744,6 @@ function AIDriver:setDriveNow()
17481744
self.triggerHandler:onDriveNow()
17491745
end
17501746

1751-
function AIDriver:getDriveUnloadNow()
1752-
return self.settings.driveUnloadNow:get()
1753-
end
17541747

17551748
function AIDriver:refreshHUD()
17561749
courseplay.hud:setReloadPageOrder(self.vehicle, self.vehicle.cp.hud.currentPage, true);

ActionEventsLoader.lua

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,11 @@ function ActionEventCallbacks.actionEventOpenCloseHud(vehicle, actionName, input
365365
end
366366

367367
function ActionEventCallbacks.actionEventNextDriverMode(vehicle, actionName, inputValue, callbackState, isAnalog)
368-
local newMode = SettingsUtil.getNextCpMode(vehicle)
369-
if newMode ~= vehicle.cp.mode then
370-
vehicle:setCourseplayFunc('setCpMode', newMode);
371-
end
368+
vehicle.cp.settings.driverMode:setNext()
372369
end
373370

374371
function ActionEventCallbacks.actionEventPreviousDriverMode(vehicle, actionName, inputValue, callbackState, isAnalog)
375-
local newMode = SettingsUtil.getPrevCpMode(vehicle)
376-
if newMode ~= vehicle.cp.mode then
377-
vehicle:setCourseplayFunc('setCpMode', newMode);
378-
end
372+
vehicle.cp.settings.driverMode:setPrevious()
379373
end
380374

381375
function ActionEventCallbacks.actionEventNextHudPage(vehicle, actionName, inputValue, callbackState, isAnalog)

CombineUnloadAIDriver.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ function CombineUnloadAIDriver:start(startingPoint)
171171

172172
self.unloadCourse = Course(self.vehicle, self.vehicle.Waypoints)
173173
self.ppc:setNormalLookaheadDistance()
174-
174+
self:setDriveUnloadNow(false)
175+
175176
if startingPoint:is(StartingPointSetting.START_WITH_UNLOAD) then
176177
if CpManager.isDeveloper then
177178
-- automatically select closest combine
@@ -180,7 +181,6 @@ function CombineUnloadAIDriver:start(startingPoint)
180181
self:info('Start unloading, waiting for a combine to call')
181182
self:setNewState(self.states.ON_FIELD)
182183
self:disableCollisionDetection()
183-
self:setDriveUnloadNow(false)
184184
self:startWaitingForCombine()
185185
else
186186
-- 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()
895895
return self:getFillLevelPercent() > self:getDriveOnThreshold()
896896
end
897897

898+
function CombineUnloadAIDriver:getDriveUnloadNow()
899+
return self.settings.driveUnloadNow:get()
900+
end
901+
902+
function CombineUnloadAIDriver:setDriveUnloadNow(driveUnloadNow)
903+
self.settings.driveUnloadNow:set(driveUnloadNow)
904+
self:refreshHUD()
905+
end
906+
898907
function CombineUnloadAIDriver:getCombinesFillLevelPercent()
899908
return g_combineUnloadManager:getCombinesFillLevelPercent(self.combineToUnload)
900909
end

CombineUnloadManager.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ function CombineUnloadManager:addUnloaderToCombine(unloader,combine,noEventSend)
149149
if not noEventSend then
150150
UnloaderEvents:sendAddUnloaderToCombine(unloader,combine)
151151
end
152+
combine.cp.driver:refreshHUD()
152153
else
153154
self:debug('%s is already assigned to combine %s as number %d', nameNum(unloader), nameNum(combine), #self.combines[combine].unloaders)
154155
end
@@ -194,9 +195,10 @@ function CombineUnloadManager:giveMeACombineToUnload(unloader)
194195
self:debug('Combine with most fill level is %s', nameNum(combine))
195196
local bestUnloader
196197
if combine ~= nil and combine.cp.driver:getFieldworkCourse() then
197-
if combine.cp.settings.combineWantsCourseplayer:is(true) then
198+
if combine.cp.settings.requestUnloader:is(true) then
198199
self:addUnloaderToCombine(unloader,combine)
199-
combine.cp.settings.combineWantsCourseplayer:set(false)
200+
combine.cp.settings.requestUnloader:set(false)
201+
combine.cp.driver:refreshHUD()
200202
return combine
201203
end
202204
local num = self:getUnloadersNumber(unloader, combine)
@@ -260,7 +262,7 @@ function CombineUnloadManager:getCombineWithMostFillLevel(unloader)
260262
self:debug('For unloader %s: %s (fill level %.1f, ready to unload: %s) has %d unloaders, this unloader is # %d',
261263
nameNum(unloader), nameNum(combine), fillLevelPct, tostring(combineReadyToUnload), numUnloaders, unloaderIndex or -1)
262264
if data and data.isCombine and (numUnloaders == 0 or unloaderIndex == 1) and combineReadyToUnload then
263-
if combine.cp.settings.combineWantsCourseplayer:is(true) then
265+
if combine.cp.settings.requestUnloader:is(true) then
264266
return combine
265267
end
266268
if mostFillLevel < fillLevelPct then

CpManager.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ function CpManager:loadAIDriver()
637637
local result = self:loadFile()
638638
if g_currentMission.controlledVehicle then
639639
-- re-instantiate the AIDriver after loaded
640-
courseplay:setAIDriver(g_currentMission.controlledVehicle, g_currentMission.controlledVehicle.cp.mode)
640+
g_currentMission.controlledVehicle.cp.settings.driverMode:setAIDriver()
641641
g_combineUnloadManager:addNewCombines()
642642
end
643643
return result

FieldworkAIDriver.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ function FieldworkAIDriver:changeToFieldwork()
564564
self.state = self.states.ON_FIELDWORK_COURSE
565565
self.fieldworkState = self.states.WAITING_FOR_LOWER
566566
self:startWork()
567-
self:setDriveUnloadNow(false);
568567
self:refreshHUD();
569568
end
570569

TriggerHandler.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,16 @@ end
429429
--scanning for LoadingTriggers and FillTriggers(checkFillTriggers)
430430
function TriggerHandler:activateLoadingTriggerWhenAvailable()
431431
for key, object in pairs(g_currentMission.activatableObjects) do
432-
if object:getIsActivatable(self.vehicle) then
432+
if object:getIsActivatable(self.vehicle) and self:isObjectALoadingTrigger(object) then
433433
self:activateTriggerForVehicle(object, self.vehicle)
434434
end
435435
end
436436
end
437437

438+
function TriggerHandler:isObjectALoadingTrigger(object)
439+
return object.source and (object.source.getAllFillLevels or object.source.getAllProvidedFillLevels)
440+
end
441+
438442
function TriggerHandler:enableFillTypeLoading()
439443
self.validFillTypeLoading = true
440444
end

base.lua

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ function courseplay:onLoad(savegame)
7272
--- Adds the vehicle to the global info texts handler
7373
g_globalInfoTextHandler:addVehicle(self)
7474

75-
76-
-- CP mode
77-
self.cp.mode = courseplay.MODE_DEFAULT;
7875
--courseplay:setNextPrevModeVars(self);
7976
-- for modes 4 and 6, this the index of the waypoint where the work begins
8077
self.cp.startWork = nil
@@ -286,7 +283,7 @@ function courseplay:onLoad(savegame)
286283

287284
courseplay.signs:updateWaypointSigns(self);
288285

289-
courseplay:setAIDriver(self, self.cp.mode)
286+
self.cp.settings.driverMode:setAIDriver()
290287
end;
291288

292289
function courseplay:onPostLoad(savegame)
@@ -334,7 +331,7 @@ function courseplay:onDraw()
334331
local isDriving = self:getIsCourseplayDriving();
335332

336333
--WORKWIDTH DISPLAY
337-
if self.cp.mode ~= 7 and self.cp.timers.showWorkWidth and self.cp.timers.showWorkWidth > 0 then
334+
if self.cp.settings.driverMode:get() ~= courseplay.MODE_BALE_COLLECTOR and self.cp.timers.showWorkWidth and self.cp.timers.showWorkWidth > 0 then
338335
if courseplay:timerIsThrough(self, 'showWorkWidth') then -- stop showing, reset timer
339336
courseplay:resetCustomTimer(self, 'showWorkWidth');
340337
else -- timer running, show
@@ -488,8 +485,7 @@ function courseplay:onUpdate(dt)
488485
--- Reset the current mode, as all implements are now attached.
489486
--- If the vehicle is new, then cp.loadedMode is nil
490487
if g_server then
491-
local mode = self.cp.loadedMode or self.cp.mode
492-
courseplay:setCpMode(self, mode, true)
488+
self.cp.settings.driverMode:postInit()
493489
end
494490
if self.cp.driver then
495491
---Post init function, as not all giants variables are
@@ -777,8 +773,6 @@ function courseplay:onReadStream(streamId, connection)
777773
end
778774

779775
--Make sure every vehicle has same AIDriver as the Server
780-
courseplay:setAIDriver(self, self.cp.mode)
781-
782776

783777
self.cp.driver:onReadStream(streamId)
784778

@@ -942,9 +936,7 @@ function courseplay:loadVehicleCPSettings(xmlFile, key, resetVehicles)
942936
if not resetVehicles and g_server ~= nil then
943937
-- COURSEPLAY
944938
local curKey = key .. '.courseplay.basics';
945-
--courseplay:setCpMode(self, Utils.getNoNil(getXMLInt(xmlFile, curKey .. '#aiMode'), self.cp.mode), true);
946-
--- Save the loaded mode and set it later after all implements are attached.
947-
self.cp.loadedMode = Utils.getNoNil(getXMLInt(xmlFile, curKey .. '#aiMode'), courseplay.MODE_DEFAULT)
939+
948940
local courses = Utils.getNoNil(getXMLString(xmlFile, curKey .. '#courses'), '');
949941
self.cp.loadedCourses = StringUtil.splitString(",", courses);
950942
courseplay:reloadCourses(self, true);
@@ -1002,7 +994,6 @@ function courseplay:saveToXMLFile(xmlFile, key, usedModNames)
1002994

1003995

1004996
--CP basics
1005-
setXMLInt(xmlFile, newKey..".basics #aiMode", self.cp.mode)
1006997
if #self.cp.loadedCourses == 0 and self.cp.currentCourseId ~= 0 then
1007998
-- this is the case when a course has been generated and than saved, it is not in loadedCourses (should probably
1008999
-- fix it there), so make sure it is in the savegame
@@ -1183,6 +1174,17 @@ function courseplay.onStartCpAIDriver(vehicle,helperIndex,noEventSend, startedFa
11831174
else
11841175
spec.currentHelper = g_helperManager:getRandomHelper()
11851176
end
1177+
--- Add new helpers, if we run out of giants helpers available.
1178+
--- TODO: Figure out if this needs tweaks for multiplayer.
1179+
while(spec.currentHelper == nil) do
1180+
--- Default helpers are index 1-10
1181+
local index = math.random(1,10)
1182+
local source = g_helperManager:getHelperByIndex(index)
1183+
local name = "C"..tostring(math.random(1,100))
1184+
1185+
spec.currentHelper = g_helperManager:addHelper(name, name, source.filename)
1186+
end
1187+
11861188
g_helperManager:useHelper(spec.currentHelper)
11871189
---Make sure the farmId is never: 0 == spectator farm id,
11881190
---which could be the case when autodrive starts a CP driver.
@@ -1337,7 +1339,8 @@ function CpMapHotSpot.createMapHotSpot(vehicle,text)
13371339
local rawUvs = courseplay.hud:getModeUvs()
13381340
local uvsSize = courseplay.hud:getIconSpriteSize()
13391341
local imagePath = courseplay.hud:getIconSpritePath()
1340-
local uvs = courseplay.utils:getUvs(rawUvs[vehicle.cp.mode], uvsSize.x,uvsSize.y)
1342+
local mode = vehicle.cp.settings.driverMode:get()
1343+
local uvs = courseplay.utils:getUvs(rawUvs[mode], uvsSize.x,uvsSize.y)
13411344

13421345
local hotspotX, _, hotspotZ = getWorldTranslation(vehicle.rootNode)
13431346
local _, textSize = getNormalizedScreenValues(0, 9)

button.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ end;
9191

9292
function courseplay.button:setSetting(setting)
9393
self.settingCall = setting
94+
95+
--- ugly hack to allow the drive mode button overlays,
96+
--- as the settingCall only gets passed after the button was created
97+
self:setSpecialButtonUVs()
9498
return self;
9599
end;
96100

@@ -108,7 +112,7 @@ function courseplay.button:setSpecialButtonUVs()
108112
local prm = self.parameter;
109113
local txtSizeX, txtSizeY = courseplay.hud.iconSpriteSize.x, courseplay.hud.iconSpriteSize.y;
110114

111-
if fn == 'setCpMode' then
115+
if self.settingCall and self.settingCall == self.vehicle.cp.settings.driverMode then
112116
courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.modeButtonsUVsPx[prm], txtSizeX, txtSizeY);
113117

114118
elseif fn == 'setHudPage' then

courseplay.lua

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ local function setVersionData()
189189
end;
190190

191191
local function setGlobalData()
192-
-- CP MODES, TODO create a setting for cp.mode !
193192
courseplay.MODE_GRAIN_TRANSPORT = 1;
194193
courseplay.MODE_COMBI = 2;
195194
courseplay.MODE_OVERLOADER = 3;
@@ -251,25 +250,24 @@ local function setGlobalData()
251250

252251
courseplay.multiplayerSyncTable = {
253252

254-
[1]={name='self.cp.mode',dataFormat='Int'},
255-
[2]={name='self.cp.turnDiameterAuto',dataFormat='Float'},
256-
[3]={name='self.cp.canDrive',dataFormat='Bool'},
257-
[4]={name='self.cp.drivingDirReverse',dataFormat='Bool'},
258-
[5]={name='self.cp.fieldEdge.customField.isCreated',dataFormat='Bool'},
259-
[6]={name='self.cp.fieldEdge.customField.fieldNum',dataFormat='Int'},
260-
[7]={name='self.cp.fieldEdge.customField.selectedFieldNumExists',dataFormat='Bool'},
261-
[8]={name='self.cp.fieldEdge.selectedField.fieldNum',dataFormat='Int'},
262-
[9]={name='self.cp.isDriving',dataFormat='Bool'},
263-
[10]={name='self.cp.hud.openWithMouse',dataFormat='Bool'},
264-
[11]={name='self.cp.workWidth',dataFormat='Float'},
265-
[12]={name='self.cp.turnDiameterAutoMode',dataFormat='Bool'},
266-
[13]={name='self.cp.turnDiameter',dataFormat='Float'},
267-
[14]={name='self.cp.coursePlayerNum',dataFormat='Int'}, --??
268-
[15]={name='self.cp.laneOffset',dataFormat='Float'},
269-
[16]={name='self.cp.hud.currentPage',dataFormat='Int'},
270-
[17]={name='self.cp.waypointIndex',dataFormat='Int'},
271-
[18]={name='self.cp.isRecording',dataFormat='Bool'},
272-
[19]={name='self.cp.recordingIsPaused',dataFormat='Bool'},
253+
[1]={name='self.cp.turnDiameterAuto',dataFormat='Float'},
254+
[2]={name='self.cp.canDrive',dataFormat='Bool'},
255+
[3]={name='self.cp.drivingDirReverse',dataFormat='Bool'},
256+
[4]={name='self.cp.fieldEdge.customField.isCreated',dataFormat='Bool'},
257+
[5]={name='self.cp.fieldEdge.customField.fieldNum',dataFormat='Int'},
258+
[6]={name='self.cp.fieldEdge.customField.selectedFieldNumExists',dataFormat='Bool'},
259+
[7]={name='self.cp.fieldEdge.selectedField.fieldNum',dataFormat='Int'},
260+
[8]={name='self.cp.isDriving',dataFormat='Bool'},
261+
[9]={name='self.cp.hud.openWithMouse',dataFormat='Bool'},
262+
[10]={name='self.cp.workWidth',dataFormat='Float'},
263+
[11]={name='self.cp.turnDiameterAutoMode',dataFormat='Bool'},
264+
[12]={name='self.cp.turnDiameter',dataFormat='Float'},
265+
[13]={name='self.cp.coursePlayerNum',dataFormat='Int'}, --??
266+
[14]={name='self.cp.laneOffset',dataFormat='Float'},
267+
[15]={name='self.cp.hud.currentPage',dataFormat='Int'},
268+
[16]={name='self.cp.waypointIndex',dataFormat='Int'},
269+
[17]={name='self.cp.isRecording',dataFormat='Bool'},
270+
[18]={name='self.cp.recordingIsPaused',dataFormat='Bool'},
273271
}
274272

275273
courseplay.globalSettings = SettingsContainer.createGlobalSettings()

0 commit comments

Comments
 (0)