15#include "nlua_pilotoutfit.h"
18#include "nlua_asteroid.h"
19#include "nlua_munition.h"
20#include "nlua_outfit.h"
21#include "nlua_pilot.h"
27int pilotoutfit_modified = 0;
34static int poL_set( lua_State *L );
62 nlua_register( env, PILOTOUTFIT_METATABLE,
poL_methods, 1 );
93 luaL_typerror( L, ind, PILOTOUTFIT_METATABLE );
110 luaL_typerror( L, ind, PILOTOUTFIT_METATABLE );
115 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 ) )
176 lua_pushstring( L,
"type" );
180 lua_pushstring( L,
"size" );
184 lua_pushstring( L,
"property" );
188 lua_pushstring( L,
"required" );
189 lua_pushboolean( L, sslot->
required );
192 lua_pushstring( L,
"exclusive" );
196 lua_pushstring( L,
"locked" );
197 lua_pushboolean( L, sslot->
locked );
235 const char *state = luaL_optstring( L, 2, NULL );
236 PilotOutfitState pos = po->
state;
240 if ( state == NULL || strcmp( state,
"off" ) == 0 ) {
241 po->
flags &= ~( PILOTOUTFIT_DYNAMIC_FLAGS |
243 }
else if ( strcmp( state,
"on" ) == 0 ) {
244 po->
state = PILOT_OUTFIT_ON;
247 PILOTOUTFIT_ISON_TOGGLE;
249 return NLUA_ERROR( L,
250 _(
"'pilotoutfit.%s' only works with \"on\" and "
251 "\"off\" for weapon outfits!" ),
256 _(
"'pilotoutfit.%s' only works with modifier or weapon outfits!" ),
260 if ( state == NULL || strcmp( state,
"off" ) == 0 ) {
261 po->
state = PILOT_OUTFIT_OFF;
263 ~( PILOTOUTFIT_DYNAMIC_FLAGS | PILOTOUTFIT_ISON );
264 }
else if ( strcmp( state,
"warmup" ) == 0 ) {
265 po->
state = PILOT_OUTFIT_WARMUP;
266 }
else if ( strcmp( state,
"on" ) == 0 ) {
267 if ( po->
state != PILOT_OUTFIT_ON )
268 po->
flags |= PILOTOUTFIT_ISON | PILOTOUTFIT_ISON_TOGGLE;
269 po->
state = PILOT_OUTFIT_ON;
270 }
else if ( strcmp( state,
"cooldown" ) == 0 ) {
271 po->
state = PILOT_OUTFIT_COOLDOWN;
273 ~( PILOTOUTFIT_DYNAMIC_FLAGS | PILOTOUTFIT_ISON );
275 return NLUA_ERROR( L, _(
"Unknown PilotOutfit state '%s'!" ), state );
278 if ( pos != po->
state )
279 pilotoutfit_modified = 1;
298 L, _(
"'pilotoutfit.%s' only works with modifier outfits!" ),
318 const char *name = luaL_checkstring( L, 2 );
319 double value = luaL_checknumber( L, 3 );
322 pilotoutfit_modified = 1;
337 pilotoutfit_modified = 1;
341static Target lua_totarget( lua_State *L,
int idx )
345 if ( lua_isnoneornil( L, idx ) )
346 t.type = TARGET_NONE;
348 t.type = TARGET_PILOT;
352 t.type = TARGET_ASTEROID;
353 t.u.ast.anchor = ast->parent;
354 t.u.ast.asteroid = ast->id;
357 t.type = TARGET_WEAPON;
360 NLUA_INVALID_PARAMETER_NORET( L, idx );
361 t.type = TARGET_NONE;
390 Target t = lua_totarget( L, 4 );
391 double dir = luaL_optnumber( L, 5, p->solid.dir );
392 const vec2 *vp = luaL_optvector( L, 6, &p->solid.pos );
393 const vec2 *vv = luaL_optvector( L, 7, &p->solid.vel );
394 int noaim = lua_toboolean( L, 8 );
416 Target t = lua_totarget( L, 3 );
417 int stagger = lua_toboolean( L, 4 );
423 if ( po->
timer > 0. ) {
424 lua_pushboolean( L, 0 );
432 lua_pushboolean( L, 0 );
438 double q, maxt, rate_mod, energy_mod;
449 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
457 if ( pos->
timer <= 0. ) {
459 if ( ( minh < 0 ) || ( p->outfits[minh]->u.ammo.quantity <
463 if ( ( minh < 0 ) || ( p->outfits[minh]->heat_T > pos->
heat_T ) )
469 if ( ( maxp < 0 ) || ( pos->
timer > maxt ) ) {
478 ( ( q - 1. ) / q ) ) ) {
479 lua_pushboolean( L, 0 );
487 lua_pushboolean( L, ret );
504 if ( lua_isboolean( L, 2 ) )
505 lua_pushnumber( L, po->
heat_T );
529 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_isWeapon(const Outfit *o)
Checks to see if an outfit is a weapon.
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.