15#include "nlua_munition.h"
20#include "nlua_faction.h"
21#include "nlua_outfit.h"
23#include "nlua_pilot.h"
110 luaL_typerror(L, ind, MUNITION_METATABLE);
124 NLUA_ERROR(L,_(
"Munition is invalid."));
142 luaL_getmetatable(L, MUNITION_METATABLE);
143 lua_setmetatable(L, -2);
157 if (lua_getmetatable(L,ind)==0)
159 lua_getfield(L, LUA_REGISTRYINDEX, MUNITION_METATABLE);
162 if (lua_rawequal(L, -1, -2))
183 lua_pushboolean(L, lm1->
id==lm2->
id);
214 Weapon *w = munition_get(lm);
216 lua_pushstring(L,_(w->outfit->name));
218 lua_pushstring(L,
"(inexistent munition)");
232 lua_pushboolean(L, munition_get(lm)!=NULL);
258 int onlyhittable = lua_toboolean(L,1);
263 if (weapon_isFlag(w,WEAPON_FLAG_DESTROYED))
265 if (onlyhittable && !weapon_isFlag(w,WEAPON_FLAG_HITTABLE))
268 lua_rawseti( L, -2, n++ );
273static int weapon_isHostile(
const Weapon *w,
const Pilot *p )
275 if (p->id == w->parent)
278 if ((w->target.type==TARGET_PILOT) && (w->target.u.id==p->id))
282 if (p->faction == FACTION_PLAYER) {
284 if (parent != NULL) {
312 double range = luaL_checknumber(L,2);
313 const Pilot *p = luaL_optpilot(L,3,NULL);
314 double r2 =
pow2(range);
322 qt = weapon_collideQuery( x-r, y-r, x+r, y+r );
323 for (
int i=0; i<il_size(qt); i++) {
325 if (weapon_isFlag(w,WEAPON_FLAG_DESTROYED))
327 if ((p!=NULL) && !weapon_isHostile(w,p))
329 if (vec2_dist2( &w->solid.pos, pos ) > r2 )
332 lua_rawseti( L, -2, n++ );
434 lua_pushnumber( L, w->strength );
449 double sb = w->strength_base;
450 w->strength_base = luaL_checknumber( L, 2 );
451 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 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