From edc6127109c961cbae53daa8f0d4e37bee71c370 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 22 Dec 2015 17:58:37 +0000 Subject: [PATCH] Fix for AI attacking secondary targets. --- src/battle/ai.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/battle/ai.c b/src/battle/ai.c index 4723d58..80c3ff0 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -272,16 +272,6 @@ static void huntAndAttackTarget(void) 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) { int i; @@ -302,11 +292,8 @@ static void findTarget(void) if (dist < closest) { - if (!self->target || attackSecondaryTarget(e)) - { - self->target = e; - closest = dist; - } + self->target = e; + closest = dist; } } } @@ -316,6 +303,14 @@ static int canAttack(Entity *e) { 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->systemPower > 0)