Naev

Module system

Lua system module.

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

Typical example would be something like:

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

Functions

cur () Gets the current system.
get (param) Gets a system.
getAll () Gets all the systems.
__eq (s, comp) Check systems for equality.
name (s) Returns the system's translated name.
nameRaw (s) Returns the system's raw (untranslated) name.
faction (s) Gets system faction.
nebula (s) Gets the system's nebula parameters.
jumpDist (s, system[, hidden=false[, known=false]]) Gets jump distance from current system, or to another.
jumpPath (s, system[, hidden=false]) Gets jump path from current system, or to another.
adjacentSystems (s[, hidden=false]) Gets all the adjacent systems to a system.
jumps (s[, exitonly=false]) Gets all the jumps in a system.
asteroid () Gets a random asteroid in the current system
asteroidPos (anchor, asteroid) Gets the position and velocity of an asteroid
asteroidDestroyed (anchor, asteroid) Sees if a given asteroid has been destroyed recently
addGatherable (commodity, nb, pos, vel[, lifelength]) Adds a gatherable object
presences (s) Returns the factions that have presence in a system and their respective presence values.
planets (s) Gets the planets in a system.
presence (s) Gets the presence in the system.
radius (s) Gets the radius of the system.
known (s) Checks to see if a system is known by the player.
setKnown (s[, b=false[, r=false]]) Sets a system's known state.
mrkClear () Clears the system markers.
mrkAdd (str, v) Adds a system marker.
mrkRm (id) Removes a system marker.


Functions

cur ()
Gets the current system. ()

Returns:

    System Current system.

Usage:

    sys = system.cur() -- Gets the current system
get (param)
Gets a system.

Behaves differently depending on what you pass as param:
- string : Gets the system by raw (untranslated) name.
- planet : Gets the system by planet.
( param )

Parameters:

  • param string or Planet Read description for details.

Returns:

    System System matching param.

Usage:

  • sys = system.get( p ) -- Gets system where planet 'p' is located.
  • sys = system.get( "Gamma Polaris" ) -- Gets the system by name.
getAll ()
Gets all the systems. ()

Returns:

    {System,...} A list of all the systems.
__eq (s, comp)
Check systems for equality.

Allows you to use the '==' operator in Lua with systems. ( s, comp )

Parameters:

  • s System System comparing.
  • comp System System to compare against.

Returns:

    boolean true if both systems are the same.

Usage:

    if sys == system.get( "Draygar" ) then -- Do something
name (s)
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. ( s )

Parameters:

  • s System System to get the translated name of.

Returns:

    string The translated name of the system.

Usage:

    name = sys:name() -- Equivalent to `_(sys:nameRaw())`
nameRaw (s)
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 _(). ( s )

Parameters:

  • s System System to get the raw name of.

Returns:

    string The raw name of the system.

Usage:

    name = sys:nameRaw()
faction (s)
Gets system faction. ( s )

Parameters:

  • s System System to get the faction of.

Returns:

    Faction The dominant faction in the system.
nebula (s)
Gets the system's nebula parameters. ( s )

Parameters:

  • s System System to get nebula parameters from.

Returns:

  1. number The density of the system.
  2. number The volatility of the system.

Usage:

    density, volatility = sys:nebula()
jumpDist (s, system[, hidden=false[, known=false]])
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 ( s, param, hidden, known )

Parameters:

  • s System Starting system.
  • system nil, string or Goal param See description.
  • hidden boolean Whether or not to consider hidden jumps. (default false)
  • known boolean Whether or not to consider only jumps known by the player. (default false)

Returns:

    number Number of jumps to system.

Usage:

  • d = sys:jumpDist() -- Distance from sys to current system.
  • d = sys:jumpDist( "Draygar" ) -- Distance from sys to system Draygar.
  • d = sys:jumpDist( another_sys ) -- Distance from sys to another_sys.
jumpPath (s, system[, hidden=false])
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
( s, param, hidden )

Parameters:

  • s System Starting system.
  • system nil, string or Goal param See description.
  • hidden boolean Whether or not to consider hidden jumps. (default false)

Returns:

    {Jump,...} Table of jumps.

Usage:

  • jumps = sys:jumpPath() -- Path from sys to current system.
  • jumps = sys:jumpPath( "Draygar" ) -- Path from sys to Draygar.
  • jumps = system.jumpPath( "Draygar", another_sys ) -- Path from Draygar to another_sys.
adjacentSystems (s[, hidden=false])
Gets all the adjacent systems to a system. ( s, hidden )

Parameters:

  • s System System to get adjacent systems of.
  • hidden boolean Whether or not to show hidden jumps also. (default false)

Returns:

    {System,...} An ordered table with all the adjacent systems.

Usage:

    for i, s in ipairs( sys:adjacentSystems() ) do -- Iterate over adjacent systems.
jumps (s[, exitonly=false])
Gets all the jumps in a system. ( s, exitonly )

Parameters:

  • s System System to get the jumps of.
  • exitonly boolean Whether to exclude exit-only jumps. (default false)

Returns:

    {Jump,...} An ordered table with all the jumps.

Usage:

    for i, s in ipairs( sys:jumps() ) do -- Iterate over jumps.
asteroid ()
Gets a random asteroid in the current system ()

Returns:

  1. int anchor Id of an asteroid anchor.
  2. int asteroid Id of an asteroid of this anchor.

Usage:

    anchor, ast = system.asteroid()
asteroidPos (anchor, asteroid)
Gets the position and velocity of an asteroid ()

Parameters:

  • anchor int Id of the asteroid anchor.
  • asteroid int Id of the asteroid of this anchor.

Returns:

  1. Vec2 pos position of the asteroid.
  2. Vec2 vel velocity of the asteroid.

Usage:

    pos = system.asteroidPos( anchor, ast )
asteroidDestroyed (anchor, asteroid)
Sees if a given asteroid has been destroyed recently ()

Parameters:

  • anchor int Id of the asteroid anchor.
  • asteroid int Id of the asteroid of this anchor.

Returns:

    bool i true if the asteroid was destroyed.

Usage:

    i = system.asteroidDestroyed( anchor, ast )
addGatherable (commodity, nb, pos, vel[, lifelength])
Adds a gatherable object ( commodity, nb, pos, vel, lifelength )

Parameters:

  • commodity string name of the commodity.
  • nb int quantity of commodity in the gatherable .
  • pos Vec2 position of the gatherable.
  • vel Vec2 velocity of the gatherable.
  • lifelength number Lifelength of the gatherable. (optional)

Returns:

    int i Id of the created gatherable object.

Usage:

    i = system.addGatherable( "Gold", 5, vec2.new(0,0), vec2.new(0,0) ) -- creates 5 tons of gold at the origin
presences (s)
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 _(). ( s )

Parameters:

  • s System System to get the factional presences of.

Returns:

    {Faction,...} A table with the factions that have presence in the system.

Usage:

  • if sys:presences()["Empire"] then -- Checks to see if Empire has ships in the system
  • if sys:presences()[faction.get("Pirate")] then -- Checks to see if the Pirates have ships in the system
planets (s)
Gets the planets in a system. ( s )

Parameters:

  • s System System to get planets of

Returns:

    {Planet,...} A table with all the planets

Usage:

  • for key, planet in ipairs( sys:planets() ) do -- Iterate over planets in system
  • if \#sys:planets() > 0 then -- System has planets
presence (s)
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.
( s )

Parameters:

  • s System System to get presence level of.

Returns:

    number The presence level in sys (absolute value).

Usage:

  • p = sys:presence( f ) -- Gets the presence of a faction f
  • p = sys:presence( "all" ) -- Gets the sum of all the presences
  • if sys:presence("friendly") > sys:presence("hostile") then -- Checks to see if the system is dominantly friendly
radius (s)
Gets the radius of the system.

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

Parameters:

  • s System System to get the radius of.

Returns:

    number The radius of the system.

Usage:

    r = s:radius()
known (s)
Checks to see if a system is known by the player. ( s )

Parameters:

  • s System System to check if the player knows.

Returns:

    boolean true if the player knows the system.

Usage:

    b = s:known()
setKnown (s[, b=false[, r=false]])
Sets a system's known state. ( s, b, r )

Parameters:

  • s System System to set known.
  • b boolean Whether or not to set as known. (default false)
  • r boolean Whether or not to iterate over the system's assets and jump points. (default false)

Usage:

    s:setKnown( false ) -- Makes system unknown.
mrkClear ()
Clears the system markers.

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

Usage:

    system.mrkClear()
mrkAdd (str, v)
Adds a system marker. ( str, v )

Parameters:

  • str string String to display next to marker.
  • v Vec2 Position to display marker at.

Returns:

    number The id of the marker.

Usage:

    mrk_id = system.mrkAdd( "Hello", vec2.new( 50, 30 ) ) -- Creates a marker at (50,30)
mrkRm (id)
Removes a system marker. ( id )

Parameters:

  • id number ID of the marker to remove.

Usage:

    system.mrkRm( mrk_id ) -- Removes a marker by mrk_id
generated by LDoc 1.4.6 Last updated 2020-11-30 06:21:28