naev 0.11.5
nlua_ship.c File Reference

Handles the Lua ship bindings. More...

#include "nlua_ship.h"
#include "array.h"
#include "log.h"
#include "nlua_outfit.h"
#include "nlua_tex.h"
#include "nluadef.h"
#include "rng.h"
#include "slots.h"

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_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_getPoints (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_gfxComm (lua_State *L)
 Gets the ship's comm graphics.
 
static int shipL_gfxTarget (lua_State *L)
 Gets the ship's target 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_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_tags (lua_State *L)
 Gets the ship tags.
 
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 182 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 166 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 116 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 127 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 141 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 90 of file nlua_ship.c.

◆ ship_outfitSlotFromID()

static 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 465 of file nlua_ship.c.

◆ shipL_baseType()

static 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 304 of file nlua_ship.c.

◆ shipL_class()

static 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 320 of file nlua_ship.c.

◆ shipL_classDisplay()

static 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 336 of file nlua_ship.c.

◆ shipL_CPU()

static 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 513 of file nlua_ship.c.

◆ shipL_description()

static 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 659 of file nlua_ship.c.

◆ shipL_dims()

static 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 642 of file nlua_ship.c.

◆ shipL_eq()

static 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 208 of file nlua_ship.c.

◆ shipL_fitsSlot()

static 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 490 of file nlua_ship.c.

◆ shipL_get()

static 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 229 of file nlua_ship.c.

◆ shipL_getAll()

static 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 242 of file nlua_ship.c.

◆ shipL_getPoints()

static int shipL_getPoints ( 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 352 of file nlua_ship.c.

◆ shipL_getShipStat()

static 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 675 of file nlua_ship.c.

◆ shipL_getShipStatDesc()

static 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 691 of file nlua_ship.c.

◆ shipL_getSize()

static 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 559 of file nlua_ship.c.

◆ shipL_getSlots()

static 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 391 of file nlua_ship.c.

◆ shipL_gfx()

static 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 623 of file nlua_ship.c.

◆ shipL_gfxComm()

static 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 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 577 of file nlua_ship.c.

◆ shipL_gfxTarget()

static int shipL_gfxTarget ( lua_State * L)
static

Gets the ship's target graphics.

Will not work without access to the Tex module.

Lua usage parameter: gfx = s:gfxTarget()

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

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

Lua function: gfxTarget

Definition at line 600 of file nlua_ship.c.

◆ shipL_name()

static 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 266 of file nlua_ship.c.

◆ shipL_nameRaw()

static 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 286 of file nlua_ship.c.

◆ shipL_price()

static 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 530 of file nlua_ship.c.

◆ shipL_slots()

static 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 370 of file nlua_ship.c.

◆ shipL_tags()

static int shipL_tags ( lua_State * L)
static

Gets the ship tags.

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

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

◆ shipL_time_mod()

static 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 545 of file nlua_ship.c.

Variable Documentation

◆ shipL_methods

const luaL_Reg shipL_methods[]
static
Initial value:
= {
{ "__tostring", shipL_name },
{ "__eq", shipL_eq },
{ "get", shipL_get },
{ "getAll", shipL_getAll },
{ "name", shipL_name },
{ "nameRaw", shipL_nameRaw },
{ "baseType", shipL_baseType },
{ "class", shipL_class },
{ "classDisplay", shipL_classDisplay },
{ "points", shipL_getPoints },
{ "slots", shipL_slots },
{ "getSlots", shipL_getSlots },
{ "fitsSlot", shipL_fitsSlot },
{ "cpu", shipL_CPU },
{ "price", shipL_price },
{ "time_mod", shipL_time_mod },
{ "size", shipL_getSize },
{ "gfxComm", shipL_gfxComm },
{ "gfxTarget", shipL_gfxTarget },
{ "gfx", shipL_gfx },
{ "dims", shipL_dims },
{ "description", shipL_description },
{ "shipstat", shipL_getShipStat },
{ "shipstatDesc", shipL_getShipStatDesc },
{ "tags", shipL_tags },
{0,0}
}
static int shipL_tags(lua_State *L)
Gets the ship tags.
Definition nlua_ship.c:709
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,...
Definition nlua_ship.c:559
static int shipL_getShipStatDesc(lua_State *L)
Gets the ship stats description for a ship.
Definition nlua_ship.c:691
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.
Definition nlua_ship.c:675
static int shipL_price(lua_State *L)
Gets the ship's price, with and without default outfits.
Definition nlua_ship.c:530
static int shipL_class(lua_State *L)
Gets the raw (untranslated) name of the ship's class.
Definition nlua_ship.c:320
static int shipL_dims(lua_State *L)
Gets the onscreen dimensions of the ship.
Definition nlua_ship.c:642
static int shipL_time_mod(lua_State *L)
Gets the ship's time_mod.
Definition nlua_ship.c:545
static int shipL_eq(lua_State *L)
Checks to see if two ships are the same.
Definition nlua_ship.c:208
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.
Definition nlua_ship.c:391
static int shipL_CPU(lua_State *L)
Gets the ship available CPU.
Definition nlua_ship.c:513
static int shipL_gfxComm(lua_State *L)
Gets the ship's comm graphics.
Definition nlua_ship.c:577
static int shipL_baseType(lua_State *L)
Gets the raw (untranslated) name of the ship's base type.
Definition nlua_ship.c:304
static int shipL_nameRaw(lua_State *L)
Gets the raw (untranslated) name of the ship.
Definition nlua_ship.c:286
static int shipL_slots(lua_State *L)
Gets the amount of the ship's slots.
Definition nlua_ship.c:370
static int shipL_description(lua_State *L)
Gets the description of the ship (translated).
Definition nlua_ship.c:659
static int shipL_classDisplay(lua_State *L)
Gets the raw (untranslated) display name of the ship's class (not ship's base class).
Definition nlua_ship.c:336
static int shipL_getAll(lua_State *L)
Gets a table containing all the ships.
Definition nlua_ship.c:242
static int shipL_name(lua_State *L)
Gets the translated name of the ship.
Definition nlua_ship.c:266
static int shipL_get(lua_State *L)
Gets a ship.
Definition nlua_ship.c:229
static int shipL_gfx(lua_State *L)
Gets the ship's graphics.
Definition nlua_ship.c:623
static int shipL_getPoints(lua_State *L)
Gets the point value of a ship. Used for comparing relative ship strengths (minus outfits).
Definition nlua_ship.c:352
static int shipL_fitsSlot(lua_State *L)
Checks to see if an outfit fits a ship slot.
Definition nlua_ship.c:490
static int shipL_gfxTarget(lua_State *L)
Gets the ship's target graphics.
Definition nlua_ship.c:600

Ship metatable methods.

Definition at line 55 of file nlua_ship.c.