10#include "nlua_safelanes.h"
13#include "nlua_faction.h"
14#include "nlua_system.h"
66 int faction, standing, onlyknown;
71 if ( !lua_isnoneornil( L, 1 ) )
75 std = luaL_optstring( L, 2, NULL );
76 if ( !lua_isnoneornil( L, 3 ) )
80 onlyknown = lua_toboolean( L, 4 );
84 if ( ( faction >= 0 ) && ( std != NULL ) ) {
85 if ( strcmp( std,
"friendly" ) == 0 )
86 standing |= SAFELANES_FRIENDLY;
87 else if ( strcmp( std,
"neutral" ) == 0 )
88 standing |= SAFELANES_NEUTRAL;
89 else if ( strcmp( std,
"hostile" ) == 0 )
90 standing |= SAFELANES_HOSTILE;
91 else if ( strcmp( std,
"non-friendly" ) == 0 )
92 standing |= SAFELANES_NEUTRAL | SAFELANES_HOSTILE;
93 else if ( strcmp( std,
"non-hostile" ) == 0 )
94 standing |= SAFELANES_NEUTRAL | SAFELANES_FRIENDLY;
96 return NLUA_ERROR( L, _(
"Unknown standing type '%s'!" ), std );
102 for (
int i = 0; i <
array_size( lanes ); i++ ) {
107 for (
int j = 0; j < 2; j++ ) {
109 case SAFELANE_LOC_SPOB:
113 case SAFELANE_LOC_DEST_SYS:
119 return NLUA_ERROR( L, _(
"Safe-lane vertex type is invalid." ) );
126 for (
int j = 0; j < 2; j++ ) {
128 const JumpPoint *jmp;
130 case SAFELANE_LOC_SPOB:
135 return NLUA_ERROR( L, _(
"Spob is invalid" ) );
139 case SAFELANE_LOC_DEST_SYS:
146 return NLUA_ERROR( L, _(
"Jump is invalid" ) );
151 return NLUA_ERROR( L, _(
"Safe-lane vertex type is invalid." ) );
153 lua_rawseti( L, -2, j + 1 );
155 lua_pushstring( L,
"faction" );
158 lua_rawseti( L, -2, i + 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.
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.
static int safelanesL_get(lua_State *L)
Lua accessor functions to safe lane information.
static const luaL_Reg safelanesL_methods[]
int nlua_loadSafelanes(nlua_env env)
Loads the safelanes Lua library.
StarSystem * luaL_validsystem(lua_State *L, int ind)
Gets system (or system name) at index raising an error if type doesn't match.
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
SafeLane * safelanes_get(int faction, int standing, const StarSystem *system)
Gets a set of safelanes for a faction and system.
StarSystem * system_getIndex(int id)
Get the system by its index.
JumpPoint * jump_getTarget(const StarSystem *target, const StarSystem *sys)
Less safe version of jump_get that works with pointers.
Spob * spob_getIndex(int ind)
Gets spob by index.
Describes a safe lane, patrolled by a faction, within a system.
SafeLaneLocType point_type[2]
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...