naev 0.11.5
nlua_faction.c File Reference

Handles the Lua faction bindings. More...

#include "nlua_faction.h"
#include "array.h"
#include "faction.h"
#include "log.h"
#include "nlua_colour.h"
#include "nlua_tex.h"
#include "nluadef.h"

Go to the source code of this file.

Functions

static LuaFaction luaL_validfactionSilent (lua_State *L, int ind)
 
static int factionL_exists (lua_State *L)
 Lua bindings to deal with factions.
 
static int factionL_get (lua_State *L)
 Gets the faction based on its name.
 
static int factionL_getAll (lua_State *L)
 Gets all the factions.
 
static int factionL_player (lua_State *L)
 Gets the player's faction.
 
static int factionL_eq (lua_State *L)
 __eq (equality) metamethod for factions.
 
static int factionL_name (lua_State *L)
 Gets the faction's translated short name.
 
static int factionL_nameRaw (lua_State *L)
 Gets the faction's raw / "real" (untranslated, internal) name.
 
static int factionL_longname (lua_State *L)
 Gets the faction's translated long name.
 
static int factionL_areenemies (lua_State *L)
 Checks to see if f is an enemy of e.
 
static int factionL_areallies (lua_State *L)
 Checks to see if f is an ally of a.
 
static int factionL_usesHiddenJumps (lua_State *L)
 Gets whether or not a faction uses hidden jumps.
 
static int factionL_modplayer (lua_State *L)
 Modifies the player's standing with the faction.
 
static int factionL_modplayersingle (lua_State *L)
 Modifies 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_setplayerstanding (lua_State *L)
 Sets the player's standing with the faction.
 
static int factionL_playerstanding (lua_State *L)
 Gets the player's standing with the faction.
 
static int factionL_playerstandingdefault (lua_State *L)
 Gets the player's default standing with the faction.
 
static int factionL_enemies (lua_State *L)
 Gets the enemies of the faction.
 
static int factionL_allies (lua_State *L)
 Gets the allies of the faction.
 
static int factionL_logo (lua_State *L)
 Gets the faction logo.
 
static int factionL_colour (lua_State *L)
 Gets the faction colour.
 
static int factionL_isKnown (lua_State *L)
 Checks to see if a faction is known by the player.
 
static int factionL_setKnown (lua_State *L)
 Sets a faction's known state.
 
static int factionL_isInvisible (lua_State *L)
 Checks to see if a faction is invisible the player.
 
static int factionL_isStatic (lua_State *L)
 Checks to see if a faction has a static standing with the player.
 
static int factionL_tags (lua_State *L)
 Gets the tags a faction has.
 
static int factionL_dynAdd (lua_State *L)
 Adds a faction dynamically. Note that if the faction already exists as a dynamic faction, the existing one is returned.
 
static int factionL_dynAlly (lua_State *L)
 Adds or removes allies to a faction. Only works with dynamic factions.
 
static int factionL_dynEnemy (lua_State *L)
 Adds or removes enemies to a faction. Only works with dynamic factions.
 
int nlua_loadFaction (nlua_env env)
 Loads the faction library.
 
LuaFaction lua_tofaction (lua_State *L, int ind)
 Gets faction at index.
 
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.
 
LuaFaction * lua_pushfaction (lua_State *L, LuaFaction faction)
 Pushes a faction on the stack.
 
int lua_isfaction (lua_State *L, int ind)
 Checks to see if ind is a faction.
 

Variables

static const luaL_Reg faction_methods []
 

Detailed Description

Handles the Lua faction bindings.

These bindings control the factions.

Definition in file nlua_faction.c.

Function Documentation

◆ factionL_allies()

static int factionL_allies ( lua_State * L)
static

Gets the allies of the faction.

Lua usage parameter: for k,v in pairs(f:allies()) do – Iterate over faction allies

Lua function parameter: Faction f Faction to get allies of. Lua return parameter: {Faction,...} A table containing the allies of the faction.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: allies

Definition at line 526 of file nlua_faction.c.

◆ factionL_areallies()

static int factionL_areallies ( lua_State * L)
static

Checks to see if f is an ally of a.

Lua usage parameter: if f:areAllies( faction.get( "Pirate" ) ) then

Lua function parameter: Faction f Faction to check against. Lua function parameter: faction a Faction to check if is an enemy. Lua return parameter: boolean true if they are enemies, false if they aren't.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: areAllies

Definition at line 369 of file nlua_faction.c.

◆ factionL_areenemies()

static int factionL_areenemies ( lua_State * L)
static

Checks to see if f is an enemy of e.

Lua usage parameter: if f:areEnemies( faction.get( "Dvaered" ) ) then

Lua function parameter: Faction f Faction to check against. Lua function parameter: Faction e Faction to check if is an enemy. Lua return parameter: string true if they are enemies, false if they aren't.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: areEnemies

Definition at line 351 of file nlua_faction.c.

◆ factionL_colour()

static int factionL_colour ( lua_State * L)
static

Gets the faction colour.

Lua function parameter: Faction f Faction to get colour from. Lua return parameter: Colour|nil The faction colour or nil if not applicable.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: colour

Definition at line 580 of file nlua_faction.c.

◆ factionL_dynAdd()

static int factionL_dynAdd ( lua_State * L)
static

Adds a faction dynamically. Note that if the faction already exists as a dynamic faction, the existing one is returned.

Note
Defaults to known.

Lua function parameter: Faction|nil base Faction to base it off of or nil for new faction. Lua function parameter: string name Name to give the faction. Lua function parameter:[opt] string display Display name to give the faction. Lua function parameter:[opt] table params Table of parameters. Options include "ai" (string) to set the AI to use, "clear_allies" (boolean) to clear all allies, "clear_enemies" (boolean) to clear all enemies, "player" (number) to set the default player standing, "colour" (string|colour) which represents the factional colours.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: dynAdd

Definition at line 687 of file nlua_faction.c.

◆ factionL_dynAlly()

static int factionL_dynAlly ( lua_State * L)
static

Adds or removes allies to a faction. Only works with dynamic factions.

Lua function parameter: Faction fac Faction to add ally to. Lua function parameter: Faction ally Faction to add as an ally. Lua function parameter:[opt=false] boolean remove Whether or not to remove the ally from the faction instead of adding it.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: dynAlly

Definition at line 773 of file nlua_faction.c.

◆ factionL_dynEnemy()

static int factionL_dynEnemy ( lua_State * L)
static

Adds or removes enemies to a faction. Only works with dynamic factions.

Lua function parameter: Faction fac Faction to add enemy to. Lua function parameter: Faction enemy Faction to add as an enemy. Lua function parameter:[opt=false] boolean remove Whether or not to remove the enemy from the faction instead of adding it.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: dynEnemy

Definition at line 797 of file nlua_faction.c.

◆ factionL_enemies()

static int factionL_enemies ( lua_State * L)
static

Gets the enemies of the faction.

Lua usage parameter: for k,v in pairs(f:enemies()) do – Iterates over enemies

Lua function parameter: Faction f Faction to get enemies of. Lua return parameter: {Faction,...} A table containing the enemies of the faction.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: enemies

Definition at line 501 of file nlua_faction.c.

◆ factionL_eq()

static int factionL_eq ( lua_State * L)
static

__eq (equality) metamethod for factions.

You can use the '==' operator within Lua to compare factions with this.

Lua usage parameter: if f == faction.get( "Dvaered" ) then

Lua function parameter: Faction f Faction comparing. Lua function parameter: Faction comp faction to compare against. Lua return parameter: boolean true if both factions are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 271 of file nlua_faction.c.

◆ factionL_exists()

static int factionL_exists ( lua_State * L)
static

Lua bindings to deal with factions.

Use like:

f = faction.get( "Empire" )
if f:playerStanding() < 0 then
-- player is hostile to "Empire"
end
Player_t player
Definition player.c:74

Lua module: faction

Gets a faction if it exists.

Lua usage parameter: f = faction.exists( "Empire" )

Lua function parameter: string name Name of the faction to get if exists. Lua return parameter: Faction The faction matching name or nil if not matched.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: exists

Definition at line 126 of file nlua_faction.c.

◆ factionL_get()

static int factionL_get ( lua_State * L)
static

Gets the faction based on its name.

Lua usage parameter: f = faction.get( "Empire" )

Lua function parameter: string name Name of the faction to get. Lua return parameter: Faction The faction matching name.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: get

Definition at line 145 of file nlua_faction.c.

◆ factionL_getAll()

static int factionL_getAll ( lua_State * L)
static

Gets all the factions.

Lua return parameter: {Faction,...} An ordered table containing all of the factions.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getAll

Definition at line 158 of file nlua_faction.c.

◆ factionL_isInvisible()

static int factionL_isInvisible ( lua_State * L)
static

Checks to see if a faction is invisible the player.

Lua usage parameter: b = f:invisible()

Lua function parameter: Faction f Faction to check if is invisible to the player. Lua return parameter: boolean true if the faction is invisible to the player.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: invisible

Definition at line 631 of file nlua_faction.c.

◆ factionL_isKnown()

static int factionL_isKnown ( lua_State * L)
static

Checks to see if a faction is known by the player.

Lua usage parameter: b = f:known()

Lua function parameter: Faction f Faction to check if the player knows. Lua return parameter: boolean true if the player knows the faction.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: known

Definition at line 599 of file nlua_faction.c.

◆ factionL_isStatic()

static int factionL_isStatic ( lua_State * L)
static

Checks to see if a faction has a static standing with the player.

Lua usage parameter: b = f:static()

Lua function parameter: Faction f Faction to check if has a static standing to the player. Lua return parameter: boolean true if the faction is static to the player.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: static

Definition at line 647 of file nlua_faction.c.

◆ factionL_logo()

static int factionL_logo ( lua_State * L)
static

Gets the faction logo.

Lua function parameter: Faction f Faction to get logo from. Lua return parameter: Tex The faction logo or nil if not applicable.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: logo

Definition at line 563 of file nlua_faction.c.

◆ factionL_longname()

static int factionL_longname ( lua_State * L)
static

Gets the faction's translated long name.

This translated name should be used for display purposes (e.g. messages) where the longer version of the faction's display name should be used. It cannot be used as an identifier for the faction; for that, use faction.nameRaw() instead.

Lua usage parameter: longname = f:longname() Lua function parameter: Faction f Faction to get long name of. Lua return parameter: string The long name of the faction (translated).

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: longname

Definition at line 334 of file nlua_faction.c.

◆ factionL_modplayer()

static int factionL_modplayer ( lua_State * L)
static

Modifies the player's standing with the faction.

Also modifies standing with allies and enemies of the faction.

Lua usage parameter: f:modPlayer( -5 ) – Lowers faction by 5

Lua function parameter: Faction f Faction to modify player's standing with. Lua function parameter: number mod The modifier to modify faction by.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: modPlayer

Definition at line 388 of file nlua_faction.c.

◆ factionL_modplayerraw()

static int factionL_modplayerraw ( lua_State * L)
static

Modifies the player's standing with the faction.

Does not affect other faction standings and is not processed by the faction Lua script, so it indicates exactly the amount to be changed.

Lua usage parameter: f:modPlayerRaw( 10 )

Lua function parameter: Faction f Faction to modify player's standing with. Lua function parameter: number mod The modifier to modify faction by.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: modPlayerRaw

Definition at line 427 of file nlua_faction.c.

◆ factionL_modplayersingle()

static int factionL_modplayersingle ( lua_State * L)
static

Modifies the player's standing with the faction.

Does not affect other faction standings.

Lua usage parameter: f:modPlayerSingle( 10 )

Lua function parameter: Faction f Faction to modify player's standing with. Lua function parameter: number mod The modifier to modify faction by.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: modPlayerSingle

Definition at line 407 of file nlua_faction.c.

◆ factionL_name()

static int factionL_name ( lua_State * L)
static

Gets the faction's translated short name.

This translated name should be used for display purposes (e.g. messages) where the shorter version of the faction's display name should be used. It cannot be used as an identifier for the faction; for that, use faction.nameRaw() instead.

Lua usage parameter: shortname = f:name()

Lua function parameter: Faction f The faction to get the name of. Lua return parameter: string The name of the faction.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: name

Definition at line 293 of file nlua_faction.c.

◆ factionL_nameRaw()

static int factionL_nameRaw ( lua_State * L)
static

Gets the faction's raw / "real" (untranslated, internal) name.

This untranslated name should be used for identification purposes (e.g. can be passed to faction.get()). It should not be used for display purposes; for that, use faction.name() or faction.longname() instead.

Lua usage parameter: name = f:nameRaw()

Lua function parameter: Faction f The faction to get the name of. Lua return parameter: string The name of the faction.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: nameRaw

Definition at line 314 of file nlua_faction.c.

◆ factionL_player()

static int factionL_player ( lua_State * L)
static

Gets the player's faction.

Lua usage parameter: pf = faction.player()

Lua return parameter: Faction The player's faction.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: player

Definition at line 178 of file nlua_faction.c.

◆ factionL_playerstanding()

static int factionL_playerstanding ( lua_State * L)
static

Gets the player's standing with the faction.

Lua usage parameter: if f:playerStanding() > 70 then – Player is an ally Lua usage parameter: _v, str = f:playerStanding(50) – Get the standing text for a value of 50

Lua function parameter: Faction f Faction to get player's standing with. Lua function parameter: number value Faction standing value to get string of. Lua return parameter: number The value of the standing and the human readable string. Lua return parameter: string The text corresponding to the standing (translated).

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: playerStanding

Definition at line 464 of file nlua_faction.c.

◆ factionL_playerstandingdefault()

static int factionL_playerstandingdefault ( lua_State * L)
static

Gets the player's default standing with the faction.

Lua function parameter: Faction f Faction to get player's default standing with. Lua return parameter: number The value of the standing and the human readable string.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: playerStandingDefault

Definition at line 484 of file nlua_faction.c.

◆ factionL_setKnown()

static int factionL_setKnown ( lua_State * L)
static

Sets a faction's known state.

Lua usage parameter: f:setKnown( false ) – Makes faction unknown. Lua function parameter: Faction f Faction to set known. Lua function parameter:[opt=false] boolean b Whether or not to set as known.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setKnown

Definition at line 614 of file nlua_faction.c.

◆ factionL_setplayerstanding()

static int factionL_setplayerstanding ( lua_State * L)
static

Sets the player's standing with the faction.

Lua usage parameter: f:setPlayerStanding(70) – Make player an ally

Lua function parameter: Faction f Faction to set the player's standing for. Lua function parameter: number value Value to set the player's standing to (from -100 to 100).

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setPlayerStanding

Definition at line 444 of file nlua_faction.c.

◆ factionL_tags()

static int factionL_tags ( lua_State * L)
static

Gets the tags a faction has.

Lua usage parameter: for k,v in ipairs(f:tags()) do ... end Lua usage parameter: if f:tags().likes_cheese then ... end Lua function parameter: Faction f Faction to get tags of. Lua return parameter: table A table containing all the tags of the faction.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: tags

Definition at line 663 of file nlua_faction.c.

◆ factionL_usesHiddenJumps()

static int factionL_usesHiddenJumps ( lua_State * L)
static

Gets whether or not a faction uses hidden jumps.

Lua function parameter: Faction f Faction to get whether or not they use hidden jumps. Lua return parameter: boolean true if the faction uses hidden jumps, false otherwise.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: usesHiddenJumps

Definition at line 549 of file nlua_faction.c.

◆ lua_isfaction()

int lua_isfaction ( lua_State * L,
int ind )

Checks to see if ind is a faction.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a faction.

Definition at line 243 of file nlua_faction.c.

◆ lua_pushfaction()

LuaFaction * lua_pushfaction ( lua_State * L,
LuaFaction faction )

Pushes a faction on the stack.

Parameters
LLua state to push faction into.
factionFaction to push.
Returns
Newly pushed faction.

Definition at line 228 of file nlua_faction.c.

◆ lua_tofaction()

LuaFaction lua_tofaction ( lua_State * L,
int ind )

Gets faction at index.

Parameters
LLua state to get faction from.
indIndex position to find the faction.
Returns
Faction found at the index in the state.

Definition at line 191 of file nlua_faction.c.

◆ luaL_validfaction()

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.

Parameters
LLua state to get faction from.
indIndex position to find the faction.
Returns
Faction found at the index in the state.

Definition at line 213 of file nlua_faction.c.

◆ luaL_validfactionSilent()

static LuaFaction luaL_validfactionSilent ( lua_State * L,
int ind )
static

Definition at line 196 of file nlua_faction.c.

◆ nlua_loadFaction()

int nlua_loadFaction ( nlua_env env)

Loads the faction library.

Parameters
envEnvironment to load faction library into.
Returns
0 on success.

Definition at line 98 of file nlua_faction.c.

Variable Documentation

◆ faction_methods

const luaL_Reg faction_methods[]
static

Faction metatable methods.

Definition at line 58 of file nlua_faction.c.