[Change] faction_modPlayer() now affects allies and enemies.

[Remove] Alliance references.
This commit is contained in:
Allanis 2013-08-09 18:11:43 +01:00
parent c792e75240
commit c58223606b

View File

@ -5,6 +5,7 @@
#include "log.h" #include "log.h"
#include "pack.h" #include "pack.h"
#include "xml.h" #include "xml.h"
#include "rng.h"
#include "faction.h" #include "faction.h"
#define XML_FACTION_ID "Factions" /* XML section id. */ #define XML_FACTION_ID "Factions" /* XML section id. */
@ -34,6 +35,7 @@ static int faction_nstack = 0;
/* Static. */ /* Static. */
static int faction_isFaction(int f); static int faction_isFaction(int f);
static void faction_sanitizePlayer(Faction* faction);
static Faction* faction_parse(xmlNodePtr parent); static Faction* faction_parse(xmlNodePtr parent);
static void faction_parseSocial(xmlNodePtr parent); static void faction_parseSocial(xmlNodePtr parent);
/* Extern. */ /* Extern. */
@ -66,27 +68,54 @@ char* faction_longname(int f) {
return faction_stack[f].name; return faction_stack[f].name;
} }
/* Sanitize player faction standing. */
static void faction_sanitizePlayer(Faction* faction) {
if(faction->player > 100)
faction->player = 100;
else if(faction->player < -100)
faction->player = -100;
}
/* Modify the player's standing with a faction. */ /* Modify the player's standing with a faction. */
void faction_modPlayer(int f, int mod) { void faction_modPlayer(int f, int mod) {
if(faction_isFaction(f)) { int i;
faction_stack[f].player += mod; Faction* faction, *ally, *enemy;
if(faction_isFaction(f)) {
faction = &faction_stack[f];
/* Faction in question gets direct increment. */
faction->player += mod;
faction_sanitizePlayer(faction);
/* Now mod allies to a lesser degree. */
for(i = 0; i < faction->nallies; i++) {
ally = &faction_stack[faction->allies[i]];
ally->player += RNG(0, mod/2);
faction_sanitizePlayer(ally);
}
/* Now mod enemies. */
for(i = 0; i < faction->nenemies; i++) {
enemy = &faction_stack[faction->enemies[i]];
enemy->player -= RNG(0, mod/2);
faction_sanitizePlayer(enemy);
}
/* Sanitize. */
if(faction_stack[f].player > 100)
faction_stack[f].player = 100;
else if(faction_stack[f].player < -100)
faction_stack[f].player = -100;
} else { } else {
DEBUG("%d is an invalid faction/alliance", f); DEBUG("%d is an invalid faction.", f);
return; return;
} }
} }
/* Get the player's standing with a faction. */
int faction_getPlayer(int f) { int faction_getPlayer(int f) {
if(faction_isFaction(f)) { if(faction_isFaction(f)) {
return faction_stack[f].player; return faction_stack[f].player;
} else { } else {
DEBUG("%d is an invalid faction/alliance", f); DEBUG("%d is an invalid faction.", f);
return -1000; return -1000;
} }
} }
@ -133,7 +162,7 @@ int areEnemies(int a, int b) {
return 1; return 1;
else return 0; else return 0;
} else { } else {
DEBUG("areEnemies: %d is an invalid faction/alliance", b); DEBUG("areEnemies: %d is an invalid faction.", b);
return 0; return 0;
} }
} }
@ -143,7 +172,7 @@ int areEnemies(int a, int b) {
return 1; return 1;
else return 0; else return 0;
} else { } else {
DEBUG("areEnemies: %d is an invalid faction/alliance", a); DEBUG("areEnemies: %d is an invalid faction.", a);
return 0; return 0;
} }
} }
@ -152,7 +181,7 @@ int areEnemies(int a, int b) {
if(faction_isFaction(a)) fa = &faction_stack[a]; if(faction_isFaction(a)) fa = &faction_stack[a];
else { else {
/* a isn't valid. */ /* a isn't valid. */
DEBUG("areEnemies: %d is an invalid faction/alliance", a); DEBUG("areEnemies: %d is an invalid faction.", a);
return 0; return 0;
} }
@ -160,7 +189,7 @@ int areEnemies(int a, int b) {
if(faction_isFaction(b)) fb = &faction_stack[b]; if(faction_isFaction(b)) fb = &faction_stack[b];
else { else {
/* b isn't valid. */ /* b isn't valid. */
DEBUG("areEnemies: %d is an invalid faction/alliance", b); DEBUG("areEnemies: %d is an invalid faction.", b);
return 0; return 0;
} }
@ -187,7 +216,7 @@ int areAllies(int a, int b) {
if(faction_stack[b].player > PLAYER_ALLY) return 1; if(faction_stack[b].player > PLAYER_ALLY) return 1;
else return 0; else return 0;
} else { } else {
DEBUG("%d is an invalid faction/alliance", b); DEBUG("%d is an invalid faction.", b);
return 0; return 0;
} }
} }
@ -196,7 +225,7 @@ int areAllies(int a, int b) {
if(faction_stack[a].player > PLAYER_ALLY) return 1; if(faction_stack[a].player > PLAYER_ALLY) return 1;
else return 0; else return 0;
} else { } else {
DEBUG("%d is an invalid faction/alliance", a); DEBUG("%d is an invalid faction.", a);
return 0; return 0;
} }
} }
@ -209,7 +238,7 @@ int areAllies(int a, int b) {
if(faction_isFaction(a)) fa = &faction_stack[a]; if(faction_isFaction(a)) fa = &faction_stack[a];
else { else {
/* b isn't valid. */ /* b isn't valid. */
DEBUG("%d is an invalid faction/alliance", a); DEBUG("%d is an invalid faction.", a);
return 0; return 0;
} }
@ -217,7 +246,7 @@ int areAllies(int a, int b) {
if(faction_isFaction(b)) fb = &faction_stack[b]; if(faction_isFaction(b)) fb = &faction_stack[b];
else { else {
/* b isn't valid. */ /* b isn't valid. */
DEBUG("%d is an invalid faction/alliance", b); DEBUG("%d is an invalid faction.", b);
return 0; return 0;
} }
@ -271,6 +300,7 @@ static Faction* faction_parse(xmlNodePtr parent) {
return tmp; return tmp;
} }
/* Parse the social tidbits: Allies and enemies. */
static void faction_parseSocial(xmlNodePtr parent) { static void faction_parseSocial(xmlNodePtr parent) {
xmlNodePtr node, cur; xmlNodePtr node, cur;
char* buf; char* buf;