If at edge of battle area when fleeing, turn around.

This commit is contained in:
Steve 2016-05-22 16:50:11 +01:00
parent a1d58ff996
commit 2a725471c7
1 changed files with 25 additions and 1 deletions

View File

@ -55,6 +55,7 @@ static int selectWeaponForTarget(Entity *e);
static void deployMine(void); static void deployMine(void);
static int isSurrendering(void); static int isSurrendering(void);
static void doSurrender(void); static void doSurrender(void);
static void fleeWithinBattleArea(void);
void doAI(void) void doAI(void)
{ {
@ -680,15 +681,35 @@ static int nearEnemies(void)
self->targetLocation.x += (rand() % 100 - rand() % 100); self->targetLocation.x += (rand() % 100 - rand() % 100);
self->targetLocation.y += (rand() % 100 - rand() % 100); self->targetLocation.y += (rand() % 100 - rand() % 100);
self->action = fleeEnemies;
self->aiActionTime = FPS * 2; self->aiActionTime = FPS * 2;
fleeWithinBattleArea();
self->action = fleeEnemies;
return 1; return 1;
} }
return 0; return 0;
} }
static void fleeWithinBattleArea(void)
{
/* at the limit of the battle area, try somewhere else */
if (self->targetLocation.x < SCREEN_WIDTH || self->targetLocation.x >= BATTLE_AREA_WIDTH - SCREEN_WIDTH)
{
self->targetLocation.x = -self->targetLocation.x;
self->aiActionTime = FPS * 5;
}
/* at the limit of the battle area, try somewhere else */
if (self->targetLocation.y < SCREEN_HEIGHT || self->targetLocation.y >= BATTLE_AREA_HEIGHT - SCREEN_HEIGHT)
{
self->targetLocation.y = -self->targetLocation.y;
self->aiActionTime = FPS * 5;
}
}
static void deployMine(void) static void deployMine(void)
{ {
Entity *mine; Entity *mine;
@ -739,8 +760,11 @@ static int nearMines(void)
self->targetLocation.y += (rand() % 100 - rand() % 100); self->targetLocation.y += (rand() % 100 - rand() % 100);
self->action = fleeEnemies; self->action = fleeEnemies;
self->aiActionTime = FPS * 2; self->aiActionTime = FPS * 2;
fleeWithinBattleArea();
return 1; return 1;
} }