diff --git a/src/galaxy/galacticMap.c b/src/galaxy/galacticMap.c index 24bb2c2..085ca24 100644 --- a/src/galaxy/galacticMap.c +++ b/src/galaxy/galacticMap.c @@ -108,6 +108,8 @@ void initGalacticMap(void) getWidget("ok", "stats")->action = statsOK; + updateStarSystemMissions(); + endSectionTransition(); playMusic("music/Pressure.ogg"); @@ -402,28 +404,6 @@ static void drawGalaxy(void) static void selectStarSystem(void) { - Mission *mission, *prev; - - selectedMission = selectedStarSystem->missionHead.next; - - selectedStarSystem->completedMissions = selectedStarSystem->totalMissions = 0; - - prev = &selectedStarSystem->missionHead; - - for (mission = selectedStarSystem->missionHead.next ; mission != NULL ; mission = mission->next) - { - selectedStarSystem->totalMissions++; - - if (mission->completed) - { - selectedStarSystem->completedMissions++; - } - - mission->available = prev->completed; - - prev = mission; - } - missionListStart = 0; selectedMissionIndex = 0; diff --git a/src/galaxy/galacticMap.h b/src/galaxy/galacticMap.h index 91ba33d..5ab9f4f 100644 --- a/src/galaxy/galacticMap.h +++ b/src/galaxy/galacticMap.h @@ -64,6 +64,8 @@ extern void playSound(int id); extern void blitRotated(SDL_Texture *texture, int x, int y, int angle); extern void initStatsDisplay(void); extern void handleStatsKB(void); +extern Mission *getMission(char *filename); +extern void updateStarSystemMissions(void); extern App app; extern Colors colors; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 3801ed0..63286cd 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -200,15 +200,19 @@ static void loadFighterGroups(cJSON *node) } } -Mission *getMission(StarSystem *starSystem, char *filename) +Mission *getMission(char *filename) { + StarSystem *starSystem; Mission *mission; - for (mission = starSystem->missionHead.next ; mission != NULL ; mission = mission->next) + for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next) { - if (strcmp(mission->filename, filename) == 0) + for (mission = starSystem->missionHead.next ; mission != NULL ; mission = mission->next) { - return mission; + if (strcmp(mission->filename, filename) == 0) + { + return mission; + } } } diff --git a/src/galaxy/starSystems.c b/src/galaxy/starSystems.c index 4dfd43f..0e2cf9c 100644 --- a/src/galaxy/starSystems.c +++ b/src/galaxy/starSystems.c @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void loadStarSystem(cJSON *starSystemJSON); static void loadMissionMeta(char *filename, StarSystem *starSystem); +static int isAvailable(Mission *mission, Mission *prev); void initStarSystems(void) { @@ -89,6 +90,11 @@ static void loadMissionMeta(char *filename, StarSystem *starSystem) STRNCPY(mission->description, cJSON_GetObjectItem(root, "description")->valuestring, MAX_DESCRIPTION_LENGTH); STRNCPY(mission->filename, filename, MAX_DESCRIPTION_LENGTH); + if (cJSON_GetObjectItem(root, "requires")) + { + STRNCPY(mission->requires, cJSON_GetObjectItem(root, "requires")->valuestring, MAX_DESCRIPTION_LENGTH); + } + node = cJSON_GetObjectItem(root, "player"); if (node) @@ -174,6 +180,50 @@ void updateStarSystemDescriptions(void) } } +void updateStarSystemMissions(void) +{ + StarSystem *starSystem; + Mission *mission, *prev; + + for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next) + { + starSystem->completedMissions = starSystem->totalMissions = 0; + + prev = &starSystem->missionHead; + + for (mission = starSystem->missionHead.next ; mission != NULL ; mission = mission->next) + { + starSystem->totalMissions++; + + if (mission->completed) + { + starSystem->completedMissions++; + } + + mission->available = isAvailable(mission, prev); + + prev = mission; + } + } +} + +static int isAvailable(Mission *mission, Mission *prev) +{ + Mission *reqMission; + + if (mission->requires) + { + reqMission = getMission(mission->requires); + + if (reqMission != NULL) + { + return reqMission->completed; + } + } + + return prev->completed; +} + void destroyStarSystems(void) { StarSystem *starSystem; diff --git a/src/galaxy/starSystems.h b/src/galaxy/starSystems.h index 48a53b0..90712ff 100644 --- a/src/galaxy/starSystems.h +++ b/src/galaxy/starSystems.h @@ -26,5 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern char *readFile(char *filename); extern long lookup(char *name); +extern Mission *getMission(char *filename); extern Game game; diff --git a/src/structs.h b/src/structs.h index 23ba54c..6b024b3 100644 --- a/src/structs.h +++ b/src/structs.h @@ -178,6 +178,7 @@ struct Mission { char name[MAX_NAME_LENGTH]; char description[MAX_DESCRIPTION_LENGTH]; char filename[MAX_DESCRIPTION_LENGTH]; + char requires[MAX_DESCRIPTION_LENGTH]; char pilot[MAX_NAME_LENGTH]; char squadron[MAX_NAME_LENGTH]; char craft[MAX_NAME_LENGTH]; diff --git a/src/system/load.c b/src/system/load.c index 56714ba..7281667 100644 --- a/src/system/load.c +++ b/src/system/load.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void loadStats(cJSON *stats); static void loadStarSystems(cJSON *starSystemsJSON); -static void loadMissions(StarSystem *starSystem, cJSON *missionsCJSON); +static void loadMissions(cJSON *missionsCJSON); static void loadChallenges(Mission *mission, cJSON *challengesCJSON); void loadGame(void) @@ -45,25 +45,22 @@ void loadGame(void) static void loadStarSystems(cJSON *starSystemsJSON) { - StarSystem *starSystem; cJSON *starSystemJSON; for (starSystemJSON = starSystemsJSON->child ; starSystemJSON != NULL ; starSystemJSON = starSystemJSON->next) { - starSystem = getStarSystem(cJSON_GetObjectItem(starSystemJSON, "name")->valuestring); - - loadMissions(starSystem, cJSON_GetObjectItem(starSystemJSON, "missions")); + loadMissions(cJSON_GetObjectItem(starSystemJSON, "missions")); } } -static void loadMissions(StarSystem *starSystem, cJSON *missionsCJSON) +static void loadMissions(cJSON *missionsCJSON) { Mission *mission; cJSON *missionCJSON; for (missionCJSON = missionsCJSON->child ; missionCJSON != NULL ; missionCJSON = missionCJSON->next) { - mission = getMission(starSystem, cJSON_GetObjectItem(missionCJSON, "filename")->valuestring); + mission = getMission(cJSON_GetObjectItem(missionCJSON, "filename")->valuestring); mission->completed = cJSON_GetObjectItem(missionCJSON, "completed")->valueint; diff --git a/src/system/load.h b/src/system/load.h index c7ad636..a6d160c 100644 --- a/src/system/load.h +++ b/src/system/load.h @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern char *readFile(char *filename); extern StarSystem *getStarSystem(char *name); -extern Mission *getMission(StarSystem *starSystem, char *filename); +extern Mission *getMission(char *filename); extern Challenge *getChallenge(Mission *mission, int type); extern int lookup(char *lookup); extern char *getSaveFilePath(char *filename);