Module system
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" )
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. |
pos (s) | Returns the position of the system. |
nameRaw (s) | Returns the system's raw (untranslated) name. |
faction (s) | Gets system faction. |
background (s) | Gets system background. |
nebula (s) | Gets the system's nebula parameters. |
interference (s) | Gets the system's interference level. |
jumpDist (s, system[, hidden=false[, known=false]]) | Gets jump distance from current system, or to another. |
jumpPath (s, goal[, 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. |
asteroidFields (s) | Gets all the asteroid fields in a system. |
addGatherable (commodity, nb[, pos=vec2.new(0[, vel=vec2.new(0[, lifelength[, If=false]]]]) | Adds a gatherable object |
presences (s) | Returns the factions that have presence in a system and their respective presence values. |
spobs (s) | Gets the spobs 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. |
hidden (s) | Checks to see if a system is hidden by the player. |
hidden (s, hide) | Sets a system to be hidden to the player. |
markerClear () | Clears the system markers. |
markerAdd (v[, str[, If]]) | Adds a system marker. |
markerRm (id) | Removes a system marker. |
reputation (s[, f=nil]) | Gets the stored local reputation of a system. |
setReputation (s, f, value) | Sets the stored local reputation of a system. |
tags (s[, tag=nil]) | Gets the system tags. |
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. <br/> - spob : Gets the system by spob. <br/>
Parameters:
- param string or Spob Read description for details.
Returns:
-
System
System matching param.
Usage:
sys = system.get( p ) -- Gets system where spob '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.
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.
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())`
- pos (s)
-
Returns the position of the system.
Parameters:
- s System System to get position of.
Returns:
-
vec2
Position of the system.
- 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 _().
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.
Parameters:
- s System System to get the faction of.
Returns:
-
Faction
The dominant faction in the system.
- background (s)
-
Gets system background.
Parameters:
- s System System to get the background of.
Returns:
-
string or nil
The background of the system or nil for default.
- nebula (s)
-
Gets the system's nebula parameters.
Parameters:
- s System System to get nebula parameters from.
Returns:
- number The density of the system.
- number The amount of nebula damage done per second.
Usage:
density, volatility = sys:nebula()
- interference (s)
-
Gets the system's interference level.
Parameters:
- s System System to get interference of.
Returns:
-
number
The amount of interference (in percent).
- 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
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 or math.huge if no path
found.
Usage:
d = sys:jumpDist() -- Distance the current system to sys.
d = sys:jumpDist( "Draygar" ) -- Distance from sys to system Draygar.
d = sys:jumpDist( another_sys ) -- Distance from sys to another_sys.
- jumpPath (s, goal[, hidden=false])
-
Gets jump path from current system, or to another.
Does different things depending on the parameter type:
<li>nil : Gets path to current system.</li> <li>string : Gets path to system with the given raw (untranslated)
name.
- system : Gets path to system
Parameters:
- s System Starting system.
- goal System Goal system param See description.
- hidden boolean Whether or not to consider hidden jumps. (default false)
Returns:
-
{Jump,...}
Table of jumps.
Usage:
jumps = sys:jumpPath( system.cur() ) -- 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.
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.
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.
- asteroidFields (s)
-
Gets all the asteroid fields in a system.
Parameters:
- s System System to get the asteroid fields of.
Returns:
-
{Table,...}
An ordered table with all the asteroid fields.
Usage:
for i, s in ipairs( sys:asteroidFields() ) do -- Iterate over asteroid fields
- addGatherable (commodity, nb[, pos=vec2.new(0[, vel=vec2.new(0[, lifelength[, If=false]]]])
-
Adds a gatherable object
Parameters:
- commodity string name of the commodity.
- nb int quantity of commodity in the gatherable .
- pos Vec2 position of the gatherable. (default vec2.new(0)
- vel Vec2 velocity of the gatherable. (default vec2.new(0)
- lifelength number Lifelength of the gatherable in seconds. (optional)
- If boolean true, the gatherable can only be gathered by player. (default false)
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 _().
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("Dvaered"):nameRaw()] then -- Checks to see if the Dvaered have ships in the system
- spobs (s)
-
Gets the spobs in a system.
Parameters:
- s System System to get spobs of
Returns:
-
{Spob,...}
A table with all the spobs
Usage:
for key, spob in ipairs( sys:spobs() ) do -- Iterate over spobs in system
if \#sys:spobs() > 0 then -- System has spobs
- 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.
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.
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.
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.
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 spobs and jump points. (default false)
Usage:
s:setKnown( false ) -- Makes system unknown.
- hidden (s)
-
Checks to see if a system is hidden by the player.
Parameters:
- s System System to check if the player knows.
Returns:
-
boolean
true if the player knows the system.
Usage:
b = s:hidden()
- hidden (s, hide)
-
Sets a system to be hidden to the player.
Parameters:
- s System System to check if the player knows.
- hide boolean Whether or not to hide the system.
Usage:
s:setHidden( true )
- markerClear ()
-
Clears the system markers.
This can be dangerous and clash with other missions, do not try this at home kids.
Usage:
system.markerClear()
- markerAdd (v[, str[, If]])
-
Adds a system marker.
Parameters:
- v Vec2 Position to display marker at.
- str string String to display next to marker. (optional)
- If number specified, changes the marker to circle type marker and specifies the radius of the circle to use. (optional)
Returns:
-
number
The id of the marker.
Usage:
mrk_id = system.markerAdd( vec2.new( 50, 30 ), "Hello" ) -- Creates a marker at (50,30)
- markerRm (id)
-
Removes a system marker.
Parameters:
- id number ID of the marker to remove.
Usage:
system.markerRm( mrk_id ) -- Removes a marker by mrk_id
- reputation (s[, f=nil])
-
Gets the stored local reputation of a system.
Parameters:
- s System System to get the stored local reputation of.
- f Faction Faction to get reputation of or nil to get the local reputation of all factions in the system. (default nil)
Returns:
-
number, table or 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.
- setReputation (s, f, value)
-
Sets the stored local reputation of a system.
Parameters:
- s System System to set the stored local reputation of.
- f Faction Faction to set the local reputation of.
- value number Value to set the local reputation to.
- tags (s[, tag=nil])
-
Gets the system tags.
Parameters:
- s System System to get tags of.
- tag string Tag to check if exists. (default nil)
Returns:
-
table or 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.
Usage:
if system.cur():tags["fancy"] then -- Has "fancy" tag