15#include "nlua_outfit.h"
19#include "damagetype.h"
20#include "nlua_faction.h"
21#include "nlua_pilot.h"
112 return *((
const Outfit**) lua_touserdata(L,ind));
125 luaL_typerror(L, ind, OUTFIT_METATABLE);
141 else if (lua_isstring(L, ind))
144 luaL_typerror(L, ind, OUTFIT_METATABLE);
149 NLUA_ERROR(L, _(
"Outfit is invalid."));
164 luaL_getmetatable(L, OUTFIT_METATABLE);
165 lua_setmetatable(L, -2);
179 if (lua_getmetatable(L,ind)==0)
181 lua_getfield(L, LUA_REGISTRYINDEX, OUTFIT_METATABLE);
184 if (lua_rawequal(L, -1, -2))
207 lua_pushboolean(L,1);
209 lua_pushboolean(L,0);
241 lua_rawseti( L, -2, i+1 );
262 lua_pushstring(L, _(o->
name));
282 lua_pushstring(L, o->
name);
348 lua_pushnumber(L, o->
mass);
387 lua_pushstring(L,o->
limit);
421 lua_pushnumber(L, o->
price);
459 int noname = lua_toboolean(L,3);
479 lua_pushboolean(L, outfit_isProp(o, OUTFIT_PROP_UNIQUE));
498 const char *str = luaL_optstring(L,2,NULL);
499 int internal = lua_toboolean(L,3);
520 double eps, dps, disable, shots;
521 double mod_energy, mod_damage, mod_shots;
528 if (o->
slot.
type != OUTFIT_SLOT_WEAPON)
535 if (o->
type == OUTFIT_TYPE_BEAM) {
536 mod_energy = p->stats.fwd_energy;
537 mod_damage = p->stats.fwd_damage;
538 mod_shots = 1. / p->stats.fwd_firerate;
541 mod_energy = p->stats.tur_energy;
542 mod_damage = p->stats.tur_damage;
543 mod_shots = 1. / p->stats.tur_firerate;
552 mod_shots = shots / (shots + mod_shots *
outfit_delay(o));
556 NLUA_ERROR(L, _(
"Outfit has invalid damage type."));
557 mod_damage *= 0.5*(sdmg+admg);
559 dps = mod_shots * mod_damage * dmg->
damage;
560 disable = mod_shots * mod_damage * dmg->
disable;
562 lua_pushnumber( L, dps );
563 lua_pushnumber( L, disable );
564 lua_pushnumber( L, eps );
571 case OUTFIT_TYPE_BOLT:
572 mod_energy = p->stats.fwd_energy;
573 mod_damage = p->stats.fwd_damage;
574 mod_shots = 1. / p->stats.fwd_firerate;
576 case OUTFIT_TYPE_TURRET_BOLT:
577 mod_energy = p->stats.tur_energy;
578 mod_damage = p->stats.tur_damage;
579 mod_shots = 1. / p->stats.tur_firerate;
581 case OUTFIT_TYPE_LAUNCHER:
582 case OUTFIT_TYPE_TURRET_LAUNCHER:
584 mod_damage = p->stats.launch_damage;
585 mod_shots = 1. / p->stats.launch_rate;
587 case OUTFIT_TYPE_BEAM:
588 case OUTFIT_TYPE_TURRET_BEAM:
606 mod_damage *= 0.5*(sdmg+admg);
608 dps = shots * mod_damage * dmg->
damage;
609 disable = shots * mod_damage * dmg->
disable;
612 lua_pushnumber( L, dps );
613 lua_pushnumber( L, disable );
614 lua_pushnumber( L, eps );
621 lua_pushboolean( L, o->
u.
lau.
ai!=AMMO_AI_UNGUIDED );
627#define SETFIELD( name, value ) \
628 lua_pushnumber( L, value ); \
629 lua_setfield( L, -2, name )
630#define SETFIELDI( name, value ) \
631 lua_pushinteger( L, value ); \
632 lua_setfield( L, -2, name )
633#define SETFIELDB( name, value ) \
634 lua_pushboolean( L, value ); \
635 lua_setfield( L, -2, name )
647 case OUTFIT_TYPE_AFTERBURNER:
658 case OUTFIT_TYPE_FIGHTER_BAY:
660 lua_setfield( L, -2,
"ship" );
666 case OUTFIT_TYPE_TURRET_BOLT:
667 SETFIELDB(
"isturret", 1 );
669 case OUTFIT_TYPE_BOLT:
686 case OUTFIT_TYPE_TURRET_BEAM:
687 SETFIELDB(
"isturret", 1 );
689 case OUTFIT_TYPE_BEAM:
705 case OUTFIT_TYPE_TURRET_LAUNCHER:
706 SETFIELDB(
"isturret", 1 );
708 case OUTFIT_TYPE_LAUNCHER:
716 SETFIELD(
"arc", o->
u.
lau.
arc );
725 SETFIELDB(
"seek", o->
u.
lau.
ai!=AMMO_AI_UNGUIDED );
726 SETFIELDB(
"smart", o->
u.
lau.
ai==AMMO_AI_SMART );
755 lua_rawseti( L, -2, i+1 );
774 lua_pushstring(L,o->
tags[i]);
775 lua_pushboolean(L,1);
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int dtype_raw(int type, double *shield, double *armour, double *knockback)
Gets the raw modulation stats of a damage type.
Header file with generic functions and naev-specifics.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
static int outfitL_limit(lua_State *L)
Gets the limit string of the outfit. Only one outfit can be equipped at the same time for each limit ...
static int outfitL_mass(lua_State *L)
Gets the mass of an outfit.
static int outfitL_illegality(lua_State *L)
Gets the factions to which the outfit is illegal to.
const Outfit * luaL_validoutfit(lua_State *L, int ind)
Makes sure the outfit is valid or raises a Lua error.
static int outfitL_cpu(lua_State *L)
Gets the cpu usage of an outfit.
static int outfitL_slot(lua_State *L)
Gets the slot name, size and property of an outfit.
int nlua_loadOutfit(nlua_env env)
Loads the outfit library.
static int outfitL_tags(lua_State *L)
Gets the outfit tags.
static int outfitL_typeBroad(lua_State *L)
Gets the broad type of an outfit.
static int outfitL_specificStats(lua_State *L)
Returns raw data specific to each outfit type.
static int outfitL_summary(lua_State *L)
Gets the summary of an outfit (translated).
static int outfitL_type(lua_State *L)
Gets the type of an outfit.
static int outfitL_icon(lua_State *L)
Gets the store icon for an outfit.
static int outfitL_getShipStat(lua_State *L)
Gets a shipstat from an Outfit by name, or a table containing all the ship stats if not specified.
static int outfitL_getAll(lua_State *L)
Gets all the outfits.
static int outfitL_nameRaw(lua_State *L)
Gets the raw (untranslated) name of the outfit.
static int outfitL_get(lua_State *L)
Gets a outfit.
static int outfitL_description(lua_State *L)
Gets the description of an outfit (translated).
static int outfitL_name(lua_State *L)
Gets the translated name of the outfit.
const Outfit * luaL_checkoutfit(lua_State *L, int ind)
Gets outfit at index or raises error if there is no outfit at index.
static int outfitL_weapStats(lua_State *L)
Computes statistics for weapons.
static int outfitL_price(lua_State *L)
Gets the price of an outfit.
static const luaL_Reg outfitL_methods[]
const Outfit ** lua_pushoutfit(lua_State *L, const Outfit *outfit)
Pushes a outfit on the stack.
static int outfitL_eq(lua_State *L)
Checks to see if two outfits are the same.
int lua_isoutfit(lua_State *L, int ind)
Checks to see if ind is a outfit.
static int outfitL_unique(lua_State *L)
Gets whether or not an outfit is unique.
const Outfit * lua_tooutfit(lua_State *L, int ind)
Lua bindings to interact with outfits.
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.
const Ship ** lua_pushship(lua_State *L, const Ship *ship)
Pushes a ship on the stack.
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
double outfit_trackmin(const Outfit *o)
Gets the outfit's minimal tracking.
int outfit_isBeam(const Outfit *o)
Checks if outfit is a beam type weapon.
const Outfit * outfit_getAll(void)
Gets the array (array.h) of all outfits.
double outfit_cpu(const Outfit *o)
Gets the outfit's cpu usage.
const Outfit * outfit_get(const char *name)
Gets an outfit by name.
int outfit_isLauncher(const Outfit *o)
Checks if outfit is a weapon launcher.
const char * outfit_getTypeBroad(const Outfit *o)
Gets the outfit's broad type.
double outfit_range(const Outfit *o)
Gets the outfit's range.
const char * outfit_getType(const Outfit *o)
Gets the outfit's specific type.
double outfit_trackmax(const Outfit *o)
Gets the outfit's minimal tracking.
const Damage * outfit_damage(const Outfit *o)
Gets the outfit's damage.
double outfit_duration(const Outfit *o)
Gets the outfit's duration.
const char * outfit_slotName(const Outfit *o)
Gets the name of the slot type of an outfit.
const char * outfit_slotSize(const Outfit *o)
Gets the name of the slot size of an outfit.
double outfit_energy(const Outfit *o)
Gets the outfit's energy usage.
double outfit_delay(const Outfit *o)
Gets the outfit's delay.
const char * pilot_outfitDescription(const Pilot *p, const Outfit *o)
Gets the description of an outfit for a given pilot.
const char * pilot_outfitSummary(const Pilot *p, const Outfit *o, int withname)
Gets the summary of an outfit for a give pilot.
const Ship * ship_get(const char *name)
Gets a ship based on its name.
int ss_statsModFromList(ShipStats *stats, const ShipStatList *list)
Updates a stat structure from a stat list.
int ss_statsGetLua(lua_State *L, const ShipStats *s, const char *name, int internal)
Gets a ship stat value by name and pushes it to Lua.
int ss_statsInit(ShipStats *stats)
Initializes a stat structure.
const char * sp_display(unsigned int spid)
Gets the display name of a slot property (in English).
int sp_required(unsigned int spid)
Gets whether or not a slot property is required.
int sp_exclusive(unsigned int spid)
Gets whether or not a slot property is exclusive.
Core damage that an outfit does.
A ship outfit, depends radically on the type.
OutfitAfterburnerData afb
The representation of an in-game pilot.
Represents ship statistics, properties ship can use.