15#include "nlua_munition.h"
19#include "nlua_faction.h"
20#include "nlua_outfit.h"
21#include "nlua_pilot.h"
112 luaL_typerror( L, ind, MUNITION_METATABLE );
127 NLUA_ERROR( L, _(
"Munition is invalid." ) );
145 luaL_getmetatable( L, MUNITION_METATABLE );
146 lua_setmetatable( L, -2 );
160 if ( lua_getmetatable( L, ind ) == 0 )
162 lua_getfield( L, LUA_REGISTRYINDEX, MUNITION_METATABLE );
165 if ( lua_rawequal( L, -1, -2 ) )
186 lua_pushboolean( L, lm1->
id == lm2->
id );
220 Weapon *w = munition_get( lm );
222 lua_pushstring( L, _( w->outfit->name ) );
224 lua_pushstring( L,
"(inexistent munition)" );
238 lua_pushboolean( L, munition_get( lm ) != NULL );
265 int onlyhittable = lua_toboolean( L, 1 );
270 if ( weapon_isFlag( w, WEAPON_FLAG_DESTROYED ) )
272 if ( onlyhittable && !weapon_isFlag( w, WEAPON_FLAG_HITTABLE ) )
275 lua_rawseti( L, -2, n++ );
288 if ( p->id == w->parent )
291 if ( ( w->target.type == TARGET_PILOT ) && ( w->target.u.id == p->id ) )
295 if ( p->faction == FACTION_PLAYER ) {
297 if ( parent != NULL ) {
326 double range = luaL_checknumber( L, 2 );
327 const Pilot *p = luaL_optpilot( L, 3, NULL );
328 double r2 =
pow2( range );
336 qt = weapon_collideQuery( x - r, y - r, x + r, y + r );
337 for (
int i = 0; i < il_size( qt ); i++ ) {
339 if ( weapon_isFlag( w, WEAPON_FLAG_DESTROYED ) )
343 if ( vec2_dist2( &w->solid.pos, pos ) > r2 )
346 lua_rawseti( L, -2, n++ );
450 lua_pushnumber( L, w->strength );
466 double sb = w->strength_base;
467 w->strength_base = luaL_checknumber( L, 2 );
468 w->strength *= w->strength_base / sb;
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int areEnemies(int a, int b)
Checks whether two factions are enemies.
Header file with generic functions and naev-specifics.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
int nlua_loadMunition(nlua_env env)
Loads the munition library.
static int munitionL_exists(lua_State *L)
Checks to see if a munition still exists.
static int munitionL_getAll(lua_State *L)
Gets all the munitions in the system.
int lua_ismunition(lua_State *L, int ind)
Checks to see if ind is a munition.
LuaMunition * lua_tomunition(lua_State *L, int ind)
Lua bindings to interact with munitions.
static int munitionL_pos(lua_State *L)
Gets the position of the munition.
static int munitionL_strengthSet(lua_State *L)
Sets the strength of a munition.
LuaMunition * luaL_checkmunition(lua_State *L, int ind)
Gets munition at index or raises error if there is no munition at index.
static int munitionL_target(lua_State *L)
Gets the target of the munition.
static const luaL_Reg munitionL_methods[]
static int weapon_isHostile(const Weapon *w, const Pilot *p)
Sees if a weapon is hostile to a pilot or not.
static int munitionL_getInrange(lua_State *L)
Get munitions in range. Note that this can only get hittable munitions.
static int munitionL_outfit(lua_State *L)
Gets the outfit corresponding to the munition.
static int munitionL_parent(lua_State *L)
Gets the parent of the munition.
static int munitionL_tostring(lua_State *L)
Gets the munition's current (translated) name or notes it is inexistent.
static int munitionL_eq(lua_State *L)
Checks to see if munition and p are the same.
static int munitionL_strength(lua_State *L)
Gets the strength of a munition.
static int munitionL_clear(lua_State *L)
Clears all the munitions in the system.
Weapon * luaL_validmunition(lua_State *L, int ind)
Makes sure the munition is valid or raises a Lua error.
static int munitionL_faction(lua_State *L)
Gets the faction of the munition.
LuaMunition * lua_pushmunition(lua_State *L, const Weapon *w)
Pushes a weapon as a munition on the stack.
static int munitionL_vel(lua_State *L)
Gets the velocity of the munition.
int nlua_loadOutfit(nlua_env env)
Loads the outfit library.
const Outfit ** lua_pushoutfit(lua_State *L, const Outfit *outfit)
Pushes a outfit on the stack.
LuaPilot * lua_pushpilot(lua_State *L, LuaPilot pilot)
Pushes a pilot on the stack.
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.
int pilot_isHostile(const Pilot *p)
Checks to see if pilot is hostile to the player.
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
The representation of an in-game pilot.
In-game representation of a weapon.
Weapon * weapon_getID(unsigned int id)
Gets a weapon by ID.
void weapon_clear(void)
Clears all the weapons, does NOT free the layers.
Weapon * weapon_getStack(void)
Gets the weapon stack. Do not manipulate directly.
static Weapon * weapon_stack