15#include "nlua_outfit.h"
18#include "damagetype.h"
19#include "nlua_faction.h"
20#include "nlua_pilot.h"
128 return *( (
const Outfit **)lua_touserdata( L, ind ) );
141 luaL_typerror( L, ind, OUTFIT_METATABLE );
157 else if ( lua_isstring( L, ind ) )
160 luaL_typerror( L, ind, OUTFIT_METATABLE );
165 NLUA_ERROR( L, _(
"Outfit is invalid." ) );
180 luaL_getmetatable( L, OUTFIT_METATABLE );
181 lua_setmetatable( L, -2 );
195 if ( lua_getmetatable( L, ind ) == 0 )
197 lua_getfield( L, LUA_REGISTRYINDEX, OUTFIT_METATABLE );
200 if ( lua_rawequal( L, -1, -2 ) )
223 lua_pushboolean( L, 1 );
225 lua_pushboolean( L, 0 );
264 else if ( lua_isstring( L, 1 ) ) {
265 const char *str = lua_tostring( L, 1 );
268 luaL_typerror( L, 1, OUTFIT_METATABLE );
288 for (
int i = 0; i <
array_size( outfits ); i++ ) {
290 lua_rawseti( L, -2, i + 1 );
311 lua_pushstring( L, _( o->
name ) );
331 lua_pushstring( L, o->
name );
415 lua_pushnumber( L, o->
mass );
434 double heatup = luaL_checknumber( L, 2 );
437 double heat = ( ( 800. - CONST_SPACE_STAR_TEMP ) *
C +
438 STEEL_HEAT_CONDUCTIVITY *
439 ( ( 800. - CONST_SPACE_STAR_TEMP ) * area ) ) /
441 lua_pushnumber( L, heat );
482 lua_pushstring( L, o->
limit );
517 lua_pushnumber( L, o->
price );
557 int noname = lua_toboolean( L, 3 );
566static int getprop( lua_State *L,
int prop )
569 lua_pushboolean( L, outfit_isProp( o, prop ) );
584 return getprop( L, OUTFIT_PROP_UNIQUE );
596 return getprop( L, OUTFIT_PROP_WEAP_FRIENDLYFIRE );
608 return getprop( L, OUTFIT_PROP_WEAP_POINTDEFENSE );
620 return getprop( L, OUTFIT_PROP_WEAP_MISS_SHIPS );
632 return getprop( L, OUTFIT_PROP_WEAP_MISS_ASTEROIDS );
667 const char *str = luaL_optstring( L, 2, NULL );
668 int internal = lua_toboolean( L, 3 );
689 double eps, dps, disable, shots;
690 double mod_energy, mod_damage, mod_shots;
704 if ( o->
type == OUTFIT_TYPE_BEAM ) {
705 mod_energy = p->stats.fwd_energy;
706 mod_damage = p->stats.fwd_damage;
707 mod_shots = 1. / p->stats.fwd_firerate;
709 mod_energy = p->stats.tur_energy;
710 mod_damage = p->stats.tur_damage;
711 mod_shots = 1. / p->stats.tur_firerate;
719 mod_shots = shots / ( shots + mod_shots *
outfit_delay( o ) );
723 return NLUA_ERROR( L, _(
"Outfit has invalid damage type." ) );
724 mod_damage *= 0.5 * ( sdmg + admg );
726 dps = mod_shots * mod_damage * dmg->
damage;
727 disable = mod_shots * mod_damage * dmg->
disable;
731 lua_pushnumber( L, dps );
732 lua_pushnumber( L, disable );
733 lua_pushnumber( L, eps );
740 case OUTFIT_TYPE_BOLT:
741 mod_energy = p->stats.fwd_energy;
742 mod_damage = p->stats.fwd_damage;
743 mod_shots = 1. / p->stats.fwd_firerate;
745 case OUTFIT_TYPE_TURRET_BOLT:
746 mod_energy = p->stats.tur_energy;
747 mod_damage = p->stats.tur_damage;
748 mod_shots = 1. / p->stats.tur_firerate;
750 case OUTFIT_TYPE_LAUNCHER:
751 case OUTFIT_TYPE_TURRET_LAUNCHER:
753 mod_damage = p->stats.launch_damage;
754 mod_shots = 1. / p->stats.launch_rate;
756 case OUTFIT_TYPE_BEAM:
757 case OUTFIT_TYPE_TURRET_BEAM:
776 mod_damage *= 0.5 * ( sdmg + admg );
778 dps = shots * mod_damage * dmg->
damage;
779 disable = shots * mod_damage * dmg->
disable;
783 lua_pushnumber( L, dps );
784 lua_pushnumber( L, disable );
785 lua_pushnumber( L, eps );
792 lua_pushboolean( L, o->
u.
lau.
ai != AMMO_AI_UNGUIDED );
798#define SETFIELD( name, value ) \
799 lua_pushnumber( L, value ); \
800 lua_setfield( L, -2, name )
801#define SETFIELDI( name, value ) \
802 lua_pushinteger( L, value ); \
803 lua_setfield( L, -2, name )
804#define SETFIELDB( name, value ) \
805 lua_pushboolean( L, value ); \
806 lua_setfield( L, -2, name )
818 case OUTFIT_TYPE_AFTERBURNER:
829 case OUTFIT_TYPE_FIGHTER_BAY:
831 lua_setfield( L, -2,
"ship" );
837 case OUTFIT_TYPE_TURRET_BOLT:
838 SETFIELDB(
"isturret", 1 );
840 case OUTFIT_TYPE_BOLT:
857 case OUTFIT_TYPE_TURRET_BEAM:
858 SETFIELDB(
"isturret", 1 );
860 case OUTFIT_TYPE_BEAM:
876 case OUTFIT_TYPE_TURRET_LAUNCHER:
877 SETFIELDB(
"isturret", 1 );
879 case OUTFIT_TYPE_LAUNCHER:
887 SETFIELD(
"arc", o->
u.
lau.
arc );
896 SETFIELDB(
"seek", o->
u.
lau.
ai != AMMO_AI_UNGUIDED );
897 SETFIELDB(
"smart", o->
u.
lau.
ai == AMMO_AI_SMART );
926 lua_rawseti( L, -2, i + 1 );
941 for (
int i = 0; i <
array_size( po ); i++ ) {
942 if ( po[i].o == o ) {
943 lua_pushboolean( L, 1 );
948 for (
int i = 0; i <
array_size( ps ); i++ ) {
949 for (
int j = 0; j <
array_size( ps[i].p->outfits ); j++ ) {
950 if ( ps[i].p->outfits[j]->outfit == o ) {
951 lua_pushboolean( L, 1 );
957 for (
int i = 0; i <
array_size( ss ); i++ ) {
958 const Spob *spb = &ss[i];
959 if ( !spob_hasService( spb, SPOB_SERVICE_SHIPYARD ) )
961 if ( !spob_isKnown( spb ) )
964 lua_pushboolean( L, 1 );
968 lua_pushboolean( L, 0 );
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.
int nlua_helperTags(lua_State *L, int idx, char *const *tags)
Helper function to deal with tags.
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_miss_ships(lua_State *L)
Gets whether or not a weapon outfit misses ships.
static int outfitL_toggleable(lua_State *L)
Gets whether or not an outfit is toggleable.
static int outfitL_type(lua_State *L)
Gets the type of an outfit.
static int outfitL_exists(lua_State *L)
Gets a outfit if it exists, nil otherwise.
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_miss_asteroids(lua_State *L)
Gets whether or not a weapon outfit misses asteroids.
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_friendlyfire(lua_State *L)
Gets whether or not a weapon outfit can do friendly fire.
static int outfitL_shortname(lua_State *L)
Gets the translated short name of the outfit.
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 int outfitL_pointdefense(lua_State *L)
Gets whether or not a weapon outfit is point defense.
static int outfitL_heatFor(lua_State *L)
Calculates a heat value to be used with heat up.
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.
static int outfitL_known(lua_State *L)
Gets whether or not the outfit is known to the player, as in they know a spob that sells it or own it...
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.
const char * outfit_shortname(const Outfit *o)
Gets the short name (translated) of an outfit.
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.
int outfit_isWeapon(const Outfit *o)
Checks to see if an outfit is a weapon.
int outfit_isToggleable(const Outfit *o)
Checks if outfit can be toggled.
const Outfit * outfit_getW(const char *name)
Gets an outfit by name without warning on no-find.
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.
int outfit_gfxStoreLoad(Outfit *o)
Loads the store graphics for the outfit.
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.
double pilot_heatCalcOutfitC(const Outfit *o)
Calculates the thermal mass of an outfit.
double pilot_heatCalcOutfitArea(const Outfit *o)
Calculates the effective transfer area of an outfit.
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 PlayerShip_t * player_getShipStack(void)
Gets the array (array.h) of the player's ships.
const PlayerOutfit_t * player_getOutfits(void)
Gets an array (array.h) of the player's outfits.
int ss_statsMergeFromList(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.
Spob * spob_getAll(void)
Gets an array (array.h) of all spobs.
Core damage that an outfit does.
const struct Ship_ * ship
A ship outfit, depends radically on the type.
union Outfit::@052125200133344144252153256241104103242010347340 u
OutfitAfterburnerData afb
The representation of an in-game pilot.
Represents ship statistics, properties ship can use.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
int tech_hasOutfit(const tech_group_t *tech, const Outfit *outfit)
Checks to see whether a tech group contains a outfit.