From b6da6c2ec5f3840a3976223c6676282f30b4ce64 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 25 Oct 2015 12:56:24 +0000 Subject: [PATCH] Allow for mixed fighter groups, using 'types' --- data/fighters/ataf.json | 8 +- data/galaxy/starSystems.json | 4 +- .../coyote/01 - coyote assault #1.json | 96 +++++++++++++++++++ .../temper/01 - pirate uprising #1.json | 8 +- .../temper/02 - pirate uprising #2.json | 8 +- .../temper/03 - pirate uprising #3.json | 4 +- src/galaxy/galacticMap.c | 8 ++ src/galaxy/mission.c | 45 ++++++++- 8 files changed, 164 insertions(+), 17 deletions(-) create mode 100644 data/missions/coyote/01 - coyote assault #1.json diff --git a/data/fighters/ataf.json b/data/fighters/ataf.json index e690c39..1bb36dc 100644 --- a/data/fighters/ataf.json +++ b/data/fighters/ataf.json @@ -2,7 +2,7 @@ "name" : "ATAF", "health" : 50, "shield" : 9999, - "speed" : 3, + "speed" : 2.5, "reloadTime" : 6, "shieldRechargeRate" : 5, "textureName" : "gfx/fighters/ataf.png", @@ -37,5 +37,9 @@ "x" : -13, "y" : -8 } - ] + ], + "missiles" : { + "type" : "MISSILE_MISSILE", + "ammo" : 4 + } } diff --git a/data/galaxy/starSystems.json b/data/galaxy/starSystems.json index 8de36de..35d00a2 100644 --- a/data/galaxy/starSystems.json +++ b/data/galaxy/starSystems.json @@ -142,7 +142,9 @@ "side" : "SIDE_UNF", "x": 325, "y": 385, - "missions" : [] + "missions" : [ + "data/missions/coyote/01 - coyote assault #1.json" + ] }, { "name": "Rothan", diff --git a/data/missions/coyote/01 - coyote assault #1.json b/data/missions/coyote/01 - coyote assault #1.json new file mode 100644 index 0000000..941435b --- /dev/null +++ b/data/missions/coyote/01 - coyote assault #1.json @@ -0,0 +1,96 @@ +{ + "name" : "Coyote Assault #1", + "description" : "Though we suffered heavy losses at Coyote, it is still important that we attempt to prevent, or at least slow, the Pandoran war machine's advance. Admiral Jenkins has ordered that the White Knights lead an attack on the enemy forces gathered in the system. The weight of the opposing forces remains tremendous, though the ATAFs should help to give us the edge in battle. Be advised that the enemy are now in possession of UNF fighter craft.", + "background" : "gfx/backgrounds/background03.jpg", + "planet" : "gfx/planets/mythos.png", + "music" : "music/heroism.ogg", + "objectives" : [ + { + "description" : "Destroy all enemy targets", + "targetName" : "Pandoran", + "targetValue" : 250, + "targetType" : "TT_DESTROY" + } + ], + "player" : { + "type" : "ATAF", + "side" : "SIDE_ALLIES", + "pilot" : "Simon Dodds", + "squadron" : "White Knights" + }, + "fighterGroups" : [ + { + "name" : "Ally", + "types" : "ATAF", + "number" : 4, + "side" : "SIDE_ALLIES", + "x" : 0, + "y" : 0, + "scatter" : 500 + }, + { + "name" : "Ally", + "types" : "TAF", + "number" : 2, + "side" : "SIDE_ALLIES", + "x" : 0, + "y" : 0, + "scatter" : 500 + }, + { + "name" : "Ally", + "types" : "Ray", + "number" : 2, + "side" : "SIDE_ALLIES", + "x" : 0, + "y" : 0, + "scatter" : 500 + }, + { + "name" : "Pandoran", + "types" : "Jackal;Sphinx", + "number" : 50, + "side" : "SIDE_PANDORAN", + "x" : -5000, + "y" : 0, + "scatter" : 2000 + }, + { + "name" : "Pandoran", + "types" : "Jackal;Sphinx", + "number" : 50, + "side" : "SIDE_PANDORAN", + "x" : -5000, + "y" : 5000, + "scatter" : 2000 + }, + { + "name" : "Pandoran", + "types" : "Jackal;Sphinx", + "number" : 50, + "side" : "SIDE_PANDORAN", + "x" : -5000, + "y" : -5000, + "scatter" : 2000 + }, + { + "name" : "Pandoran", + "types" : "Jackal;Sphinx", + "number" : 50, + "side" : "SIDE_PANDORAN", + "x" : 5000, + "y" : 8000, + "scatter" : 2000 + }, + { + "name" : "Pandoran", + "types" : "Jackal;Sphinx", + "number" : 50, + "side" : "SIDE_PANDORAN", + "x" : 7000, + "y" : -4000, + "scatter" : 2000 + } + ] +} + diff --git a/data/missions/temper/01 - pirate uprising #1.json b/data/missions/temper/01 - pirate uprising #1.json index e5c3e79..e90bcab 100644 --- a/data/missions/temper/01 - pirate uprising #1.json +++ b/data/missions/temper/01 - pirate uprising #1.json @@ -35,15 +35,15 @@ "fighterGroups" : [ { "name" : "Ally", - "type" : "TAF", + "types" : "TAF", "number" : 4, "side" : "SIDE_ALLIES", "x" : 0, "y" : 0 }, { - "type" : "SimpleDart", "name" : "Dart", + "types" : "SimpleDart", "number" : 10, "side" : "SIDE_PIRATE", "x" : 1000, @@ -51,7 +51,7 @@ "scatter" : 2000 }, { - "type" : "SimpleDart", + "types" : "SimpleDart", "name" : "Dart", "number" : 10, "side" : "SIDE_PIRATE", @@ -60,8 +60,8 @@ "scatter" : 2000 }, { - "type" : "Dart", "name" : "Dart", + "types" : "SimpleDart", "number" : 10, "side" : "SIDE_PIRATE", "x" : 0, diff --git a/data/missions/temper/02 - pirate uprising #2.json b/data/missions/temper/02 - pirate uprising #2.json index 72be6ce..d856a1e 100644 --- a/data/missions/temper/02 - pirate uprising #2.json +++ b/data/missions/temper/02 - pirate uprising #2.json @@ -35,15 +35,15 @@ "fighterGroups" : [ { "name" : "Ally", - "type" : "TAF", + "types" : "TAF", "number" : 4, "side" : "SIDE_ALLIES", "x" : 0, "y" : 0 }, { - "type" : "Dart", "name" : "Dart", + "types" : "Dart", "number" : 12, "side" : "SIDE_PIRATE", "x" : -3000, @@ -51,8 +51,8 @@ "scatter" : 2000 }, { - "type" : "Dart", "name" : "Dart", + "types" : "Dart", "number" : 12, "side" : "SIDE_PIRATE", "x" : 4000, @@ -60,8 +60,8 @@ "scatter" : 2000 }, { - "type" : "Dart", "name" : "Dart", + "types" : "Dart", "number" : 12, "side" : "SIDE_PIRATE", "x" : 0, diff --git a/data/missions/temper/03 - pirate uprising #3.json b/data/missions/temper/03 - pirate uprising #3.json index 58ba7d4..62f8947 100644 --- a/data/missions/temper/03 - pirate uprising #3.json +++ b/data/missions/temper/03 - pirate uprising #3.json @@ -54,15 +54,15 @@ "fighterGroups" : [ { "name" : "Ally", - "type" : "TAF", + "types" : "TAF", "number" : 2, "side" : "SIDE_ALLIES", "x" : 1600, "y" : 400 }, { - "type" : "Dart", "name" : "Dart", + "types" : "Dart", "number" : 12, "side" : "SIDE_PIRATE", "x" : -5000, diff --git a/src/galaxy/galacticMap.c b/src/galaxy/galacticMap.c index fe93cb4..cd4dd15 100644 --- a/src/galaxy/galacticMap.c +++ b/src/galaxy/galacticMap.c @@ -34,6 +34,7 @@ static void centerOnSelectedStarSystem(void); static void doStarSystems(void); void destroyGalacticMap(void); static void drawPulses(void); +static void drawInfoBars(void); static void doPulses(void); static void addPulses(void); static void drawMenu(void); @@ -257,6 +258,8 @@ static void draw(void) drawPulses(); + drawInfoBars(); + if (viewingSystem) { drawStarSystemDetail(); @@ -386,6 +389,11 @@ static void drawGalaxy(void) } } } +} + +static void drawInfoBars(void) +{ + SDL_Rect r; if (!viewingSystem && selectedStarSystem != NULL) { diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 63286cd..b357596 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -25,6 +25,7 @@ static void loadPlayer(cJSON *node); static void loadFighters(cJSON *node); static void loadFighterGroups(cJSON *node); static unsigned long hashcode(const char *str); +static char **toFighterTypeArray(char *types, int *numTypes); void loadMission(char *filename) { @@ -161,9 +162,9 @@ static void loadFighters(cJSON *node) static void loadFighterGroups(cJSON *node) { Fighter *f; - char *type, *name; - int side, x, y, scatter; - int number, i; + char **types, *name, *type; + int side, x, y, scatter, number; + int i, numTypes; scatter = 1; @@ -173,7 +174,7 @@ static void loadFighterGroups(cJSON *node) while (node) { - type = cJSON_GetObjectItem(node, "type")->valuestring; + types = toFighterTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes); side = lookup(cJSON_GetObjectItem(node, "side")->valuestring); number = cJSON_GetObjectItem(node, "number")->valueint; x = cJSON_GetObjectItem(node, "x")->valueint; @@ -187,6 +188,8 @@ static void loadFighterGroups(cJSON *node) for (i = 0 ; i < number ; i++) { + type = types[rand() % numTypes]; + f = spawnFighter(type, x, y, side); f->x += (rand() % scatter) - (rand() % scatter); @@ -196,10 +199,44 @@ static void loadFighterGroups(cJSON *node) } node = node->next; + + free(types); } } } +static char **toFighterTypeArray(char *types, int *numTypes) +{ + int i; + char **typeArray, *type; + + *numTypes = 1; + + for (i = 0 ; i < strlen(types) ; i++) + { + if (types[i] == ';') + { + *numTypes = *numTypes + 1; + } + } + + typeArray = malloc(*numTypes * sizeof(char*)); + + i = 0; + type = strtok(types, ";"); + while (type) + { + typeArray[i] = malloc(strlen(type) + 1); + strcpy(typeArray[i], type); + + type = strtok(NULL, ";"); + + i++; + } + + return typeArray; +} + Mission *getMission(char *filename) { StarSystem *starSystem;