Skip to content

Commit

Permalink
Added debug for distance check
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Sep 23, 2023
1 parent 3f4763c commit 6573f6f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 11 additions & 0 deletions scripts/ai/jobs/CpAIJob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function CpAIJob.new(isServer, customMt)

self:setupJobParameters()

self.debugChannel = CpDebug.DBG_FIELDWORK
return self
end

Expand Down Expand Up @@ -347,6 +348,16 @@ function CpAIJob:getCanGenerateFieldWorkCourse()
return false
end

function CpAIJob:debug(...)
local vehicle = self:getVehicle()
if vehicle then
CpUtil.debugVehicle(self.debugChannel, vehicle, ...)
else
CpUtil.debugFormat(self.debugChannel, ...)
end
end


--- Ugly hack to fix a mp problem from giants, where the job class can not be found.
function CpAIJob.getJobTypeIndex(aiJobTypeManager, superFunc, job)
local ret = superFunc(aiJobTypeManager, job)
Expand Down
18 changes: 14 additions & 4 deletions scripts/ai/jobs/CpAIJobSiloLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function CpAIJobSiloLoader.new(isServer, customMt)
self.heapNode = CpUtil.createNode("siloNode", 0, 0, 0, nil)
self.heap = nil
self.hasValidPosition = false
self.debugChannel = CpDebug.DBG_SILO
return self
end

Expand Down Expand Up @@ -230,8 +231,12 @@ function CpAIJobSiloLoader.getTrailerUnloadArea(position, silo)
--- to the trailer unload area marker is which the max limit.
local fx, fz = silo:getFrontCenter()
local bx, bz = silo:getBackCenter()
if MathUtil.vector2Length(x-fx, z-fz) > CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO and
MathUtil.vector2Length(x-bx, z-bz) > CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO then
local dist1 = MathUtil.vector2Length(x-fx, z-fz)
local dist2 = MathUtil.vector2Length(x-bx, z-bz)
CpUtil.debugFormat(CpDebug.DBG_SILO, "Trailer marker is %.1fm/%.1fm away from the silo",
math.min(dist1, dist2), CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO)
if dist1 > CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO and
dist2 > CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO then
--- Trailer unload area is to far away from the silo
return true, area, false
end
Expand Down Expand Up @@ -303,8 +308,13 @@ function CpAIJobSiloLoader:getUnloadTriggerAt(unloadPosition)
local fx, fz = silo:getFrontCenter()
local bx, bz = silo:getBackCenter()
--- Checks the distance of the unloading station to the bunker silo/heap
if MathUtil.vector2Length(x-fx, z-fz) < CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO or
MathUtil.vector2Length(x-bx, z-bz) < CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO then
local dist1 = MathUtil.vector2Length(x-fx, z-fz)
local dist2 = MathUtil.vector2Length(x-bx, z-bz)
self:debug("Unloading trigger: %s is %.1fm/%.1fm away from the silo",
CpUtil.getName(station), math.min(dist1, dist2),
self.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO)
if dist1 < CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO or
dist2 < CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO then
--- Unloading point is close enough to the bunker silo.
return found, trigger, station, true
end
Expand Down

0 comments on commit 6573f6f

Please sign in to comment.