naev 0.12.5
nlua_faction.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
12#include <lauxlib.h>
14
15#include "nlua_faction.h"
16
17#include "array.h"
18#include "faction.h"
19#include "nlua.h"
20#include "nlua_colour.h"
21#include "nlua_system.h"
22#include "nlua_tex.h"
23#include "nluadef.h"
24
25/* Internal useful functions. */
26static LuaFaction luaL_validfactionSilent( lua_State *L, int ind );
27/* Faction metatable methods */
28static int factionL_exists( lua_State *L );
29static int factionL_get( lua_State *L );
30static int factionL_getAll( lua_State *L );
31static int factionL_player( lua_State *L );
32static int factionL_eq( lua_State *L );
33static int factionL_name( lua_State *L );
34static int factionL_nameRaw( lua_State *L );
35static int factionL_longname( lua_State *L );
36static int factionL_areneutral( lua_State *L );
37static int factionL_areenemies( lua_State *L );
38static int factionL_areallies( lua_State *L );
39static int factionL_usesHiddenJumps( lua_State *L );
40static int factionL_hit( lua_State *L );
41static int factionL_hitTest( lua_State *L );
42static int factionL_reputationGlobal( lua_State *L );
43static int factionL_reputationText( lua_State *L );
44static int factionL_reputationDefault( lua_State *L );
45static int factionL_setReputationGlobal( lua_State *L );
46static int factionL_applyLocalThreshold( lua_State *L );
47static int factionL_enemies( lua_State *L );
48static int factionL_allies( lua_State *L );
49static int factionL_logo( lua_State *L );
50static int factionL_colour( lua_State *L );
51static int factionL_isKnown( lua_State *L );
52static int factionL_setKnown( lua_State *L );
53static int factionL_isInvisible( lua_State *L );
54static int factionL_isStatic( lua_State *L );
55static int factionL_reputationOverride( lua_State *L );
56static int factionL_setReputationOverride( lua_State *L );
57static int factionL_tags( lua_State *L );
58static int factionL_dynAdd( lua_State *L );
59static int factionL_dynAlly( lua_State *L );
60static int factionL_dynEnemy( lua_State *L );
61/* Following functions are deprecated and should be removed in 0.13.0. */
62static int factionL_modplayer( lua_State *L );
63static int factionL_modplayersingle( lua_State *L );
64static int factionL_modplayerraw( lua_State *L );
65static int factionL_setplayerstanding( lua_State *L );
66static int factionL_playerstanding( lua_State *L );
67static int factionL_playerstandingdefault( lua_State *L );
68/* End of deprecated functions. */
69
70static const luaL_Reg faction_methods[] = {
71 { "exists", factionL_exists },
72 { "get", factionL_get },
73 { "getAll", factionL_getAll },
74 { "player", factionL_player },
75 { "__eq", factionL_eq },
76 { "__tostring", factionL_name },
77 { "name", factionL_name },
78 { "nameRaw", factionL_nameRaw },
79 { "longname", factionL_longname },
80 { "areNeutral", factionL_areneutral },
81 { "areEnemies", factionL_areenemies },
82 { "areAllies", factionL_areallies },
83 { "hit", factionL_hit },
84 { "hitTest", factionL_hitTest },
85 { "reputationGlobal", factionL_reputationGlobal },
86 { "reputationText", factionL_reputationText },
87 { "reputationDefault", factionL_reputationDefault },
88 { "setReputationGlobal", factionL_setReputationGlobal },
89 { "applyLocalThreshold", factionL_applyLocalThreshold },
90 { "modPlayer", factionL_modplayer },
91 { "modPlayerSingle", factionL_modplayersingle },
92 { "modPlayerRaw", factionL_modplayerraw },
93 { "setPlayerStanding", factionL_setplayerstanding },
94 { "playerStanding", factionL_playerstanding },
95 { "playerStandingDefault", factionL_playerstandingdefault },
96 { "enemies", factionL_enemies },
97 { "allies", factionL_allies },
98 { "usesHiddenJumps", factionL_usesHiddenJumps },
99 { "logo", factionL_logo },
100 { "colour", factionL_colour },
101 { "known", factionL_isKnown },
102 { "setKnown", factionL_setKnown },
103 { "invisible", factionL_isInvisible },
104 { "static", factionL_isStatic },
105 { "reputationOverride", factionL_reputationOverride },
106 { "setReputationOverride", factionL_setReputationOverride },
107 { "tags", factionL_tags },
108 { "dynAdd", factionL_dynAdd },
109 { "dynAlly", factionL_dynAlly },
110 { "dynEnemy", factionL_dynEnemy },
111 { 0, 0 } };
112
119int nlua_loadFaction( nlua_env env )
120{
121 nlua_register( env, FACTION_METATABLE, faction_methods, 1 );
122 return 0; /* No error */
123}
124
147static int factionL_exists( lua_State *L )
148{
149 const char *s = luaL_checkstring( L, 1 );
150 if ( faction_exists( s ) ) {
151 lua_pushfaction( L, faction_get( s ) );
152 return 1;
153 }
154 return 0;
155}
156
166static int factionL_get( lua_State *L )
167{
168 LuaFaction f = luaL_validfaction( L, 1 );
169 lua_pushfaction( L, f );
170 return 1;
171}
172
179static int factionL_getAll( lua_State *L )
180{
181 const int *factions = faction_getAll();
182 lua_newtable( L );
183 for ( int i = 0; i < array_size( factions ); i++ ) {
184 lua_pushfaction( L, factions[i] );
185 lua_rawseti( L, -2, i + 1 );
186 }
187 array_free( factions );
188 return 1;
189}
190
199static int factionL_player( lua_State *L )
200{
202 return 1;
203}
204
212LuaFaction lua_tofaction( lua_State *L, int ind )
213{
214 return *( (LuaFaction *)lua_touserdata( L, ind ) );
215}
216
217LuaFaction lua_checkfaction( lua_State *L, int ind )
218{
219 if ( lua_isfaction( L, ind ) )
220 return lua_tofaction( L, ind );
221 luaL_typerror( L, ind, FACTION_METATABLE );
222 return -1;
223}
224
225static LuaFaction luaL_validfactionSilent( lua_State *L, int ind )
226{
227 if ( lua_isfaction( L, ind ) )
228 return lua_tofaction( L, ind );
229 else if ( lua_isstring( L, ind ) )
230 return faction_get( lua_tostring( L, ind ) );
231 luaL_typerror( L, ind, FACTION_METATABLE );
232 return 0;
233}
234
243LuaFaction luaL_validfaction( lua_State *L, int ind )
244{
245 int id = luaL_validfactionSilent( L, ind );
246 if ( id == -1 )
247 return NLUA_ERROR( L, _( "Faction '%s' not found in stack." ),
248 lua_tostring( L, ind ) );
249 return id;
250}
251
259LuaFaction *lua_pushfaction( lua_State *L, LuaFaction faction )
260{
261 LuaFaction *f = (LuaFaction *)lua_newuserdata( L, sizeof( LuaFaction ) );
262 *f = faction;
263 luaL_getmetatable( L, FACTION_METATABLE );
264 lua_setmetatable( L, -2 );
265 return f;
266}
267
274int lua_isfaction( lua_State *L, int ind )
275{
276 int ret;
277
278 if ( lua_getmetatable( L, ind ) == 0 )
279 return 0;
280 lua_getfield( L, LUA_REGISTRYINDEX, FACTION_METATABLE );
281
282 ret = 0;
283 if ( lua_rawequal( L, -1, -2 ) ) /* does it have the correct mt? */
284 ret = 1;
285
286 lua_pop( L, 2 ); /* remove both metatables */
287 return ret;
288}
289
302static int factionL_eq( lua_State *L )
303{
304 int a = luaL_validfaction( L, 1 );
305 int b = luaL_validfaction( L, 2 );
306 lua_pushboolean( L, a == b );
307 return 1;
308}
309
324static int factionL_name( lua_State *L )
325{
326 int f = luaL_validfaction( L, 1 );
327 lua_pushstring( L, faction_shortname( f ) );
328 return 1;
329}
330
345static int factionL_nameRaw( lua_State *L )
346{
347 int f = luaL_validfaction( L, 1 );
348 lua_pushstring( L, faction_name( f ) );
349 return 1;
350}
351
365static int factionL_longname( lua_State *L )
366{
367 int f = luaL_validfaction( L, 1 );
368 lua_pushstring( L, faction_longname( f ) );
369 return 1;
370}
371
381static int factionL_areneutral( lua_State *L )
382{
383 int f = luaL_validfaction( L, 1 );
384 int ff = luaL_validfaction( L, 2 );
385 lua_pushboolean( L, areNeutral( f, ff ) );
386 return 1;
387}
388
401static int factionL_areenemies( lua_State *L )
402{
403 int f = luaL_validfaction( L, 1 );
404 int ff = luaL_validfaction( L, 2 );
405 if ( !lua_isnoneornil( L, 3 ) )
406 lua_pushboolean( L, areEnemiesSystem( f, ff, luaL_validsystem( L, 3 ) ) );
407 else
408 lua_pushboolean( L, areEnemies( f, ff ) );
409 return 1;
410}
411
424static int factionL_areallies( lua_State *L )
425{
426 int f = luaL_validfaction( L, 1 );
427 int ff = luaL_validfaction( L, 2 );
428 if ( !lua_isnoneornil( L, 3 ) )
429 lua_pushboolean( L, areAlliesSystem( f, ff, luaL_validsystem( L, 3 ) ) );
430 else
431 lua_pushboolean( L, areAllies( f, ff ) );
432 return 1;
433}
434
458static int factionL_hit( lua_State *L )
459{
460 int f = luaL_validfaction( L, 1 );
461 double mod = luaL_checknumber( L, 2 );
462 const StarSystem *sys =
463 ( lua_isnoneornil( L, 3 ) ) ? NULL : luaL_validsystem( L, 3 );
464 const char *reason = luaL_optstring( L, 4, "script" );
465 double ret = faction_hit( f, sys, mod, reason, lua_toboolean( L, 5 ) );
466 lua_pushnumber( L, ret );
467 return 1;
468}
469
485static int factionL_hitTest( lua_State *L )
486{
487 int f = luaL_validfaction( L, 1 );
488 double mod = luaL_checknumber( L, 2 );
489 const StarSystem *sys =
490 ( lua_isnoneornil( L, 3 ) ) ? NULL : luaL_validsystem( L, 3 );
491 const char *reason = luaL_optstring( L, 4, "script" );
492 double ret = faction_hitTest( f, sys, mod, reason );
493 lua_pushnumber( L, ret );
494 return 1;
495}
496
506static int factionL_reputationGlobal( lua_State *L )
507{
508 int f = luaL_validfaction( L, 1 );
509 lua_pushnumber( L, faction_reputation( f ) );
510 return 1;
511}
512
522static int factionL_reputationText( lua_State *L )
523{
524 int f = luaL_validfaction( L, 1 );
525 if ( lua_isnoneornil( L, 2 ) )
526 lua_pushstring( L, faction_getStandingTextAtValue(
527 f, faction_reputationDefault( f ) ) );
528 else
529 lua_pushstring(
530 L, faction_getStandingTextAtValue( f, luaL_checknumber( L, 2 ) ) );
531 return 1;
532}
533
541static int factionL_reputationDefault( lua_State *L )
542{
543 int f = luaL_validfaction( L, 1 );
544 lua_pushnumber( L, faction_reputationDefault( f ) );
545 return 1;
546}
547
556static int factionL_setReputationGlobal( lua_State *L )
557{
558 int f = luaL_validfaction( L, 1 );
559 double n = luaL_checknumber( L, 2 );
560 /* TODO finish. */
561 faction_setReputation( f, n );
562 return 0;
563}
564
575static int factionL_applyLocalThreshold( lua_State *L )
576{
577 int f = luaL_validfaction( L, 1 );
578 StarSystem *sys = luaL_validsystem( L, 2 );
579 faction_applyLocalThreshold( f, sys );
580 return 0;
581}
582
597static int factionL_modplayer( lua_State *L )
598{
599 NLUA_DEPRECATED( L, "modPlayer" );
600 int f = luaL_validfaction( L, 1 );
601 double n = luaL_checknumber( L, 2 );
602 const char *reason = luaL_optstring( L, 3, "script" );
603 faction_modPlayer( f, n, reason );
604 return 0;
605}
606
621static int factionL_modplayersingle( lua_State *L )
622{
623 NLUA_DEPRECATED( L, "modPlayerSingle" );
624 int f = luaL_validfaction( L, 1 );
625 double n = luaL_checknumber( L, 2 );
626 const char *reason = luaL_optstring( L, 3, "script" );
627 faction_modPlayerSingle( f, n, reason );
628 return 0;
629}
630
643static int factionL_modplayerraw( lua_State *L )
644{
645 NLUA_DEPRECATED( L, "modPlayerRaw" );
646 int f = luaL_validfaction( L, 1 );
647 double n = luaL_checknumber( L, 2 );
648 faction_modPlayerRaw( f, n );
649 return 0;
650}
651
662static int factionL_setplayerstanding( lua_State *L )
663{
664 NLUA_DEPRECATED( L, "setPlayerStanding" );
665 int f = luaL_validfaction( L, 1 );
666 double n = luaL_checknumber( L, 2 );
667 faction_setReputation( f, n );
668 return 0;
669}
670
685static int factionL_playerstanding( lua_State *L )
686{
687 NLUA_DEPRECATED( L, "playerStanding" );
688 int f = luaL_validfaction( L, 1 );
689 double n;
690 if ( !lua_isnoneornil( L, 2 ) )
691 n = luaL_checknumber( L, 2 );
692 else
693 n = faction_reputation( f );
694 lua_pushnumber( L, n );
695 lua_pushstring( L, faction_getStandingTextAtValue( f, n ) );
696 return 2;
697}
698
706static int factionL_playerstandingdefault( lua_State *L )
707{
708 NLUA_DEPRECATED( L, "playerStandingDefault" );
709 int f = luaL_validfaction( L, 1 );
710 double n = faction_reputationDefault( f );
711 lua_pushnumber( L, n );
712 return 1;
713}
714
724static int factionL_enemies( lua_State *L )
725{
726 const int *factions;
727 int f = luaL_validfaction( L, 1 );
728
729 /* Push the enemies in a table. */
730 lua_newtable( L );
731 factions = faction_getEnemies( f );
732 for ( int i = 0; i < array_size( factions ); i++ ) {
733 lua_pushfaction( L, factions[i] ); /* value */
734 lua_rawseti( L, -2, i + 1 );
735 }
736
737 return 1;
738}
739
749static int factionL_allies( lua_State *L )
750{
751 const int *factions;
752 int f = luaL_validfaction( L, 1 );
753
754 /* Push the enemies in a table. */
755 lua_newtable( L );
756 factions = faction_getAllies( f );
757 for ( int i = 0; i < array_size( factions ); i++ ) {
758 lua_pushfaction( L, factions[i] ); /* value */
759 lua_rawseti( L, -2, i + 1 );
760 }
761
762 return 1;
763}
764
773static int factionL_usesHiddenJumps( lua_State *L )
774{
775 int f = luaL_validfaction( L, 1 );
776 lua_pushboolean( L, faction_usesHiddenJumps( f ) );
777 return 1;
778}
779
787static int factionL_logo( lua_State *L )
788{
789 int lf = luaL_validfaction( L, 1 );
790 const glTexture *tex = faction_logo( lf );
791 if ( tex == NULL )
792 return 0;
793 lua_pushtex( L, gl_dupTexture( tex ) );
794 return 1;
795}
796
804static int factionL_colour( lua_State *L )
805{
806 int lf = luaL_validfaction( L, 1 );
807 const glColour *col = faction_reputationColour( lf );
808 if ( col == NULL )
809 return 0;
810 lua_pushcolour( L, *col );
811 return 1;
812}
813
823static int factionL_isKnown( lua_State *L )
824{
825 int fac = luaL_validfaction( L, 1 );
826 lua_pushboolean( L, faction_isKnown( fac ) );
827 return 1;
828}
829
838static int factionL_setKnown( lua_State *L )
839{
840 int fac = luaL_validfaction( L, 1 );
841 int b = lua_toboolean( L, 2 );
842 faction_setKnown( fac, b );
843 return 0;
844}
845
855static int factionL_isInvisible( lua_State *L )
856{
857 int fac = luaL_validfaction( L, 1 );
858 lua_pushboolean( L, faction_isInvisible( fac ) );
859 return 1;
860}
861
872static int factionL_isStatic( lua_State *L )
873{
874 int fac = luaL_validfaction( L, 1 );
875 lua_pushboolean( L, faction_isStatic( fac ) );
876 return 1;
877}
878
888static int factionL_reputationOverride( lua_State *L )
889{
890 int fac = luaL_validfaction( L, 1 );
891 int set;
892 double val = faction_reputationOverride( fac, &set );
893 if ( !set )
894 return 0;
895 lua_pushnumber( L, val );
896 return 1;
897}
898
907static int factionL_setReputationOverride( lua_State *L )
908{
909 int fac = luaL_validfaction( L, 1 );
910 int set = !lua_isnoneornil( L, 2 );
911 faction_setReputationOverride( fac, set, luaL_optnumber( L, 2, 0. ) );
912 return 1;
913}
914
928static int factionL_tags( lua_State *L )
929{
930 int fac = luaL_validfaction( L, 1 );
931 return nlua_helperTags( L, 2, (char *const *)faction_tags( fac ) );
932}
933
951static int factionL_dynAdd( lua_State *L )
952{
953 LuaFaction fac, newfac;
954 const char *name, *display, *ai;
955 const glColour *colour;
956 int clear_allies, clear_enemies;
957 double player;
958 int set_player;
959
960 if ( !lua_isnoneornil( L, 1 ) )
961 fac = luaL_validfactionSilent( L, 1 ); /* Won't error. */
962 else
963 fac = -1;
964 name = luaL_checkstring( L, 2 );
965 display = luaL_optstring( L, 3, name );
966 set_player = 0;
967
968 /* Just return existing and ignore the rest. */
969 if ( faction_exists( name ) ) {
970 int f = faction_get( name );
971 if ( !faction_isDynamic( f ) )
972 return NLUA_ERROR( L,
973 _( "Trying to overwrite existing faction '%s' with "
974 "dynamic faction!" ),
975 name );
976
977 lua_pushfaction( L, f );
978 return 1;
979 }
980
981 /* Parse parameters. */
982 if ( lua_istable( L, 4 ) ) {
983 lua_getfield( L, 4, "ai" );
984 ai = luaL_optstring( L, -1, NULL );
985 lua_pop( L, 1 );
986
987 lua_getfield( L, 4, "clear_allies" );
988 clear_allies = lua_toboolean( L, -1 );
989 lua_pop( L, 1 );
990
991 lua_getfield( L, 4, "clear_enemies" );
992 clear_enemies = lua_toboolean( L, -1 );
993 lua_pop( L, 1 );
994
995 lua_getfield( L, 4, "player" );
996 if ( lua_isnumber( L, -1 ) ) {
997 player = lua_tonumber( L, -1 );
998 set_player = 1;
999 }
1000 lua_pop( L, 1 );
1001
1002 lua_getfield( L, 4, "colour" );
1003 if ( lua_isstring( L, -1 ) )
1004 colour = col_fromName( lua_tostring( L, -1 ) );
1005 else
1006 colour = lua_tocolour( L, -1 );
1007 lua_pop( L, 1 );
1008 } else {
1009 ai = NULL;
1010 clear_allies = 0;
1011 clear_enemies = 0;
1012 player = 0.;
1013 colour = NULL;
1014 }
1015
1016 /* Create new faction. */
1017 newfac = faction_dynAdd( fac, name, display, ai, colour );
1018
1019 /* Clear if necessary. */
1020 if ( clear_allies )
1021 faction_clearAlly( newfac );
1022 if ( clear_enemies )
1023 faction_clearEnemy( newfac );
1024 if ( set_player )
1025 faction_setReputation( newfac, player );
1026
1027 lua_pushfaction( L, newfac );
1028 return 1;
1029}
1030
1040static int factionL_dynAlly( lua_State *L )
1041{
1042 LuaFaction fac, ally;
1043 int remove;
1044 fac = luaL_validfaction( L, 1 );
1045 if ( !faction_isDynamic( fac ) )
1046 return NLUA_ERROR( L, _( "Can only add allies to dynamic factions" ) );
1047 ally = luaL_validfaction( L, 2 );
1048 remove = lua_toboolean( L, 3 );
1049 if ( remove )
1050 faction_rmAlly( fac, ally );
1051 else
1052 faction_addAlly( fac, ally );
1053 return 0;
1054}
1055
1066static int factionL_dynEnemy( lua_State *L )
1067{
1068 LuaFaction fac, enemy;
1069 int remove;
1070 fac = luaL_validfaction( L, 1 );
1071 if ( !faction_isDynamic( fac ) )
1072 return NLUA_ERROR( L, _( "Can only add allies to dynamic factions" ) );
1073 enemy = luaL_validfaction( L, 2 );
1074 remove = lua_toboolean( L, 3 );
1075 if ( remove )
1076 faction_rmEnemy( fac, enemy );
1077 else
1078 faction_addEnemy( fac, enemy );
1079 return 0;
1080}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition array.h:170
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:179
const char * faction_longname(int f)
Gets the faction's long name (formal, human-readable).
Definition faction.c:373
const glColour * faction_reputationColour(int f)
Gets the colour of the faction based on it's standing with the player.
Definition faction.c:1196
int faction_exists(const char *name)
Checks to see if a faction exists by name.
Definition faction.c:198
const int * faction_getEnemies(int f)
Gets the list of enemies of a faction.
Definition faction.c:509
int faction_dynAdd(int base, const char *name, const char *display, const char *ai, const glColour *colour)
Dynamically add a faction.
Definition faction.c:2397
int faction_player
Definition faction.c:57
void faction_rmAlly(int f, int o)
Removes an ally from the faction's allies list.
Definition faction.c:732
int faction_isKnown(int id)
Is the faction known?
Definition faction.c:300
double faction_reputationDefault(int f)
Gets the player's default standing with a faction.
Definition faction.c:1148
const glTexture * faction_logo(int f)
Gets the faction's logo (ideally 256x256).
Definition faction.c:479
void faction_clearEnemy(int f)
Clears all the enemies of a dynamic faction.
Definition faction.c:568
void faction_rmEnemy(int f, int o)
Removes an enemy from the faction's enemies list.
Definition faction.c:636
int areEnemies(int a, int b)
Checks whether two factions are enemies.
Definition faction.c:1450
const char *const * faction_tags(int f)
Gets the tags the faction has.
Definition faction.c:439
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.
Definition faction.c:871
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.
Definition faction.c:903
const char * faction_name(int f)
Gets a factions "real" (internal) name.
Definition faction.c:331
const char * faction_shortname(int f)
Gets a factions short name (human-readable).
Definition faction.c:350
int faction_isDynamic(int id)
Is faction dynamic.
Definition faction.c:308
int areNeutral(int a, int b)
Checks whether two factions are true neutral.
Definition faction.c:1424
const int * faction_getAllies(int f)
Gets the list of allies of a faction.
Definition faction.c:539
void faction_modPlayerRaw(int f, double mod)
Modifies the player's standing without affecting others.
Definition faction.c:1026
int faction_usesHiddenJumps(int f)
Checks to see if a faction uses hidden jumps.
Definition faction.c:2356
int faction_isInvisible(int id)
Is the faction invisible?
Definition faction.c:275
const char * faction_getStandingTextAtValue(int f, double value)
Gets the player's standing in human readable form.
Definition faction.c:1269
void faction_clearAlly(int f)
Clears all the ally of a dynamic faction.
Definition faction.c:664
void faction_modPlayer(int f, double mod, const char *source)
Modifies the player's standing with a faction.
Definition faction.c:967
void faction_setReputation(int f, double value)
Sets the player's standing with a faction.
Definition faction.c:1057
int * faction_getAll(void)
Returns all faction IDs in an array (array.h).
Definition faction.c:220
void faction_modPlayerSingle(int f, double mod, const char *source)
Modifies the player's standing without affecting others.
Definition faction.c:1007
int faction_setKnown(int id, int state)
Sets the factions known state.
Definition faction.c:316
void faction_addAlly(int f, int o)
Adds an ally to the faction's allies list.
Definition faction.c:685
double faction_reputation(int f)
Gets the player's standing with a faction.
Definition faction.c:1129
int faction_isStatic(int id)
Is the faction static?
Definition faction.c:267
void faction_addEnemy(int f, int o)
Adds an enemy to the faction's enemies list.
Definition faction.c:589
int faction_get(const char *name)
Gets a faction ID by name.
Definition faction.c:209
int areAllies(int a, int b)
Checks whether two factions are allies or not.
Definition faction.c:1476
int nlua_helperTags(lua_State *L, int idx, char *const *tags)
Helper function to deal with tags.
Definition nlua.c:1118
glColour * lua_tocolour(lua_State *L, int ind)
Lua bindings to interact with colours.
Definition nlua_colour.c:87
glColour * lua_pushcolour(lua_State *L, glColour colour)
Pushes a colour on the stack.
static int factionL_setplayerstanding(lua_State *L)
Sets the player's standing with the faction.
static int factionL_modplayerraw(lua_State *L)
Modifies the player's standing with the faction.
static int factionL_setReputationOverride(lua_State *L)
Gets the overriden reputation value of a faction.
static int factionL_reputationGlobal(lua_State *L)
Gets the player's global reputation with the faction.
static int factionL_longname(lua_State *L)
Gets the faction's translated long name.
static int factionL_tags(lua_State *L)
Gets the tags a faction has.
static int factionL_playerstandingdefault(lua_State *L)
Gets the player's default standing with the faction.
static int factionL_getAll(lua_State *L)
Gets all the factions.
static int factionL_dynAlly(lua_State *L)
Adds or removes allies to a faction. Only works with dynamic factions.
static int factionL_exists(lua_State *L)
Lua bindings to deal with factions.
static int factionL_colour(lua_State *L)
Gets the faction colour.
static int factionL_hitTest(lua_State *L)
Simulates modifying the player's standing with a faction and computes how much would be changed.
static int factionL_allies(lua_State *L)
Gets the allies of the faction.
static int factionL_areenemies(lua_State *L)
Checks to see if f is an enemy of e.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
LuaFaction luaL_validfaction(lua_State *L, int ind)
Gets faction (or faction name) at index, raising an error if type isn't a valid faction.
static int factionL_logo(lua_State *L)
Gets the faction logo.
static int factionL_dynEnemy(lua_State *L)
Adds or removes enemies to a faction. Only works with dynamic factions.
static int factionL_reputationDefault(lua_State *L)
Gets the player's default reputation with the faction.
static int factionL_playerstanding(lua_State *L)
Gets the player's standing with the faction.
static int factionL_areallies(lua_State *L)
Checks to see if f is an ally of a.
static int factionL_setReputationGlobal(lua_State *L)
Overrides the player's faction global standing with a faction. Use sparingly as it overrites local st...
int nlua_loadFaction(nlua_env env)
Loads the faction library.
static int factionL_setKnown(lua_State *L)
Sets a faction's known state.
static int factionL_reputationOverride(lua_State *L)
Gets the overriden reputation value of a faction.
static int factionL_usesHiddenJumps(lua_State *L)
Gets whether or not a faction uses hidden jumps.
static int factionL_hit(lua_State *L)
Modifies the player's standing with the faction.
static int factionL_dynAdd(lua_State *L)
Adds a faction dynamically. Note that if the faction already exists as a dynamic faction,...
static int factionL_nameRaw(lua_State *L)
Gets the faction's raw / "real" (untranslated, internal) name.
static int factionL_name(lua_State *L)
Gets the faction's translated short name.
static int factionL_enemies(lua_State *L)
Gets the enemies of the faction.
static int factionL_modplayersingle(lua_State *L)
Modifies the player's standing with the faction.
static int factionL_applyLocalThreshold(lua_State *L)
Enforces the local threshold of a faction starting at a particular system. Meant to be used when comp...
int lua_isfaction(lua_State *L, int ind)
Checks to see if ind is a faction.
static const luaL_Reg faction_methods[]
LuaFaction lua_tofaction(lua_State *L, int ind)
Gets faction at index.
static int factionL_reputationText(lua_State *L)
Gets the human readable standing text correpsonding (translated).
static int factionL_isInvisible(lua_State *L)
Checks to see if a faction is invisible the player.
static int factionL_areneutral(lua_State *L)
Checks to see if two factions are truly neutral with respect to each other.
static int factionL_isStatic(lua_State *L)
Checks to see if a faction has a static standing with the player.
static int factionL_eq(lua_State *L)
__eq (equality) metamethod for factions.
static int factionL_modplayer(lua_State *L)
Modifies the player's standing with the faction.
static int factionL_isKnown(lua_State *L)
Checks to see if a faction is known by the player.
static int factionL_get(lua_State *L)
Gets the faction based on its name.
static int factionL_player(lua_State *L)
Gets the player's faction.
StarSystem * luaL_validsystem(lua_State *L, int ind)
Gets system (or system name) at index raising an error if type doesn't match.
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
Definition nlua_tex.c:129
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
Definition opengl_tex.c:891
Player_t player
Definition player.c:77
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:43