naev 0.10.4
Functions | Variables
nlua_spob.c File Reference

Lua spob module. More...

#include "nlua_spob.h"
#include "array.h"
#include "land.h"
#include "land_outfits.h"
#include "log.h"
#include "map.h"
#include "map_overlay.h"
#include "nlua_colour.h"
#include "nlua_commodity.h"
#include "nlua_faction.h"
#include "nlua_outfit.h"
#include "nlua_ship.h"
#include "nlua_system.h"
#include "nlua_tex.h"
#include "nlua_time.h"
#include "nlua_vec2.h"
#include "nluadef.h"
#include "nmath.h"
#include "nstring.h"
#include "rng.h"

Go to the source code of this file.

Functions

static int spobL_cur (lua_State *L)
 Gets the current spob - MUST BE LANDED. More...
 
static int spobL_get (lua_State *L)
 Gets a spob. More...
 
static int spobL_getS (lua_State *L)
 Gets a spob and its corresponding system. More...
 
static int spobL_getLandable (lua_State *L)
 Gets a spob only if it's landable. More...
 
static int spobL_getAll (lua_State *L)
 Gets all the spobs. Lua function parameter: boolean all_spob Whether or not to get all Spob, including those that may not be located in a system at the time. Lua return parameter: {Spob,...} An ordered list of all the spobs. More...
 
static int spobL_system (lua_State *L)
 Gets the system corresponding to a spob. Lua function parameter: Spob p Spob to get system of. Lua return parameter: System|nil The system to which the spob belongs or nil if it has none. More...
 
static int spobL_eq (lua_State *L)
 You can use the '==' operator within Lua to compare spobs with this. More...
 
static int spobL_name (lua_State *L)
 Gets the spob's translated name. More...
 
static int spobL_nameRaw (lua_State *L)
 Gets the spob's raw (untranslated) name. More...
 
static int spobL_population (lua_State *L)
 Gets the spob's population. More...
 
static int spobL_radius (lua_State *L)
 Gets the spob's radius. More...
 
static int spobL_faction (lua_State *L)
 Gets the spob's faction. More...
 
static int spobL_colour (lua_State *L)
 Gets a spob's colour based on its friendliness or hostility to the player. More...
 
static int spobL_class (lua_State *L)
 Gets the spob's class. More...
 
static int spobL_classLong (lua_State *L)
 Gets the spob's class in long human-readable format already translated. More...
 
static int spobL_position (lua_State *L)
 Gets the position of the spob in the system. More...
 
static int spobL_services (lua_State *L)
 Checks for spob services. More...
 
static int spobL_flags (lua_State *L)
 Checks for spob flags. More...
 
static int spobL_canland (lua_State *L)
 Gets whether or not the player can land on the spob (or bribe it). More...
 
static int spobL_landOverride (lua_State *L)
 Lets player land on a spob no matter what. The override lasts until the player jumps or lands. More...
 
static int spobL_getLandOverride (lua_State *L)
 Gets the land override status for a spob. More...
 
static int spobL_gfxSpace (lua_State *L)
 Gets the texture of the spob in space. More...
 
static int spobL_gfxExterior (lua_State *L)
 Gets the texture of the spob in exterior. More...
 
static int spobL_shipsSold (lua_State *L)
 Gets the ships sold at a spob. More...
 
static int spobL_outfitsSold (lua_State *L)
 Gets the outfits sold at a spob. More...
 
static int spobL_commoditiesSold (lua_State *L)
 Gets the commodities sold at a spob. More...
 
static int spobL_isBlackMarket (lua_State *L)
 Checks to see if a spob is a black market. More...
 
static int spobL_isKnown (lua_State *L)
 Checks to see if a spob is known by the player. More...
 
static int spobL_setKnown (lua_State *L)
 Sets a spobs's known state. More...
 
static int spobL_recordCommodityPriceAtTime (lua_State *L)
 Records commodity prices at a given time, adding to players stats. More...
 
static int spobL_tags (lua_State *L)
 Gets the spob tags. More...
 
int nlua_loadSpob (nlua_env env)
 Loads the spob library. More...
 
LuaSpob lua_tospob (lua_State *L, int ind)
 This module allows you to handle the spobs from Lua. More...
 
LuaSpob luaL_checkspob (lua_State *L, int ind)
 Gets spob at index raising an error if isn't a spob. More...
 
SpobluaL_validspob (lua_State *L, int ind)
 Gets a spob directly. More...
 
LuaSpob * lua_pushspob (lua_State *L, LuaSpob spob)
 Pushes a spob on the stack. More...
 
int lua_isspob (lua_State *L, int ind)
 Checks to see if ind is a spob. More...
 
static int spobL_getBackend (lua_State *L, int system, int landable)
 

Variables

static const luaL_Reg spob_methods []
 

Detailed Description

Lua spob module.

Definition in file nlua_spob.c.

Function Documentation

◆ lua_isspob()

int lua_isspob ( lua_State *  L,
int  ind 
)

Checks to see if ind is a spob.

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

Definition at line 207 of file nlua_spob.c.

◆ lua_pushspob()

LuaSpob * lua_pushspob ( lua_State *  L,
LuaSpob  spob 
)

Pushes a spob on the stack.

Parameters
LLua state to push spob into.
spobSpob to push.
Returns
Newly pushed spob.

Definition at line 192 of file nlua_spob.c.

◆ lua_tospob()

LuaSpob lua_tospob ( lua_State *  L,
int  ind 
)

This module allows you to handle the spobs from Lua.

Generally you do something like:

p,s = spob.get() -- Get current spob and system
if p:services()["inhabited"] > 0 then -- spob is inhabited
v = p:pos() -- Get the position
-- Do other stuff
end

Lua module: spob

Gets spob at index.

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

Definition at line 139 of file nlua_spob.c.

◆ luaL_checkspob()

LuaSpob luaL_checkspob ( lua_State *  L,
int  ind 
)

Gets spob at index raising an error if isn't a spob.

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

Definition at line 150 of file nlua_spob.c.

◆ luaL_validspob()

Spob * luaL_validspob ( lua_State *  L,
int  ind 
)

Gets a spob directly.

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

Definition at line 164 of file nlua_spob.c.

◆ nlua_loadSpob()

int nlua_loadSpob ( nlua_env  env)

Loads the spob library.

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

Definition at line 111 of file nlua_spob.c.

◆ spobL_canland()

static int spobL_canland ( lua_State *  L)
static

Gets whether or not the player can land on the spob (or bribe it).

Lua usage parameter: can_land, can_bribe = p:canLand() Lua function parameter: Spob p Spob to get land and bribe status of. Lua return parameter: boolean The land status of the spob.

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

Lua function: canLand

Definition at line 697 of file nlua_spob.c.

◆ spobL_class()

static int spobL_class ( lua_State *  L)
static

Gets the spob's class.

Usually classes are characters for spobs and numbers for stations.

Lua usage parameter: c = p:class() Lua function parameter: Spob p Spob to get the class of. Lua return parameter: string The class of the spob in a one char identifier.

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

Lua function: class

Definition at line 603 of file nlua_spob.c.

◆ spobL_classLong()

static int spobL_classLong ( lua_State *  L)
static

Gets the spob's class in long human-readable format already translated.

Lua usage parameter: c = p:classLong() Lua function parameter: Spob p Spob to get the class of. Lua return parameter: string The class of the spob in descriptive form such as "Pelagic".

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

Lua function: classLong

Definition at line 618 of file nlua_spob.c.

◆ spobL_colour()

static int spobL_colour ( lua_State *  L)
static

Gets a spob's colour based on its friendliness or hostility to the player.

Lua usage parameter: col = p:colour()

Lua function parameter: Pilot p Spob to get the colour of. Lua return parameter: Colour The spob's colour.

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

Lua function: colour

Definition at line 584 of file nlua_spob.c.

◆ spobL_commoditiesSold()

static int spobL_commoditiesSold ( lua_State *  L)
static

Gets the commodities sold at a spob.

Lua function parameter: Pilot p Spob to get commodities sold at. Lua return parameter: {Commodity,...} An ordered table containing all the commodities sold (empty if none sold).

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

Lua function: commoditiesSold

Definition at line 854 of file nlua_spob.c.

◆ spobL_cur()

static int spobL_cur ( lua_State *  L)
static

Gets the current spob - MUST BE LANDED.

Lua usage parameter: p,s = spob.cur() – Gets current spob (assuming landed)

Lua return parameter: Spob The spob the player is landed on. Lua return parameter: System The system it is in.

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

Lua function: cur

Definition at line 232 of file nlua_spob.c.

◆ spobL_eq()

static int spobL_eq ( lua_State *  L)
static

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

Lua usage parameter: if p.__eq( spob.get( "Anecu" ) ) then – Do something Lua usage parameter: if p == spob.get( "Anecu" ) then – Do something Lua function parameter: Spob p Spob comparing. Lua function parameter: Spob comp spob to compare against. Lua return parameter: boolean true if both spobs are the same.

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

Lua function: __eq

Definition at line 476 of file nlua_spob.c.

◆ spobL_faction()

static int spobL_faction ( lua_State *  L)
static

Gets the spob's faction.

Lua usage parameter: f = p:faction() Lua function parameter: Spob p Spob to get the faction of. Lua return parameter: Faction The spob's faction, or nil if it has no faction.

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

Lua function: faction

Definition at line 566 of file nlua_spob.c.

◆ spobL_flags()

static int spobL_flags ( lua_State *  L)
static

Checks for spob flags.

Possible services are:

  • "nomissionspawn"

Lua usage parameter: if p:flags()["nomissionspawn"] then – Spob doesn't spawn missions Lua function parameter: Spob p Spob to get the services of. Lua return parameter: table Table containing all the services.

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

Lua function: services

Definition at line 677 of file nlua_spob.c.

◆ spobL_get()

static int spobL_get ( lua_State *  L)
static

Gets a spob.

Possible values of param:

  • bool : Gets a random spob.
  • faction : Gets random spob belonging to faction matching the number.
  • string : Gets the spob by raw (untranslated) name.
  • table : Gets random spob belonging to any of the factions in the table.

Lua usage parameter: p = spob.get( "Anecu" ) – Gets spob by name Lua usage parameter: p = spob.get( faction.get( "Empire" ) ) – Gets random Empire spob Lua usage parameter: p = spob.get(true) – Gets completely random spob Lua usage parameter: p = spob.get( { faction.get("Empire"), faction.get("Dvaered") } ) – Random spob belonging to Empire or Dvaered Lua function parameter: boolean|Faction|string|table param See description. Lua return parameter: Spob The matching spob.

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

Lua function: get

Definition at line 382 of file nlua_spob.c.

◆ spobL_getAll()

static int spobL_getAll ( lua_State *  L)
static

Gets all the spobs. Lua function parameter: boolean all_spob Whether or not to get all Spob, including those that may not be located in a system at the time. Lua return parameter: {Spob,...} An ordered list of all the spobs.

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

Lua function: getAll

Definition at line 433 of file nlua_spob.c.

◆ spobL_getBackend()

static int spobL_getBackend ( lua_State *  L,
int  system,
int  landable 
)
static

Definition at line 245 of file nlua_spob.c.

◆ spobL_getLandable()

static int spobL_getLandable ( lua_State *  L)
static

Gets a spob only if it's landable.

It works exactly the same as spob.get(), but it can only return landable spobs. So if the target is not landable it returns nil.

Lua function parameter: boolean|Faction|string|table param See spob.get() description. Lua return parameter: Spob The matching spob, if it is landable. Lua return parameter: System The system it is in.

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

Lua function: getLandable

Definition at line 422 of file nlua_spob.c.

◆ spobL_getLandOverride()

static int spobL_getLandOverride ( lua_State *  L)
static

Gets the land override status for a spob.

Lua usage parameter: if p:getLandOverride() then – Player can definitely land. Lua function parameter: Spob p Spob to check. Lua return parameter: b Whether or not the player is always allowed to land.

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

Lua function: getLandOverride

Definition at line 735 of file nlua_spob.c.

◆ spobL_getS()

static int spobL_getS ( lua_State *  L)
static

Gets a spob and its corresponding system.

Possible values of param:

  • bool : Gets a random spob.
  • faction : Gets random spob belonging to faction matching the number.
  • string : Gets the spob by raw (untranslated) name.
  • table : Gets random spob belonging to any of the factions in the table.

Lua usage parameter: p,s = spob.get( "Anecu" ) – Gets spob by name Lua usage parameter: p,s = spob.get( faction.get( "Empire" ) ) – Gets random Empire spob Lua usage parameter: p,s = spob.get(true) – Gets completely random spob Lua usage parameter: p,s = spob.get( { faction.get("Empire"), faction.get("Dvaered") } ) – Random spob belonging to Empire or Dvaered Lua function parameter: boolean|Faction|string|table param See description. Lua return parameter: Spob The matching spob. Lua return parameter: System The system it is in.

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

Lua function: getS

Definition at line 406 of file nlua_spob.c.

◆ spobL_gfxExterior()

static int spobL_gfxExterior ( lua_State *  L)
static

Gets the texture of the spob in exterior.

Lua usage parameter: gfx = p:gfxExterior() Lua function parameter: Spob p Spob Spob to get texture of. Lua return parameter: Tex The exterior texture of the spob.

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

Lua function: gfxExterior

Definition at line 789 of file nlua_spob.c.

◆ spobL_gfxSpace()

static int spobL_gfxSpace ( lua_State *  L)
static

Gets the texture of the spob in space.

Lua usage parameter: gfx = p:gfxSpace() Lua function parameter: Spob p Spob to get texture of. Lua return parameter: Tex The space texture of the spob.

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

Lua function: gfxSpace

Definition at line 765 of file nlua_spob.c.

◆ spobL_isBlackMarket()

static int spobL_isBlackMarket ( lua_State *  L)
static

Checks to see if a spob is a black market.

Lua usage parameter: b = p:blackmarket()

Lua function parameter: Spob p Spob to check if it's a black market. Lua return parameter: boolean true if the spob is a black market.

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

Lua function: blackmarket

Definition at line 878 of file nlua_spob.c.

◆ spobL_isKnown()

static int spobL_isKnown ( lua_State *  L)
static

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

Lua usage parameter: b = p:known()

Lua function parameter: Spob p Spob to check if the player knows. Lua return parameter: boolean true if the player knows the spob.

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

Lua function: known

Definition at line 894 of file nlua_spob.c.

◆ spobL_landOverride()

static int spobL_landOverride ( lua_State *  L)
static

Lets player land on a spob no matter what. The override lasts until the player jumps or lands.

Lua usage parameter: p:landOverride( true ) – Spob can land on p now. Lua function parameter: Spob p Spob to forcibly allow the player to land on. Lua function parameter:[opt=false] boolean b Whether or not the player should be allowed to land, true enables, false disables override.

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

Lua function: landOverride

Definition at line 713 of file nlua_spob.c.

◆ spobL_name()

static int spobL_name ( lua_State *  L)
static

Gets the spob's translated name.

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

Note that it can be overwritten by the spob's display name which makes it not equivalent to _(p:nameRaw()) in some cases.

Lua usage parameter: name = p:name() Lua function parameter: Spob p Spob to get the translated name of. Lua return parameter: string The translated name of the spob.

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

Lua function: name

Definition at line 500 of file nlua_spob.c.

◆ spobL_nameRaw()

static int spobL_nameRaw ( lua_State *  L)
static

Gets the spob's raw (untranslated) name.

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

Lua usage parameter: name = p:nameRaw() Lua function parameter: Spob p Spob to get the raw name of. Lua return parameter: string The raw name of the spob.

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

Lua function: nameRaw

Definition at line 519 of file nlua_spob.c.

◆ spobL_outfitsSold()

static int spobL_outfitsSold ( lua_State *  L)
static

Gets the outfits sold at a spob.

Lua function parameter: Spob p Spob to get outfits sold at. Lua return parameter: {Outfit,...} An ordered table containing all the outfits sold (empty if none sold).

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

Lua function: outfitsSold

Definition at line 831 of file nlua_spob.c.

◆ spobL_population()

static int spobL_population ( lua_State *  L)
static

Gets the spob's population.

Lua function parameter: Spob p Spob to get the population of. Lua return parameter: number The spob's population.

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

Lua function: population

Definition at line 533 of file nlua_spob.c.

◆ spobL_position()

static int spobL_position ( lua_State *  L)
static

Gets the position of the spob in the system.

Lua usage parameter: v = p:pos() Lua function parameter: Spob p Spob to get the position of. Lua return parameter: Vec2 The position of the spob in the system.

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

Lua function: pos

Definition at line 750 of file nlua_spob.c.

◆ spobL_radius()

static int spobL_radius ( lua_State *  L)
static

Gets the spob's radius.

Lua usage parameter: radius = p:radius() Lua function parameter: Spob p Spob to get the radius of. Lua return parameter: number The spob's graphics radius.

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

Lua function: radius

Definition at line 548 of file nlua_spob.c.

◆ spobL_recordCommodityPriceAtTime()

static int spobL_recordCommodityPriceAtTime ( lua_State *  L)
static

Records commodity prices at a given time, adding to players stats.

Lua usage parameter: p:recordCommodityPriceAtTime( t ) Lua function parameter: Spob p Spob to record prices at Lua function parameter: ntime_t t Time at which to record prices.

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

Lua function: recordCommodityPriceAtTime

Definition at line 938 of file nlua_spob.c.

◆ spobL_services()

static int spobL_services ( lua_State *  L)
static

Checks for spob services.

Possible services are:

  • "land"
  • "inhabited"
  • "refuel"
  • "bar"
  • "missions"
  • "commodity"
  • "outfits"
  • "shipyard"
  • "blackmarket"

Lua usage parameter: if p:services()["refuel"] then – Spob has refuel service. Lua usage parameter: if p:services()["shipyard"] then – Spob has shipyard service. Lua function parameter: Spob p Spob to get the services of. Lua return parameter: table Table containing all the services.

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

Lua function: services

Definition at line 645 of file nlua_spob.c.

◆ spobL_setKnown()

static int spobL_setKnown ( lua_State *  L)
static

Sets a spobs's known state.

Lua usage parameter: p:setKnown( false ) – Makes spob unknown. Lua function parameter: Spob p Spob 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 909 of file nlua_spob.c.

◆ spobL_shipsSold()

static int spobL_shipsSold ( lua_State *  L)
static

Gets the ships sold at a spob.

Lua function parameter: Spob p Spob to get ships sold at. Lua return parameter: {Ship,...} An ordered table containing all the ships sold (empty if none sold).

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

Lua function: shipsSold

Definition at line 808 of file nlua_spob.c.

◆ spobL_system()

static int spobL_system ( lua_State *  L)
static

Gets the system corresponding to a spob. Lua function parameter: Spob p Spob to get system of. Lua return parameter: System|nil The system to which the spob belongs or nil if it has none.

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

Lua function: system

Definition at line 454 of file nlua_spob.c.

◆ spobL_tags()

static int spobL_tags ( lua_State *  L)
static

Gets the spob tags.

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

Lua function parameter: Spob p Spob to get tags of. Lua return parameter: table Table of tags where the name is the key and true is the value.

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

Lua function: tags

Definition at line 955 of file nlua_spob.c.

Variable Documentation

◆ spob_methods

const luaL_Reg spob_methods[]
static

Spob metatable methods.

Definition at line 69 of file nlua_spob.c.