Refactored challenge data, for display on Challenge Home.
This commit is contained in:
parent
9dac6aa0ba
commit
0c31b2204c
|
@ -305,7 +305,7 @@ static void continueGame(void)
|
||||||
|
|
||||||
destroyBattle();
|
destroyBattle();
|
||||||
|
|
||||||
if (!battle.challengeData.isChallenge)
|
if (!game.currentMission->challengeData.isChallenge)
|
||||||
{
|
{
|
||||||
initGalacticMap();
|
initGalacticMap();
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ static void quitBattle(void)
|
||||||
|
|
||||||
destroyBattle();
|
destroyBattle();
|
||||||
|
|
||||||
if (!battle.challengeData.isChallenge)
|
if (!game.currentMission->challengeData.isChallenge)
|
||||||
{
|
{
|
||||||
initGalacticMap();
|
initGalacticMap();
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ static void postBattle(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!battle.challengeData.isChallenge)
|
if (!game.currentMission->challengeData.isChallenge)
|
||||||
{
|
{
|
||||||
if (game.currentMission && !game.currentMission->completed)
|
if (game.currentMission && !game.currentMission->completed)
|
||||||
{
|
{
|
||||||
|
|
|
@ -402,15 +402,15 @@ static void drawNumFighters(void)
|
||||||
|
|
||||||
static void drawObjectives(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);
|
drawText(SCREEN_WIDTH / 2, 10, 16, TA_CENTER, colors.white, "%d / %d", battle.numObjectivesComplete, battle.numObjectivesTotal);
|
||||||
}
|
}
|
||||||
else
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,3 +39,4 @@ extern App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
extern Entity *player;
|
extern Entity *player;
|
||||||
|
extern Game game;
|
||||||
|
|
|
@ -32,15 +32,17 @@ static const char *objectiveStatus[OS_MAX];
|
||||||
|
|
||||||
void initMissionInfo(void)
|
void initMissionInfo(void)
|
||||||
{
|
{
|
||||||
|
int isChallenge = game.currentMission->challengeData.isChallenge;
|
||||||
|
|
||||||
objectiveStatus[OS_INCOMPLETE] = _("Incomplete");
|
objectiveStatus[OS_INCOMPLETE] = _("Incomplete");
|
||||||
objectiveStatus[OS_COMPLETE] = _("Complete");
|
objectiveStatus[OS_COMPLETE] = _("Complete");
|
||||||
objectiveStatus[OS_FAILED] = _("Failed");
|
objectiveStatus[OS_FAILED] = _("Failed");
|
||||||
objectiveStatus[OS_CONDITION] = _("Condition");
|
objectiveStatus[OS_CONDITION] = _("Condition");
|
||||||
|
|
||||||
missionStartTexture = !battle.challengeData.isChallenge ? getTexture("gfx/battle/missionStart.png") : getTexture("gfx/battle/challengeStart.png");
|
missionStartTexture = !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");
|
missionInProgressTexture = !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");
|
missionCompleteTexture = !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");
|
missionFailedTexture = !isChallenge ? getTexture("gfx/battle/missionFailed.png") : getTexture("gfx/battle/challengeFailed.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawMissionInfo(void)
|
void drawMissionInfo(void)
|
||||||
|
@ -84,7 +86,7 @@ static void drawMissionSummary(SDL_Texture *header)
|
||||||
|
|
||||||
blit(header, SCREEN_WIDTH / 2, 150, 1);
|
blit(header, SCREEN_WIDTH / 2, 150, 1);
|
||||||
|
|
||||||
if (!battle.challengeData.isChallenge)
|
if (!game.currentMission->challengeData.isChallenge)
|
||||||
{
|
{
|
||||||
drawObjectives();
|
drawObjectives();
|
||||||
}
|
}
|
||||||
|
@ -153,16 +155,16 @@ static void drawChallenges(void)
|
||||||
|
|
||||||
drawText(SCREEN_WIDTH / 2, y, 24, TA_CENTER, colors.white, game.currentMission->description);
|
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;
|
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;
|
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;
|
y += 50;
|
||||||
|
|
||||||
|
|
|
@ -73,14 +73,14 @@ void initChallenges(void)
|
||||||
|
|
||||||
void doChallenges(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();
|
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();
|
completeChallenge();
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ static void updateChallenges(void)
|
||||||
{
|
{
|
||||||
Challenge *c;
|
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)
|
if (!c->passed)
|
||||||
{
|
{
|
||||||
|
@ -239,7 +239,7 @@ Challenge *getChallenge(Mission *mission, int type, int value)
|
||||||
{
|
{
|
||||||
Challenge *c;
|
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)
|
if (c->type == type && c->value == value)
|
||||||
{
|
{
|
||||||
|
@ -272,7 +272,7 @@ void updateChallengeMissions(void)
|
||||||
{
|
{
|
||||||
m->totalChallenges = m->completedChallenges = 0;
|
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++;
|
m->totalChallenges++;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ static void loadLocations(cJSON *node);
|
||||||
static unsigned long hashcode(const char *str);
|
static unsigned long hashcode(const char *str);
|
||||||
static char **toTypeArray(char *types, int *numTypes);
|
static char **toTypeArray(char *types, int *numTypes);
|
||||||
static void loadEpicData(cJSON *node);
|
static void loadEpicData(cJSON *node);
|
||||||
static void loadChallengeData(cJSON *node);
|
|
||||||
static char *getAutoBackground(char *filename);
|
static char *getAutoBackground(char *filename);
|
||||||
static char *getAutoPlanet(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);
|
STRNCPY(mission->craft, cJSON_GetObjectItem(node, "type")->valuestring, MAX_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
challengeTail = &mission->challengeHead;
|
challengeTail = &mission->challengeData.challengeHead;
|
||||||
|
|
||||||
node = cJSON_GetObjectItem(root, "challenge");
|
node = cJSON_GetObjectItem(root, "challenge");
|
||||||
|
|
||||||
if (node)
|
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");
|
node = cJSON_GetObjectItem(node, "challenges");
|
||||||
|
|
||||||
if (node)
|
if (node)
|
||||||
|
@ -144,11 +147,6 @@ void loadMission(char *filename)
|
||||||
loadEpicData(cJSON_GetObjectItem(root, "epic"));
|
loadEpicData(cJSON_GetObjectItem(root, "epic"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(root, "challenge"))
|
|
||||||
{
|
|
||||||
loadChallengeData(cJSON_GetObjectItem(root, "challenge"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(root, "manualComplete"))
|
if (cJSON_GetObjectItem(root, "manualComplete"))
|
||||||
{
|
{
|
||||||
battle.manualComplete = cJSON_GetObjectItem(root, "manualComplete")->valueint;
|
battle.manualComplete = cJSON_GetObjectItem(root, "manualComplete")->valueint;
|
||||||
|
@ -195,7 +193,7 @@ void loadMission(char *filename)
|
||||||
{
|
{
|
||||||
game.stats[STAT_MISSIONS_STARTED]++;
|
game.stats[STAT_MISSIONS_STARTED]++;
|
||||||
}
|
}
|
||||||
else if (battle.challengeData.isChallenge)
|
else if (game.currentMission->challengeData.isChallenge)
|
||||||
{
|
{
|
||||||
game.stats[STAT_CHALLENGES_STARTED]++;
|
game.stats[STAT_CHALLENGES_STARTED]++;
|
||||||
}
|
}
|
||||||
|
@ -219,7 +217,7 @@ static char *getAutoBackground(char *filename)
|
||||||
{
|
{
|
||||||
int hash;
|
int hash;
|
||||||
|
|
||||||
if (!battle.challengeData.isChallenge)
|
if (!game.currentMission->challengeData.isChallenge)
|
||||||
{
|
{
|
||||||
hash = hashcode(game.selectedStarSystem);
|
hash = hashcode(game.selectedStarSystem);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +233,7 @@ static char *getAutoPlanet(char *filename)
|
||||||
{
|
{
|
||||||
int hash;
|
int hash;
|
||||||
|
|
||||||
if (!battle.challengeData.isChallenge)
|
if (!game.currentMission->challengeData.isChallenge)
|
||||||
{
|
{
|
||||||
hash = hashcode(game.selectedStarSystem);
|
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)
|
Mission *getMission(char *filename)
|
||||||
{
|
{
|
||||||
StarSystem *starSystem;
|
StarSystem *starSystem;
|
||||||
|
|
|
@ -240,6 +240,15 @@ struct Challenge {
|
||||||
Challenge *next;
|
Challenge *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int isChallenge;
|
||||||
|
int timeLimit;
|
||||||
|
int killLimit;
|
||||||
|
int lossLimit;
|
||||||
|
int itemLimit;
|
||||||
|
Challenge challengeHead;
|
||||||
|
} ChallengeData;
|
||||||
|
|
||||||
struct Mission {
|
struct Mission {
|
||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
char description[MAX_DESCRIPTION_LENGTH];
|
char description[MAX_DESCRIPTION_LENGTH];
|
||||||
|
@ -253,7 +262,7 @@ struct Mission {
|
||||||
int completedChallenges;
|
int completedChallenges;
|
||||||
int totalChallenges;
|
int totalChallenges;
|
||||||
int epic;
|
int epic;
|
||||||
Challenge challengeHead;
|
ChallengeData challengeData;
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
Mission *next;
|
Mission *next;
|
||||||
};
|
};
|
||||||
|
@ -282,14 +291,6 @@ struct Quadtree {
|
||||||
Quadtree *node[4];
|
Quadtree *node[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int isChallenge;
|
|
||||||
int timeLimit;
|
|
||||||
int killLimit;
|
|
||||||
int lossLimit;
|
|
||||||
int itemLimit;
|
|
||||||
} ChallengeData;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int entId;
|
int entId;
|
||||||
SDL_Point camera;
|
SDL_Point camera;
|
||||||
|
@ -321,7 +322,6 @@ typedef struct {
|
||||||
Location locationHead, *locationTail;
|
Location locationHead, *locationTail;
|
||||||
struct cJSON *missionJSON;
|
struct cJSON *missionJSON;
|
||||||
unsigned int stats[STAT_MAX];
|
unsigned int stats[STAT_MAX];
|
||||||
ChallengeData challengeData;
|
|
||||||
Quadtree quadtree;
|
Quadtree quadtree;
|
||||||
} Battle;
|
} Battle;
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ static void saveChallenges(cJSON *gameJSON)
|
||||||
|
|
||||||
challengesJSON = cJSON_CreateArray();
|
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();
|
challengeJSON = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type));
|
cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type));
|
||||||
|
|
Loading…
Reference in New Issue