Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Dec 28, 2023
1 parent fc9c915 commit ea0bc6a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 42 deletions.
32 changes: 1 addition & 31 deletions scripts/ai/jobs/CpAIJobStreet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,6 @@ function CpAIJobStreet:setupTasks(isServer)
self.driveToAndLoadTask = CpAITaskDriveLoading(isServer, self)
end

function CpAIJobStreet:getLoadAndUnloadStartCourse()
local ADGraphManager = FS22_AutoDrive.ADGraphManager
if not ADGraphManager then
return
end
local startId, targetId = self.cpJobParameters:getClosestRelevantTargetPoint()
if true then --- Start at load task
targetId = self.cpJobParameters.loadTargetPoint:getValue()
else --- Start at unload task
targetId = self.cpJobParameters.unloadTargetPoint:getValue()
end
if not startId or startId < 1 or not targetId or targetId < 1 then
return
end
local waypoints = ADGraphManager:pathFromTo(startId, targetId)
if waypoints ~= nil and #waypoints > 1 then
self:debug("Drive to course generation was successfully with %d waypoints!", #waypoints)
local course = Course(self:getVehicle(), waypoints, true)
course:addReverseForAutoDriveCourse()
return course
end
end

function CpAIJobStreet:onPreStart()
self:removeTask(self.driveToAndUnloadTask)
self:removeTask(self.driveToAndLoadTask)
Expand All @@ -57,10 +34,6 @@ function CpAIJobStreet:onPreStart()
self:addTask(self.driveToAndUnloadTask)
end
self.runCounter = 0
if not self.cpJobParameters:isLoadTargetPointDisabled() then
--- Drive to course only gets added now, as this one depends on the fill level
self.driveToTargetPointTask:setCourse(self:getLoadAndUnloadStartCourse())
end
for _, setting in pairs(self.cpJobParameters:getFillTypeSelectionSettings()) do
setting:applyCounter(true)
end
Expand Down Expand Up @@ -88,10 +61,7 @@ function CpAIJobStreet:getCanStartJob()
end

function CpAIJobStreet:isDriveToTaskNeeded()
if self.cpJobParameters:isUnloadTargetPointDisabled() then
return true
end
return not self.cpJobParameters:isLoadTargetPointDisabled()
return self.cpJobParameters:isUnloadTargetPointDisabled()
end

---@param vehicle table
Expand Down
8 changes: 0 additions & 8 deletions scripts/ai/jobs/CpJobParameters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,6 @@ function CpBaleFinderJobParameters:isBaleWrapSettingVisible()
return self:hasBaleLoader()
end

function CpBaleFinderJobParameters:isUnloadTargetPointDisabled()
return self:isGiantsForStreetActive() or not self:hasBaleLoader()
end

function CpBaleFinderJobParameters:isBaleWrapSettingVisible()
return self:hasBaleLoader()
end

--- AI parameters for the bale finder job.
---@class CpCombineUnloaderJobParameters : CpJobParameters
---@field unloadWith AIParameterSettingList
Expand Down
6 changes: 5 additions & 1 deletion scripts/ai/parameters/CpAIParameterFillTypeSetting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function CpAIParameterFillTypeSetting:__tostring()
end

function CpAIParameterFillTypeSetting:getIsValid()
return self.fillType:getValue() > 0 and self.currentCounterValue <= self.counter:getValue()
return self.fillType:getValue() > 0
end

function CpAIParameterFillTypeSetting:applyCounter(reset)
Expand All @@ -146,3 +146,7 @@ end
function CpAIParameterFillTypeSetting:getCounter()
return self.currentCounterValue
end

function CpAIParameterFillTypeSetting:getIsCounterValid()
return self.currentCounterValue <= self.counter:getValue()
end
10 changes: 9 additions & 1 deletion scripts/ai/strategies/AIDriveStrategyDriveLoading.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function AIDriveStrategyDriveLoading:initializeImplementControllers(vehicle)
end

function AIDriveStrategyDriveLoading:isCoverOpeningAllowed()
return self.course:isCloseToLastWaypoint(self.vehicleLength * 1.5)
return self.driveToCourse:isCloseToLastWaypoint(self.vehicleLength * 1.5)
end

function AIDriveStrategyDriveLoading:onCourseEndReached()
Expand Down Expand Up @@ -189,3 +189,11 @@ function AIDriveStrategyDriveLoading:updateLoading()
end
end

local function EnableLoadingAtLoadSilos(trigger, superFunc, fillableObject)
if fillableObject and fillableObject.rootVehicle:getIsAIActive() then
return true
end
superFunc(trigger, fillableObject)
end

LoadTrigger.getAllowsActivation = Utils.overwrittenFunction(LoadTrigger.getAllowsActivation, EnableLoadingAtLoadSilos)
1 change: 0 additions & 1 deletion scripts/ai/strategies/AIDriveStrategyDriveToStartPoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ function AIDriveStrategyDriveToStartPoint:getDriveData(dt, vX, vY, vZ)
end

self:checkProximitySensors(moveForwards)

return gx, gz, moveForwards, self.maxSpeed, 100
end

Expand Down

0 comments on commit ea0bc6a

Please sign in to comment.