naev 0.11.5
faction.c File Reference

Handles the Naev factions. More...

#include "faction.h"
#include "conf.h"
#include "array.h"
#include "colour.h"
#include "hook.h"
#include "log.h"
#include "ndata.h"
#include "nlua.h"
#include "nluadef.h"
#include "nxml.h"
#include "nstring.h"
#include "player.h"
#include "opengl.h"
#include "rng.h"
#include "space.h"

Go to the source code of this file.

Data Structures

struct  Faction
 Description of a lane-building faction. More...
 

Macros

#define XML_FACTION_ID   "Factions"
 
#define XML_FACTION_TAG   "faction"
 
#define FACTION_STATIC   (1<<0)
 
#define FACTION_INVISIBLE   (1<<1)
 
#define FACTION_KNOWN   (1<<2)
 
#define FACTION_DYNAMIC   (1<<3)
 
#define FACTION_USESHIDDENJUMPS   (1<<4)
 
#define faction_setFlag(fa, f)
 
#define faction_rmFlag(fa, f)
 
#define faction_isFlag(fa, f)
 
#define faction_isKnown_(fa)
 

Functions

static int faction_getRaw (const char *name)
 Gets a faction ID by name.
 
static void faction_freeOne (Faction *f)
 Frees a single faction.
 
static void faction_sanitizePlayer (Faction *faction)
 Sanitizes player faction standing.
 
static void faction_modPlayerLua (int f, double mod, const char *source, int secondary)
 Mods player using the power of Lua.
 
static int faction_parse (Faction *temp, const char *file)
 Parses a single faction, but doesn't set the allies/enemies bit.
 
static int faction_parseSocial (const char *file)
 Parses the social tidbits of a faction: allies and enemies.
 
static void faction_addStandingScript (Faction *temp, const char *scriptname)
 Sets up a standing script for a faction.
 
static void faction_computeGrid (void)
 Computes the faction relationship grid.
 
int pfaction_save (xmlTextWriterPtr writer)
 Saves player's standings with the factions.
 
int pfaction_load (xmlNodePtr parent)
 Loads the player's faction standings.
 
static int faction_cmp (const void *p1, const void *p2)
 
int faction_exists (const char *name)
 Checks to see if a faction exists by name.
 
int faction_get (const char *name)
 Gets a faction ID by name.
 
int * faction_getAll (void)
 Returns all faction IDs in an array (array.h).
 
int * faction_getAllVisible (void)
 Returns all non-invisible faction IDs in an array (array.h).
 
int * faction_getKnown ()
 Gets all the known factions in an array (array.h).
 
void faction_clearKnown ()
 Clears the known factions.
 
int faction_isStatic (int id)
 Is the faction static?
 
int faction_isInvisible (int id)
 Is the faction invisible?
 
int faction_setInvisible (int id, int state)
 Sets the faction's invisible state.
 
int faction_isKnown (int id)
 Is the faction known?
 
int faction_isDynamic (int id)
 Is faction dynamic.
 
int faction_setKnown (int id, int state)
 Sets the factions known state.
 
const char * faction_name (int f)
 Gets a factions "real" (internal) name.
 
const char * faction_shortname (int f)
 Gets a factions short name (human-readable).
 
const char * faction_longname (int f)
 Gets the faction's long name (formal, human-readable).
 
const char * faction_mapname (int f)
 Gets the faction's map name (translated).
 
const char * faction_description (int f)
 Gets the faction's description (translated).
 
const char * faction_default_ai (int f)
 Gets the name of the default AI profile for the faction's pilots.
 
const char ** faction_tags (int f)
 Gets the tags the faction has.
 
double faction_lane_length_per_presence (int f)
 Gets the faction's weight for patrolled safe-lane construction (0 means they don't build lanes).
 
double faction_lane_base_cost (int f)
 Gets the faction's weight for patrolled safe-lane construction;.
 
const glTexturefaction_logo (int f)
 Gets the faction's logo (ideally 256x256).
 
const glColour * faction_colour (int f)
 Gets the colour of the faction.
 
const int * faction_getEnemies (int f)
 Gets the list of enemies of a faction.
 
const int * faction_getAllies (int f)
 Gets the list of allies of a faction.
 
void faction_clearEnemy (int f)
 Clears all the enemies of a dynamic faction.
 
void faction_addEnemy (int f, int o)
 Adds an enemy to the faction's enemies list.
 
void faction_rmEnemy (int f, int o)
 Removes an enemy from the faction's enemies list.
 
void faction_clearAlly (int f)
 Clears all the ally of a dynamic faction.
 
void faction_addAlly (int f, int o)
 Adds an ally to the faction's allies list.
 
void faction_rmAlly (int f, int o)
 Removes an ally from the faction's allies list.
 
nlua_env faction_getScheduler (int f)
 Gets the state associated to the faction scheduler.
 
nlua_env faction_getEquipper (int f)
 Gets the equipper state associated to the faction scheduler.
 
void faction_modPlayer (int f, double mod, const char *source)
 Modifies the player's standing with a faction.
 
void faction_modPlayerSingle (int f, double mod, const char *source)
 Modifies the player's standing without affecting others.
 
void faction_modPlayerRaw (int f, double mod)
 Modifies the player's standing without affecting others.
 
void faction_setPlayer (int f, double value)
 Sets the player's standing with a faction.
 
double faction_getPlayer (int f)
 Gets the player's standing with a faction.
 
double faction_getPlayerDef (int f)
 Gets the player's default standing with a faction.
 
int faction_isPlayerFriend (int f)
 Gets whether or not the player is a friend of the faction.
 
int faction_isPlayerEnemy (int f)
 Gets whether or not the player is an enemy of the faction.
 
const glColour * faction_getColour (int f)
 Gets the colour of the faction based on it's standing with the player.
 
char faction_getColourChar (int f)
 Gets the faction character associated to its standing with the player.
 
const char * faction_getStandingText (int f)
 Gets the player's standing in human readable form.
 
const char * faction_getStandingTextAtValue (int f, double value)
 Gets the player's standing in human readable form.
 
const char * faction_getStandingBroad (int f, int bribed, int override)
 Gets the broad faction standing.
 
double faction_reputationMax (int f)
 Gets the maximum reputation of a faction.
 
int areEnemies (int a, int b)
 Checks whether two factions are enemies.
 
int areAllies (int a, int b)
 Checks whether two factions are allies or not.
 
int faction_isFaction (int f)
 Checks whether or not a faction is valid.
 
void factions_reset (void)
 Resets player standing and flags of factions to default.
 
int factions_load (void)
 Loads up all the factions from the data file.
 
void factions_free (void)
 Frees the factions.
 
int * faction_getGroup (int which)
 Returns an array of faction ids.
 
int faction_usesHiddenJumps (int f)
 Checks to see if a faction uses hidden jumps.
 
const FactionGeneratorfaction_generators (int f)
 Gets the faction's generators.
 
void factions_clearDynamic (void)
 Clears dynamic factions.
 
int faction_dynAdd (int base, const char *name, const char *display, const char *ai, const glColour *colour)
 Dynamically add a faction.
 

Variables

int faction_player
 
static Factionfaction_stack = NULL
 
static int * faction_grid = NULL
 
static size_t faction_mgrid = 0
 

Detailed Description

Handles the Naev factions.

Definition in file faction.c.

Macro Definition Documentation

◆ FACTION_DYNAMIC

#define FACTION_DYNAMIC   (1<<3)

Faction was created dynamically.

Definition at line 39 of file faction.c.

◆ FACTION_INVISIBLE

#define FACTION_INVISIBLE   (1<<1)

Faction isn't exposed to the player.

Definition at line 37 of file faction.c.

◆ faction_isFlag

#define faction_isFlag ( fa,
f )
Value:
((fa)->flags & (f))

Definition at line 44 of file faction.c.

◆ faction_isKnown_

#define faction_isKnown_ ( fa)
Value:
((fa)->flags & (FACTION_KNOWN))
#define FACTION_KNOWN
Definition faction.c:38

Definition at line 45 of file faction.c.

◆ FACTION_KNOWN

#define FACTION_KNOWN   (1<<2)

Faction is known to the player.

Definition at line 38 of file faction.c.

◆ faction_rmFlag

#define faction_rmFlag ( fa,
f )
Value:
((fa)->flags &= ~(f))

Definition at line 43 of file faction.c.

◆ faction_setFlag

#define faction_setFlag ( fa,
f )
Value:
((fa)->flags |= (f))

Definition at line 42 of file faction.c.

◆ FACTION_STATIC

#define FACTION_STATIC   (1<<0)

Faction doesn't change standing with player.

Definition at line 36 of file faction.c.

◆ FACTION_USESHIDDENJUMPS

#define FACTION_USESHIDDENJUMPS   (1<<4)

Faction will try to use hidden jumps when possible.

Definition at line 40 of file faction.c.

◆ XML_FACTION_ID

#define XML_FACTION_ID   "Factions"

XML section identifier

Definition at line 33 of file faction.c.

◆ XML_FACTION_TAG

#define XML_FACTION_TAG   "faction"

XML tag identifier.

Definition at line 34 of file faction.c.

Function Documentation

◆ areAllies()

int areAllies ( int a,
int b )

Checks whether two factions are allies or not.

Parameters
aFaction A.
bFaction B.
Returns
1 if A and B are allies, 0 otherwise.

Definition at line 1253 of file faction.c.

◆ areEnemies()

int areEnemies ( int a,
int b )

Checks whether two factions are enemies.

Parameters
aFaction A.
bFaction B.
Returns
1 if A and B are enemies, 0 otherwise.

Definition at line 1227 of file faction.c.

◆ faction_addAlly()

void faction_addAlly ( int f,
int o )

Adds an ally to the faction's allies list.

Parameters
fThe faction to add an ally to.
oThe other faction to make an ally.

Definition at line 657 of file faction.c.

◆ faction_addEnemy()

void faction_addEnemy ( int f,
int o )

Adds an enemy to the faction's enemies list.

Parameters
fThe faction to add an enemy to.
oThe other faction to make an enemy.

Definition at line 564 of file faction.c.

◆ faction_addStandingScript()

static void faction_addStandingScript ( Faction * temp,
const char * scriptname )
static

Sets up a standing script for a faction.

Parameters
tempFaction to associate the script to.
scriptnameName of the lua script to use (e.g., "static").

Definition at line 1431 of file faction.c.

◆ faction_clearAlly()

void faction_clearAlly ( int f)

Clears all the ally of a dynamic faction.

Parameters
fFaction to clear ally of.

Definition at line 637 of file faction.c.

◆ faction_clearEnemy()

void faction_clearEnemy ( int f)

Clears all the enemies of a dynamic faction.

Parameters
fFaction to clear enemies of.

Definition at line 544 of file faction.c.

◆ faction_clearKnown()

void faction_clearKnown ( void )

Clears the known factions.

Definition at line 232 of file faction.c.

◆ faction_cmp()

static int faction_cmp ( const void * p1,
const void * p2 )
static

Definition at line 125 of file faction.c.

◆ faction_colour()

const glColour * faction_colour ( int f)

Gets the colour of the faction.

Parameters
fFaction to get the colour of.
Returns
The faction's colour

Definition at line 469 of file faction.c.

◆ faction_computeGrid()

static void faction_computeGrid ( void )
static

Computes the faction relationship grid.

Definition at line 1967 of file faction.c.

◆ faction_default_ai()

const char * faction_default_ai ( int f)

Gets the name of the default AI profile for the faction's pilots.

Parameters
fFaction ID.
Returns
The faction's AI profile name.

Definition at line 399 of file faction.c.

◆ faction_description()

const char * faction_description ( int f)

Gets the faction's description (translated).

Parameters
fFaction to get the name of.
Returns
The faction's description (in User's language).

Definition at line 382 of file faction.c.

◆ faction_dynAdd()

int faction_dynAdd ( int base,
const char * name,
const char * display,
const char * ai,
const glColour * colour )

Dynamically add a faction.

Parameters
baseFaction to base it off (negative for none).
nameName of the faction to set.
displayDisplay name to use.
aiDefault pilot AI to use (if NULL, inherit from base).
colourDefault colour to use (if NULL, inherit from base).

Definition at line 1915 of file faction.c.

◆ faction_exists()

int faction_exists ( const char * name)

Checks to see if a faction exists by name.

Parameters
nameName of the faction to seek.
Returns
ID of the faction.

Definition at line 173 of file faction.c.

◆ faction_freeOne()

static void faction_freeOne ( Faction * f)
static

Frees a single faction.

Definition at line 1716 of file faction.c.

◆ faction_generators()

const FactionGenerator * faction_generators ( int f)

Gets the faction's generators.

Definition at line 1883 of file faction.c.

◆ faction_get()

int faction_get ( const char * name)

Gets a faction ID by name.

Parameters
nameName of the faction to seek.
Returns
ID of the faction.

Definition at line 184 of file faction.c.

◆ faction_getAll()

int * faction_getAll ( void )

Returns all faction IDs in an array (array.h).

Definition at line 195 of file faction.c.

◆ faction_getAllies()

const int * faction_getAllies ( int f)

Gets the list of allies of a faction.

Parameters
fFaction to get allies of.
Returns
Array (array.h): The allies of the faction.

Definition at line 515 of file faction.c.

◆ faction_getAllVisible()

int * faction_getAllVisible ( void )

Returns all non-invisible faction IDs in an array (array.h).

Definition at line 207 of file faction.c.

◆ faction_getColour()

const glColour * faction_getColour ( int f)

Gets the colour of the faction based on it's standing with the player.

Used to unify the colour checks all over.

Parameters
fFaction to get the colour of based on player's standing.
Returns
Pointer to the colour.

Definition at line 1035 of file faction.c.

◆ faction_getColourChar()

char faction_getColourChar ( int f)

Gets the faction character associated to its standing with the player.

Use this to do something like "#%c", faction_getColourChar( some_faction ) in the font print routines.

Parameters
fFaction to get the colour of based on player's standing.
Returns
The character associated to the faction.

Definition at line 1052 of file faction.c.

◆ faction_getEnemies()

const int * faction_getEnemies ( int f)

Gets the list of enemies of a faction.

Parameters
fFaction to get enemies of.
Returns
Array (array.h): The enemies of the faction.

Definition at line 485 of file faction.c.

◆ faction_getEquipper()

nlua_env faction_getEquipper ( int f)

Gets the equipper state associated to the faction scheduler.

Definition at line 740 of file faction.c.

◆ faction_getGroup()

int * faction_getGroup ( int which)

Returns an array of faction ids.

Parameters
whichWhich factions to get. (0,1,2,3 : all, friendly, neutral, hostile)
Returns
Array (array.h): The faction IDs of the specified alignment.

Definition at line 1836 of file faction.c.

◆ faction_getKnown()

int * faction_getKnown ( )

Gets all the known factions in an array (array.h).

Definition at line 219 of file faction.c.

◆ faction_getPlayer()

double faction_getPlayer ( int f)

Gets the player's standing with a faction.

Parameters
fFaction to get player's standing from.
Returns
The standing the player has with the faction.

Definition at line 981 of file faction.c.

◆ faction_getPlayerDef()

double faction_getPlayerDef ( int f)

Gets the player's default standing with a faction.

Parameters
fFaction to get player's default standing from.
Returns
The default standing the player has with the faction.

Definition at line 995 of file faction.c.

◆ faction_getRaw()

static int faction_getRaw ( const char * name)
static

Gets a faction ID by name.

Parameters
nameName of the faction to seek.
Returns
ID of the faction.

Definition at line 139 of file faction.c.

◆ faction_getScheduler()

nlua_env faction_getScheduler ( int f)

Gets the state associated to the faction scheduler.

Definition at line 728 of file faction.c.

◆ faction_getStandingBroad()

const char * faction_getStandingBroad ( int f,
int bribed,
int override )

Gets the broad faction standing.

Parameters
fFaction to get broad standing of.
bribedWhether or not the respective pilot is bribed.
overrideIf positive sets to ally, if negative sets to hostile.
Returns
Human readable broad player's standing.

Definition at line 1129 of file faction.c.

◆ faction_getStandingText()

const char * faction_getStandingText ( int f)

Gets the player's standing in human readable form.

Parameters
fFaction to get standing of.
Returns
Human readable player's standing (in player's native language).

Definition at line 1066 of file faction.c.

◆ faction_getStandingTextAtValue()

const char * faction_getStandingTextAtValue ( int f,
double value )

Gets the player's standing in human readable form.

Parameters
fFaction to get standing of.
valueValue to get the readable string from.
Returns
Human readable player's standing (in player's native language).

Definition at line 1078 of file faction.c.

◆ faction_isDynamic()

int faction_isDynamic ( int id)

Is faction dynamic.

Definition at line 283 of file faction.c.

◆ faction_isFaction()

int faction_isFaction ( int f)

Checks whether or not a faction is valid.

Parameters
fFaction to check for validity.
Returns
1 if faction is valid, 0 otherwise.

Definition at line 1277 of file faction.c.

◆ faction_isInvisible()

int faction_isInvisible ( int id)

Is the faction invisible?

Definition at line 250 of file faction.c.

◆ faction_isKnown()

int faction_isKnown ( int id)

Is the faction known?

Definition at line 275 of file faction.c.

◆ faction_isPlayerEnemy()

int faction_isPlayerEnemy ( int f)

Gets whether or not the player is an enemy of the faction.

Parameters
fFaction to check hostility of.
Returns
1 if the player is an enemy, 0 otherwise.

Definition at line 1021 of file faction.c.

◆ faction_isPlayerFriend()

int faction_isPlayerFriend ( int f)

Gets whether or not the player is a friend of the faction.

Parameters
fFaction to check friendliness of.
Returns
1 if the player is a friend, 0 otherwise.

Definition at line 1009 of file faction.c.

◆ faction_isStatic()

int faction_isStatic ( int id)

Is the faction static?

Definition at line 242 of file faction.c.

◆ faction_lane_base_cost()

double faction_lane_base_cost ( int f)

Gets the faction's weight for patrolled safe-lane construction;.

Definition at line 438 of file faction.c.

◆ faction_lane_length_per_presence()

double faction_lane_length_per_presence ( int f)

Gets the faction's weight for patrolled safe-lane construction (0 means they don't build lanes).

Definition at line 426 of file faction.c.

◆ faction_logo()

const glTexture * faction_logo ( int f)

Gets the faction's logo (ideally 256x256).

Parameters
fFaction to get the logo of.
Returns
The faction's logo image.

Definition at line 453 of file faction.c.

◆ faction_longname()

const char * faction_longname ( int f)

Gets the faction's long name (formal, human-readable).

Parameters
fFaction to get the name of.
Returns
The faction's long name (in player's native language).

Definition at line 348 of file faction.c.

◆ faction_mapname()

const char * faction_mapname ( int f)

Gets the faction's map name (translated).

Parameters
fFaction to get the name of.
Returns
The faction's map name (in User's language).

Definition at line 365 of file faction.c.

◆ faction_modPlayer()

void faction_modPlayer ( int f,
double mod,
const char * source )

Modifies the player's standing with a faction.

Affects enemies and allies too.

Parameters
fFaction to modify player's standing.
modModifier to modify by.
sourceSource of the faction modifier.

Possible sources:

  • "kill" : Pilot death.
  • "distress" : Pilot distress signal.
  • "script" : Either a mission or an event.

Definition at line 843 of file faction.c.

◆ faction_modPlayerLua()

static void faction_modPlayerLua ( int f,
double mod,
const char * source,
int secondary )
static

Mods player using the power of Lua.

Definition at line 762 of file faction.c.

◆ faction_modPlayerRaw()

void faction_modPlayerRaw ( int f,
double mod )

Modifies the player's standing without affecting others.

Does not affect allies nor enemies and does not run through the Lua script.

Parameters
fFaction whose standing to modify.
modAmount to modify standing by.
See also
faction_modPlayer

Definition at line 903 of file faction.c.

◆ faction_modPlayerSingle()

void faction_modPlayerSingle ( int f,
double mod,
const char * source )

Modifies the player's standing without affecting others.

Does not affect allies nor enemies.

Parameters
fFaction whose standing to modify.
modAmount to modify standing by.
sourceSource of the faction modifier.

Possible sources:

  • "kill" : Pilot death.
  • "distress" : Pilot distress signal.
  • "script" : Either a mission or an event.
See also
faction_modPlayer

Definition at line 883 of file faction.c.

◆ faction_name()

const char * faction_name ( int f)

Gets a factions "real" (internal) name.

Parameters
fFaction to get the name of.
Returns
Name of the faction (internal/English).

Definition at line 306 of file faction.c.

◆ faction_parse()

static int faction_parse ( Faction * temp,
const char * file )
static

Parses a single faction, but doesn't set the allies/enemies bit.

Parameters
tempFaction to load data into.
fileFile to parse.
Returns
Faction created from parent node.

Definition at line 1291 of file faction.c.

◆ faction_parseSocial()

static int faction_parseSocial ( const char * file)
static

Parses the social tidbits of a faction: allies and enemies.

Parameters
fileFile to parse.
Returns
0 on success.

Definition at line 1468 of file faction.c.

◆ faction_reputationMax()

double faction_reputationMax ( int f)

Gets the maximum reputation of a faction.

Parameters
fFaction to get maximum reputation of.
Returns
Maximum value of the reputation with a faction.

Definition at line 1179 of file faction.c.

◆ faction_rmAlly()

void faction_rmAlly ( int f,
int o )

Removes an ally from the faction's allies list.

Parameters
fThe faction to remove an ally from.
oThe other faction to remove as an ally.

Definition at line 703 of file faction.c.

◆ faction_rmEnemy()

void faction_rmEnemy ( int f,
int o )

Removes an enemy from the faction's enemies list.

Parameters
fThe faction to remove an enemy from.
oThe other faction to remove as an enemy.

Definition at line 610 of file faction.c.

◆ faction_sanitizePlayer()

static void faction_sanitizePlayer ( Faction * faction)
static

Sanitizes player faction standing.

Parameters
factionFaction to sanitize.

Definition at line 754 of file faction.c.

◆ faction_setInvisible()

int faction_setInvisible ( int id,
int state )

Sets the faction's invisible state.

Definition at line 258 of file faction.c.

◆ faction_setKnown()

int faction_setKnown ( int id,
int state )

Sets the factions known state.

Definition at line 291 of file faction.c.

◆ faction_setPlayer()

void faction_setPlayer ( int f,
double value )

Sets the player's standing with a faction.

Parameters
fFaction to set the player's standing for.
valueValue to set the player's standing to.

Definition at line 940 of file faction.c.

◆ faction_shortname()

const char * faction_shortname ( int f)

Gets a factions short name (human-readable).

Parameters
fFaction to get the name of.
Returns
Name of the faction (in player's native language).

Definition at line 325 of file faction.c.

◆ faction_tags()

const char ** faction_tags ( int f)

Gets the tags the faction has.

Parameters
fFaction ID.
Returns
The tagss the faction has (array.h).

Definition at line 414 of file faction.c.

◆ faction_usesHiddenJumps()

int faction_usesHiddenJumps ( int f)

Checks to see if a faction uses hidden jumps.

Definition at line 1873 of file faction.c.

◆ factions_clearDynamic()

void factions_clearDynamic ( void )

Clears dynamic factions.

Definition at line 1893 of file faction.c.

◆ factions_free()

void factions_free ( void )

Frees the factions.

Definition at line 1740 of file faction.c.

◆ factions_load()

int factions_load ( void )

Loads up all the factions from the data file.

Returns
0 on success.

Definition at line 1610 of file faction.c.

◆ factions_reset()

void factions_reset ( void )

Resets player standing and flags of factions to default.

Definition at line 1597 of file faction.c.

◆ pfaction_load()

int pfaction_load ( xmlNodePtr parent)

Loads the player's faction standings.

Parameters
parentParent xml node to read from.
Returns
0 on success.

Definition at line 1791 of file faction.c.

◆ pfaction_save()

int pfaction_save ( xmlTextWriterPtr writer)

Saves player's standings with the factions.

Parameters
writerThe xml writer to use.
Returns
0 on success.

Definition at line 1760 of file faction.c.

Variable Documentation

◆ faction_grid

int* faction_grid = NULL
static

Grid of faction status.

Definition at line 106 of file faction.c.

◆ faction_mgrid

size_t faction_mgrid = 0
static

Allocated memory.

Definition at line 107 of file faction.c.

◆ faction_player

int faction_player

Player faction identifier.

Definition at line 47 of file faction.c.

◆ faction_stack

Faction* faction_stack = NULL
static

Faction stack.

Definition at line 105 of file faction.c.