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
}
],
"challenges" : [
{
"type" : "CHALLENGE_TIME_MINS",
"targetValue" : 3
},
{
"type" : "CHALLENGE_DISABLE",
"targetValue" : 3
}
],
"player" : {
"type" : "Ray",
"side" : "SIDE_ALLIES",

View File

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

View File

@ -25,6 +25,7 @@ static void updateAccuracyChallenge(Challenge *c);
static void updateArmourChallenge(Challenge *c);
static void updateLossesChallenge(Challenge *c);
static void updatePlayerKillsChallenge(Challenge *c);
static void updateDisabledChallenge(Challenge *c);
static char *getFormattedChallengeDescription(const char *format, ...);
char *getChallengeDescription(Challenge *c);
@ -37,7 +38,9 @@ static char *challengeDescription[] = {
"Do not lose any team mates",
"Do not lose more than 1 team mate",
"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)
@ -51,6 +54,7 @@ void updateChallenges(void)
switch (c->type)
{
case CHALLENGE_TIME:
case CHALLENGE_TIME_MINS:
updateTimeChallenge(c);
break;
@ -71,6 +75,10 @@ void updateChallenges(void)
case CHALLENGE_PLAYER_KILLS:
updatePlayerKillsChallenge(c);
break;
case CHALLENGE_DISABLE:
updateDisabledChallenge(c);
break;
}
}
}
@ -78,9 +86,21 @@ void updateChallenges(void)
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)
{
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;
f->alive = ALIVE_DYING;
f->die();
if (f == battle.missionTarget)
if (f->health <= 0)
{
battle.missionTarget = NULL;
f->health = 0;
f->alive = ALIVE_DYING;
f->die();
if (f == battle.missionTarget)
{
battle.missionTarget = NULL;
}
}
}
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)
else if (f->systemPower <= 0)
{
updateObjective(f->name, TT_DISABLE);
f->alive = ALIVE_DISABLED;
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);
battle.stats.disabled++;
}
}
}

View File

@ -68,8 +68,7 @@ enum
{
ALIVE_ALIVE,
ALIVE_DYING,
ALIVE_DEAD,
ALIVE_DISABLED
ALIVE_DEAD
};
enum
@ -167,5 +166,7 @@ enum
CHALLENGE_NO_LOSSES,
CHALLENGE_1_LOSS,
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 + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats.playerKilled);
y += 40;
y += 60;
seconds = game.stats.time / FPS;
minutes = (seconds / 60) % 60;

View File

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

View File

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

View File

@ -128,6 +128,7 @@ static void saveStats(cJSON *gameJSON)
cJSON_AddNumberToObject(stats, "alliesKilled", game.stats.alliesKilled);
cJSON_AddNumberToObject(stats, "playerKilled", game.stats.playerKilled);
cJSON_AddNumberToObject(stats, "playerKills", game.stats.playerKills);
cJSON_AddNumberToObject(stats, "disabled", game.stats.disabled);
cJSON_AddNumberToObject(stats, "time", game.stats.time);
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 void loadChallenges(char *filename);
void loadTestMission(char *filename)
{
memset(&mission, 0, sizeof(Mission));
@ -33,4 +35,42 @@ void loadTestMission(char *filename)
initBattle();
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 "../structs.h"
#include "../json/cJSON.h"
extern void initBattle(void);
extern void loadMission(char *filename);
extern long lookup(char *name);
extern char *readFile(char *filename);
extern Game game;