From a9dc374d403833a9f72948a8056160e4f4f12b48 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 17 Nov 2015 07:23:50 +0000 Subject: [PATCH] Added new stats. --- src/battle/battle.c | 8 +++++--- src/battle/bullets.c | 13 +++++++++++++ src/battle/challenges.c | 2 +- src/battle/fighters.c | 19 +++++++++++-------- src/battle/items.c | 9 +++++++-- src/battle/items.h | 4 +++- src/battle/player.c | 8 ++++++++ src/battle/player.h | 1 + src/battle/rope.c | 7 ++++++- src/battle/rope.h | 1 + src/defs.h | 16 ++++++++++++++-- src/galaxy/galacticMap.c | 4 ++-- src/galaxy/mission.c | 10 ++++++++++ src/galaxy/stats.c | 12 +++++++++++- src/system/lookup.c | 14 ++++++++++++-- 15 files changed, 105 insertions(+), 23 deletions(-) diff --git a/src/battle/battle.c b/src/battle/battle.c index 8b05646..939385a 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -310,10 +310,12 @@ static void postBattle(void) { int i; - /* we don't want to count the time when adding up stats */ - for (i = 0 ; i < STAT_TIME ; i++) + for (i = 0 ; i < STAT_MAX ; i++) { - game.stats[i] += battle.stats[i]; + if (i != STAT_TIME && i != STAT_EPIC_KILL_STREAK) + { + game.stats[i] += battle.stats[i]; + } } if (game.currentMission && !game.currentMission->completed) diff --git a/src/battle/bullets.c b/src/battle/bullets.c index 832042a..16d99a1 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -89,6 +89,12 @@ void doBullets(void) if (--b->life <= 0) { + + if (player != NULL && player->alive == ALIVE_ALIVE && b->type == BT_MISSILE && b->damage > 0 && b->target == player) + { + battle.stats[STAT_MISSILES_EVADED]++; + } + if (b == battle.bulletTail) { battle.bulletTail = prev; @@ -140,16 +146,23 @@ static void checkCollisions(Bullet *b) damageFighter(e, b->damage, b->flags); b->life = 0; + b->damage = 0; if (b->flags & BF_EXPLODES) { addMissileExplosion(b); + + if (e == player) + { + battle.stats[STAT_MISSILES_STRUCK]++; + } } /* assuming that health <= 0 will always mean killed */ if (e->health <= 0 && b->owner == player) { battle.stats[STAT_ENEMIES_KILLED_PLAYER]++; + battle.stats[STAT_EPIC_KILL_STREAK]++; } if (b->owner == player && b->type == BT_MISSILE) diff --git a/src/battle/challenges.c b/src/battle/challenges.c index cc7677b..28b0e29 100644 --- a/src/battle/challenges.c +++ b/src/battle/challenges.c @@ -152,7 +152,7 @@ static void updateDisabledChallenge(Challenge *c) { if (!c->passed) { - c->passed = battle.stats[STAT_DISABLED] >= c->targetValue; + c->passed = battle.stats[STAT_ENEMIES_DISABLED] >= c->targetValue; } } diff --git a/src/battle/fighters.c b/src/battle/fighters.c index a7d52f3..9c6eebc 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -211,7 +211,7 @@ void doFighter(void) { self->flags |= EF_DISABLED; updateObjective(self->name, TT_DISABLE); - battle.stats[STAT_DISABLED]++; + battle.stats[STAT_ENEMIES_DISABLED]++; } } } @@ -223,9 +223,9 @@ void doFighter(void) addHudMessage(colors.red, "Mission target has escaped."); battle.stats[STAT_ENEMIES_ESCAPED]++; } - else + else if (self->flags & EF_CIVILIAN) { - battle.stats[STAT_ALLIES_ESCAPED]++; + battle.stats[STAT_CIVILIANS_RESCUED]++; } updateObjective(self->name, TT_ESCAPED); @@ -251,15 +251,18 @@ void doFighter(void) } else { - battle.stats[STAT_ALLIES_KILLED]++; - - if (!battle.epic) + if (self->flags & EF_CIVILIAN) { - if (self->flags & EF_CIVILIAN) + battle.stats[STAT_CIVILIANS_KILLED]++; + if (!battle.epic) { addHudMessage(colors.red, "Civilian has been killed"); } - else + } + else + { + battle.stats[STAT_ALLIES_KILLED]++; + if (!battle.epic) { addHudMessage(colors.red, "Ally has been killed"); } diff --git a/src/battle/items.c b/src/battle/items.c index 2d91d14..20642d8 100644 --- a/src/battle/items.c +++ b/src/battle/items.c @@ -107,12 +107,17 @@ static void action(void) if ((e->flags & EF_COLLECTS_ITEMS) && collision(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h)) { self->alive = ALIVE_DEAD; - playSound(SND_GET_ITEM); - addHudMessage(colors.white, "Picked up %s", self->name); + playBattleSound(SND_GET_ITEM, self->x, self->y); updateObjective(self->name, TT_ITEM); checkTrigger(self->name, TRIGGER_ITEM); + + if (e == player) + { + addHudMessage(colors.white, "Picked up %s", self->name); + battle.stats[STAT_ITEMS_COLLECTED]++; + } } } } diff --git a/src/battle/items.h b/src/battle/items.h index a900ada..bb2da56 100644 --- a/src/battle/items.h +++ b/src/battle/items.h @@ -31,10 +31,12 @@ extern long flagsToLong(char *flags); extern Entity *spawnEntity(void); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); -extern void playSound(int id); +extern void playBattleSound(int id, int x, int y); extern void addHudMessage(SDL_Color c, char *format, ...); extern void updateObjective(char *name, int type); extern void checkTrigger(char *name, int type); +extern Battle battle; extern Entity *self; +extern Entity *player; extern Colors colors; diff --git a/src/battle/player.c b/src/battle/player.c index a7481e3..9c96ccc 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -62,6 +62,10 @@ void initPlayer(void) battle.boostTimer = BOOST_RECHARGE_TIME; battle.ecmTimer = ECM_RECHARGE_TIME; + + game.stats[STAT_EPIC_KILL_STREAK] = MAX(game.stats[STAT_EPIC_KILL_STREAK], battle.stats[STAT_EPIC_KILL_STREAK]); + + battle.stats[STAT_EPIC_KILL_STREAK] = 0; } void doPlayer(void) @@ -246,6 +250,8 @@ static void activateBoost(void) self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy)); battle.boostTimer = 0; + + battle.stats[STAT_BOOST]++; } static void deactivateBoost(void) @@ -268,6 +274,8 @@ static void deactivateBoost(void) static void activateECM(void) { battle.ecmTimer = 0; + + battle.stats[STAT_ECM]++; } static void switchGuns(void) diff --git a/src/battle/player.h b/src/battle/player.h index 432165c..b6c4144 100644 --- a/src/battle/player.h +++ b/src/battle/player.h @@ -40,3 +40,4 @@ extern Battle battle; extern Colors colors; extern Entity *player; extern Entity *self; +extern Game game; diff --git a/src/battle/rope.c b/src/battle/rope.c index 0614d48..f3ae743 100644 --- a/src/battle/rope.c +++ b/src/battle/rope.c @@ -39,7 +39,12 @@ void attachRope(void) { self->towing = e; e->owner = self; - addHudMessage(colors.white, "Tow rope attached"); + + if (self == player) + { + battle.stats[STAT_NUM_TOWED]++; + addHudMessage(colors.white, "Tow rope attached"); + } } } } diff --git a/src/battle/rope.h b/src/battle/rope.h index be3c4fc..6472a88 100644 --- a/src/battle/rope.h +++ b/src/battle/rope.h @@ -34,3 +34,4 @@ extern App app; extern Battle battle; extern Colors colors; extern Entity *self; +extern Entity *player; diff --git a/src/defs.h b/src/defs.h index 324deef..02321fd 100644 --- a/src/defs.h +++ b/src/defs.h @@ -108,6 +108,7 @@ enum { SIDE_NONE, SIDE_ALLIES, + SIDE_REBEL, SIDE_PANDORAN, SIDE_PIRATE, SIDE_CSN, @@ -241,9 +242,20 @@ enum STAT_ENEMIES_KILLED_PLAYER, STAT_ALLIES_KILLED, STAT_PLAYER_KILLED, - STAT_DISABLED, + STAT_ENEMIES_DISABLED, STAT_ENEMIES_ESCAPED, - STAT_ALLIES_ESCAPED, + STAT_ECM, + STAT_BOOST, + STAT_MISSILES_EVADED, + STAT_MISSILES_STRUCK, + STAT_CIVILIANS_RESCUED, + STAT_CIVILIANS_KILLED, + STAT_TUG, + STAT_SHUTTLE, + STAT_NUM_TOWED, + STAT_ITEMS_COLLECTED, + STAT_EPIC_KILL_STREAK, + /* add stats before here, so as not to mess up the stats screen */ STAT_TIME, STAT_MAX }; diff --git a/src/galaxy/galacticMap.c b/src/galaxy/galacticMap.c index fc571a2..b0ce0fc 100644 --- a/src/galaxy/galacticMap.c +++ b/src/galaxy/galacticMap.c @@ -422,8 +422,8 @@ static void drawInfoBars(void) SDL_RenderFillRect(app.renderer, &r); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); - drawText((SCREEN_WIDTH / 2) - 50, 5, 18, TA_RIGHT, colors.white, "Missions %d / %d", completedMissions, totalMissions); - drawText((SCREEN_WIDTH / 2) + 50, 5, 18, TA_LEFT, colors.white, "Challenges %d / %d", completedChallenges, totalChallenges); + drawText((SCREEN_WIDTH / 2) - 50, 5, 18, TA_RIGHT, colors.white, "Missions: %d / %d", completedMissions, totalMissions); + drawText((SCREEN_WIDTH / 2) + 50, 5, 18, TA_LEFT, colors.white, "Challenges: %d / %d", completedChallenges, totalChallenges); } static void selectStarSystem(void) diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index f8ed906..1ffeb1b 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -210,6 +210,16 @@ static void loadPlayer(cJSON *node) player = spawnFighter(type, 0, 0, side); player->x = (GRID_SIZE * GRID_CELL_WIDTH) / 2; player->y = (GRID_SIZE * GRID_CELL_HEIGHT) / 2; + + if (strcmp(type, "Tug") == 0) + { + battle.stats[STAT_TUG]++; + } + + if (strcmp(type, "Shuttle") == 0) + { + battle.stats[STAT_SHUTTLE]++; + } } static void loadFighters(cJSON *node) diff --git a/src/galaxy/stats.c b/src/galaxy/stats.c index a3a27d7..41a3618 100644 --- a/src/galaxy/stats.c +++ b/src/galaxy/stats.c @@ -33,7 +33,17 @@ static char *statDescription[] = { "Times Killed", "Enemies Disabled", "Enemies Escaped", - "Allies Escaped", + "ECM Used", + "Boost Used", + "Missiles Evaded", + "Missiles Struck Player", + "Civilians Rescued", + "Civilians Killed", + "Times used Tug", + "Times used Shuttle", + "Craft Towed", + "Items Collected", + "Longest Epic Kill Streak", "STAT_TIME" }; diff --git a/src/system/lookup.c b/src/system/lookup.c index 264464d..98f3a71 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -101,9 +101,19 @@ void initLookups(void) addLookup("STAT_ENEMIES_KILLED_PLAYER", STAT_ENEMIES_KILLED_PLAYER); addLookup("STAT_ALLIES_KILLED", STAT_ALLIES_KILLED); addLookup("STAT_PLAYER_KILLED", STAT_PLAYER_KILLED); - addLookup("STAT_DISABLED", STAT_DISABLED); + addLookup("STAT_ENEMIES_DISABLED", STAT_ENEMIES_DISABLED); addLookup("STAT_ENEMIES_ESCAPED", STAT_ENEMIES_ESCAPED); - addLookup("STAT_ALLIES_ESCAPED", STAT_ALLIES_ESCAPED); + addLookup("STAT_CIVILIANS_RESCUED", STAT_CIVILIANS_RESCUED); + addLookup("STAT_ECM", STAT_ECM); + addLookup("STAT_BOOST", STAT_BOOST); + addLookup("STAT_MISSILES_EVADED", STAT_MISSILES_EVADED); + addLookup("STAT_MISSILES_STRUCK", STAT_MISSILES_STRUCK); + addLookup("STAT_CIVILIANS_KILLED", STAT_CIVILIANS_KILLED); + addLookup("STAT_TUG", STAT_TUG); + addLookup("STAT_SHUTTLE", STAT_SHUTTLE); + addLookup("STAT_NUM_TOWED", STAT_NUM_TOWED); + addLookup("STAT_ITEMS_COLLECTED", STAT_ITEMS_COLLECTED); + addLookup("STAT_EPIC_KILL_STREAK", STAT_EPIC_KILL_STREAK); addLookup("STAT_TIME", STAT_TIME); addLookup("TRIGGER_TIME", TRIGGER_TIME);