15#include "nlua_pilotoutfit.h"
19#include "nlua_asteroid.h"
20#include "nlua_outfit.h"
21#include "nlua_pilot.h"
22#include "nlua_munition.h"
28int pilotoutfit_modified = 0;
35static int poL_set( lua_State *L );
63 nlua_register(env, PILOTOUTFIT_METATABLE,
poL_methods, 1);
94 luaL_typerror(L, ind, PILOTOUTFIT_METATABLE);
111 luaL_typerror(L, ind, PILOTOUTFIT_METATABLE);
116 NLUA_ERROR(L, _(
"Pilot Outfit is invalid."));
131 luaL_getmetatable(L, PILOTOUTFIT_METATABLE);
132 lua_setmetatable(L, -2);
146 if (lua_getmetatable(L,ind)==0)
148 lua_getfield(L, LUA_REGISTRYINDEX, PILOTOUTFIT_METATABLE);
151 if (lua_rawequal(L, -1, -2))
175 lua_pushstring(L,
"type");
179 lua_pushstring(L,
"size");
183 lua_pushstring(L,
"property");
187 lua_pushstring(L,
"required");
188 lua_pushboolean( L, sslot->
required);
191 lua_pushstring(L,
"exclusive");
195 lua_pushstring(L,
"locked");
196 lua_pushboolean( L, sslot->
locked);
226 const char *state = luaL_optstring(L,2,NULL);
227 PilotOutfitState pos = po->
state;
230 return NLUA_ERROR( L, _(
"'pilotoutfit.%s' only works with modifier outfits!"),
"state");
232 if (state==NULL || strcmp(state,
"off")==0)
233 po->
state = PILOT_OUTFIT_OFF;
234 else if (strcmp(state,
"warmup")==0)
235 po->
state = PILOT_OUTFIT_WARMUP;
236 else if (strcmp(state,
"on")==0)
237 po->
state = PILOT_OUTFIT_ON;
238 else if (strcmp(state,
"cooldown")==0)
239 po->
state = PILOT_OUTFIT_COOLDOWN;
241 return NLUA_ERROR( L, _(
"Unknown PilotOutfit state '%s'!"), state );
244 if (pos != po->
state)
245 pilotoutfit_modified = 1;
262 return NLUA_ERROR( L, _(
"'pilotoutfit.%s' only works with modifier outfits!"),
"progress");
279 const char *name = luaL_checkstring(L,2);
280 double value = luaL_checknumber(L,3);
282 pilotoutfit_modified = 1;
297 pilotoutfit_modified = 1;
301static Target lua_totarget( lua_State *L,
int idx )
305 if (lua_isnoneornil(L,idx))
306 t.type = TARGET_NONE;
308 t.type = TARGET_PILOT;
313 t.type = TARGET_ASTEROID;
314 t.u.ast.anchor = ast->parent;
315 t.u.ast.asteroid = ast->id;
319 t.type = TARGET_WEAPON;
323 NLUA_INVALID_PARAMETER_NORET(L,idx);
324 t.type = TARGET_NONE;
348 Target t = lua_totarget( L, 4 );
349 double dir = luaL_optnumber( L, 5, p->solid.dir );
350 const vec2 *vp = luaL_optvector( L, 6, &p->solid.pos );
351 const vec2 *vv = luaL_optvector( L, 7, &p->solid.vel );
352 int noaim = lua_toboolean( L, 8 );
372 Target t = lua_totarget( L, 3 );
373 int stagger = lua_toboolean( L, 4 );
379 if (po->
timer > 0.) {
380 lua_pushboolean(L,0);
387 lua_pushboolean(L,0);
393 double q, maxt, rate_mod, energy_mod;
404 for (
int i=0; i<
array_size(p->outfits); i++) {
412 if (pos->
timer <= 0.) {
414 if ((minh < 0) || (p->outfits[ minh ]->u.ammo.quantity < pos->u.
ammo.
quantity))
418 if ((minh < 0) || (p->outfits[ minh ]->heat_T > pos->
heat_T))
424 if ((maxp < 0) || (pos->
timer > maxt)) {
433 lua_pushboolean(L,0);
441 lua_pushboolean( L, ret );
456 if (lua_isboolean(L,2))
457 lua_pushnumber( L, po->
heat_T );
479 double heat = luaL_checknumber( L, 2 );
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Header file with generic functions and naev-specifics.
int lua_isasteroid(lua_State *L, int ind)
Checks to see if ind is a asteroid.
LuaAsteroid_t * lua_toasteroid(lua_State *L, int ind)
Gets asteroid at index.
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.
LuaMunition * lua_pushmunition(lua_State *L, const Weapon *w)
Pushes a weapon as a munition on the stack.
const Outfit ** lua_pushoutfit(lua_State *L, const Outfit *outfit)
Pushes a outfit on the stack.
LuaPilot lua_topilot(lua_State *L, int ind)
Lua bindings to interact with pilots.
Pilot * luaL_validpilot(lua_State *L, int ind)
Makes sure the pilot is valid or raises a Lua error.
int lua_ispilot(lua_State *L, int ind)
Checks to see if ind is a pilot.
static const luaL_Reg poL_methods[]
int nlua_loadPilotOutfit(nlua_env env)
Loads the pilot outfit library.
PilotOutfitSlot * luaL_validpilotoutfit(lua_State *L, int ind)
Makes sure the outfit is valid or raises a Lua error.
static int poL_progress(lua_State *L)
Sets the state progress of the PilotOutfit.
static int poL_heat(lua_State *L)
Gets the heat status of the pilot outfit.
PilotOutfitSlot * luaL_checkpilotoutfit(lua_State *L, int ind)
Gets outfit at index or raises error if there is no outfit at index.
static int poL_munition(lua_State *L)
Creates a munition.
PilotOutfitSlot ** lua_pushpilotoutfit(lua_State *L, PilotOutfitSlot *po)
Pushes a pilot outfit on the stack.
static int poL_set(lua_State *L)
Sets a temporary ship stat modifier of the pilot outfit.
static int poL_outfit(lua_State *L)
Gets the outfit of the PilotOutfit.
PilotOutfitSlot * lua_topilotoutfit(lua_State *L, int ind)
Lua bindings to interact with pilot outfits.
static int poL_heatup(lua_State *L)
Heats up a pilot outfit.
int lua_ispilotoutfit(lua_State *L, int ind)
Checks to see if ind is a pilot outfit.
static int poL_shoot(lua_State *L)
Shoots at an object.
static int poL_state(lua_State *L)
Sets the state of the PilotOutfit.
static int poL_clear(lua_State *L)
Clears all the temporary ship stat modifiers of the pilot outfit.
static int poL_slot(lua_State *L)
Gets the properties of the outfit slot.
int outfit_isLauncher(const Outfit *o)
Checks if outfit is a weapon launcher.
int outfit_isFighterBay(const Outfit *o)
Checks if outfit is a fighter bay.
const char * slotName(const OutfitSlotType type)
int outfit_isMod(const Outfit *o)
Checks if outfit is a ship modification.
const char * slotSize(const OutfitSlotSize o)
Gets the slot size as a string.
double outfit_delay(const Outfit *o)
Gets the outfit's delay.
double pilot_heatEfficiencyMod(double T, double Tb, double Tc)
Returns a 0:1 modifier representing efficiency (1. being normal).
void pilot_getRateMod(double *rate_mod, double *energy_mod, const Pilot *p, const Outfit *o)
Gets applicable fire rate and energy modifications for a pilot's weapon.
int pilot_shootWeapon(Pilot *p, PilotOutfitSlot *w, const Target *target, double time, int aim)
Actually handles the shooting, how often the player.p can shoot and such.
void ss_free(ShipStatList *ll)
Frees a list of ship stats.
ShipStatsType ss_typeFromName(const char *name)
Gets the type from the name.
const char * sp_display(unsigned int spid)
Gets the display name of a slot property (in English).
Pilot slot that can contain outfits.
A ship outfit, depends radically on the type.
Stores an outfit the pilot has.
The representation of an in-game pilot.
Represents a weapon target.
In-game representation of a weapon.
double weapon_targetFlyTime(const Outfit *o, const Pilot *p, const Target *t)
Gets the fly time for a weapon target.
Weapon * weapon_add(PilotOutfitSlot *po, const Outfit *ref, double dir, const vec2 *pos, const vec2 *vel, const Pilot *parent, const Target *target, double time, int aim)
Creates a new weapon.