Allow for mixed fighter groups, using 'types'

This commit is contained in:
Steve 2015-10-25 12:56:24 +00:00
parent b790aa5c00
commit b6da6c2ec5
8 changed files with 164 additions and 17 deletions

View File

@ -2,7 +2,7 @@
"name" : "ATAF", "name" : "ATAF",
"health" : 50, "health" : 50,
"shield" : 9999, "shield" : 9999,
"speed" : 3, "speed" : 2.5,
"reloadTime" : 6, "reloadTime" : 6,
"shieldRechargeRate" : 5, "shieldRechargeRate" : 5,
"textureName" : "gfx/fighters/ataf.png", "textureName" : "gfx/fighters/ataf.png",
@ -37,5 +37,9 @@
"x" : -13, "x" : -13,
"y" : -8 "y" : -8
} }
] ],
"missiles" : {
"type" : "MISSILE_MISSILE",
"ammo" : 4
}
} }

View File

@ -142,7 +142,9 @@
"side" : "SIDE_UNF", "side" : "SIDE_UNF",
"x": 325, "x": 325,
"y": 385, "y": 385,
"missions" : [] "missions" : [
"data/missions/coyote/01 - coyote assault #1.json"
]
}, },
{ {
"name": "Rothan", "name": "Rothan",

View File

@ -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
}
]
}

View File

@ -35,15 +35,15 @@
"fighterGroups" : [ "fighterGroups" : [
{ {
"name" : "Ally", "name" : "Ally",
"type" : "TAF", "types" : "TAF",
"number" : 4, "number" : 4,
"side" : "SIDE_ALLIES", "side" : "SIDE_ALLIES",
"x" : 0, "x" : 0,
"y" : 0 "y" : 0
}, },
{ {
"type" : "SimpleDart",
"name" : "Dart", "name" : "Dart",
"types" : "SimpleDart",
"number" : 10, "number" : 10,
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
"x" : 1000, "x" : 1000,
@ -51,7 +51,7 @@
"scatter" : 2000 "scatter" : 2000
}, },
{ {
"type" : "SimpleDart", "types" : "SimpleDart",
"name" : "Dart", "name" : "Dart",
"number" : 10, "number" : 10,
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
@ -60,8 +60,8 @@
"scatter" : 2000 "scatter" : 2000
}, },
{ {
"type" : "Dart",
"name" : "Dart", "name" : "Dart",
"types" : "SimpleDart",
"number" : 10, "number" : 10,
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
"x" : 0, "x" : 0,

View File

@ -35,15 +35,15 @@
"fighterGroups" : [ "fighterGroups" : [
{ {
"name" : "Ally", "name" : "Ally",
"type" : "TAF", "types" : "TAF",
"number" : 4, "number" : 4,
"side" : "SIDE_ALLIES", "side" : "SIDE_ALLIES",
"x" : 0, "x" : 0,
"y" : 0 "y" : 0
}, },
{ {
"type" : "Dart",
"name" : "Dart", "name" : "Dart",
"types" : "Dart",
"number" : 12, "number" : 12,
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
"x" : -3000, "x" : -3000,
@ -51,8 +51,8 @@
"scatter" : 2000 "scatter" : 2000
}, },
{ {
"type" : "Dart",
"name" : "Dart", "name" : "Dart",
"types" : "Dart",
"number" : 12, "number" : 12,
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
"x" : 4000, "x" : 4000,
@ -60,8 +60,8 @@
"scatter" : 2000 "scatter" : 2000
}, },
{ {
"type" : "Dart",
"name" : "Dart", "name" : "Dart",
"types" : "Dart",
"number" : 12, "number" : 12,
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
"x" : 0, "x" : 0,

View File

@ -54,15 +54,15 @@
"fighterGroups" : [ "fighterGroups" : [
{ {
"name" : "Ally", "name" : "Ally",
"type" : "TAF", "types" : "TAF",
"number" : 2, "number" : 2,
"side" : "SIDE_ALLIES", "side" : "SIDE_ALLIES",
"x" : 1600, "x" : 1600,
"y" : 400 "y" : 400
}, },
{ {
"type" : "Dart",
"name" : "Dart", "name" : "Dart",
"types" : "Dart",
"number" : 12, "number" : 12,
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
"x" : -5000, "x" : -5000,

View File

@ -34,6 +34,7 @@ static void centerOnSelectedStarSystem(void);
static void doStarSystems(void); static void doStarSystems(void);
void destroyGalacticMap(void); void destroyGalacticMap(void);
static void drawPulses(void); static void drawPulses(void);
static void drawInfoBars(void);
static void doPulses(void); static void doPulses(void);
static void addPulses(void); static void addPulses(void);
static void drawMenu(void); static void drawMenu(void);
@ -257,6 +258,8 @@ static void draw(void)
drawPulses(); drawPulses();
drawInfoBars();
if (viewingSystem) if (viewingSystem)
{ {
drawStarSystemDetail(); drawStarSystemDetail();
@ -386,6 +389,11 @@ static void drawGalaxy(void)
} }
} }
} }
}
static void drawInfoBars(void)
{
SDL_Rect r;
if (!viewingSystem && selectedStarSystem != NULL) if (!viewingSystem && selectedStarSystem != NULL)
{ {

View File

@ -25,6 +25,7 @@ static void loadPlayer(cJSON *node);
static void loadFighters(cJSON *node); static void loadFighters(cJSON *node);
static void loadFighterGroups(cJSON *node); static void loadFighterGroups(cJSON *node);
static unsigned long hashcode(const char *str); static unsigned long hashcode(const char *str);
static char **toFighterTypeArray(char *types, int *numTypes);
void loadMission(char *filename) void loadMission(char *filename)
{ {
@ -161,9 +162,9 @@ static void loadFighters(cJSON *node)
static void loadFighterGroups(cJSON *node) static void loadFighterGroups(cJSON *node)
{ {
Fighter *f; Fighter *f;
char *type, *name; char **types, *name, *type;
int side, x, y, scatter; int side, x, y, scatter, number;
int number, i; int i, numTypes;
scatter = 1; scatter = 1;
@ -173,7 +174,7 @@ static void loadFighterGroups(cJSON *node)
while (node) while (node)
{ {
type = cJSON_GetObjectItem(node, "type")->valuestring; types = toFighterTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring); side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
number = cJSON_GetObjectItem(node, "number")->valueint; number = cJSON_GetObjectItem(node, "number")->valueint;
x = cJSON_GetObjectItem(node, "x")->valueint; x = cJSON_GetObjectItem(node, "x")->valueint;
@ -187,6 +188,8 @@ static void loadFighterGroups(cJSON *node)
for (i = 0 ; i < number ; i++) for (i = 0 ; i < number ; i++)
{ {
type = types[rand() % numTypes];
f = spawnFighter(type, x, y, side); f = spawnFighter(type, x, y, side);
f->x += (rand() % scatter) - (rand() % scatter); f->x += (rand() % scatter) - (rand() % scatter);
@ -196,10 +199,44 @@ static void loadFighterGroups(cJSON *node)
} }
node = node->next; 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) Mission *getMission(char *filename)
{ {
StarSystem *starSystem; StarSystem *starSystem;