Automatically load missions from star system misson dir (data/mission/xxx)
This commit is contained in:
parent
7855cd59ea
commit
af04c5a7ef
|
@ -4,299 +4,230 @@
|
||||||
"name": "Sol",
|
"name": "Sol",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 840,
|
"x": 840,
|
||||||
"y": 425,
|
"y": 425
|
||||||
"missions" : [
|
|
||||||
"data/missions/sol/01 - free flight.json",
|
|
||||||
"data/missions/sol/02 - weapons.json",
|
|
||||||
"data/missions/sol/03 - moving target.json",
|
|
||||||
"data/missions/sol/04 - armed target.json",
|
|
||||||
"data/missions/sol/05 - ecm.json",
|
|
||||||
"data/missions/sol/06 - wingmates.json",
|
|
||||||
"data/missions/sol/07 - final.json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Alpha Centauri",
|
"name": "Alpha Centauri",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 860,
|
"x": 860,
|
||||||
"y": 404,
|
"y": 404
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Ecuador Minor",
|
"name": "Ecuador Minor",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 831,
|
"x": 831,
|
||||||
"y": 333,
|
"y": 333
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Angel",
|
"name": "Angel",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 690,
|
"x": 690,
|
||||||
"y": 305,
|
"y": 305
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Indigo",
|
"name": "Indigo",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 760,
|
"x": 760,
|
||||||
"y": 270,
|
"y": 270
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Rex",
|
"name": "Rex",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 834,
|
"x": 834,
|
||||||
"y": 276,
|
"y": 276
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Gabriel",
|
"name": "Gabriel",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 860,
|
"x": 860,
|
||||||
"y": 170,
|
"y": 170
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Darlon",
|
"name": "Darlon",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 808,
|
"x": 808,
|
||||||
"y": 190,
|
"y": 190
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Granada",
|
"name": "Granada",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 741,
|
"x": 741,
|
||||||
"y": 221,
|
"y": 221
|
||||||
"missions" : [
|
|
||||||
"data/missions/granada/01 - suspect packages #1.json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Parish",
|
"name": "Parish",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 666,
|
"x": 666,
|
||||||
"y": 261,
|
"y": 261
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Temper",
|
"name": "Temper",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 595,
|
"x": 595,
|
||||||
"y": 260,
|
"y": 260
|
||||||
"missions" : [
|
|
||||||
"data/missions/temper/01 - pirate uprising #1.json",
|
|
||||||
"data/missions/temper/02 - pirate uprising #2.json",
|
|
||||||
"data/missions/temper/03 - pirate uprising #3.json",
|
|
||||||
"data/missions/temper/04 - pirate uprising #4.json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Lenon",
|
"name": "Lenon",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 655,
|
"x": 655,
|
||||||
"y": 180,
|
"y": 180
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "HD 21563010",
|
"name": "HD 21563010",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_CSN",
|
||||||
"x": 813,
|
"x": 813,
|
||||||
"y": 54,
|
"y": 54
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Trilliack",
|
"name": "Trilliack",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 501,
|
"x": 501,
|
||||||
"y": 312,
|
"y": 312
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Alba",
|
"name": "Alba",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 465,
|
"x": 465,
|
||||||
"y": 235,
|
"y": 235
|
||||||
"missions" : [
|
|
||||||
"data/missions/alba/01 - patrol #1.json",
|
|
||||||
"data/missions/alba/02 - patrol #2.json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Aster",
|
"name": "Aster",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 445,
|
"x": 445,
|
||||||
"y": 145,
|
"y": 145
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Iliad",
|
"name": "Iliad",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 335,
|
"x": 335,
|
||||||
"y": 135,
|
"y": 135
|
||||||
"missions" : [
|
|
||||||
"data/missions/iliad/01 - iliad defence #1.json",
|
|
||||||
"data/missions/iliad/02 - iliad defence #2.json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Warro",
|
"name": "Warro",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 289,
|
"x": 289,
|
||||||
"y": 216,
|
"y": 216
|
||||||
"missions" : [
|
|
||||||
"data/missions/warro/01 - evacuation #1.json",
|
|
||||||
"data/missions/warro/02 - evacuation #2.json",
|
|
||||||
"data/missions/warro/03 - evacuation #3.json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Coyote",
|
"name": "Coyote",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 325,
|
"x": 325,
|
||||||
"y": 385,
|
"y": 385,
|
||||||
"fallsToPandorans" : 1,
|
"fallsToPandorans" : 1
|
||||||
"missions" : [
|
|
||||||
"data/missions/coyote/01 - coyote assault #1.json",
|
|
||||||
"data/missions/coyote/02 - coyote assault #2.json",
|
|
||||||
"data/missions/coyote/03 - coyote assault #3.json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Rothan",
|
"name": "Rothan",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 366,
|
"x": 366,
|
||||||
"y": 298,
|
"y": 298
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Donesta",
|
"name": "Donesta",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 527,
|
"x": 527,
|
||||||
"y": 161,
|
"y": 161
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "India",
|
"name": "India",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 539,
|
"x": 539,
|
||||||
"y": 427,
|
"y": 427
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Antomis",
|
"name": "Antomis",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 582,
|
"x": 582,
|
||||||
"y": 115,
|
"y": 115
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Mace",
|
"name": "Mace",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 444,
|
"x": 444,
|
||||||
"y": 359,
|
"y": 359
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Clarke",
|
"name": "Clarke",
|
||||||
"side" : "SIDE_UNF",
|
"side" : "SIDE_UNF",
|
||||||
"x": 398,
|
"x": 398,
|
||||||
"y": 84,
|
"y": 84
|
||||||
"missions" : [
|
|
||||||
"data/missions/clarke/01 - clarke defence #1.json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Adetton",
|
"name": "Adetton",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 228,
|
"x": 228,
|
||||||
"y": 228,
|
"y": 228
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Atlante",
|
"name": "Atlante",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 212,
|
"x": 212,
|
||||||
"y": 85,
|
"y": 85
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Carthege",
|
"name": "Carthege",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 163,
|
"x": 163,
|
||||||
"y": 122,
|
"y": 122
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Codexa",
|
"name": "Codexa",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 195,
|
"x": 195,
|
||||||
"y": 101,
|
"y": 101
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Haylahe",
|
"name": "Haylahe",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 204,
|
"x": 204,
|
||||||
"y": 132,
|
"y": 132
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Kethlan",
|
"name": "Kethlan",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 95,
|
"x": 95,
|
||||||
"y": 95,
|
"y": 95
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Krasst",
|
"name": "Krasst",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 135,
|
"x": 135,
|
||||||
"y": 305,
|
"y": 305
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Mekel",
|
"name": "Mekel",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 228,
|
"x": 228,
|
||||||
"y": 113,
|
"y": 113
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Phylent",
|
"name": "Phylent",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 275,
|
"x": 275,
|
||||||
"y": 165,
|
"y": 165
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Sampi-Persei VII",
|
"name": "Sampi-Persei VII",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 342,
|
"x": 342,
|
||||||
"y": 182,
|
"y": 182
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Tigris",
|
"name": "Tigris",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 269,
|
"x": 269,
|
||||||
"y": 274,
|
"y": 274
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Troy",
|
"name": "Troy",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 107,
|
"x": 107,
|
||||||
"y": 269,
|
"y": 269
|
||||||
"missions" : []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Pearl",
|
"name": "Pearl",
|
||||||
"side" : "SIDE_INF",
|
"side" : "SIDE_INF",
|
||||||
"x": 133,
|
"x": 133,
|
||||||
"y": 215,
|
"y": 215
|
||||||
"missions" : []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#define MAX_DESCRIPTION_LENGTH 512
|
#define MAX_DESCRIPTION_LENGTH 512
|
||||||
#define MAX_FILENAME_LENGTH 1024
|
#define MAX_FILENAME_LENGTH 1024
|
||||||
|
|
||||||
|
#define MAX_LISTED_FILES 64
|
||||||
|
|
||||||
#define NUM_TEXTURE_BUCKETS 32
|
#define NUM_TEXTURE_BUCKETS 32
|
||||||
|
|
||||||
#define MAX_STARS 500
|
#define MAX_STARS 500
|
||||||
|
|
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "starSystems.h"
|
#include "starSystems.h"
|
||||||
|
|
||||||
|
static void loadMissions(StarSystem *starSystem);
|
||||||
static void loadStarSystem(cJSON *starSystemJSON);
|
static void loadStarSystem(cJSON *starSystemJSON);
|
||||||
static void loadMissionMeta(char *filename, StarSystem *starSystem);
|
static void loadMissionMeta(char *filename, StarSystem *starSystem);
|
||||||
|
|
||||||
|
@ -42,7 +43,6 @@ void initStarSystems(void)
|
||||||
|
|
||||||
static void loadStarSystem(cJSON *starSystemJSON)
|
static void loadStarSystem(cJSON *starSystemJSON)
|
||||||
{
|
{
|
||||||
cJSON *node;
|
|
||||||
StarSystem *starSystem;
|
StarSystem *starSystem;
|
||||||
|
|
||||||
starSystem = malloc(sizeof(StarSystem));
|
starSystem = malloc(sizeof(StarSystem));
|
||||||
|
@ -63,15 +63,42 @@ static void loadStarSystem(cJSON *starSystemJSON)
|
||||||
starSystem->missionHead.completed = 1;
|
starSystem->missionHead.completed = 1;
|
||||||
starSystem->missionTail = &starSystem->missionHead;
|
starSystem->missionTail = &starSystem->missionHead;
|
||||||
|
|
||||||
for (node = cJSON_GetObjectItem(starSystemJSON, "missions")->child ; node != NULL ; node = node->next)
|
loadMissions(starSystem);
|
||||||
{
|
|
||||||
loadMissionMeta(node->valuestring, starSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
starSystem->x *= 3;
|
starSystem->x *= 3;
|
||||||
starSystem->y *= 3;
|
starSystem->y *= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void loadMissions(StarSystem *starSystem)
|
||||||
|
{
|
||||||
|
int i, count;
|
||||||
|
char name[MAX_NAME_LENGTH];
|
||||||
|
char path[MAX_FILENAME_LENGTH];
|
||||||
|
char **filenames;
|
||||||
|
|
||||||
|
STRNCPY(name, starSystem->name, MAX_NAME_LENGTH);
|
||||||
|
|
||||||
|
for (i = 0 ; name[i] ; i++)
|
||||||
|
{
|
||||||
|
name[i] = tolower(name[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(path, "data/missions/%s", name);
|
||||||
|
|
||||||
|
filenames = getFileList(path, &count);
|
||||||
|
|
||||||
|
for (i = 0 ; i < count ; i++)
|
||||||
|
{
|
||||||
|
sprintf(path, "data/missions/%s/%s", name, filenames[i]);
|
||||||
|
|
||||||
|
loadMissionMeta(path, starSystem);
|
||||||
|
|
||||||
|
free(filenames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(filenames);
|
||||||
|
}
|
||||||
|
|
||||||
static void loadMissionMeta(char *filename, StarSystem *starSystem)
|
static void loadMissionMeta(char *filename, StarSystem *starSystem)
|
||||||
{
|
{
|
||||||
Mission *mission;
|
Mission *mission;
|
||||||
|
|
|
@ -26,5 +26,6 @@ extern char *readFile(char *filename);
|
||||||
extern long lookup(char *name);
|
extern long lookup(char *name);
|
||||||
extern int isMissionAvailable(Mission *mission, Mission *prev);
|
extern int isMissionAvailable(Mission *mission, Mission *prev);
|
||||||
extern char *getFileLocation(char *filename);
|
extern char *getFileLocation(char *filename);
|
||||||
|
extern char **getFileList(char *dir, int *count);
|
||||||
|
|
||||||
extern Game game;
|
extern Game game;
|
||||||
|
|
|
@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
|
static int stringComparator(const void *a, const void *b);
|
||||||
|
|
||||||
int fileExists(char *filename)
|
int fileExists(char *filename)
|
||||||
{
|
{
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
|
@ -89,3 +91,49 @@ char *getFileLocation(char *filename)
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char **getFileList(char *dir, int *count)
|
||||||
|
{
|
||||||
|
DIR *d;
|
||||||
|
struct dirent *ent;
|
||||||
|
int i;
|
||||||
|
char **filenames;
|
||||||
|
|
||||||
|
filenames = malloc(sizeof(char*) * MAX_LISTED_FILES);
|
||||||
|
memset(filenames, 0, sizeof(char*) * MAX_LISTED_FILES);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
if ((d = opendir(dir)) != NULL)
|
||||||
|
{
|
||||||
|
while ((ent = readdir(d)) != NULL)
|
||||||
|
{
|
||||||
|
if (ent->d_name[0] != '.')
|
||||||
|
{
|
||||||
|
filenames[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
|
||||||
|
|
||||||
|
STRNCPY(filenames[i], ent->d_name, MAX_FILENAME_LENGTH);
|
||||||
|
|
||||||
|
if (++i >= MAX_LISTED_FILES)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
*count = i;
|
||||||
|
|
||||||
|
qsort(filenames, i, sizeof(char*), stringComparator);
|
||||||
|
|
||||||
|
return filenames;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int stringComparator(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
char **s1 = (char **)a;
|
||||||
|
char **s2 = (char **)b;
|
||||||
|
return strcmp(*s1, *s2);
|
||||||
|
}
|
||||||
|
|
|
@ -21,5 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
#include "sys/stat.h"
|
#include "sys/stat.h"
|
||||||
|
#include "dirent.h"
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
|
|
Loading…
Reference in New Issue