Tell AI to avoid mines.
This commit is contained in:
parent
e8f70072d5
commit
58fb3e911b
|
@ -37,6 +37,7 @@ static int nearJumpgate(void);
|
||||||
static void moveToJumpgate(void);
|
static void moveToJumpgate(void);
|
||||||
static int nearEnemies(void);
|
static int nearEnemies(void);
|
||||||
static int nearItems(void);
|
static int nearItems(void);
|
||||||
|
static int nearMines(void);
|
||||||
static void moveToItem(void);
|
static void moveToItem(void);
|
||||||
static int nearTowableCraft(void);
|
static int nearTowableCraft(void);
|
||||||
static void moveToTowableCraft(void);
|
static void moveToTowableCraft(void);
|
||||||
|
@ -64,6 +65,11 @@ void doAI(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nearMines())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((self->aiFlags & AIF_GOAL_JUMPGATE) && nearJumpgate())
|
if ((self->aiFlags & AIF_GOAL_JUMPGATE) && nearJumpgate())
|
||||||
{
|
{
|
||||||
/* near jumpgate, but you might decide to continue to fight, anyway */
|
/* near jumpgate, but you might decide to continue to fight, anyway */
|
||||||
|
@ -612,6 +618,45 @@ static int nearEnemies(void)
|
||||||
return 0;
|
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)
|
static void fleeEnemies(void)
|
||||||
{
|
{
|
||||||
int wantedAngle = 180 + getAngle(self->x, self->y, self->targetLocation.x, self->targetLocation.y);
|
int wantedAngle = 180 + getAngle(self->x, self->y, self->targetLocation.x, self->targetLocation.y);
|
||||||
|
|
Loading…
Reference in New Issue