diff --git a/data/fighters/blizzard.json b/data/fighters/blizzard.json index 999885c..89e83b1 100644 --- a/data/fighters/blizzard.json +++ b/data/fighters/blizzard.json @@ -35,5 +35,5 @@ } ], "missiles" : 5, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/dart.json b/data/fighters/dart.json index d1a4d94..564f2e4 100644 --- a/data/fighters/dart.json +++ b/data/fighters/dart.json @@ -17,5 +17,5 @@ } ], "missiles" : 2, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/firefly.json b/data/fighters/firefly.json index 9cfdddd..459c105 100644 --- a/data/fighters/firefly.json +++ b/data/fighters/firefly.json @@ -25,5 +25,5 @@ ], "combinedGuns" : 1, "missiles" : 3, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/hammerhead.json b/data/fighters/hammerhead.json index caca23b..4cf4963 100644 --- a/data/fighters/hammerhead.json +++ b/data/fighters/hammerhead.json @@ -24,6 +24,6 @@ } ], "missiles" : 6, - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER", "aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE" } diff --git a/data/fighters/hyenaA.json b/data/fighters/hyenaA.json index fae1cfb..aa89e3d 100644 --- a/data/fighters/hyenaA.json +++ b/data/fighters/hyenaA.json @@ -29,5 +29,5 @@ } ], "missiles" : 4, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/hyenaB.json b/data/fighters/hyenaB.json index 07a49db..bb79f80 100644 --- a/data/fighters/hyenaB.json +++ b/data/fighters/hyenaB.json @@ -29,5 +29,5 @@ } ], "missiles" : 4, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/jackal.json b/data/fighters/jackal.json index 733b91b..42e9de6 100644 --- a/data/fighters/jackal.json +++ b/data/fighters/jackal.json @@ -19,5 +19,5 @@ } ], "missiles" : 3, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/khepri.json b/data/fighters/khepri.json index 8e23e38..a9392d1 100644 --- a/data/fighters/khepri.json +++ b/data/fighters/khepri.json @@ -29,6 +29,6 @@ } ], "missiles" : 8, - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER", "aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE" } diff --git a/data/fighters/kingfisher.json b/data/fighters/kingfisher.json index 4882f2a..c76bcd1 100644 --- a/data/fighters/kingfisher.json +++ b/data/fighters/kingfisher.json @@ -29,5 +29,5 @@ } ], "missiles" : 4, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/leopard.json b/data/fighters/leopard.json index 9cdde33..ad1c6a2 100644 --- a/data/fighters/leopard.json +++ b/data/fighters/leopard.json @@ -24,5 +24,5 @@ } ], "missiles" : 3, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/lynx.json b/data/fighters/lynx.json index a01581d..4fb7ed0 100644 --- a/data/fighters/lynx.json +++ b/data/fighters/lynx.json @@ -24,6 +24,6 @@ } ], "missiles" : 6, - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER", "aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE" } diff --git a/data/fighters/mantis.json b/data/fighters/mantis.json index 7165a17..2f4d09b 100644 --- a/data/fighters/mantis.json +++ b/data/fighters/mantis.json @@ -30,5 +30,5 @@ ], "combinedGuns" : 1, "missiles" : 6, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/nymph.json b/data/fighters/nymph.json index 0e9a0a2..da2857a 100644 --- a/data/fighters/nymph.json +++ b/data/fighters/nymph.json @@ -19,5 +19,5 @@ } ], "missiles" : 3, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/ray.json b/data/fighters/ray.json index 272dba7..379df8b 100644 --- a/data/fighters/ray.json +++ b/data/fighters/ray.json @@ -29,5 +29,5 @@ } ], "missiles" : 4, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/razor.json b/data/fighters/razor.json index 1950ce4..fea0345 100644 --- a/data/fighters/razor.json +++ b/data/fighters/razor.json @@ -25,5 +25,5 @@ ], "combinedGuns" : 1, "missiles" : 4, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/rook.json b/data/fighters/rook.json index f1974e4..86d9673 100644 --- a/data/fighters/rook.json +++ b/data/fighters/rook.json @@ -34,5 +34,5 @@ } ], "missiles" : 4, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/scarab.json b/data/fighters/scarab.json index e592f73..3998db3 100644 --- a/data/fighters/scarab.json +++ b/data/fighters/scarab.json @@ -24,6 +24,6 @@ } ], "missiles" : 8, - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER", "aiFlags" : "AIF_MISSILE_BOAT+AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" } diff --git a/data/fighters/shale.json b/data/fighters/shale.json index f8f5c09..77fe10a 100644 --- a/data/fighters/shale.json +++ b/data/fighters/shale.json @@ -24,5 +24,5 @@ } ], "missiles" : 3, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/sk31.json b/data/fighters/sk31.json index fbf26c1..1272483 100644 --- a/data/fighters/sk31.json +++ b/data/fighters/sk31.json @@ -29,5 +29,5 @@ } ], "missiles" : 5, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/sk34.json b/data/fighters/sk34.json index 17304f2..063db0a 100644 --- a/data/fighters/sk34.json +++ b/data/fighters/sk34.json @@ -29,5 +29,5 @@ } ], "missiles" : 6, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/sphinx.json b/data/fighters/sphinx.json index 7b46272..1deddfc 100644 --- a/data/fighters/sphinx.json +++ b/data/fighters/sphinx.json @@ -29,5 +29,5 @@ } ], "missiles" : 2, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/taf.json b/data/fighters/taf.json index b145f7e..c2bf7d8 100644 --- a/data/fighters/taf.json +++ b/data/fighters/taf.json @@ -19,5 +19,5 @@ } ], "missiles" : 4, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/fighters/thunderhead.json b/data/fighters/thunderhead.json index cca33cb..cc5357a 100644 --- a/data/fighters/thunderhead.json +++ b/data/fighters/thunderhead.json @@ -35,5 +35,5 @@ ], "combinedGuns" : 1, "missiles" : 4, - "flags" : "EF_TAKES_DAMAGE" + "flags" : "EF_TAKES_DAMAGE+EF_COMMON_FIGHTER" } diff --git a/data/trophies/trophies.json b/data/trophies/trophies.json index 81a5f97..be53402 100644 --- a/data/trophies/trophies.json +++ b/data/trophies/trophies.json @@ -286,5 +286,11 @@ "description" : "Destroy two or more fighters by shooting one mine", "value" : "TROPHY_BRONZE", "hidden" : 1 + }, + { + "id" : "FREQUENT_FLYER", + "title" : "Frequent flyer", + "description" : "Destroy one of each common type of starfighter", + "value" : "TROPHY_SILVER" } ] diff --git a/src/battle/fighters.c b/src/battle/fighters.c index adf86ad..d83bcea 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -31,6 +31,8 @@ static void randomizeDartGuns(Entity *dart); static void loadFighterDef(char *filename); static void loadFighterDefList(char *filename); static Entity *getFighterDef(char *name); +static void addFighterStat(char *name); +static void incFighterStat(char *key); static Entity defHead, *defTail; @@ -562,6 +564,11 @@ static void die(void) { battle.stats[STAT_ENEMIES_KILLED_PLAYER]++; + if (self->flags & EF_COMMON_FIGHTER) + { + incFighterStat(self->defName); + } + if (battle.hasSuspicionLevel) { 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); } + + if (e->flags & EF_COMMON_FIGHTER) + { + addFighterStat(e->name); + } e->separationRadius = MAX(e->w, e->h) * 3; @@ -832,6 +844,47 @@ static void loadFighterDef(char *filename) 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) { Entity *e; diff --git a/src/defs.h b/src/defs.h index 5c8ffbf..95c6627 100644 --- a/src/defs.h +++ b/src/defs.h @@ -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_NO_THREAT (2 << 23) #define EF_DROPS_ITEMS (2 << 24) +#define EF_COMMON_FIGHTER (2 << 25) #define AIF_NONE 0 #define AIF_FOLLOWS_PLAYER (2 << 0) diff --git a/src/game/trophies.c b/src/game/trophies.c index c8884d1..f1789f7 100644 --- a/src/game/trophies.c +++ b/src/game/trophies.c @@ -385,6 +385,7 @@ static void loadTrophyData(char *filename) void awardStatsTrophies(void) { Trophy *t; + Tuple *tp; for (t = game.trophyHead.next ; t != NULL ; t = t->next) { @@ -399,6 +400,17 @@ void awardStatsTrophies(void) 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) diff --git a/src/structs.h b/src/structs.h index e17a9f4..246fc02 100644 --- a/src/structs.h +++ b/src/structs.h @@ -39,6 +39,7 @@ typedef struct ScriptRunner ScriptRunner; typedef struct Location Location; typedef struct Bucket Bucket; typedef struct Trophy Trophy; +typedef struct Tuple Tuple; typedef struct { int debug; @@ -400,6 +401,12 @@ typedef struct { int healthBars; } Gameplay; +struct Tuple { + char key[MAX_NAME_LENGTH]; + int value; + Tuple *next; +}; + typedef struct { StarSystem starSystemHead; Mission challengeMissionHead; @@ -412,6 +419,7 @@ typedef struct { int totalChallenges; unsigned int stats[STAT_MAX]; Trophy trophyHead; + Tuple fighterStatHead; } Game; struct Widget { diff --git a/src/system/load.c b/src/system/load.c index 24e07be..db69fbf 100644 --- a/src/system/load.c +++ b/src/system/load.c @@ -25,6 +25,7 @@ static void loadStarSystems(cJSON *starSystemsJSON); static void loadMissions(cJSON *missionsCJSON); static void loadChallenges(cJSON *challengesCJSON); static void loadTrophies(cJSON *trophiesJSON); +static void loadFighterStats(cJSON *fighterStatsJSON); void loadGame(void) { @@ -45,6 +46,8 @@ void loadGame(void) loadStats(cJSON_GetObjectItem(gameJSON, "stats")); loadTrophies(cJSON_GetObjectItem(gameJSON, "trophies")); + + loadFighterStats(cJSON_GetObjectItem(gameJSON, "fighterStats")); cJSON_Delete(root); 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; + } + } +} diff --git a/src/system/lookup.c b/src/system/lookup.c index 27f8704..692f806 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -70,6 +70,7 @@ void initLookups(void) addLookup("EF_NO_THREAT", EF_NO_THREAT); addLookup("EF_NO_HEALTH_BAR", EF_NO_HEALTH_BAR); addLookup("EF_DROPS_ITEMS", EF_DROPS_ITEMS); + addLookup("EF_COMMON_FIGHTER", EF_COMMON_FIGHTER); addLookup("AIF_NONE", AIF_NONE); addLookup("AIF_MOVES_TO_PLAYER", AIF_MOVES_TO_PLAYER); diff --git a/src/system/save.c b/src/system/save.c index 83ce48b..3e84b89 100644 --- a/src/system/save.c +++ b/src/system/save.c @@ -25,6 +25,7 @@ static void saveChallenges(cJSON *gameJSON); static cJSON *getMissionsJSON(StarSystem *starSystem); static void saveStats(cJSON *gameJSON); static void saveTrophies(cJSON *gameJSON); +static void saveFighterStats(cJSON *gameJSON); void saveGame(void) { @@ -46,6 +47,8 @@ void saveGame(void) saveStats(gameJSON); saveTrophies(gameJSON); + + saveFighterStats(gameJSON); out = cJSON_Print(root); @@ -175,3 +178,23 @@ static void saveTrophies(cJSON *gameJSON) 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); +}