Skip to content

Commit

Permalink
Merge pull request #2834 from Courseplay/openPipeForRegisteredUnloader
Browse files Browse the repository at this point in the history
Open pipe for registered unloader
  • Loading branch information
Tensuko authored Oct 14, 2023
2 parents 57aa6fd + 0ba0d23 commit ce61313
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 @@ -1410,14 +1410,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 @@ -2025,4 +2039,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 ce61313

Please sign in to comment.