From 0c31b2204c615711e203ded08eaaf2dd08cd4ab9 Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 2 Mar 2016 06:46:13 +0000 Subject: [PATCH] Refactored challenge data, for display on Challenge Home. --- src/battle/battle.c | 6 +++--- src/battle/hud.c | 6 +++--- src/battle/hud.h | 1 + src/battle/missionInfo.c | 18 ++++++++++-------- src/challenges/challenges.c | 12 ++++++------ src/galaxy/mission.c | 25 ++++++++----------------- src/structs.h | 20 ++++++++++---------- src/system/save.c | 2 +- 8 files changed, 42 insertions(+), 48 deletions(-) diff --git a/src/battle/battle.c b/src/battle/battle.c index ddd3764..f03b735 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -305,7 +305,7 @@ static void continueGame(void) destroyBattle(); - if (!battle.challengeData.isChallenge) + if (!game.currentMission->challengeData.isChallenge) { initGalacticMap(); } @@ -346,7 +346,7 @@ static void quitBattle(void) destroyBattle(); - if (!battle.challengeData.isChallenge) + if (!game.currentMission->challengeData.isChallenge) { initGalacticMap(); } @@ -368,7 +368,7 @@ static void postBattle(void) } } - if (!battle.challengeData.isChallenge) + if (!game.currentMission->challengeData.isChallenge) { if (game.currentMission && !game.currentMission->completed) { diff --git a/src/battle/hud.c b/src/battle/hud.c index 40371cc..8f2cb9e 100644 --- a/src/battle/hud.c +++ b/src/battle/hud.c @@ -402,15 +402,15 @@ static void drawNumFighters(void) static void drawObjectives(void) { - if (!battle.challengeData.isChallenge) + if (!game.currentMission->challengeData.isChallenge) { drawText(SCREEN_WIDTH / 2, 10, 16, TA_CENTER, colors.white, "%d / %d", battle.numObjectivesComplete, battle.numObjectivesTotal); } else { - if (battle.challengeData.timeLimit) + if (game.currentMission->challengeData.timeLimit) { - drawText(SCREEN_WIDTH / 2, 10, 16, TA_CENTER, colors.white, timeToString(battle.challengeData.timeLimit - battle.stats[STAT_TIME], 0)); + drawText(SCREEN_WIDTH / 2, 10, 16, TA_CENTER, colors.white, timeToString(game.currentMission->challengeData.timeLimit - battle.stats[STAT_TIME], 0)); } else { diff --git a/src/battle/hud.h b/src/battle/hud.h index 1b4cc34..832fc6e 100644 --- a/src/battle/hud.h +++ b/src/battle/hud.h @@ -39,3 +39,4 @@ extern App app; extern Battle battle; extern Colors colors; extern Entity *player; +extern Game game; diff --git a/src/battle/missionInfo.c b/src/battle/missionInfo.c index d9b651d..c3c76fa 100644 --- a/src/battle/missionInfo.c +++ b/src/battle/missionInfo.c @@ -32,15 +32,17 @@ static const char *objectiveStatus[OS_MAX]; void initMissionInfo(void) { + int isChallenge = game.currentMission->challengeData.isChallenge; + objectiveStatus[OS_INCOMPLETE] = _("Incomplete"); objectiveStatus[OS_COMPLETE] = _("Complete"); objectiveStatus[OS_FAILED] = _("Failed"); objectiveStatus[OS_CONDITION] = _("Condition"); - missionStartTexture = !battle.challengeData.isChallenge ? getTexture("gfx/battle/missionStart.png") : getTexture("gfx/battle/challengeStart.png"); - missionInProgressTexture = !battle.challengeData.isChallenge ? getTexture("gfx/battle/missionInProgress.png") : getTexture("gfx/battle/challengeInProgress.png"); - missionCompleteTexture = !battle.challengeData.isChallenge ? getTexture("gfx/battle/missionComplete.png") : getTexture("gfx/battle/challengeComplete.png"); - missionFailedTexture = !battle.challengeData.isChallenge ? getTexture("gfx/battle/missionFailed.png") : getTexture("gfx/battle/challengeFailed.png"); + missionStartTexture = !isChallenge ? getTexture("gfx/battle/missionStart.png") : getTexture("gfx/battle/challengeStart.png"); + missionInProgressTexture = !isChallenge ? getTexture("gfx/battle/missionInProgress.png") : getTexture("gfx/battle/challengeInProgress.png"); + missionCompleteTexture = !isChallenge ? getTexture("gfx/battle/missionComplete.png") : getTexture("gfx/battle/challengeComplete.png"); + missionFailedTexture = !isChallenge ? getTexture("gfx/battle/missionFailed.png") : getTexture("gfx/battle/challengeFailed.png"); } void drawMissionInfo(void) @@ -84,7 +86,7 @@ static void drawMissionSummary(SDL_Texture *header) blit(header, SCREEN_WIDTH / 2, 150, 1); - if (!battle.challengeData.isChallenge) + if (!game.currentMission->challengeData.isChallenge) { drawObjectives(); } @@ -153,16 +155,16 @@ static void drawChallenges(void) drawText(SCREEN_WIDTH / 2, y, 24, TA_CENTER, colors.white, game.currentMission->description); - if (battle.status == MS_START && battle.challengeData.timeLimit) + if (battle.status == MS_START && game.currentMission->challengeData.timeLimit) { y+= 50; - drawText(SCREEN_WIDTH / 2, y, 20, TA_CENTER, colors.white, "Time Limit: %s", timeToString(battle.challengeData.timeLimit, 0)); + drawText(SCREEN_WIDTH / 2, y, 20, TA_CENTER, colors.white, "Time Limit: %s", timeToString(game.currentMission->challengeData.timeLimit, 0)); } y += 25; - for (c = game.currentMission->challengeHead.next ; c != NULL ; c = c->next) + for (c = game.currentMission->challengeData.challengeHead.next ; c != NULL ; c = c->next) { y += 50; diff --git a/src/challenges/challenges.c b/src/challenges/challenges.c index c9c8b10..f8859ff 100644 --- a/src/challenges/challenges.c +++ b/src/challenges/challenges.c @@ -73,14 +73,14 @@ void initChallenges(void) void doChallenges(void) { - if (battle.challengeData.isChallenge && battle.status == MS_IN_PROGRESS) + if (game.currentMission->challengeData.isChallenge && battle.status == MS_IN_PROGRESS) { - if (battle.challengeData.timeLimit > 0 && battle.stats[STAT_TIME] / FPS >= battle.challengeData.timeLimit) + if (game.currentMission->challengeData.timeLimit > 0 && battle.stats[STAT_TIME] / FPS >= game.currentMission->challengeData.timeLimit) { failChallenge(); } - if (battle.challengeData.killLimit > 0 && battle.stats[STAT_ENEMIES_KILLED_PLAYER] >= battle.challengeData.killLimit) + if (game.currentMission->challengeData.killLimit > 0 && battle.stats[STAT_ENEMIES_KILLED_PLAYER] >= game.currentMission->challengeData.killLimit) { completeChallenge(); } @@ -96,7 +96,7 @@ static void updateChallenges(void) { Challenge *c; - for (c = game.currentMission->challengeHead.next ; c != NULL ; c = c->next) + for (c = game.currentMission->challengeData.challengeHead.next ; c != NULL ; c = c->next) { if (!c->passed) { @@ -239,7 +239,7 @@ Challenge *getChallenge(Mission *mission, int type, int value) { Challenge *c; - for (c = mission->challengeHead.next ; c != NULL ; c = c->next) + for (c = mission->challengeData.challengeHead.next ; c != NULL ; c = c->next) { if (c->type == type && c->value == value) { @@ -272,7 +272,7 @@ void updateChallengeMissions(void) { m->totalChallenges = m->completedChallenges = 0; - for (c = m->challengeHead.next ; c != NULL ; c = c->next) + for (c = m->challengeData.challengeHead.next ; c != NULL ; c = c->next) { m->totalChallenges++; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 28bcdf0..7c3b79b 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -30,7 +30,6 @@ static void loadLocations(cJSON *node); static unsigned long hashcode(const char *str); static char **toTypeArray(char *types, int *numTypes); static void loadEpicData(cJSON *node); -static void loadChallengeData(cJSON *node); static char *getAutoBackground(char *filename); static char *getAutoPlanet(char *filename); @@ -73,12 +72,16 @@ Mission *loadMissionMeta(char *filename) STRNCPY(mission->craft, cJSON_GetObjectItem(node, "type")->valuestring, MAX_NAME_LENGTH); } - challengeTail = &mission->challengeHead; + challengeTail = &mission->challengeData.challengeHead; node = cJSON_GetObjectItem(root, "challenge"); if (node) { + mission->challengeData.isChallenge = 1; + mission->challengeData.timeLimit = cJSON_GetObjectItem(node, "timeLimit")->valueint * FPS; + mission->challengeData.killLimit = cJSON_GetObjectItem(node, "killLimit")->valueint; + node = cJSON_GetObjectItem(node, "challenges"); if (node) @@ -144,11 +147,6 @@ void loadMission(char *filename) loadEpicData(cJSON_GetObjectItem(root, "epic")); } - if (cJSON_GetObjectItem(root, "challenge")) - { - loadChallengeData(cJSON_GetObjectItem(root, "challenge")); - } - if (cJSON_GetObjectItem(root, "manualComplete")) { battle.manualComplete = cJSON_GetObjectItem(root, "manualComplete")->valueint; @@ -195,7 +193,7 @@ void loadMission(char *filename) { game.stats[STAT_MISSIONS_STARTED]++; } - else if (battle.challengeData.isChallenge) + else if (game.currentMission->challengeData.isChallenge) { game.stats[STAT_CHALLENGES_STARTED]++; } @@ -219,7 +217,7 @@ static char *getAutoBackground(char *filename) { int hash; - if (!battle.challengeData.isChallenge) + if (!game.currentMission->challengeData.isChallenge) { hash = hashcode(game.selectedStarSystem); } @@ -235,7 +233,7 @@ static char *getAutoPlanet(char *filename) { int hash; - if (!battle.challengeData.isChallenge) + if (!game.currentMission->challengeData.isChallenge) { hash = hashcode(game.selectedStarSystem); } @@ -873,13 +871,6 @@ static void loadEpicData(cJSON *node) } } -static void loadChallengeData(cJSON *node) -{ - battle.challengeData.isChallenge = 1; - battle.challengeData.timeLimit = cJSON_GetObjectItem(node, "timeLimit")->valueint * FPS; - battle.challengeData.killLimit = cJSON_GetObjectItem(node, "killLimit")->valueint; -} - Mission *getMission(char *filename) { StarSystem *starSystem; diff --git a/src/structs.h b/src/structs.h index 385e459..ec41c7e 100644 --- a/src/structs.h +++ b/src/structs.h @@ -240,6 +240,15 @@ struct Challenge { Challenge *next; }; +typedef struct { + int isChallenge; + int timeLimit; + int killLimit; + int lossLimit; + int itemLimit; + Challenge challengeHead; +} ChallengeData; + struct Mission { char name[MAX_NAME_LENGTH]; char description[MAX_DESCRIPTION_LENGTH]; @@ -253,7 +262,7 @@ struct Mission { int completedChallenges; int totalChallenges; int epic; - Challenge challengeHead; + ChallengeData challengeData; SDL_Rect rect; Mission *next; }; @@ -282,14 +291,6 @@ struct Quadtree { Quadtree *node[4]; }; -typedef struct { - int isChallenge; - int timeLimit; - int killLimit; - int lossLimit; - int itemLimit; -} ChallengeData; - typedef struct { int entId; SDL_Point camera; @@ -321,7 +322,6 @@ typedef struct { Location locationHead, *locationTail; struct cJSON *missionJSON; unsigned int stats[STAT_MAX]; - ChallengeData challengeData; Quadtree quadtree; } Battle; diff --git a/src/system/save.c b/src/system/save.c index e6cc574..bbdb053 100644 --- a/src/system/save.c +++ b/src/system/save.c @@ -109,7 +109,7 @@ static void saveChallenges(cJSON *gameJSON) challengesJSON = cJSON_CreateArray(); - for (c = mission->challengeHead.next ; c != NULL ; c = c->next) + for (c = mission->challengeData.challengeHead.next ; c != NULL ; c = c->next) { challengeJSON = cJSON_CreateObject(); cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type));