naev 0.10.4
Functions | Variables
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. More...
 
static int shipL_eq (lua_State *L)
 Checks to see if two ships are the same. More...
 
static int shipL_get (lua_State *L)
 Gets a ship. More...
 
static int shipL_getAll (lua_State *L)
 Gets a table containing all the ships. More...
 
static int shipL_name (lua_State *L)
 Gets the translated name of the ship. More...
 
static int shipL_nameRaw (lua_State *L)
 Gets the raw (untranslated) name of the ship. More...
 
static int shipL_baseType (lua_State *L)
 Gets the raw (untranslated) name of the ship's base type. More...
 
static int shipL_class (lua_State *L)
 Gets the raw (untranslated) name of the ship's class. More...
 
static int shipL_classDisplay (lua_State *L)
 Gets the raw (untranslated) display name of the ship's class (not ship's base class). More...
 
static int shipL_getPoints (lua_State *L)
 Gets the point value of a ship. Used for comparing relative ship strengths (minus outfits). More...
 
static int shipL_slots (lua_State *L)
 Gets the amount of the ship's slots. More...
 
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. More...
 
static int shipL_fitsSlot (lua_State *L)
 Checks to see if an outfit fits a ship slot. More...
 
static int shipL_CPU (lua_State *L)
 Gets the ship available CPU. More...
 
static int shipL_gfxComm (lua_State *L)
 Gets the ship's comm graphics. More...
 
static int shipL_gfxTarget (lua_State *L)
 Gets the ship's target graphics. More...
 
static int shipL_gfx (lua_State *L)
 Gets the ship's graphics. More...
 
static int shipL_price (lua_State *L)
 Gets the ship's price, with and without default outfits. More...
 
static int shipL_time_mod (lua_State *L)
 Gets the ship's time_mod. More...
 
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. More...
 
static int shipL_description (lua_State *L)
 Gets the description of the ship (translated). More...
 
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. More...
 
static int shipL_getShipStatDesc (lua_State *L)
 Gets the ship stats description for a ship. More...
 
static int shipL_tags (lua_State *L)
 Gets the ship tags. More...
 
int nlua_loadShip (nlua_env env)
 Loads the ship library. More...
 
const Shiplua_toship (lua_State *L, int ind)
 Lua bindings to interact with ships. More...
 
const ShipluaL_checkship (lua_State *L, int ind)
 Gets ship at index or raises error if there is no ship at index. More...
 
const ShipluaL_validship (lua_State *L, int ind)
 Makes sure the ship is valid or raises a Lua error. More...
 
const Ship ** lua_pushship (lua_State *L, const Ship *ship)
 Pushes a ship on the stack. More...
 
int lua_isship (lua_State *L, int ind)
 Checks to see if ind is a ship. More...
 

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 180 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 164 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 114 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 125 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 139 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 88 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 457 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 302 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 318 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 334 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 505 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 636 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 206 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 482 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 227 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 240 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 350 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 652 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 668 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 551 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 389 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 615 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 569 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 592 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 264 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 284 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 522 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 368 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 686 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 537 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 },
{ "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:686
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:551
static int shipL_getShipStatDesc(lua_State *L)
Gets the ship stats description for a ship.
Definition: nlua_ship.c:668
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:652
static int shipL_price(lua_State *L)
Gets the ship's price, with and without default outfits.
Definition: nlua_ship.c:522
static int shipL_class(lua_State *L)
Gets the raw (untranslated) name of the ship's class.
Definition: nlua_ship.c:318
static int shipL_time_mod(lua_State *L)
Gets the ship's time_mod.
Definition: nlua_ship.c:537
static int shipL_eq(lua_State *L)
Checks to see if two ships are the same.
Definition: nlua_ship.c:206
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:389
static int shipL_CPU(lua_State *L)
Gets the ship available CPU.
Definition: nlua_ship.c:505
static int shipL_gfxComm(lua_State *L)
Gets the ship's comm graphics.
Definition: nlua_ship.c:569
static int shipL_baseType(lua_State *L)
Gets the raw (untranslated) name of the ship's base type.
Definition: nlua_ship.c:302
static int shipL_nameRaw(lua_State *L)
Gets the raw (untranslated) name of the ship.
Definition: nlua_ship.c:284
static int shipL_slots(lua_State *L)
Gets the amount of the ship's slots.
Definition: nlua_ship.c:368
static int shipL_description(lua_State *L)
Gets the description of the ship (translated).
Definition: nlua_ship.c:636
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:334
static int shipL_getAll(lua_State *L)
Gets a table containing all the ships.
Definition: nlua_ship.c:240
static int shipL_name(lua_State *L)
Gets the translated name of the ship.
Definition: nlua_ship.c:264
static int shipL_get(lua_State *L)
Gets a ship.
Definition: nlua_ship.c:227
static int shipL_gfx(lua_State *L)
Gets the ship's graphics.
Definition: nlua_ship.c:615
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:350
static int shipL_fitsSlot(lua_State *L)
Checks to see if an outfit fits a ship slot.
Definition: nlua_ship.c:482
static int shipL_gfxTarget(lua_State *L)
Gets the ship's target graphics.
Definition: nlua_ship.c:592

Ship metatable methods.

Definition at line 54 of file nlua_ship.c.