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);
165 else if (lua_isstring(L, ind))
168 luaL_typerror(L, ind, SYSTEM_METATABLE);
173 NLUA_ERROR(L, _(
"System is invalid"));
187 LuaSystem *s = (LuaSystem*) lua_newuserdata(L,
sizeof(LuaSystem));
189 luaL_getmetatable(L, SYSTEM_METATABLE);
190 lua_setmetatable(L, -2);
205 if (lua_getmetatable(L,ind)==0)
207 lua_getfield(L, LUA_REGISTRYINDEX, SYSTEM_METATABLE);
210 if (lua_rawequal(L, -1, -2))
251 if (lua_isstring(L,1)) {
264 NLUA_INVALID_PARAMETER(L);
268 NLUA_ERROR(L, _(
"No matching systems found."));
288 lua_rawseti( L, -2, i+1 );
311 lua_pushboolean(L,1);
313 lua_pushboolean(L,0);
333 lua_pushstring(L, _(sys->name));
367 lua_pushstring(L, sys->name);
381 if (s->faction == -1)
398 if (s->background==NULL)
400 lua_pushstring(L,s->background);
420 lua_pushnumber(L, s->nebu_density);
421 lua_pushnumber(L, s->nebu_volatility);
435 lua_pushnumber( L, s->interference );
462 const char *start, *goal;
467 h = lua_toboolean(L,3);
468 k = !lua_toboolean(L,4);
470 if (lua_gettop(L) > 1) {
471 if (lua_isstring(L,2))
472 goal = lua_tostring(L,2);
478 NLUA_INVALID_PARAMETER(L);
486 if (strcmp(start,goal)==0) {
487 lua_pushnumber(L, 0.);
491 s = map_getJumpPath( start, goal, k, h, NULL );
493 lua_pushnumber(L, HUGE_VAL);
525 StarSystem *sys, *sysp;
528 const char *start, *goal;
530 h = lua_toboolean(L,3);
539 s = map_getJumpPath( start, goal, 1, h, NULL );
552 lua_rawseti(L, -2, ++pushed);
559 lua_rawseti(L, -2, ++pushed);
583 h = lua_toboolean(L,2);
589 if (jp_isFlag(&s->jumps[i], JP_EXITONLY ))
591 if (!h && jp_isFlag(&s->jumps[i], JP_HIDDEN))
595 lua_rawseti(L,-2,
id++);
613 int exitonly, pushed;
617 exitonly = lua_toboolean(L,2);
625 if ((exitonly) && (jp_isFlag( &s->jumps[i], JP_EXITONLY)))
629 lj.
destid = s->jumps[i].targetid;
631 lua_rawseti(L,-2, ++pushed);
651 for (
int i=0; i<
array_size(s->asteroids); i++) {
654 lua_pushinteger(L,i+1);
655 lua_setfield(L,-2,
"id");
658 lua_setfield(L,-2,
"pos");
660 lua_pushnumber(L,s->asteroids[i].density);
661 lua_setfield(L,-2,
"density");
663 lua_pushnumber(L,s->asteroids[i].radius);
664 lua_setfield(L,-2,
"radius");
666 lua_rawseti(L,-2,i+1);
688 unsigned int player_only;
691 vec2 zero = { .
x = 0., .y = 0., .mod = 0., .angle = 0. };
696 nb = luaL_checkint(L,2);
697 pos = luaL_optvector(L,3,&zero);
698 vel = luaL_optvector(L,4,&zero);
699 lifelength = luaL_optnumber(L,5, -1.);
700 player_only = lua_toboolean(L,6);
702 lua_pushnumber( L,
gatherable_init( commodity, *pos, *vel, lifelength, nb, player_only ) );
723 for (
int i=0; i<
array_size(s->presence); i++) {
725 if (s->presence[i].value <= 0)
728 lua_pushstring( L,
faction_name(s->presence[i].faction) );
729 lua_pushnumber(L,s->presence[i].value);
753 lua_rawseti(L,-2,i+1);
790 if (lua_isstring(L, 2)) {
792 const char *cmd = lua_tostring(L, 2);
796 if (strcmp(cmd,
"all") == 0)
798 else if (strcmp(cmd,
"friendly") == 0)
800 else if (strcmp(cmd,
"hostile") == 0)
802 else if (strcmp(cmd,
"neutral") == 0)
828 lua_pushnumber(L, presence);
846 lua_pushnumber( L, sys->radius );
862 lua_pushboolean(L, sys_isKnown(sys));
882 b = lua_toboolean(L, 2);
883 if (lua_gettop(L) > 2)
884 r = lua_toboolean(L, 3);
887 sys_setFlag( sys, SYSTEM_KNOWN );
889 sys_rmFlag( sys, SYSTEM_KNOWN );
893 for (
int i=0; i <
array_size(sys->spobs); i++)
895 for (
int i=0; i <
array_size(sys->jumps); i++)
896 jp_setFlag( &sys->jumps[i], JP_KNOWN );
899 for (
int i=0; i <
array_size(sys->spobs); i++)
900 spob_rmFlag( sys->spobs[i], SPOB_KNOWN );
901 for (
int i=0; i <
array_size(sys->jumps); i++)
902 jp_rmFlag( &sys->jumps[i], JP_KNOWN );
925 lua_pushboolean(L, sys_isFlag( sys, SYSTEM_HIDDEN ));
941 int b = lua_toboolean(L,2);
943 sys_setFlag( sys, SYSTEM_HIDDEN );
945 sys_rmFlag( sys, SYSTEM_HIDDEN );
985 str = luaL_optstring( L, 2, NULL );
986 r = luaL_optnumber( L, 3, -1. );
990 id = ovr_mrkAddPoint( str, vec->
x, vec->
y );
992 id = ovr_mrkAddCircle( str, vec->
x, vec->
y, r );
993 lua_pushnumber( L,
id );
1007 unsigned int id = luaL_checklong( L, 1 );
1026 lua_pushstring(L,s->tags[i]);
1027 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, vec2 pos, 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.
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,...