From 05b42f21ce198fed1c3c9caa7153e709f56ba07c Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 20 Dec 2015 16:13:49 +0000 Subject: [PATCH] AI evasion updates. --- src/battle/ai.c | 9 +++++++-- src/battle/fighters.c | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/battle/ai.c b/src/battle/ai.c index a24fd58..4723d58 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -56,7 +56,7 @@ void doAI(void) return; } - if ((self->aiFlags & AIF_DEFENSIVE) && rand() % 50 && nearEnemies()) + if ((self->aiFlags & AIF_DEFENSIVE) && rand() % 25 && nearEnemies()) { return; } @@ -555,8 +555,13 @@ static int nearEnemies(void) { self->targetLocation.x /= numEnemies; self->targetLocation.y /= numEnemies; + + /* dodge slightly */ + self->targetLocation.x += (rand() % 100 - rand() % 100); + self->targetLocation.y += (rand() % 100 - rand() % 100); + self->action = fleeEnemies; - self->aiActionTime = FPS / 2; + self->aiActionTime = FPS * 2; return 1; } diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 8b25e73..4ce6740 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -445,13 +445,13 @@ void damageFighter(Entity *e, int amount, long flags) /* * 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 (e->type == ET_FIGHTER && (!(e->aiFlags & AIF_EVADE)) && e != player && e->aiDamagePerSec >= (e->maxHealth + e->maxShield) * 0.1) { - if (rand() % 3) + if ((rand() % 10) > 6) { e->action = doAI; e->aiFlags |= AIF_EVADE; - e->aiActionTime = e->aiEvadeTimer = FPS * 3; + e->aiActionTime = e->aiEvadeTimer = FPS * (1 + (rand() % 3)); } else {