diff --git a/src/battle/ai.c b/src/battle/ai.c index 0d434bf..51d22fe 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -29,8 +29,8 @@ static int aggression[][5] = {5, 10, 15, 20, 25} }; -static void faceTarget(Fighter *f); -static int isInFOV(Fighter *f, int fov); +static void faceTarget(Entity *f); +static int isInFOV(Entity *f, int fov); static void preAttack(void); static void huntTarget(void); static void huntAndAttackTarget(void); @@ -43,7 +43,7 @@ static void boost(void); static void slow(void); static int targetOutOfRange(void); static void moveToPlayer(void); -static int canAttack(Fighter *f); +static int canAttack(Entity *f); static int selectWeapon(int type); void doAI(void) @@ -142,13 +142,13 @@ static void huntAndAttackTarget(void) static void findTarget(void) { - Fighter *f; + Entity *f; int closest = 2000; int dist = 2000; 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)) { @@ -162,11 +162,11 @@ static void findTarget(void) } } -static int canAttack(Fighter *f) +static int canAttack(Entity *f) { self->selectedGunType = self->guns[0].type; - if (f->flags & FF_DISABLE) + if (f->flags & EF_DISABLE) { if (f->systemPower > 0) { @@ -176,7 +176,7 @@ static int canAttack(Fighter *f) return 0; } - if (f->flags & FF_NO_KILL) + if (f->flags & EF_NO_KILL) { return selectWeapon(BT_LASER) || selectWeapon(BT_MAG); } @@ -200,7 +200,7 @@ static int selectWeapon(int type) return 0; } -static void faceTarget(Fighter *f) +static void faceTarget(Entity *f) { int dir; 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) { - dir = (wantedAngle - self->angle + 360) % 360 > 180 ? -1 : 1; + dir = ((int)(wantedAngle - self->angle + 360)) % 360 > 180 ? -1 : 1; 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; @@ -249,13 +249,13 @@ static void slow(void) static int hasClearShot(void) { int dist; - Fighter *f; + Entity *f; if (isInFOV(self->target, 4)) { 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)) { @@ -296,7 +296,7 @@ static void dodge(void) 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; diff --git a/src/battle/ai.h b/src/battle/ai.h index b606de0..21b1231 100644 --- a/src/battle/ai.h +++ b/src/battle/ai.h @@ -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 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 void applyFighterThrust(void); extern void applyFighterBrakes(void); extern Battle battle; -extern Fighter *self; -extern Fighter *player; +extern Entity *self; +extern Entity *player; diff --git a/src/battle/battle.c b/src/battle/battle.c index 80e4e78..ef56e6c 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -42,7 +42,6 @@ void initBattle(void) memset(&battle, 0, sizeof(Battle)); battle.bulletTail = &battle.bulletHead; battle.entityTail = &battle.entityHead; - battle.fighterTail = &battle.fighterHead; battle.effectTail = &battle.effectHead; battle.objectiveTail = &battle.objectiveHead; battle.triggerTail = &battle.triggerHead; @@ -118,8 +117,6 @@ static void doBattle(void) doBullets(); - doFighters(); - doEntities(); doEffects(); @@ -162,8 +159,6 @@ static void draw(void) drawBullets(); - drawFighters(); - drawEntities(); drawEffects(); @@ -320,21 +315,12 @@ static void postBattle(void) void destroyBattle(void) { - Fighter *f; Entity *ent; Bullet *b; Effect *e; Objective *o; 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) { ent = battle.entityHead.next; diff --git a/src/battle/battle.h b/src/battle/battle.h index 44bef77..6be9e3f 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -34,10 +34,8 @@ extern void doBullets(void); extern void drawBullets(void); extern void doStars(float dx, float dy); extern void drawStars(void); -extern void doFighters(void); extern void doEntities(void); extern void drawEntities(void); -extern void drawFighters(void); extern void initStars(void); extern void doPlayer(void); extern void drawHud(void); @@ -66,5 +64,5 @@ extern void checkTrigger(char *name, int type); extern App app; extern Battle battle; -extern Fighter *player; +extern Entity *player; extern Game game; diff --git a/src/battle/bullets.c b/src/battle/bullets.c index 3347525..e0e3403 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -94,47 +94,50 @@ void doBullets(void) static void checkCollisions(Bullet *b) { - Fighter *f; + Entity *f; int bw, bh, ew, eh; 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 (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 (f->type == ET_FIGHTER) { - 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; @@ -238,7 +241,7 @@ Bullet *createBullet(int type, int x, int y, Fighter *owner) return b; } -void fireGuns(Fighter *owner) +void fireGuns(Entity *owner) { Bullet *b; int i; @@ -272,7 +275,7 @@ void fireGuns(Fighter *owner) playBattleSound(b->sound, owner->x, owner->y); } -void fireMissile(Fighter *owner) +void fireMissile(Entity *owner) { Bullet *b; diff --git a/src/battle/bullets.h b/src/battle/bullets.h index 5613eb4..4d96e43 100644 --- a/src/battle/bullets.h +++ b/src/battle/bullets.h @@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern SDL_Texture *getTexture(char *filename); 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 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 long flagsToLong(char *flags); extern long lookup(char *name); @@ -41,4 +41,4 @@ extern int mod(int n, int x); extern void addMissileExplosion(Bullet *b); extern Battle battle; -extern Fighter *player; +extern Entity *player; diff --git a/src/battle/challenges.h b/src/battle/challenges.h index d30318c..470ce08 100644 --- a/src/battle/challenges.h +++ b/src/battle/challenges.h @@ -24,5 +24,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../structs.h" extern Battle battle; -extern Fighter *player; +extern Entity *player; extern Game game; diff --git a/src/battle/effects.h b/src/battle/effects.h index e2d738c..1e908d7 100644 --- a/src/battle/effects.h +++ b/src/battle/effects.h @@ -28,4 +28,4 @@ extern SDL_Texture *getTexture(char *name); extern App app; extern Battle battle; -extern Fighter *self; +extern Entity *self; diff --git a/src/battle/entities.c b/src/battle/entities.c index 6fea766..80b9d2f 100644 --- a/src/battle/entities.c +++ b/src/battle/entities.c @@ -20,45 +20,85 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "entities.h" +static void drawEntity(Entity *e); +static void doEntity(Entity *e, Entity *prev); + void doEntities(void) { Entity *e, *prev; prev = &battle.entityHead; + battle.numAllies = battle.numEnemies = 0; + for (e = battle.entityHead.next ; e != NULL ; e = e->next) { - e->x += e->dx; - e->y += e->dy; + self = e; - e->x -= battle.ssx; - e->y -= battle.ssy; - - if (e->action != NULL) + switch (e->type) { - if (--e->thinkTime <= 0) - { - e->action(); - } + case ET_FIGHTER: + doFighter(e, prev); + break; + + default: + doEntity(e, prev); + break; } - - if (e->health <= 0) - { - prev->next = e->next; - 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) { Entity *e; 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); +} diff --git a/src/battle/entities.h b/src/battle/entities.h index 518d828..476a5ac 100644 --- a/src/battle/entities.h +++ b/src/battle/entities.h @@ -24,5 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../structs.h" 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 Entity *self; diff --git a/src/battle/fighterDefs.c b/src/battle/fighterDefs.c index 168aa7b..e1e6564 100644 --- a/src/battle/fighterDefs.c +++ b/src/battle/fighterDefs.c @@ -22,11 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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) { @@ -48,7 +48,7 @@ void loadFighterDefs(void) text = readFile("data/fighters/list.json"); root = cJSON_Parse(text); - memset(&defHead, 0, sizeof(Fighter)); + memset(&defHead, 0, sizeof(Entity)); defTail = &defHead; for (node = root->child ; node != NULL ; node = node->next) @@ -64,15 +64,15 @@ static void loadFighterDef(char *filename) { cJSON *root, *node; char *text; - Fighter *f; + Entity *f; int i, w, h; SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename); text = readFile(filename); - f = malloc(sizeof(Fighter)); - memset(f, 0, sizeof(Fighter)); + f = malloc(sizeof(Entity)); + memset(f, 0, sizeof(Entity)); defTail->next = f; defTail = f; @@ -127,7 +127,7 @@ static void loadFighterDef(char *filename) void destroyFighterDefs(void) { - Fighter *f; + Entity *f; while (defHead.next) { diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 3a1934c..34a23fe 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -25,24 +25,24 @@ static void die(void); static void immediateDie(void); static void spinDie(void); static void straightDie(void); -static void randomizeDart(Fighter *dart); -static void randomizeDartGuns(Fighter *dart); +static void randomizeDart(Entity *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)); - memset(f, 0, sizeof(Fighter)); + f = malloc(sizeof(Entity)); + memset(f, 0, sizeof(Entity)); def = getFighterDef(name); - memcpy(f, def, sizeof(Fighter)); + memcpy(f, def, sizeof(Entity)); f->next = NULL; - battle.fighterTail->next = f; - battle.fighterTail = f; + battle.entityTail->next = f; + battle.entityTail = f; f->x = x; f->y = y; @@ -79,7 +79,7 @@ Fighter *spawnFighter(char *name, int x, int y, int side) return f; } -static void randomizeDart(Fighter *dart) +static void randomizeDart(Entity *dart) { char textureName[MAX_DESCRIPTION_LENGTH]; @@ -111,7 +111,7 @@ static void randomizeDart(Fighter *dart) dart->texture = getTexture(textureName); } -static void randomizeDartGuns(Fighter *dart) +static void randomizeDartGuns(Entity *dart) { int i; @@ -153,163 +153,150 @@ static void randomizeDartGuns(Fighter *dart) } } -void doFighters(void) +void doFighter(Entity *f, Entity *prev) { - Fighter *f, *prev; - - battle.numAllies = battle.numEnemies = 0; - - prev = &battle.fighterHead; - - for (f = battle.fighterHead.next ; f != NULL ; f = f->next) + if (player != NULL) { - self = f; - - if (player != NULL) + if (f != player && f->health > 0) { - 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) + { + 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 (!f->shieldRecharge) + { + f->shield = MIN(f->shield + 1, f->maxShield); + f->shieldRecharge = f->shieldRechargeRate; + } + + if (f->action == NULL && f->defaultAction != NULL) + { + f->action = f->defaultAction; + } + } + + if (f->action != NULL) + { + if (--f->thinkTime <= 0) + { + f->thinkTime = 0; + f->action(); + } + } + + if (f->alive == ALIVE_ALIVE) + { + if (f->health <= 0) + { + f->health = 0; + f->alive = ALIVE_DYING; + f->die(); - if (f->side == player->side) + if (f == battle.missionTarget) { - battle.numAllies++; - } - else - { - battle.numEnemies++; + battle.missionTarget = NULL; } } - - if (self->target != NULL && self->target->health <= 0) + else if (f->systemPower <= 0) { - self->action = self->defaultAction; - self->target = NULL; - } - - if (!battle.missionTarget && f->flags & FF_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); + f->dx *= 0.99; + f->dy *= 0.99; + f->thrust = 0; + f->shield = f->maxShield = 0; + f->action = NULL; - if (self->thrust > 0.25) + if (f->alive == ALIVE_ALIVE) { - addEngineEffect(); - } - - if (!f->shieldRecharge) - { - f->shield = MIN(f->shield + 1, f->maxShield); - f->shieldRecharge = f->shieldRechargeRate; - } - - if (f->action == NULL && f->defaultAction != NULL) - { - f->action = f->defaultAction; + updateObjective(f->name, TT_DISABLE); + battle.stats[STAT_DISABLED]++; } } - - if (f->action != NULL) + } + + if (f->alive == ALIVE_DEAD) + { + if (f == player) { - if (--f->thinkTime <= 0) - { - f->thinkTime = 0; - f->action(); - } + battle.stats[STAT_PLAYER_KILLED]++; } - - if (f->alive == ALIVE_ALIVE) + else if (player != NULL) { - if (f->health <= 0) + if (player->alive == ALIVE_ALIVE) { - f->health = 0; - f->alive = ALIVE_DYING; - f->die(); - - if (f == battle.missionTarget) + if (f->side != player->side) { - battle.missionTarget = NULL; - } - } - 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_DISABLE); - battle.stats[STAT_DISABLED]++; + 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->alive == ALIVE_DEAD) + if (f == battle.entityTail) { - if (f == player) - { - 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; + battle.entityTail = 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; float dx, dy, force; int count; - Fighter *f; + Entity *f; dx = dy = 0; count = 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) { @@ -357,58 +344,54 @@ static void separate(void) } } -void drawFighters(void) +void drawFighter(Entity *e) { - Fighter *f; SDL_Rect r; 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); - - if (f->armourHit > 0) + SDL_SetTextureColorMod(e->texture, 255, 255 - e->armourHit, 255 - e->armourHit); + } + + 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); - } - - if (f->systemHit > 0) - { - SDL_SetTextureColorMod(f->texture, 255 - f->systemHit, 255, 255); - } - - blitRotated(f->texture, f->x, f->y, f->angle); - - 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); - } + r.x = e->x - 32; + r.y = e->y - 32; + r.w = 64; + r.h = 64; - 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); - } + SDL_SetRenderDrawColor(app.renderer, 255, 64, 0, 255); + SDL_RenderDrawRect(app.renderer, &r); + } + + if (e == battle.missionTarget) + { + r.x = e->x - 28; + r.y = e->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)); } -void damageFighter(Fighter *f, int amount, long flags) +void damageFighter(Entity *f, int amount, long flags) { if (flags & BF_SYSTEM_DAMAGE) { diff --git a/src/battle/fighters.h b/src/battle/fighters.h index eea1839..70dc095 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -35,12 +35,12 @@ extern void addSmallFighterExplosion(void); extern void playBattleSound(int id, int x, int y); extern void updateObjective(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 checkTrigger(char *name, int type); extern App app; extern Battle battle; extern Colors colors; -extern Fighter *player; -extern Fighter *self; +extern Entity *player; +extern Entity *self; diff --git a/src/battle/hud.h b/src/battle/hud.h index 14b41a5..d2aa748 100644 --- a/src/battle/hud.h +++ b/src/battle/hud.h @@ -36,4 +36,4 @@ extern void drawRadar(void); extern App app; extern Battle battle; extern Colors colors; -extern Fighter *player; +extern Entity *player; diff --git a/src/battle/player.c b/src/battle/player.c index 83de399..65ef66a 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -102,7 +102,7 @@ void doPlayer(void) } } - player->angle = player->angle % 360; + player->angle = ((int)player->angle) % 360; player->x = SCREEN_WIDTH / 2; player->y = SCREEN_HEIGHT / 2; @@ -136,13 +136,13 @@ static void selectTarget(void) { unsigned int closest = 65535; unsigned int dist = 65535; - Fighter *f; + Entity *f; 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); if (dist < closest) diff --git a/src/battle/player.h b/src/battle/player.h index 5e4ee36..b2602a2 100644 --- a/src/battle/player.h +++ b/src/battle/player.h @@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../defs.h" #include "../structs.h" -extern void fireGuns(Fighter *owner); -extern void fireMissile(Fighter *owner); +extern void fireGuns(Entity *owner); +extern void fireMissile(Entity *owner); extern void applyFighterThrust(void); extern void applyFighterBrakes(void); extern int getDistance(int x1, int y1, int x2, int y2); @@ -32,5 +32,5 @@ extern void failIncompleteObjectives(void); extern App app; extern Battle battle; -extern Fighter *player; -extern Fighter *self; +extern Entity *player; +extern Entity *self; diff --git a/src/battle/radar.c b/src/battle/radar.c index e320ca8..3ee5614 100644 --- a/src/battle/radar.c +++ b/src/battle/radar.c @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void drawRadar(void) { SDL_Rect r; - Fighter *f; + Entity *f; drawFilledCircle(SCREEN_WIDTH - 85, SCREEN_HEIGHT - 85, 75, 0, 128, 0, 32); @@ -34,7 +34,7 @@ void drawRadar(void) 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) { diff --git a/src/battle/radar.h b/src/battle/radar.h index 237161d..8479772 100644 --- a/src/battle/radar.h +++ b/src/battle/radar.h @@ -29,4 +29,4 @@ extern int getDistance(int x1, int y1, int x2, int y2); extern App app; extern Battle battle; -extern Fighter *player; +extern Entity *player; diff --git a/src/battle/waypoints.c b/src/battle/waypoints.c index 3a69da0..f7e61c9 100644 --- a/src/battle/waypoints.c +++ b/src/battle/waypoints.c @@ -29,6 +29,7 @@ Entity *spawnWaypoint(void) battle.entityTail->next = waypoint; battle.entityTail = waypoint; + waypoint->type = ET_WAYPOINT; waypoint->health = waypoint->maxHealth = FPS; waypoint->texture = getTexture("gfx/entities/waypoint.png"); waypoint->action = rotate; @@ -38,5 +39,9 @@ Entity *spawnWaypoint(void) static void rotate(void) { - + self->angle += 0.1; + if (self->angle >= 360) + { + self -= 360; + } } diff --git a/src/battle/waypoints.h b/src/battle/waypoints.h index 588a06a..f7b2553 100644 --- a/src/battle/waypoints.h +++ b/src/battle/waypoints.h @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../defs.h" #include "../structs.h" -extern Battle battle; - extern SDL_Texture *getTexture(char *filename); + +extern Battle battle; +extern Entity *self; diff --git a/src/defs.h b/src/defs.h index 9a05eb1..39e705b 100644 --- a/src/defs.h +++ b/src/defs.h @@ -51,14 +51,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define BF_SYSTEM_DAMAGE (2 << 1) #define BF_EXPLODES (2 << 2) -#define FF_NONE 0 -#define FF_NO_KILL (2 << 0) -#define FF_DISABLE (2 << 1) -#define FF_IMMORTAL (2 << 2) -#define FF_MISSION_TARGET (2 << 3) +#define EF_NONE 0 +#define EF_NO_KILL (2 << 0) +#define EF_DISABLE (2 << 1) +#define EF_IMMORTAL (2 << 2) +#define EF_MISSION_TARGET (2 << 3) enum { + ET_FIGHTER, ET_WAYPOINT }; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 6496c22..9f2c687 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -174,7 +174,7 @@ static void loadPlayer(cJSON *node) static void loadFighters(cJSON *node) { - Fighter *f; + Entity *f; char *type; int side, x, y; @@ -205,7 +205,7 @@ static void loadFighters(cJSON *node) static void loadFighterGroups(cJSON *node) { - Fighter *f; + Entity *f; char **types, *name, *type; int side, x, y, scatter, number; int i, numTypes; diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 9ba9e15..be3d88c 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern long lookup(char *name); extern char *readFile(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 endSectionTransition(void); extern void playMusic(char *filename); @@ -38,5 +38,5 @@ extern long flagsToLong(char *flags); extern Entity *spawnWaypoint(void); extern Battle battle; -extern Fighter *player; +extern Entity *player; extern Game game; diff --git a/src/game/title.c b/src/game/title.c index d8fecda..7d8d767 100644 --- a/src/game/title.c +++ b/src/game/title.c @@ -37,7 +37,7 @@ static SDL_Texture *logo; static SDL_Texture *pandoranWar; static SDL_Texture *earthTexture; 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 int showingOptions; @@ -99,7 +99,7 @@ static void initFighters(void) 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++) { diff --git a/src/game/title.h b/src/game/title.h index 77e2535..e2ebb3a 100644 --- a/src/game/title.h +++ b/src/game/title.h @@ -60,4 +60,4 @@ extern App app; extern Battle battle; extern Colors colors; extern Game game; -extern Fighter *self; +extern Entity *self; diff --git a/src/main.h b/src/main.h index 71dffa7..d4b7a1a 100644 --- a/src/main.h +++ b/src/main.h @@ -35,6 +35,6 @@ extern void saveScreenshot(void); App app; Colors colors; Battle battle; -Fighter *self; -Fighter *player; +Entity *self; +Entity *player; Game game; diff --git a/src/structs.h b/src/structs.h index 3d1d523..8654abf 100644 --- a/src/structs.h +++ b/src/structs.h @@ -22,7 +22,6 @@ typedef struct SDL_Texture SDL_Texture; typedef struct Texture Texture; typedef struct Lookup Lookup; typedef struct Weapon Weapon; -typedef struct Fighter Fighter; typedef struct Entity Entity; typedef struct Bullet Bullet; typedef struct Effect Effect; @@ -71,26 +70,6 @@ struct Weapon { struct Entity { 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]; int active; int side; @@ -100,7 +79,7 @@ struct Fighter { float dy; float thrust; float speed; - int angle; + float angle; int alive; int health; int maxHealth; @@ -122,12 +101,12 @@ struct Fighter { Weapon guns[MAX_FIGHTER_GUNS]; Weapon missiles; long flags; - Fighter *target; + Entity *target; void (*action)(void); void (*defaultAction)(void); void (*die)(void); SDL_Texture *texture; - Fighter *next; + Entity *next; }; struct Bullet { @@ -142,8 +121,8 @@ struct Bullet { int angle; long flags; SDL_Texture *texture; - Fighter *owner; - Fighter *target; + Entity *owner; + Entity *target; Bullet *next; }; @@ -241,10 +220,9 @@ typedef struct { int status; int missionFinishedTimer; int numObjectivesComplete, numObjectivesTotal; - Fighter *missionTarget; + Entity *missionTarget; SDL_Texture *background, *planetTexture; PointF planet; - Fighter fighterHead, *fighterTail; Entity entityHead, *entityTail; Bullet bulletHead, *bulletTail; Effect effectHead, *effectTail; diff --git a/src/system/lookup.c b/src/system/lookup.c index c9f28c7..b1d5cef 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -32,10 +32,10 @@ void initLookups(void) addLookup("ET_WAYPOINT", ET_WAYPOINT); - addLookup("FF_NO_KILL", FF_NO_KILL); - addLookup("FF_DISABLE", FF_DISABLE); - addLookup("FF_IMMORTAL", FF_IMMORTAL); - addLookup("FF_MISSION_TARGET", FF_MISSION_TARGET); + addLookup("EF_NO_KILL", EF_NO_KILL); + addLookup("EF_DISABLE", EF_DISABLE); + addLookup("EF_IMMORTAL", EF_IMMORTAL); + addLookup("EF_MISSION_TARGET", EF_MISSION_TARGET); addLookup("TT_DESTROY", TT_DESTROY); addLookup("TT_DISABLE", TT_DISABLE); diff --git a/src/system/sound.h b/src/system/sound.h index eea849a..c226cb4 100644 --- a/src/system/sound.h +++ b/src/system/sound.h @@ -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 Fighter *player; +extern Entity *player;