From 7979b175a22b056e539b3bec6996a0580dba3b2b Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 4 Mar 2016 22:59:16 +0000 Subject: [PATCH] Waypoint challenge updates. --- data/challenges/07.json | 79 +++++++++++++++++-------------------- src/battle/waypoints.c | 2 + src/challenges/challenges.c | 55 ++++++++++++++------------ src/challenges/challenges.h | 1 + src/defs.h | 2 +- src/galaxy/mission.c | 4 +- src/galaxy/stats.c | 1 + src/structs.h | 1 + src/system/lookup.c | 2 +- 9 files changed, 76 insertions(+), 71 deletions(-) diff --git a/data/challenges/07.json b/data/challenges/07.json index 54a9a1b..0196e3c 100644 --- a/data/challenges/07.json +++ b/data/challenges/07.json @@ -14,18 +14,19 @@ }, "challenge" : { "waypointLimit" : 5, + "timeLimit" : 120, "challenges" : [ { "type" : "CHALLENGE_TIME", - "value" : 60 - }, - { - "type" : "CHALLENGE_TIME", - "value" : 90 + "value" : 80 }, { "type" : "CHALLENGE_TIME", "value" : 120 + }, + { + "type" : "CHALLENGE_ARMOUR", + "value" : 100 } ] }, @@ -33,34 +34,46 @@ { "groupName" : "RT1", "types" : "Rocket Turret", - "x" : 35, - "y" : 15, + "x" : 30, + "y" : 30, "side" : "SIDE_REBEL", - "active" : 0 + "scatter" : 1000, + "number" : 2 + }, + { + "groupName" : "RT1", + "types" : "Rocket Turret", + "x" : 30, + "y" : 20, + "side" : "SIDE_REBEL", + "scatter" : 1000, + "number" : 2 }, { "groupName" : "RT2", "types" : "Rocket Turret", - "x" : 15, - "y" : 15, + "x" : 20, + "y" : 20, "side" : "SIDE_REBEL", - "active" : 0 + "scatter" : 1000, + "number" : 2 }, { "groupName" : "RT3", "types" : "Rocket Turret", - "x" : 15, - "y" : 35, + "x" : 20, + "y" : 30, "side" : "SIDE_REBEL", - "active" : 0 - } + "scatter" : 1000, + "number" : 2 + }, { "groupName" : "RT4", "types" : "Rocket Turret", "x" : 25, "y" : 25, "side" : "SIDE_REBEL", - "scatter" : 500, + "scatter" : 1000, "number" : 2, "active" : 0 } @@ -68,26 +81,26 @@ "entities" : [ { "type" : "ET_WAYPOINT", - "x" : 35, - "y" : 35, + "x" : 30, + "y" : 30, "active" : 0 }, { "type" : "ET_WAYPOINT", - "x" : 35, - "y" : 15, + "x" : 30, + "y" : 20, "active" : 0 }, { "type" : "ET_WAYPOINT", - "x" : 15, - "y" : 15, + "x" : 20, + "y" : 20, "active" : 0 }, { "type" : "ET_WAYPOINT", - "x" : 15, - "y" : 35, + "x" : 20, + "y" : 30, "active" : 0 }, { @@ -98,24 +111,6 @@ } ], "script" : [ - { - "function" : "Waypoint #1", - "lines" : [ - "ACTIVATE_ENTITY_GROUPS RT1" - ] - }, - { - "function" : "Waypoint #2", - "lines" : [ - "ACTIVATE_ENTITY_GROUPS RT2" - ] - }, - { - "function" : "Waypoint #3", - "lines" : [ - "ACTIVATE_ENTITY_GROUPS RT3" - ] - }, { "function" : "Waypoint #4", "lines" : [ diff --git a/src/battle/waypoints.c b/src/battle/waypoints.c index 79b3150..cd87001 100644 --- a/src/battle/waypoints.c +++ b/src/battle/waypoints.c @@ -67,6 +67,8 @@ static void think(void) runScriptFunction(self->name); activateNextWaypoint(self->id); + + battle.stats[STAT_WAYPOINTS_VISITED]++; } } diff --git a/src/challenges/challenges.c b/src/challenges/challenges.c index 5a734ed..379e860 100644 --- a/src/challenges/challenges.c +++ b/src/challenges/challenges.c @@ -32,6 +32,7 @@ static void updateChallenges(void); static char *getFormattedChallengeDescription(const char *format, ...); char *getChallengeDescription(Challenge *c); static int hasFailedAllChallenges(void); +static int challengeFinished(void); static void printStats(void); static char descriptionBuffer[MAX_DESCRIPTION_LENGTH]; @@ -54,7 +55,6 @@ void initChallenges(void) challengeDescription[CHALLENGE_LOSSES] = _("Do not lose more than %d team mates"); challengeDescription[CHALLENGE_PLAYER_KILLS] = _("Take down %d enemy targets"); challengeDescription[CHALLENGE_DISABLE] = _("Disable %d or more enemy fighters"); - challengeDescription[CHALLENGE_TIME_MINS] = _("Complete challenge in %d minutes or less"); tail = &game.challengeMissionHead; @@ -78,7 +78,7 @@ void doChallenges(void) { if (game.currentMission->challengeData.isChallenge && battle.status == MS_IN_PROGRESS) { - if (game.currentMission->challengeData.timeLimit > 0 && battle.stats[STAT_TIME] >= game.currentMission->challengeData.timeLimit) + if (challengeFinished()) { updateChallenges(); @@ -91,17 +91,35 @@ void doChallenges(void) completeChallenge(); } } - - /* disabled enemies count as killed during challenges - not player exclusive, but no need to worry about AI contributions here */ - if (game.currentMission->challengeData.killLimit > 0 && (battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_ENEMIES_DISABLED]) >= game.currentMission->challengeData.killLimit) - { - updateChallenges(); - - completeChallenge(); - } } } +static int challengeFinished(void) +{ + if (game.currentMission->challengeData.timeLimit > 0 && battle.stats[STAT_TIME] >= game.currentMission->challengeData.timeLimit) + { + return 1; + } + + /* disabled enemies count as killed during challenges - not player exclusive, but no need to worry about AI contributions here */ + if (game.currentMission->challengeData.killLimit > 0 && (battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_ENEMIES_DISABLED]) >= game.currentMission->challengeData.killLimit) + { + return 1; + } + + if (game.currentMission->challengeData.waypointLimit > 0 && battle.stats[STAT_WAYPOINTS_VISITED] >= game.currentMission->challengeData.waypointLimit) + { + return 1; + } + + if (game.currentMission->challengeData.itemLimit > 0 && battle.stats[STAT_ITEMS_COLLECTED] >= game.currentMission->challengeData.itemLimit) + { + return 1; + } + + return 0; +} + static int hasFailedAllChallenges(void) { int i; @@ -136,7 +154,6 @@ static void updateChallenges(void) switch (c->type) { case CHALLENGE_TIME: - case CHALLENGE_TIME_MINS: updateTimeChallenge(c); break; @@ -195,21 +212,9 @@ static void printStats(void) static void updateTimeChallenge(Challenge *c) { - switch (c->type) + if (battle.stats[STAT_TIME] / FPS < c->value) { - case CHALLENGE_TIME: - if (battle.stats[STAT_TIME] / FPS < c->value) - { - c->passed = 1; - } - break; - - case CHALLENGE_TIME_MINS: - if ((battle.stats[STAT_TIME] / FPS) / 60 < c->value) - { - c->passed = 1; - } - break; + c->passed = 1; } } diff --git a/src/challenges/challenges.h b/src/challenges/challenges.h index 81f7cfe..b148329 100644 --- a/src/challenges/challenges.h +++ b/src/challenges/challenges.h @@ -30,6 +30,7 @@ extern char *getLookupName(char *prefix, long num); extern char *timeToString(long millis, int showHours); extern int getPercent(float current, float total); extern void updateAccuracyStats(unsigned int *stats); +extern char *timeToString(long millis, int showHours); extern Dev dev; extern Battle battle; diff --git a/src/defs.h b/src/defs.h index 56c4005..63fc269 100644 --- a/src/defs.h +++ b/src/defs.h @@ -287,7 +287,6 @@ enum CHALLENGE_LOSSES, CHALLENGE_PLAYER_KILLS, CHALLENGE_DISABLE, - CHALLENGE_TIME_MINS, CHALLENGE_MAX }; @@ -323,6 +322,7 @@ enum STAT_SHUTTLE, STAT_NUM_TOWED, STAT_ITEMS_COLLECTED, + STAT_WAYPOINTS_VISITED, STAT_EPIC_KILL_STREAK, STAT_CAPITAL_SHIPS_DESTROYED, STAT_CAPITAL_SHIPS_LOST, diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 33e254c..58327ea 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -76,8 +76,8 @@ Mission *loadMissionMeta(char *filename) if (node) { mission->challengeData.isChallenge = 1; - - mission->challengeData.timeLimit = getJSONValue(node, "timeLimit", 0); + + mission->challengeData.timeLimit = getJSONValue(node, "timeLimit", 0) * FPS; mission->challengeData.killLimit = getJSONValue(node, "killLimit", 0); mission->challengeData.waypointLimit = getJSONValue(node, "waypointLimit", 0); mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0); diff --git a/src/galaxy/stats.c b/src/galaxy/stats.c index 713fdd3..952c8c5 100644 --- a/src/galaxy/stats.c +++ b/src/galaxy/stats.c @@ -64,6 +64,7 @@ void initStats(void) statDescription[STAT_NUM_TOWED] = _("Craft Towed"); statDescription[STAT_ITEMS_COLLECTED] = _("Items Collected"); statDescription[STAT_EPIC_KILL_STREAK] = _("Longest Epic Kill Streak"); + statDescription[STAT_WAYPOINTS_VISITED] = _("Waypoints Visited"); statDescription[STAT_CAPITAL_SHIPS_DESTROYED] = _("Capital Ships Destroyed"); statDescription[STAT_CAPITAL_SHIPS_LOST] = _("Capital Ships Lost"); statDescription[STAT_TIME] = _("Time Played"); diff --git a/src/structs.h b/src/structs.h index 5f1987c..64d2977 100644 --- a/src/structs.h +++ b/src/structs.h @@ -247,6 +247,7 @@ typedef struct { int killLimit; int lossLimit; int itemLimit; + int waypointLimit; int noMissiles; int noBoost; int noECM; diff --git a/src/system/lookup.c b/src/system/lookup.c index ce6ed44..04aef2e 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -130,7 +130,6 @@ void initLookups(void) addLookup("CHALLENGE_LOSSES", CHALLENGE_LOSSES); addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS); addLookup("CHALLENGE_DISABLE", CHALLENGE_DISABLE); - addLookup("CHALLENGE_TIME_MINS", CHALLENGE_TIME_MINS); addLookup("STAT_PERCENT_COMPLETE", STAT_PERCENT_COMPLETE); addLookup("STAT_MISSIONS_STARTED", STAT_MISSIONS_STARTED); @@ -162,6 +161,7 @@ void initLookups(void) addLookup("STAT_SHUTTLE", STAT_SHUTTLE); addLookup("STAT_NUM_TOWED", STAT_NUM_TOWED); addLookup("STAT_ITEMS_COLLECTED", STAT_ITEMS_COLLECTED); + addLookup("STAT_WAYPOINTS_VISITED", STAT_WAYPOINTS_VISITED); addLookup("STAT_EPIC_KILL_STREAK", STAT_EPIC_KILL_STREAK); addLookup("STAT_CAPITAL_SHIPS_DESTROYED", STAT_CAPITAL_SHIPS_DESTROYED); addLookup("STAT_CAPITAL_SHIPS_LOST", STAT_CAPITAL_SHIPS_LOST);