naev 0.12.5
nlua_ship.c File Reference

Handles the Lua ship bindings. More...

#include "nlua_ship.h"
#include "array.h"
#include "nlua_canvas.h"
#include "nlua_faction.h"
#include "nlua_outfit.h"
#include "nlua_tex.h"
#include "nluadef.h"
#include "player.h"
#include "slots.h"
Include dependency graph for nlua_ship.c:

Go to the source code of this file.

Functions

static const ShipOutfitSlotship_outfitSlotFromID (const Ship *s, int id)
 Gets an outfit slot from ID.
static int shipL_eq (lua_State *L)
 Checks to see if two ships are the same.
static int shipL_get (lua_State *L)
 Gets a ship.
static int shipL_getAll (lua_State *L)
 Gets a table containing all the ships.
static int shipL_name (lua_State *L)
 Gets the translated name of the ship.
static int shipL_nameRaw (lua_State *L)
 Gets the raw (untranslated) name of the ship.
static int shipL_baseType (lua_State *L)
 Gets the raw (untranslated) name of the ship's base type.
static int shipL_inherits (lua_State *L)
 Gets the ship it inherits stats from if applicable.
static int shipL_class (lua_State *L)
 Gets the raw (untranslated) name of the ship's class.
static int shipL_classDisplay (lua_State *L)
 Gets the raw (untranslated) display name of the ship's class (not ship's base class).
static int shipL_faction (lua_State *L)
 Gets the faction of a ship.
static int shipL_fabricator (lua_State *L)
 Gets the raw (untranslated) fabricator of the ship.
static int shipL_crew (lua_State *L)
 Gets the number of crew of the ship.
static int shipL_mass (lua_State *L)
 Gets the number of mass of the ship.
static int shipL_armour (lua_State *L)
 Gets the number of armour of the ship.
static int shipL_cargo (lua_State *L)
 Gets the number of cargo of the ship.
static int shipL_fuelConsumption (lua_State *L)
 Gets the number of fuel consumption of the ship.
static int shipL_license (lua_State *L)
 Gets license required for the ship.
static int shipL_points (lua_State *L)
 Gets the point value of a ship. Used for comparing relative ship strengths (minus outfits).
static int shipL_slots (lua_State *L)
 Gets the amount of the ship's slots.
static int shipL_getSlots (lua_State *L)
 Get a table of slots of a ship, where a slot is a table with a string size, type, and property.
static int shipL_fitsSlot (lua_State *L)
 Checks to see if an outfit fits a ship slot.
static int shipL_CPU (lua_State *L)
 Gets the ship available CPU.
static int shipL_gfxPath (lua_State *L)
 Gets the path where the ship's graphics are located. Useful for seeing if two ships share the same graphics.
static int shipL_gfxComm (lua_State *L)
 Gets the ship's comm graphics.
static int shipL_gfxStore (lua_State *L)
 Gets the ship's store graphics.
static int shipL_gfx (lua_State *L)
 Gets the ship's graphics.
static int shipL_dims (lua_State *L)
 Gets the onscreen dimensions of the ship.
static int shipL_screenSize (lua_State *L)
 Gets the onscreen size of the ship.
static int shipL_price (lua_State *L)
 Gets the ship's price, with and without default outfits.
static int shipL_time_mod (lua_State *L)
 Gets the ship's time_mod.
static int shipL_getSize (lua_State *L)
 Gets the ship's size. Ultra-light is 1, light is 2, medium is 3, heavy-medium is 4, heavy is 5, and super-heavy is 6.
static int shipL_description (lua_State *L)
 Gets the description of the ship (translated).
static int shipL_getShipStat (lua_State *L)
 Gets a shipstat from an Ship by name, or a table containing all the ship stats if not specified.
static int shipL_getShipStatDesc (lua_State *L)
 Gets the ship stats description for a ship.
static int shipL_known (lua_State *L)
 Gets whether or not the ship is known to the player, as in they know a spob that sells it or own it.
static int shipL_tags (lua_State *L)
 Gets the ship tags.
static int shipL_render (lua_State *L)
 Renders the pilot to a canvas.
int nlua_loadShip (nlua_env env)
 Loads the ship library.
const Shiplua_toship (lua_State *L, int ind)
 Lua bindings to interact with ships.
const ShipluaL_checkship (lua_State *L, int ind)
 Gets ship at index or raises error if there is no ship at index.
const ShipluaL_validship (lua_State *L, int ind)
 Makes sure the ship is valid or raises a Lua error.
const Ship ** lua_pushship (lua_State *L, const Ship *ship)
 Pushes a ship on the stack.
int lua_isship (lua_State *L, int ind)
 Checks to see if ind is a ship.

Variables

static const luaL_Reg shipL_methods []

Detailed Description

Handles the Lua ship bindings.

Definition in file nlua_ship.c.

Function Documentation

◆ lua_isship()

int lua_isship ( lua_State * L,
int ind )

Checks to see if ind is a ship.

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

Definition at line 209 of file nlua_ship.c.

◆ lua_pushship()

const Ship ** lua_pushship ( lua_State * L,
const Ship * ship )

Pushes a ship on the stack.

Parameters
LLua state to push ship into.
shipShip to push.
Returns
Newly pushed ship.

Definition at line 193 of file nlua_ship.c.

◆ lua_toship()

const Ship * lua_toship ( lua_State * L,
int ind )

Lua bindings to interact with ships.

This will allow you to create and manipulate ships in-game.

An example would be:

s = ship.get( "Empire Lancelot" ) -- Gets the ship
cpu_free = s:cpu() -- Gets the CPU

Lua module: ship

Gets ship at index.

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

Definition at line 143 of file nlua_ship.c.

◆ luaL_checkship()

const Ship * luaL_checkship ( lua_State * L,
int ind )

Gets ship at index or raises error if there is no ship at index.

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

Definition at line 154 of file nlua_ship.c.

◆ luaL_validship()

const Ship * luaL_validship ( lua_State * L,
int ind )

Makes sure the ship is valid or raises a Lua error.

Parameters
LState currently running.
indIndex of the ship to validate.
Returns
The ship (doesn't return if fails - raises Lua error ).

Definition at line 168 of file nlua_ship.c.

◆ nlua_loadShip()

int nlua_loadShip ( nlua_env env)

Loads the ship library.

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

Definition at line 117 of file nlua_ship.c.

◆ ship_outfitSlotFromID()

const ShipOutfitSlot * ship_outfitSlotFromID ( const Ship * s,
int id )
static

Gets an outfit slot from ID.

Parameters
sShip to get slot of.
idID to get slot of.

Definition at line 639 of file nlua_ship.c.

◆ shipL_armour()

int shipL_armour ( lua_State * L)
static

Gets the number of armour of the ship.

Lua function parameter: Ship s Ship to get armour of. Lua return parameter: integer The number of armour the ship has.

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

Lua function: armour

Definition at line 457 of file nlua_ship.c.

◆ shipL_baseType()

int shipL_baseType ( lua_State * L)
static

Gets the raw (untranslated) name of the ship's base type.

For example "Empire Lancelot" and "Lancelot" are both of the base type "Lancelot".

Lua usage parameter: type = s:baseType()

Lua function parameter: Ship s Ship to get the ship base type of. Lua return parameter: string The raw name of the ship base type.

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

Lua function: baseType

Definition at line 332 of file nlua_ship.c.

◆ shipL_cargo()

int shipL_cargo ( lua_State * L)
static

Gets the number of cargo of the ship.

Lua function parameter: Ship s Ship to get cargo of. Lua return parameter: integer The number of cargo the ship has.

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

Lua function: cargo

Definition at line 471 of file nlua_ship.c.

◆ shipL_class()

int shipL_class ( lua_State * L)
static

Gets the raw (untranslated) name of the ship's class.

Lua usage parameter: shipclass = s:class()

Lua function parameter: Ship s Ship to get ship class name of. Lua return parameter: string The raw name of the ship's class.

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

Lua function: class

Definition at line 365 of file nlua_ship.c.

◆ shipL_classDisplay()

int shipL_classDisplay ( lua_State * L)
static

Gets the raw (untranslated) display name of the ship's class (not ship's base class).

Lua usage parameter: shipclass = s:classDisplay()

Lua function parameter: Ship s Ship to get ship display class name of. Lua return parameter: string The raw name of the ship's display class.

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

Lua function: classDisplay

Definition at line 382 of file nlua_ship.c.

◆ shipL_CPU()

int shipL_CPU ( lua_State * L)
static

Gets the ship available CPU.

Lua usage parameter: cpu_left = s:cpu()

Lua function parameter: Ship s Ship to get available CPU of. Lua return parameter: number The CPU available on the ship.

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

Lua function: cpu

Definition at line 685 of file nlua_ship.c.

◆ shipL_crew()

int shipL_crew ( lua_State * L)
static

Gets the number of crew of the ship.

Lua function parameter: Ship s Ship to get crew of. Lua return parameter: integer The number of crew the ship has.

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

Lua function: crew

Definition at line 429 of file nlua_ship.c.

◆ shipL_description()

int shipL_description ( lua_State * L)
static

Gets the description of the ship (translated).

Lua usage parameter: description = s:description()

Lua function parameter: Ship s Ship to get the description of. Lua return parameter: string The description of the ship.

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

Lua function: description

Definition at line 865 of file nlua_ship.c.

◆ shipL_dims()

int shipL_dims ( lua_State * L)
static

Gets the onscreen dimensions of the ship.

Lua return parameter: number Width of the ship. Lua return parameter: number Height of the ship.

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

Lua function: dims

Definition at line 835 of file nlua_ship.c.

◆ shipL_eq()

int shipL_eq ( lua_State * L)
static

Checks to see if two ships are the same.

Lua usage parameter: if s1 == s2 then – Checks to see if ship s1 and s2 are the same

Lua function parameter: Ship s1 First ship to compare. Lua function parameter: Ship s2 Second ship to compare. Lua return parameter: boolean true if both ships are the same.

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

Lua function: __eq

Definition at line 235 of file nlua_ship.c.

◆ shipL_fabricator()

int shipL_fabricator ( lua_State * L)
static

Gets the raw (untranslated) fabricator of the ship.

Lua function parameter: Ship s Ship to get fabricator of. Lua return parameter: string The raw name of the ship's fabricator.

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

Lua function: fabricator

Definition at line 415 of file nlua_ship.c.

◆ shipL_faction()

int shipL_faction ( lua_State * L)
static

Gets the faction of a ship.

Lua usage parameter: shipclass = s:faction()

Lua function parameter: Ship s Ship to get faction of. Lua return parameter: Faction The faction of the ship, or nil if not applicable.

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

Lua function: faction

Definition at line 398 of file nlua_ship.c.

◆ shipL_fitsSlot()

int shipL_fitsSlot ( lua_State * L)
static

Checks to see if an outfit fits a ship slot.

Lua function parameter: Ship s Ship to check. Lua function parameter: number id ID of the slot to check (index in getSlots table). Lua function parameter: Outfit o Outfit to check to see if it fits in the slot. Lua return parameter: boolean WHether or not the outfit fits the slot.

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

Lua function: fitsSlot

Definition at line 662 of file nlua_ship.c.

◆ shipL_fuelConsumption()

int shipL_fuelConsumption ( lua_State * L)
static

Gets the number of fuel consumption of the ship.

Lua function parameter: Ship s Ship to get fuel consumption of. Lua return parameter: integer The number of fuel consumption of the ship.

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

Lua function: fuelConsumption

Definition at line 485 of file nlua_ship.c.

◆ shipL_get()

int shipL_get ( lua_State * L)
static

Gets a ship.

Lua usage parameter: s = ship.get( "Hyena" ) – Gets the hyena

Lua function parameter: string s Raw (untranslated) name of the ship to get. Lua return parameter: Ship The ship matching name or nil if error.

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

Lua function: get

Definition at line 256 of file nlua_ship.c.

◆ shipL_getAll()

int shipL_getAll ( lua_State * L)
static

Gets a table containing all the ships.

Lua return parameter: table A table containing all the ships in the game.

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

Lua function: getAll

Definition at line 269 of file nlua_ship.c.

◆ shipL_getShipStat()

int shipL_getShipStat ( lua_State * L)
static

Gets a shipstat from an Ship by name, or a table containing all the ship stats if not specified.

Lua function parameter: Ship s Ship to get ship stat of. Lua function parameter:[opt=nil] string name Name of the ship stat to get. Lua function parameter:[opt=false] boolean internal Whether or not to use the internal representation. Lua return parameter: number|table Value of the ship stat or a tale containing all the ship stats if name is not specified.

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

Lua function: shipstat

Definition at line 884 of file nlua_ship.c.

◆ shipL_getShipStatDesc()

int shipL_getShipStatDesc ( lua_State * L)
static

Gets the ship stats description for a ship.

Lua function parameter: Ship s Ship to get ship stat description of. Lua return parameter: string Description of the ship's stats.

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

Lua function: shipstatDesc

Definition at line 900 of file nlua_ship.c.

◆ shipL_getSize()

int shipL_getSize ( lua_State * L)
static

Gets the ship's size. Ultra-light is 1, light is 2, medium is 3, heavy-medium is 4, heavy is 5, and super-heavy is 6.

Lua function parameter: Ship s Ship to get the size of. Lua return parameter: number The ship's size.

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

Lua function: size

Definition at line 732 of file nlua_ship.c.

◆ shipL_getSlots()

int shipL_getSlots ( lua_State * L)
static

Get a table of slots of a ship, where a slot is a table with a string size, type, and property.

Lua usage parameter: for i, v in ipairs( ship.getSlots( ship.get("Llama") ) ) do print(v["type"]) end

Lua function parameter: Ship s Ship to get slots of Lua function parameter:[opt=false] boolean ignore_locked Whether or not to ignore locked slots. Lua return parameter: A table of tables with slot properties string "size", string "type", string "property", boolean "required", boolean "exclusive", boolean "locked", and (if applicable) outfit "outfit" (Strings are English.)

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

Lua function: getSlots

Definition at line 563 of file nlua_ship.c.

◆ shipL_gfx()

int shipL_gfx ( lua_State * L)
static

Gets the ship's graphics.

Will not work without access to the Tex module. These are nearly always a sprite sheet.

Lua usage parameter: gfx = s:gfx()

Lua function parameter: Ship s Ship to get graphics of. Lua return parameter: Tex The graphics of the ship.

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

Lua function: gfx

Definition at line 815 of file nlua_ship.c.

◆ shipL_gfxComm()

int shipL_gfxComm ( lua_State * L)
static

Gets the ship's comm graphics.

Will not work without access to the Tex module.

Lua usage parameter: gfx = s:gfxComm()

Lua function parameter: Ship s Ship to get comm graphics of. Lua function parameter:[opt=512] number resolution Resolution to render the image at. Lua return parameter: Tex The comm graphics of the ship.

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

Lua function: gfxComm

Definition at line 766 of file nlua_ship.c.

◆ shipL_gfxPath()

int shipL_gfxPath ( lua_State * L)
static

Gets the path where the ship's graphics are located. Useful for seeing if two ships share the same graphics.

Lua function parameter: Ship s Ship to get the path of the graphis of. Lua return parameter: string The path to the ship graphics.

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

Lua function: size

Definition at line 747 of file nlua_ship.c.

◆ shipL_gfxStore()

int shipL_gfxStore ( lua_State * L)
static

Gets the ship's store graphics.

Will not work without access to the Tex module.

Lua usage parameter: gfx = s:gfxStore()

Lua function parameter: Ship s Ship to get store graphics of. Lua return parameter: Tex The store graphics of the ship.

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

Lua function: gfxStore

Definition at line 790 of file nlua_ship.c.

◆ shipL_inherits()

int shipL_inherits ( lua_State * L)
static

Gets the ship it inherits stats from if applicable.

Lua function parameter: Ship s Ship to get the ship it is inheriting from. Lua return parameter: Ship|nil The ship it is inheritng from or nil if not applicable.

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

Lua function: inherits

Definition at line 347 of file nlua_ship.c.

◆ shipL_known()

int shipL_known ( lua_State * L)
static

Gets whether or not the ship is known to the player, as in they know a spob that sells it or own it.

Definition at line 913 of file nlua_ship.c.

◆ shipL_license()

int shipL_license ( lua_State * L)
static

Gets license required for the ship.

Lua usage parameter: license = s:license()

Lua function parameter: Ship s Ship to get license of. Lua return parameter: string Required license or nil if not necessary.

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

Lua function: license

Definition at line 501 of file nlua_ship.c.

◆ shipL_mass()

int shipL_mass ( lua_State * L)
static

Gets the number of mass of the ship.

Lua function parameter: Ship s Ship to get mass of. Lua return parameter: integer The number of mass the ship has.

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

Lua function: mass

Definition at line 443 of file nlua_ship.c.

◆ shipL_name()

int shipL_name ( lua_State * L)
static

Gets the translated name of the ship.

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

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

Lua function parameter: Ship s Ship to get the translated name of. Lua return parameter: string The translated name of the ship.

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

Lua function: name

Definition at line 293 of file nlua_ship.c.

◆ shipL_nameRaw()

int shipL_nameRaw ( lua_State * L)
static

Gets the raw (untranslated) name of the ship.

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

Lua usage parameter: shipname = s:nameRaw()

Lua function parameter: Ship s Ship to get the raw name of. Lua return parameter: string The raw name of the ship.

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

Lua function: nameRaw

Definition at line 313 of file nlua_ship.c.

◆ shipL_points()

int shipL_points ( lua_State * L)
static

Gets the point value of a ship. Used for comparing relative ship strengths (minus outfits).

Lua usage parameter: points = s:points()

Lua function parameter: Ship s Ship to get points of. Lua return parameter: number Point value of the ship.

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

Lua function: points

Definition at line 520 of file nlua_ship.c.

◆ shipL_price()

int shipL_price ( lua_State * L)
static

Gets the ship's price, with and without default outfits.

Lua usage parameter: price, base = s:price()

Lua function parameter: Ship s Ship to get the price of. Lua return parameter: number The ship's final purchase price. Lua return parameter: number The ship's base price.

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

Lua function: price

Definition at line 702 of file nlua_ship.c.

◆ shipL_render()

int shipL_render ( lua_State * L)
static

Renders the pilot to a canvas.

Lua function parameter: Ship s Ship to render on the screen. Lua function parameter: number dir Direction the ship should be facing (in radians). Lua function parameter: number engineglow How much engine glow to render with. Lua function parameter: number tilt How much to tilt the ship (in radians). Lua return parameter: Canvas The canvas with the pilot drawn on it.

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

Lua function: render

Definition at line 970 of file nlua_ship.c.

◆ shipL_screenSize()

int shipL_screenSize ( lua_State * L)
static

Gets the onscreen size of the ship.

Lua return parameter: number Size of the ship.

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

Lua function: screenSize

Definition at line 849 of file nlua_ship.c.

◆ shipL_slots()

int shipL_slots ( lua_State * L)
static

Gets the amount of the ship's slots.

Lua usage parameter: slots_weapon, slots_utility, slots_structure = p:slots()

Lua function parameter: Ship s Ship to get ship slots of. Lua return parameter: number Number of weapon slots. Lua return parameter: number Number of utility slots. Lua return parameter: number Number of structure slots.

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

Lua function: slots

Definition at line 538 of file nlua_ship.c.

◆ shipL_tags()

int shipL_tags ( lua_State * L)
static

Gets the ship tags.

Lua usage parameter: if s:tags()["fancy"] then – Has the "fancy" tag Lua usage parameter: if s:tags("fancy") then – Has the "fancy" tag

Lua function parameter: Ship s Ship 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 954 of file nlua_ship.c.

◆ shipL_time_mod()

int shipL_time_mod ( lua_State * L)
static

Gets the ship's time_mod.

Lua function parameter: Ship s Ship to get the time_mod of. Lua return parameter: number The ship's time_mod.

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

Lua function: time_mod

Definition at line 717 of file nlua_ship.c.

Variable Documentation

◆ shipL_methods

const luaL_Reg shipL_methods[]
static

Ship metatable methods.

Definition at line 70 of file nlua_ship.c.