From 52691f7be5ef1963f117782f3425834a815c7963 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 29 Mar 2016 22:45:46 +0100 Subject: [PATCH] Enable AI flags to focus on targets. --- src/battle/ai.c | 15 +++++++++++---- src/defs.h | 1 + src/system/lookup.c | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/battle/ai.c b/src/battle/ai.c index 11d5e55..9212c17 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -332,13 +332,15 @@ static int canAttack(Entity *e) { if (e->aiFlags & (AIF_AVOIDS_COMBAT | AIF_EVADE) || e->flags & EF_SECONDARY_TARGET) { - if (rand() % 5) - { - return 0; - } + return !(rand() % 5); } } + if ((self->aiFlags & AIF_TARGET_FOCUS) && (!(e->flags & EF_AI_TARGET))) + { + return 0; + } + return selectWeaponForTarget(e); } @@ -578,6 +580,11 @@ static int nearEnemies(void) { if ((e->flags & EF_TAKES_DAMAGE) && e->side != self->side && !(e->flags & EF_DISABLED)) { + if ((self->aiFlags & AIF_TARGET_FOCUS) && (e->flags & EF_AI_TARGET)) + { + continue; + } + if (getDistance(e->x, e->y, self->x, self->y) < 1000) { self->targetLocation.x += e->x; diff --git a/src/defs.h b/src/defs.h index 1ac1255..3f83cd1 100644 --- a/src/defs.h +++ b/src/defs.h @@ -115,6 +115,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define AIF_EVADE (2 << 13) #define AIF_WANDERS (2 << 14) #define AIF_COVERS_RETREAT (2 << 15) +#define AIF_TARGET_FOCUS (2 << 16) /* player abilities */ #define BOOST_RECHARGE_TIME (FPS * 7) diff --git a/src/system/lookup.c b/src/system/lookup.c index c7e7d36..02bcb85 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -79,6 +79,7 @@ void initLookups(void) addLookup("AIF_MOVES_TO_LEADER", AIF_MOVES_TO_LEADER); addLookup("AIF_WANDERS", AIF_WANDERS); addLookup("AIF_COVERS_RETREAT", AIF_COVERS_RETREAT); + addLookup("AIF_TARGET_FOCUS", AIF_TARGET_FOCUS); addLookup("DT_ANY", DT_ANY); addLookup("DT_NO_SPIN", DT_NO_SPIN);