Skip to content

Commit

Permalink
Do not open pipe for cp unloader standing arround
Browse files Browse the repository at this point in the history
When a courseplay unloader is standing arround, do not open the pipe for it.
  • Loading branch information
Tensuko committed Oct 6, 2023
1 parent 12623d2 commit 0ba0d23
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
20 changes: 17 additions & 3 deletions scripts/ai/AIDriveStrategyCombineCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1413,14 +1413,28 @@ function AIDriveStrategyCombineCourse:handlePipe(dt)
end

function AIDriveStrategyCombineCourse:handleCombinePipe(dt)

if self.pipeController:isFillableTrailerUnderPipe() or self:isAutoDriveWaitingForPipe() then
if self:isAGoodTrailerInRange() or self:isAutoDriveWaitingForPipe() then
self.pipeController:openPipe()
else
self.pipeController:closePipe(true)
end
end

function AIDriveStrategyCombineCourse:isAGoodTrailerInRange()
local _, trailer = self.pipeController:isFillableTrailerUnderPipe()
local unloaderVehicle = trailer and trailer:getRootVehicle()

if unloaderVehicle == nil then
return false
end

if AIDriveStrategyUnloadCombine.isActiveCpCombineUnloader(unloaderVehicle) then
return unloaderVehicle:getCpDriveStrategy():getCombineToUnload() == self.vehicle
else
return true
end
end

--- Not exactly sure what this does, but without this the chopper just won't move.
--- Copied from AIDriveStrategyCombine:update()
function AIDriveStrategyCombineCourse:updateChopperFillType()
Expand Down Expand Up @@ -2045,4 +2059,4 @@ function AIDriveStrategyCombineCourse:updateInfoTexts()
self:clearInfoText(infoText)
end
end
end
end
3 changes: 3 additions & 0 deletions scripts/ai/AIDriveStrategyUnloadCombine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,9 @@ function AIDriveStrategyUnloadCombine:isPathFound(path, goalNodeInvalid, goalDes
end
end
end
function AIDriveStrategyUnloadCombine:getCombineToUnload()
return self.combineToUnload
end

function AIDriveStrategyUnloadCombine:getCombineRootNode()
-- for attached harvesters this gets the root node of the harvester as that is our reference point to the
Expand Down
5 changes: 3 additions & 2 deletions scripts/ai/controllers/PipeController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ function PipeController:getFillType()
return nil
end


---@return boolean true if there is a fillable trailer under the pipe
---@return table|nil the trailer vehicle, if there is one
function PipeController:isFillableTrailerUnderPipe()
for trailer, value in pairs(self.pipeSpec.objectsInTriggers) do
if value > 0 then
if FillLevelManager.canLoadTrailer(trailer, self:getFillType()) then
return true
return true, trailer
end
end
end
Expand Down

0 comments on commit 0ba0d23

Please sign in to comment.