Added ability to set mission availability dependencies.

This commit is contained in:
Steve 2015-10-25 09:29:41 +00:00
parent c322cced55
commit b5154d3ab8
8 changed files with 69 additions and 34 deletions

View File

@ -108,6 +108,8 @@ void initGalacticMap(void)
getWidget("ok", "stats")->action = statsOK; getWidget("ok", "stats")->action = statsOK;
updateStarSystemMissions();
endSectionTransition(); endSectionTransition();
playMusic("music/Pressure.ogg"); playMusic("music/Pressure.ogg");
@ -402,28 +404,6 @@ static void drawGalaxy(void)
static void selectStarSystem(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; missionListStart = 0;
selectedMissionIndex = 0; selectedMissionIndex = 0;

View File

@ -64,6 +64,8 @@ extern void playSound(int id);
extern void blitRotated(SDL_Texture *texture, int x, int y, int angle); extern void blitRotated(SDL_Texture *texture, int x, int y, int angle);
extern void initStatsDisplay(void); extern void initStatsDisplay(void);
extern void handleStatsKB(void); extern void handleStatsKB(void);
extern Mission *getMission(char *filename);
extern void updateStarSystemMissions(void);
extern App app; extern App app;
extern Colors colors; extern Colors colors;

View File

@ -200,15 +200,19 @@ static void loadFighterGroups(cJSON *node)
} }
} }
Mission *getMission(StarSystem *starSystem, char *filename) Mission *getMission(char *filename)
{ {
StarSystem *starSystem;
Mission *mission; 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;
}
} }
} }

View File

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void loadStarSystem(cJSON *starSystemJSON); static void loadStarSystem(cJSON *starSystemJSON);
static void loadMissionMeta(char *filename, StarSystem *starSystem); static void loadMissionMeta(char *filename, StarSystem *starSystem);
static int isAvailable(Mission *mission, Mission *prev);
void initStarSystems(void) 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->description, cJSON_GetObjectItem(root, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
STRNCPY(mission->filename, filename, 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"); node = cJSON_GetObjectItem(root, "player");
if (node) 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) void destroyStarSystems(void)
{ {
StarSystem *starSystem; StarSystem *starSystem;

View File

@ -26,5 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern char *readFile(char *filename); extern char *readFile(char *filename);
extern long lookup(char *name); extern long lookup(char *name);
extern Mission *getMission(char *filename);
extern Game game; extern Game game;

View File

@ -178,6 +178,7 @@ struct Mission {
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
char description[MAX_DESCRIPTION_LENGTH]; char description[MAX_DESCRIPTION_LENGTH];
char filename[MAX_DESCRIPTION_LENGTH]; char filename[MAX_DESCRIPTION_LENGTH];
char requires[MAX_DESCRIPTION_LENGTH];
char pilot[MAX_NAME_LENGTH]; char pilot[MAX_NAME_LENGTH];
char squadron[MAX_NAME_LENGTH]; char squadron[MAX_NAME_LENGTH];
char craft[MAX_NAME_LENGTH]; char craft[MAX_NAME_LENGTH];

View File

@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void loadStats(cJSON *stats); static void loadStats(cJSON *stats);
static void loadStarSystems(cJSON *starSystemsJSON); static void loadStarSystems(cJSON *starSystemsJSON);
static void loadMissions(StarSystem *starSystem, cJSON *missionsCJSON); static void loadMissions(cJSON *missionsCJSON);
static void loadChallenges(Mission *mission, cJSON *challengesCJSON); static void loadChallenges(Mission *mission, cJSON *challengesCJSON);
void loadGame(void) void loadGame(void)
@ -45,25 +45,22 @@ void loadGame(void)
static void loadStarSystems(cJSON *starSystemsJSON) static void loadStarSystems(cJSON *starSystemsJSON)
{ {
StarSystem *starSystem;
cJSON *starSystemJSON; cJSON *starSystemJSON;
for (starSystemJSON = starSystemsJSON->child ; starSystemJSON != NULL ; starSystemJSON = starSystemJSON->next) for (starSystemJSON = starSystemsJSON->child ; starSystemJSON != NULL ; starSystemJSON = starSystemJSON->next)
{ {
starSystem = getStarSystem(cJSON_GetObjectItem(starSystemJSON, "name")->valuestring); loadMissions(cJSON_GetObjectItem(starSystemJSON, "missions"));
loadMissions(starSystem, cJSON_GetObjectItem(starSystemJSON, "missions"));
} }
} }
static void loadMissions(StarSystem *starSystem, cJSON *missionsCJSON) static void loadMissions(cJSON *missionsCJSON)
{ {
Mission *mission; Mission *mission;
cJSON *missionCJSON; cJSON *missionCJSON;
for (missionCJSON = missionsCJSON->child ; missionCJSON != NULL ; missionCJSON = missionCJSON->next) 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; mission->completed = cJSON_GetObjectItem(missionCJSON, "completed")->valueint;

View File

@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern char *readFile(char *filename); extern char *readFile(char *filename);
extern StarSystem *getStarSystem(char *name); 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 Challenge *getChallenge(Mission *mission, int type);
extern int lookup(char *lookup); extern int lookup(char *lookup);
extern char *getSaveFilePath(char *filename); extern char *getSaveFilePath(char *filename);