Skip to content

Commit

Permalink
Out of map orders leniency (#1769)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
saurtron authored Nov 24, 2024
1 parent 053b44e commit 2203a5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 10 additions & 4 deletions rts/Game/UI/GuiHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 5 additions & 9 deletions rts/Sim/Units/CommandAI/CommandAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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: {
Expand Down

0 comments on commit 2203a5d

Please sign in to comment.