Challenges integration.
This commit is contained in:
parent
ef6e65a51c
commit
2e5b45064a
|
@ -1,7 +1,7 @@
|
|||
VERSION = 0.6
|
||||
REVISION = $(shell date +"%y%m%d")
|
||||
|
||||
SEARCHPATH += src/ src/battle src/draw src/game src/galaxy src/json src/system src/test
|
||||
SEARCHPATH += src/ src/battle src/challenges src/draw src/game src/galaxy src/json src/system src/test
|
||||
vpath %.c $(SEARCHPATH)
|
||||
vpath %.h $(SEARCHPATH)
|
||||
|
||||
|
@ -9,7 +9,7 @@ DEPS += defs.h structs.h
|
|||
|
||||
OBJS += ai.o
|
||||
OBJS += battle.o bullets.o
|
||||
OBJS += capitalShips.o challenges.o cJSON.o
|
||||
OBJS += capitalShips.o challengeHome.o challenges.o cJSON.o
|
||||
OBJS += debris.o dev.o draw.o
|
||||
OBJS += effects.o entities.o extractionPoint.o
|
||||
OBJS += fighters.o
|
||||
|
|
|
@ -23,15 +23,15 @@
|
|||
"challenges" : [
|
||||
{
|
||||
"type" : "CHALLENGE_TIME",
|
||||
"targetValue" : 10
|
||||
"value" : 20
|
||||
},
|
||||
{
|
||||
"type" : "CHALLENGE_TIME",
|
||||
"targetValue" : 15
|
||||
"value" : 15
|
||||
},
|
||||
{
|
||||
"type" : "CHALLENGE_TIME",
|
||||
"targetValue" : 20
|
||||
"value" : 10
|
||||
}
|
||||
],
|
||||
"fighters" : [
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
[
|
||||
{
|
||||
"name" : "start",
|
||||
"group" : "challenges",
|
||||
"type" : "WT_BUTTON",
|
||||
"text" : "Start Challenge Mission",
|
||||
"x" : -1,
|
||||
"y" : 680,
|
||||
"w" : 250,
|
||||
"h": 34
|
||||
}
|
||||
]
|
|
@ -249,7 +249,7 @@ static void drawMenu(void)
|
|||
|
||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
|
||||
SDL_RenderFillRect(app.renderer, &r);
|
||||
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
|
||||
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderDrawRect(app.renderer, &r);
|
||||
|
||||
drawWidgets("inBattle");
|
||||
|
@ -305,7 +305,14 @@ static void continueGame(void)
|
|||
|
||||
destroyBattle();
|
||||
|
||||
if (!battle.isChallenge)
|
||||
{
|
||||
initGalacticMap();
|
||||
}
|
||||
else
|
||||
{
|
||||
initChallengeHome();
|
||||
}
|
||||
}
|
||||
|
||||
static void options(void)
|
||||
|
@ -339,7 +346,14 @@ static void quitBattle(void)
|
|||
|
||||
destroyBattle();
|
||||
|
||||
if (!battle.isChallenge)
|
||||
{
|
||||
initGalacticMap();
|
||||
}
|
||||
else
|
||||
{
|
||||
initChallengeHome();
|
||||
}
|
||||
}
|
||||
|
||||
static void postBattle(void)
|
||||
|
@ -354,11 +368,13 @@ static void postBattle(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (!battle.isChallenge)
|
||||
{
|
||||
if (game.currentMission && !game.currentMission->completed)
|
||||
{
|
||||
game.currentMission->completed = (battle.status == MS_COMPLETE || !battle.numObjectivesTotal);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void destroyBattle(void)
|
||||
|
|
|
@ -81,6 +81,7 @@ extern void drawLocations(void);
|
|||
extern void destroyDebris(void);
|
||||
extern void destroyBullets(void);
|
||||
extern void destroyEffects(void);
|
||||
extern void initChallengeHome(void);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
Copyright (C) 2015-2016 Parallel Realities
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include "challengeHome.h"
|
||||
|
||||
static void logic(void);
|
||||
static void draw(void);
|
||||
static void handleKeyboard(void);
|
||||
static void drawChallenges(void);
|
||||
static void updateChallengeMissions(void);
|
||||
static void doChallenges(void);
|
||||
static void startChallengeMission(void);
|
||||
|
||||
static SDL_Texture *background;
|
||||
static int startIndex;
|
||||
static Widget *start;
|
||||
|
||||
void initChallengeHome(void)
|
||||
{
|
||||
startSectionTransition();
|
||||
|
||||
stopMusic();
|
||||
|
||||
updateChallengeMissions();
|
||||
|
||||
saveGame();
|
||||
|
||||
app.delegate.logic = &logic;
|
||||
app.delegate.draw = &draw;
|
||||
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
|
||||
|
||||
background = getTexture("gfx/backgrounds/background04.jpg");
|
||||
|
||||
battle.camera.x = battle.camera.y = 0;
|
||||
|
||||
game.currentMission = NULL;
|
||||
|
||||
startIndex = 0;
|
||||
|
||||
initBackground();
|
||||
|
||||
start = getWidget("start", "challenges");
|
||||
start->enabled = 0;
|
||||
start->action = startChallengeMission;
|
||||
|
||||
setMouse(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
||||
|
||||
endSectionTransition();
|
||||
}
|
||||
|
||||
static void updateChallengeMissions(void)
|
||||
{
|
||||
Mission *m;
|
||||
Challenge *c;
|
||||
|
||||
for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next)
|
||||
{
|
||||
m->totalChallenges = m->completedChallenges = 0;
|
||||
|
||||
for (c = m->challengeHead.next ; c != NULL ; c = c->next)
|
||||
{
|
||||
m->totalChallenges++;
|
||||
|
||||
if (c->passed)
|
||||
{
|
||||
m->completedChallenges++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void logic(void)
|
||||
{
|
||||
handleKeyboard();
|
||||
|
||||
scrollBackground(-0.25, 0);
|
||||
|
||||
doStars(0.5, 0);
|
||||
|
||||
doChallenges();
|
||||
|
||||
doWidgets();
|
||||
}
|
||||
|
||||
static void doChallenges(void)
|
||||
{
|
||||
Mission *c;
|
||||
|
||||
for (c = game.challengeMissionHead.next ; c != NULL ; c = c->next)
|
||||
{
|
||||
if (app.mouse.button[SDL_BUTTON_LEFT] && collision(app.mouse.x, app.mouse.y, 3, 3, c->rect.x, c->rect.y, c->rect.w, c->rect.h))
|
||||
{
|
||||
game.currentMission = c;
|
||||
|
||||
start->enabled = 1;
|
||||
|
||||
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw(void)
|
||||
{
|
||||
drawBackground(background);
|
||||
|
||||
drawStars();
|
||||
|
||||
drawChallenges();
|
||||
|
||||
drawWidgets("challenges");
|
||||
}
|
||||
|
||||
static void drawChallenges(void)
|
||||
{
|
||||
Mission *c;
|
||||
SDL_Rect r;
|
||||
int i, endIndex;
|
||||
|
||||
r.x = 135;
|
||||
r.y = 165;
|
||||
r.w = r.h = 96;
|
||||
|
||||
endIndex = startIndex + MAX_ITEMS;
|
||||
i = 0;
|
||||
|
||||
for (c = game.challengeMissionHead.next ; c != NULL ; c = c->next)
|
||||
{
|
||||
c->rect = r;
|
||||
|
||||
if (i >= startIndex && i <= endIndex)
|
||||
{
|
||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
|
||||
SDL_RenderFillRect(app.renderer, &r);
|
||||
|
||||
if (game.currentMission == c)
|
||||
{
|
||||
SDL_SetRenderDrawColor(app.renderer, 64, 128, 200, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderFillRect(app.renderer, &r);
|
||||
SDL_SetRenderDrawColor(app.renderer, 128, 192, 255, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderDrawRect(app.renderer, &r);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_SetRenderDrawColor(app.renderer, 64, 64, 64, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderDrawRect(app.renderer, &r);
|
||||
}
|
||||
|
||||
drawText(r.x + (r.w / 2), r.y + 28, 30, TA_CENTER, colors.white, "%d", i + 1);
|
||||
|
||||
drawText(r.x + (r.w / 2), r.y + r.w + 5, 18, TA_CENTER, (c->completedChallenges < c->totalChallenges) ? colors.white : colors.green, "%d / %d", c->completedChallenges, c->totalChallenges);
|
||||
|
||||
r.x += 150;
|
||||
|
||||
if (r.x > SCREEN_WIDTH - 200)
|
||||
{
|
||||
r.y += 165;
|
||||
r.x = 135;
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static void handleKeyboard(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void startChallengeMission(void)
|
||||
{
|
||||
initBattle();
|
||||
|
||||
loadMission(game.currentMission->filename);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
Copyright (C) 2015-2016 Parallel Realities
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#define MAX_ITEMS 21
|
||||
|
||||
extern void startSectionTransition(void);
|
||||
extern void endSectionTransition(void);
|
||||
extern void stopMusic(void);
|
||||
extern void initBattle(void);
|
||||
extern void loadMission(char *filename);
|
||||
extern void setMouse(int x, int y);
|
||||
extern void doStars(float dx, float dy);
|
||||
extern void drawStars(void);
|
||||
extern void doWidgets(void);
|
||||
extern SDL_Texture *getTexture(const char *filename);
|
||||
extern void drawBackground(SDL_Texture *texture);
|
||||
extern void initBackground(void);
|
||||
extern void scrollBackground(float x, float y);
|
||||
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
|
||||
extern void drawWidgets(char *groupName);
|
||||
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
|
||||
extern Widget *getWidget(const char *name, const char *group);
|
||||
extern void saveGame(void);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
extern Colors colors;
|
||||
extern Game game;
|
|
@ -114,14 +114,14 @@ static void updateTimeChallenge(Challenge *c)
|
|||
switch (c->type)
|
||||
{
|
||||
case CHALLENGE_TIME:
|
||||
if (battle.stats[STAT_TIME] / FPS <= c->targetValue)
|
||||
if (battle.stats[STAT_TIME] / FPS < c->value)
|
||||
{
|
||||
c->passed = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case CHALLENGE_TIME_MINS:
|
||||
if ((battle.stats[STAT_TIME] / FPS) / 60 <= c->targetValue)
|
||||
if ((battle.stats[STAT_TIME] / FPS) / 60 < c->value)
|
||||
{
|
||||
c->passed = 1;
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ static void updateAccuracyChallenge(Challenge *c)
|
|||
percent /= battle.stats[STAT_SHOTS_FIRED];
|
||||
percent *= 100;
|
||||
|
||||
if (percent >= c->targetValue)
|
||||
if (percent >= c->value)
|
||||
{
|
||||
c->passed = 1;
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ static void updateArmourChallenge(Challenge *c)
|
|||
percent /= player->maxHealth;
|
||||
percent *= 100;
|
||||
|
||||
if (percent >= c->targetValue)
|
||||
if (percent >= c->value)
|
||||
{
|
||||
c->passed = 1;
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ static void updateLossesChallenge(Challenge *c)
|
|||
{
|
||||
if (!c->passed)
|
||||
{
|
||||
c->passed = battle.stats[STAT_ALLIES_KILLED] <= c->targetValue;
|
||||
c->passed = battle.stats[STAT_ALLIES_KILLED] <= c->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ static void updatePlayerKillsChallenge(Challenge *c)
|
|||
{
|
||||
if (!c->passed)
|
||||
{
|
||||
c->passed = battle.stats[STAT_ENEMIES_KILLED_PLAYER] >= c->targetValue;
|
||||
c->passed = battle.stats[STAT_ENEMIES_KILLED_PLAYER] >= c->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,24 +177,24 @@ static void updateDisabledChallenge(Challenge *c)
|
|||
{
|
||||
if (!c->passed)
|
||||
{
|
||||
c->passed = battle.stats[STAT_ENEMIES_DISABLED] >= c->targetValue;
|
||||
c->passed = battle.stats[STAT_ENEMIES_DISABLED] >= c->value;
|
||||
}
|
||||
}
|
||||
|
||||
char *getChallengeDescription(Challenge *c)
|
||||
{
|
||||
return getFormattedChallengeDescription(challengeDescription[c->type], c->targetValue);
|
||||
return getFormattedChallengeDescription(challengeDescription[c->type], c->value);
|
||||
}
|
||||
|
||||
Challenge *getChallenge(Mission *mission, int type)
|
||||
Challenge *getChallenge(Mission *mission, int type, int value)
|
||||
{
|
||||
Challenge *challenge;
|
||||
Challenge *c;
|
||||
|
||||
for (challenge = mission->challengeHead.next ; challenge != NULL ; challenge = challenge->next)
|
||||
for (c = mission->challengeHead.next ; c != NULL ; c = c->next)
|
||||
{
|
||||
if (challenge->type == type)
|
||||
if (c->type == type && c->value == value)
|
||||
{
|
||||
return challenge;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,6 @@ static void updatePandoranAdvance(void);
|
|||
static void fallenOK(void);
|
||||
|
||||
static StarSystem *selectedStarSystem;
|
||||
static Mission *selectedMission = {0};
|
||||
static SDL_Texture *background;
|
||||
static SDL_Texture *starSystemTexture;
|
||||
static SDL_Texture *arrowTexture;
|
||||
|
@ -263,12 +262,12 @@ static void doStarSystemView(void)
|
|||
{
|
||||
if (mission->available && app.mouse.button[SDL_BUTTON_LEFT] && collision(app.mouse.x - app.mouse.w / 2, app.mouse.y - app.mouse.h / 2, app.mouse.w, app.mouse.h, mission->rect.x, mission->rect.y, mission->rect.w, mission->rect.h))
|
||||
{
|
||||
if (selectedMission != mission)
|
||||
if (game.currentMission != mission)
|
||||
{
|
||||
playSound(SND_GUI_CLICK);
|
||||
}
|
||||
|
||||
selectedMission = mission;
|
||||
game.currentMission = mission;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -500,7 +499,7 @@ static void selectStarSystem(void)
|
|||
{
|
||||
show = SHOW_STAR_SYSTEM;
|
||||
STRNCPY(game.selectedStarSystem, selectedStarSystem->name, MAX_NAME_LENGTH);
|
||||
selectedMission = selectedStarSystem->missionHead.next;
|
||||
game.currentMission = selectedStarSystem->missionHead.next;
|
||||
playSound(SND_GUI_SELECT);
|
||||
}
|
||||
}
|
||||
|
@ -542,7 +541,7 @@ static void drawStarSystemDetail(void)
|
|||
mission->rect.w = 300;
|
||||
mission->rect.h = 40;
|
||||
|
||||
if (mission == selectedMission)
|
||||
if (mission == game.currentMission)
|
||||
{
|
||||
SDL_SetRenderDrawColor(app.renderer, 32, 64, 128, 255);
|
||||
SDL_RenderFillRect(app.renderer, &mission->rect);
|
||||
|
@ -559,27 +558,27 @@ static void drawStarSystemDetail(void)
|
|||
y += 50;
|
||||
}
|
||||
|
||||
if (selectedMission->available)
|
||||
if (game.currentMission->available)
|
||||
{
|
||||
drawText(525, 135, 18, TA_LEFT, colors.lightGrey, "Pilot: %s", selectedMission->pilot);
|
||||
drawText(525, 160, 18, TA_LEFT, colors.lightGrey, "Craft: %s", selectedMission->craft);
|
||||
drawText(525, 185, 18, TA_LEFT, colors.lightGrey, "Squadron: %s", selectedMission->squadron);
|
||||
drawText(525, 135, 18, TA_LEFT, colors.lightGrey, "Pilot: %s", game.currentMission->pilot);
|
||||
drawText(525, 160, 18, TA_LEFT, colors.lightGrey, "Craft: %s", game.currentMission->craft);
|
||||
drawText(525, 185, 18, TA_LEFT, colors.lightGrey, "Squadron: %s", game.currentMission->squadron);
|
||||
|
||||
limitTextWidth(500);
|
||||
drawText(525, 230, 22, TA_LEFT, colors.white, selectedMission->description);
|
||||
drawText(525, 230, 22, TA_LEFT, colors.white, game.currentMission->description);
|
||||
limitTextWidth(0);
|
||||
}
|
||||
|
||||
if (selectedMission->completed)
|
||||
if (game.currentMission->completed)
|
||||
{
|
||||
drawText(525, SCREEN_HEIGHT - 95, 18, TA_LEFT, colors.green, "This mission has been completed.");
|
||||
}
|
||||
else if (selectedMission->epic)
|
||||
else if (game.currentMission->epic)
|
||||
{
|
||||
drawText(525, SCREEN_HEIGHT - 95, 18, TA_LEFT, colors.yellow, "Note: this is an Epic Mission.");
|
||||
}
|
||||
|
||||
startMissionButton->enabled = (!selectedMission->completed || selectedStarSystem->isSol);
|
||||
startMissionButton->enabled = (!game.currentMission->completed || selectedStarSystem->isSol);
|
||||
|
||||
drawWidgets("starSystem");
|
||||
}
|
||||
|
@ -646,8 +645,8 @@ static void handleMouse(void)
|
|||
static void startMission(void)
|
||||
{
|
||||
initBattle();
|
||||
game.currentMission = selectedMission;
|
||||
loadMission(selectedMission->filename);
|
||||
|
||||
loadMission(game.currentMission->filename);
|
||||
}
|
||||
|
||||
static void drawMenu(void)
|
||||
|
|
|
@ -84,7 +84,7 @@ Mission *loadMissionMeta(char *filename)
|
|||
memset(challenge, 0, sizeof(Challenge));
|
||||
|
||||
challenge->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
||||
challenge->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
||||
challenge->value = cJSON_GetObjectItem(node, "value")->valueint;
|
||||
|
||||
challengeTail->next = challenge;
|
||||
challengeTail = challenge;
|
||||
|
@ -817,6 +817,7 @@ Mission *getMission(char *filename)
|
|||
StarSystem *starSystem;
|
||||
Mission *mission;
|
||||
|
||||
/* First, search the star systems */
|
||||
for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next)
|
||||
{
|
||||
for (mission = starSystem->missionHead.next ; mission != NULL ; mission = mission->next)
|
||||
|
@ -828,6 +829,17 @@ Mission *getMission(char *filename)
|
|||
}
|
||||
}
|
||||
|
||||
/* now search the challenges */
|
||||
for (mission = game.challengeMissionHead.next ; mission != NULL ; mission = mission->next)
|
||||
{
|
||||
if (strcmp(mission->filename, filename) == 0)
|
||||
{
|
||||
return mission;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "No such mission '%s'", filename);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@ static StarSystem *loadStarSystem(cJSON *starSystemJSON)
|
|||
}
|
||||
|
||||
starSystem->missionHead.completed = 1;
|
||||
starSystem->missionTail = &starSystem->missionHead;
|
||||
|
||||
loadMissions(starSystem);
|
||||
|
||||
|
@ -84,6 +83,9 @@ static void loadMissions(StarSystem *starSystem)
|
|||
char name[MAX_NAME_LENGTH];
|
||||
char path[MAX_FILENAME_LENGTH];
|
||||
char **filenames;
|
||||
Mission *mission, *tail;
|
||||
|
||||
tail = &starSystem->missionHead;
|
||||
|
||||
STRNCPY(name, starSystem->name, MAX_NAME_LENGTH);
|
||||
|
||||
|
@ -100,7 +102,9 @@ static void loadMissions(StarSystem *starSystem)
|
|||
{
|
||||
sprintf(path, "data/missions/%s/%s", name, filenames[i]);
|
||||
|
||||
loadMissionMeta(path);
|
||||
mission = loadMissionMeta(path);
|
||||
tail->next = mission;
|
||||
tail = mission;
|
||||
|
||||
free(filenames[i]);
|
||||
}
|
||||
|
|
|
@ -27,30 +27,6 @@ void initGame(void)
|
|||
STRNCPY(game.selectedStarSystem, "Sol", MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
void resetGame(void)
|
||||
{
|
||||
StarSystem *starSystem;
|
||||
Mission *mission;
|
||||
Challenge *challenge;
|
||||
|
||||
memset(&game.stats, 0, sizeof(int) * STAT_MAX);
|
||||
|
||||
for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next)
|
||||
{
|
||||
for (mission = starSystem->missionHead.next ; mission != NULL ; mission = mission->next)
|
||||
{
|
||||
mission->completed = 0;
|
||||
|
||||
for (challenge = mission->challengeHead.next ; challenge != NULL ; challenge = challenge->next)
|
||||
{
|
||||
challenge->passed = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STRNCPY(game.selectedStarSystem, "Sol", MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
void destroyGame(void)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ void initTitle(void)
|
|||
|
||||
endSectionTransition();
|
||||
|
||||
SDL_WarpMouseInWindow(app.window, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 100);
|
||||
setMouse(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
||||
|
||||
playMusic("music/Rise of spirit.ogg");
|
||||
}
|
||||
|
@ -199,20 +199,12 @@ static void handleKeyboard(void)
|
|||
|
||||
static void campaign(void)
|
||||
{
|
||||
if (fileExists(getSaveFilePath("game.save")))
|
||||
{
|
||||
loadGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
resetGame();
|
||||
}
|
||||
|
||||
initGalacticMap();
|
||||
}
|
||||
|
||||
static void challenges(void)
|
||||
{
|
||||
initChallengeHome();
|
||||
}
|
||||
|
||||
static void options(void)
|
||||
|
|
|
@ -40,20 +40,17 @@ extern void drawWidgets(char *groupName);
|
|||
extern void doWidgets(void);
|
||||
extern Widget *getWidget(const char *name, const char *group);
|
||||
extern void selectWidget(const char *name, const char *group);
|
||||
extern void loadGame(void);
|
||||
extern int fileExists(char *filename);
|
||||
extern void resetGame(void);
|
||||
extern void initGalacticMap(void);
|
||||
extern void initOptions(void (*returnFromOptions)(void));
|
||||
extern void drawOptions(void);
|
||||
extern char *getSaveFilePath(char *filename);
|
||||
extern void playMusic(char *filename);
|
||||
extern void destroyBattle(void);
|
||||
extern void playSound(int id);
|
||||
extern void initEffects(void);
|
||||
extern void setMouse(int x, int y);
|
||||
extern void initChallengeHome(void);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
extern Colors colors;
|
||||
extern Game game;
|
||||
extern Entity *self;
|
||||
|
|
|
@ -177,6 +177,11 @@ static void handleArguments(int argc, char *argv[])
|
|||
|
||||
if (!testingMission)
|
||||
{
|
||||
if (fileExists(getSaveFilePath("game.save")))
|
||||
{
|
||||
loadGame();
|
||||
}
|
||||
|
||||
initTitle();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ extern void prepareScene(void);
|
|||
extern void presentScene(void);
|
||||
extern void doModalDialog(void);
|
||||
extern void drawModalDialog(void);
|
||||
extern void loadGame(void);
|
||||
extern int fileExists(char *filename);
|
||||
extern char *getSaveFilePath(char *filename);
|
||||
|
||||
App app;
|
||||
Colors colors;
|
||||
|
|
|
@ -235,7 +235,7 @@ struct Objective {
|
|||
|
||||
struct Challenge {
|
||||
int type;
|
||||
int targetValue;
|
||||
int value;
|
||||
int passed;
|
||||
Challenge *next;
|
||||
};
|
||||
|
@ -251,6 +251,8 @@ struct Mission {
|
|||
int available;
|
||||
int completed;
|
||||
int epic;
|
||||
int completedChallenges;
|
||||
int totalChallenges;
|
||||
SDL_Rect rect;
|
||||
Challenge challengeHead;
|
||||
Mission *next;
|
||||
|
@ -267,7 +269,7 @@ struct StarSystem {
|
|||
int availableMissions;
|
||||
int fallsToPandorans;
|
||||
int isSol;
|
||||
Mission missionHead, *missionTail;
|
||||
Mission missionHead;
|
||||
StarSystem *next;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,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(cJSON *missionsCJSON);
|
||||
static void loadChallenges(Mission *mission, cJSON *challengesCJSON);
|
||||
static void loadChallenges(cJSON *challengesCJSON);
|
||||
|
||||
void loadGame(void)
|
||||
{
|
||||
|
@ -39,6 +39,8 @@ void loadGame(void)
|
|||
|
||||
loadStarSystems(cJSON_GetObjectItem(gameJSON, "starSystems"));
|
||||
|
||||
loadChallenges(cJSON_GetObjectItem(gameJSON, "challenges"));
|
||||
|
||||
loadStats(cJSON_GetObjectItem(gameJSON, "stats"));
|
||||
|
||||
cJSON_Delete(root);
|
||||
|
@ -60,40 +62,41 @@ static void loadStarSystems(cJSON *starSystemsJSON)
|
|||
}
|
||||
}
|
||||
|
||||
static void loadMissions(cJSON *missionsCJSON)
|
||||
static void loadMissions(cJSON *missionsJSON)
|
||||
{
|
||||
Mission *mission;
|
||||
cJSON *missionCJSON;
|
||||
cJSON *missionJSON;
|
||||
|
||||
for (missionCJSON = missionsCJSON->child ; missionCJSON != NULL ; missionCJSON = missionCJSON->next)
|
||||
for (missionJSON = missionsJSON->child ; missionJSON != NULL ; missionJSON = missionJSON->next)
|
||||
{
|
||||
mission = getMission(cJSON_GetObjectItem(missionCJSON, "filename")->valuestring);
|
||||
|
||||
mission->completed = cJSON_GetObjectItem(missionCJSON, "completed")->valueint;
|
||||
|
||||
if (cJSON_GetObjectItem(missionCJSON, "challenges"))
|
||||
{
|
||||
loadChallenges(mission, cJSON_GetObjectItem(missionCJSON, "challenges"));
|
||||
}
|
||||
mission = getMission(cJSON_GetObjectItem(missionJSON, "filename")->valuestring);
|
||||
mission->completed = cJSON_GetObjectItem(missionJSON, "completed")->valueint;
|
||||
}
|
||||
}
|
||||
|
||||
static void loadChallenges(Mission *mission, cJSON *challengesCJSON)
|
||||
static void loadChallenges(cJSON *missionsJSON)
|
||||
{
|
||||
Mission *mission;
|
||||
Challenge *challenge;
|
||||
cJSON *challengeCJSON;
|
||||
cJSON *missionJSON, *challengeJSON;
|
||||
int type, value;
|
||||
|
||||
for (challengeCJSON = challengesCJSON->child ; challengeCJSON != NULL ; challengeCJSON = challengeCJSON->next)
|
||||
if (missionsJSON)
|
||||
{
|
||||
challenge = getChallenge(mission, lookup(cJSON_GetObjectItem(challengeCJSON, "type")->valuestring));
|
||||
for (missionJSON = missionsJSON->child ; missionJSON != NULL ; missionJSON = missionJSON->next)
|
||||
{
|
||||
mission = getMission(cJSON_GetObjectItem(missionJSON, "filename")->valuestring);
|
||||
|
||||
if (!challenge)
|
||||
for (challengeJSON = cJSON_GetObjectItem(missionJSON, "challenges")->child ; challengeJSON != NULL ; challengeJSON = challengeJSON->next)
|
||||
{
|
||||
printf("Couldn't find challenge to update\n");
|
||||
continue;
|
||||
type = lookup(cJSON_GetObjectItem(challengeJSON, "type")->valuestring);
|
||||
value = cJSON_GetObjectItem(challengeJSON, "value")->valueint;
|
||||
|
||||
challenge = getChallenge(mission, type, value);
|
||||
|
||||
challenge->passed = cJSON_GetObjectItem(challengeJSON, "passed")->valueint;
|
||||
}
|
||||
}
|
||||
|
||||
challenge->passed = cJSON_GetObjectItem(challengeCJSON, "passed")->valueint;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
extern char *readFile(char *filename);
|
||||
extern Mission *getMission(char *filename);
|
||||
extern Challenge *getChallenge(Mission *mission, int type);
|
||||
extern Challenge *getChallenge(Mission *mission, int type, int value);
|
||||
extern int lookup(char *lookup);
|
||||
extern char *getSaveFilePath(char *filename);
|
||||
extern char *getLookupName(char *prefix, long num);
|
||||
|
|
|
@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "save.h"
|
||||
|
||||
static void saveStarSystems(cJSON *gameJSON);
|
||||
static void saveChallenges(cJSON *gameJSON);
|
||||
static cJSON *getMissionsJSON(StarSystem *starSystem);
|
||||
static cJSON *getChallengesJSON(Mission *mission);
|
||||
static void saveStats(cJSON *gameJSON);
|
||||
|
||||
void saveGame(void)
|
||||
|
@ -40,6 +40,8 @@ void saveGame(void)
|
|||
|
||||
saveStarSystems(gameJSON);
|
||||
|
||||
saveChallenges(gameJSON);
|
||||
|
||||
saveStats(gameJSON);
|
||||
|
||||
out = cJSON_Print(root);
|
||||
|
@ -85,36 +87,44 @@ static cJSON *getMissionsJSON(StarSystem *starSystem)
|
|||
cJSON_AddStringToObject(missionJSON, "filename", mission->filename);
|
||||
cJSON_AddNumberToObject(missionJSON, "completed", mission->completed);
|
||||
|
||||
if (mission->challengeHead.next)
|
||||
{
|
||||
cJSON_AddItemToObject(missionJSON, "challenges", getChallengesJSON(mission));
|
||||
}
|
||||
|
||||
cJSON_AddItemToArray(missionsJSON, missionJSON);
|
||||
}
|
||||
|
||||
return missionsJSON;
|
||||
}
|
||||
|
||||
static cJSON *getChallengesJSON(Mission *mission)
|
||||
static void saveChallenges(cJSON *gameJSON)
|
||||
{
|
||||
cJSON *challengesJSON, *challengeJSON;
|
||||
Challenge *challenge;
|
||||
Mission *mission;
|
||||
Challenge *c;
|
||||
cJSON *missionsJSON, *missionJSON, *challengesJSON, *challengeJSON;
|
||||
|
||||
missionsJSON = cJSON_CreateArray();
|
||||
|
||||
for (mission = game.challengeMissionHead.next ; mission != NULL ; mission = mission->next)
|
||||
{
|
||||
missionJSON = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(missionJSON, "filename", mission->filename);
|
||||
|
||||
challengesJSON = cJSON_CreateArray();
|
||||
|
||||
for (challenge = mission->challengeHead.next ; challenge != NULL ; challenge = challenge->next)
|
||||
for (c = mission->challengeHead.next ; c != NULL ; c = c->next)
|
||||
{
|
||||
challengeJSON = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", challenge->type));
|
||||
cJSON_AddNumberToObject(challengeJSON, "targetValue", challenge->targetValue);
|
||||
cJSON_AddNumberToObject(challengeJSON, "passed", challenge->passed);
|
||||
cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type));
|
||||
cJSON_AddNumberToObject(challengeJSON, "value", c->value);
|
||||
cJSON_AddNumberToObject(challengeJSON, "passed", c->passed);
|
||||
|
||||
cJSON_AddItemToArray(challengesJSON, challengeJSON);
|
||||
}
|
||||
|
||||
return challengesJSON;
|
||||
cJSON_AddItemToObject(missionJSON, "challenges", challengesJSON);
|
||||
|
||||
cJSON_AddItemToArray(missionsJSON, missionJSON);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(gameJSON, "challenges", missionsJSON);
|
||||
}
|
||||
|
||||
static void saveStats(cJSON *gameJSON)
|
||||
|
|
|
@ -63,7 +63,7 @@ static void loadChallenges(char *filename)
|
|||
memset(challenge, 0, sizeof(Challenge));
|
||||
|
||||
challenge->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
||||
challenge->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
||||
challenge->value = cJSON_GetObjectItem(node, "value")->valueint;
|
||||
|
||||
challengeTail->next = challenge;
|
||||
challengeTail = challenge;
|
||||
|
|
Loading…
Reference in New Issue