Skip to content

Commit

Permalink
Make sure that a droid's weapon can actually damage the target before…
Browse files Browse the repository at this point in the history
… getting orders to pursue the target.

Patch by Kreuvf & vexed

fixes ticket:4134
  • Loading branch information
vexed committed Dec 4, 2013
1 parent cc70e11 commit af746f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/ai.cpp
Expand Up @@ -1166,6 +1166,20 @@ void aiUpdateDroid(DROID *psDroid)
}
}

/* Check if any of our weapons can hit the target... */
bool checkAnyWeaponsTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget)
{
DROID *psDroid = (DROID *) psObject;
for (int i = 0;i < psDroid->numWeaps;i++)
{
if (validTarget(psObject, psTarget, i))
{
return true;
}
}
return false;
}

/* Set of rules which determine whether the weapon associated with the object can fire on the propulsion type of the target. */
bool validTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget, int weapon_slot)
{
Expand Down
3 changes: 2 additions & 1 deletion src/ai.h
Expand Up @@ -80,5 +80,6 @@ bool aiChooseSensorTarget(BASE_OBJECT *psObj, BASE_OBJECT **ppsTarget);
/*set of rules which determine whether the weapon associated with the object
can fire on the propulsion type of the target*/
bool validTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget, int weapon_slot);

// Check if any of the weapons can target the target
bool checkAnyWeaponsTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget);
#endif // __INCLUDED_SRC_AI_H__
2 changes: 1 addition & 1 deletion src/order.cpp
Expand Up @@ -1025,7 +1025,7 @@ void orderUpdateDroid(DROID *psDroid)
psFireTarget = psSpotter->psTarget[0];
}

if (psFireTarget && !psFireTarget->died)
if (psFireTarget && !psFireTarget->died && checkAnyWeaponsTarget(psDroid, psFireTarget))
{
bAttack = false;
if (isVtolDroid(psDroid))
Expand Down

0 comments on commit af746f5

Please sign in to comment.