Skip to content
Permalink
Browse files

[AI] Read enemy weapons in los (#480)

lgtm
  • Loading branch information...
rlcevg authored and rtri committed Nov 2, 2019
1 parent 1add37c commit 1153be931efad9fa4c390603ee33c7cc7784b01b
Showing with 9 additions and 4 deletions.
  1. +9 −4 rts/ExternalAI/SSkirmishAICallbackImpl.cpp
@@ -113,8 +113,13 @@ static const CUnit* getUnit(int unitId) {
return (unitHandler.GetUnit(unitId));
}

static bool isAlliedUnit(int skirmishAIId, const CUnit* unit) {
return teamHandler.AlliedTeams(unit->team, AI_TEAM_IDS[skirmishAIId]);
static bool isUnitInLos(int skirmishAIId, const CUnit* unit) {
const int teamId = AI_TEAM_IDS[skirmishAIId];
if (teamHandler.AlliedTeams(unit->team, teamId))
return true;

const int allyID = teamHandler.AllyTeam(teamId);
return (unit->losStatus[allyID] & LOS_INLOS);
}

static int unitModParamLosMask(int skirmishAIId, const CUnit* unit) {
@@ -3877,7 +3882,7 @@ EXPORT(int) skirmishAiCallback_Unit_getLastUserOrderFrame(int skirmishAIId, int
EXPORT(int) skirmishAiCallback_Unit_getWeapons(int skirmishAIId, int unitId) {
const CUnit* unit = getUnit(unitId);

if (unit != nullptr && (isAlliedUnit(skirmishAIId, unit) || skirmishAiCallback_Cheats_isEnabled(skirmishAIId)))
if (unit != nullptr && (skirmishAiCallback_Cheats_isEnabled(skirmishAIId) || isUnitInLos(skirmishAIId, unit)))
return unit->weapons.size();

return 0;
@@ -3889,7 +3894,7 @@ EXPORT(int) skirmishAiCallback_Unit_getWeapon(int skirmishAIId, int unitId, int
if (unit == nullptr || ((size_t)weaponMountId >= unit->weapons.size()))
return -1;

if (isAlliedUnit(skirmishAIId, unit) || skirmishAiCallback_Cheats_isEnabled(skirmishAIId))
if (skirmishAiCallback_Cheats_isEnabled(skirmishAIId) || isUnitInLos(skirmishAIId, unit))
return weaponMountId;

return -1;

0 comments on commit 1153be9

Please sign in to comment.
You can’t perform that action at this time.