From 2203a5d1a3274e162ed6bdf735bb8488c77bcba1 Mon Sep 17 00:00:00 2001 From: saurtron Date: Sun, 24 Nov 2024 18:53:26 +0100 Subject: [PATCH] Out of map orders leniency (#1769) * Allow centering area commands out of map. * Allow attacking out of map units. * Allow guarding out of map units when both the actor and guardee are builders. * No need to allow out of map CMD_AREA_ATTACK. * Remove out of map guard restrictions. * Explicitly block out of map ground attack. * Also evaluate attack command with 3 parameters as ground attack. --- rts/Game/UI/GuiHandler.cpp | 14 ++++++++++---- rts/Sim/Units/CommandAI/CommandAI.cpp | 14 +++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/rts/Game/UI/GuiHandler.cpp b/rts/Game/UI/GuiHandler.cpp index 5952320c35..acf36c3a86 100644 --- a/rts/Game/UI/GuiHandler.cpp +++ b/rts/Game/UI/GuiHandler.cpp @@ -2376,8 +2376,11 @@ Command CGuiHandler::GetCommand(int mouseX, int mouseY, int buttonHint, bool pre const float3 camTraceDir = mouse->buttons[button].dir; const float traceDist = camera->GetFarPlaneDist() * 1.4f; - const float innerDist = CGround::LineGroundCol(camTracePos, camTracePos + camTraceDir * traceDist, false); - float outerDist = -1.0f; + float innerDist = CGround::LineGroundCol(camTracePos, camTracePos + camTraceDir * traceDist, false); + float outerDist = -1.0f; + + if (innerDist < 0.0f) // in case area center is out of map + innerDist = CGround::LinePlaneCol(camTracePos, camTraceDir, traceDist, CGround::GetWaterPlaneLevel()); if (innerDist < 0.0f) return defaultRet; @@ -3592,8 +3595,11 @@ void CGuiHandler::DrawMapStuff(bool onMiniMap) const float3 camTraceDir = mouse->buttons[button].dir; const float traceDist = camera->GetFarPlaneDist() * 1.4f; - const float innerDist = CGround::LineGroundCol(camTracePos, camTracePos + camTraceDir * traceDist, false); - float outerDist = -1.0f; + float innerDist = CGround::LineGroundCol(camTracePos, camTracePos + camTraceDir * traceDist, false); + float outerDist = -1.0f; + + if (innerDist < 0.0f) // in case area center is out of map + innerDist = CGround::LinePlaneCol(camTracePos, camTraceDir, traceDist, CGround::GetWaterPlaneLevel()); if (innerDist < 0.0f) break; diff --git a/rts/Sim/Units/CommandAI/CommandAI.cpp b/rts/Sim/Units/CommandAI/CommandAI.cpp index 738c2e3a56..e2cb5709d3 100644 --- a/rts/Sim/Units/CommandAI/CommandAI.cpp +++ b/rts/Sim/Units/CommandAI/CommandAI.cpp @@ -640,7 +640,6 @@ bool CCommandAI::AllowedCommand(const Command& c, bool fromSynced) // TODO check if the command is in the map first, for more commands switch (cmdID) { case CMD_MOVE: - case CMD_ATTACK: case CMD_AREA_ATTACK: case CMD_RECLAIM: case CMD_REPAIR: @@ -701,9 +700,12 @@ bool CCommandAI::AllowedCommand(const Command& c, bool fromSynced) if (attackee == nullptr) return false; - if (!attackee->pos.IsInBounds()) - return false; } else { + const bool isGroundTargeted = (c.GetNumParams() > 3 && c.GetParam(3) == 0) + || c.GetNumParams() == 3; + if (isGroundTargeted && !IsCommandInMap(c)) + return false; // don't allow direct ground attack out of map + AdjustGroundAttackCommand(c, fromSynced, aiOrder); } } break; @@ -717,14 +719,8 @@ bool CCommandAI::AllowedCommand(const Command& c, bool fromSynced) return false; } break; case CMD_GUARD: { - const CUnit* guardee = GetCommandUnit(c, 0); - if (!ud->canGuard) return false; - if (owner && !owner->pos.IsInBounds()) - return false; - if (guardee && !guardee->pos.IsInBounds()) - return false; } break; case CMD_PATROL: {