Removed Fighter struct and replaced with Entity.

This commit is contained in:
Steve 2015-10-26 19:16:12 +00:00
parent 73eb5517bf
commit 705a2cebe9
29 changed files with 357 additions and 359 deletions

View File

@ -29,8 +29,8 @@ static int aggression[][5] =
{5, 10, 15, 20, 25} {5, 10, 15, 20, 25}
}; };
static void faceTarget(Fighter *f); static void faceTarget(Entity *f);
static int isInFOV(Fighter *f, int fov); 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);
@ -43,7 +43,7 @@ static void boost(void);
static void slow(void); static void slow(void);
static int targetOutOfRange(void); static int targetOutOfRange(void);
static void moveToPlayer(void); static void moveToPlayer(void);
static int canAttack(Fighter *f); static int canAttack(Entity *f);
static int selectWeapon(int type); static int selectWeapon(int type);
void doAI(void) void doAI(void)
@ -142,13 +142,13 @@ static void huntAndAttackTarget(void)
static void findTarget(void) static void findTarget(void)
{ {
Fighter *f; Entity *f;
int closest = 2000; int closest = 2000;
int dist = 2000; int dist = 2000;
self->target = NULL; self->target = NULL;
for (f = battle.fighterHead.next ; f != NULL ; f = f->next) for (f = battle.entityHead.next ; f != NULL ; f = f->next)
{ {
if (f->side != self->side && f->health > 0 && canAttack(f)) if (f->side != self->side && f->health > 0 && canAttack(f))
{ {
@ -162,11 +162,11 @@ static void findTarget(void)
} }
} }
static int canAttack(Fighter *f) static int canAttack(Entity *f)
{ {
self->selectedGunType = self->guns[0].type; self->selectedGunType = self->guns[0].type;
if (f->flags & FF_DISABLE) if (f->flags & EF_DISABLE)
{ {
if (f->systemPower > 0) if (f->systemPower > 0)
{ {
@ -176,7 +176,7 @@ static int canAttack(Fighter *f)
return 0; return 0;
} }
if (f->flags & FF_NO_KILL) if (f->flags & EF_NO_KILL)
{ {
return selectWeapon(BT_LASER) || selectWeapon(BT_MAG); return selectWeapon(BT_LASER) || selectWeapon(BT_MAG);
} }
@ -200,7 +200,7 @@ static int selectWeapon(int type)
return 0; return 0;
} }
static void faceTarget(Fighter *f) static void faceTarget(Entity *f)
{ {
int dir; int dir;
int wantedAngle = getAngle(self->x, self->y, f->x, f->y); int wantedAngle = getAngle(self->x, self->y, f->x, f->y);
@ -209,7 +209,7 @@ static void faceTarget(Fighter *f)
if (fabs(wantedAngle - self->angle) > TURN_THRESHOLD) if (fabs(wantedAngle - self->angle) > TURN_THRESHOLD)
{ {
dir = (wantedAngle - self->angle + 360) % 360 > 180 ? -1 : 1; dir = ((int)(wantedAngle - self->angle + 360)) % 360 > 180 ? -1 : 1;
self->angle += dir * TURN_SPEED; self->angle += dir * TURN_SPEED;
@ -219,7 +219,7 @@ static void faceTarget(Fighter *f)
} }
} }
static int isInFOV(Fighter *f, int fov) static int isInFOV(Entity *f, int fov)
{ {
int angle, a, b; int angle, a, b;
@ -249,13 +249,13 @@ static void slow(void)
static int hasClearShot(void) static int hasClearShot(void)
{ {
int dist; int dist;
Fighter *f; Entity *f;
if (isInFOV(self->target, 4)) if (isInFOV(self->target, 4))
{ {
dist = getDistance(self->x, self->y, self->target->x, self->target->y); dist = getDistance(self->x, self->y, self->target->x, self->target->y);
for (f = battle.fighterHead.next ; f != NULL ; f = f->next) for (f = battle.entityHead.next ; f != NULL ; f = f->next)
{ {
if (f != self && f != self->target && (getDistance(self->x, self->y, f->x, f->y) < dist)) if (f != self && f != self->target && (getDistance(self->x, self->y, f->x, f->y) < dist))
{ {
@ -296,7 +296,7 @@ static void dodge(void)
if (fabs(wantedAngle - self->angle) > TURN_THRESHOLD) if (fabs(wantedAngle - self->angle) > TURN_THRESHOLD)
{ {
dir = (wantedAngle - self->angle + 360) % 360 > 180 ? -1 : 1; dir = ((int)(wantedAngle - self->angle + 360)) % 360 > 180 ? -1 : 1;
self->angle += dir * TURN_SPEED; self->angle += dir * TURN_SPEED;

View File

@ -28,11 +28,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern int mod(int n, int x); extern int mod(int n, int x);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern void fireGuns(Fighter *owner); extern void fireGuns(Entity *owner);
extern float getAngle(int x1, int y1, int x2, int y2); 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 Battle battle; extern Battle battle;
extern Fighter *self; extern Entity *self;
extern Fighter *player; extern Entity *player;

View File

@ -42,7 +42,6 @@ void initBattle(void)
memset(&battle, 0, sizeof(Battle)); memset(&battle, 0, sizeof(Battle));
battle.bulletTail = &battle.bulletHead; battle.bulletTail = &battle.bulletHead;
battle.entityTail = &battle.entityHead; battle.entityTail = &battle.entityHead;
battle.fighterTail = &battle.fighterHead;
battle.effectTail = &battle.effectHead; battle.effectTail = &battle.effectHead;
battle.objectiveTail = &battle.objectiveHead; battle.objectiveTail = &battle.objectiveHead;
battle.triggerTail = &battle.triggerHead; battle.triggerTail = &battle.triggerHead;
@ -118,8 +117,6 @@ static void doBattle(void)
doBullets(); doBullets();
doFighters();
doEntities(); doEntities();
doEffects(); doEffects();
@ -162,8 +159,6 @@ static void draw(void)
drawBullets(); drawBullets();
drawFighters();
drawEntities(); drawEntities();
drawEffects(); drawEffects();
@ -320,21 +315,12 @@ static void postBattle(void)
void destroyBattle(void) void destroyBattle(void)
{ {
Fighter *f;
Entity *ent; Entity *ent;
Bullet *b; Bullet *b;
Effect *e; Effect *e;
Objective *o; Objective *o;
Trigger *t; Trigger *t;
while (battle.fighterHead.next)
{
f = battle.fighterHead.next;
battle.fighterHead.next = f->next;
free(f);
}
battle.fighterTail = &battle.fighterHead;
while (battle.entityHead.next) while (battle.entityHead.next)
{ {
ent = battle.entityHead.next; ent = battle.entityHead.next;

View File

@ -34,10 +34,8 @@ extern void doBullets(void);
extern void drawBullets(void); extern void drawBullets(void);
extern void doStars(float dx, float dy); extern void doStars(float dx, float dy);
extern void drawStars(void); extern void drawStars(void);
extern void doFighters(void);
extern void doEntities(void); extern void doEntities(void);
extern void drawEntities(void); extern void drawEntities(void);
extern void drawFighters(void);
extern void initStars(void); extern void initStars(void);
extern void doPlayer(void); extern void doPlayer(void);
extern void drawHud(void); extern void drawHud(void);
@ -66,5 +64,5 @@ extern void checkTrigger(char *name, int type);
extern App app; extern App app;
extern Battle battle; extern Battle battle;
extern Fighter *player; extern Entity *player;
extern Game game; extern Game game;

View File

@ -94,47 +94,50 @@ void doBullets(void)
static void checkCollisions(Bullet *b) static void checkCollisions(Bullet *b)
{ {
Fighter *f; Entity *f;
int bw, bh, ew, eh; int bw, bh, ew, eh;
SDL_QueryTexture(b->texture, NULL, NULL, &bw, &bh); SDL_QueryTexture(b->texture, NULL, NULL, &bw, &bh);
for (f = battle.fighterHead.next ; f != NULL ; f = f->next) for (f = battle.entityHead.next ; f != NULL ; f = f->next)
{ {
SDL_QueryTexture(f->texture, NULL, NULL, &ew, &eh); if (f->type == ET_FIGHTER)
if (b->owner != f && f->health > 0 && collision(b->x - bw / 2, b->y - bh / 2, bw, bh, f->x - ew / 2, f->y - eh / 2, ew, eh))
{ {
if (b->owner->side == f->side) SDL_QueryTexture(f->texture, NULL, NULL, &ew, &eh);
if (b->owner != f && f->health > 0 && collision(b->x - bw / 2, b->y - bh / 2, bw, bh, f->x - ew / 2, f->y - eh / 2, ew, eh))
{ {
b->damage = 0; if (b->owner->side == f->side)
{
b->damage = 0;
}
else if (b->owner == player)
{
battle.stats[STAT_SHOTS_HIT]++;
}
damageFighter(f, b->damage, b->flags);
b->life = 0;
if (b->flags & BF_EXPLODES)
{
addMissileExplosion(b);
}
/* assuming that health <= 0 will always mean killed */
if (f->health <= 0 && b->owner == player)
{
battle.stats[STAT_ENEMIES_KILLED_PLAYER]++;
}
if (b->owner == player && b->type == BT_MISSILE)
{
battle.stats[STAT_MISSILES_HIT]++;
}
return;
} }
else if (b->owner == player)
{
battle.stats[STAT_SHOTS_HIT]++;
}
damageFighter(f, b->damage, b->flags);
b->life = 0;
if (b->flags & BF_EXPLODES)
{
addMissileExplosion(b);
}
/* assuming that health <= 0 will always mean killed */
if (f->health <= 0 && b->owner == player)
{
battle.stats[STAT_ENEMIES_KILLED_PLAYER]++;
}
if (b->owner == player && b->type == BT_MISSILE)
{
battle.stats[STAT_MISSILES_HIT]++;
}
return;
} }
} }
} }
@ -213,7 +216,7 @@ static void huntTarget(Bullet *b)
} }
} }
Bullet *createBullet(int type, int x, int y, Fighter *owner) Bullet *createBullet(int type, int x, int y, Entity *owner)
{ {
Bullet *b; Bullet *b;
@ -238,7 +241,7 @@ Bullet *createBullet(int type, int x, int y, Fighter *owner)
return b; return b;
} }
void fireGuns(Fighter *owner) void fireGuns(Entity *owner)
{ {
Bullet *b; Bullet *b;
int i; int i;
@ -272,7 +275,7 @@ void fireGuns(Fighter *owner)
playBattleSound(b->sound, owner->x, owner->y); playBattleSound(b->sound, owner->x, owner->y);
} }
void fireMissile(Fighter *owner) void fireMissile(Entity *owner)
{ {
Bullet *b; Bullet *b;

View File

@ -30,7 +30,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 blitRotated(SDL_Texture *texture, int x, int y, int angle); extern void blitRotated(SDL_Texture *texture, int x, int y, int angle);
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
extern void damageFighter(Fighter *f, int damage, long flags); extern void damageFighter(Entity *f, int damage, long flags);
extern void playBattleSound(int id, int x, int y); extern void playBattleSound(int id, int x, int y);
extern long flagsToLong(char *flags); extern long flagsToLong(char *flags);
extern long lookup(char *name); extern long lookup(char *name);
@ -41,4 +41,4 @@ extern int mod(int n, int x);
extern void addMissileExplosion(Bullet *b); extern void addMissileExplosion(Bullet *b);
extern Battle battle; extern Battle battle;
extern Fighter *player; extern Entity *player;

View File

@ -24,5 +24,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../structs.h" #include "../structs.h"
extern Battle battle; extern Battle battle;
extern Fighter *player; extern Entity *player;
extern Game game; extern Game game;

View File

@ -28,4 +28,4 @@ extern SDL_Texture *getTexture(char *name);
extern App app; extern App app;
extern Battle battle; extern Battle battle;
extern Fighter *self; extern Entity *self;

View File

@ -20,45 +20,85 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "entities.h" #include "entities.h"
static void drawEntity(Entity *e);
static void doEntity(Entity *e, Entity *prev);
void doEntities(void) void doEntities(void)
{ {
Entity *e, *prev; Entity *e, *prev;
prev = &battle.entityHead; prev = &battle.entityHead;
battle.numAllies = battle.numEnemies = 0;
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
e->x += e->dx; self = e;
e->y += e->dy;
e->x -= battle.ssx; switch (e->type)
e->y -= battle.ssy;
if (e->action != NULL)
{ {
if (--e->thinkTime <= 0) case ET_FIGHTER:
{ doFighter(e, prev);
e->action(); break;
}
}
if (e->health <= 0) default:
{ doEntity(e, prev);
prev->next = e->next; break;
free(e);
e = prev;
} }
prev = e;
} }
} }
static void doEntity(Entity *e, Entity *prev)
{
e->x += e->dx;
e->y += e->dy;
e->x -= battle.ssx;
e->y -= battle.ssy;
if (e->action != NULL)
{
if (--e->thinkTime <= 0)
{
e->action();
}
}
if (e->health <= 0)
{
if (e == battle.entityTail)
{
battle.entityTail = prev;
}
prev->next = e->next;
free(e);
e = prev;
}
prev = e;
}
void drawEntities(void) void drawEntities(void)
{ {
Entity *e; Entity *e;
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
blitRotated(e->texture, e->x, e->y, e->angle); switch (e->type)
{
case ET_FIGHTER:
drawFighter(e);
break;
default:
drawEntity(e);
break;
}
} }
} }
static void drawEntity(Entity *e)
{
blitRotated(e->texture, e->x, e->y, e->angle);
}

View File

@ -24,5 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../structs.h" #include "../structs.h"
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 drawFighter(Entity *e);
extern void doFighter(Entity *e, Entity *prev);
extern Battle battle; extern Battle battle;
extern Entity *self;

View File

@ -22,11 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void loadFighterDef(char *filename); static void loadFighterDef(char *filename);
static Fighter defHead, *defTail; static Entity defHead, *defTail;
Fighter *getFighterDef(char *name) Entity *getFighterDef(char *name)
{ {
Fighter *f; Entity *f;
for (f = defHead.next ; f != NULL ; f = f->next) for (f = defHead.next ; f != NULL ; f = f->next)
{ {
@ -48,7 +48,7 @@ void loadFighterDefs(void)
text = readFile("data/fighters/list.json"); text = readFile("data/fighters/list.json");
root = cJSON_Parse(text); root = cJSON_Parse(text);
memset(&defHead, 0, sizeof(Fighter)); memset(&defHead, 0, sizeof(Entity));
defTail = &defHead; defTail = &defHead;
for (node = root->child ; node != NULL ; node = node->next) for (node = root->child ; node != NULL ; node = node->next)
@ -64,15 +64,15 @@ static void loadFighterDef(char *filename)
{ {
cJSON *root, *node; cJSON *root, *node;
char *text; char *text;
Fighter *f; Entity *f;
int i, w, h; int i, w, h;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
text = readFile(filename); text = readFile(filename);
f = malloc(sizeof(Fighter)); f = malloc(sizeof(Entity));
memset(f, 0, sizeof(Fighter)); memset(f, 0, sizeof(Entity));
defTail->next = f; defTail->next = f;
defTail = f; defTail = f;
@ -127,7 +127,7 @@ static void loadFighterDef(char *filename)
void destroyFighterDefs(void) void destroyFighterDefs(void)
{ {
Fighter *f; Entity *f;
while (defHead.next) while (defHead.next)
{ {

View File

@ -25,24 +25,24 @@ static void die(void);
static void immediateDie(void); static void immediateDie(void);
static void spinDie(void); static void spinDie(void);
static void straightDie(void); static void straightDie(void);
static void randomizeDart(Fighter *dart); static void randomizeDart(Entity *dart);
static void randomizeDartGuns(Fighter *dart); static void randomizeDartGuns(Entity *dart);
Fighter *spawnFighter(char *name, int x, int y, int side) Entity *spawnFighter(char *name, int x, int y, int side)
{ {
Fighter *f, *def; Entity *f, *def;
f = malloc(sizeof(Fighter)); f = malloc(sizeof(Entity));
memset(f, 0, sizeof(Fighter)); memset(f, 0, sizeof(Entity));
def = getFighterDef(name); def = getFighterDef(name);
memcpy(f, def, sizeof(Fighter)); memcpy(f, def, sizeof(Entity));
f->next = NULL; f->next = NULL;
battle.fighterTail->next = f; battle.entityTail->next = f;
battle.fighterTail = f; battle.entityTail = f;
f->x = x; f->x = x;
f->y = y; f->y = y;
@ -79,7 +79,7 @@ Fighter *spawnFighter(char *name, int x, int y, int side)
return f; return f;
} }
static void randomizeDart(Fighter *dart) static void randomizeDart(Entity *dart)
{ {
char textureName[MAX_DESCRIPTION_LENGTH]; char textureName[MAX_DESCRIPTION_LENGTH];
@ -111,7 +111,7 @@ static void randomizeDart(Fighter *dart)
dart->texture = getTexture(textureName); dart->texture = getTexture(textureName);
} }
static void randomizeDartGuns(Fighter *dart) static void randomizeDartGuns(Entity *dart)
{ {
int i; int i;
@ -153,163 +153,150 @@ static void randomizeDartGuns(Fighter *dart)
} }
} }
void doFighters(void) void doFighter(Entity *f, Entity *prev)
{ {
Fighter *f, *prev; if (player != NULL)
battle.numAllies = battle.numEnemies = 0;
prev = &battle.fighterHead;
for (f = battle.fighterHead.next ; f != NULL ; f = f->next)
{ {
self = f; if (f != player && f->health > 0)
if (player != NULL)
{ {
if (f != player && f->health > 0) separate();
{
separate();
}
if (f->side == player->side)
{
battle.numAllies++;
}
else
{
battle.numEnemies++;
}
} }
if (self->target != NULL && self->target->health <= 0) if (f->side == player->side)
{ {
self->action = self->defaultAction; battle.numAllies++;
self->target = NULL; }
else
{
battle.numEnemies++;
}
}
if (self->target != NULL && self->target->health <= 0)
{
self->action = self->defaultAction;
self->target = NULL;
}
if (!battle.missionTarget && f->flags & EF_MISSION_TARGET && f->health > 0)
{
battle.missionTarget = f;
}
f->x += f->dx;
f->y += f->dy;
if (f != player)
{
f->x -= battle.ssx;
f->y -= battle.ssy;
}
if (f->health > 0)
{
f->reload = MAX(f->reload - 1, 0);
f->shieldRecharge = MAX(f->shieldRecharge - 1, 0);
f->armourHit = MAX(f->armourHit - 25, 0);
f->shieldHit = MAX(f->shieldHit - 5, 0);
f->systemHit = MAX(f->systemHit - 25, 0);
if (self->thrust > 0.25)
{
addEngineEffect();
} }
if (!battle.missionTarget && f->flags & FF_MISSION_TARGET && f->health > 0) if (!f->shieldRecharge)
{ {
battle.missionTarget = f; f->shield = MIN(f->shield + 1, f->maxShield);
f->shieldRecharge = f->shieldRechargeRate;
} }
f->x += f->dx; if (f->action == NULL && f->defaultAction != NULL)
f->y += f->dy;
if (f != player)
{ {
f->x -= battle.ssx; f->action = f->defaultAction;
f->y -= battle.ssy;
} }
}
if (f->health > 0) if (f->action != NULL)
{
if (--f->thinkTime <= 0)
{ {
f->reload = MAX(f->reload - 1, 0); f->thinkTime = 0;
f->shieldRecharge = MAX(f->shieldRecharge - 1, 0); f->action();
f->armourHit = MAX(f->armourHit - 25, 0); }
f->shieldHit = MAX(f->shieldHit - 5, 0); }
f->systemHit = MAX(f->systemHit - 25, 0);
if (self->thrust > 0.25) if (f->alive == ALIVE_ALIVE)
{ {
addEngineEffect(); if (f->health <= 0)
} {
f->health = 0;
f->alive = ALIVE_DYING;
f->die();
if (!f->shieldRecharge) if (f == battle.missionTarget)
{ {
f->shield = MIN(f->shield + 1, f->maxShield); battle.missionTarget = NULL;
f->shieldRecharge = f->shieldRechargeRate;
}
if (f->action == NULL && f->defaultAction != NULL)
{
f->action = f->defaultAction;
} }
} }
else if (f->systemPower <= 0)
if (f->action != NULL)
{ {
if (--f->thinkTime <= 0) f->dx *= 0.99;
f->dy *= 0.99;
f->thrust = 0;
f->shield = f->maxShield = 0;
f->action = NULL;
if (f->alive == ALIVE_ALIVE)
{ {
f->thinkTime = 0; updateObjective(f->name, TT_DISABLE);
f->action(); battle.stats[STAT_DISABLED]++;
} }
} }
}
if (f->alive == ALIVE_ALIVE) if (f->alive == ALIVE_DEAD)
{
if (f == player)
{ {
if (f->health <= 0) battle.stats[STAT_PLAYER_KILLED]++;
}
else if (player != NULL)
{
if (player->alive == ALIVE_ALIVE)
{ {
f->health = 0; if (f->side != player->side)
f->alive = ALIVE_DYING;
f->die();
if (f == battle.missionTarget)
{ {
battle.missionTarget = NULL; battle.stats[STAT_ENEMIES_KILLED]++;
}
else
{
battle.stats[STAT_ALLIES_KILLED]++;
addHudMessage(colors.red, "Ally has been killed");
} }
} }
else if (f->systemPower <= 0)
{
f->dx *= 0.99;
f->dy *= 0.99;
f->thrust = 0;
f->shield = f->maxShield = 0;
f->action = NULL;
if (f->alive == ALIVE_ALIVE) updateObjective(f->name, TT_DESTROY);
{
updateObjective(f->name, TT_DISABLE); updateCondition(f->name, TT_DESTROY);
battle.stats[STAT_DISABLED]++;
} checkTrigger(f->name, TRIGGER_KILLS);
}
} }
if (f->alive == ALIVE_DEAD) if (f == battle.entityTail)
{ {
if (f == player) battle.entityTail = prev;
{
battle.stats[STAT_PLAYER_KILLED]++;
}
else if (player != NULL)
{
if (player->alive == ALIVE_ALIVE)
{
if (f->side != player->side)
{
battle.stats[STAT_ENEMIES_KILLED]++;
}
else
{
battle.stats[STAT_ALLIES_KILLED]++;
addHudMessage(colors.red, "Ally has been killed");
}
}
updateObjective(f->name, TT_DESTROY);
updateCondition(f->name, TT_DESTROY);
checkTrigger(f->name, TRIGGER_KILLS);
}
if (f == battle.fighterTail)
{
battle.fighterTail = prev;
}
if (f == player)
{
player = NULL;
}
prev->next = f->next;
free(f);
f = prev;
} }
prev = f; if (f == player)
{
player = NULL;
}
prev->next = f->next;
free(f);
f = prev;
} }
} }
@ -319,13 +306,13 @@ static void separate(void)
int distance; int distance;
float dx, dy, force; float dx, dy, force;
int count; int count;
Fighter *f; Entity *f;
dx = dy = 0; dx = dy = 0;
count = 0; count = 0;
force = 0; force = 0;
for (f = battle.fighterHead.next ; f != NULL ; f = f->next) for (f = battle.entityHead.next ; f != NULL ; f = f->next)
{ {
if (f != self) if (f != self)
{ {
@ -357,58 +344,54 @@ static void separate(void)
} }
} }
void drawFighters(void) void drawFighter(Entity *e)
{ {
Fighter *f;
SDL_Rect r; SDL_Rect r;
SDL_Texture *shieldHitTexture = getTexture("gfx/battle/shieldHit.png"); SDL_Texture *shieldHitTexture = getTexture("gfx/battle/shieldHit.png");
for (f = battle.fighterHead.next ; f != NULL ; f = f->next) SDL_SetTextureColorMod(e->texture, 255, 255, 255);
if (e->armourHit > 0)
{ {
SDL_SetTextureColorMod(f->texture, 255, 255, 255); SDL_SetTextureColorMod(e->texture, 255, 255 - e->armourHit, 255 - e->armourHit);
}
if (f->armourHit > 0) if (e->systemHit > 0)
{
SDL_SetTextureColorMod(e->texture, 255 - e->systemHit, 255, 255);
}
blitRotated(e->texture, e->x, e->y, e->angle);
if (e->shieldHit > 0)
{
SDL_SetTextureBlendMode(shieldHitTexture, SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(shieldHitTexture, e->shieldHit);
blit(shieldHitTexture, e->x, e->y, 1);
}
if (player != NULL)
{
if (e == player->target)
{ {
SDL_SetTextureColorMod(f->texture, 255, 255 - f->armourHit, 255 - f->armourHit); r.x = e->x - 32;
r.y = e->y - 32;
r.w = 64;
r.h = 64;
SDL_SetRenderDrawColor(app.renderer, 255, 64, 0, 255);
SDL_RenderDrawRect(app.renderer, &r);
} }
if (f->systemHit > 0) if (e == battle.missionTarget)
{ {
SDL_SetTextureColorMod(f->texture, 255 - f->systemHit, 255, 255); r.x = e->x - 28;
} r.y = e->y - 28;
r.w = 56;
r.h = 56;
blitRotated(f->texture, f->x, f->y, f->angle); SDL_SetRenderDrawColor(app.renderer, 64, 255, 0, 255);
SDL_RenderDrawRect(app.renderer, &r);
if (f->shieldHit > 0)
{
SDL_SetTextureBlendMode(shieldHitTexture, SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(shieldHitTexture, f->shieldHit);
blit(shieldHitTexture, f->x, f->y, 1);
}
if (player != NULL)
{
if (f == player->target)
{
r.x = f->x - 32;
r.y = f->y - 32;
r.w = 64;
r.h = 64;
SDL_SetRenderDrawColor(app.renderer, 255, 64, 0, 255);
SDL_RenderDrawRect(app.renderer, &r);
}
if (f == battle.missionTarget)
{
r.x = f->x - 28;
r.y = f->y - 28;
r.w = 56;
r.h = 56;
SDL_SetRenderDrawColor(app.renderer, 64, 255, 0, 255);
SDL_RenderDrawRect(app.renderer, &r);
}
} }
} }
} }
@ -437,7 +420,7 @@ void applyFighterBrakes(void)
self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy)); self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy));
} }
void damageFighter(Fighter *f, int amount, long flags) void damageFighter(Entity *f, int amount, long flags)
{ {
if (flags & BF_SYSTEM_DAMAGE) if (flags & BF_SYSTEM_DAMAGE)
{ {

View File

@ -35,12 +35,12 @@ extern void addSmallFighterExplosion(void);
extern void playBattleSound(int id, int x, int y); extern void playBattleSound(int id, int x, int y);
extern void updateObjective(char *name, int type); extern void updateObjective(char *name, int type);
extern void updateCondition(char *name, int type); extern void updateCondition(char *name, int type);
extern Fighter *getFighterDef(char *name); extern Entity *getFighterDef(char *name);
extern void addHudMessage(SDL_Color c, char *format, ...); extern void addHudMessage(SDL_Color c, char *format, ...);
extern void checkTrigger(char *name, int type); extern void checkTrigger(char *name, int type);
extern App app; extern App app;
extern Battle battle; extern Battle battle;
extern Colors colors; extern Colors colors;
extern Fighter *player; extern Entity *player;
extern Fighter *self; extern Entity *self;

View File

@ -36,4 +36,4 @@ extern void drawRadar(void);
extern App app; extern App app;
extern Battle battle; extern Battle battle;
extern Colors colors; extern Colors colors;
extern Fighter *player; extern Entity *player;

View File

@ -102,7 +102,7 @@ void doPlayer(void)
} }
} }
player->angle = player->angle % 360; player->angle = ((int)player->angle) % 360;
player->x = SCREEN_WIDTH / 2; player->x = SCREEN_WIDTH / 2;
player->y = SCREEN_HEIGHT / 2; player->y = SCREEN_HEIGHT / 2;
@ -136,13 +136,13 @@ static void selectTarget(void)
{ {
unsigned int closest = 65535; unsigned int closest = 65535;
unsigned int dist = 65535; unsigned int dist = 65535;
Fighter *f; Entity *f;
player->target = NULL; player->target = NULL;
for (f = battle.fighterHead.next ; f != NULL ; f = f->next) for (f = battle.entityHead.next ; f != NULL ; f = f->next)
{ {
if (f != player && f->side != player->side && f->alive == ALIVE_ALIVE) if (f != player && f->side != SIDE_NONE && f->side != player->side && f->alive == ALIVE_ALIVE)
{ {
dist = getDistance(self->x, self->y, f->x, f->y); dist = getDistance(self->x, self->y, f->x, f->y);
if (dist < closest) if (dist < closest)

View File

@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../defs.h" #include "../defs.h"
#include "../structs.h" #include "../structs.h"
extern void fireGuns(Fighter *owner); extern void fireGuns(Entity *owner);
extern void fireMissile(Fighter *owner); extern void fireMissile(Entity *owner);
extern void applyFighterThrust(void); extern void applyFighterThrust(void);
extern void applyFighterBrakes(void); extern void applyFighterBrakes(void);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
@ -32,5 +32,5 @@ extern void failIncompleteObjectives(void);
extern App app; extern App app;
extern Battle battle; extern Battle battle;
extern Fighter *player; extern Entity *player;
extern Fighter *self; extern Entity *self;

View File

@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void drawRadar(void) void drawRadar(void)
{ {
SDL_Rect r; SDL_Rect r;
Fighter *f; Entity *f;
drawFilledCircle(SCREEN_WIDTH - 85, SCREEN_HEIGHT - 85, 75, 0, 128, 0, 32); drawFilledCircle(SCREEN_WIDTH - 85, SCREEN_HEIGHT - 85, 75, 0, 128, 0, 32);
@ -34,7 +34,7 @@ void drawRadar(void)
r.w = r.h = 3; r.w = r.h = 3;
for (f = battle.fighterHead.next ; f != NULL ; f = f->next) for (f = battle.entityHead.next ; f != NULL ; f = f->next)
{ {
if (getDistance(f->x, f->y, player->x, player->y) / RADAR_RANGE < 70) if (getDistance(f->x, f->y, player->x, player->y) / RADAR_RANGE < 70)
{ {

View File

@ -29,4 +29,4 @@ extern int getDistance(int x1, int y1, int x2, int y2);
extern App app; extern App app;
extern Battle battle; extern Battle battle;
extern Fighter *player; extern Entity *player;

View File

@ -29,6 +29,7 @@ Entity *spawnWaypoint(void)
battle.entityTail->next = waypoint; battle.entityTail->next = waypoint;
battle.entityTail = waypoint; battle.entityTail = waypoint;
waypoint->type = ET_WAYPOINT;
waypoint->health = waypoint->maxHealth = FPS; waypoint->health = waypoint->maxHealth = FPS;
waypoint->texture = getTexture("gfx/entities/waypoint.png"); waypoint->texture = getTexture("gfx/entities/waypoint.png");
waypoint->action = rotate; waypoint->action = rotate;
@ -38,5 +39,9 @@ Entity *spawnWaypoint(void)
static void rotate(void) static void rotate(void)
{ {
self->angle += 0.1;
if (self->angle >= 360)
{
self -= 360;
}
} }

View File

@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../defs.h" #include "../defs.h"
#include "../structs.h" #include "../structs.h"
extern Battle battle;
extern SDL_Texture *getTexture(char *filename); extern SDL_Texture *getTexture(char *filename);
extern Battle battle;
extern Entity *self;

View File

@ -51,14 +51,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define BF_SYSTEM_DAMAGE (2 << 1) #define BF_SYSTEM_DAMAGE (2 << 1)
#define BF_EXPLODES (2 << 2) #define BF_EXPLODES (2 << 2)
#define FF_NONE 0 #define EF_NONE 0
#define FF_NO_KILL (2 << 0) #define EF_NO_KILL (2 << 0)
#define FF_DISABLE (2 << 1) #define EF_DISABLE (2 << 1)
#define FF_IMMORTAL (2 << 2) #define EF_IMMORTAL (2 << 2)
#define FF_MISSION_TARGET (2 << 3) #define EF_MISSION_TARGET (2 << 3)
enum enum
{ {
ET_FIGHTER,
ET_WAYPOINT ET_WAYPOINT
}; };

View File

@ -174,7 +174,7 @@ static void loadPlayer(cJSON *node)
static void loadFighters(cJSON *node) static void loadFighters(cJSON *node)
{ {
Fighter *f; Entity *f;
char *type; char *type;
int side, x, y; int side, x, y;
@ -205,7 +205,7 @@ static void loadFighters(cJSON *node)
static void loadFighterGroups(cJSON *node) static void loadFighterGroups(cJSON *node)
{ {
Fighter *f; Entity *f;
char **types, *name, *type; char **types, *name, *type;
int side, x, y, scatter, number; int side, x, y, scatter, number;
int i, numTypes; int i, numTypes;

View File

@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern long lookup(char *name); extern long lookup(char *name);
extern char *readFile(char *filename); extern char *readFile(char *filename);
extern SDL_Texture *getTexture(char *filename); extern SDL_Texture *getTexture(char *filename);
extern Fighter *spawnFighter(char *name, int x, int y, int side); extern Entity *spawnFighter(char *name, int x, int y, int side);
extern void startSectionTransition(void); extern void startSectionTransition(void);
extern void endSectionTransition(void); extern void endSectionTransition(void);
extern void playMusic(char *filename); extern void playMusic(char *filename);
@ -38,5 +38,5 @@ extern long flagsToLong(char *flags);
extern Entity *spawnWaypoint(void); extern Entity *spawnWaypoint(void);
extern Battle battle; extern Battle battle;
extern Fighter *player; extern Entity *player;
extern Game game; extern Game game;

View File

@ -37,7 +37,7 @@ static SDL_Texture *logo;
static SDL_Texture *pandoranWar; static SDL_Texture *pandoranWar;
static SDL_Texture *earthTexture; static SDL_Texture *earthTexture;
static PointF earth; static PointF earth;
static Fighter fighters[NUM_FIGHTERS]; static Entity fighters[NUM_FIGHTERS];
static const char *fighterTextures[] = {"gfx/fighters/firefly.png", "gfx/fighters/hammerhead.png", "gfx/fighters/hyena.png", "gfx/fighters/khepri.png", "gfx/fighters/kingfisher.png", "gfx/fighters/leopard.png", "gfx/fighters/nymph.png", "gfx/fighters/ray.png", "gfx/fighters/rook.png", "gfx/fighters/taf.png"}; static const char *fighterTextures[] = {"gfx/fighters/firefly.png", "gfx/fighters/hammerhead.png", "gfx/fighters/hyena.png", "gfx/fighters/khepri.png", "gfx/fighters/kingfisher.png", "gfx/fighters/leopard.png", "gfx/fighters/nymph.png", "gfx/fighters/ray.png", "gfx/fighters/rook.png", "gfx/fighters/taf.png"};
static int showingOptions; static int showingOptions;
@ -99,7 +99,7 @@ static void initFighters(void)
numTextures = sizeof(fighterTextures) / sizeof(char*); numTextures = sizeof(fighterTextures) / sizeof(char*);
memset(&fighters, 0, sizeof(Fighter) * NUM_FIGHTERS); memset(&fighters, 0, sizeof(Entity) * NUM_FIGHTERS);
for (i = 0 ; i < NUM_FIGHTERS ; i++) for (i = 0 ; i < NUM_FIGHTERS ; i++)
{ {

View File

@ -60,4 +60,4 @@ extern App app;
extern Battle battle; extern Battle battle;
extern Colors colors; extern Colors colors;
extern Game game; extern Game game;
extern Fighter *self; extern Entity *self;

View File

@ -35,6 +35,6 @@ extern void saveScreenshot(void);
App app; App app;
Colors colors; Colors colors;
Battle battle; Battle battle;
Fighter *self; Entity *self;
Fighter *player; Entity *player;
Game game; Game game;

View File

@ -22,7 +22,6 @@ typedef struct SDL_Texture SDL_Texture;
typedef struct Texture Texture; typedef struct Texture Texture;
typedef struct Lookup Lookup; typedef struct Lookup Lookup;
typedef struct Weapon Weapon; typedef struct Weapon Weapon;
typedef struct Fighter Fighter;
typedef struct Entity Entity; typedef struct Entity Entity;
typedef struct Bullet Bullet; typedef struct Bullet Bullet;
typedef struct Effect Effect; typedef struct Effect Effect;
@ -71,26 +70,6 @@ struct Weapon {
struct Entity { struct Entity {
int type; int type;
char name[MAX_NAME_LENGTH];
int side;
float x;
float y;
float dx;
float dy;
int angle;
int health;
int maxHealth;
int shield;
int thinkTime;
long flags;
void (*action)(void);
void (*defaultAction)(void);
void (*die)(void);
SDL_Texture *texture;
Entity *next;
};
struct Fighter {
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
int active; int active;
int side; int side;
@ -100,7 +79,7 @@ struct Fighter {
float dy; float dy;
float thrust; float thrust;
float speed; float speed;
int angle; float angle;
int alive; int alive;
int health; int health;
int maxHealth; int maxHealth;
@ -122,12 +101,12 @@ struct Fighter {
Weapon guns[MAX_FIGHTER_GUNS]; Weapon guns[MAX_FIGHTER_GUNS];
Weapon missiles; Weapon missiles;
long flags; long flags;
Fighter *target; Entity *target;
void (*action)(void); void (*action)(void);
void (*defaultAction)(void); void (*defaultAction)(void);
void (*die)(void); void (*die)(void);
SDL_Texture *texture; SDL_Texture *texture;
Fighter *next; Entity *next;
}; };
struct Bullet { struct Bullet {
@ -142,8 +121,8 @@ struct Bullet {
int angle; int angle;
long flags; long flags;
SDL_Texture *texture; SDL_Texture *texture;
Fighter *owner; Entity *owner;
Fighter *target; Entity *target;
Bullet *next; Bullet *next;
}; };
@ -241,10 +220,9 @@ typedef struct {
int status; int status;
int missionFinishedTimer; int missionFinishedTimer;
int numObjectivesComplete, numObjectivesTotal; int numObjectivesComplete, numObjectivesTotal;
Fighter *missionTarget; Entity *missionTarget;
SDL_Texture *background, *planetTexture; SDL_Texture *background, *planetTexture;
PointF planet; PointF planet;
Fighter fighterHead, *fighterTail;
Entity entityHead, *entityTail; Entity entityHead, *entityTail;
Bullet bulletHead, *bulletTail; Bullet bulletHead, *bulletTail;
Effect effectHead, *effectTail; Effect effectHead, *effectTail;

View File

@ -32,10 +32,10 @@ void initLookups(void)
addLookup("ET_WAYPOINT", ET_WAYPOINT); addLookup("ET_WAYPOINT", ET_WAYPOINT);
addLookup("FF_NO_KILL", FF_NO_KILL); addLookup("EF_NO_KILL", EF_NO_KILL);
addLookup("FF_DISABLE", FF_DISABLE); addLookup("EF_DISABLE", EF_DISABLE);
addLookup("FF_IMMORTAL", FF_IMMORTAL); addLookup("EF_IMMORTAL", EF_IMMORTAL);
addLookup("FF_MISSION_TARGET", FF_MISSION_TARGET); addLookup("EF_MISSION_TARGET", EF_MISSION_TARGET);
addLookup("TT_DESTROY", TT_DESTROY); addLookup("TT_DESTROY", TT_DESTROY);
addLookup("TT_DISABLE", TT_DISABLE); addLookup("TT_DISABLE", TT_DISABLE);

View File

@ -29,4 +29,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern Fighter *player; extern Entity *player;