Start of Frequent Flyer trophy.

This commit is contained in:
Steve 2016-05-17 19:02:58 +01:00
parent 8bbe9f69e2
commit b55574a9e6
31 changed files with 153 additions and 23 deletions

View File

@ -35,5 +35,5 @@
} }
], ],
"missiles" : 5, "missiles" : 5,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -17,5 +17,5 @@
} }
], ],
"missiles" : 2, "missiles" : 2,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -25,5 +25,5 @@
], ],
"combinedGuns" : 1, "combinedGuns" : 1,
"missiles" : 3, "missiles" : 3,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -24,6 +24,6 @@
} }
], ],
"missiles" : 6, "missiles" : 6,
"flags" : "EF_TAKES_DAMAGE", "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER",
"aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE" "aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE"
} }

View File

@ -29,5 +29,5 @@
} }
], ],
"missiles" : 4, "missiles" : 4,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -29,5 +29,5 @@
} }
], ],
"missiles" : 4, "missiles" : 4,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -19,5 +19,5 @@
} }
], ],
"missiles" : 3, "missiles" : 3,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -29,6 +29,6 @@
} }
], ],
"missiles" : 8, "missiles" : 8,
"flags" : "EF_TAKES_DAMAGE", "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER",
"aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE" "aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE"
} }

View File

@ -29,5 +29,5 @@
} }
], ],
"missiles" : 4, "missiles" : 4,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -24,5 +24,5 @@
} }
], ],
"missiles" : 3, "missiles" : 3,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -24,6 +24,6 @@
} }
], ],
"missiles" : 6, "missiles" : 6,
"flags" : "EF_TAKES_DAMAGE", "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER",
"aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE" "aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE"
} }

View File

@ -30,5 +30,5 @@
], ],
"combinedGuns" : 1, "combinedGuns" : 1,
"missiles" : 6, "missiles" : 6,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -19,5 +19,5 @@
} }
], ],
"missiles" : 3, "missiles" : 3,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -29,5 +29,5 @@
} }
], ],
"missiles" : 4, "missiles" : 4,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -25,5 +25,5 @@
], ],
"combinedGuns" : 1, "combinedGuns" : 1,
"missiles" : 4, "missiles" : 4,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -34,5 +34,5 @@
} }
], ],
"missiles" : 4, "missiles" : 4,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -24,6 +24,6 @@
} }
], ],
"missiles" : 8, "missiles" : 8,
"flags" : "EF_TAKES_DAMAGE", "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER",
"aiFlags" : "AIF_MISSILE_BOAT+AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" "aiFlags" : "AIF_MISSILE_BOAT+AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE"
} }

View File

@ -24,5 +24,5 @@
} }
], ],
"missiles" : 3, "missiles" : 3,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -29,5 +29,5 @@
} }
], ],
"missiles" : 5, "missiles" : 5,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -29,5 +29,5 @@
} }
], ],
"missiles" : 6, "missiles" : 6,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -29,5 +29,5 @@
} }
], ],
"missiles" : 2, "missiles" : 2,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -19,5 +19,5 @@
} }
], ],
"missiles" : 4, "missiles" : 4,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -35,5 +35,5 @@
], ],
"combinedGuns" : 1, "combinedGuns" : 1,
"missiles" : 4, "missiles" : 4,
"flags" : "EF_TAKES_DAMAGE" "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER"
} }

View File

@ -286,5 +286,11 @@
"description" : "Destroy two or more fighters by shooting one mine", "description" : "Destroy two or more fighters by shooting one mine",
"value" : "TROPHY_BRONZE", "value" : "TROPHY_BRONZE",
"hidden" : 1 "hidden" : 1
},
{
"id" : "FREQUENT_FLYER",
"title" : "Frequent flyer",
"description" : "Destroy one of each common type of starfighter",
"value" : "TROPHY_SILVER"
} }
] ]

View File

@ -31,6 +31,8 @@ static void randomizeDartGuns(Entity *dart);
static void loadFighterDef(char *filename); static void loadFighterDef(char *filename);
static void loadFighterDefList(char *filename); static void loadFighterDefList(char *filename);
static Entity *getFighterDef(char *name); static Entity *getFighterDef(char *name);
static void addFighterStat(char *name);
static void incFighterStat(char *key);
static Entity defHead, *defTail; static Entity defHead, *defTail;
@ -562,6 +564,11 @@ static void die(void)
{ {
battle.stats[STAT_ENEMIES_KILLED_PLAYER]++; battle.stats[STAT_ENEMIES_KILLED_PLAYER]++;
if (self->flags & EF_COMMON_FIGHTER)
{
incFighterStat(self->defName);
}
if (battle.hasSuspicionLevel) if (battle.hasSuspicionLevel)
{ {
battle.suspicionLevel = MAX(0, battle.suspicionLevel - (MAX_SUSPICION_LEVEL * 0.1)); battle.suspicionLevel = MAX(0, battle.suspicionLevel - (MAX_SUSPICION_LEVEL * 0.1));
@ -817,6 +824,11 @@ static void loadFighterDef(char *filename)
{ {
e->deathType = lookup(cJSON_GetObjectItem(root, "deathType")->valuestring); e->deathType = lookup(cJSON_GetObjectItem(root, "deathType")->valuestring);
} }
if (e->flags & EF_COMMON_FIGHTER)
{
addFighterStat(e->name);
}
e->separationRadius = MAX(e->w, e->h) * 3; e->separationRadius = MAX(e->w, e->h) * 3;
@ -832,6 +844,47 @@ static void loadFighterDef(char *filename)
free(text); free(text);
} }
static void addFighterStat(char *key)
{
Tuple *t, *tail;
tail = &game.fighterStatHead;
for (t = game.fighterStatHead.next ; t != NULL ; t = t->next)
{
if (strcmp(t->key, key) == 0)
{
return;
}
tail = t;
}
t = malloc(sizeof(Tuple));
memset(t, 0, sizeof(Tuple));
STRNCPY(t->key, key, MAX_NAME_LENGTH);
t->value = 0;
tail->next = t;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Added '%s' to fighter stats", key);
}
static void incFighterStat(char *key)
{
Tuple *t;
for (t = game.fighterStatHead.next ; t != NULL ; t = t->next)
{
if (strcmp(t->key, key) == 0)
{
t->value++;
return;
}
}
}
void loadFighters(cJSON *node) void loadFighters(cJSON *node)
{ {
Entity *e; Entity *e;

View File

@ -108,6 +108,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define EF_FRIENDLY_HEALTH_BAR (2 << 22) #define EF_FRIENDLY_HEALTH_BAR (2 << 22)
#define EF_NO_THREAT (2 << 23) #define EF_NO_THREAT (2 << 23)
#define EF_DROPS_ITEMS (2 << 24) #define EF_DROPS_ITEMS (2 << 24)
#define EF_COMMON_FIGHTER (2 << 25)
#define AIF_NONE 0 #define AIF_NONE 0
#define AIF_FOLLOWS_PLAYER (2 << 0) #define AIF_FOLLOWS_PLAYER (2 << 0)

View File

@ -385,6 +385,7 @@ static void loadTrophyData(char *filename)
void awardStatsTrophies(void) void awardStatsTrophies(void)
{ {
Trophy *t; Trophy *t;
Tuple *tp;
for (t = game.trophyHead.next ; t != NULL ; t = t->next) for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{ {
@ -399,6 +400,17 @@ void awardStatsTrophies(void)
app.saveGame = 1; app.saveGame = 1;
} }
} }
/* check to see if we've destroyed one of each common starfighter */
for (tp = game.fighterStatHead.next ; tp != NULL ; tp = tp->next)
{
if (tp->value == 0)
{
return;
}
}
awardTrophy("FREQUENT_FLYER");
} }
void awardCampaignTrophies(void) void awardCampaignTrophies(void)

View File

@ -39,6 +39,7 @@ typedef struct ScriptRunner ScriptRunner;
typedef struct Location Location; typedef struct Location Location;
typedef struct Bucket Bucket; typedef struct Bucket Bucket;
typedef struct Trophy Trophy; typedef struct Trophy Trophy;
typedef struct Tuple Tuple;
typedef struct { typedef struct {
int debug; int debug;
@ -400,6 +401,12 @@ typedef struct {
int healthBars; int healthBars;
} Gameplay; } Gameplay;
struct Tuple {
char key[MAX_NAME_LENGTH];
int value;
Tuple *next;
};
typedef struct { typedef struct {
StarSystem starSystemHead; StarSystem starSystemHead;
Mission challengeMissionHead; Mission challengeMissionHead;
@ -412,6 +419,7 @@ typedef struct {
int totalChallenges; int totalChallenges;
unsigned int stats[STAT_MAX]; unsigned int stats[STAT_MAX];
Trophy trophyHead; Trophy trophyHead;
Tuple fighterStatHead;
} Game; } Game;
struct Widget { struct Widget {

View File

@ -25,6 +25,7 @@ static void loadStarSystems(cJSON *starSystemsJSON);
static void loadMissions(cJSON *missionsCJSON); static void loadMissions(cJSON *missionsCJSON);
static void loadChallenges(cJSON *challengesCJSON); static void loadChallenges(cJSON *challengesCJSON);
static void loadTrophies(cJSON *trophiesJSON); static void loadTrophies(cJSON *trophiesJSON);
static void loadFighterStats(cJSON *fighterStatsJSON);
void loadGame(void) void loadGame(void)
{ {
@ -45,6 +46,8 @@ void loadGame(void)
loadStats(cJSON_GetObjectItem(gameJSON, "stats")); loadStats(cJSON_GetObjectItem(gameJSON, "stats"));
loadTrophies(cJSON_GetObjectItem(gameJSON, "trophies")); loadTrophies(cJSON_GetObjectItem(gameJSON, "trophies"));
loadFighterStats(cJSON_GetObjectItem(gameJSON, "fighterStats"));
cJSON_Delete(root); cJSON_Delete(root);
free(text); free(text);
@ -145,3 +148,26 @@ static void loadTrophies(cJSON *trophiesJSON)
} }
} }
} }
static void loadFighterStats(cJSON *fighterStatsJSON)
{
Tuple *t, *tail;
cJSON *fighterStatJSON;
tail = &game.fighterStatHead;
if (fighterStatsJSON)
{
for (fighterStatJSON = fighterStatsJSON->child ; fighterStatJSON != NULL ; fighterStatJSON = fighterStatJSON->next)
{
t = malloc(sizeof(Tuple));
memset(t, 0, sizeof(Tuple));
STRNCPY(t->key, cJSON_GetObjectItem(fighterStatJSON, "key")->valuestring, MAX_NAME_LENGTH);
t->value = cJSON_GetObjectItem(fighterStatJSON, "value")->valueint;
tail->next = t;
tail = t;
}
}
}

View File

@ -70,6 +70,7 @@ void initLookups(void)
addLookup("EF_NO_THREAT", EF_NO_THREAT); addLookup("EF_NO_THREAT", EF_NO_THREAT);
addLookup("EF_NO_HEALTH_BAR", EF_NO_HEALTH_BAR); addLookup("EF_NO_HEALTH_BAR", EF_NO_HEALTH_BAR);
addLookup("EF_DROPS_ITEMS", EF_DROPS_ITEMS); addLookup("EF_DROPS_ITEMS", EF_DROPS_ITEMS);
addLookup("EF_COMMON_FIGHTER", EF_COMMON_FIGHTER);
addLookup("AIF_NONE", AIF_NONE); addLookup("AIF_NONE", AIF_NONE);
addLookup("AIF_MOVES_TO_PLAYER", AIF_MOVES_TO_PLAYER); addLookup("AIF_MOVES_TO_PLAYER", AIF_MOVES_TO_PLAYER);

View File

@ -25,6 +25,7 @@ static void saveChallenges(cJSON *gameJSON);
static cJSON *getMissionsJSON(StarSystem *starSystem); static cJSON *getMissionsJSON(StarSystem *starSystem);
static void saveStats(cJSON *gameJSON); static void saveStats(cJSON *gameJSON);
static void saveTrophies(cJSON *gameJSON); static void saveTrophies(cJSON *gameJSON);
static void saveFighterStats(cJSON *gameJSON);
void saveGame(void) void saveGame(void)
{ {
@ -46,6 +47,8 @@ void saveGame(void)
saveStats(gameJSON); saveStats(gameJSON);
saveTrophies(gameJSON); saveTrophies(gameJSON);
saveFighterStats(gameJSON);
out = cJSON_Print(root); out = cJSON_Print(root);
@ -175,3 +178,23 @@ static void saveTrophies(cJSON *gameJSON)
cJSON_AddItemToObject(gameJSON, "trophies", trophiesJSON); cJSON_AddItemToObject(gameJSON, "trophies", trophiesJSON);
} }
static void saveFighterStats(cJSON *gameJSON)
{
Tuple *t;
cJSON *fighterStatsJSON, *fighterStatJSON;
fighterStatsJSON = cJSON_CreateArray();
for (t = game.fighterStatHead.next ; t != NULL ; t = t->next)
{
fighterStatJSON = cJSON_CreateObject();
cJSON_AddStringToObject(fighterStatJSON, "key", t->key);
cJSON_AddNumberToObject(fighterStatJSON, "value", t->value);
cJSON_AddItemToArray(fighterStatsJSON, fighterStatJSON);
}
cJSON_AddItemToObject(gameJSON, "fighterStats", fighterStatsJSON);
}