15#include "nlua_system.h"
19#include "land_outfits.h"
21#include "gatherable.h"
23#include "map_overlay.h"
25#include "nlua_commodity.h"
26#include "nlua_faction.h"
132 return *((LuaSystem*) lua_touserdata(L,ind));
145 luaL_typerror(L, ind, SYSTEM_METATABLE);
164 else if (lua_isstring(L, ind))
167 luaL_typerror(L, ind, SYSTEM_METATABLE);
172 NLUA_ERROR(L, _(
"System is invalid"));
186 LuaSystem *s = (LuaSystem*) lua_newuserdata(L,
sizeof(LuaSystem));
188 luaL_getmetatable(L, SYSTEM_METATABLE);
189 lua_setmetatable(L, -2);
204 if (lua_getmetatable(L,ind)==0)
206 lua_getfield(L, LUA_REGISTRYINDEX, SYSTEM_METATABLE);
209 if (lua_rawequal(L, -1, -2))
250 if (lua_isstring(L,1)) {
263 NLUA_INVALID_PARAMETER(L,1);
267 return NLUA_ERROR(L, _(
"No matching systems found."));
285 lua_rawseti( L, -2, i+1 );
308 lua_pushboolean(L,1);
310 lua_pushboolean(L,0);
330 lua_pushstring(L, _(sys->name));
364 lua_pushstring(L, sys->name);
378 if (s->faction == -1)
395 if (s->background==NULL)
397 lua_pushstring(L,s->background);
416 lua_pushnumber(L, s->nebu_density);
417 lua_pushnumber(L, s->nebu_volatility);
431 lua_pushnumber( L, s->interference );
458 const char *start, *goal;
463 h = lua_toboolean(L,3);
464 k = !lua_toboolean(L,4);
466 if (lua_gettop(L) > 1) {
467 if (lua_isstring(L,2))
468 goal = lua_tostring(L,2);
474 NLUA_INVALID_PARAMETER(L,2);
482 if (strcmp(start,goal)==0) {
483 lua_pushnumber(L, 0.);
487 s = map_getJumpPath( start, NULL, goal, k, h, NULL, NULL );
489 lua_pushnumber(L, HUGE_VAL);
521 StarSystem *sys, *sysp;
524 const char *start, *goal;
526 h = lua_toboolean(L,3);
535 s = map_getJumpPath( start, NULL, goal, 1, h, NULL, NULL );
548 lua_rawseti(L, -2, ++pushed);
555 lua_rawseti(L, -2, ++pushed);
579 h = lua_toboolean(L,2);
585 if (jp_isFlag(&s->jumps[i], JP_EXITONLY ))
587 if (!h && jp_isFlag(&s->jumps[i], JP_HIDDEN))
591 lua_rawseti(L,-2,
id++);
610 int exitonly = lua_toboolean(L,2);
618 if ((exitonly) && (jp_isFlag( &s->jumps[i], JP_EXITONLY)))
622 lj.
destid = s->jumps[i].targetid;
624 lua_rawseti(L,-2, ++pushed);
644 for (
int i=0; i<
array_size(s->asteroids); i++) {
647 lua_pushinteger(L,i+1);
648 lua_setfield(L,-2,
"id");
651 lua_setfield(L,-2,
"pos");
653 lua_pushnumber(L,s->asteroids[i].density);
654 lua_setfield(L,-2,
"density");
656 lua_pushnumber(L,s->asteroids[i].radius);
657 lua_setfield(L,-2,
"radius");
659 lua_rawseti(L,-2,i+1);
681 unsigned int player_only;
684 vec2 zero = { .x = 0., .y = 0., .mod = 0., .angle = 0. };
689 nb = luaL_checkint(L,2);
690 pos = luaL_optvector(L,3,&zero);
691 vel = luaL_optvector(L,4,&zero);
692 lifelength = luaL_optnumber(L,5, -1.);
693 player_only = lua_toboolean(L,6);
695 lua_pushnumber( L,
gatherable_init( commodity, pos, vel, lifelength, nb, player_only ) );
716 for (
int i=0; i<
array_size(s->presence); i++) {
718 if (s->presence[i].value <= 0)
721 lua_pushstring( L,
faction_name(s->presence[i].faction) );
722 lua_pushnumber(L,s->presence[i].value);
746 lua_rawseti(L,-2,i+1);
783 if (lua_isstring(L, 2)) {
785 const char *cmd = lua_tostring(L, 2);
789 if (strcmp(cmd,
"all") == 0)
791 else if (strcmp(cmd,
"friendly") == 0)
793 else if (strcmp(cmd,
"hostile") == 0)
795 else if (strcmp(cmd,
"neutral") == 0)
821 lua_pushnumber(L, presence);
839 lua_pushnumber( L, sys->radius );
855 lua_pushboolean(L, sys_isKnown(sys));
875 b = lua_toboolean(L, 2);
876 if (lua_gettop(L) > 2)
877 r = lua_toboolean(L, 3);
880 sys_setFlag( sys, SYSTEM_KNOWN );
882 sys_rmFlag( sys, SYSTEM_KNOWN );
886 for (
int i=0; i <
array_size(sys->spobs); i++)
888 for (
int i=0; i <
array_size(sys->jumps); i++)
889 jp_setFlag( &sys->jumps[i], JP_KNOWN );
892 for (
int i=0; i <
array_size(sys->spobs); i++)
893 spob_rmFlag( sys->spobs[i], SPOB_KNOWN );
894 for (
int i=0; i <
array_size(sys->jumps); i++)
895 jp_rmFlag( &sys->jumps[i], JP_KNOWN );
918 lua_pushboolean(L, sys_isFlag( sys, SYSTEM_HIDDEN ));
934 int b = lua_toboolean(L,2);
936 sys_setFlag( sys, SYSTEM_HIDDEN );
938 sys_rmFlag( sys, SYSTEM_HIDDEN );
978 str = luaL_optstring( L, 2, NULL );
979 r = luaL_optnumber( L, 3, -1. );
983 id = ovr_mrkAddPoint( str, vec->
x, vec->
y );
985 id = ovr_mrkAddCircle( str, vec->
x, vec->
y, r );
986 lua_pushnumber( L,
id );
1000 unsigned int id = luaL_checklong( L, 1 );
1019 lua_pushstring(L,s->tags[i]);
1020 lua_pushboolean(L,1);
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
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’.
int * faction_getGroup(int which)
Returns an array of faction ids.
const char * faction_name(int f)
Gets a factions "real" (internal) name.
int gatherable_init(const Commodity *com, const vec2 *pos, const vec2 *vel, double lifeleng, int qtt, unsigned int player_only)
Initializes a gatherable object.
void outfits_updateEquipmentOutfits(void)
Updates the outfitter and equipment outfit image arrays.
Header file with generic functions and naev-specifics.
Commodity * luaL_validcommodity(lua_State *L, int ind)
Makes sure the commodity is valid or raises a Lua error.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
LuaFaction luaL_validfaction(lua_State *L, int ind)
Gets faction (or faction name) at index, raising an error if type isn't a valid faction.
LuaJump * lua_pushjump(lua_State *L, LuaJump jump)
Pushes a jump on the stack.
LuaSpob * lua_pushspob(lua_State *L, LuaSpob spob)
Pushes a spob on the stack.
Spob * luaL_validspob(lua_State *L, int ind)
Gets a spob directly.
int lua_isspob(lua_State *L, int ind)
Checks to see if ind is a spob.
static int systemL_name(lua_State *L)
Returns the system's translated name.
static int systemL_adjacent(lua_State *L)
Gets all the adjacent systems to a system.
static int systemL_position(lua_State *L)
Returns the position of the system.
static int systemL_eq(lua_State *L)
Check systems for equality.
LuaSystem luaL_checksystem(lua_State *L, int ind)
Gets system at index raising an error if type doesn't match.
static int systemL_faction(lua_State *L)
Gets system faction.
static int systemL_markerClear(lua_State *L)
Clears the system markers.
static int systemL_markerAdd(lua_State *L)
Adds a system marker.
int nlua_loadSystem(nlua_env env)
Loads the system library.
LuaSystem * lua_pushsystem(lua_State *L, LuaSystem sys)
Pushes a system on the stack.
static int systemL_presence(lua_State *L)
Gets the presence in the system.
static int systemL_jumpPath(lua_State *L)
Gets jump path from current system, or to another.
static int systemL_interference(lua_State *L)
Gets the system's interference level.
static int systemL_addGatherable(lua_State *L)
Adds a gatherable object.
static int systemL_setHidden(lua_State *L)
Sets a system to be hidden to the player.
static int systemL_markerRm(lua_State *L)
Removes a system marker.
static const luaL_Reg system_methods[]
static int systemL_asteroidFields(lua_State *L)
Gets all the asteroid fields in a system.
static int systemL_hidden(lua_State *L)
Checks to see if a system is hidden by the player.
static int systemL_background(lua_State *L)
Gets system background.
static int systemL_nebula(lua_State *L)
Gets the system's nebula parameters.
static int systemL_tags(lua_State *L)
Gets the system tags.
StarSystem * luaL_validsystem(lua_State *L, int ind)
Gets system (or system name) at index raising an error if type doesn't match.
static int systemL_jumps(lua_State *L)
Gets all the jumps in a system.
static int systemL_presences(lua_State *L)
Returns the factions that have presence in a system and their respective presence values....
static int systemL_isknown(lua_State *L)
Checks to see if a system is known by the player.
static int systemL_spobs(lua_State *L)
Gets the spobs in a system.
static int systemL_jumpdistance(lua_State *L)
Gets jump distance from current system, or to another.
LuaSystem lua_tosystem(lua_State *L, int ind)
Lua system module.
static int systemL_cur(lua_State *L)
Gets the current system.
static int systemL_setknown(lua_State *L)
Sets a system's known state.
static int systemL_get(lua_State *L)
Gets a system.
static int systemL_getAll(lua_State *L)
Gets all the systems. Lua return parameter: {System,...} A list of all the systems.
static int systemL_radius(lua_State *L)
Gets the radius of the system.
static int systemL_nameRaw(lua_State *L)
Returns the system's raw (untranslated) name.
int lua_issystem(lua_State *L, int ind)
Checks to see if ind is a system.
vec2 * luaL_checkvector(lua_State *L, int ind)
Gets vector at index making sure type is valid.
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
StarSystem * system_getIndex(int id)
Get the system by its index.
int spob_index(const Spob *p)
Gets the ID of a spob.
StarSystem * system_getAll(void)
Gets an array (array.h) of all star systems.
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.
double system_getPresence(const StarSystem *sys, int faction)
Get the presence of a faction in a system.
int system_index(const StarSystem *sys)
Gets the index of a star system.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...