26#include "nlua_system.h"
28#include "opengl_tex.h"
32#define XML_FACTION_ID "Factions"
33#define XML_FACTION_TAG "faction"
35#define FACTION_STATIC \
37#define FACTION_INVISIBLE \
39#define FACTION_KNOWN ( 1 << 2 )
40#define FACTION_DYNAMIC ( 1 << 3 )
41#define FACTION_USESHIDDENJUMPS \
43#define FACTION_REPOVERRIDE ( 1 << 5 )
45#define faction_setFlag( fa, f ) ( ( fa )->flags |= ( f ) )
46#define faction_rmFlag( fa, f ) ( ( fa )->flags &= ~( f ) )
47#define faction_isFlag( fa, f ) ( ( fa )->flags & ( f ) )
48#define faction_isKnown_( fa ) ( ( fa )->flags & ( FACTION_KNOWN ) )
50typedef enum FactionGrid {
64typedef struct Faction_ {
74 char *script_standing;
140static double faction_hitLua(
int f,
const StarSystem *sys,
double mod,
141 const char *source,
int secondary,
142 int primary_faction );
151static int faction_cmp(
const void *p1,
const void *p2 )
155 return strcmp( f1->
name, f2->
name );
170 if ( strcmp( name,
"Escort" ) == 0 )
171 return FACTION_PLAYER;
173 if ( name != NULL ) {
213 WARN( _(
"Faction '%s' not found in stack." ), name );
286 WARN( _(
"Faction id '%d' is invalid." ),
id );
334 WARN( _(
"Faction id '%d' is invalid." ), f );
338 if ( f == FACTION_PLAYER )
353 WARN( _(
"Faction id '%d' is invalid." ), f );
357 if ( f == FACTION_PLAYER )
358 return _(
"Escort" );
376 WARN( _(
"Faction id '%d' is invalid." ), f );
393 WARN( _(
"Faction id '%d' is invalid." ), f );
410 WARN( _(
"Faction id '%d' is invalid." ), f );
427 WARN( _(
"Faction id '%d' is invalid." ), f );
442 WARN( _(
"Faction id '%d' is invalid." ), f );
455 WARN( _(
"Faction id '%d' is invalid." ), f );
467 WARN( _(
"Faction id '%d' is invalid." ), f );
482 WARN( _(
"Faction id '%d' is invalid." ), f );
497 WARN( _(
"Faction id '%d' is invalid." ), f );
512 WARN( _(
"Faction id '%d' is invalid." ), f );
517 if ( f == FACTION_PLAYER ) {
542 WARN( _(
"Faction id '%d' is invalid." ), f );
547 if ( f == FACTION_PLAYER ) {
575 WARN( _(
"Faction id '%d' is invalid." ), f );
600 WARN( _(
"Faction id '%d' is invalid." ), f );
605 WARN( _(
"Faction id '%d' is invalid." ), o );
610 if ( f == FACTION_PLAYER ) {
611 WARN( _(
"%d is the player faction" ), f );
614 if ( o == FACTION_PLAYER ) {
615 WARN( _(
"%d is the player faction" ), o );
646 WARN( _(
"Faction id '%d' is invalid." ), f );
671 WARN( _(
"Faction id '%d' is invalid." ), f );
696 WARN( _(
"Faction id '%d' is invalid." ), f );
701 WARN( _(
"Faction id '%d' is invalid." ), o );
706 if ( f == FACTION_PLAYER ) {
707 WARN( _(
"%d is the player faction" ), f );
710 if ( o == FACTION_PLAYER ) {
711 WARN( _(
"%d is the player faction" ), o );
742 WARN( _(
"Faction id '%d' is invalid." ), f );
747 if ( ff->
allies[i] == o ) {
761 WARN( _(
"Faction id '%d' is invalid." ), f );
773 WARN( _(
"Faction id '%d' is invalid." ), f );
793 const char *source,
int secondary,
794 int primary_faction )
807 if ( faction_isFlag( faction, FACTION_REPOVERRIDE ) )
812 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, faction->
lua_hit );
816 lua_pushnil(
naevL );
817 lua_pushnumber(
naevL, mod );
818 lua_pushstring(
naevL, source );
819 lua_pushinteger(
naevL, secondary );
823 lua_pushnil(
naevL );
826 if ( nlua_pcall( faction->
lua_env, 5, 1 ) ) {
827 WARN( _(
"Faction '%s': %s" ), faction->
name, lua_tostring(
naevL, -1 ) );
836 double delta = lua_tonumber(
naevL, -1 );
838 if (
FABS( delta ) > DOUBLE_TOL ) {
840 hparam[0].
type = HOOK_PARAM_FACTION;
843 hparam[1].
type = HOOK_PARAM_SSYS;
844 hparam[1].
u.
ls = sys->id;
846 hparam[1].
type = HOOK_PARAM_NIL;
847 hparam[2].
type = HOOK_PARAM_NUMBER;
848 hparam[2].
u.
num = delta;
849 hparam[3].
type = HOOK_PARAM_STRING;
850 hparam[3].
u.
str = source;
851 hparam[4].
type = HOOK_PARAM_NUMBER;
852 hparam[4].
u.
num = secondary;
854 hparam[5].
type = HOOK_PARAM_FACTION;
855 hparam[5].
u.
lf = primary_faction;
857 hparam[5].
type = HOOK_PARAM_NIL;
858 hparam[6].
type = HOOK_PARAM_SENTINEL;
872 const char *source,
int single )
876 WARN( _(
"Faction id '%d' is invalid." ), f );
907 WARN( _(
"Faction id '%d' is invalid." ), f );
922 if ( faction_isFlag( faction, FACTION_REPOVERRIDE ) )
927 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, faction->
lua_hit );
931 lua_pushnil(
naevL );
932 lua_pushnumber(
naevL, mod );
933 lua_pushstring(
naevL, source );
934 lua_pushinteger(
naevL, 0 );
935 lua_pushnil(
naevL );
938 if ( nlua_pcall( faction->
lua_env, 5, 1 ) ) {
939 WARN( _(
"Faction '%s': %s" ), faction->
name, lua_tostring(
naevL, -1 ) );
948 double delta = lua_tonumber(
naevL, -1 );
972 WARN( _(
"Faction id '%d' is invalid." ), f );
1010 WARN( _(
"Faction id '%d' is invalid." ), f );
1035 WARN( _(
"Faction id '%d' is invalid." ), f );
1067 WARN( _(
"Faction id '%d' is invalid." ), f );
1071 value =
CLAMP( -100., 100.,
1085 if ( faction_isFlag( faction, FACTION_REPOVERRIDE ) )
1089 mod = value - faction->
player;
1094 for (
int j = 0; j <
array_size( sys_stack ); j++ ) {
1095 StarSystem *sys = &sys_stack[j];
1096 for (
int k = 0; k <
array_size( sys->presence ); k++ ) {
1106 hparam[0].
type = HOOK_PARAM_FACTION;
1108 hparam[1].
type = HOOK_PARAM_NIL;
1109 hparam[2].
type = HOOK_PARAM_NUMBER;
1110 hparam[2].
u.
num = mod;
1111 hparam[3].
type = HOOK_PARAM_STRING;
1112 hparam[3].
u.
str =
"script";
1113 hparam[4].
type = HOOK_PARAM_NUMBER;
1114 hparam[4].
u.
num = 0;
1115 hparam[5].
type = HOOK_PARAM_NIL;
1116 hparam[6].
type = HOOK_PARAM_SENTINEL;
1133 if ( faction_isFlag( fac, FACTION_REPOVERRIDE ) )
1136 return round( fac->
player );
1138 WARN( _(
"Faction id '%d' is invalid." ), f );
1152 WARN( _(
"Faction id '%d' is invalid." ), f );
1167int faction_isPlayerFriendSystem(
int f,
const StarSystem *sys )
1183int faction_isPlayerEnemySystem(
int f,
const StarSystem *sys )
1200 else if (
areAllies( FACTION_PLAYER, f ) )
1207const glColour *faction_reputationColourSystem(
int f,
const StarSystem *sys )
1211 else if ( areAlliesSystem( FACTION_PLAYER, f, sys ) )
1213 else if ( areEnemiesSystem( FACTION_PLAYER, f, sys ) )
1234 else if (
areAllies( FACTION_PLAYER, f ) )
1239char faction_reputationColourCharSystem(
int f,
const StarSystem *sys )
1243 else if ( areEnemiesSystem( FACTION_PLAYER, f, sys ) )
1245 else if ( areAlliesSystem( FACTION_PLAYER, f, sys ) )
1278 if ( f == FACTION_PLAYER )
1279 return _(
"Escort" );
1283 if ( faction->
lua_env == LUA_NOREF )
1290 lua_pushnumber(
naevL, round( value ) );
1293 if ( nlua_pcall( faction->
lua_env, 1, 1 ) ) {
1295 WARN( _(
"Faction '%s': %s" ), faction->
name,
1296 lua_tostring(
naevL, -1 ) );
1297 lua_pop(
naevL, 1 );
1302 if ( !lua_isstring(
naevL, -1 ) ) {
1304 _(
"Lua script for faction '%s' did not return a %s from '%s'." ),
1305 faction->
name, _(
"string" ),
"text_rank" );
1308 r = lua_tostring(
naevL, -1 );
1309 lua_pop(
naevL, 1 );
1332 if ( f == FACTION_PLAYER )
1333 return _(
"Escort" );
1337 if ( faction->
lua_env == LUA_NOREF )
1343 lua_pushnumber(
naevL, ( faction_isFlag( faction, FACTION_REPOVERRIDE )
1346 lua_pushboolean(
naevL, bribed );
1347 lua_pushinteger(
naevL,
override );
1350 if ( nlua_pcall( faction->
lua_env, 3, 1 ) ) {
1352 WARN( _(
"Faction '%s': %s" ), faction->
name, lua_tostring(
naevL, -1 ) );
1353 lua_pop(
naevL, 1 );
1358 if ( !lua_isstring(
naevL, -1 ) ) {
1359 WARN( _(
"Lua script for faction '%s' did not return a %s from '%s'." ),
1360 faction->
name, _(
"string" ),
"text_broad" );
1363 r = lua_tostring(
naevL, -1 );
1364 lua_pop(
naevL, 1 );
1384 if ( f == FACTION_PLAYER )
1389 if ( faction->
lua_env == LUA_NOREF )
1397 if ( nlua_pcall( faction->
lua_env, 0, 1 ) ) {
1399 WARN( _(
"Faction '%s': %s" ), faction->
name, lua_tostring(
naevL, -1 ) );
1400 lua_pop(
naevL, 1 );
1405 if ( !lua_isnumber(
naevL, -1 ) ) {
1406 WARN( _(
"Lua script for faction '%s' did not return a %s from '%s'." ),
1407 faction->
name, _(
"number" ),
"reputation_max" );
1410 r = lua_tonumber(
naevL, -1 );
1411 lua_pop(
naevL, 1 );
1435 if ( a == FACTION_PLAYER )
1437 else if ( b == FACTION_PLAYER )
1461 if ( a == FACTION_PLAYER )
1463 else if ( b == FACTION_PLAYER )
1487 if ( a == FACTION_PLAYER )
1489 else if ( b == FACTION_PLAYER )
1495int areEnemiesSystem(
int a,
int b,
const StarSystem *sys )
1506 if ( a == FACTION_PLAYER )
1507 return faction_isPlayerEnemySystem( b, sys );
1508 else if ( b == FACTION_PLAYER )
1509 return faction_isPlayerEnemySystem( a, sys );
1514int areAlliesSystem(
int a,
int b,
const StarSystem *sys )
1525 if ( a == FACTION_PLAYER )
1526 return faction_isPlayerFriendSystem( b, sys );
1527 else if ( b == FACTION_PLAYER )
1528 return faction_isPlayerFriendSystem( a, sys );
1555 xmlNodePtr node, parent;
1562 parent = doc->xmlChildrenNode;
1563 if ( parent == NULL ) {
1564 WARN( _(
"Malformed '%s' file: does not contain elements" ), file );
1569 memset( temp, 0,
sizeof(
Faction ) );
1580 xmlr_attr_strd( parent,
"name", temp->
name );
1581 if ( temp->
name == NULL )
1582 WARN( _(
"Faction from file '%s' has no name!" ), file );
1585 node = parent->xmlChildrenNode;
1588 xml_onlyNodes( node );
1591 if ( xml_isNode( node,
"player" ) ) {
1597 xmlr_strd( node,
"longname", temp->
longname );
1599 xmlr_strd( node,
"mapname", temp->
mapname );
1600 xmlr_strd( node,
"description", temp->
description );
1601 xmlr_strd( node,
"ai", temp->
ai );
1602 xmlr_float( node,
"local_th", temp->
local_th );
1603 xmlr_float( node,
"lane_length_per_presence",
1606 if ( xml_isNode( node,
"colour" ) ) {
1607 const char *ctmp = xml_get( node );
1608 if ( ctmp != NULL ) {
1609 const glColour *
c = col_fromName( xml_raw( node ) );
1613 WARN( _(
"Faction '%s' has invalid colour '%s'!" ), temp->
name,
1619 xmlr_attr_float( node,
"r", temp->
colour.r );
1620 xmlr_attr_float( node,
"g", temp->
colour.g );
1621 xmlr_attr_float( node,
"b", temp->
colour.b );
1623 col_gammaToLinear( &temp->
colour );
1628 if ( xml_isNode( node,
"known" ) ) {
1633 if ( xml_isNode( node,
"logo" ) ) {
1635 if ( temp->
logo != NULL ) {
1636 WARN( _(
"Faction '%s' has duplicate 'logo' tag." ), temp->
name );
1639 snprintf( buf,
sizeof( buf ), FACTION_LOGO_PATH
"%s.webp",
1645 if ( xml_isNode( node,
"static" ) ) {
1650 if ( xml_isNode( node,
"invisible" ) ) {
1655 if ( xml_isNode( node,
"useshiddenjumps" ) ) {
1660 if ( xml_isNode( node,
"tags" ) ) {
1661 xmlNodePtr cur = node->children;
1662 if ( temp->
tags != NULL )
1663 WARN( _(
"Faction '%s' has duplicate '%s' node!" ), temp->
name,
1668 xml_onlyNodes( cur );
1669 if ( xml_isNode( cur,
"tag" ) ) {
1670 const char *tmp = xml_get( cur );
1675 WARN( _(
"Faction '%s' has unknown node in tags '%s'." ),
1676 temp->
name, cur->name );
1677 }
while ( xml_nextNode( cur ) );
1683 if ( xml_isNode( node,
"allies" ) || xml_isNode( node,
"enemies" ) ||
1684 xml_isNode( node,
"neutrals" ) || xml_isNode( node,
"generator" ) ||
1685 xml_isNode( node,
"standing" ) || xml_isNode( node,
"spawn" ) ||
1686 xml_isNode( node,
"equip" ) )
1688 WARN( _(
"Unknown node '%s' in faction '%s'" ), node->name, temp->
name );
1691 }
while ( xml_nextNode( node ) );
1694 WARN( _(
"Faction '%s' missing 'player' tag." ), temp->
name );
1695 if ( faction_isKnown_( temp ) &&
1698 WARN( _(
"Faction '%s' is known but missing 'description' tag." ),
1717 snprintf( buf,
sizeof( buf ), FACTIONS_PATH
"standing/%s.lua", scriptname );
1722 if ( nlua_dobufenv( temp->
lua_env, dat, ndat, buf ) != 0 ) {
1723 WARN( _(
"Failed to run standing script: %s\n"
1725 "Most likely Lua file has improper syntax, please check" ),
1726 buf, lua_tostring(
naevL, -1 ) );
1727 nlua_freeEnv( temp->
lua_env );
1730 lua_pop(
naevL, 1 );
1748 lua_pop(
naevL, 1 );
1760 xmlNodePtr node, parent;
1767 parent = doc->xmlChildrenNode;
1768 if ( parent == NULL ) {
1769 WARN( _(
"Malformed '%s' file: does not contain elements" ), file );
1775 xmlr_attr_strd( parent,
"name", name );
1781 assert( base != NULL );
1789 node = parent->xmlChildrenNode;
1791 xml_onlyNodes( node );
1793 if ( xml_isNode( node,
"generator" ) ) {
1798 xmlr_attr_float( node,
"weight", fg->
weight );
1804 xmlr_strd( node,
"standing", base->script_standing );
1805 xmlr_strd( node,
"spawn", base->script_spawn );
1806 xmlr_strd( node,
"equip", base->script_equip );
1809 if ( xml_isNode( node,
"allies" ) ) {
1810 xmlNodePtr cur = node->xmlChildrenNode;
1812 xml_onlyNodes( cur );
1813 if ( xml_isNode( cur,
"ally" ) ) {
1818 }
while ( xml_nextNode( cur ) );
1823 if ( xml_isNode( node,
"enemies" ) ) {
1824 xmlNodePtr cur = node->xmlChildrenNode;
1826 xml_onlyNodes( cur );
1827 if ( xml_isNode( cur,
"enemy" ) ) {
1832 }
while ( xml_nextNode( cur ) );
1837 if ( xml_isNode( node,
"neutrals" ) ) {
1838 xmlNodePtr cur = node->xmlChildrenNode;
1840 xml_onlyNodes( cur );
1841 if ( xml_isNode( cur,
"neutral" ) ) {
1846 }
while ( xml_nextNode( cur ) );
1849 }
while ( xml_nextNode( node ) );
1876 for (
int i = 0; i <
array_size( sys_stack ); i++ ) {
1877 StarSystem *sys = &sys_stack[i];
1878 for (
int j = 0; j <
array_size( sys->presence ); j++ ) {
1886void faction_updateSingle(
int f )
1891 for (
int j = 0; j <
array_size( sys_stack ); j++ ) {
1892 StarSystem *sys = &sys_stack[j];
1893 for (
int k = 0; k <
array_size( sys->presence ); k++ ) {
1910 faction_updateSingle( i );
1913void faction_applyLocalThreshold(
int f, StarSystem *sys )
1916 system_getFactionPresence( sys, f );
1921 if ( srep->
value <= 0. ) {
1922 WARN(
"Trying to apply local faction threshold from system with no "
1929 double rep = srep->
local;
1941 for (
int i = 0; i <
array_size( queuea ); i++ ) {
1942 StarSystem *qsys = &sys_stack[queuea[i]];
1945 srep = system_getFactionPresence( qsys, f );
1948 MIN( rep + n * th, 100 ), srep->
local );
1951 for (
int j = 0; j <
array_size( qsys->jumps ); j++ ) {
1952 StarSystem *nsys = qsys->jumps[j].target;
1955 for (
int k = 0; k <
array_size( done ); k++ ) {
1956 if ( nsys->id == done[k] ) {
1976 int *queue = queuea;
1986 faction_updateSingle( f );
1997 Uint32 time = SDL_GetTicks();
2005 memset( f, 0,
sizeof(
Faction ) );
2006 f->name = strdup(
"Player" );
2008 f->equip_env = LUA_NOREF;
2009 f->sched_env = LUA_NOREF;
2010 f->lua_env = LUA_NOREF;
2011 f->lua_hit = LUA_NOREF;
2012 f->lua_hit_test = LUA_NOREF;
2013 f->lua_text_rank = LUA_NOREF;
2014 f->lua_text_broad = LUA_NOREF;
2015 f->lua_reputation_max = LUA_NOREF;
2020 for (
int i = 0; i <
array_size( faction_files ); i++ ) {
2040 for (
int i = 0; i <
array_size( faction_files ); i++ ) {
2051 for (
int j = 0; j <
array_size( f->allies ); j++ ) {
2055 if ( sf->
allies[k] == i ) {
2066 for (
int j = 0; j <
array_size( f->enemies ); j++ ) {
2081 for (
int i = 0; i <
array_size( faction_files ); i++ )
2082 free( faction_files[i] );
2088 if ( conf.devmode ) {
2089 time = SDL_GetTicks() - time;
2090 DEBUG( n_(
"Loaded %d Faction in %.3f s",
"Loaded %d Factions in %.3f s",
2094 DEBUG( n_(
"Loaded %d Faction",
"Loaded %d Factions",
2102void factions_loadPost(
void )
2108 if ( f->script_standing != NULL )
2111 if ( f->script_spawn != NULL ) {
2115 snprintf( buf,
sizeof( buf ), FACTIONS_PATH
"spawn/%s.lua",
2117 f->sched_env = nlua_newEnv( buf );
2120 if ( nlua_dobufenv( f->sched_env, dat, ndat, buf ) != 0 ) {
2121 WARN( _(
"Failed to run spawn script: %s\n"
2123 "Most likely Lua file has improper syntax, please check" ),
2124 buf, lua_tostring(
naevL, -1 ) );
2125 nlua_freeEnv( f->sched_env );
2126 f->sched_env = LUA_NOREF;
2131 if ( f->script_equip != NULL ) {
2135 snprintf( buf,
sizeof( buf ), FACTIONS_PATH
"equip/%s.lua",
2137 f->equip_env = nlua_newEnv( buf );
2140 if ( nlua_dobufenv( f->equip_env, dat, ndat, buf ) != 0 ) {
2141 WARN( _(
"Failed to run equip script: %s\n"
2143 "Most likely Lua file has improper syntax, please check" ),
2144 buf, lua_tostring(
naevL, -1 ) );
2145 nlua_freeEnv( f->equip_env );
2146 f->equip_env = LUA_NOREF;
2152 if ( ( f->lua_env == LUA_NOREF ) && !faction_isFlag( f,
FACTION_STATIC ) )
2153 WARN( _(
"Faction '%s' has no Lua and isn't static!" ), f->name );
2163 free( f->longname );
2164 free( f->displayname );
2166 free( f->description );
2168 free( f->script_standing );
2169 free( f->script_spawn );
2170 free( f->script_equip );
2176 nlua_freeEnv( f->sched_env );
2177 nlua_freeEnv( f->lua_env );
2179 nlua_freeEnv( f->equip_env );
2180 for (
int i = 0; i <
array_size( f->tags ); i++ )
2210 xmlw_startElem( writer,
"factions" );
2219 xmlw_startElem( writer,
"faction" );
2221 xmlw_attr( writer,
"name",
"%s", f->name );
2222 xmlw_elem( writer,
"standing",
"%f", f->player );
2223 if ( faction_isFlag( f, FACTION_REPOVERRIDE ) )
2224 xmlw_elem( writer,
"override",
"%f", f->override );
2226 if ( faction_isKnown_( f ) )
2227 xmlw_elemEmpty( writer,
"known" );
2229 xmlw_endElem( writer );
2232 xmlw_endElem( writer );
2244 xmlNodePtr node = parent->xmlChildrenNode;
2247 if ( xml_isNode( node,
"factions" ) ) {
2248 xmlNodePtr cur = node->xmlChildrenNode;
2250 if ( xml_isNode( cur,
"faction" ) ) {
2253 xmlr_attr_strd( cur,
"name", str );
2259 xmlNodePtr sub = cur->xmlChildrenNode;
2262 if ( xml_isNode( sub,
"standing" ) ) {
2266 fct->
player = xml_getFloat( sub );
2269 if ( xml_isNode( sub,
"known" ) ) {
2273 if ( xml_isNode( sub,
"override" ) ) {
2274 fct->
override = xml_getFloat( sub );
2275 faction_setFlag( fct, FACTION_REPOVERRIDE );
2278 }
while ( xml_nextNode( sub ) );
2280 }
while ( xml_nextNode( cur ) );
2282 }
while ( xml_nextNode( node ) );
2329double faction_reputationOverride(
int f,
int *set )
2336 *set = faction_isFlag( fct, FACTION_REPOVERRIDE );
2340void faction_setReputationOverride(
int f,
int set,
double value )
2346 faction_rmFlag( fct, FACTION_REPOVERRIDE );
2349 faction_setFlag( fct, FACTION_REPOVERRIDE );
2398 const char *ai,
const glColour *colour )
2401 memset( f, 0,
sizeof(
Faction ) );
2402 f->name = strdup( name );
2403 f->displayname = ( display == NULL ) ? NULL : strdup( display );
2404 f->ai = ( ai == NULL ) ? NULL : strdup( ai );
2407 f->equip_env = LUA_NOREF;
2408 f->lua_env = LUA_NOREF;
2409 f->sched_env = LUA_NOREF;
2416 if ( bf->
ai != NULL && f->ai == NULL )
2417 f->ai = strdup( bf->
ai );
2418 if ( bf->
logo != NULL )
2439 if ( colour != NULL )
2440 f->colour = *colour;
2468 if ( ( fij != GRID_ALLIES && fij != GRID_NONE ) ||
2469 ( fji != GRID_ALLIES && fji != GRID_NONE ) )
2470 WARN(
"Incoherent faction grid! '%s' and '%s' already have a "
2472 "but trying to set to allies!",
2483 if ( ( fij != GRID_ENEMIES && fij != GRID_NONE ) ||
2484 ( fji != GRID_ENEMIES && fji != GRID_NONE ) )
2485 WARN(
"Incoherent faction grid! '%s' and '%s' already have a "
2487 "but trying to set to enemies!",
2498 if ( ( fij != GRID_NEUTRAL && fij != GRID_NONE ) ||
2499 ( fji != GRID_NEUTRAL && fji != GRID_NONE ) )
2500 WARN(
"Incoherent faction grid! '%s' and '%s' already have a "
2502 "but trying to set to neutrals!",
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_copy(basic_type, ptr_array)
Returns a shallow copy of the input array.
#define array_end(array)
Returns a pointer to the end of the reserved memory space.
#define array_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_begin(array)
Returns a pointer to the beginning of the reserved memory space.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
const char * faction_getStandingBroad(int f, int bribed, int override)
Gets the broad faction standing.
const char * faction_longname(int f)
Gets the faction's long name (formal, human-readable).
static void faction_freeOne(Faction *f)
Frees a single faction.
const glColour * faction_reputationColour(int f)
Gets the colour of the faction based on it's standing with the player.
int faction_isPlayerEnemy(int f)
Gets whether or not the player is an enemy of the faction.
int faction_exists(const char *name)
Checks to see if a faction exists by name.
const char * faction_default_ai(int f)
Gets the name of the default AI profile for the faction's pilots.
const int * faction_getEnemies(int f)
Gets the list of enemies of a faction.
int faction_dynAdd(int base, const char *name, const char *display, const char *ai, const glColour *colour)
Dynamically add a faction.
static int faction_getRaw(const char *name)
Gets a faction ID by name.
void faction_rmAlly(int f, int o)
Removes an ally from the faction's allies list.
int faction_isKnown(int id)
Is the faction known?
#define FACTION_INVISIBLE
int faction_isFaction(int f)
Checks whether or not a faction is valid.
static size_t faction_mgrid
static Faction * faction_stack
double faction_reputationDefault(int f)
Gets the player's default standing with a faction.
void faction_updateGlobal(void)
Computes the global faction standing for each of the factions.
const glTexture * faction_logo(int f)
Gets the faction's logo (ideally 256x256).
nlua_env faction_getEquipper(int f)
Gets the equipper state associated to the faction scheduler.
int factions_load(void)
Loads up all the factions from the data file.
void faction_clearEnemy(int f)
Clears all the enemies of a dynamic faction.
void factions_reset(void)
Resets player standing and flags of factions to default.
void faction_rmEnemy(int f, int o)
Removes an enemy from the faction's enemies list.
int faction_isPlayerFriend(int f)
Gets whether or not the player is a friend of the faction.
int areEnemies(int a, int b)
Checks whether two factions are enemies.
void factions_clearDynamic(void)
Clears dynamic factions.
int * faction_getGroup(int which)
Returns an array of faction ids.
const char *const * faction_tags(int f)
Gets the tags the faction has.
double faction_hit(int f, const StarSystem *sys, double mod, const char *source, int single)
Handles a faction hit against a faction and how to apply it.
double faction_hitTest(int f, const StarSystem *sys, double mod, const char *source)
Tests a faction hit to see how much it would apply. Does not actually modify standing.
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_getStandingText(int f)
Gets the player's standing in human readable form.
int faction_isDynamic(int id)
Is faction dynamic.
void factions_free(void)
Frees the factions.
int areNeutral(int a, int b)
Checks whether two factions are true neutral.
void factions_resetLocal(void)
Reset local standing.
const int * faction_getAllies(int f)
Gets the list of allies of a faction.
void faction_modPlayerRaw(int f, double mod)
Modifies the player's standing without affecting others.
const FactionGenerator * faction_generators(int f)
Gets the faction's generators.
int faction_usesHiddenJumps(int f)
Checks to see if a faction uses hidden jumps.
int * faction_getKnown()
Gets all the known factions in an array (array.h).
int faction_isInvisible(int id)
Is the faction invisible?
int pfaction_save(xmlTextWriterPtr writer)
Saves player's standings with the factions.
const glColour * faction_colour(int f)
Gets the colour of the faction.
static void faction_sanitizePlayer(Faction *faction)
Sanitizes player faction standing.
const char * faction_getStandingTextAtValue(int f, double value)
Gets the player's standing in human readable form.
void faction_clearAlly(int f)
Clears all the ally of a dynamic faction.
int pfaction_load(xmlNodePtr parent)
Loads the player's faction standings.
double faction_lane_base_cost(int f)
Gets the faction's weight for patrolled safe-lane construction;.
void faction_modPlayer(int f, double mod, const char *source)
Modifies the player's standing with a faction.
void faction_setReputation(int f, double value)
Sets the player's standing with a faction.
static int * faction_grid
static int faction_parseSocial(const char *file)
Parses the social tidbits of a faction: allies and enemies.
char faction_reputationColourChar(int f)
Gets the faction character associated to its standing with the player.
static double faction_hitLua(int f, const StarSystem *sys, double mod, const char *source, int secondary, int primary_faction)
Mods player using the power of Lua.
#define FACTION_USESHIDDENJUMPS
int * faction_getAll(void)
Returns all faction IDs in an array (array.h).
void faction_modPlayerSingle(int f, double mod, const char *source)
Modifies the player's standing without affecting others.
static void faction_addStandingScript(Faction *temp, const char *scriptname)
Sets up a standing script for a faction.
static int faction_parse(Faction *temp, const char *file)
Parses a single faction, but doesn't set the allies/enemies bit.
int faction_setInvisible(int id, int state)
Sets the faction's invisible state.
int faction_setKnown(int id, int state)
Sets the factions known state.
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).
int * faction_getAllVisible(void)
Returns all non-invisible faction IDs in an array (array.h).
const char * faction_mapname(int f)
Gets the faction's map name (translated).
double faction_reputationMax(int f)
Gets the maximum reputation of a faction.
void faction_addAlly(int f, int o)
Adds an ally to the faction's allies list.
nlua_env faction_getScheduler(int f)
Gets the state associated to the faction scheduler.
static void faction_computeGrid(void)
Computes the faction relationship grid.
double faction_reputation(int f)
Gets the player's standing with a faction.
const char * faction_description(int f)
Gets the faction's description (translated).
void faction_clearKnown()
Clears the known factions.
int faction_isStatic(int id)
Is the faction static?
void faction_addEnemy(int f, int o)
Adds an enemy to the faction's enemies list.
int faction_get(const char *name)
Gets a faction ID by name.
int areAllies(int a, int b)
Checks whether two factions are allies or not.
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
void naev_renderLoadscreen(void)
Renders the loadscreen if necessary.
Header file with generic functions and naev-specifics.
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
int ndata_matchExt(const char *path, const char *ext)
Sees if a file matches an extension.
char ** ndata_listRecursive(const char *path)
Lists all the visible files in a directory, at any depth.
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
int nlua_refenvtype(nlua_env env, const char *name, int type)
Gets the reference of a global in a lua environment if it matches a type.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
LuaSystem * lua_pushsystem(lua_State *L, LuaSystem sys)
Pushes a system on the stack.
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
void gl_freeTexture(glTexture *texture)
Frees a texture.
void space_factionChange(void)
Mark when a faction changes.
double system_getReputationOrGlobal(const StarSystem *sys, int faction)
Gets the local reputation of the player in a system or returns the global standing.
StarSystem * system_getAll(void)
Gets an array (array.h) of all star systems.
double system_getPresence(const StarSystem *sys, int faction)
Get the presence of a faction in a system.
Description of a lane-building faction.
FactionGenerator * generators
double lane_length_per_presence
The actual hook parameter.
union HookParam::@325330313164266255110350307176363262300250041145 u
Represents presence in a system.
Abstraction for rendering sprite sheets.