Skip to content

Commit

Permalink
Avoid useless calls to aiBestNearestTarget()
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Aug 6, 2024
1 parent d4d93fb commit f61584a
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,15 +743,13 @@ void actionUpdateDroid(DROID *psDroid)
if (psDroid->asWeaps[i].nStat > 0
&& psWeapStats->rotate
&& IS_TIME_TO_CHECK_FOR_NEW_TARGET(psDroid)
&& (secondaryGetState(psDroid, DSO_ATTACK_LEVEL) == DSS_ALEV_ALWAYS)
// don't bother doing this costly calculation again if aiUpdateDroid already checked this tick and failed
&& psDroid->lastCheckNearestTargetFailed[i] != gameTime
&& aiBestNearestTarget(psDroid, &psTemp, i) >= 0)
{
if (secondaryGetState(psDroid, DSO_ATTACK_LEVEL) == DSS_ALEV_ALWAYS)
{
psDroid->action = DACTION_ATTACK;
setDroidActionTarget(psDroid, psTemp, i);
}
psDroid->action = DACTION_ATTACK;
setDroidActionTarget(psDroid, psTemp, i);
}
}
}
Expand Down Expand Up @@ -850,13 +848,11 @@ void actionUpdateDroid(DROID *psDroid)
&& psWeapStats->rotate
&& psWeapStats->fireOnMove
&& IS_TIME_TO_CHECK_FOR_NEW_TARGET(psDroid)
&& (secondaryGetState(psDroid, DSO_ATTACK_LEVEL) == DSS_ALEV_ALWAYS)
&& aiBestNearestTarget(psDroid, &psTemp, i) >= 0)
{
if (secondaryGetState(psDroid, DSO_ATTACK_LEVEL) == DSS_ALEV_ALWAYS)
{
psDroid->action = DACTION_MOVEFIRE;
setDroidActionTarget(psDroid, psTemp, i);
}
psDroid->action = DACTION_MOVEFIRE;
setDroidActionTarget(psDroid, psTemp, i);
}
}
}
Expand Down

0 comments on commit f61584a

Please sign in to comment.