naev 0.10.4
Data Structures | Macros | Functions | Variables
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)   ((fa)->flags |= (f))
 
#define faction_rmFlag(fa, f)   ((fa)->flags &= ~(f))
 
#define faction_isFlag(fa, f)   ((fa)->flags & (f))
 
#define faction_isKnown_(fa)   ((fa)->flags & (FACTION_KNOWN))
 

Functions

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

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,
 
)    ((fa)->flags & (f))

Definition at line 44 of file faction.c.

◆ faction_isKnown_

#define faction_isKnown_ (   fa)    ((fa)->flags & (FACTION_KNOWN))

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,
 
)    ((fa)->flags &= ~(f))

Definition at line 43 of file faction.c.

◆ faction_setFlag

#define faction_setFlag (   fa,
 
)    ((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 1222 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 1197 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 655 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 562 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 1396 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 635 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 542 of file faction.c.

◆ faction_clearKnown()

void faction_clearKnown ( void  )

Clears the known factions.

Definition at line 230 of file faction.c.

◆ faction_cmp()

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

Definition at line 126 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 467 of file faction.c.

◆ faction_computeGrid()

static void faction_computeGrid ( void  )
static

Computes the faction relationship grid.

Definition at line 1932 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 397 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 380 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 1880 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 171 of file faction.c.

◆ faction_freeOne()

static void faction_freeOne ( Faction f)
static

Frees a single faction.

Definition at line 1681 of file faction.c.

◆ faction_generators()

const FactionGenerator * faction_generators ( int  f)

Gets the faction's generators.

Definition at line 1848 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 182 of file faction.c.

◆ faction_getAll()

int * faction_getAll ( void  )

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

Definition at line 193 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 513 of file faction.c.

◆ faction_getAllVisible()

int * faction_getAllVisible ( void  )

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

Definition at line 205 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 1023 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 1040 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 483 of file faction.c.

◆ faction_getEquipper()

nlua_env faction_getEquipper ( int  f)

Gets the equipper state associated to the faction scheduler.

Definition at line 738 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 1801 of file faction.c.

◆ faction_getKnown()

int * faction_getKnown ( )

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

Definition at line 217 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 969 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 983 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 140 of file faction.c.

◆ faction_getScheduler()

nlua_env faction_getScheduler ( int  f)

Gets the state associated to the faction scheduler.

Definition at line 726 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 1103 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 1054 of file faction.c.

◆ faction_isDynamic()

int faction_isDynamic ( int  id)

Is faction dynamic.

Definition at line 281 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 1246 of file faction.c.

◆ faction_isInvisible()

int faction_isInvisible ( int  id)

Is the faction invisible?

Definition at line 248 of file faction.c.

◆ faction_isKnown()

int faction_isKnown ( int  id)

Is the faction known?

Definition at line 273 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 1009 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 997 of file faction.c.

◆ faction_isStatic()

int faction_isStatic ( int  id)

Is the faction static?

Definition at line 240 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 436 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 424 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 451 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 346 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 363 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 839 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 760 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 899 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 879 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 304 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 1260 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 1441 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 1151 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 701 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 608 of file faction.c.

◆ faction_sanitizePlayer()

static void faction_sanitizePlayer ( Faction faction)
static

Sanitizes player faction standing.

Parameters
factionFaction to sanitize.

Definition at line 752 of file faction.c.

◆ faction_setInvisible()

int faction_setInvisible ( int  id,
int  state 
)

Sets the faction's invisible state.

Definition at line 256 of file faction.c.

◆ faction_setKnown()

int faction_setKnown ( int  id,
int  state 
)

Sets the factions known state.

Definition at line 289 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 932 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 323 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 412 of file faction.c.

◆ faction_usesHiddenJumps()

int faction_usesHiddenJumps ( int  f)

Checks to see if a faction uses hidden jumps.

Definition at line 1838 of file faction.c.

◆ factions_clearDynamic()

void factions_clearDynamic ( void  )

Clears dynamic factions.

Definition at line 1858 of file faction.c.

◆ factions_free()

void factions_free ( void  )

Frees the factions.

Definition at line 1705 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 1583 of file faction.c.

◆ factions_reset()

void factions_reset ( void  )

Resets player standing and flags of factions to default.

Definition at line 1570 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 1756 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 1725 of file faction.c.

Variable Documentation

◆ faction_grid

int* faction_grid = NULL
static

Grid of faction status.

Definition at line 107 of file faction.c.

◆ faction_mgrid

size_t faction_mgrid = 0
static

Allocated memory.

Definition at line 108 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 106 of file faction.c.