diff --git a/src/battle/ai.c b/src/battle/ai.c index dafecdb..a24fd58 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -51,7 +51,7 @@ static void moveToLeader(void); void doAI(void) { - if ((self->aiFlags & AIF_AVOIDS_COMBAT) && nearEnemies()) + if ((self->aiFlags & (AIF_AVOIDS_COMBAT | AIF_EVADE)) && nearEnemies()) { return; } @@ -130,7 +130,14 @@ static void doFighterAI(void) { if (!lookForLeader()) { - applyFighterBrakes(); + if (self->aiFlags & AIF_MOVES_TO_PLAYER && player != NULL) + { + moveToPlayer(); + } + else + { + applyFighterBrakes(); + } } } else if (self->aiFlags & AIF_MOVES_TO_PLAYER && player != NULL) @@ -244,7 +251,7 @@ static void huntTarget(void) static void huntAndAttackTarget(void) { int dist = getDistance(self->x, self->y, self->target->x, self->target->y); - int range = self->aiFlags & AIF_LONG_RANGE_FIRE ? 1250 : 625; + int range = self->aiFlags & AIF_LONG_RANGE_FIRE ? (SCREEN_WIDTH * 1.5) : SCREEN_HEIGHT; faceTarget(self->target); @@ -267,7 +274,7 @@ static void huntAndAttackTarget(void) static int attackSecondaryTarget(Entity *e) { - if (self->target->aiFlags & AIF_AVOIDS_COMBAT || self->target->flags & EF_SECONDARY_TARGET) + if (self->target->aiFlags & (AIF_AVOIDS_COMBAT | AIF_EVADE) || self->target->flags & EF_SECONDARY_TARGET) { return rand() % 4 == 0; } diff --git a/src/battle/entities.c b/src/battle/entities.c index f836d3f..e0018b7 100644 --- a/src/battle/entities.c +++ b/src/battle/entities.c @@ -113,6 +113,13 @@ void doEntities(void) e->shieldHit = MAX(e->shieldHit - 5, 0); e->systemHit = MAX(e->systemHit - 25, 0); + e->aiDamageTimer = MAX(e->aiDamageTimer - 1, 0); + if (!e->aiDamageTimer) + { + e->aiDamagePerSec = 0; + e->aiFlags &= ~AIF_EVADE; + } + switch (e->type) { case ET_FIGHTER: @@ -213,8 +220,8 @@ void doEntities(void) prev = e; } - battle.numAllies = numAllies; - battle.numEnemies = numEnemies; + battle.numAllies = numActiveAllies; + battle.numEnemies = numActiveEnemies; if (!battle.numInitialEnemies) { diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 4a3f0b2..8b25e73 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -383,6 +383,9 @@ void damageFighter(Entity *e, int amount, long flags) { int prevShield = e->shield; + e->aiDamageTimer = FPS; + e->aiDamagePerSec += amount; + if (flags & BF_SYSTEM_DAMAGE) { e->systemPower = MAX(0, e->systemPower - amount); @@ -438,6 +441,23 @@ void damageFighter(Entity *e, int amount, long flags) playBattleSound(SND_SHIELD_HIT, e->x, e->y); } + + /* + * Sometimes run away if you take too much damage in a short space of time + */ + if (e->type == ET_FIGHTER && e != player && e->aiDamagePerSec >= (e->maxHealth + e->maxShield) * 0.1 && (!(e->aiFlags & AIF_EVADE))) + { + if (rand() % 3) + { + e->action = doAI; + e->aiFlags |= AIF_EVADE; + e->aiActionTime = e->aiEvadeTimer = FPS * 3; + } + else + { + e->aiDamagePerSec = 0; + } + } } static void die(void) diff --git a/src/defs.h b/src/defs.h index 4489e8d..fb44f5e 100644 --- a/src/defs.h +++ b/src/defs.h @@ -102,6 +102,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define AIF_INSTANT_DIE (2 << 11) #define AIF_LONG_RANGE_FIRE (2 << 12) #define AIF_MOVES_TO_LEADER (2 << 13) +#define AIF_EVADE (2 << 14) /* player abilities */ #define BOOST_RECHARGE_TIME (FPS * 7) diff --git a/src/structs.h b/src/structs.h index c38e81e..153ccdd 100644 --- a/src/structs.h +++ b/src/structs.h @@ -119,6 +119,9 @@ struct Entity { int thinkTime; int aiActionTime; int aiAggression; + int aiDamagePerSec; + int aiDamageTimer; + int aiEvadeTimer; int separationRadius; Weapon guns[MAX_FIGHTER_GUNS]; int missiles;