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

Commit

Permalink
Div changes
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
schwiti6190 committed Jul 18, 2021
1 parent dcec463 commit a89e3bd
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 212 deletions.
9 changes: 1 addition & 8 deletions AIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions ActionEventsLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions CombineUnloadAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions CombineUnloadManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CpManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion FieldworkAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion TriggerHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 17 additions & 14 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
38 changes: 18 additions & 20 deletions courseplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit a89e3bd

Please sign in to comment.