Tell AI to avoid mines.

This commit is contained in:
Steve 2016-04-01 11:40:09 +01:00
parent e8f70072d5
commit 58fb3e911b
1 changed files with 45 additions and 0 deletions

View File

@ -37,6 +37,7 @@ static int nearJumpgate(void);
static void moveToJumpgate(void);
static int nearEnemies(void);
static int nearItems(void);
static int nearMines(void);
static void moveToItem(void);
static int nearTowableCraft(void);
static void moveToTowableCraft(void);
@ -64,6 +65,11 @@ void doAI(void)
return;
}
if (nearMines())
{
return;
}
if ((self->aiFlags & AIF_GOAL_JUMPGATE) && nearJumpgate())
{
/* near jumpgate, but you might decide to continue to fight, anyway */
@ -612,6 +618,45 @@ static int nearEnemies(void)
return 0;
}
static int nearMines(void)
{
int i, numMines;
Entity *e, **candidates;
candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self);
self->targetLocation.x = self->targetLocation.y = 0;
numMines = 0;
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)
{
self->targetLocation.x += e->x;
self->targetLocation.y += e->y;
numMines++;
}
}
if (numMines)
{
self->targetLocation.x /= numMines;
self->targetLocation.y /= numMines;
/* dodge slightly */
self->targetLocation.x += (rand() % 100 - rand() % 100);
self->targetLocation.y += (rand() % 100 - rand() % 100);
self->action = fleeEnemies;
self->aiActionTime = FPS * 2;
return 1;
}
return 0;
}
static void fleeEnemies(void)
{
int wantedAngle = 180 + getAngle(self->x, self->y, self->targetLocation.x, self->targetLocation.y);