Start of civilian ships: will follow player when close and flee in to extraction points.

This commit is contained in:
Steve 2015-11-11 06:46:58 +00:00
parent 9de4bf6255
commit ad405c57ae
13 changed files with 120 additions and 12 deletions

View File

@ -0,0 +1,10 @@
{
"name" : "Civilian",
"health" : 10,
"shield" : 0,
"speed" : 2,
"reloadTime" : 0,
"shieldRechargeRate" : 0,
"textureName" : "gfx/craft/civilian01.png",
"flags" : "EF_CIVILIAN+EF_FLEEING"
}

View File

@ -11,5 +11,6 @@
"data/fighters/nymph.json", "data/fighters/nymph.json",
"data/fighters/firefly.json", "data/fighters/firefly.json",
"data/fighters/hyena.json", "data/fighters/hyena.json",
"data/fighters/leopard.json" "data/fighters/leopard.json",
"data/fighters/civilian.json"
] ]

BIN
gfx/craft/civilian01.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
gfx/craft/civilian02.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -46,6 +46,10 @@ static void moveToPlayer(void);
static int canAttack(Entity *f); static int canAttack(Entity *f);
static int selectWeapon(int type); static int selectWeapon(int type);
static void flee(void); static void flee(void);
static int nearExtractionPoint(void);
static int nearEnemies(void);
static void lookForPlayer(void);
static void moveToExtractionPoint(void);
void doAI(void) void doAI(void)
{ {
@ -384,3 +388,68 @@ static void moveToPlayer(void)
applyFighterThrust(); applyFighterThrust();
} }
} }
/* ====== Civilian AI ======= */
void doCivilianAI(void)
{
if (!nearExtractionPoint() && !nearEnemies())
{
lookForPlayer();
}
}
static int nearExtractionPoint(void)
{
Entity *e, **candidates;
int i;
candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self);
i = 0;
e = candidates[i];
self->target = NULL;
while (e)
{
if (e->type == ET_EXTRACTION_POINT)
{
self->target = e;
}
i++;
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
}
if (self->target != NULL)
{
self->action = moveToExtractionPoint;
}
return self->target != NULL;
}
static int nearEnemies(void)
{
return 0;
}
static void moveToExtractionPoint(void)
{
faceTarget(self->target);
applyFighterThrust();
}
static void lookForPlayer(void)
{
if (getDistance(self->x, self->y, player->x, player->y) < 1000)
{
moveToPlayer();
return;
}
applyFighterBrakes();
}

View File

@ -34,6 +34,7 @@ extern float getAngle(int x1, int y1, int x2, int y2);
extern void applyFighterThrust(void); extern void applyFighterThrust(void);
extern void applyFighterBrakes(void); extern void applyFighterBrakes(void);
extern void addHudMessage(SDL_Color c, char *format, ...); extern void addHudMessage(SDL_Color c, char *format, ...);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern Battle battle; extern Battle battle;
extern Colors colors; extern Colors colors;

View File

@ -58,11 +58,17 @@ static void handleFleeingEntities(void)
candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self); candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self);
i = 0; i = 0;
for (e = candidates[i] ; (e != NULL && i < MAX_GRID_CANDIDATES) ; i++) e = candidates[i];
while (e)
{ {
if (e->health > 0 && e->flags & EF_FLEEING && getDistance(e->x, e->y, self->x, self->y) <= 64) if (e->health > 0 && e->flags & EF_FLEEING && getDistance(e->x, e->y, self->x, self->y) <= 64)
{ {
e->alive = ALIVE_DEAD; e->alive = ALIVE_DEAD;
} }
i++;
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
} }
} }

View File

@ -126,6 +126,11 @@ static void loadFighterDef(char *filename)
f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint; f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint;
} }
if (cJSON_GetObjectItem(root, "flags"))
{
f->flags = flagsToLong(cJSON_GetObjectItem(root, "flags")->valuestring);
}
f->separationRadius = MAX(f->w, f->h); f->separationRadius = MAX(f->w, f->h);
f->separationRadius *= 2; f->separationRadius *= 2;

View File

@ -27,4 +27,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern char *readFile(char *filename); extern char *readFile(char *filename);
extern SDL_Texture *getTexture(char *filename); extern SDL_Texture *getTexture(char *filename);
extern long lookup(char *name); extern long lookup(char *name);
extern long flagsToLong(char *flags);

View File

@ -71,7 +71,15 @@ Entity *spawnFighter(char *name, int x, int y, int side)
randomizeDart(f); randomizeDart(f);
} }
if (f->flags & EF_CIVILIAN)
{
f->defaultAction = doCivilianAI;
}
else
{
f->defaultAction = doAI; f->defaultAction = doAI;
}
f->die = die; f->die = die;
return f; return f;
@ -270,6 +278,8 @@ static void separate(void)
e = candidates[i]; e = candidates[i];
while (e) while (e)
{
if (e->type == ET_FIGHTER)
{ {
distance = getDistance(e->x, e->y, self->x, self->y); distance = getDistance(e->x, e->y, self->x, self->y);
@ -283,6 +293,7 @@ static void separate(void)
count++; count++;
} }
}
i++; i++;

View File

@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern SDL_Texture *getTexture(char *filename); extern SDL_Texture *getTexture(char *filename);
extern void doAI(void); extern void doAI(void);
extern void doCivilianAI(void);
extern void blitRotated(SDL_Texture *t, int x, int y, int angle); extern void blitRotated(SDL_Texture *t, int x, int y, int angle);
extern void blit(SDL_Texture *t, int x, int y, int center); extern void blit(SDL_Texture *t, int x, int y, int center);
extern float getAngle(int x1, int y1, int x2, int y2); extern float getAngle(int x1, int y1, int x2, int y2);

View File

@ -66,6 +66,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define EF_FLEES (2 << 4) #define EF_FLEES (2 << 4)
#define EF_FLEEING (2 << 5) #define EF_FLEEING (2 << 5)
#define EF_NO_MT_BOX (2 << 6) #define EF_NO_MT_BOX (2 << 6)
#define EF_CIVILIAN (2 << 7)
enum enum
{ {

View File

@ -38,6 +38,8 @@ void initLookups(void)
addLookup("EF_IMMORTAL", EF_IMMORTAL); addLookup("EF_IMMORTAL", EF_IMMORTAL);
addLookup("EF_MISSION_TARGET", EF_MISSION_TARGET); addLookup("EF_MISSION_TARGET", EF_MISSION_TARGET);
addLookup("EF_FLEES", EF_FLEES); addLookup("EF_FLEES", EF_FLEES);
addLookup("EF_FLEEING", EF_FLEEING);
addLookup("EF_CIVILIAN", EF_CIVILIAN);
addLookup("TT_DESTROY", TT_DESTROY); addLookup("TT_DESTROY", TT_DESTROY);
addLookup("TT_DISABLE", TT_DISABLE); addLookup("TT_DISABLE", TT_DISABLE);