Allow AI to drop mines.

This commit is contained in:
Steve 2016-04-01 14:19:03 +01:00
parent 58fb3e911b
commit d178134a00
4 changed files with 25 additions and 1 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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);