[Change] Removed alliance deal, now each faction states it's own allies/enemies.
This commit is contained in:
parent
5de9fd60d9
commit
b4e325a9fe
143
dat/faction.xml
143
dat/faction.xml
@ -2,49 +2,142 @@
|
|||||||
<Factions>
|
<Factions>
|
||||||
<faction name="Independent">
|
<faction name="Independent">
|
||||||
<player>0</player>
|
<player>0</player>
|
||||||
|
<allies>
|
||||||
|
<ally>Militia</ally>
|
||||||
|
<ally>Merchant</ally>
|
||||||
|
</allies>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
<enemy>Unknown1</enemy>
|
||||||
|
<enemy>Unknown2</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
</enemies>
|
||||||
</faction>
|
</faction>
|
||||||
<faction name="Merchant">
|
<faction name="Merchant">
|
||||||
<player>0</player>
|
<player>0</player>
|
||||||
|
<allies>
|
||||||
|
<ally>Militia</ally>
|
||||||
|
<ally>Independent</ally>
|
||||||
|
<ally>Empire</ally>
|
||||||
|
<ally>Unknown6</ally>
|
||||||
|
</allies>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Unknown2</enemy>
|
||||||
|
<enemy>Unknown1</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
</enemies>
|
||||||
</faction>
|
</faction>
|
||||||
<faction name="Pirate">
|
<faction name="Pirate">
|
||||||
<player>-20</player>
|
<player>-20</player>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Empire</enemy>
|
||||||
|
<enemy>Unknown3</enemy>
|
||||||
|
<enemy>Unknown4</enemy>
|
||||||
|
<enemy>Unknown1</enemy>
|
||||||
|
<enemy>Unknown5</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
<enemy>Unknown6</enemy>
|
||||||
|
</enemies>
|
||||||
</faction>
|
</faction>
|
||||||
<faction name="Militia">
|
<faction name="Militia">
|
||||||
<player>0</player>
|
<player>0</player>
|
||||||
|
<allies>
|
||||||
|
<ally>Independent</ally>
|
||||||
|
<ally>Merchant</ally>
|
||||||
|
</allies>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
<enemy>Unknown2</enemy>
|
||||||
|
</enemies>
|
||||||
</faction>
|
</faction>
|
||||||
<faction name="Empire">
|
<faction name="Empire">
|
||||||
<player>0</player>
|
<player>0</player>
|
||||||
|
<allies>
|
||||||
|
<ally>Unknown6</ally>
|
||||||
|
<ally>Merchant</ally>
|
||||||
|
</allies>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Unknown2</enemy>
|
||||||
|
<enemy>Unknown1</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
</enemies>
|
||||||
</faction>
|
</faction>
|
||||||
<faction name="Collective">
|
<faction name="Collective">
|
||||||
<player>-100</player>
|
<player>-100</player>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Empire</enemy>
|
||||||
|
<enemy>Unknown3</enemy>
|
||||||
|
<enemy>Unknown4</enemy>
|
||||||
|
<enemy>Unknown1</enemy>
|
||||||
|
<enemy>Unknown5</enemy>
|
||||||
|
<enemy>Unknown6</enemy>
|
||||||
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Unknown2</enemy>
|
||||||
|
</enemies>
|
||||||
</faction>
|
</faction>
|
||||||
<Alliances>
|
<faction name="Unknown3">
|
||||||
<alliance name="Neutral">
|
<player>0</player>
|
||||||
<ally>Independent</ally>
|
<enemies>
|
||||||
<ally>Merchant</ally>
|
<enemy>Pirate</enemy>
|
||||||
<ally>Militia</ally>
|
<enemy>Collective</enemy>
|
||||||
</alliance>
|
<enemy>Unknown1</enemy>
|
||||||
<alliance name="Empire United">
|
</enemies>
|
||||||
|
</faction>
|
||||||
|
<faction name="Unknown2">
|
||||||
|
<player>-10</player>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Empire</enemy>
|
||||||
|
<enemy>Unknown4</enemy>
|
||||||
|
<enemy>Unknown1</enemy>
|
||||||
|
<enemy>Unknown5</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
<enemy>Unknown6</enemy>
|
||||||
|
</enemies>
|
||||||
|
</faction>
|
||||||
|
<faction name="Unknown4">
|
||||||
|
<player>0</player>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
<enemy>Unknown1</enemy>
|
||||||
|
</enemies>
|
||||||
|
</faction>
|
||||||
|
<faction name="Unknown1">
|
||||||
|
<player>-80</player>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Empire</enemy>
|
||||||
|
<enemy>Unknown3</enemy>
|
||||||
|
<enemy>Unknown4</enemy>
|
||||||
|
<enemy>Unknown5</enemy>
|
||||||
|
<enemy>Unknown6</enemy>
|
||||||
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Unknown2</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
</enemies>
|
||||||
|
</faction>
|
||||||
|
<faction name="Unknown5">
|
||||||
|
<player>0</player>
|
||||||
|
<enemies>
|
||||||
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
|
<enemy>Unknown1</enemy>
|
||||||
|
</enemies>
|
||||||
|
</faction>
|
||||||
|
<faction name="Unknown6">
|
||||||
|
<player>0</player>
|
||||||
|
<allies>
|
||||||
<ally>Empire</ally>
|
<ally>Empire</ally>
|
||||||
<ally>Merchant</ally>
|
<ally>Merchant</ally>
|
||||||
</alliance>
|
</allies>
|
||||||
</Alliances>
|
|
||||||
<Enemies>
|
|
||||||
<enemies>
|
<enemies>
|
||||||
<enemy type="faction">Collective</enemy>
|
<enemy>Unknown1</enemy>
|
||||||
<enemy type="alliance">Neutral</enemy>
|
<enemy>Pirate</enemy>
|
||||||
|
<enemy>Unknown2</enemy>
|
||||||
|
<enemy>Collective</enemy>
|
||||||
</enemies>
|
</enemies>
|
||||||
<enemies>
|
</faction>
|
||||||
<enemy type="faction">Collective</enemy>
|
|
||||||
<enemy type="alliance">Empire United</enemy>
|
|
||||||
</enemies>
|
|
||||||
<enemies>
|
|
||||||
<enemy type="alliance">Neutral</enemy>
|
|
||||||
<enemy type="faction">Pirate</enemy>
|
|
||||||
</enemies>
|
|
||||||
<enemies>
|
|
||||||
<enemy type="alliance">Empire United</enemy>
|
|
||||||
<enemy type="faction">Pirate</enemy>
|
|
||||||
</enemies>
|
|
||||||
</Enemies>
|
|
||||||
</Factions>
|
</Factions>
|
||||||
|
@ -13,8 +13,9 @@
|
|||||||
<avail>
|
<avail>
|
||||||
<chance>960</chance>
|
<chance>960</chance>
|
||||||
<location>Computer</location>
|
<location>Computer</location>
|
||||||
<alliance>Neutral</alliance>
|
<faction>Independent</faction>
|
||||||
<alliance>Empire United</alliance>
|
<faction>Empire</faction>
|
||||||
|
<faction>Unkown6</faction>
|
||||||
</avail>
|
</avail>
|
||||||
</mission>
|
</mission>
|
||||||
<mission name="Empire Recruitment">
|
<mission name="Empire Recruitment">
|
||||||
@ -25,8 +26,7 @@
|
|||||||
<avail>
|
<avail>
|
||||||
<chance>80</chance>
|
<chance>80</chance>
|
||||||
<location>Bar</location>
|
<location>Bar</location>
|
||||||
<alliance>Empire United</alliance>
|
<faction>Empire</faction>
|
||||||
<alliance>Neutral</alliance>
|
|
||||||
</avail>
|
</avail>
|
||||||
</mission>
|
</mission>
|
||||||
<mission name="Empire Shipping">
|
<mission name="Empire Shipping">
|
||||||
@ -35,8 +35,8 @@
|
|||||||
<cond>var.peek("es_cargo") == true</cond>
|
<cond>var.peek("es_cargo") == true</cond>
|
||||||
<chance>350</chance>
|
<chance>350</chance>
|
||||||
<location>Computer</location>
|
<location>Computer</location>
|
||||||
<alliance>Empire United</alliance>
|
<faction>Empire</faction>
|
||||||
<alliance>Neutral</alliance>
|
<faction>Unkown6</faction>
|
||||||
</avail>
|
</avail>
|
||||||
</mission>
|
</mission>
|
||||||
<mission name="Empire Scouting">
|
<mission name="Empire Scouting">
|
||||||
@ -48,7 +48,7 @@
|
|||||||
<req>es_cargo</req>
|
<req>es_cargo</req>
|
||||||
<chance>70</chance>
|
<chance>70</chance>
|
||||||
<location>Bar</location>
|
<location>Bar</location>
|
||||||
<alliance>Empire United</alliance>
|
<faction>Empire</faction>
|
||||||
</avail>
|
</avail>
|
||||||
</mission>
|
</mission>
|
||||||
</Missions>
|
</Missions>
|
||||||
|
277
src/faction.c
277
src/faction.c
@ -9,17 +9,11 @@
|
|||||||
|
|
||||||
#define XML_FACTION_ID "Factions" /* XML section id. */
|
#define XML_FACTION_ID "Factions" /* XML section id. */
|
||||||
#define XML_FACTION_TAG "faction"
|
#define XML_FACTION_TAG "faction"
|
||||||
#define XML_ALLIANCE_ID "Alliances"
|
|
||||||
#define XML_ALLIANCE_TAG "alliance"
|
|
||||||
#define XML_ENEMIES_ID "Enemies"
|
|
||||||
#define XML_ENEMIES_TAG "enemies"
|
|
||||||
|
|
||||||
#define FACTION_DATA "../dat/faction.xml"
|
#define FACTION_DATA "../dat/faction.xml"
|
||||||
|
|
||||||
#define PLAYER_ALLY 70 /* Above this, player is considered ally. */
|
#define PLAYER_ALLY 70 /* Above this, player is considered ally. */
|
||||||
|
|
||||||
#define ALLIANCE_OFFSET 27182 /* Special offset for alliances. */
|
|
||||||
|
|
||||||
typedef struct Faction_ {
|
typedef struct Faction_ {
|
||||||
char* name;
|
char* name;
|
||||||
|
|
||||||
@ -35,24 +29,12 @@ typedef struct Faction_ {
|
|||||||
} Faction;
|
} Faction;
|
||||||
|
|
||||||
static Faction* faction_stack = NULL;
|
static Faction* faction_stack = NULL;
|
||||||
static int nfactions = 0;
|
static int faction_nstack = 0;
|
||||||
|
|
||||||
/* Save alliance. */
|
|
||||||
typedef struct Alliance_ {
|
|
||||||
char* name;
|
|
||||||
int* factions;
|
|
||||||
int nfactions;
|
|
||||||
} Alliance;
|
|
||||||
|
|
||||||
/* Stack of alliances. */
|
|
||||||
static Alliance* alliances = NULL;
|
|
||||||
static int nalliances = 0;
|
|
||||||
|
|
||||||
/* Static. */
|
/* Static. */
|
||||||
|
static int faction_isFaction(int f);
|
||||||
static Faction* faction_parse(xmlNodePtr parent);
|
static Faction* faction_parse(xmlNodePtr parent);
|
||||||
static void alliance_parse(xmlNodePtr parent);
|
static void faction_parseSocial(xmlNodePtr parent);
|
||||||
static void enemies_parse(xmlNodePtr parent);
|
|
||||||
static Alliance* alliance_get(char* name);
|
|
||||||
/* Extern. */
|
/* Extern. */
|
||||||
int pfaction_save(xmlTextWriterPtr writer);
|
int pfaction_save(xmlTextWriterPtr writer);
|
||||||
int pfaction_load(xmlNodePtr parent);
|
int pfaction_load(xmlNodePtr parent);
|
||||||
@ -60,47 +42,23 @@ int pfaction_load(xmlNodePtr parent);
|
|||||||
/* Return the faction of name "name". */
|
/* Return the faction of name "name". */
|
||||||
int faction_get(const char* name) {
|
int faction_get(const char* name) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < nfactions; i++)
|
for(i = 0; i < faction_nstack; i++)
|
||||||
if(strcmp(faction_stack[i].name, name)==0)
|
if(strcmp(faction_stack[i].name, name)==0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if(i != nfactions)
|
if(i != faction_nstack)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
DEBUG("Faction '%s' not found in stack.", name);
|
DEBUG("Faction '%s' not found in stack.", name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the id of an alliance. */
|
/* Return the faction's name. */
|
||||||
int faction_getAlliance(char* name) {
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < nalliances; i++)
|
|
||||||
if(strcmp(alliances[i].name, name)==0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if(i != nalliances)
|
|
||||||
return ALLIANCE_OFFSET + i;
|
|
||||||
DEBUG("Alliance '%s' not found in stack.", name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* faction_name(int f) {
|
char* faction_name(int f) {
|
||||||
return faction_stack[f].name;
|
return faction_stack[f].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the alliance of name 'name'. */
|
/* Modify the player's standing with a faction. */
|
||||||
static Alliance* alliance_get(char* name) {
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < nalliances; i++)
|
|
||||||
if(strcmp(alliances[i].name, name)==0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if(i != nalliances)
|
|
||||||
return alliances+i;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void faction_modPlayer(int f, int mod) {
|
void faction_modPlayer(int f, int mod) {
|
||||||
if(faction_isFaction(f)) {
|
if(faction_isFaction(f)) {
|
||||||
faction_stack[f].player += mod;
|
faction_stack[f].player += mod;
|
||||||
@ -264,41 +222,9 @@ int areAllies(int a, int b) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is faction f part of alliance a? */
|
|
||||||
int faction_ofAlliance(int f, int a) {
|
|
||||||
int i;
|
|
||||||
Alliance* aa;
|
|
||||||
|
|
||||||
if(!faction_isFaction(f)) {
|
|
||||||
DEBUG("faction_ofAlliance: invalid alliance '%d'", f);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!faction_isAlliance(a)) {
|
|
||||||
DEBUG("faction_ofAlliance: invalid alliance '%d'", a);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
aa = &alliances[a-ALLIANCE_OFFSET];
|
|
||||||
|
|
||||||
for(i = 0; i < aa->nfactions; i++)
|
|
||||||
if(aa->factions[i] == f)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return true if a s an alliance. */
|
|
||||||
int faction_isAlliance(int a) {
|
|
||||||
if((a < ALLIANCE_OFFSET) || (a >= ALLIANCE_OFFSET + nalliances))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return true if f is a faction. */
|
/* Return true if f is a faction. */
|
||||||
int faction_isFaction(int f) {
|
static int faction_isFaction(int f) {
|
||||||
if((f < 0) || (f >= nfactions))
|
if((f < 0) || (f >= faction_nstack))
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -311,7 +237,7 @@ static Faction* faction_parse(xmlNodePtr parent) {
|
|||||||
|
|
||||||
tmp = CALLOC_L(Faction);
|
tmp = CALLOC_L(Faction);
|
||||||
|
|
||||||
tmp->name = (char*)xmlGetProp(parent, (xmlChar*)"name");
|
tmp->name = xml_nodeProp(parent, "name");
|
||||||
if(tmp->name == NULL)
|
if(tmp->name == NULL)
|
||||||
WARN("Faction from "FACTION_DATA" has invalid or no name");
|
WARN("Faction from "FACTION_DATA" has invalid or no name");
|
||||||
|
|
||||||
@ -329,143 +255,51 @@ static Faction* faction_parse(xmlNodePtr parent) {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We set allies/enemies here, in the faction_stack. */
|
static void faction_parseSocial(xmlNodePtr parent) {
|
||||||
static void alliance_parse(xmlNodePtr parent) {
|
|
||||||
Alliance* a;
|
|
||||||
int* i, j, n, m;
|
|
||||||
Faction* ft;
|
|
||||||
xmlNodePtr node, cur;
|
xmlNodePtr node, cur;
|
||||||
|
char* buf;
|
||||||
|
Faction* base;
|
||||||
|
int mod;
|
||||||
|
|
||||||
|
buf = xml_nodeProp(parent, "name");
|
||||||
|
base = &faction_stack[faction_get(buf)];
|
||||||
|
free(buf);
|
||||||
|
|
||||||
node = parent->xmlChildrenNode;
|
node = parent->xmlChildrenNode;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if((node->type == XML_NODE_START) && (strcmp((char*)node->name,
|
if(xml_isNode(node, "allies")) {
|
||||||
XML_ALLIANCE_TAG)==0)) {
|
|
||||||
/* Allocate a new alliance. */
|
|
||||||
alliances = realloc(alliances, sizeof(Alliance)*(++nalliances));
|
|
||||||
alliances[nalliances-1].name = (char*)xmlGetProp(node,(xmlChar*)"name");
|
|
||||||
alliances[nalliances-1].factions = NULL;
|
|
||||||
alliances[nalliances-1].nfactions = 0;
|
|
||||||
|
|
||||||
/* Parse the current alliance's allies. */
|
|
||||||
cur = node->xmlChildrenNode;
|
cur = node->xmlChildrenNode;
|
||||||
do {
|
do {
|
||||||
if(strcmp((char*)cur->name, "ally")==0) {
|
if(xml_isNode(cur, "ally")) {
|
||||||
/* Add the faction (and pointers to make things simple). */
|
mod = faction_get(xml_get(cur));
|
||||||
a = alliances + nalliances-1;
|
base->nallies++;
|
||||||
i = &a->nfactions;
|
base->allies = realloc(base->allies, sizeof(int)*base->nallies);
|
||||||
(*i)++;
|
base->allies[base->nallies-1] = mod;
|
||||||
|
|
||||||
/* Load the faction. */
|
|
||||||
a->factions = realloc(a->factions, (*i)*sizeof(int));
|
|
||||||
a->factions[(*i)-1] = faction_get((char*)cur->children->content);
|
|
||||||
|
|
||||||
if(a->factions[(*i)-1] == -1)
|
|
||||||
WARN("Faction '%s' in alliance '%s' does not exist in "FACTION_DATA,
|
|
||||||
(char*)cur->children->content, a->name);
|
|
||||||
}
|
}
|
||||||
} while((cur = cur->next));
|
} while(xml_nextNode(cur));
|
||||||
|
|
||||||
/* Set the crap needed by faction_stack. */
|
|
||||||
for(j = 0; j < (*i); j++) {
|
|
||||||
ft = &faction_stack[a->factions[j]];
|
|
||||||
ft->nallies += (*i)-1;
|
|
||||||
ft->allies = realloc(ft->allies, (ft->nallies)*sizeof(int));
|
|
||||||
for(n = 0, m = 0; n < (*i); n++, m++) {
|
|
||||||
/* Add as ally for all factions exept self. */
|
|
||||||
if(n == j) m--;
|
|
||||||
else if(n != j)
|
|
||||||
ft->allies[ft->nallies-(*i)+1+m] = a->factions[n];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while((node = node->next));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enemies_parse(xmlNodePtr parent) {
|
/* Grab the enemies. */
|
||||||
xmlNodePtr node, cur;
|
if(xml_isNode(node, "enemies")) {
|
||||||
int** f;
|
|
||||||
Faction* ft;
|
|
||||||
Alliance* a;
|
|
||||||
int i, *j, n, m, x, y, z, e;
|
|
||||||
char* type;
|
|
||||||
|
|
||||||
node = parent->xmlChildrenNode;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if((node->type == XML_NODE_START)
|
|
||||||
&& (strcmp((char*)node->name, XML_ENEMIES_TAG)==0)) {
|
|
||||||
i = 0;
|
|
||||||
f = NULL;
|
|
||||||
j = NULL;
|
|
||||||
|
|
||||||
cur = node->xmlChildrenNode;
|
cur = node->xmlChildrenNode;
|
||||||
do {
|
do {
|
||||||
if(strcmp((char*)cur->name,"enemy")==0) {
|
if(xml_isNode(cur, "enemy")) {
|
||||||
type = (char*)xmlGetProp(cur, (xmlChar*)"type");
|
mod = faction_get(xml_get(cur));
|
||||||
|
base->nenemies++;
|
||||||
i++;
|
base->enemies = realloc(base->enemies, sizeof(int)*base->nenemies);
|
||||||
j = realloc(j, sizeof(int)*i);
|
base->enemies[base->nenemies-1] = mod;
|
||||||
f = realloc(f, sizeof(int*)*i);
|
|
||||||
|
|
||||||
if(strcmp(type, "alliance")==0) {
|
|
||||||
/* Enemy thing is an alliance. */
|
|
||||||
a = alliance_get((char*)cur->children->content);
|
|
||||||
if(a == NULL)
|
|
||||||
WARN("Alliance %s not found in stack",
|
|
||||||
(char*)cur->children->content);
|
|
||||||
j[i-1] = a->nfactions;
|
|
||||||
f[i-1] = a->factions;
|
|
||||||
}
|
}
|
||||||
else if(strcmp(type,"faction")==0) {
|
} while(xml_nextNode(cur));
|
||||||
/* Enemy thing is only a faction. */
|
|
||||||
j[i-1] = 1;
|
|
||||||
f[i-1] = malloc(sizeof(int));
|
|
||||||
f[i-1][0] = faction_get((char*)cur->children->content);
|
|
||||||
if(f[i-1][0] == -1)
|
|
||||||
WARN("Faction %s not found in stack",
|
|
||||||
(char*)cur->children->content);
|
|
||||||
}
|
}
|
||||||
free(type);
|
} while(xml_nextNode(node));
|
||||||
}
|
}
|
||||||
} while((cur = cur->next));
|
|
||||||
/* Now actually parse and load up the enemies. */
|
|
||||||
for(n = 0; n < i; n++) { /* Unsinged int. */
|
|
||||||
for(m = 0; m < j[n]; m++) { /* Unsigned int. */
|
|
||||||
/* Faction. */
|
|
||||||
/* Add all the faction enemies to nenemies and alloc. */
|
|
||||||
for(e = 0, x = 0; x < i; x++)
|
|
||||||
if(x != n) e += j[x]; /* Store the total enemies. */
|
|
||||||
/* Now allocate the memory. */
|
|
||||||
ft = &faction_stack[f[n][m]];
|
|
||||||
ft->nenemies += e;
|
|
||||||
ft->enemies = realloc(ft->enemies, sizeof(int)*ft->nenemies);
|
|
||||||
|
|
||||||
/* Add the actualy enemies. */
|
|
||||||
for(x = 0, z = 0; x < i; x++)
|
|
||||||
if(x != n)
|
|
||||||
/* Make sure it's not from the same group. */
|
|
||||||
if(x != n)
|
|
||||||
for(y = 0; y < j[x]; y++, z++)
|
|
||||||
ft->enemies[ft->nenemies-e+z] = f[x][y];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Free al the temp memory. */
|
|
||||||
for(x = 0; x < i; x++)
|
|
||||||
if(j[x]==1) free(f[x]); /* Free the single malloced factions. */
|
|
||||||
free(f); /* Free the rest. */
|
|
||||||
free(j);
|
|
||||||
}
|
|
||||||
} while((node = node->next));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Load all the factions. */
|
/* Load all the factions. */
|
||||||
int factions_load(void) {
|
int factions_load(void) {
|
||||||
uint32_t bufsize;
|
uint32_t bufsize;
|
||||||
char* buf = pack_readfile(DATA, FACTION_DATA, &bufsize);
|
char* buf = pack_readfile(DATA, FACTION_DATA, &bufsize);
|
||||||
|
|
||||||
xmlNodePtr node;
|
xmlNodePtr factions, node;
|
||||||
xmlDocPtr doc = xmlParseMemory(buf, bufsize);
|
xmlDocPtr doc = xmlParseMemory(buf, bufsize);
|
||||||
|
|
||||||
Faction* tmp = NULL;
|
Faction* tmp = NULL;
|
||||||
@ -476,8 +310,8 @@ int factions_load(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = node->xmlChildrenNode; /* First faction node. */
|
factions = node->xmlChildrenNode; /* First faction node. */
|
||||||
if(node == NULL) {
|
if(factions == NULL) {
|
||||||
ERR("Malformed "FACTION_DATA" file: does not contain elements");
|
ERR("Malformed "FACTION_DATA" file: does not contain elements");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -487,50 +321,47 @@ int factions_load(void) {
|
|||||||
faction_stack[0].name = strdup("Player");
|
faction_stack[0].name = strdup("Player");
|
||||||
faction_stack[0].nallies = 0;
|
faction_stack[0].nallies = 0;
|
||||||
faction_stack[0].nenemies = 0;
|
faction_stack[0].nenemies = 0;
|
||||||
nfactions++;
|
faction_nstack++;
|
||||||
|
|
||||||
|
/* First pass. */
|
||||||
|
node = factions;
|
||||||
do {
|
do {
|
||||||
if(xml_isNode(node, XML_FACTION_TAG)) {
|
if(xml_isNode(node, XML_FACTION_TAG)) {
|
||||||
tmp = faction_parse(node);
|
tmp = faction_parse(node);
|
||||||
faction_stack = realloc(faction_stack, sizeof(Faction)*(++nfactions));
|
faction_stack = realloc(faction_stack, sizeof(Faction)*(++faction_nstack));
|
||||||
memcpy(faction_stack + nfactions - 1, tmp, sizeof(Faction));
|
memcpy(faction_stack + faction_nstack - 1, tmp, sizeof(Faction));
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
else if(xml_isNode(node, XML_ALLIANCE_ID))
|
} while(xml_nextNode(node));
|
||||||
alliance_parse(node);
|
|
||||||
else if(xml_isNode(node, XML_ENEMIES_ID))
|
/* Second pass - Set allies and enemies. */
|
||||||
enemies_parse(node);
|
node = factions;
|
||||||
} while((node = node->next));
|
do {
|
||||||
|
if (xml_isNode(node,XML_FACTION_TAG))
|
||||||
|
faction_parseSocial(node);
|
||||||
|
} while (xml_nextNode(node));
|
||||||
|
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
free(buf);
|
free(buf);
|
||||||
xmlCleanupParser();
|
xmlCleanupParser();
|
||||||
|
|
||||||
DEBUG("Loaded %d Faction%s", nfactions, (nfactions==1) ?"": "s");
|
DEBUG("Loaded %d Faction%s", faction_nstack, (faction_nstack==1) ?"": "s");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void factions_free(void) {
|
void factions_free(void) {
|
||||||
int i;
|
int i;
|
||||||
/* Free alliances. */
|
|
||||||
for(i = 0; i < nalliances; i++) {
|
|
||||||
free(alliances[i].name);
|
|
||||||
free(alliances[i].factions);
|
|
||||||
}
|
|
||||||
free(alliances);
|
|
||||||
alliances = NULL;
|
|
||||||
nalliances = 0;
|
|
||||||
|
|
||||||
/* Free factions. */
|
/* Free factions. */
|
||||||
for(i = 0; i < nfactions; i++) {
|
for(i = 0; i < faction_nstack; i++) {
|
||||||
free(faction_stack[i].name);
|
free(faction_stack[i].name);
|
||||||
if(faction_stack[i].nallies > 0) free(faction_stack[i].allies);
|
if(faction_stack[i].nallies > 0) free(faction_stack[i].allies);
|
||||||
if(faction_stack[i].nenemies > 0) free(faction_stack[i].enemies);
|
if(faction_stack[i].nenemies > 0) free(faction_stack[i].enemies);
|
||||||
}
|
}
|
||||||
free(faction_stack);
|
free(faction_stack);
|
||||||
faction_stack = NULL;
|
faction_stack = NULL;
|
||||||
nfactions = 0;
|
faction_nstack = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pfaction_save(xmlTextWriterPtr writer) {
|
int pfaction_save(xmlTextWriterPtr writer) {
|
||||||
@ -539,7 +370,7 @@ int pfaction_save(xmlTextWriterPtr writer) {
|
|||||||
xmlw_startElem(writer, "factions");
|
xmlw_startElem(writer, "factions");
|
||||||
|
|
||||||
/* Player is faction 0. */
|
/* Player is faction 0. */
|
||||||
for(i = 1; i < nfactions; i++) {
|
for(i = 1; i < faction_nstack; i++) {
|
||||||
xmlw_startElem(writer, "faction");
|
xmlw_startElem(writer, "faction");
|
||||||
|
|
||||||
xmlw_attr(writer, "name", "%s", faction_stack[i].name);
|
xmlw_attr(writer, "name", "%s", faction_stack[i].name);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
/* Get stuff. */
|
/* Get stuff. */
|
||||||
int faction_get(const char* name);
|
int faction_get(const char* name);
|
||||||
int faction_getAlliance(char* name);
|
|
||||||
char* faction_name(int f);
|
char* faction_name(int f);
|
||||||
|
|
||||||
/* Player stuff. */
|
/* Player stuff. */
|
||||||
@ -16,13 +15,6 @@ char* faction_getStanding(int mod);
|
|||||||
int areEnemies(int a, int b);
|
int areEnemies(int a, int b);
|
||||||
int areAllies(int a, int b);
|
int areAllies(int a, int b);
|
||||||
|
|
||||||
/* Faction + Alliance. */
|
|
||||||
int faction_ofAlliance(int f, int a);
|
|
||||||
|
|
||||||
/* Check. */
|
|
||||||
int faction_isAlliance(int a);
|
|
||||||
int faction_isFaction(int f);
|
|
||||||
|
|
||||||
/* Load/Free. */
|
/* Load/Free. */
|
||||||
int factions_load(void);
|
int factions_load(void);
|
||||||
void factions_free(void);
|
void factions_free(void);
|
||||||
|
@ -342,13 +342,9 @@ static void mission_freeData(MissionData* mission) {
|
|||||||
static int mission_matchFaction(MissionData* misn, int faction) {
|
static int mission_matchFaction(MissionData* misn, int faction) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < misn->avail.nfactions; i++) {
|
for(i = 0; i < misn->avail.nfactions; i++)
|
||||||
if(faction_isFaction(misn->avail.factions[i]) &&
|
if(faction == misn->avail.factions[i])
|
||||||
(faction == misn->avail.factions[i]))
|
|
||||||
return 1;
|
return 1;
|
||||||
else if(faction_ofAlliance(faction, misn->avail.factions[i]))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,12 +432,6 @@ static MissionData* mission_parse(const xmlNodePtr parent) {
|
|||||||
tmp->avail.planet = strdup(xml_get(cur));
|
tmp->avail.planet = strdup(xml_get(cur));
|
||||||
else if(xml_isNode(cur, "system"))
|
else if(xml_isNode(cur, "system"))
|
||||||
tmp->avail.system = strdup(xml_get(cur));
|
tmp->avail.system = strdup(xml_get(cur));
|
||||||
else if(xml_isNode(cur, "alliance")) {
|
|
||||||
tmp->avail.factions = realloc(tmp->avail.factions,
|
|
||||||
sizeof(int) * ++tmp->avail.nfactions);
|
|
||||||
tmp->avail.factions[tmp->avail.nfactions-1] =
|
|
||||||
faction_getAlliance(xml_get(cur));
|
|
||||||
}
|
|
||||||
else if(xml_isNode(cur, "faction")) {
|
else if(xml_isNode(cur, "faction")) {
|
||||||
tmp->avail.factions = realloc(tmp->avail.factions,
|
tmp->avail.factions = realloc(tmp->avail.factions,
|
||||||
sizeof(int) * ++tmp->avail.nfactions);
|
sizeof(int) * ++tmp->avail.nfactions);
|
||||||
|
@ -227,10 +227,7 @@ char** space_getFactionPlanet(int* nplanets, int* factions, int nfactions) {
|
|||||||
for(j = 0; j < systems_stack[i].nplanets; j++) {
|
for(j = 0; j < systems_stack[i].nplanets; j++) {
|
||||||
planet = &systems_stack[i].planets[j];
|
planet = &systems_stack[i].planets[j];
|
||||||
for(k = 0; k < nfactions; k++)
|
for(k = 0; k < nfactions; k++)
|
||||||
if((faction_isFaction(factions[k]) &&
|
if(planet->faction == factions[k]) {
|
||||||
(planet->faction == factions[k])) ||
|
|
||||||
(faction_isAlliance(factions[k]) &&
|
|
||||||
faction_ofAlliance(planet->faction, factions[k]))) {
|
|
||||||
ntmp++;
|
ntmp++;
|
||||||
if(ntmp > mtmp) {
|
if(ntmp > mtmp) {
|
||||||
mtmp += 25;
|
mtmp += 25;
|
||||||
|
Loading…
Reference in New Issue
Block a user