From 317994133204238c4c1723e5e5df5cc088e656b9 Mon Sep 17 00:00:00 2001
From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com>
Date: Fri, 22 Sep 2023 21:16:32 +0200
Subject: [PATCH] Added error message if the trailer unload is to far away from
the silo
---
config/MasterTranslations.xml | 4 ++++
scripts/ai/jobs/CpAIJobSiloLoader.lua | 24 ++++++++++++++++++++----
scripts/silo/BunkerSiloWrapper.lua | 2 +-
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/config/MasterTranslations.xml b/config/MasterTranslations.xml
index 7a25eeeb1..5ce861949 100644
--- a/config/MasterTranslations.xml
+++ b/config/MasterTranslations.xml
@@ -83,6 +83,10 @@
+
+
+
+
diff --git a/scripts/ai/jobs/CpAIJobSiloLoader.lua b/scripts/ai/jobs/CpAIJobSiloLoader.lua
index 0bfd645b5..4bb40db9a 100644
--- a/scripts/ai/jobs/CpAIJobSiloLoader.lua
+++ b/scripts/ai/jobs/CpAIJobSiloLoader.lua
@@ -14,6 +14,8 @@ local AIJobCombineUnloaderCp_mt = Class(CpAIJobSiloLoader, CpAIJob)
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
function CpAIJobSiloLoader.new(isServer, customMt)
local self = CpAIJob.new(isServer, customMt or AIJobCombineUnloaderCp_mt)
@@ -167,11 +169,15 @@ function CpAIJobSiloLoader:validate(farmId)
return false, g_i18n:getText("CP_error_no_unload_trigger_found")
end
else
- local found, area = CpAIJobSiloLoader.getTrailerUnloadArea(self.cpJobParameters.unloadPosition)
+ local found, area, validDistanceToSilo = CpAIJobSiloLoader.getTrailerUnloadArea(
+ self.cpJobParameters.unloadPosition, self.bunkerSilo or self.heap)
if found then
self.trailerAreaPlot:setVisible(true)
self.trailerAreaPlot:setArea(area)
end
+ if not validDistanceToSilo then
+ return false, g_i18n:getText("CP_error_trailer_unload_to_far_away_from_silo")
+ end
end
end
return isValid, errorMessage
@@ -179,13 +185,15 @@ end
--- Gets the area for search for trailers
---@param position CpAIParameterPositionAngle
+---@param silo CpSilo|nil
---@return boolean found?
---@return table area
-function CpAIJobSiloLoader.getTrailerUnloadArea(position)
+---@return boolean distance to silo is valid
+function CpAIJobSiloLoader.getTrailerUnloadArea(position, silo)
local x, z = position:getPosition()
local dirX, dirZ = position:getDirection()
if x == nil or dirX == nil then
- return false, {}
+ return false, {}, true
end
--- Rotation matrix to rotate Z directions to x directions
local dirX2 = dirX * math.cos(math.pi/2) - dirZ * math.sin(math.pi/2)
@@ -213,7 +221,15 @@ function CpAIJobSiloLoader.getTrailerUnloadArea(position)
z = z + dirZ * CpAIJobSiloLoader.TRAILER_SEARCH_LENGTH/2 + dirZ2 * CpAIJobSiloLoader.TRAILER_SEARCH_WIDTH/2
},
}
- return true, area
+ 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
+ return true, area, false
+ end
+ end
+ return true, area, true
end
--- Gets the bunker silo or heap at the loading position in that order.
diff --git a/scripts/silo/BunkerSiloWrapper.lua b/scripts/silo/BunkerSiloWrapper.lua
index 2ddfe1a4f..c221111a5 100644
--- a/scripts/silo/BunkerSiloWrapper.lua
+++ b/scripts/silo/BunkerSiloWrapper.lua
@@ -124,7 +124,7 @@ end
function CpSilo:getBackCenter()
local length = self:getLength()
local fcx, fcz = self:getFrontCenter()
- return fcx + self.dirXLength * length/2, fcz + self.dirZLength * length/2
+ return fcx + self.dirXLength * length, fcz + self.dirZLength * length
end
--- Is the point directly in the silo area?