naev 0.12.6
nlua_system.c File Reference

Lua system module. More...

#include "nlua_system.h"
#include "array.h"
#include "gatherable.h"
#include "land_outfits.h"
#include "map.h"
#include "map_overlay.h"
#include "nlua_commodity.h"
#include "nlua_faction.h"
#include "nlua_jump.h"
#include "nlua_spob.h"
#include "nlua_vec2.h"
#include "nluadef.h"
#include "space.h"
Include dependency graph for nlua_system.c:

Go to the source code of this file.

Functions

static int systemL_cur (lua_State *L)
 Gets the current system.
static int systemL_get (lua_State *L)
 Gets a system.
static int systemL_getAll (lua_State *L)
 Gets all the systems. Lua return parameter: {System,...} A list of all the systems.
static int systemL_eq (lua_State *L)
 Check systems for equality.
static int systemL_name (lua_State *L)
 Returns the system's translated name.
static int systemL_nameRaw (lua_State *L)
 Returns the system's raw (untranslated) name.
static int systemL_position (lua_State *L)
 Returns the position of the system.
static int systemL_faction (lua_State *L)
 Gets system faction.
static int systemL_background (lua_State *L)
 Gets system background.
static int systemL_nebula (lua_State *L)
 Gets the system's nebula parameters.
static int systemL_interference (lua_State *L)
 Gets the system's interference level.
static int systemL_jumpdistance (lua_State *L)
 Gets jump distance from current system, or to another.
static int systemL_jumpPath (lua_State *L)
 Gets jump path from current system, or to another.
static int systemL_adjacent (lua_State *L)
 Gets all the adjacent systems to a system.
static int systemL_jumps (lua_State *L)
 Gets all the jumps in a system.
static int systemL_asteroidFields (lua_State *L)
 Gets all the asteroid fields in a system.
static int systemL_addGatherable (lua_State *L)
 Adds a gatherable object.
static int systemL_presences (lua_State *L)
 Returns the factions that have presence in a system and their respective presence values. Faction names are internal – can be passed to other functions as a faction identifier, but should not be shown to the user without being translated by _().
static int systemL_spobs (lua_State *L)
 Gets the spobs in a system.
static int systemL_presence (lua_State *L)
 Gets the presence in the system.
static int systemL_radius (lua_State *L)
 Gets the radius of the system.
static int systemL_isknown (lua_State *L)
 Checks to see if a system is known by the player.
static int systemL_setknown (lua_State *L)
 Sets a system's known state.
static int systemL_hidden (lua_State *L)
 Checks to see if a system is hidden by the player.
static int systemL_setHidden (lua_State *L)
 Sets a system to be hidden to the player.
static int systemL_markerClear (lua_State *L)
 Clears the system markers.
static int systemL_markerAdd (lua_State *L)
 Adds a system marker.
static int systemL_markerRm (lua_State *L)
 Removes a system marker.
static int systemL_reputation (lua_State *L)
 Gets the stored local reputation of a system.
static int systemL_setReputation (lua_State *L)
 Sets the stored local reputation of a system.
static int systemL_tags (lua_State *L)
 Gets the system tags.
int nlua_loadSystem (nlua_env env)
 Loads the system library.
LuaSystem lua_tosystem (lua_State *L, int ind)
 Lua system module.
LuaSystem luaL_checksystem (lua_State *L, int ind)
 Gets system at index raising an error if type doesn't match.
StarSystem * luaL_validsystem (lua_State *L, int ind)
 Gets system (or system name) at index raising an error if type doesn't match.
LuaSystem * lua_pushsystem (lua_State *L, LuaSystem sys)
 Pushes a system on the stack.
int lua_issystem (lua_State *L, int ind)
 Checks to see if ind is a system.

Variables

static const luaL_Reg system_methods []

Detailed Description

Lua system module.

Definition in file nlua_system.c.

Function Documentation

◆ lua_issystem()

int lua_issystem ( lua_State * L,
int ind )

Checks to see if ind is a system.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if there is a system at index position.

Definition at line 198 of file nlua_system.c.

◆ lua_pushsystem()

LuaSystem * lua_pushsystem ( lua_State * L,
LuaSystem sys )

Pushes a system on the stack.

Parameters
LLua state to push system onto.
sysSystem to push.
Returns
System just pushed.

Definition at line 182 of file nlua_system.c.

◆ lua_tosystem()

LuaSystem lua_tosystem ( lua_State * L,
int ind )

Lua system module.

This module allows you to use the Star Systems from Lua.

Typical example would be something like:

cur = system.cur() -- Gets current system
sys = system.get( "Gamma Polaris" )

Lua module: system

Gets system at index.

Parameters
LLua state to get system from.
indIndex position of system.
Returns
The LuaSystem at ind.

Definition at line 128 of file nlua_system.c.

◆ luaL_checksystem()

LuaSystem luaL_checksystem ( lua_State * L,
int ind )

Gets system at index raising an error if type doesn't match.

Parameters
LLua state to get system from.
indIndex position of system.
Returns
The LuaSystem at ind.

Definition at line 139 of file nlua_system.c.

◆ luaL_validsystem()

StarSystem * luaL_validsystem ( lua_State * L,
int ind )

Gets system (or system name) at index raising an error if type doesn't match.

Parameters
LLua state to get system from.
indIndex position of system.
Returns
The System at ind.

Definition at line 155 of file nlua_system.c.

◆ nlua_loadSystem()

int nlua_loadSystem ( nlua_env env)

Loads the system library.

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

Definition at line 102 of file nlua_system.c.

◆ systemL_addGatherable()

int systemL_addGatherable ( lua_State * L)
static

Adds a gatherable object.

Lua usage parameter: i = system.addGatherable( "Gold", 5, vec2.new(0,0), vec2.new(0,0) ) – creates 5 tons of gold at the origin

Lua function parameter: string commodity name of the commodity. Lua function parameter: int nb quantity of commodity in the gatherable . Lua function parameter:[opt=vec2.new(0,0)] Vec2 pos position of the gatherable. Lua function parameter:[opt=vec2.new(0,0)] Vec2 vel velocity of the gatherable. Lua function parameter:[opt] number lifelength Lifelength of the gatherable in seconds. Lua function parameter:[opt=false] boolean If true, the gatherable can only be gathered by player. Lua return parameter: int i Id of the created gatherable object.

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

Lua function: addGatherable

Definition at line 672 of file nlua_system.c.

◆ systemL_adjacent()

int systemL_adjacent ( lua_State * L)
static

Gets all the adjacent systems to a system.

Lua usage parameter: for i, s in ipairs( sys:adjacentSystems() ) do – Iterate over adjacent systems.

Lua function parameter: System s System to get adjacent systems of. Lua function parameter:[opt=false] boolean hidden Whether or not to show hidden jumps also. Lua return parameter: {System,...} An ordered table with all the adjacent systems.

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

Lua function: adjacentSystems

Definition at line 563 of file nlua_system.c.

◆ systemL_asteroidFields()

int systemL_asteroidFields ( lua_State * L)
static

Gets all the asteroid fields in a system.

Lua usage parameter: for i, s in ipairs( sys:asteroidFields() ) do – Iterate over asteroid fields

Lua function parameter: System s System to get the asteroid fields of. Lua return parameter: {Table,...} An ordered table with all the asteroid fields.

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

Lua function: asteroidFields

Definition at line 631 of file nlua_system.c.

◆ systemL_background()

int systemL_background ( lua_State * L)
static

Gets system background.

Lua function parameter: System s System to get the background of. Lua return parameter: string|nil The background of the system or nil for default.

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

Lua function: background

Definition at line 387 of file nlua_system.c.

◆ systemL_cur()

int systemL_cur ( lua_State * L)
static

Gets the current system.

Lua usage parameter: sys = system.cur() – Gets the current system

Lua return parameter: System Current system.

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

Lua function: cur

Definition at line 222 of file nlua_system.c.

◆ systemL_eq()

int systemL_eq ( lua_State * L)
static

Check systems for equality.

Allows you to use the '==' operator in Lua with systems.

Lua usage parameter: if sys == system.get( "Draygar" ) then – Do something

Lua function parameter: System s System comparing. Lua function parameter: System comp System to compare against. Lua return parameter: boolean true if both systems are the same.

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

Lua function: __eq

Definition at line 298 of file nlua_system.c.

◆ systemL_faction()

int systemL_faction ( lua_State * L)
static

Gets system faction.

Lua function parameter: System s System to get the faction of. Lua return parameter: Faction The dominant faction in the system.

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

Lua function: faction

Definition at line 371 of file nlua_system.c.

◆ systemL_get()

int systemL_get ( lua_State * L)
static

Gets a system.

Behaves differently depending on what you pass as param:

  • string : Gets the system by raw (untranslated) name.
  • spob : Gets the system by spob.

Lua usage parameter: sys = system.get( p ) – Gets system where spob 'p' is located. Lua usage parameter: sys = system.get( "Gamma Polaris" ) – Gets the system by name.

Lua function parameter: string|Spob param Read description for details. Lua return parameter: System System matching param.

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

Lua function: get

Definition at line 242 of file nlua_system.c.

◆ systemL_getAll()

int systemL_getAll ( lua_State * L)
static

Gets all the systems. Lua return parameter: {System,...} A list of all the systems.

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

Lua function: getAll

Definition at line 275 of file nlua_system.c.

◆ systemL_hidden()

int systemL_hidden ( lua_State * L)
static

Checks to see if a system is hidden by the player.

Lua usage parameter: b = s:hidden()

Lua function parameter: System s System to check if the player knows. Lua return parameter: boolean true if the player knows the system.

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

Lua function: hidden

Definition at line 916 of file nlua_system.c.

◆ systemL_interference()

int systemL_interference ( lua_State * L)
static

Gets the system's interference level.

Lua function parameter: System s System to get interference of. Lua return parameter: number The amount of interference (in percent).

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

Lua function: interference

Definition at line 422 of file nlua_system.c.

◆ systemL_isknown()

int systemL_isknown ( lua_State * L)
static

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

Lua usage parameter: b = s:known()

Lua function parameter: System s System to check if the player knows. Lua return parameter: boolean true if the player knows the system.

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

Lua function: known

Definition at line 853 of file nlua_system.c.

◆ systemL_jumpdistance()

int systemL_jumpdistance ( lua_State * L)
static

Gets jump distance from current system, or to another.

Does different things depending on the parameter type:

  • nil : Gets distance to current system.
  • string : Gets distance to system matching name.
  • system : Gets distance to system

Lua usage parameter: d = sys:jumpDist() – Distance the current system to sys. Lua usage parameter: d = sys:jumpDist( "Draygar" ) – Distance from sys to system Draygar. Lua usage parameter: d = sys:jumpDist( another_sys ) – Distance from sys to another_sys.

Lua function parameter: System s Starting system. Lua function parameter: nil|string|Goal system param See description. Lua function parameter:[opt=false] boolean hidden Whether or not to consider hidden jumps. Lua function parameter:[opt=false] boolean known Whether or not to consider only jumps known by the player. Lua return parameter: number Number of jumps to system or math.huge if no path found.

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

Lua function: jumpDist

Definition at line 451 of file nlua_system.c.

◆ systemL_jumpPath()

int systemL_jumpPath ( lua_State * L)
static

Gets jump path from current system, or to another.

Does different things depending on the parameter type:

  • nil : Gets path to current system.
  • string : Gets path to system with the given raw (untranslated) name.
  • system : Gets path to system

Lua usage parameter: jumps = sys:jumpPath( system.cur() ) – Path from sys to current system. Lua usage parameter: jumps = sys:jumpPath( "Draygar" ) – Path from sys to Draygar. Lua usage parameter: jumps = system.jumpPath( "Draygar", another_sys ) – Path from Draygar to another_sys.

Lua function parameter: System s Starting system. Lua function parameter: System goal Goal system param See description. Lua function parameter:[opt=false] boolean hidden Whether or not to consider hidden jumps. Lua return parameter: {Jump,...} Table of jumps.

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

Lua function: jumpPath

Definition at line 510 of file nlua_system.c.

◆ systemL_jumps()

int systemL_jumps ( lua_State * L)
static

Gets all the jumps in a system.

Lua usage parameter: for i, s in ipairs( sys:jumps() ) do – Iterate over jumps.

Lua function parameter: System s System to get the jumps of. Lua function parameter:[opt=false] boolean exitonly Whether to exclude exit-only jumps. Lua return parameter: {Jump,...} An ordered table with all the jumps.

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

Lua function: jumps

Definition at line 598 of file nlua_system.c.

◆ systemL_markerAdd()

int systemL_markerAdd ( lua_State * L)
static

Adds a system marker.

Lua usage parameter: mrk_id = system.markerAdd( vec2.new( 50, 30 ), "Hello" ) – Creates a marker at (50,30)

Lua function parameter: Vec2 v Position to display marker at. Lua function parameter:[opt] string str String to display next to marker. Lua function parameter:[opt] number If specified, changes the marker to circle type marker and specifies the radius of the circle to use. Lua return parameter: number The id of the marker.

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

Lua function: markerAdd

Definition at line 973 of file nlua_system.c.

◆ systemL_markerClear()

int systemL_markerClear ( lua_State * L)
static

Clears the system markers.

This can be dangerous and clash with other missions, do not try this at home kids.

Lua usage parameter: system.markerClear()

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

Lua function: markerClear

Definition at line 953 of file nlua_system.c.

◆ systemL_markerRm()

int systemL_markerRm ( lua_State * L)
static

Removes a system marker.

Lua usage parameter: system.markerRm( mrk_id ) – Removes a marker by mrk_id

Lua function parameter: number id ID of the marker to remove.

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

Lua function: markerRm

Definition at line 1002 of file nlua_system.c.

◆ systemL_name()

int systemL_name ( lua_State * L)
static

Returns the system's translated name.

This translated name should be used for display purposes (e.g. messages). It cannot be used as an identifier for the system; for that, use system.nameRaw() instead.

Lua usage parameter: name = sys:name() – Equivalent to _(sys:nameRaw())

Lua function parameter: System s System to get the translated name of. Lua return parameter: string The translated name of the system.

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

Lua function: name

Definition at line 323 of file nlua_system.c.

◆ systemL_nameRaw()

int systemL_nameRaw ( lua_State * L)
static

Returns the system's raw (untranslated) name.

This untranslated name should be used for identification purposes (e.g. can be passed to system.get()). It should not be used directly for display purposes without manually translating it with _().

Lua usage parameter: name = sys:nameRaw()

Lua function parameter: System s System to get the raw name of. Lua return parameter: string The raw name of the system.

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

Lua function: nameRaw

Definition at line 357 of file nlua_system.c.

◆ systemL_nebula()

int systemL_nebula ( lua_State * L)
static

Gets the system's nebula parameters.

Lua usage parameter: density, volatility = sys:nebula()

Lua function parameter: System s System to get nebula parameters from. Lua return parameter: number The density of the system. Lua return parameter: number The amount of nebula damage done per second.

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

Lua function: nebula

Definition at line 406 of file nlua_system.c.

◆ systemL_position()

int systemL_position ( lua_State * L)
static

Returns the position of the system.

Lua function parameter: System s System to get position of. Lua return parameter: vec2 Position of the system.

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

Lua function: pos

Definition at line 337 of file nlua_system.c.

◆ systemL_presence()

int systemL_presence ( lua_State * L)
static

Gets the presence in the system.

Possible parameters are besides a faction:

  • "all": Gets the sum of all the presences.
  • "friendly": Gets the sum of all the friendly presences.
  • "hostile": Gets the sum of all the hostile presences.
  • "neutral": Gets the sum of all the neutral presences.

Lua usage parameter: p = sys:presence( f ) – Gets the presence of a faction f Lua usage parameter: p = sys:presence( "all" ) – Gets the sum of all the presences Lua usage parameter: if sys:presence("friendly") > sys:presence("hostile") then – Checks to see if the system is dominantly friendly

Lua function parameter: System s System to get presence level of. Lua return parameter: number The presence level in sys (absolute value).

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

Lua function: presence

Definition at line 769 of file nlua_system.c.

◆ systemL_presences()

int systemL_presences ( lua_State * L)
static

Returns the factions that have presence in a system and their respective presence values. Faction names are internal – can be passed to other functions as a faction identifier, but should not be shown to the user without being translated by _().

Lua usage parameter: if sys:presences()["Empire"] then – Checks to see if Empire has ships in the system Lua usage parameter: if sys:presences()[faction.get("Dvaered"):nameRaw()] then – Checks to see if the Dvaered have ships in the system

Lua function parameter: System s System to get the factional presences of. Lua return parameter: {Faction,...} A table with the factions that have presence in the system.

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

Lua function: presences

Definition at line 710 of file nlua_system.c.

◆ systemL_radius()

int systemL_radius ( lua_State * L)
static

Gets the radius of the system.

This is the radius of the circle which all the default jumps will be on.

Lua usage parameter: r = s:radius()

Lua function parameter: System s System to get the radius of. Lua return parameter: number The radius of the system.

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

Lua function: radius

Definition at line 837 of file nlua_system.c.

◆ systemL_reputation()

int systemL_reputation ( lua_State * L)
static

Gets the stored local reputation of a system.

Lua function parameter: System s System to get the stored local reputation of. Lua function parameter:[opt=nil] Faction f Faction to get reputation of or nil to get the local reputation of all factions in the system. Lua return parameter: number|table|nil Either a number if the faction has a reputation in the system, a table if the faction wasn't set, or nil if nothing was found.

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

Lua function: reputation

Definition at line 1020 of file nlua_system.c.

◆ systemL_setHidden()

int systemL_setHidden ( lua_State * L)
static

Sets a system to be hidden to the player.

Lua usage parameter: s:setHidden( true )

Lua function parameter: System s System to check if the player knows. Lua function parameter: boolean hide Whether or not to hide the system.

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

Lua function: hidden

Definition at line 932 of file nlua_system.c.

◆ systemL_setknown()

int systemL_setknown ( lua_State * L)
static

Sets a system's known state.

Lua usage parameter: s:setKnown( false ) – Makes system unknown. Lua function parameter: System s System to set known. Lua function parameter:[opt=false] boolean b Whether or not to set as known. Lua function parameter:[opt=false] boolean r Whether or not to iterate over the system's spobs and jump points.

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

Lua function: setKnown

Definition at line 870 of file nlua_system.c.

◆ systemL_setReputation()

int systemL_setReputation ( lua_State * L)
static

Sets the stored local reputation of a system.

Lua function parameter: System s System to set the stored local reputation of. Lua function parameter: Faction f Faction to set the local reputation of. Lua function parameter: number value Value to set the local reputation to.

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

Lua function: setReputation

Definition at line 1052 of file nlua_system.c.

◆ systemL_spobs()

int systemL_spobs ( lua_State * L)
static

Gets the spobs in a system.

Lua usage parameter: for key, spob in ipairs( sys:spobs() ) do – Iterate over spobs in system Lua usage parameter: if #sys:spobs() > 0 then – System has spobs

Lua function parameter: System s System to get spobs of Lua return parameter: {Spob,...} A table with all the spobs

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

Lua function: spobs

Definition at line 739 of file nlua_system.c.

◆ systemL_tags()

int systemL_tags ( lua_State * L)
static

Gets the system tags.

Lua usage parameter: if system.cur():tags["fancy"] then – Has "fancy" tag

Lua function parameter: System s System to get tags of. Lua function parameter:[opt=nil] string tag Tag to check if exists. Lua return parameter: table|boolean Table of tags where the name is the key and true is the value or a boolean value if a string is passed as the second parameter indicating whether or not the specified tag exists.

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

Lua function: tags

Definition at line 1076 of file nlua_system.c.

Variable Documentation

◆ system_methods

const luaL_Reg system_methods[]
static

System metatable methods.

Definition at line 61 of file nlua_system.c.