[Change] Cleaned up some code.
This commit is contained in:
parent
2e65fb94a1
commit
6769b024b3
6
TODO
6
TODO
@ -4,11 +4,11 @@ Vital:
|
||||
-- Interference
|
||||
-- Asteroids.
|
||||
-- Real news.
|
||||
-- Event System.
|
||||
-- Like mission system, but they occur naturally/randomly.
|
||||
-- Has similar power to mission system.
|
||||
|
||||
Major:
|
||||
-- Event System.
|
||||
-- Like mission system, but they accur naturally/randomly.
|
||||
-- Had similar power to mission system
|
||||
-- Unique pilot system (besides mission uniques).
|
||||
-- Escorts available for hire.
|
||||
-- Nicer AI.
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#define PLAYER_ALLY 70. /**< Above this, player is considered ally. */
|
||||
|
||||
#define CHUNK_SIZE 32 /**< Size of chunk for allocation. */
|
||||
|
||||
/**
|
||||
* @struct Faction.
|
||||
*
|
||||
@ -53,15 +55,13 @@ static int faction_nstack = 0; /**< Number of factions in the faction s
|
||||
/* Static. */
|
||||
static int faction_isFaction(int f);
|
||||
static void faction_sanitizePlayer(Faction* faction);
|
||||
static Faction* faction_parse(xmlNodePtr parent);
|
||||
static int faction_parse(Faction* tmp, xmlNodePtr parent);
|
||||
static void faction_parseSocial(xmlNodePtr parent);
|
||||
/* Extern. */
|
||||
int pfaction_save(xmlTextWriterPtr writer);
|
||||
int pfaction_load(xmlNodePtr parent);
|
||||
|
||||
/**
|
||||
* @fn int faction_get(const char* name)
|
||||
*
|
||||
* @brief Get a faction ID by name.
|
||||
* @param name Name of the faction to seek.
|
||||
* @return ID of the faction.
|
||||
@ -437,13 +437,13 @@ static int faction_isFaction(int f) {
|
||||
* @param parent Parent node to extract faction from.
|
||||
* @return Faction created from parent node.
|
||||
*/
|
||||
static Faction* faction_parse(xmlNodePtr parent) {
|
||||
static int faction_parse(Faction* tmp, xmlNodePtr parent) {
|
||||
xmlNodePtr node;
|
||||
int player;
|
||||
Faction* tmp;
|
||||
char buf[PATH_MAX];
|
||||
|
||||
tmp = CALLOC_L(Faction);
|
||||
/* Clear memory. */
|
||||
memset(tmp, 0, sizeof(Faction));
|
||||
|
||||
tmp->name = xml_nodeProp(parent, "name");
|
||||
if(tmp->name == NULL)
|
||||
@ -470,7 +470,7 @@ static Faction* faction_parse(xmlNodePtr parent) {
|
||||
|
||||
if(player == 0) WARN("Faction '%s' missing player tag", tmp->name);
|
||||
|
||||
return tmp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse the social tidbits: Allies and enemies. */
|
||||
@ -531,14 +531,13 @@ void factions_reset(void) {
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int factions_load(void) {
|
||||
int mem;
|
||||
uint32_t bufsize;
|
||||
char* buf = pack_readfile(DATA, FACTION_DATA, &bufsize);
|
||||
|
||||
xmlNodePtr factions, node;
|
||||
xmlDocPtr doc = xmlParseMemory(buf, bufsize);
|
||||
|
||||
Faction* tmp = NULL;
|
||||
|
||||
node = doc->xmlChildrenNode; /* Faction node. */
|
||||
if(!xml_isNode(node, XML_FACTION_ID)) {
|
||||
ERR("Malformed "FACTION_DATA" file: missing root element '"XML_FACTION_ID"'");
|
||||
@ -559,15 +558,24 @@ int factions_load(void) {
|
||||
|
||||
/* First pass. */
|
||||
node = factions;
|
||||
mem = 0;
|
||||
do {
|
||||
if(xml_isNode(node, XML_FACTION_TAG)) {
|
||||
tmp = faction_parse(node);
|
||||
faction_stack = realloc(faction_stack, sizeof(Faction)*(++faction_nstack));
|
||||
memcpy(faction_stack + faction_nstack - 1, tmp, sizeof(Faction));
|
||||
free(tmp);
|
||||
/* See if stack needs to grow. */
|
||||
faction_nstack++;
|
||||
if(faction_nstack > mem) {
|
||||
mem += CHUNK_SIZE;
|
||||
faction_stack = realloc(faction_stack, sizeof(Faction)*mem);
|
||||
}
|
||||
|
||||
/* Load faction. */
|
||||
faction_parse(&faction_stack[faction_nstack-1], node);
|
||||
}
|
||||
} while(xml_nextNode(node));
|
||||
|
||||
/* Shrink stack to minimum size. */
|
||||
faction_stack = realloc(faction_stack, sizeof(Faction)*faction_nstack);
|
||||
|
||||
/* Second pass - Set allies and enemies. */
|
||||
node = factions;
|
||||
do {
|
||||
|
Loading…
Reference in New Issue
Block a user