AI updates.

This commit is contained in:
Steve 2015-11-22 13:06:19 +00:00
parent a40f46e88f
commit 223231fb76
4 changed files with 26 additions and 52 deletions

View File

@ -25,12 +25,10 @@ static int isInFOV(Entity *f, int fov);
static void preAttack(void); static void preAttack(void);
static void huntTarget(void); static void huntTarget(void);
static void huntAndAttackTarget(void); static void huntAndAttackTarget(void);
static void flyStraight(void);
static void evade(void); static void evade(void);
static void nextAction(void); static void nextAction(void);
static void findTarget(void); static void findTarget(void);
static int hasClearShot(void); static int hasClearShot(void);
static void boost(void);
static void fallback(void); static void fallback(void);
static void moveToPlayer(void); static void moveToPlayer(void);
static int canAttack(Entity *f); static int canAttack(Entity *f);
@ -143,22 +141,11 @@ static void doFighterAI(void)
self->action = evade; self->action = evade;
self->aiActionTime = FPS; self->aiActionTime = FPS;
} }
else if (r <= getActionChance(AI_BOOST))
{
applyFighterThrust();
self->action = boost;
self->aiActionTime = FPS * 0.5;
}
else if (r <= getActionChance(AI_FALLBACK)) else if (r <= getActionChance(AI_FALLBACK))
{ {
self->action = fallback; self->action = fallback;
self->aiActionTime = FPS * 2; self->aiActionTime = FPS * 2;
} }
else if (r <= getActionChance(AI_STRAIGHT))
{
self->action = flyStraight;
self->aiActionTime = FPS;
}
else if (r <= getActionChance(AI_HUNT)) else if (r <= getActionChance(AI_HUNT))
{ {
self->action = huntTarget; self->action = huntTarget;
@ -178,15 +165,9 @@ static int getActionChance(int type)
case AI_EVADE: case AI_EVADE:
return 25 - (self->aiAggression * 4); return 25 - (self->aiAggression * 4);
case AI_BOOST:
return 40 - (self->aiAggression * 4);
case AI_FALLBACK: case AI_FALLBACK:
return 55 - (self->aiAggression * 4); return 55 - (self->aiAggression * 4);
case AI_STRAIGHT:
return 70 - (self->aiAggression * 4);
case AI_HUNT: case AI_HUNT:
return 85 - (self->aiAggression * 4); return 85 - (self->aiAggression * 4);
} }
@ -329,19 +310,6 @@ static int isInFOV(Entity *f, int fov)
return (a < b) ? (a <= angle && angle <= b) : (a <= angle || angle <= b); return (a < b) ? (a <= angle && angle <= b) : (a <= angle || angle <= b);
} }
static void boost(void)
{
self->dx *= 1.001;
self->dy *= 1.001;
nextAction();
if (self->action == doAI)
{
applyFighterThrust();
}
}
static int hasClearShot(void) static int hasClearShot(void)
{ {
int dist; int dist;
@ -401,13 +369,6 @@ static void preAttack(void)
} }
} }
static void flyStraight(void)
{
applyFighterThrust();
nextAction();
}
static void turnAndFly(int wantedAngle) static void turnAndFly(int wantedAngle)
{ {
int dir; int dir;
@ -452,9 +413,17 @@ static void nextAction(void)
static int isRetreating(void) static int isRetreating(void)
{ {
float chance;
if (!(self->flags & EF_RETREATING)) if (!(self->flags & EF_RETREATING))
{ {
if (battle.numEnemies > 0 && rand() % (battle.numEnemies * 5) == 0) if (battle.numInitialEnemies > 0)
{
chance = battle.numEnemies;
chance /= battle.numInitialEnemies;
chance *= 256;
if (battle.numEnemies > 0 && rand() % 100 > chance)
{ {
self->flags |= EF_RETREATING; self->flags |= EF_RETREATING;
@ -467,6 +436,7 @@ static int isRetreating(void)
return 1; return 1;
} }
} }
}
return self->flags & EF_RETREATING; return self->flags & EF_RETREATING;
} }

View File

@ -24,10 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../structs.h" #include "../structs.h"
#define AI_EVADE 0 #define AI_EVADE 0
#define AI_BOOST 1 #define AI_FALLBACK 1
#define AI_FALLBACK 2 #define AI_HUNT 2
#define AI_STRAIGHT 3
#define AI_HUNT 4
#define TURN_SPEED 4 #define TURN_SPEED 4
#define TURN_THRESHOLD 2 #define TURN_THRESHOLD 2

View File

@ -148,6 +148,11 @@ void doEntities(void)
battle.numAllies = numAllies; battle.numAllies = numAllies;
battle.numEnemies = numEnemies; battle.numEnemies = numEnemies;
if (!battle.numInitialEnemies)
{
battle.numInitialEnemies = battle.numEnemies;
}
if (battle.epic && battle.stats[STAT_TIME] % FPS == 0) if (battle.epic && battle.stats[STAT_TIME] % FPS == 0)
{ {
if (numAllies > battle.epicFighterLimit) if (numAllies > battle.epicFighterLimit)

View File

@ -237,6 +237,7 @@ typedef struct {
SDL_Point camera; SDL_Point camera;
int numAllies; int numAllies;
int numEnemies; int numEnemies;
int numInitialEnemies;
int status; int status;
int epic; int epic;
int epicFighterLimit; int epicFighterLimit;