Skip to content

Commit

Permalink
Also checks distance for the unload target silo
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Sep 22, 2023
1 parent 031fc0c commit eaf8a22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions config/MasterTranslations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
<Text language="de"><![CDATA[Keinen Abladepunkt gefunden.]]></Text>
<Text language="en"><![CDATA[No unloading point found.]]></Text>
</Translation>
<Translation name="CP_error_trailer_unload_to_far_away_from_silo">
<Text language="de"><![CDATA[Anhänger Abladepunkt ist zu weit vom Silo entfernt.]]></Text>
<Text language="en"><![CDATA[Trailer unloading point is to far away from the silo.]]></Text>
<Translation name="CP_error_unload_target_to_far_away_from_silo">
<Text language="de"><![CDATA[Ausgewählter Abladepunkt ist zu weit vom Silo entfernt.]]></Text>
<Text language="en"><![CDATA[Chosen unloading point is to far away from the silo.]]></Text>
</Translation>
</Category>
<Category name="AI job parameters">
Expand Down
20 changes: 15 additions & 5 deletions scripts/ai/jobs/CpAIJobSiloLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CpAIJobSiloLoader.TRAILER_SEARCH_LENGTH = 25
--- Trailer unload marker width, -TRAILER_SEARCH_WIDTH/2 to TRAILER_SEARCH_WIDTH/2
CpAIJobSiloLoader.TRAILER_SEARCH_WIDTH = 20
--- Max distance the trailer unload spot can be from the silo/heap.
CpAIJobSiloLoader.MAX_TRAILER_DISTANCE_FROM_SILO = 100
CpAIJobSiloLoader.MAX_UNLOAD_TARGET_DISTANCE_FROM_SILO = 100

function CpAIJobSiloLoader.new(isServer, customMt)
local self = CpAIJob.new(isServer, customMt or AIJobCombineUnloaderCp_mt)
Expand Down Expand Up @@ -146,7 +146,7 @@ function CpAIJobSiloLoader:validate(farmId)
if not AIUtil.hasChildVehicleWithSpecialization(vehicle, ConveyorBelt) then
if self.cpJobParameters.unloadAt:getValue() == CpSiloLoaderJobParameters.UNLOAD_TRIGGER then
--- Validates the unload trigger setup
local found, unloadTrigger, unloadStation = self:getUnloadTriggerAt(self.cpJobParameters.unloadPosition)
local found, unloadTrigger, unloadStation, validDistanceToSilo = self:getUnloadTriggerAt(self.cpJobParameters.unloadPosition)
if found then
self.unloadStation = unloadStation
self.unloadTrigger = unloadTrigger
Expand All @@ -168,6 +168,9 @@ function CpAIJobSiloLoader:validate(farmId)
if unloadPosition.x == nil or unloadPosition.angle == nil then
return false, g_i18n:getText("CP_error_no_unload_trigger_found")
end
if not validDistanceToSilo then
return false, g_i18n:getText("CP_error_unload_target_to_far_away_from_silo")
end
else
local found, area, validDistanceToSilo = CpAIJobSiloLoader.getTrailerUnloadArea(
self.cpJobParameters.unloadPosition, self.bunkerSilo or self.heap)
Expand All @@ -176,7 +179,7 @@ function CpAIJobSiloLoader:validate(farmId)
self.trailerAreaPlot:setArea(area)
end
if not validDistanceToSilo then
return false, g_i18n:getText("CP_error_trailer_unload_to_far_away_from_silo")
return false, g_i18n:getText("CP_error_unload_target_to_far_away_from_silo")
end
end
end
Expand Down Expand Up @@ -224,8 +227,8 @@ function CpAIJobSiloLoader.getTrailerUnloadArea(position, silo)
if silo then
local fx, fz = silo:getFrontCenter()
local bx, bz = silo:getBackCenter()
if MathUtil.vector2Length(x-fx, z-fz) < CpAIJobSiloLoader.MAX_TRAILER_DISTANCE_FROM_SILO and
MathUtil.vector2Length(x-bx, z-bz) < CpAIJobSiloLoader.MAX_TRAILER_DISTANCE_FROM_SILO then
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
return true, area, false
end
end
Expand Down Expand Up @@ -260,6 +263,7 @@ end
---@return boolean found?
---@return table|nil Trigger
---@return table|nil unloadStation
---@return boolean|nil distance is close enough to the bunker silo/heap
function CpAIJobSiloLoader:getUnloadTriggerAt(unloadPosition)
local x, z = unloadPosition:getPosition()
local dirX, dirZ = unloadPosition:getDirection()
Expand Down Expand Up @@ -288,6 +292,12 @@ function CpAIJobSiloLoader:getUnloadTriggerAt(unloadPosition)
end
end
end
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
return found, trigger, station, true
end
return found, trigger, station
end

Expand Down

0 comments on commit eaf8a22

Please sign in to comment.