Move away from targets that you're not allowed to kill, but are still aggressive.
This commit is contained in:
parent
43c6a1e3f6
commit
b36b35834d
|
@ -55,7 +55,8 @@ 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);
|
static void fleeWithinBattleArea(int x, int y, int numEnemies);
|
||||||
|
static int evadeNonKillTargets(void);
|
||||||
|
|
||||||
void doAI(void)
|
void doAI(void)
|
||||||
{
|
{
|
||||||
|
@ -161,6 +162,8 @@ static void doFighterAI(void)
|
||||||
findTarget();
|
findTarget();
|
||||||
|
|
||||||
if (!self->target)
|
if (!self->target)
|
||||||
|
{
|
||||||
|
if (!evadeNonKillTargets())
|
||||||
{
|
{
|
||||||
/* move to leader and wander take priority over move to player */
|
/* move to leader and wander take priority over move to player */
|
||||||
if (self->aiFlags & AIF_MOVES_TO_LEADER)
|
if (self->aiFlags & AIF_MOVES_TO_LEADER)
|
||||||
|
@ -189,6 +192,7 @@ static void doFighterAI(void)
|
||||||
{
|
{
|
||||||
applyFighterBrakes();
|
applyFighterBrakes();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -673,6 +677,51 @@ static int nearEnemies(void)
|
||||||
|
|
||||||
if (numEnemies)
|
if (numEnemies)
|
||||||
{
|
{
|
||||||
|
fleeWithinBattleArea(x, y, numEnemies);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int evadeNonKillTargets(void)
|
||||||
|
{
|
||||||
|
int i, numEnemies, x, y;
|
||||||
|
Entity *e, **candidates;
|
||||||
|
|
||||||
|
candidates = getAllEntsInRadius(self->x, self->y, SCREEN_WIDTH, self);
|
||||||
|
|
||||||
|
self->target = NULL;
|
||||||
|
x = y = 0;
|
||||||
|
|
||||||
|
numEnemies = 0;
|
||||||
|
|
||||||
|
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
|
||||||
|
{
|
||||||
|
if ((e->flags & EF_TAKES_DAMAGE) && e->side != SIDE_NONE && e->side != self->side && (!(e->flags & EF_DISABLED)))
|
||||||
|
{
|
||||||
|
if (getDistance(e->x, e->y, self->x, self->y) <= SCREEN_WIDTH)
|
||||||
|
{
|
||||||
|
x += e->x;
|
||||||
|
y += e->y;
|
||||||
|
numEnemies++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numEnemies)
|
||||||
|
{
|
||||||
|
fleeWithinBattleArea(x, y, numEnemies);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fleeWithinBattleArea(int x, int y, int numEnemies)
|
||||||
|
{
|
||||||
self->targetLocation.x = x;
|
self->targetLocation.x = x;
|
||||||
self->targetLocation.y = y;
|
self->targetLocation.y = y;
|
||||||
|
|
||||||
|
@ -685,18 +734,6 @@ static int nearEnemies(void)
|
||||||
|
|
||||||
self->aiActionTime = FPS * 2;
|
self->aiActionTime = FPS * 2;
|
||||||
|
|
||||||
fleeWithinBattleArea();
|
|
||||||
|
|
||||||
self->action = fleeEnemies;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fleeWithinBattleArea(void)
|
|
||||||
{
|
|
||||||
/* at the limit of the battle area, try somewhere else */
|
/* at the limit of the battle area, try somewhere else */
|
||||||
if (self->targetLocation.x < SCREEN_WIDTH || self->targetLocation.x >= BATTLE_AREA_WIDTH - SCREEN_WIDTH)
|
if (self->targetLocation.x < SCREEN_WIDTH || self->targetLocation.x >= BATTLE_AREA_WIDTH - SCREEN_WIDTH)
|
||||||
{
|
{
|
||||||
|
@ -710,6 +747,8 @@ static void fleeWithinBattleArea(void)
|
||||||
self->targetLocation.y = -self->targetLocation.y;
|
self->targetLocation.y = -self->targetLocation.y;
|
||||||
self->aiActionTime = FPS * 5;
|
self->aiActionTime = FPS * 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->action = fleeEnemies;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deployMine(void)
|
static void deployMine(void)
|
||||||
|
@ -733,12 +772,12 @@ static void deployMine(void)
|
||||||
|
|
||||||
static int nearMines(void)
|
static int nearMines(void)
|
||||||
{
|
{
|
||||||
int i, numMines;
|
int i, numMines, x, y;
|
||||||
Entity *e, **candidates;
|
Entity *e, **candidates;
|
||||||
|
|
||||||
candidates = getAllEntsInRadius(self->x, self->y, SCREEN_HEIGHT, self);
|
candidates = getAllEntsInRadius(self->x, self->y, SCREEN_HEIGHT, self);
|
||||||
|
|
||||||
self->targetLocation.x = self->targetLocation.y = 0;
|
x = y = 0;
|
||||||
|
|
||||||
numMines = 0;
|
numMines = 0;
|
||||||
|
|
||||||
|
@ -746,26 +785,15 @@ static int nearMines(void)
|
||||||
{
|
{
|
||||||
if (e->side != self->side && e->type == ET_MINE && getDistance(e->x, e->y, self->x, self->y) <= SCREEN_HEIGHT)
|
if (e->side != self->side && e->type == ET_MINE && getDistance(e->x, e->y, self->x, self->y) <= SCREEN_HEIGHT)
|
||||||
{
|
{
|
||||||
self->targetLocation.x += e->x;
|
x += e->x;
|
||||||
self->targetLocation.y += e->y;
|
y += e->y;
|
||||||
numMines++;
|
numMines++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numMines)
|
if (numMines)
|
||||||
{
|
{
|
||||||
self->targetLocation.x /= numMines;
|
fleeWithinBattleArea(x, y, 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;
|
|
||||||
|
|
||||||
fleeWithinBattleArea();
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue