From 5081b011cf83e9563af19775d4526334319cafa1 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 24 Oct 2015 16:00:06 +0100 Subject: [PATCH] Allow disabled fighters to be destroyed. Added more challenges and stats. --- .../temper/03 - pirate uprising #3.json | 10 +++++ src/battle/bullets.c | 2 +- src/battle/challenges.c | 34 +++++++++++++-- src/battle/fighters.c | 42 ++++++++++--------- src/defs.h | 7 ++-- src/galaxy/stats.c | 2 +- src/structs.h | 21 +++++----- src/system/load.c | 34 ++++++++++----- src/system/lookup.c | 2 + src/system/save.c | 1 + src/test/testMission.c | 40 ++++++++++++++++++ src/test/testMission.h | 3 ++ 12 files changed, 149 insertions(+), 49 deletions(-) diff --git a/data/missions/temper/03 - pirate uprising #3.json b/data/missions/temper/03 - pirate uprising #3.json index 7bbcd9a..58ba7d4 100644 --- a/data/missions/temper/03 - pirate uprising #3.json +++ b/data/missions/temper/03 - pirate uprising #3.json @@ -25,6 +25,16 @@ "isCondition" : 1 } ], + "challenges" : [ + { + "type" : "CHALLENGE_TIME_MINS", + "targetValue" : 3 + }, + { + "type" : "CHALLENGE_DISABLE", + "targetValue" : 3 + } + ], "player" : { "type" : "Ray", "side" : "SIDE_ALLIES", diff --git a/src/battle/bullets.c b/src/battle/bullets.c index edb4c02..28debb3 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -166,7 +166,7 @@ static void faceTarget(Bullet *b) brakeAmount = angleDist; brakeAmount /= 360; - brakeAmount = 0.7 - brakeAmount; + brakeAmount = 0.6 - brakeAmount; /* halve your speed while you're not at the correct angle */ b->dx *= brakeAmount; diff --git a/src/battle/challenges.c b/src/battle/challenges.c index 1ce0055..18b1e05 100644 --- a/src/battle/challenges.c +++ b/src/battle/challenges.c @@ -25,6 +25,7 @@ static void updateAccuracyChallenge(Challenge *c); static void updateArmourChallenge(Challenge *c); static void updateLossesChallenge(Challenge *c); static void updatePlayerKillsChallenge(Challenge *c); +static void updateDisabledChallenge(Challenge *c); static char *getFormattedChallengeDescription(const char *format, ...); char *getChallengeDescription(Challenge *c); @@ -37,7 +38,9 @@ static char *challengeDescription[] = { "Do not lose any team mates", "Do not lose more than 1 team mate", "Do not lose more than %d team mates", - "Take down %d enemy targets" + "Take down %d enemy targets", + "Disable %d or more enemy fighters", + "Finish mission in %d minutes or less" }; void updateChallenges(void) @@ -51,6 +54,7 @@ void updateChallenges(void) switch (c->type) { case CHALLENGE_TIME: + case CHALLENGE_TIME_MINS: updateTimeChallenge(c); break; @@ -71,6 +75,10 @@ void updateChallenges(void) case CHALLENGE_PLAYER_KILLS: updatePlayerKillsChallenge(c); break; + + case CHALLENGE_DISABLE: + updateDisabledChallenge(c); + break; } } } @@ -78,9 +86,21 @@ void updateChallenges(void) static void updateTimeChallenge(Challenge *c) { - if (battle.stats.time / FPS <= c->targetValue) + switch (c->type) { - c->passed = 1; + case CHALLENGE_TIME: + if (battle.stats.time / FPS <= c->targetValue) + { + c->passed = 1; + } + break; + + case CHALLENGE_TIME_MINS: + if ((battle.stats.time / FPS) / 60 <= c->targetValue) + { + c->passed = 1; + } + break; } } @@ -128,6 +148,14 @@ static void updatePlayerKillsChallenge(Challenge *c) } } +static void updateDisabledChallenge(Challenge *c) +{ + if (!c->passed) + { + c->passed = battle.stats.disabled >= c->targetValue; + } +} + char *getChallengeDescription(Challenge *c) { return getFormattedChallengeDescription(challengeDescription[c->type], c->targetValue); diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 846bc48..1dafad6 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -236,30 +236,32 @@ void doFighters(void) } } - if (f->health <= 0 && f->alive == ALIVE_ALIVE) + if (f->alive == ALIVE_ALIVE) { - f->health = 0; - f->alive = ALIVE_DYING; - f->die(); - - if (f == battle.missionTarget) + if (f->health <= 0) { - battle.missionTarget = NULL; + f->health = 0; + f->alive = ALIVE_DYING; + f->die(); + + if (f == battle.missionTarget) + { + battle.missionTarget = NULL; + } } - } - - 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) + else if (f->systemPower <= 0) { - updateObjective(f->name, TT_DISABLE); - f->alive = ALIVE_DISABLED; + 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.disabled++; + } } } diff --git a/src/defs.h b/src/defs.h index a24f4fa..8f2cb40 100644 --- a/src/defs.h +++ b/src/defs.h @@ -68,8 +68,7 @@ enum { ALIVE_ALIVE, ALIVE_DYING, - ALIVE_DEAD, - ALIVE_DISABLED + ALIVE_DEAD }; enum @@ -167,5 +166,7 @@ enum CHALLENGE_NO_LOSSES, CHALLENGE_1_LOSS, CHALLENGE_LOSSES, - CHALLENGE_PLAYER_KILLS + CHALLENGE_PLAYER_KILLS, + CHALLENGE_DISABLE, + CHALLENGE_TIME_MINS }; diff --git a/src/galaxy/stats.c b/src/galaxy/stats.c index e7a4da4..ec4d1f9 100644 --- a/src/galaxy/stats.c +++ b/src/galaxy/stats.c @@ -86,7 +86,7 @@ void drawStats(void) drawText(r.x + 20, y, 18, TA_LEFT, colors.white, "Times Killed"); drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats.playerKilled); - y += 40; + y += 60; seconds = game.stats.time / FPS; minutes = (seconds / 60) % 60; diff --git a/src/structs.h b/src/structs.h index 2569500..28ebfb3 100644 --- a/src/structs.h +++ b/src/structs.h @@ -202,16 +202,17 @@ struct StarSystem { }; typedef struct { - int missionsStarted; - int missionsCompleted; - int shotsFired; - int shotsHit; - int missilesFired; - int missilesHit; - int enemiesKilled; - int alliesKilled; - int playerKilled; - int playerKills; + unsigned int missionsStarted; + unsigned int missionsCompleted; + unsigned int shotsFired; + unsigned int shotsHit; + unsigned int missilesFired; + unsigned int missilesHit; + unsigned int enemiesKilled; + unsigned int alliesKilled; + unsigned int playerKilled; + unsigned int playerKills; + unsigned int disabled; unsigned int time; } Stats; diff --git a/src/system/load.c b/src/system/load.c index 5942235..9d25d01 100644 --- a/src/system/load.c +++ b/src/system/load.c @@ -24,6 +24,7 @@ static void loadStats(cJSON *stats); static void loadStarSystems(cJSON *starSystemsJSON); static void loadMissions(StarSystem *starSystem, cJSON *missionsCJSON); static void loadChallenges(Mission *mission, cJSON *challengesCJSON); +static int getStat(cJSON *stats, char *name); void loadGame(void) { @@ -95,15 +96,26 @@ static void loadChallenges(Mission *mission, cJSON *challengesCJSON) static void loadStats(cJSON *stats) { - game.stats.missionsStarted = cJSON_GetObjectItem(stats, "missionsStarted")->valueint; - game.stats.missionsCompleted = cJSON_GetObjectItem(stats, "missionsCompleted")->valueint; - game.stats.shotsFired = cJSON_GetObjectItem(stats, "shotsFired")->valueint; - game.stats.shotsHit = cJSON_GetObjectItem(stats, "shotsHit")->valueint; - game.stats.missilesFired = cJSON_GetObjectItem(stats, "missilesFired")->valueint; - game.stats.missilesHit = cJSON_GetObjectItem(stats, "missilesHit")->valueint; - game.stats.enemiesKilled = cJSON_GetObjectItem(stats, "enemiesKilled")->valueint; - game.stats.alliesKilled = cJSON_GetObjectItem(stats, "alliesKilled")->valueint; - game.stats.playerKilled = cJSON_GetObjectItem(stats, "playerKilled")->valueint; - game.stats.playerKills = cJSON_GetObjectItem(stats, "playerKills")->valueint; - game.stats.time = cJSON_GetObjectItem(stats, "time")->valueint; + game.stats.missionsStarted = getStat(stats, "missionsStarted"); + game.stats.missionsCompleted = getStat(stats, "missionsCompleted"); + game.stats.shotsFired = getStat(stats, "shotsFired"); + game.stats.shotsHit = getStat(stats, "shotsHit"); + game.stats.missilesFired = getStat(stats, "missilesFired"); + game.stats.missilesHit = getStat(stats, "missilesHit"); + game.stats.enemiesKilled = getStat(stats, "enemiesKilled"); + game.stats.alliesKilled = getStat(stats, "alliesKilled"); + game.stats.playerKilled = getStat(stats, "playerKilled"); + game.stats.playerKills = getStat(stats, "playerKills"); + game.stats.disabled = getStat(stats, "disabled"); + game.stats.time = getStat(stats, "time"); +} + +static int getStat(cJSON *stats, char *name) +{ + if (cJSON_GetObjectItem(stats, name)) + { + return cJSON_GetObjectItem(stats, name)->valueint; + } + + return 0; } diff --git a/src/system/lookup.c b/src/system/lookup.c index 7cf5ff8..580da7f 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -76,6 +76,8 @@ void initLookups(void) addLookup("CHALLENGE_1_LOSS", CHALLENGE_1_LOSS); addLookup("CHALLENGE_LOSSES", CHALLENGE_LOSSES); addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS); + addLookup("CHALLENGE_DISABLE", CHALLENGE_DISABLE); + addLookup("CHALLENGE_TIME_MINS", CHALLENGE_TIME_MINS); } static void addLookup(char *name, long value) diff --git a/src/system/save.c b/src/system/save.c index 4c2126d..4c521ac 100644 --- a/src/system/save.c +++ b/src/system/save.c @@ -128,6 +128,7 @@ static void saveStats(cJSON *gameJSON) cJSON_AddNumberToObject(stats, "alliesKilled", game.stats.alliesKilled); cJSON_AddNumberToObject(stats, "playerKilled", game.stats.playerKilled); cJSON_AddNumberToObject(stats, "playerKills", game.stats.playerKills); + cJSON_AddNumberToObject(stats, "disabled", game.stats.disabled); cJSON_AddNumberToObject(stats, "time", game.stats.time); cJSON_AddItemToObject(gameJSON, "stats", stats); diff --git a/src/test/testMission.c b/src/test/testMission.c index 2ed1f4a..3145b2a 100644 --- a/src/test/testMission.c +++ b/src/test/testMission.c @@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static Mission mission; +static void loadChallenges(char *filename); + void loadTestMission(char *filename) { memset(&mission, 0, sizeof(Mission)); @@ -33,4 +35,42 @@ void loadTestMission(char *filename) initBattle(); loadMission(filename); + loadChallenges(filename); +} + +static void loadChallenges(char *filename) +{ + Challenge *challenge, *challengeTail; + cJSON *root, *node; + char *text; + + text = readFile(filename); + + root = cJSON_Parse(text); + + challengeTail = &mission.challengeHead; + + node = cJSON_GetObjectItem(root, "challenges"); + + if (node) + { + node = node->child; + + while (node) + { + challenge = malloc(sizeof(Challenge)); + memset(challenge, 0, sizeof(Challenge)); + + challenge->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring); + challenge->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint; + + challengeTail->next = challenge; + challengeTail = challenge; + + node = node->next; + } + } + + cJSON_Delete(root); + free(text); } diff --git a/src/test/testMission.h b/src/test/testMission.h index a2692ad..98992c5 100644 --- a/src/test/testMission.h +++ b/src/test/testMission.h @@ -22,8 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../defs.h" #include "../structs.h" +#include "../json/cJSON.h" extern void initBattle(void); extern void loadMission(char *filename); +extern long lookup(char *name); +extern char *readFile(char *filename); extern Game game;