[Change] faction_modPlayer() now affects allies and enemies.
[Remove] Alliance references.
This commit is contained in:
		
							parent
							
								
									c792e75240
								
							
						
					
					
						commit
						c58223606b
					
				| @ -5,6 +5,7 @@ | ||||
| #include "log.h" | ||||
| #include "pack.h" | ||||
| #include "xml.h" | ||||
| #include "rng.h" | ||||
| #include "faction.h" | ||||
| 
 | ||||
| #define XML_FACTION_ID    "Factions" /* XML section id. */ | ||||
| @ -34,6 +35,7 @@ static int faction_nstack = 0; | ||||
| 
 | ||||
| /* Static. */ | ||||
| static int faction_isFaction(int f); | ||||
| static void faction_sanitizePlayer(Faction* faction); | ||||
| static Faction* faction_parse(xmlNodePtr parent); | ||||
| static void faction_parseSocial(xmlNodePtr parent); | ||||
| /* Extern. */ | ||||
| @ -66,27 +68,54 @@ char* faction_longname(int f) { | ||||
|   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. */ | ||||
| void faction_modPlayer(int f, int mod) { | ||||
|   if(faction_isFaction(f)) { | ||||
|     faction_stack[f].player += mod; | ||||
|   int i; | ||||
|   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 { | ||||
|     DEBUG("%d is an invalid faction/alliance", f); | ||||
|     DEBUG("%d is an invalid faction.", f); | ||||
|     return; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /* Get the player's standing with a faction. */ | ||||
| int faction_getPlayer(int f) { | ||||
|   if(faction_isFaction(f)) { | ||||
|     return faction_stack[f].player; | ||||
|   } else { | ||||
|     DEBUG("%d is an invalid faction/alliance", f); | ||||
|     DEBUG("%d is an invalid faction.", f); | ||||
|     return -1000; | ||||
|   } | ||||
| } | ||||
| @ -133,7 +162,7 @@ int areEnemies(int a, int b) { | ||||
|         return 1; | ||||
|       else return 0; | ||||
|     } else { | ||||
|       DEBUG("areEnemies: %d is an invalid faction/alliance", b); | ||||
|       DEBUG("areEnemies: %d is an invalid faction.", b); | ||||
|       return 0; | ||||
|     } | ||||
|   } | ||||
| @ -143,7 +172,7 @@ int areEnemies(int a, int b) { | ||||
|         return 1; | ||||
|       else return 0; | ||||
|     } else { | ||||
|       DEBUG("areEnemies: %d is an invalid faction/alliance", a); | ||||
|       DEBUG("areEnemies: %d is an invalid faction.", a); | ||||
|       return 0; | ||||
|     } | ||||
|   } | ||||
| @ -152,7 +181,7 @@ int areEnemies(int a, int b) { | ||||
|   if(faction_isFaction(a)) fa = &faction_stack[a]; | ||||
|   else { | ||||
|     /* a isn't valid. */ | ||||
|     DEBUG("areEnemies: %d is an invalid faction/alliance", a); | ||||
|     DEBUG("areEnemies: %d is an invalid faction.", a); | ||||
|     return 0; | ||||
|   } | ||||
| 
 | ||||
| @ -160,7 +189,7 @@ int areEnemies(int a, int b) { | ||||
|   if(faction_isFaction(b)) fb = &faction_stack[b]; | ||||
|   else { | ||||
|     /* b isn't valid. */ | ||||
|     DEBUG("areEnemies: %d is an invalid faction/alliance", b); | ||||
|     DEBUG("areEnemies: %d is an invalid faction.", b); | ||||
|     return 0; | ||||
|   } | ||||
| 
 | ||||
| @ -187,7 +216,7 @@ int areAllies(int a, int b) { | ||||
|       if(faction_stack[b].player > PLAYER_ALLY) return 1; | ||||
|       else return 0; | ||||
|     } else { | ||||
|       DEBUG("%d is an invalid faction/alliance", b); | ||||
|       DEBUG("%d is an invalid faction.", b); | ||||
|       return 0; | ||||
|     } | ||||
|   } | ||||
| @ -196,7 +225,7 @@ int areAllies(int a, int b) { | ||||
|       if(faction_stack[a].player > PLAYER_ALLY) return 1; | ||||
|       else return 0; | ||||
|     } else { | ||||
|       DEBUG("%d is an invalid faction/alliance", a); | ||||
|       DEBUG("%d is an invalid faction.", a); | ||||
|       return 0; | ||||
|     } | ||||
|   } | ||||
| @ -209,7 +238,7 @@ int areAllies(int a, int b) { | ||||
|   if(faction_isFaction(a)) fa = &faction_stack[a]; | ||||
|   else { | ||||
|     /* b isn't valid. */ | ||||
|     DEBUG("%d is an invalid faction/alliance", a); | ||||
|     DEBUG("%d is an invalid faction.", a); | ||||
|     return 0; | ||||
|   } | ||||
| 
 | ||||
| @ -217,7 +246,7 @@ int areAllies(int a, int b) { | ||||
|   if(faction_isFaction(b)) fb = &faction_stack[b]; | ||||
|   else { | ||||
|     /* b isn't valid. */ | ||||
|     DEBUG("%d is an invalid faction/alliance", b); | ||||
|     DEBUG("%d is an invalid faction.", b); | ||||
|     return 0; | ||||
|   } | ||||
| 
 | ||||
| @ -271,6 +300,7 @@ static Faction* faction_parse(xmlNodePtr parent) { | ||||
|   return tmp; | ||||
| } | ||||
| 
 | ||||
| /* Parse the social tidbits: Allies and enemies. */ | ||||
| static void faction_parseSocial(xmlNodePtr parent) { | ||||
|   xmlNodePtr node, cur; | ||||
|   char* buf; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Allanis
						Allanis