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: {