2015-10-20 13:51:49 +02:00
|
|
|
/*
|
2016-02-21 16:50:27 +01:00
|
|
|
Copyright (C) 2015-2016 Parallel Realities
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
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);
|
2015-12-07 20:19:14 +01:00
|
|
|
static void loadCapitalShips(cJSON *node);
|
2015-10-26 18:27:43 +01:00
|
|
|
static void loadEntities(cJSON *node);
|
2015-11-16 13:31:50 +01:00
|
|
|
static void loadItems(cJSON *node);
|
2015-12-22 13:42:04 +01:00
|
|
|
static void loadLocations(cJSON *node);
|
2015-10-20 13:51:49 +02:00
|
|
|
static unsigned long hashcode(const char *str);
|
2015-12-07 20:19:14 +01:00
|
|
|
static char **toTypeArray(char *types, int *numTypes);
|
2015-11-01 10:25:10 +01:00
|
|
|
static void loadEpicData(cJSON *node);
|
2016-02-29 15:42:46 +01:00
|
|
|
static char *getAutoBackground(char *filename);
|
|
|
|
static char *getAutoPlanet(char *filename);
|
2016-03-03 17:16:12 +01:00
|
|
|
static char *getAutoMusic(char *filename);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
Mission *loadMissionMeta(char *filename)
|
|
|
|
{
|
2016-03-03 00:20:37 +01:00
|
|
|
int i;
|
2016-02-27 13:14:29 +01:00
|
|
|
Mission *mission;
|
2016-03-03 00:20:37 +01:00
|
|
|
Challenge *challenge;
|
2016-02-27 13:14:29 +01:00
|
|
|
cJSON *root, *node;
|
|
|
|
char *text;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-04 15:29:50 +01:00
|
|
|
text = readFile(filename);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
root = cJSON_Parse(text);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
mission = malloc(sizeof(Mission));
|
|
|
|
memset(mission, 0, sizeof(Mission));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
STRNCPY(mission->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
|
2016-02-27 20:16:17 +01:00
|
|
|
STRNCPY(mission->description, _(cJSON_GetObjectItem(root, "description")->valuestring), MAX_DESCRIPTION_LENGTH);
|
2016-02-27 13:14:29 +01:00
|
|
|
STRNCPY(mission->filename, filename, MAX_DESCRIPTION_LENGTH);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
|
|
|
mission->requires = getJSONValue(root, "requires", 0);
|
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
if (cJSON_GetObjectItem(root, "epic"))
|
|
|
|
{
|
|
|
|
mission->epic = 1;
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
node = cJSON_GetObjectItem(root, "player");
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
STRNCPY(mission->pilot, cJSON_GetObjectItem(node, "pilot")->valuestring, MAX_NAME_LENGTH);
|
|
|
|
STRNCPY(mission->squadron, cJSON_GetObjectItem(node, "squadron")->valuestring, MAX_NAME_LENGTH);
|
|
|
|
STRNCPY(mission->craft, cJSON_GetObjectItem(node, "type")->valuestring, MAX_NAME_LENGTH);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
node = cJSON_GetObjectItem(root, "challenge");
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
if (node)
|
|
|
|
{
|
2016-03-02 07:46:13 +01:00
|
|
|
mission->challengeData.isChallenge = 1;
|
2016-03-04 23:59:16 +01:00
|
|
|
|
|
|
|
mission->challengeData.timeLimit = getJSONValue(node, "timeLimit", 0) * FPS;
|
2016-03-04 15:14:04 +01:00
|
|
|
mission->challengeData.killLimit = getJSONValue(node, "killLimit", 0);
|
|
|
|
mission->challengeData.waypointLimit = getJSONValue(node, "waypointLimit", 0);
|
|
|
|
mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0);
|
|
|
|
mission->challengeData.noECM = getJSONValue(node, "noECM", 0);
|
|
|
|
mission->challengeData.noBoost = getJSONValue(node, "noBoost", 0);
|
|
|
|
mission->challengeData.noGuns = getJSONValue(node, "noGuns", 0);
|
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
node = cJSON_GetObjectItem(node, "challenges");
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
if (node)
|
2016-02-27 13:14:29 +01:00
|
|
|
{
|
2016-02-28 14:02:57 +01:00
|
|
|
node = node->child;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-03 00:20:37 +01:00
|
|
|
i = 0;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-03 00:20:37 +01:00
|
|
|
while (node && i < MAX_CHALLENGES)
|
2016-02-28 14:02:57 +01:00
|
|
|
{
|
|
|
|
challenge = malloc(sizeof(Challenge));
|
|
|
|
memset(challenge, 0, sizeof(Challenge));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
challenge->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
|
|
|
challenge->value = cJSON_GetObjectItem(node, "value")->valueint;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-03 00:20:37 +01:00
|
|
|
mission->challengeData.challenges[i] = challenge;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
node = node->next;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-03 00:20:37 +01:00
|
|
|
i++;
|
2016-02-28 14:02:57 +01:00
|
|
|
}
|
2016-02-27 13:14:29 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
cJSON_Delete(root);
|
|
|
|
free(text);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 13:14:29 +01:00
|
|
|
return mission;
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
void loadMission(char *filename)
|
|
|
|
{
|
|
|
|
cJSON *root;
|
2016-02-29 15:42:46 +01:00
|
|
|
char *text, music[MAX_DESCRIPTION_LENGTH], *background, *planet;
|
2016-02-21 14:47:10 +01:00
|
|
|
float planetScale;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
startSectionTransition();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
stopMusic();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-04 15:29:50 +01:00
|
|
|
text = readFile(filename);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
root = cJSON_Parse(text);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-29 15:42:46 +01:00
|
|
|
srand(hashcode(filename));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
loadObjectives(cJSON_GetObjectItem(root, "objectives"));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
loadPlayer(cJSON_GetObjectItem(root, "player"));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
loadFighters(cJSON_GetObjectItem(root, "fighters"));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
loadCapitalShips(cJSON_GetObjectItem(root, "capitalShips"));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-26 18:27:43 +01:00
|
|
|
loadEntities(cJSON_GetObjectItem(root, "entities"));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
loadItems(cJSON_GetObjectItem(root, "items"));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-22 13:42:04 +01:00
|
|
|
loadLocations(cJSON_GetObjectItem(root, "locations"));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-01 10:25:10 +01:00
|
|
|
if (cJSON_GetObjectItem(root, "epic"))
|
|
|
|
{
|
|
|
|
loadEpicData(cJSON_GetObjectItem(root, "epic"));
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
|
|
|
battle.manualComplete = getJSONValue(root, "manualComplete", 0);
|
|
|
|
battle.unwinnable = getJSONValue(root, "unwinnable", 0);
|
|
|
|
|
2015-11-28 11:11:20 +01:00
|
|
|
initScript(cJSON_GetObjectItem(root, "script"));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-03 17:16:12 +01:00
|
|
|
/* music, planet, and background loading must come last, so AUTO works properly */
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-03 17:16:12 +01:00
|
|
|
STRNCPY(music, cJSON_GetObjectItem(root, "music")->valuestring, MAX_DESCRIPTION_LENGTH);
|
|
|
|
if (strcmp(music, "AUTO") == 0)
|
|
|
|
{
|
|
|
|
STRNCPY(music, getAutoMusic(filename), MAX_DESCRIPTION_LENGTH);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-29 15:42:46 +01:00
|
|
|
background = cJSON_GetObjectItem(root, "background")->valuestring;
|
|
|
|
if (strcmp(background, "AUTO") == 0)
|
|
|
|
{
|
|
|
|
background = getAutoBackground(filename);
|
|
|
|
}
|
|
|
|
battle.background = getTexture(background);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-29 15:42:46 +01:00
|
|
|
planet = cJSON_GetObjectItem(root, "planet")->valuestring;
|
|
|
|
if (strcmp(planet, "AUTO") == 0)
|
|
|
|
{
|
|
|
|
planet = getAutoPlanet(filename);
|
|
|
|
}
|
|
|
|
planetScale = 75 + (rand() % 125);
|
|
|
|
planetScale *= 0.01;
|
|
|
|
battle.planetTexture = getTexture(planet);
|
|
|
|
battle.planet.x = (SCREEN_WIDTH / 2) - (rand() % SCREEN_WIDTH) + (rand() % SCREEN_WIDTH);
|
|
|
|
battle.planet.y = (SCREEN_HEIGHT / 2) - (rand() % SCREEN_HEIGHT) + (rand() % SCREEN_HEIGHT);
|
|
|
|
SDL_QueryTexture(battle.planetTexture, NULL, NULL, &battle.planetWidth, &battle.planetHeight);
|
|
|
|
battle.planetWidth *= planetScale;
|
|
|
|
battle.planetHeight *= planetScale;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
srand(time(NULL));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-29 15:42:46 +01:00
|
|
|
free(text);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
endSectionTransition();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
/* only increment num missions / challenges started if there are some (Free Flight excluded, for example) */
|
2015-10-25 01:01:46 +02:00
|
|
|
if (battle.objectiveHead.next)
|
|
|
|
{
|
|
|
|
game.stats[STAT_MISSIONS_STARTED]++;
|
|
|
|
}
|
2016-03-02 07:46:13 +01:00
|
|
|
else if (game.currentMission->challengeData.isChallenge)
|
2016-02-28 14:02:57 +01:00
|
|
|
{
|
|
|
|
game.stats[STAT_CHALLENGES_STARTED]++;
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
else
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
battle.status = MS_IN_PROGRESS;
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-28 20:12:58 +01:00
|
|
|
activateNextWaypoint();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-31 12:25:19 +01:00
|
|
|
countNumEnemies();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-23 08:08:18 +02:00
|
|
|
initPlayer();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 19:08:43 +01:00
|
|
|
initMissionInfo();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
playMusic(music);
|
|
|
|
}
|
|
|
|
|
2016-02-29 15:42:46 +01:00
|
|
|
static char *getAutoBackground(char *filename)
|
|
|
|
{
|
|
|
|
int hash;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-02 07:46:13 +01:00
|
|
|
if (!game.currentMission->challengeData.isChallenge)
|
2016-02-29 15:42:46 +01:00
|
|
|
{
|
|
|
|
hash = hashcode(game.selectedStarSystem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash = hashcode(filename);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-29 17:00:32 +01:00
|
|
|
return getBackgroundTextureName(hash);
|
2016-02-29 15:42:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *getAutoPlanet(char *filename)
|
|
|
|
{
|
|
|
|
int hash;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-02 07:46:13 +01:00
|
|
|
if (!game.currentMission->challengeData.isChallenge)
|
2016-02-29 15:42:46 +01:00
|
|
|
{
|
|
|
|
hash = hashcode(game.selectedStarSystem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash = hashcode(filename);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-29 17:00:32 +01:00
|
|
|
return getPlanetTextureName(hash);
|
2016-02-29 15:42:46 +01:00
|
|
|
}
|
|
|
|
|
2016-03-03 17:16:12 +01:00
|
|
|
static char *getAutoMusic(char *filename)
|
|
|
|
{
|
|
|
|
int hash;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-03 17:16:12 +01:00
|
|
|
if (!game.currentMission->challengeData.isChallenge)
|
|
|
|
{
|
|
|
|
hash = hashcode(game.selectedStarSystem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash = hashcode(filename);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-03 17:16:12 +01:00
|
|
|
return getMusicFilename(hash);
|
|
|
|
}
|
|
|
|
|
2015-10-26 09:10:13 +01:00
|
|
|
void completeMission(void)
|
|
|
|
{
|
2015-11-02 20:18:26 +01:00
|
|
|
if (battle.status == MS_IN_PROGRESS)
|
|
|
|
{
|
|
|
|
battle.status = MS_COMPLETE;
|
|
|
|
battle.missionFinishedTimer = FPS;
|
|
|
|
selectWidget("continue", "battleWon");
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-02 20:18:26 +01:00
|
|
|
game.stats[STAT_MISSIONS_COMPLETED]++;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-29 17:50:06 +01:00
|
|
|
completeConditions();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-21 18:32:39 +01:00
|
|
|
retreatEnemies();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-21 18:36:42 +01:00
|
|
|
player->flags |= EF_IMMORTAL;
|
2015-11-02 20:18:26 +01:00
|
|
|
}
|
2015-10-26 09:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void failMission(void)
|
|
|
|
{
|
2015-11-02 20:18:26 +01:00
|
|
|
if (battle.status == MS_IN_PROGRESS)
|
|
|
|
{
|
|
|
|
battle.status = MS_FAILED;
|
|
|
|
battle.missionFinishedTimer = FPS;
|
|
|
|
selectWidget("retry", "battleLost");
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-14 09:41:07 +01:00
|
|
|
failIncompleteObjectives();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-21 18:36:42 +01:00
|
|
|
player->flags |= EF_IMMORTAL;
|
2015-11-02 20:18:26 +01:00
|
|
|
}
|
2015-10-26 09:10:13 +01:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
static void loadObjectives(cJSON *node)
|
|
|
|
{
|
|
|
|
Objective *o;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node = node->child;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
o = malloc(sizeof(Objective));
|
|
|
|
memset(o, 0, sizeof(Objective));
|
2015-10-26 09:10:13 +01:00
|
|
|
battle.objectiveTail->next = o;
|
|
|
|
battle.objectiveTail = o;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 20:16:17 +01:00
|
|
|
STRNCPY(o->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH);
|
2015-10-20 13:51:49 +02:00
|
|
|
STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH);
|
|
|
|
o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
2015-10-22 08:08:03 +02:00
|
|
|
o->targetType = lookup(cJSON_GetObjectItem(node, "targetType")->valuestring);
|
2016-03-04 23:11:13 +01:00
|
|
|
o->active = getJSONValue(node, "active", 1);
|
2016-03-04 15:14:04 +01:00
|
|
|
o->isCondition = getJSONValue(node, "isCondition", 0);
|
|
|
|
|
|
|
|
o->isEliminateAll = getJSONValue(node, "isEliminateAll", 0);
|
2016-03-04 23:11:13 +01:00
|
|
|
if (o->isEliminateAll)
|
2015-10-22 08:08:03 +02:00
|
|
|
{
|
2015-12-22 18:58:18 +01:00
|
|
|
o->targetValue = 1;
|
2015-10-22 08:08:03 +02:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-26 09:10:13 +01:00
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
static void loadPlayer(cJSON *node)
|
|
|
|
{
|
|
|
|
char *type;
|
|
|
|
int side;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
type = cJSON_GetObjectItem(node, "type")->valuestring;
|
|
|
|
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-02 11:49:10 +01:00
|
|
|
player = spawnFighter(type, 0, 0, side);
|
2016-02-21 08:48:22 +01:00
|
|
|
player->x = BATTLE_AREA_WIDTH / 2;
|
|
|
|
player->y = BATTLE_AREA_HEIGHT / 2;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-22 12:41:28 +01:00
|
|
|
if (cJSON_GetObjectItem(node, "x"))
|
|
|
|
{
|
2016-02-21 08:48:22 +01:00
|
|
|
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;
|
2015-11-22 12:41:28 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-17 08:23:50 +01:00
|
|
|
if (strcmp(type, "Tug") == 0)
|
|
|
|
{
|
|
|
|
battle.stats[STAT_TUG]++;
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-17 08:23:50 +01:00
|
|
|
if (strcmp(type, "Shuttle") == 0)
|
|
|
|
{
|
|
|
|
battle.stats[STAT_SHUTTLE]++;
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void loadFighters(cJSON *node)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
Entity *e;
|
2015-11-14 09:41:07 +01:00
|
|
|
char **types, *name, *groupName, *type;
|
2015-11-02 11:49:10 +01:00
|
|
|
int side, scatter, number, active;
|
2015-12-12 19:24:23 +01:00
|
|
|
int i, numTypes, addFlags, addAIFlags;
|
2015-12-02 08:24:12 +01:00
|
|
|
long flags, aiFlags;
|
2015-11-02 11:49:10 +01:00
|
|
|
float x, y;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node = node->child;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
while (node)
|
|
|
|
{
|
2015-11-29 13:56:15 +01:00
|
|
|
name = NULL;
|
2015-11-14 09:41:07 +01:00
|
|
|
groupName = NULL;
|
2015-11-15 12:31:43 +01:00
|
|
|
flags = -1;
|
2015-12-02 08:24:12 +01:00
|
|
|
aiFlags = -1;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
|
2015-10-20 13:51:49 +02:00
|
|
|
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
2016-02-21 08:48:22 +01:00
|
|
|
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
|
|
|
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
2016-03-04 15:14:04 +01:00
|
|
|
name = getJSONValueStr(node, "name", NULL);
|
|
|
|
groupName = getJSONValueStr(node, "groupName", NULL);
|
2016-03-04 23:11:13 +01:00
|
|
|
number = getJSONValue(node, "number", 1);
|
|
|
|
scatter = getJSONValue(node, "scatter", 1);
|
|
|
|
active = getJSONValue(node, "active", 1);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-15 12:31:43 +01:00
|
|
|
if (cJSON_GetObjectItem(node, "flags"))
|
|
|
|
{
|
2015-12-12 19:24:23 +01:00
|
|
|
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
2015-11-15 12:31:43 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-02 08:24:12 +01:00
|
|
|
if (cJSON_GetObjectItem(node, "aiFlags"))
|
|
|
|
{
|
2015-12-12 19:24:23 +01:00
|
|
|
aiFlags = flagsToLong(cJSON_GetObjectItem(node, "aiFlags")->valuestring, &addAIFlags);
|
2015-12-02 08:24:12 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
for (i = 0 ; i < number ; i++)
|
|
|
|
{
|
2015-10-25 13:56:24 +01:00
|
|
|
type = types[rand() % numTypes];
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
e = spawnFighter(type, x, y, side);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
if (scatter > 1)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->x += (rand() % scatter) - (rand() % scatter);
|
|
|
|
e->y += (rand() % scatter) - (rand() % scatter);
|
2015-12-07 20:19:14 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
e->active = active;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-15 12:31:43 +01:00
|
|
|
if (flags != -1)
|
|
|
|
{
|
2015-12-12 19:24:23 +01:00
|
|
|
if (addFlags)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->flags |= flags;
|
2015-12-12 19:24:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->flags = flags;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
2015-12-12 19:24:23 +01:00
|
|
|
}
|
2015-11-15 12:31:43 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-02 08:24:12 +01:00
|
|
|
if (aiFlags != -1)
|
|
|
|
{
|
2015-12-12 19:24:23 +01:00
|
|
|
if (addAIFlags)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiFlags |= aiFlags;
|
2015-12-12 19:24:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiFlags = aiFlags;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "AI Flags for '%s' (%s) replaced", e->name, e->defName);
|
2015-12-12 19:24:23 +01:00
|
|
|
}
|
2015-12-02 08:24:12 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-29 13:56:15 +01:00
|
|
|
if (name)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
2015-11-29 13:56:15 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-14 09:41:07 +01:00
|
|
|
if (groupName)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
2015-11-14 09:41:07 +01:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
node = node->next;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-20 12:58:35 +01:00
|
|
|
for (i = 0 ; i < numTypes ; i++)
|
|
|
|
{
|
|
|
|
free(types[i]);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-25 13:56:24 +01:00
|
|
|
free(types);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
static void loadCapitalShips(cJSON *node)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
char **types, *name, *groupName, *type;
|
|
|
|
int side, scatter, number, active;
|
2015-12-12 19:24:23 +01:00
|
|
|
int i, numTypes, addFlags;
|
2015-12-12 18:12:25 +01:00
|
|
|
long flags;
|
2015-12-07 20:19:14 +01:00
|
|
|
float x, y;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node = node->child;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
name = NULL;
|
|
|
|
groupName = NULL;
|
2015-12-12 18:12:25 +01:00
|
|
|
flags = -1;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
|
|
|
|
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
2016-02-21 08:48:22 +01:00
|
|
|
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
|
|
|
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
2016-03-04 23:11:13 +01:00
|
|
|
name = getJSONValueStr(node, "name", NULL);
|
2016-03-04 15:14:04 +01:00
|
|
|
groupName = getJSONValueStr(node, "groupName", NULL);
|
2016-03-04 23:11:13 +01:00
|
|
|
number = getJSONValue(node, "number", 1);
|
|
|
|
scatter = getJSONValue(node, "scatter", 1);
|
|
|
|
active = getJSONValue(node, "active", 1);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-12 18:12:25 +01:00
|
|
|
if (cJSON_GetObjectItem(node, "flags"))
|
|
|
|
{
|
2015-12-12 19:24:23 +01:00
|
|
|
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
2015-12-12 18:12:25 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
for (i = 0 ; i < number ; i++)
|
|
|
|
{
|
|
|
|
type = types[rand() % numTypes];
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
e = spawnCapitalShip(type, x, y, side);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
if (scatter > 1)
|
|
|
|
{
|
|
|
|
e->x += (rand() % scatter) - (rand() % scatter);
|
|
|
|
e->y += (rand() % scatter) - (rand() % scatter);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
e->active = active;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
if (groupName)
|
|
|
|
{
|
|
|
|
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-12 18:12:25 +01:00
|
|
|
if (flags != -1)
|
|
|
|
{
|
2015-12-12 19:24:23 +01:00
|
|
|
if (addFlags)
|
|
|
|
{
|
|
|
|
e->flags |= flags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->flags = flags;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-12 19:24:23 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
|
|
|
}
|
2015-12-12 18:12:25 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-30 19:43:47 +01:00
|
|
|
updateCapitalShipComponentProperties(e);
|
2015-12-07 20:19:14 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
node = node->next;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-20 12:58:35 +01:00
|
|
|
for (i = 0 ; i < numTypes ; i++)
|
|
|
|
{
|
|
|
|
free(types[i]);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
free(types);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 18:27:43 +01:00
|
|
|
static void loadEntities(cJSON *node)
|
2015-10-27 08:24:17 +01:00
|
|
|
{
|
|
|
|
Entity *e;
|
2015-11-14 09:41:07 +01:00
|
|
|
char *name, *groupName;
|
2015-11-28 15:34:38 +01:00
|
|
|
int i, type, scatter, number, active;
|
2015-11-02 11:49:10 +01:00
|
|
|
float x, y;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node = node->child;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
while (node)
|
|
|
|
{
|
2015-11-26 18:41:05 +01:00
|
|
|
e = NULL;
|
2015-10-27 08:24:17 +01:00
|
|
|
type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
2016-02-21 08:48:22 +01:00
|
|
|
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
|
|
|
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
2015-10-29 12:08:47 +01:00
|
|
|
name = NULL;
|
2015-11-14 09:41:07 +01:00
|
|
|
groupName = NULL;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
|
|
|
name = getJSONValueStr(node, "name", NULL);
|
|
|
|
groupName = getJSONValueStr(node, "groupName", NULL);
|
2016-03-04 23:11:13 +01:00
|
|
|
number = getJSONValue(node, "number", 1);
|
|
|
|
active = getJSONValue(node, "active", 1);
|
|
|
|
scatter = getJSONValue(node, "scatter", 1);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
for (i = 0 ; i < number ; i++)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ET_WAYPOINT:
|
|
|
|
e = spawnWaypoint();
|
|
|
|
break;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-26 18:41:05 +01:00
|
|
|
case ET_EXTRACTION_POINT:
|
|
|
|
e = spawnExtractionPoint();
|
|
|
|
break;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-26 18:41:05 +01:00
|
|
|
default:
|
|
|
|
printf("Error: Unhandled entity type: %s\n", cJSON_GetObjectItem(node, "type")->valuestring);
|
|
|
|
exit(1);
|
|
|
|
break;
|
2015-10-27 08:24:17 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-28 20:12:58 +01:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-14 09:41:07 +01:00
|
|
|
if (groupName)
|
|
|
|
{
|
|
|
|
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
e->x = x;
|
|
|
|
e->y = y;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
if (scatter > 1)
|
|
|
|
{
|
|
|
|
e->x += (rand() % scatter) - (rand() % scatter);
|
|
|
|
e->y += (rand() % scatter) - (rand() % scatter);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-28 15:34:38 +01:00
|
|
|
e->active = active;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadItems(cJSON *node)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
char *name, *groupName, *type;
|
2015-12-12 19:24:23 +01:00
|
|
|
int i, scatter, number, active, addFlags;
|
2015-11-16 13:31:50 +01:00
|
|
|
long flags;
|
|
|
|
float x, y;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
flags = -1;
|
|
|
|
scatter = 1;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node = node->child;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
type = cJSON_GetObjectItem(node, "type")->valuestring;
|
2016-02-21 08:48:22 +01:00
|
|
|
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
|
|
|
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
2015-11-16 13:31:50 +01:00
|
|
|
name = NULL;
|
|
|
|
groupName = NULL;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
|
|
|
name = getJSONValueStr(node, "name", NULL);
|
|
|
|
groupName = getJSONValueStr(node, "groupName", NULL);
|
2016-03-04 23:11:13 +01:00
|
|
|
number = getJSONValue(node, "number", 1);
|
|
|
|
scatter = getJSONValue(node, "scatter", 1);
|
|
|
|
active = getJSONValue(node, "active", 1);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
if (cJSON_GetObjectItem(node, "flags"))
|
|
|
|
{
|
2015-12-12 19:24:23 +01:00
|
|
|
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
2015-11-16 13:31:50 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
for (i = 0 ; i < number ; i++)
|
|
|
|
{
|
|
|
|
e = spawnItem(type);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
if (groupName)
|
|
|
|
{
|
|
|
|
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 13:31:50 +01:00
|
|
|
if (flags != -1)
|
|
|
|
{
|
2015-12-12 19:24:23 +01:00
|
|
|
if (addFlags)
|
|
|
|
{
|
|
|
|
e->flags |= flags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->flags = flags;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-12 19:24:23 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
|
|
|
}
|
2015-11-16 13:31:50 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
e->x = x;
|
|
|
|
e->y = y;
|
2015-11-26 18:41:05 +01:00
|
|
|
e->active = active;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
if (scatter > 1)
|
|
|
|
{
|
|
|
|
e->x += (rand() % scatter) - (rand() % scatter);
|
|
|
|
e->y += (rand() % scatter) - (rand() % scatter);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-02 14:34:59 +01:00
|
|
|
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
|
2015-10-27 08:24:17 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-22 13:42:04 +01:00
|
|
|
static void loadLocations(cJSON *node)
|
|
|
|
{
|
2015-12-22 18:58:18 +01:00
|
|
|
int active;
|
2015-12-22 13:42:04 +01:00
|
|
|
Location *l;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-22 13:42:04 +01:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node = node->child;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-22 13:42:04 +01:00
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
l = malloc(sizeof(Location));
|
|
|
|
memset(l, 0, sizeof(Location));
|
|
|
|
battle.locationTail->next = l;
|
|
|
|
battle.locationTail = l;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-22 13:42:04 +01:00
|
|
|
STRNCPY(l->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
|
2016-02-21 08:48:22 +01:00
|
|
|
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;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-22 13:42:04 +01:00
|
|
|
l->size = cJSON_GetObjectItem(node, "size")->valueint;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-04 23:11:13 +01:00
|
|
|
active = getJSONValue(node, "active", 1);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-21 08:48:22 +01:00
|
|
|
l->x += (SCREEN_WIDTH / 2);
|
|
|
|
l->y += (SCREEN_HEIGHT / 2);
|
2015-12-22 18:58:18 +01:00
|
|
|
l->active = active;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-22 13:42:04 +01:00
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 20:19:14 +01:00
|
|
|
static char **toTypeArray(char *types, int *numTypes)
|
2015-10-25 13:56:24 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char **typeArray, *type;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-25 13:56:24 +01:00
|
|
|
*numTypes = 1;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-25 13:56:24 +01:00
|
|
|
for (i = 0 ; i < strlen(types) ; i++)
|
|
|
|
{
|
|
|
|
if (types[i] == ';')
|
|
|
|
{
|
|
|
|
*numTypes = *numTypes + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typeArray = malloc(*numTypes * sizeof(char*));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-25 13:56:24 +01:00
|
|
|
i = 0;
|
|
|
|
type = strtok(types, ";");
|
|
|
|
while (type)
|
|
|
|
{
|
|
|
|
typeArray[i] = malloc(strlen(type) + 1);
|
|
|
|
strcpy(typeArray[i], type);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-25 13:56:24 +01:00
|
|
|
type = strtok(NULL, ";");
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-25 13:56:24 +01:00
|
|
|
i++;
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-25 13:56:24 +01:00
|
|
|
return typeArray;
|
|
|
|
}
|
|
|
|
|
2015-11-01 10:25:10 +01:00
|
|
|
static void loadEpicData(cJSON *node)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
int numFighters[SIDE_MAX];
|
|
|
|
memset(numFighters, 0, sizeof(int) * SIDE_MAX);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
battle.isEpic = 1;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-01 10:25:10 +01:00
|
|
|
battle.epicFighterLimit = cJSON_GetObjectItem(node, "fighterLimit")->valueint;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-01 10:25:10 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->active && e->type == ET_FIGHTER && numFighters[e->side]++ >= battle.epicFighterLimit)
|
|
|
|
{
|
|
|
|
e->active = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-25 10:29:41 +01:00
|
|
|
Mission *getMission(char *filename)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-25 10:29:41 +01:00
|
|
|
StarSystem *starSystem;
|
2015-10-20 13:51:49 +02:00
|
|
|
Mission *mission;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 17:16:21 +01:00
|
|
|
/* First, search the star systems */
|
2015-10-25 10:29:41 +01:00
|
|
|
for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-25 10:29:41 +01:00
|
|
|
for (mission = starSystem->missionHead.next ; mission != NULL ; mission = mission->next)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-25 10:29:41 +01:00
|
|
|
if (strcmp(mission->filename, filename) == 0)
|
|
|
|
{
|
|
|
|
return mission;
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 17:16:21 +01:00
|
|
|
/* now search the challenges */
|
|
|
|
for (mission = game.challengeMissionHead.next ; mission != NULL ; mission = mission->next)
|
|
|
|
{
|
|
|
|
if (strcmp(mission->filename, filename) == 0)
|
|
|
|
{
|
|
|
|
return mission;
|
|
|
|
}
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 17:16:21 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "No such mission '%s'", filename);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-29 11:47:10 +01:00
|
|
|
void updateAllMissions(void)
|
|
|
|
{
|
|
|
|
updateStarSystemMissions();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-29 11:47:10 +01:00
|
|
|
updateChallengeMissions();
|
|
|
|
}
|
|
|
|
|
2015-10-29 09:03:05 +01:00
|
|
|
int isMissionAvailable(Mission *mission, Mission *prev)
|
|
|
|
{
|
2015-12-21 15:19:21 +01:00
|
|
|
return prev->completed && mission->requires <= game.completedMissions;
|
2015-10-29 09:03:05 +01:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
static unsigned long hashcode(const char *str)
|
|
|
|
{
|
|
|
|
unsigned long hash = 5381;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = *str;
|
|
|
|
|
|
|
|
while (c)
|
|
|
|
{
|
|
|
|
hash = ((hash << 5) + hash) + c;
|
|
|
|
|
|
|
|
c = *str++;
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
return abs(hash);
|
|
|
|
}
|