Skip to content

Commit 38662e5

Browse files
committed
Fix targetAttackWeight() selecting targets that can't be hit
Deduct target weight of objects if line of fire is obstructed by terrain.
1 parent a60772d commit 38662e5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/ai.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "projectile.h"
3737
#include "objmem.h"
3838
#include "order.h"
39+
#include "visibility.h"
3940

4041
/* Weights used for target selection code,
4142
* target distance is used as 'common currency'
@@ -48,6 +49,7 @@
4849
#define WEIGHT_HEALTH_STRUCT (WEIGHT_DIST_TILE * 7)
4950

5051
#define WEIGHT_NOT_VISIBLE_F 10 //We really don't like objects we can't see
52+
#define WEIGHT_NOT_LOS_VISIBLE_F 4
5153

5254
#define WEIGHT_SERVICE_DROIDS (WEIGHT_DIST_TILE_DROID * 5) //We don't want them to be repairing droids or structures while we are after them
5355
#define WEIGHT_WEAPON_DROIDS (WEIGHT_DIST_TILE_DROID * 4) //We prefer to go after anything that has a gun and can hurt us
@@ -487,6 +489,11 @@ static SDWORD targetAttackWeight(BASE_OBJECT *psTarget, BASE_OBJECT *psAttacker,
487489
return 1;
488490
}
489491

492+
if (bDirect && !lineOfFire(psAttacker, psTarget, weapon_slot, false))
493+
{
494+
attackWeight /= WEIGHT_NOT_LOS_VISIBLE_F; // Prefer objects not obstructed by terrain
495+
}
496+
490497
/* We prefer objects we can see and can attack immediately */
491498
if (!visibleObject((BASE_OBJECT *)psAttacker, psTarget, true))
492499
{

0 commit comments

Comments
 (0)