18#include "nlua_canvas.h"
19#include "nlua_faction.h"
20#include "nlua_outfit.h"
145 return *( (
Ship **)lua_touserdata( L, ind ) );
158 luaL_typerror( L, ind, SHIP_METATABLE );
174 else if ( lua_isstring( L, ind ) )
175 s =
ship_get( lua_tostring( L, ind ) );
177 luaL_typerror( L, ind, SHIP_METATABLE );
182 NLUA_ERROR( L, _(
"Ship is invalid." ) );
196 p = (
const Ship **)lua_newuserdata( L,
sizeof(
Ship *) );
198 luaL_getmetatable( L, SHIP_METATABLE );
199 lua_setmetatable( L, -2 );
213 if ( lua_getmetatable( L, ind ) == 0 )
215 lua_getfield( L, LUA_REGISTRYINDEX, SHIP_METATABLE );
218 if ( lua_rawequal( L, -1, -2 ) )
241 lua_pushboolean( L, 1 );
243 lua_pushboolean( L, 0 );
273 for (
int i = 0; i <
array_size( ships ); i++ ) {
275 lua_rawseti( L, -2, i + 1 );
296 lua_pushstring( L, _( s->
name ) );
316 lua_pushstring( L, s->
name );
432 lua_pushinteger( L, s->
crew );
446 lua_pushnumber( L, s->
mass );
460 lua_pushnumber( L, s->
armour );
506 lua_pushstring( L, s->
license );
523 lua_pushinteger( L, s->
points );
567 int ignore_locked = lua_toboolean( L, 2 );
573 for (
int i = 0; i < 3; i++ ) {
574 for (
int j = 0; j <
array_size( outfit_arrays[i] ); j++ ) {
579 if ( ignore_locked && sslot->
locked )
587 lua_pushstring(L,
"id" );
588 lua_pushinteger(L, k);
592 lua_pushstring( L,
"type" );
596 lua_pushstring( L,
"size" );
600 lua_pushstring( L,
"property" );
604 lua_pushstring( L,
"required" );
605 lua_pushboolean( L, sslot->
required );
608 lua_pushstring( L,
"exclusive" );
612 lua_pushstring( L,
"locked" );
613 lua_pushboolean( L, sslot->
locked );
616 lua_pushstring( L,
"visible" );
617 lua_pushboolean( L, sslot->
visible );
620 if ( sslot->
data != NULL ) {
621 lua_pushstring( L,
"outfit" );
626 lua_rawseti( L, -2, k++ );
644 for (
int i = 0; i < 3; i++ ) {
647 return &outfit_arrays[i][
id - 1];
665 int id = luaL_checkinteger( L, 2 );
669 lua_pushboolean( L, 0 );
688 lua_pushnumber( L, s->
cpu );
769 int size = luaL_optinteger( L, 2, 512 );
772 NLUA_WARN( L, _(
"Unable to get ship comm graphic for '%s'." ), s->
name );
795 NLUA_WARN( L, _(
"Unable to get ship store graphic for '%s'." ),
821 NLUA_WARN( L, _(
"Unable to get ship graphic for '%s'." ), s->
name );
838 lua_pushnumber( L, s->
size );
839 lua_pushnumber( L, s->
size );
852 lua_pushnumber( L, s->
size );
887 const char *str = luaL_optstring( L, 2, NULL );
888 int internal = lua_toboolean( L, 3 );
905 lua_pushstring( L, buf );
919 for (
int i = 0; i <
array_size( ps ); i++ ) {
920 if ( ps[i].p->ship == s ) {
921 lua_pushboolean( L, 1 );
926 for (
int i = 0; i <
array_size( ss ); i++ ) {
927 const Spob *spb = &ss[i];
928 if ( !spob_hasService( spb, SPOB_SERVICE_SHIPYARD ) )
930 if ( !spob_isKnown( spb ) )
933 lua_pushboolean( L, 1 );
937 lua_pushboolean( L, 0 );
975 double dir = luaL_checknumber( L, 2 );
976 double eg = luaL_optnumber( L, 3, 0. );
977 double tilt = luaL_optnumber( L, 4, 0. );
985 if ( canvas_new( &lc, w, h ) )
986 return NLUA_ERROR( L, _(
"Error setting up framebuffer!" ) );
994 0., sx, sy, NULL, NULL );
996 lua_pushcanvas( L, lc );
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int faction_isFaction(int f)
Checks whether or not a faction is valid.
Header file with generic functions and naev-specifics.
int nlua_helperTags(lua_State *L, int idx, char *const *tags)
Helper function to deal with tags.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
const Outfit * luaL_validoutfit(lua_State *L, int ind)
Makes sure the outfit is valid or raises a Lua error.
const Outfit ** lua_pushoutfit(lua_State *L, const Outfit *outfit)
Pushes a outfit on the stack.
static int shipL_tags(lua_State *L)
Gets the ship tags.
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,...
static int shipL_getShipStatDesc(lua_State *L)
Gets the ship stats description for a ship.
static int shipL_cargo(lua_State *L)
Gets the number of cargo of the ship.
static int shipL_mass(lua_State *L)
Gets the number of mass of the ship.
static int shipL_fuelConsumption(lua_State *L)
Gets the number of fuel consumption of the ship.
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_fabricator(lua_State *L)
Gets the raw (untranslated) fabricator of the ship.
static int shipL_price(lua_State *L)
Gets the ship's price, with and without default outfits.
static int shipL_gfxStore(lua_State *L)
Gets the ship's store graphics.
static int shipL_license(lua_State *L)
Gets license required for the ship.
static int shipL_screenSize(lua_State *L)
Gets the onscreen size of the ship.
static int shipL_render(lua_State *L)
Renders the pilot to a canvas.
const Ship ** lua_pushship(lua_State *L, const Ship *ship)
Pushes a ship on the stack.
int nlua_loadShip(nlua_env env)
Loads the ship library.
static int shipL_crew(lua_State *L)
Gets the number of crew of the ship.
static int shipL_class(lua_State *L)
Gets the raw (untranslated) name of the ship's class.
int lua_isship(lua_State *L, int ind)
Checks to see if ind is 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_dims(lua_State *L)
Gets the onscreen dimensions of the ship.
static int shipL_time_mod(lua_State *L)
Gets the ship's time_mod.
static int shipL_armour(lua_State *L)
Gets the number of armour of the ship.
const Ship * luaL_validship(lua_State *L, int ind)
Makes sure the ship is valid or raises a Lua error.
const Ship * luaL_checkship(lua_State *L, int ind)
Gets ship at index or raises error if there is no ship at index.
static int shipL_eq(lua_State *L)
Checks to see if two ships are the same.
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_CPU(lua_State *L)
Gets the ship available CPU.
static int shipL_gfxComm(lua_State *L)
Gets the ship's comm graphics.
const Ship * lua_toship(lua_State *L, int ind)
Lua bindings to interact with ships.
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_nameRaw(lua_State *L)
Gets the raw (untranslated) name of 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_gfxPath(lua_State *L)
Gets the path where the ship's graphics are located. Useful for seeing if two ships share the same gr...
static const luaL_Reg shipL_methods[]
static int shipL_slots(lua_State *L)
Gets the amount of the ship's slots.
static int shipL_description(lua_State *L)
Gets the description of the ship (translated).
static int shipL_classDisplay(lua_State *L)
Gets the raw (untranslated) display name of the ship's class (not ship's base class).
static const ShipOutfitSlot * ship_outfitSlotFromID(const Ship *s, int id)
Gets an outfit slot from ID.
static int shipL_getAll(lua_State *L)
Gets a table containing all the ships.
static int shipL_faction(lua_State *L)
Gets the faction of a ship.
static int shipL_name(lua_State *L)
Gets the translated name of the ship.
static int shipL_get(lua_State *L)
Gets a ship.
static int shipL_gfx(lua_State *L)
Gets the ship's graphics.
static int shipL_fitsSlot(lua_State *L)
Checks to see if an outfit fits a ship slot.
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
void gl_getSpriteFromDir(int *x, int *y, int sx, int sy, double dir)
Sets x and y to be the appropriate sprite for glTexture using dir.
int outfit_fitsSlot(const Outfit *o, const OutfitSlot *s)
Checks to see if an outfit fits a slot.
const char * slotName(const OutfitSlotType type)
const char * slotSize(const OutfitSlotSize o)
Gets the slot size as a string.
const PlayerShip_t * player_getShipStack(void)
Gets the array (array.h) of the player's ships.
int ship_size(const Ship *s)
Gets the size of the ship.
const char * ship_class(const Ship *s)
Gets the ship's class name in human readable form.
const char * ship_classDisplay(const Ship *s)
Gets the ship's display class in human readable form.
credits_t ship_basePrice(const Ship *s)
Gets the ship's base price (no outfits).
credits_t ship_buyPrice(const Ship *s)
The ship buy price, includes default outfits.
const Ship * ship_getAll(void)
Gets the array (array.h) of all ships.
glTexture * ship_gfxComm(const Ship *s, int size, double tilt, double dir, const Lighting *Lscene)
Loads the ship's comm graphic.
void ship_renderFramebuffer(const Ship *s, GLuint fbo, double fw, double fh, double dir, double engine_glow, double tilt, double r, int sx, int sy, const glColour *c, const Lighting *L)
Renders a ship to a framebuffer.
glTexture * ship_gfxStore(const Ship *s, int size, double dir, double updown, double glow)
Get the store gfx.
const Ship * ship_get(const char *name)
Gets a ship based on its name.
int ship_gfxLoad(Ship *s)
Loads the graphics for a ship if necessary.
int ss_statsGetLua(lua_State *L, const ShipStats *s, const char *name, int internal)
Gets a ship stat value by name and pushes it to Lua.
int ss_statsDesc(const ShipStats *s, char *buf, int len, int newline)
Writes the ship statistics description.
const char * sp_display(unsigned int spid)
Gets the display name of a slot property (in English).
Spob * spob_getAll(void)
Gets an array (array.h) of all spobs.
Pilot slot that can contain outfits.
A ship outfit, depends radically on the type.
ShipOutfitSlot * outfit_utility
ShipOutfitSlot * outfit_weapon
ShipOutfitSlot * outfit_structure
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Abstraction for rendering sprite sheets.
int tech_hasShip(const tech_group_t *tech, const Ship *ship)
Checks to see whether a tech group contains a ship.