Refactored challenge data, for display on Challenge Home.

This commit is contained in:
Steve 2016-03-02 06:46:13 +00:00
parent 9dac6aa0ba
commit 0c31b2204c
8 changed files with 42 additions and 48 deletions

View File

@ -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)
{

View File

@ -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
{

View File

@ -39,3 +39,4 @@ extern App app;
extern Battle battle;
extern Colors colors;
extern Entity *player;
extern Game game;

View File

@ -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;

View File

@ -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++;

View File

@ -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;

View File

@ -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;

View File

@ -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));