Allow disabled fighters to be destroyed. Added more challenges and stats.

This commit is contained in:
Steve 2015-10-24 16:00:06 +01:00
parent a21153cb12
commit 5081b011cf
12 changed files with 149 additions and 49 deletions

View File

@ -25,6 +25,16 @@
"isCondition" : 1 "isCondition" : 1
} }
], ],
"challenges" : [
{
"type" : "CHALLENGE_TIME_MINS",
"targetValue" : 3
},
{
"type" : "CHALLENGE_DISABLE",
"targetValue" : 3
}
],
"player" : { "player" : {
"type" : "Ray", "type" : "Ray",
"side" : "SIDE_ALLIES", "side" : "SIDE_ALLIES",

View File

@ -166,7 +166,7 @@ static void faceTarget(Bullet *b)
brakeAmount = angleDist; brakeAmount = angleDist;
brakeAmount /= 360; brakeAmount /= 360;
brakeAmount = 0.7 - brakeAmount; brakeAmount = 0.6 - brakeAmount;
/* halve your speed while you're not at the correct angle */ /* halve your speed while you're not at the correct angle */
b->dx *= brakeAmount; b->dx *= brakeAmount;

View File

@ -25,6 +25,7 @@ static void updateAccuracyChallenge(Challenge *c);
static void updateArmourChallenge(Challenge *c); static void updateArmourChallenge(Challenge *c);
static void updateLossesChallenge(Challenge *c); static void updateLossesChallenge(Challenge *c);
static void updatePlayerKillsChallenge(Challenge *c); static void updatePlayerKillsChallenge(Challenge *c);
static void updateDisabledChallenge(Challenge *c);
static char *getFormattedChallengeDescription(const char *format, ...); static char *getFormattedChallengeDescription(const char *format, ...);
char *getChallengeDescription(Challenge *c); char *getChallengeDescription(Challenge *c);
@ -37,7 +38,9 @@ static char *challengeDescription[] = {
"Do not lose any team mates", "Do not lose any team mates",
"Do not lose more than 1 team mate", "Do not lose more than 1 team mate",
"Do not lose more than %d team mates", "Do not lose more than %d team mates",
"Take down %d enemy targets" "Take down %d enemy targets",
"Disable %d or more enemy fighters",
"Finish mission in %d minutes or less"
}; };
void updateChallenges(void) void updateChallenges(void)
@ -51,6 +54,7 @@ void updateChallenges(void)
switch (c->type) switch (c->type)
{ {
case CHALLENGE_TIME: case CHALLENGE_TIME:
case CHALLENGE_TIME_MINS:
updateTimeChallenge(c); updateTimeChallenge(c);
break; break;
@ -71,6 +75,10 @@ void updateChallenges(void)
case CHALLENGE_PLAYER_KILLS: case CHALLENGE_PLAYER_KILLS:
updatePlayerKillsChallenge(c); updatePlayerKillsChallenge(c);
break; break;
case CHALLENGE_DISABLE:
updateDisabledChallenge(c);
break;
} }
} }
} }
@ -78,9 +86,21 @@ void updateChallenges(void)
static void updateTimeChallenge(Challenge *c) static void updateTimeChallenge(Challenge *c)
{ {
if (battle.stats.time / FPS <= c->targetValue) switch (c->type)
{ {
c->passed = 1; case CHALLENGE_TIME:
if (battle.stats.time / FPS <= c->targetValue)
{
c->passed = 1;
}
break;
case CHALLENGE_TIME_MINS:
if ((battle.stats.time / FPS) / 60 <= c->targetValue)
{
c->passed = 1;
}
break;
} }
} }
@ -128,6 +148,14 @@ static void updatePlayerKillsChallenge(Challenge *c)
} }
} }
static void updateDisabledChallenge(Challenge *c)
{
if (!c->passed)
{
c->passed = battle.stats.disabled >= c->targetValue;
}
}
char *getChallengeDescription(Challenge *c) char *getChallengeDescription(Challenge *c)
{ {
return getFormattedChallengeDescription(challengeDescription[c->type], c->targetValue); return getFormattedChallengeDescription(challengeDescription[c->type], c->targetValue);

View File

@ -236,30 +236,32 @@ void doFighters(void)
} }
} }
if (f->health <= 0 && f->alive == ALIVE_ALIVE) if (f->alive == ALIVE_ALIVE)
{ {
f->health = 0; if (f->health <= 0)
f->alive = ALIVE_DYING;
f->die();
if (f == battle.missionTarget)
{ {
battle.missionTarget = NULL; f->health = 0;
f->alive = ALIVE_DYING;
f->die();
if (f == battle.missionTarget)
{
battle.missionTarget = NULL;
}
} }
} else if (f->systemPower <= 0)
if (f->systemPower <= 0)
{
f->dx *= 0.99;
f->dy *= 0.99;
f->thrust = 0;
f->shield = f->maxShield = 0;
f->action = NULL;
if (f->alive == ALIVE_ALIVE)
{ {
updateObjective(f->name, TT_DISABLE); f->dx *= 0.99;
f->alive = ALIVE_DISABLED; f->dy *= 0.99;
f->thrust = 0;
f->shield = f->maxShield = 0;
f->action = NULL;
if (f->alive == ALIVE_ALIVE)
{
updateObjective(f->name, TT_DISABLE);
battle.stats.disabled++;
}
} }
} }

View File

@ -68,8 +68,7 @@ enum
{ {
ALIVE_ALIVE, ALIVE_ALIVE,
ALIVE_DYING, ALIVE_DYING,
ALIVE_DEAD, ALIVE_DEAD
ALIVE_DISABLED
}; };
enum enum
@ -167,5 +166,7 @@ enum
CHALLENGE_NO_LOSSES, CHALLENGE_NO_LOSSES,
CHALLENGE_1_LOSS, CHALLENGE_1_LOSS,
CHALLENGE_LOSSES, CHALLENGE_LOSSES,
CHALLENGE_PLAYER_KILLS CHALLENGE_PLAYER_KILLS,
CHALLENGE_DISABLE,
CHALLENGE_TIME_MINS
}; };

View File

@ -86,7 +86,7 @@ void drawStats(void)
drawText(r.x + 20, y, 18, TA_LEFT, colors.white, "Times Killed"); drawText(r.x + 20, y, 18, TA_LEFT, colors.white, "Times Killed");
drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats.playerKilled); drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats.playerKilled);
y += 40; y += 60;
seconds = game.stats.time / FPS; seconds = game.stats.time / FPS;
minutes = (seconds / 60) % 60; minutes = (seconds / 60) % 60;

View File

@ -202,16 +202,17 @@ struct StarSystem {
}; };
typedef struct { typedef struct {
int missionsStarted; unsigned int missionsStarted;
int missionsCompleted; unsigned int missionsCompleted;
int shotsFired; unsigned int shotsFired;
int shotsHit; unsigned int shotsHit;
int missilesFired; unsigned int missilesFired;
int missilesHit; unsigned int missilesHit;
int enemiesKilled; unsigned int enemiesKilled;
int alliesKilled; unsigned int alliesKilled;
int playerKilled; unsigned int playerKilled;
int playerKills; unsigned int playerKills;
unsigned int disabled;
unsigned int time; unsigned int time;
} Stats; } Stats;

View File

@ -24,6 +24,7 @@ static void loadStats(cJSON *stats);
static void loadStarSystems(cJSON *starSystemsJSON); static void loadStarSystems(cJSON *starSystemsJSON);
static void loadMissions(StarSystem *starSystem, cJSON *missionsCJSON); static void loadMissions(StarSystem *starSystem, cJSON *missionsCJSON);
static void loadChallenges(Mission *mission, cJSON *challengesCJSON); static void loadChallenges(Mission *mission, cJSON *challengesCJSON);
static int getStat(cJSON *stats, char *name);
void loadGame(void) void loadGame(void)
{ {
@ -95,15 +96,26 @@ static void loadChallenges(Mission *mission, cJSON *challengesCJSON)
static void loadStats(cJSON *stats) static void loadStats(cJSON *stats)
{ {
game.stats.missionsStarted = cJSON_GetObjectItem(stats, "missionsStarted")->valueint; game.stats.missionsStarted = getStat(stats, "missionsStarted");
game.stats.missionsCompleted = cJSON_GetObjectItem(stats, "missionsCompleted")->valueint; game.stats.missionsCompleted = getStat(stats, "missionsCompleted");
game.stats.shotsFired = cJSON_GetObjectItem(stats, "shotsFired")->valueint; game.stats.shotsFired = getStat(stats, "shotsFired");
game.stats.shotsHit = cJSON_GetObjectItem(stats, "shotsHit")->valueint; game.stats.shotsHit = getStat(stats, "shotsHit");
game.stats.missilesFired = cJSON_GetObjectItem(stats, "missilesFired")->valueint; game.stats.missilesFired = getStat(stats, "missilesFired");
game.stats.missilesHit = cJSON_GetObjectItem(stats, "missilesHit")->valueint; game.stats.missilesHit = getStat(stats, "missilesHit");
game.stats.enemiesKilled = cJSON_GetObjectItem(stats, "enemiesKilled")->valueint; game.stats.enemiesKilled = getStat(stats, "enemiesKilled");
game.stats.alliesKilled = cJSON_GetObjectItem(stats, "alliesKilled")->valueint; game.stats.alliesKilled = getStat(stats, "alliesKilled");
game.stats.playerKilled = cJSON_GetObjectItem(stats, "playerKilled")->valueint; game.stats.playerKilled = getStat(stats, "playerKilled");
game.stats.playerKills = cJSON_GetObjectItem(stats, "playerKills")->valueint; game.stats.playerKills = getStat(stats, "playerKills");
game.stats.time = cJSON_GetObjectItem(stats, "time")->valueint; game.stats.disabled = getStat(stats, "disabled");
game.stats.time = getStat(stats, "time");
}
static int getStat(cJSON *stats, char *name)
{
if (cJSON_GetObjectItem(stats, name))
{
return cJSON_GetObjectItem(stats, name)->valueint;
}
return 0;
} }

View File

@ -76,6 +76,8 @@ void initLookups(void)
addLookup("CHALLENGE_1_LOSS", CHALLENGE_1_LOSS); addLookup("CHALLENGE_1_LOSS", CHALLENGE_1_LOSS);
addLookup("CHALLENGE_LOSSES", CHALLENGE_LOSSES); addLookup("CHALLENGE_LOSSES", CHALLENGE_LOSSES);
addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS); addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS);
addLookup("CHALLENGE_DISABLE", CHALLENGE_DISABLE);
addLookup("CHALLENGE_TIME_MINS", CHALLENGE_TIME_MINS);
} }
static void addLookup(char *name, long value) static void addLookup(char *name, long value)

View File

@ -128,6 +128,7 @@ static void saveStats(cJSON *gameJSON)
cJSON_AddNumberToObject(stats, "alliesKilled", game.stats.alliesKilled); cJSON_AddNumberToObject(stats, "alliesKilled", game.stats.alliesKilled);
cJSON_AddNumberToObject(stats, "playerKilled", game.stats.playerKilled); cJSON_AddNumberToObject(stats, "playerKilled", game.stats.playerKilled);
cJSON_AddNumberToObject(stats, "playerKills", game.stats.playerKills); cJSON_AddNumberToObject(stats, "playerKills", game.stats.playerKills);
cJSON_AddNumberToObject(stats, "disabled", game.stats.disabled);
cJSON_AddNumberToObject(stats, "time", game.stats.time); cJSON_AddNumberToObject(stats, "time", game.stats.time);
cJSON_AddItemToObject(gameJSON, "stats", stats); cJSON_AddItemToObject(gameJSON, "stats", stats);

View File

@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static Mission mission; static Mission mission;
static void loadChallenges(char *filename);
void loadTestMission(char *filename) void loadTestMission(char *filename)
{ {
memset(&mission, 0, sizeof(Mission)); memset(&mission, 0, sizeof(Mission));
@ -33,4 +35,42 @@ void loadTestMission(char *filename)
initBattle(); initBattle();
loadMission(filename); loadMission(filename);
loadChallenges(filename);
}
static void loadChallenges(char *filename)
{
Challenge *challenge, *challengeTail;
cJSON *root, *node;
char *text;
text = readFile(filename);
root = cJSON_Parse(text);
challengeTail = &mission.challengeHead;
node = cJSON_GetObjectItem(root, "challenges");
if (node)
{
node = node->child;
while (node)
{
challenge = malloc(sizeof(Challenge));
memset(challenge, 0, sizeof(Challenge));
challenge->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
challenge->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
challengeTail->next = challenge;
challengeTail = challenge;
node = node->next;
}
}
cJSON_Delete(root);
free(text);
} }

View File

@ -22,8 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../defs.h" #include "../defs.h"
#include "../structs.h" #include "../structs.h"
#include "../json/cJSON.h"
extern void initBattle(void); extern void initBattle(void);
extern void loadMission(char *filename); extern void loadMission(char *filename);
extern long lookup(char *name);
extern char *readFile(char *filename);
extern Game game; extern Game game;