Moved entity loading code out of mission.c, and into appropriate c files.
This commit is contained in:
parent
73a3c0c78a
commit
175b7e5ca0
|
@ -564,6 +564,93 @@ void updateCapitalShipComponentProperties(Entity *parent)
|
|||
}
|
||||
}
|
||||
|
||||
void loadCapitalShips(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
char **types, *name, *groupName, *type;
|
||||
int side, scatter, number, active;
|
||||
int i, numTypes, addFlags;
|
||||
long flags;
|
||||
float x, y;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
name = NULL;
|
||||
groupName = NULL;
|
||||
flags = -1;
|
||||
|
||||
types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
|
||||
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
name = getJSONValueStr(node, "name", NULL);
|
||||
groupName = getJSONValueStr(node, "groupName", NULL);
|
||||
number = getJSONValue(node, "number", 1);
|
||||
scatter = getJSONValue(node, "scatter", 1);
|
||||
active = getJSONValue(node, "active", 1);
|
||||
|
||||
if (cJSON_GetObjectItem(node, "flags"))
|
||||
{
|
||||
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < number ; i++)
|
||||
{
|
||||
type = types[rand() % numTypes];
|
||||
|
||||
e = spawnCapitalShip(type, x, y, side);
|
||||
|
||||
if (scatter > 1)
|
||||
{
|
||||
e->x += (rand() % scatter) - (rand() % scatter);
|
||||
e->y += (rand() % scatter) - (rand() % scatter);
|
||||
}
|
||||
|
||||
e->active = active;
|
||||
|
||||
if (name)
|
||||
{
|
||||
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (groupName)
|
||||
{
|
||||
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (flags != -1)
|
||||
{
|
||||
if (addFlags)
|
||||
{
|
||||
e->flags |= flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->flags = flags;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
||||
}
|
||||
}
|
||||
|
||||
updateCapitalShipComponentProperties(e);
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
|
||||
for (i = 0 ; i < numTypes ; i++)
|
||||
{
|
||||
free(types[i]);
|
||||
}
|
||||
|
||||
free(types);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void destroyCapitalShipDefs(void)
|
||||
{
|
||||
Entity *e;
|
||||
|
|
|
@ -47,8 +47,10 @@ extern void runScriptFunction(char *format, ...);
|
|||
extern void updateObjective(char *name, int type);
|
||||
extern char **getFileList(char *dir, int *count);
|
||||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
extern char *getJSONValueStr(cJSON *node, char *name, char *defValue);
|
||||
extern char *getTranslatedString(char *string);
|
||||
extern void addLargeExplosion(void);
|
||||
extern char **toTypeArray(char *types, int *numTypes);
|
||||
|
||||
extern Battle battle;
|
||||
extern Entity *self;
|
||||
|
|
|
@ -751,6 +751,111 @@ static void loadFighterDef(char *filename)
|
|||
free(text);
|
||||
}
|
||||
|
||||
void loadFighters(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
char **types, *name, *groupName, *type;
|
||||
int side, scatter, number, active;
|
||||
int i, numTypes, addFlags, addAIFlags;
|
||||
long flags, aiFlags;
|
||||
float x, y;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
name = NULL;
|
||||
groupName = NULL;
|
||||
flags = -1;
|
||||
aiFlags = -1;
|
||||
|
||||
types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
|
||||
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
name = getJSONValueStr(node, "name", NULL);
|
||||
groupName = getJSONValueStr(node, "groupName", NULL);
|
||||
number = getJSONValue(node, "number", 1);
|
||||
scatter = getJSONValue(node, "scatter", 1);
|
||||
active = getJSONValue(node, "active", 1);
|
||||
|
||||
if (cJSON_GetObjectItem(node, "flags"))
|
||||
{
|
||||
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
||||
}
|
||||
|
||||
if (cJSON_GetObjectItem(node, "aiFlags"))
|
||||
{
|
||||
aiFlags = flagsToLong(cJSON_GetObjectItem(node, "aiFlags")->valuestring, &addAIFlags);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < number ; i++)
|
||||
{
|
||||
type = types[rand() % numTypes];
|
||||
|
||||
e = spawnFighter(type, x, y, side);
|
||||
|
||||
if (scatter > 1)
|
||||
{
|
||||
e->x += (rand() % scatter) - (rand() % scatter);
|
||||
e->y += (rand() % scatter) - (rand() % scatter);
|
||||
}
|
||||
|
||||
e->active = active;
|
||||
|
||||
if (flags != -1)
|
||||
{
|
||||
if (addFlags)
|
||||
{
|
||||
e->flags |= flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->flags = flags;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
||||
}
|
||||
}
|
||||
|
||||
if (aiFlags != -1)
|
||||
{
|
||||
if (addAIFlags)
|
||||
{
|
||||
e->aiFlags |= aiFlags;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->aiFlags = aiFlags;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "AI Flags for '%s' (%s) replaced", e->name, e->defName);
|
||||
}
|
||||
}
|
||||
|
||||
if (name)
|
||||
{
|
||||
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (groupName)
|
||||
{
|
||||
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
|
||||
for (i = 0 ; i < numTypes ; i++)
|
||||
{
|
||||
free(types[i]);
|
||||
}
|
||||
|
||||
free(types);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void destroyFighterDefs(void)
|
||||
{
|
||||
Entity *e;
|
||||
|
|
|
@ -48,6 +48,7 @@ extern char **getFileList(char *dir, int *count);
|
|||
extern char *getTranslatedString(char *string);
|
||||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
extern char **toTypeArray(char *types, int *numTypes);
|
||||
extern char *getJSONValueStr(cJSON *node, char *name, char *defValue);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
|
|
|
@ -127,6 +127,86 @@ static void action(void)
|
|||
}
|
||||
}
|
||||
|
||||
void loadItems(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
char *name, *groupName, *type;
|
||||
int i, scatter, number, active, addFlags;
|
||||
long flags;
|
||||
float x, y;
|
||||
|
||||
flags = -1;
|
||||
scatter = 1;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
type = cJSON_GetObjectItem(node, "type")->valuestring;
|
||||
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
name = NULL;
|
||||
groupName = NULL;
|
||||
|
||||
name = getJSONValueStr(node, "name", NULL);
|
||||
groupName = getJSONValueStr(node, "groupName", NULL);
|
||||
number = getJSONValue(node, "number", 1);
|
||||
scatter = getJSONValue(node, "scatter", 1);
|
||||
active = getJSONValue(node, "active", 1);
|
||||
|
||||
if (cJSON_GetObjectItem(node, "flags"))
|
||||
{
|
||||
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < number ; i++)
|
||||
{
|
||||
e = spawnItem(type);
|
||||
|
||||
if (name)
|
||||
{
|
||||
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (groupName)
|
||||
{
|
||||
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (flags != -1)
|
||||
{
|
||||
if (addFlags)
|
||||
{
|
||||
e->flags |= flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->flags = flags;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
||||
}
|
||||
}
|
||||
|
||||
e->x = x;
|
||||
e->y = y;
|
||||
e->active = active;
|
||||
|
||||
if (scatter > 1)
|
||||
{
|
||||
e->x += (rand() % scatter) - (rand() % scatter);
|
||||
e->y += (rand() % scatter) - (rand() % scatter);
|
||||
}
|
||||
|
||||
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void destroyItemDefs(void)
|
||||
{
|
||||
Entity *e;
|
||||
|
|
|
@ -31,6 +31,9 @@ extern void playBattleSound(int id, int x, int y);
|
|||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||
extern void updateObjective(char *name, int type);
|
||||
extern char *getTranslatedString(char *string);
|
||||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
extern char *getJSONValueStr(cJSON *node, char *name, char *defValue);
|
||||
extern long flagsToLong(char *flags, int *add);
|
||||
|
||||
extern Battle battle;
|
||||
extern Entity *self;
|
||||
|
|
|
@ -74,3 +74,34 @@ void activateLocations(char *locations)
|
|||
token = strtok(NULL, ";");
|
||||
}
|
||||
}
|
||||
|
||||
void loadLocations(cJSON *node)
|
||||
{
|
||||
int active;
|
||||
Location *l;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
l = malloc(sizeof(Location));
|
||||
memset(l, 0, sizeof(Location));
|
||||
battle.locationTail->next = l;
|
||||
battle.locationTail = l;
|
||||
|
||||
STRNCPY(l->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
|
||||
l->x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
l->y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
l->size = cJSON_GetObjectItem(node, "size")->valueint;
|
||||
l->active = active = getJSONValue(node, "active", 1);
|
||||
|
||||
l->x += (SCREEN_WIDTH / 2);
|
||||
l->y += (SCREEN_HEIGHT / 2);
|
||||
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "../common.h"
|
||||
|
||||
#include "../json/cJSON.h"
|
||||
|
||||
extern Battle battle;
|
||||
extern Entity *player;
|
||||
|
||||
extern int getDistance(int x1, int y1, int x2, int y2);
|
||||
extern void runScriptFunction(char *format, ...);
|
||||
extern void drawCircle(int cx, int cy, int radius, int r, int g, int b, int a);
|
||||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
|
|
|
@ -223,3 +223,38 @@ void activateObjectives(char *objectives)
|
|||
token = strtok(NULL, ";");
|
||||
}
|
||||
}
|
||||
|
||||
void loadObjectives(cJSON *node)
|
||||
{
|
||||
Objective *o;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
o = malloc(sizeof(Objective));
|
||||
memset(o, 0, sizeof(Objective));
|
||||
battle.objectiveTail->next = o;
|
||||
battle.objectiveTail = o;
|
||||
|
||||
STRNCPY(o->id, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
|
||||
STRNCPY(o->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH);
|
||||
STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH);
|
||||
o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
||||
o->targetType = lookup(cJSON_GetObjectItem(node, "targetType")->valuestring);
|
||||
o->active = getJSONValue(node, "active", 1);
|
||||
o->isCondition = getJSONValue(node, "isCondition", 0);
|
||||
o->isEliminateAll = getJSONValue(node, "isEliminateAll", 0);
|
||||
o->hideNumbers = getJSONValue(node, "hideNumbers", 0);
|
||||
|
||||
if (o->isEliminateAll)
|
||||
{
|
||||
o->targetValue = 1;
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
|
||||
#include "../common.h"
|
||||
#include "../json/cJSON.h"
|
||||
|
||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||
extern void runScriptFunction(char *format, ...);
|
||||
extern void completeMission(void);
|
||||
extern void failMission(void);
|
||||
extern char *getTranslatedString(char *string);
|
||||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
extern long lookup(char *name);
|
||||
|
||||
extern Battle battle;
|
||||
extern Colors colors;
|
||||
|
|
|
@ -591,3 +591,32 @@ int playerHasGun(int type)
|
|||
{
|
||||
return availableGuns[type];
|
||||
}
|
||||
|
||||
void loadPlayer(cJSON *node)
|
||||
{
|
||||
char *type;
|
||||
int side;
|
||||
|
||||
type = cJSON_GetObjectItem(node, "type")->valuestring;
|
||||
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
|
||||
player = spawnFighter(type, 0, 0, side);
|
||||
player->x = BATTLE_AREA_WIDTH / 2;
|
||||
player->y = BATTLE_AREA_HEIGHT / 2;
|
||||
|
||||
if (cJSON_GetObjectItem(node, "x"))
|
||||
{
|
||||
player->x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
player->y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
}
|
||||
|
||||
if (strcmp(type, "Tug") == 0)
|
||||
{
|
||||
battle.stats[STAT_TUG]++;
|
||||
}
|
||||
|
||||
if (strcmp(type, "Shuttle") == 0)
|
||||
{
|
||||
battle.stats[STAT_SHUTTLE]++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
|
||||
#include "../common.h"
|
||||
#include "../json/cJSON.h"
|
||||
|
||||
#define MAX_SELECTABLE_PLAYERS 8
|
||||
#define MAX_SELECTABLE_TARGETS 8
|
||||
|
@ -39,6 +40,8 @@ extern char *getTranslatedString(char *string);
|
|||
extern void addECMEffect(Entity *ent);
|
||||
extern int isControl(int type);
|
||||
extern void clearControl(int type);
|
||||
extern long lookup(char *name);
|
||||
extern Entity *spawnFighter(char *name, int x, int y, int side);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
|
|
|
@ -90,3 +90,34 @@ void activateSpawner(char *names, int active)
|
|||
name = strtok(NULL, ";");
|
||||
}
|
||||
}
|
||||
|
||||
void loadSpawners(cJSON *node)
|
||||
{
|
||||
int active;
|
||||
Spawner *s;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
s = malloc(sizeof(Spawner));
|
||||
memset(s, 0, sizeof(Spawner));
|
||||
battle.spawnerTail->next = s;
|
||||
battle.spawnerTail = s;
|
||||
|
||||
STRNCPY(s->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
|
||||
s->types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &s->numTypes);
|
||||
s->side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
s->interval = cJSON_GetObjectItem(node, "interval")->valueint * FPS;
|
||||
s->limit = getJSONValue(node, "limit", 0);
|
||||
s->total = getJSONValue(node, "total", 0);
|
||||
s->step = cJSON_GetObjectItem(node, "step")->valueint;
|
||||
s->offscreen = getJSONValue(node, "offscreen", 0);
|
||||
s->active = active = getJSONValue(node, "active", 1);
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "../common.h"
|
||||
|
||||
#include "../json/cJSON.h"
|
||||
|
||||
extern long lookup(char *name);
|
||||
extern Entity *spawnFighter(char *name, int x, int y, int side);
|
||||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
extern char **toTypeArray(char *types, int *numTypes);
|
||||
|
||||
extern Battle battle;
|
||||
extern Entity *player;
|
||||
|
|
|
@ -20,14 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "mission.h"
|
||||
|
||||
static void loadObjectives(cJSON *node);
|
||||
static void loadPlayer(cJSON *node);
|
||||
static void loadFighters(cJSON *node);
|
||||
static void loadCapitalShips(cJSON *node);
|
||||
static void loadEntities(cJSON *node);
|
||||
static void loadItems(cJSON *node);
|
||||
static void loadLocations(cJSON *node);
|
||||
static void loadSpawners(cJSON *node);
|
||||
static unsigned long hashcode(const char *str);
|
||||
static void loadEpicData(cJSON *node);
|
||||
static char *getAutoBackground(char *filename);
|
||||
|
@ -314,262 +307,6 @@ void failMission(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void loadObjectives(cJSON *node)
|
||||
{
|
||||
Objective *o;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
o = malloc(sizeof(Objective));
|
||||
memset(o, 0, sizeof(Objective));
|
||||
battle.objectiveTail->next = o;
|
||||
battle.objectiveTail = o;
|
||||
|
||||
STRNCPY(o->id, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
|
||||
STRNCPY(o->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH);
|
||||
STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH);
|
||||
o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
||||
o->targetType = lookup(cJSON_GetObjectItem(node, "targetType")->valuestring);
|
||||
o->active = getJSONValue(node, "active", 1);
|
||||
o->isCondition = getJSONValue(node, "isCondition", 0);
|
||||
o->isEliminateAll = getJSONValue(node, "isEliminateAll", 0);
|
||||
o->hideNumbers = getJSONValue(node, "hideNumbers", 0);
|
||||
|
||||
if (o->isEliminateAll)
|
||||
{
|
||||
o->targetValue = 1;
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadPlayer(cJSON *node)
|
||||
{
|
||||
char *type;
|
||||
int side;
|
||||
|
||||
type = cJSON_GetObjectItem(node, "type")->valuestring;
|
||||
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
|
||||
player = spawnFighter(type, 0, 0, side);
|
||||
player->x = BATTLE_AREA_WIDTH / 2;
|
||||
player->y = BATTLE_AREA_HEIGHT / 2;
|
||||
|
||||
if (cJSON_GetObjectItem(node, "x"))
|
||||
{
|
||||
player->x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
player->y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
}
|
||||
|
||||
if (strcmp(type, "Tug") == 0)
|
||||
{
|
||||
battle.stats[STAT_TUG]++;
|
||||
}
|
||||
|
||||
if (strcmp(type, "Shuttle") == 0)
|
||||
{
|
||||
battle.stats[STAT_SHUTTLE]++;
|
||||
}
|
||||
}
|
||||
|
||||
static void loadFighters(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
char **types, *name, *groupName, *type;
|
||||
int side, scatter, number, active;
|
||||
int i, numTypes, addFlags, addAIFlags;
|
||||
long flags, aiFlags;
|
||||
float x, y;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
name = NULL;
|
||||
groupName = NULL;
|
||||
flags = -1;
|
||||
aiFlags = -1;
|
||||
|
||||
types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
|
||||
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
name = getJSONValueStr(node, "name", NULL);
|
||||
groupName = getJSONValueStr(node, "groupName", NULL);
|
||||
number = getJSONValue(node, "number", 1);
|
||||
scatter = getJSONValue(node, "scatter", 1);
|
||||
active = getJSONValue(node, "active", 1);
|
||||
|
||||
if (cJSON_GetObjectItem(node, "flags"))
|
||||
{
|
||||
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
||||
}
|
||||
|
||||
if (cJSON_GetObjectItem(node, "aiFlags"))
|
||||
{
|
||||
aiFlags = flagsToLong(cJSON_GetObjectItem(node, "aiFlags")->valuestring, &addAIFlags);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < number ; i++)
|
||||
{
|
||||
type = types[rand() % numTypes];
|
||||
|
||||
e = spawnFighter(type, x, y, side);
|
||||
|
||||
if (scatter > 1)
|
||||
{
|
||||
e->x += (rand() % scatter) - (rand() % scatter);
|
||||
e->y += (rand() % scatter) - (rand() % scatter);
|
||||
}
|
||||
|
||||
e->active = active;
|
||||
|
||||
if (flags != -1)
|
||||
{
|
||||
if (addFlags)
|
||||
{
|
||||
e->flags |= flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->flags = flags;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
||||
}
|
||||
}
|
||||
|
||||
if (aiFlags != -1)
|
||||
{
|
||||
if (addAIFlags)
|
||||
{
|
||||
e->aiFlags |= aiFlags;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->aiFlags = aiFlags;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "AI Flags for '%s' (%s) replaced", e->name, e->defName);
|
||||
}
|
||||
}
|
||||
|
||||
if (name)
|
||||
{
|
||||
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (groupName)
|
||||
{
|
||||
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
|
||||
for (i = 0 ; i < numTypes ; i++)
|
||||
{
|
||||
free(types[i]);
|
||||
}
|
||||
|
||||
free(types);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadCapitalShips(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
char **types, *name, *groupName, *type;
|
||||
int side, scatter, number, active;
|
||||
int i, numTypes, addFlags;
|
||||
long flags;
|
||||
float x, y;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
name = NULL;
|
||||
groupName = NULL;
|
||||
flags = -1;
|
||||
|
||||
types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
|
||||
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
name = getJSONValueStr(node, "name", NULL);
|
||||
groupName = getJSONValueStr(node, "groupName", NULL);
|
||||
number = getJSONValue(node, "number", 1);
|
||||
scatter = getJSONValue(node, "scatter", 1);
|
||||
active = getJSONValue(node, "active", 1);
|
||||
|
||||
if (cJSON_GetObjectItem(node, "flags"))
|
||||
{
|
||||
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < number ; i++)
|
||||
{
|
||||
type = types[rand() % numTypes];
|
||||
|
||||
e = spawnCapitalShip(type, x, y, side);
|
||||
|
||||
if (scatter > 1)
|
||||
{
|
||||
e->x += (rand() % scatter) - (rand() % scatter);
|
||||
e->y += (rand() % scatter) - (rand() % scatter);
|
||||
}
|
||||
|
||||
e->active = active;
|
||||
|
||||
if (name)
|
||||
{
|
||||
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (groupName)
|
||||
{
|
||||
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (flags != -1)
|
||||
{
|
||||
if (addFlags)
|
||||
{
|
||||
e->flags |= flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->flags = flags;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
||||
}
|
||||
}
|
||||
|
||||
updateCapitalShipComponentProperties(e);
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
|
||||
for (i = 0 ; i < numTypes ; i++)
|
||||
{
|
||||
free(types[i]);
|
||||
}
|
||||
|
||||
free(types);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadEntities(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
|
@ -664,148 +401,6 @@ static void loadEntities(cJSON *node)
|
|||
}
|
||||
}
|
||||
|
||||
static void loadItems(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
char *name, *groupName, *type;
|
||||
int i, scatter, number, active, addFlags;
|
||||
long flags;
|
||||
float x, y;
|
||||
|
||||
flags = -1;
|
||||
scatter = 1;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
type = cJSON_GetObjectItem(node, "type")->valuestring;
|
||||
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
name = NULL;
|
||||
groupName = NULL;
|
||||
|
||||
name = getJSONValueStr(node, "name", NULL);
|
||||
groupName = getJSONValueStr(node, "groupName", NULL);
|
||||
number = getJSONValue(node, "number", 1);
|
||||
scatter = getJSONValue(node, "scatter", 1);
|
||||
active = getJSONValue(node, "active", 1);
|
||||
|
||||
if (cJSON_GetObjectItem(node, "flags"))
|
||||
{
|
||||
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < number ; i++)
|
||||
{
|
||||
e = spawnItem(type);
|
||||
|
||||
if (name)
|
||||
{
|
||||
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (groupName)
|
||||
{
|
||||
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
if (flags != -1)
|
||||
{
|
||||
if (addFlags)
|
||||
{
|
||||
e->flags |= flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->flags = flags;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
||||
}
|
||||
}
|
||||
|
||||
e->x = x;
|
||||
e->y = y;
|
||||
e->active = active;
|
||||
|
||||
if (scatter > 1)
|
||||
{
|
||||
e->x += (rand() % scatter) - (rand() % scatter);
|
||||
e->y += (rand() % scatter) - (rand() % scatter);
|
||||
}
|
||||
|
||||
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadLocations(cJSON *node)
|
||||
{
|
||||
int active;
|
||||
Location *l;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
l = malloc(sizeof(Location));
|
||||
memset(l, 0, sizeof(Location));
|
||||
battle.locationTail->next = l;
|
||||
battle.locationTail = l;
|
||||
|
||||
STRNCPY(l->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
|
||||
l->x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
||||
l->y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
||||
l->size = cJSON_GetObjectItem(node, "size")->valueint;
|
||||
l->active = active = getJSONValue(node, "active", 1);
|
||||
|
||||
l->x += (SCREEN_WIDTH / 2);
|
||||
l->y += (SCREEN_HEIGHT / 2);
|
||||
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadSpawners(cJSON *node)
|
||||
{
|
||||
int active;
|
||||
Spawner *s;
|
||||
|
||||
if (node)
|
||||
{
|
||||
node = node->child;
|
||||
|
||||
while (node)
|
||||
{
|
||||
s = malloc(sizeof(Spawner));
|
||||
memset(s, 0, sizeof(Spawner));
|
||||
battle.spawnerTail->next = s;
|
||||
battle.spawnerTail = s;
|
||||
|
||||
STRNCPY(s->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
|
||||
s->types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &s->numTypes);
|
||||
s->side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
||||
s->interval = cJSON_GetObjectItem(node, "interval")->valueint * FPS;
|
||||
s->limit = getJSONValue(node, "limit", 0);
|
||||
s->total = getJSONValue(node, "total", 0);
|
||||
s->step = cJSON_GetObjectItem(node, "step")->valueint;
|
||||
s->offscreen = getJSONValue(node, "offscreen", 0);
|
||||
s->active = active = getJSONValue(node, "active", 1);
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadEpicData(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
|
|
|
@ -26,8 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
extern long lookup(char *name);
|
||||
extern char *readFile(char *filename);
|
||||
extern SDL_Texture *getTexture(char *filename);
|
||||
extern Entity *spawnFighter(char *name, int x, int y, int side);
|
||||
extern Entity *spawnCapitalShip(char *name, int x, int y, int side);
|
||||
extern void startSectionTransition(void);
|
||||
extern void endSectionTransition(void);
|
||||
extern void playMusic(char *filename);
|
||||
|
@ -37,12 +35,10 @@ extern long flagsToLong(char *flags, int *add);
|
|||
extern Entity *spawnWaypoint(void);
|
||||
extern void selectWidget(const char *name, const char *group);
|
||||
extern Entity *spawnJumpgate(void);
|
||||
extern Entity *spawnItem(char *type);
|
||||
extern void failIncompleteObjectives(void);
|
||||
extern void completeConditions(void);
|
||||
extern void retreatEnemies(void);
|
||||
extern void initScript(cJSON *missionJSON);
|
||||
extern void updateCapitalShipComponentProperties(Entity *parent);
|
||||
extern void countNumEnemies(void);
|
||||
extern void initMissionInfo(void);
|
||||
extern char *getTranslatedString(char *string);
|
||||
|
@ -54,7 +50,13 @@ extern char *getMusicFilename(int n);
|
|||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
extern char *getJSONValueStr(cJSON *node, char *name, char *defValue);
|
||||
extern void addAllEntsToQuadtree(void);
|
||||
extern char **toTypeArray(char *types, int *numTypes);
|
||||
extern void loadObjectives(cJSON *node);
|
||||
extern void loadPlayer(cJSON *node);
|
||||
extern void loadCapitalShips(cJSON *node);
|
||||
extern void loadFighters(cJSON *node);
|
||||
extern void loadItems(cJSON *node);
|
||||
extern void loadLocations(cJSON *node);
|
||||
extern void loadSpawners(cJSON *node);
|
||||
|
||||
extern Battle battle;
|
||||
extern Entity *player;
|
||||
|
|
|
@ -29,7 +29,7 @@ int main(int argc, char *argv[])
|
|||
long expireTextTimer;
|
||||
SDL_Event event;
|
||||
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN);
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
memset(&app, 0, sizeof(App));
|
||||
memset(&dev, 0, sizeof(Dev));
|
||||
|
|
Loading…
Reference in New Issue