From d178134a00fc77e4aa9565d93f4e8c43160603cc Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 1 Apr 2016 14:19:03 +0100 Subject: [PATCH] Allow AI to drop mines. --- src/battle/ai.c | 23 ++++++++++++++++++++++- src/battle/ai.h | 1 + src/defs.h | 1 + src/system/lookup.c | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/battle/ai.c b/src/battle/ai.c index 329232e..5416d84 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -52,9 +52,15 @@ static void moveToLeader(void); static void wander(void); static void doWander(void); static int selectWeaponForTarget(Entity *e); +static void deployMine(void); void doAI(void) { + if (self->aiFlags & AIF_DROPS_MINES) + { + deployMine(); + } + if ((self->aiFlags & (AIF_AVOIDS_COMBAT | AIF_EVADE)) && nearEnemies()) { return; @@ -618,6 +624,21 @@ static int nearEnemies(void) return 0; } +static void deployMine(void) +{ + Entity *mine; + + if (!self->reload) + { + mine = spawnMine(); + mine->x = self->x; + mine->y = self->y; + mine->side = self->side; + + self->reload = FPS + (FPS * (rand() % 5)); + } +} + static int nearMines(void) { int i, numMines; @@ -631,7 +652,7 @@ static int nearMines(void) for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { - if (e->type == ET_MINE && getDistance(e->x, e->y, self->x, self->y) < 500) + if (e->side != self->side && e->type == ET_MINE && getDistance(e->x, e->y, self->x, self->y) < 500) { self->targetLocation.x += e->x; self->targetLocation.y += e->y; diff --git a/src/battle/ai.h b/src/battle/ai.h index 9038b97..628088b 100644 --- a/src/battle/ai.h +++ b/src/battle/ai.h @@ -38,6 +38,7 @@ extern void applyFighterBrakes(void); extern void addHudMessage(SDL_Color c, char *format, ...); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern char *getTranslatedString(char *string); +extern Entity *spawnMine(void); extern Battle battle; extern Colors colors; diff --git a/src/defs.h b/src/defs.h index 605874b..cc7d658 100644 --- a/src/defs.h +++ b/src/defs.h @@ -118,6 +118,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define AIF_WANDERS (2 << 14) #define AIF_COVERS_RETREAT (2 << 15) #define AIF_TARGET_FOCUS (2 << 16) +#define AIF_DROPS_MINES (2 << 17) /* player abilities */ #define BOOST_RECHARGE_TIME (FPS * 7) diff --git a/src/system/lookup.c b/src/system/lookup.c index 0bf0e78..964129d 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -81,6 +81,7 @@ void initLookups(void) addLookup("AIF_WANDERS", AIF_WANDERS); addLookup("AIF_COVERS_RETREAT", AIF_COVERS_RETREAT); addLookup("AIF_TARGET_FOCUS", AIF_TARGET_FOCUS); + addLookup("AIF_DROPS_MINES", AIF_DROPS_MINES); addLookup("DT_ANY", DT_ANY); addLookup("DT_NO_SPIN", DT_NO_SPIN);