Fix for AI attacking secondary targets.

This commit is contained in:
Steve 2015-12-22 17:58:37 +00:00
parent 48f08a3fb0
commit edc6127109
1 changed files with 10 additions and 15 deletions

View File

@ -272,16 +272,6 @@ static void huntAndAttackTarget(void)
nextAction(); nextAction();
} }
static int attackSecondaryTarget(Entity *e)
{
if (self->target->aiFlags & (AIF_AVOIDS_COMBAT | AIF_EVADE) || self->target->flags & EF_SECONDARY_TARGET)
{
return rand() % 4 == 0;
}
return 1;
}
static void findTarget(void) static void findTarget(void)
{ {
int i; int i;
@ -301,21 +291,26 @@ static void findTarget(void)
dist = getDistance(self->x, self->y, e->x, e->y); dist = getDistance(self->x, self->y, e->x, e->y);
if (dist < closest) if (dist < closest)
{
if (!self->target || attackSecondaryTarget(e))
{ {
self->target = e; self->target = e;
closest = dist; closest = dist;
} }
} }
} }
}
} }
static int canAttack(Entity *e) static int canAttack(Entity *e)
{ {
self->selectedGunType = self->guns[0].type; self->selectedGunType = self->guns[0].type;
if (e->aiFlags & (AIF_AVOIDS_COMBAT | AIF_EVADE) || e->flags & EF_SECONDARY_TARGET)
{
if (rand() % 10)
{
return 0;
}
}
if (e->flags & EF_MUST_DISABLE) if (e->flags & EF_MUST_DISABLE)
{ {
if (e->systemPower > 0) if (e->systemPower > 0)