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"
151 return *((LuaSpob*) lua_touserdata(L,ind));
164 luaL_typerror(L, ind, SPOB_METATABLE);
182 else if (lua_isstring(L, ind))
183 p =
spob_get( lua_tostring(L, ind) );
185 luaL_typerror(L, ind, SPOB_METATABLE);
190 NLUA_ERROR(L, _(
"Spob is invalid"));
203 LuaSpob *p = (LuaSpob*) lua_newuserdata(L,
sizeof(LuaSpob));
205 luaL_getmetatable(L, SPOB_METATABLE);
206 lua_setmetatable(L, -2);
220 if (lua_getmetatable(L,ind)==0)
222 lua_getfield(L, LUA_REGISTRYINDEX, SPOB_METATABLE);
225 if (lua_rawequal(L, -1, -2))
245 return NLUA_ERROR(L,_(
"Attempting to get landed spob when player not landed."));
252static int spobL_getBackend( lua_State *L,
int system,
int landable )
262 if (lua_isboolean(L,1)) {
274 else if (lua_isstring(L,1)) {
275 rndspob = lua_tostring(L,1);
280 return NLUA_ERROR(L, _(
"Spob '%s' not found in stack"), rndspob);
289 else if (lua_istable(L,1)) {
294 while (lua_next(L, -2) != 0) {
316 NLUA_INVALID_PARAMETER(L,1);
319 if (rndspob == NULL) {
341 if (rndspob == NULL &&
array_size( spobs ) == 0)
347 return NLUA_ERROR(L, _(
"Spob '%s' not found in stack"), rndspob);
381 return spobL_getBackend( L, 0, 0 );
405 return spobL_getBackend( L, 1, 0 );
421 return spobL_getBackend( L, 1, 1 );
434 int all_spob = lua_toboolean(L,1);
440 lua_rawseti( L, -2, n++ );
478 lua_pushboolean(L,(a == b));
520 lua_pushstring(L, p->name);
534 lua_pushnumber(L,p->population);
552 lua_pushnumber(L,p->radius);
567 if (p->presence.faction < 0)
605 lua_pushstring( L, str );
623 lua_pushstring(L,p->class);
668 for (
int i=1; i<SPOB_SERVICES_MAX; i<<=1) {
669 if (spob_hasService(p, i)) {
670 char lower[STRMAX_SHORT];
672 size_t len = strlen(name) + 1;
673 snprintf( lower,
MIN(len,
sizeof(lower)),
"%c%s", tolower(name[0]), &name[1] );
676 lua_pushstring(L, _(name));
677 lua_setfield(L, -2, lower );
698 if (spob_isFlag( p, SPOB_NOMISNSPAWN )) {
699 lua_pushstring(L,
"nomissionspawn");
700 lua_pushboolean(L, 1);
718 lua_pushboolean( L, p->can_land );
722static int landAllowDeny( lua_State *L,
int allowdeny )
725 int old = p->land_override;
726 p->land_override = allowdeny * !!lua_toboolean(L,2);
730 if (!lua_isnoneornil(L,3))
731 p->land_msg = strdup( luaL_checkstring(L,3) );
734 if (p->land_override != old)
750 return landAllowDeny( L, +1 );
764 return landAllowDeny( L, -1 );
778 lua_pushboolean(L, p->land_override>0);
793 lua_pushboolean(L, p->land_override<0);
824 if (p->gfx_space == NULL) {
826 if (p->gfx_spaceName == NULL)
828 tex =
gl_newImage( p->gfx_spaceName, OPENGL_TEX_MIPMAPS );
849 if (p->gfx_exterior==NULL)
866 lua_pushstring( L, p->gfx_exteriorPath );
881 if (p->gfx_comm==NULL)
903 lua_rawseti(L,-2,i+1);
926 lua_rawseti(L,-2,i+1);
947 for (
int i=0; i<
array_size(p->commodities); i++) {
949 lua_rawseti(L,-2,i+1);
967 lua_pushboolean(L, spob_hasService(p, SPOB_SERVICE_BLACKMARKET));
983 lua_pushboolean(L, spob_isKnown(s));
998 int b = lua_toboolean(L, 2);
1000 int changed = (b != (int)spob_isKnown(p));
1005 spob_rmFlag( p, SPOB_KNOWN );
1046 lua_pushstring(L,p->tags[i]);
1047 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_getLandAllow(lua_State *L)
Gets the land allow 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_landDeny(lua_State *L)
Disallows a player from landing on a spob. The override lasts until the player jumps or lands.
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_colourChar(lua_State *L)
Gets a spob's colour based on its friendliness or hostility to the player.
static const luaL_Reg spob_methods[]
static int spobL_getLandDeny(lua_State *L)
Gets the land deny override status for a spob.
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_gfxComm(lua_State *L)
Gets the texture of the spob for the communication window.
static int spobL_gfxExteriorPath(lua_State *L)
Gets the path of the spob in exterior.
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.
static int spobL_landAllow(lua_State *L)
Allows the player land on a spob no matter what. The override lasts until the player jumps or lands.
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).
char spob_getColourChar(const Spob *p)
Gets the spob colour char.
StarSystem * system_get(const char *sysname)
Get the system from its name.
const 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.
const char * spob_getServiceName(int service)
Gets the (English) name for a service code.
char ** space_getFactionSpob(const int *factions, int landable)
Gets the name of all the spobs that belong to factions.
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.