19#include "land_outfits.h"
22#include "map_overlay.h"
23#include "nlua_colour.h"
24#include "nlua_commodity.h"
25#include "nlua_faction.h"
26#include "nlua_outfit.h"
28#include "nlua_system.h"
141 return *((LuaSpob*) lua_touserdata(L,ind));
154 luaL_typerror(L, ind, SPOB_METATABLE);
173 else if (lua_isstring(L, ind))
174 p =
spob_get( lua_tostring(L, ind) );
176 luaL_typerror(L, ind, SPOB_METATABLE);
181 NLUA_ERROR(L, _(
"Spob is invalid"));
194 LuaSpob *p = (LuaSpob*) lua_newuserdata(L,
sizeof(LuaSpob));
196 luaL_getmetatable(L, SPOB_METATABLE);
197 lua_setmetatable(L, -2);
211 if (lua_getmetatable(L,ind)==0)
213 lua_getfield(L, LUA_REGISTRYINDEX, SPOB_METATABLE);
216 if (lua_rawequal(L, -1, -2))
236 NLUA_ERROR(L,_(
"Attempting to get landed spob when player not landed."));
245static int spobL_getBackend( lua_State *L,
int system,
int landable )
256 if (lua_isboolean(L,1)) {
270 else if (lua_isstring(L,1)) {
271 rndspob = lua_tostring(L,1);
276 NLUA_ERROR(L, _(
"Spob '%s' not found in stack"), rndspob);
288 else if (lua_istable(L,1)) {
293 while (lua_next(L, -2) != 0) {
317 NLUA_INVALID_PARAMETER(L);
320 if (rndspob == NULL) {
342 if (rndspob == NULL &&
array_size( spobs ) == 0)
348 NLUA_ERROR(L, _(
"Spob '%s' not found in stack"), rndspob);
384 return spobL_getBackend( L, 0, 0 );
408 return spobL_getBackend( L, 1, 0 );
424 return spobL_getBackend( L, 1, 1 );
437 int all_spob = lua_toboolean(L,1);
443 lua_rawseti( L, -2, n++ );
481 lua_pushboolean(L,(a == b));
522 lua_pushstring(L, p->name);
536 lua_pushnumber(L,p->population);
554 lua_pushnumber(L,p->radius);
569 if (p->presence.faction < 0)
606 lua_pushstring(L,p->class);
651 for (
int i=1; i<SPOB_SERVICES_MAX; i<<=1) {
652 if (spob_hasService(p, i)) {
653 char lower[STRMAX_SHORT];
655 size_t len = strlen(name) + 1;
656 snprintf( lower,
MIN(len,
sizeof(lower)),
"%c%s", tolower(name[0]), &name[1] );
659 lua_pushstring(L, _(name));
660 lua_setfield(L, -2, lower );
681 if (spob_isFlag( p, SPOB_NOMISNSPAWN )) {
682 lua_pushstring(L,
"nomissionspawn");
683 lua_pushboolean(L, 1);
701 lua_pushboolean( L, p->can_land );
716 int old = p->land_override;
718 p->land_override = !!lua_toboolean(L,2);
721 if (p->land_override != old)
738 lua_pushboolean(L, p->land_override);
769 if (p->gfx_space == NULL) {
771 if (p->gfx_spaceName == NULL)
773 tex =
gl_newImage( p->gfx_spaceName, OPENGL_TEX_MIPMAPS );
794 if (p->gfx_exterior==NULL)
817 lua_rawseti(L,-2,i+1);
840 lua_rawseti(L,-2,i+1);
861 for (
int i=0; i<
array_size(p->commodities); i++) {
863 lua_rawseti(L,-2,i+1);
881 lua_pushboolean(L, spob_hasService(p, SPOB_SERVICE_BLACKMARKET));
897 lua_pushboolean(L, spob_isKnown(s));
912 int b = lua_toboolean(L, 2);
914 int changed = (b != (int)spob_isKnown(p));
919 spob_rmFlag( p, SPOB_KNOWN );
960 lua_pushstring(L,p->tags[i]);
961 lua_pushboolean(L,1);
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void outfits_updateEquipmentOutfits(void)
Updates the outfitter and equipment outfit image arrays.
Header file with generic functions and naev-specifics.
glColour * lua_pushcolour(lua_State *L, glColour colour)
Pushes a colour on the stack.
Commodity ** lua_pushcommodity(lua_State *L, Commodity *commodity)
Pushes a commodity on the stack.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
int lua_isfaction(lua_State *L, int ind)
Checks to see if ind is a faction.
LuaFaction lua_tofaction(lua_State *L, int ind)
Gets faction at index.
const Outfit ** lua_pushoutfit(lua_State *L, const Outfit *outfit)
Pushes a outfit on the stack.
const Ship ** lua_pushship(lua_State *L, const Ship *ship)
Pushes a ship on the stack.
static int spobL_getLandOverride(lua_State *L)
Gets the land override status for a spob.
static int spobL_commoditiesSold(lua_State *L)
Gets the commodities sold at a spob.
static int spobL_gfxExterior(lua_State *L)
Gets the texture of the spob in exterior.
static int spobL_colour(lua_State *L)
Gets a spob's colour based on its friendliness or hostility to the player.
LuaSpob lua_tospob(lua_State *L, int ind)
This module allows you to handle the spobs from Lua.
static int spobL_getLandable(lua_State *L)
Gets a spob only if it's landable.
static int spobL_getAll(lua_State *L)
Gets all the spobs. Lua function parameter: boolean all_spob Whether or not to get all Spob,...
static int spobL_radius(lua_State *L)
Gets the spob's radius.
static int spobL_population(lua_State *L)
Gets the spob's population.
static int spobL_eq(lua_State *L)
You can use the '==' operator within Lua to compare spobs with this.
static int spobL_outfitsSold(lua_State *L)
Gets the outfits sold at a spob.
static int spobL_flags(lua_State *L)
Checks for spob flags.
LuaSpob luaL_checkspob(lua_State *L, int ind)
Gets spob at index raising an error if isn't a spob.
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.
static const luaL_Reg spob_methods[]
static int spobL_faction(lua_State *L)
Gets the spob's faction.
static int spobL_gfxSpace(lua_State *L)
Gets the texture of the spob in space.
static int spobL_shipsSold(lua_State *L)
Gets the ships sold at a spob.
static int spobL_nameRaw(lua_State *L)
Gets the spob's raw (untranslated) name.
static int spobL_isBlackMarket(lua_State *L)
Checks to see if a spob is a black market.
static int spobL_system(lua_State *L)
Gets the system corresponding to a spob. Lua function parameter: Spob p Spob to get system of....
static int spobL_classLong(lua_State *L)
Gets the spob's class in long human-readable format already translated.
static int spobL_recordCommodityPriceAtTime(lua_State *L)
Records commodity prices at a given time, adding to players stats.
static int spobL_get(lua_State *L)
Gets a spob.
LuaSpob * lua_pushspob(lua_State *L, LuaSpob spob)
Pushes a spob on the stack.
static int spobL_getS(lua_State *L)
Gets a spob and its corresponding system.
static int spobL_canland(lua_State *L)
Gets whether or not the player can land on the spob (or bribe it).
static int spobL_class(lua_State *L)
Gets the spob's class.
static int spobL_services(lua_State *L)
Checks for spob services.
Spob * luaL_validspob(lua_State *L, int ind)
Gets a spob directly.
int nlua_loadSpob(nlua_env env)
Loads the spob library.
static int spobL_position(lua_State *L)
Gets the position of the spob in the system.
static int spobL_setKnown(lua_State *L)
Sets a spobs's known state.
static int spobL_tags(lua_State *L)
Gets the spob tags.
static int spobL_name(lua_State *L)
Gets the spob's translated name.
static int spobL_isKnown(lua_State *L)
Checks to see if a spob is known by the player.
int lua_isspob(lua_State *L, int ind)
Checks to see if ind is a spob.
static int spobL_cur(lua_State *L)
Gets the current spob - MUST BE LANDED.
LuaSystem * lua_pushsystem(lua_State *L, LuaSystem sys)
Pushes a system on the stack.
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
ntime_t luaL_validtime(lua_State *L, int ind)
Gets a time directly.
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
void arrayShuffle(void **array)
Randomly sorts an array (array.h) of pointers in place with the Fisher-Yates shuffle.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
void spob_averageSeenPricesAtTime(const Spob *p, const ntime_t tupdate)
Adds cost of commodities on spob p to known statistics at time t.
const glColour * spob_getColour(const Spob *p)
Gets the spob colour.
Spob * spob_getAll(void)
Gets an array (array.h) of all spobs.
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
void space_factionChange(void)
Mark when a faction changes.
const char * space_getRndSpob(int landable, unsigned int services, int(*filter)(Spob *p))
Gets the name of a random spob.
int spob_index(const Spob *p)
Gets the ID of a spob.
int spob_hasSystem(const Spob *spb)
Get whether or not a spob has a system (i.e. is on the map).
StarSystem * system_get(const char *sysname)
Get the system from its name.
char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
void spob_setKnown(Spob *p)
Sets a spob's known status, if it's real.
void spob_updateLand(Spob *p)
Updates the land possibilities of a spob.
void spob_gfxLoad(Spob *spob)
Loads a spob's graphics (and radius).
Spob * spob_getIndex(int ind)
Gets spob by index.
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
const char * spob_getClassName(const char *class)
Gets the long class name for a spob.
char ** space_getFactionSpob(int *factions, int landable)
Gets the name of all the spobs that belong to factions.
const char * spob_getServiceName(int service)
Gets the (English) name for a service code.
int system_index(const StarSystem *sys)
Gets the index of a star system.
A ship outfit, depends radically on the type.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Abstraction for rendering sprite sheets.
Ship ** tech_getShip(const tech_group_t *tech)
Gets all of the ships associated to a tech group.
Outfit ** tech_getOutfit(const tech_group_t *tech)
Gets all of the outfits associated to a tech group.