20#include "land_outfits.h"
21#include "map_overlay.h"
22#include "nlua_colour.h"
23#include "nlua_commodity.h"
24#include "nlua_faction.h"
25#include "nlua_outfit.h"
27#include "nlua_system.h"
154 return *( (LuaSpob *)lua_touserdata( L, ind ) );
167 luaL_typerror( L, ind, SPOB_METATABLE );
184 }
else if (lua_isstring( L, ind ))
185 p =
spob_get( lua_tostring( L, ind ) );
187 luaL_typerror( L, ind, SPOB_METATABLE );
192 NLUA_ERROR( L, _(
"Spob is invalid" ) );
205 LuaSpob *p = (LuaSpob *)lua_newuserdata( L,
sizeof( LuaSpob ) );
207 luaL_getmetatable( L, SPOB_METATABLE );
208 lua_setmetatable( L, -2 );
222 if (lua_getmetatable( L, ind ) == 0)
224 lua_getfield( L, LUA_REGISTRYINDEX, SPOB_METATABLE );
227 if (lua_rawequal( L, -1, -2 ))
248 L, _(
"Attempting to get landed spob when player not landed." ) );
255static int spobL_getBackend( lua_State *L,
int system,
int landable )
265 if (lua_isboolean( L, 1 )) {
277 else if (lua_isstring( L, 1 )) {
278 rndspob = lua_tostring( L, 1 );
283 return NLUA_ERROR( L, _(
"Spob '%s' not found in stack" ),
293 else if (lua_istable( L, 1 )) {
298 while (lua_next( L, -2 ) != 0) {
319 NLUA_INVALID_PARAMETER( L, 1 );
322 if (rndspob == NULL) {
325 for (
int i = 0; i <
array_size( spobs ); i++) {
344 if (rndspob == NULL &&
array_size( spobs ) == 0)
350 return NLUA_ERROR( L, _(
"Spob '%s' not found in stack" ), rndspob );
386 return spobL_getBackend( L, 0, 0 );
412 return spobL_getBackend( L, 1, 0 );
428 return spobL_getBackend( L, 1, 1 );
442 int all_spob = lua_toboolean( L, 1 );
448 lua_rawseti( L, -2, n++ );
487 lua_pushboolean( L, ( a == b ) );
529 lua_pushstring( L, p->name );
543 lua_pushnumber( L, p->population );
561 lua_pushnumber( L, p->radius );
576 if (p->presence.faction < 0)
633 lua_pushstring( L, str );
651 lua_pushstring( L, p->class );
698 for (
int i = 1; i < SPOB_SERVICES_MAX; i <<= 1) {
699 if (spob_hasService( p, i )) {
700 char lower[STRMAX_SHORT];
702 size_t len = strlen( name ) + 1;
703 snprintf( lower,
MIN( len,
sizeof( lower ) ),
"%c%s",
704 tolower( name[0] ), &name[1] );
707 lua_pushstring( L, _( name ) );
708 lua_setfield( L, -2, lower );
729 if (spob_isFlag( p, SPOB_NOMISNSPAWN )) {
730 lua_pushstring( L,
"nomissionspawn" );
731 lua_pushboolean( L, 1 );
732 lua_settable( L, -3 );
749 lua_pushboolean( L, p->can_land );
753static int landAllowDeny( lua_State *L,
int allowdeny )
756 int old = p->land_override;
757 p->land_override = allowdeny * !!lua_toboolean( L, 2 );
761 if (!lua_isnoneornil( L, 3 ))
762 p->land_msg = strdup( luaL_checkstring( L, 3 ) );
765 if (p->land_override != old)
785 return landAllowDeny( L, +1 );
803 return landAllowDeny( L, -1 );
817 lua_pushboolean( L, p->land_override > 0 );
832 lua_pushboolean( L, p->land_override < 0 );
863 if (p->gfx_space == NULL) {
865 if (p->gfx_spaceName == NULL)
867 tex =
gl_newImage( p->gfx_spaceName, OPENGL_TEX_MIPMAPS );
887 if (p->gfx_exterior == NULL)
904 lua_pushstring( L, p->gfx_exteriorPath );
919 if (p->gfx_comm == NULL)
942 lua_rawseti( L, -2, i + 1 );
966 lua_rawseti( L, -2, i + 1 );
988 for (
int i = 0; i <
array_size( p->commodities ); i++) {
990 lua_rawseti( L, -2, i + 1 );
1008 lua_pushboolean( L, spob_hasService( p, SPOB_SERVICE_BLACKMARKET ) );
1024 lua_pushboolean( L, spob_isKnown( s ) );
1039 int b = lua_toboolean( L, 2 );
1041 int changed = ( b != (int)spob_isKnown( p ) );
1046 spob_rmFlag( p, SPOB_KNOWN );
1067 lua_pushboolean( L, spob_isFlag( p, SPOB_HOSTILE ) );
1081 if (lua_toboolean( L, 2 ))
1082 spob_setFlag( p, SPOB_HOSTILE );
1084 spob_rmFlag( p, SPOB_HOSTILE );
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.
int nlua_helperTags(lua_State *L, int idx, char *const *tags)
Helper function to deal with tags.
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_reputation(lua_State *L)
Gets the local reputation of the faction at 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_isHostile(lua_State *L)
Checks to see if a spob currently has the hostile flag set.
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_setHostile(lua_State *L)
Sets the hostile flag of a spob.
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.
double system_getReputationOrGlobal(const StarSystem *sys, int faction)
Gets the local reputation of the player in a system or returns the global standing.
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.
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_getSystemName(const char *spobname)
Get the name of a system from a spobname.
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.
StarSystem * spob_getSystem(const Spob *spob)
Gets the system a spob is in.
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.