Added Survive challenge type.
This commit is contained in:
parent
97d7e542e2
commit
5fa24f55f2
|
@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "challenges.h"
|
||||
|
||||
static void updateTimeChallenge(Challenge *c);
|
||||
static void updateSurvivalChallenge(Challenge *c);
|
||||
static void updateAccuracyChallenge(Challenge *c);
|
||||
static void updateArmourChallenge(Challenge *c);
|
||||
static void updateLossesChallenge(Challenge *c);
|
||||
|
@ -48,6 +49,7 @@ void initChallenges(void)
|
|||
|
||||
challengeDescription[CHALLENGE_ARMOUR] = _("Retain at least %d%% armour");
|
||||
challengeDescription[CHALLENGE_TIME] = _("Complete challenge in %d seconds or less");
|
||||
challengeDescription[CHALLENGE_SURVIVE] = _("Survive for %d seconds");
|
||||
challengeDescription[CHALLENGE_SHOT_ACCURACY] = _("Attain a %d%% shot hit accuracy");
|
||||
challengeDescription[CHALLENGE_ROCKET_ACCURACY] = _("Attain a %d%% rocket hit accuracy");
|
||||
challengeDescription[CHALLENGE_MISSILE_ACCURACY] = _("Attain a %d%% missile hit accuracy");
|
||||
|
@ -81,6 +83,60 @@ void initChallenges(void)
|
|||
free(filenames);
|
||||
}
|
||||
|
||||
void loadChallenge(Mission *mission, cJSON *node)
|
||||
{
|
||||
int i;
|
||||
Challenge *challenge;
|
||||
|
||||
mission->challengeData.isChallenge = 1;
|
||||
|
||||
/* limits */
|
||||
mission->challengeData.timeLimit = getJSONValue(node, "timeLimit", 0) * FPS;
|
||||
mission->challengeData.killLimit = getJSONValue(node, "killLimit", 0);
|
||||
mission->challengeData.escapeLimit = getJSONValue(node, "escapeLimit", 0);
|
||||
mission->challengeData.waypointLimit = getJSONValue(node, "waypointLimit", 0);
|
||||
mission->challengeData.itemLimit = getJSONValue(node, "itemLimit", 0);
|
||||
mission->challengeData.rescueLimit = getJSONValue(node, "rescueLimit", 0);
|
||||
|
||||
/* restrictions */
|
||||
mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0);
|
||||
mission->challengeData.noECM = getJSONValue(node, "noECM", 0);
|
||||
mission->challengeData.noBoost = getJSONValue(node, "noBoost", 0);
|
||||
mission->challengeData.noGuns = getJSONValue(node, "noGuns", 0);
|
||||
|
||||
if (getJSONValue(node, "noWeapons", 0))
|
||||
{
|
||||
mission->challengeData.noMissiles = mission->challengeData.noGuns = 1;
|
||||
}
|
||||
|
||||
/* misc */
|
||||
mission->challengeData.allowPlayerDeath = getJSONValue(node, "allowPlayerDeath", 0);
|
||||
|
||||
node = cJSON_GetObjectItem(node, "challenges");
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
i = 0;
|
||||
|
||||
while (node && i < MAX_CHALLENGES)
|
||||
{
|
||||
challenge = malloc(sizeof(Challenge));
|
||||
memset(challenge, 0, sizeof(Challenge));
|
||||
|
||||
challenge->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
||||
challenge->value = cJSON_GetObjectItem(node, "value")->valueint;
|
||||
|
||||
mission->challengeData.challenges[i] = challenge;
|
||||
|
||||
node = node->next;
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void doChallenges(void)
|
||||
{
|
||||
int passed;
|
||||
|
@ -172,6 +228,10 @@ static int updateChallenges(void)
|
|||
updateTimeChallenge(c);
|
||||
break;
|
||||
|
||||
case CHALLENGE_SURVIVE:
|
||||
updateSurvivalChallenge(c);
|
||||
break;
|
||||
|
||||
case CHALLENGE_SHOT_ACCURACY:
|
||||
case CHALLENGE_ROCKET_ACCURACY:
|
||||
case CHALLENGE_MISSILE_ACCURACY:
|
||||
|
@ -245,6 +305,14 @@ static void updateTimeChallenge(Challenge *c)
|
|||
}
|
||||
}
|
||||
|
||||
static void updateSurvivalChallenge(Challenge *c)
|
||||
{
|
||||
if (battle.stats[STAT_TIME] / FPS >= c->value)
|
||||
{
|
||||
c->passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void updateAccuracyChallenge(Challenge *c)
|
||||
{
|
||||
float percent;
|
||||
|
|
|
@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
|
||||
#include "../common.h"
|
||||
#include "../json/cJSON.h"
|
||||
|
||||
extern Mission *loadMissionMeta(char *filename);
|
||||
extern char **getFileList(char *dir, int *count);
|
||||
|
@ -30,6 +31,8 @@ extern char *getLookupName(char *prefix, long num);
|
|||
extern char *timeToString(long millis, int showHours);
|
||||
extern void updateAccuracyStats(unsigned int *stats);
|
||||
extern char *timeToString(long millis, int showHours);
|
||||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
extern long lookup(char *name);
|
||||
|
||||
extern Dev dev;
|
||||
extern Battle battle;
|
||||
|
|
|
@ -309,6 +309,7 @@ enum
|
|||
CHALLENGE_DISABLE,
|
||||
CHALLENGE_ITEMS,
|
||||
CHALLENGE_RESCUE,
|
||||
CHALLENGE_SURVIVE,
|
||||
CHALLENGE_MAX
|
||||
};
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ void initLookups(void)
|
|||
|
||||
addLookup("CHALLENGE_ARMOUR", CHALLENGE_ARMOUR);
|
||||
addLookup("CHALLENGE_TIME", CHALLENGE_TIME);
|
||||
addLookup("CHALLENGE_SURVIVE", CHALLENGE_SURVIVE);
|
||||
addLookup("CHALLENGE_SHOT_ACCURACY", CHALLENGE_SHOT_ACCURACY);
|
||||
addLookup("CHALLENGE_ROCKET_ACCURACY", CHALLENGE_ROCKET_ACCURACY);
|
||||
addLookup("CHALLENGE_MISSILE_ACCURACY", CHALLENGE_MISSILE_ACCURACY);
|
||||
|
|
Loading…
Reference in New Issue