15#include "nlua_outfit.h"
19#include "damagetype.h"
20#include "nlua_faction.h"
21#include "nlua_pilot.h"
126 return *((
const Outfit**) lua_touserdata(L,ind));
139 luaL_typerror(L, ind, OUTFIT_METATABLE);
155 else if (lua_isstring(L, ind))
158 luaL_typerror(L, ind, OUTFIT_METATABLE);
163 NLUA_ERROR(L, _(
"Outfit is invalid."));
178 luaL_getmetatable(L, OUTFIT_METATABLE);
179 lua_setmetatable(L, -2);
193 if (lua_getmetatable(L,ind)==0)
195 lua_getfield(L, LUA_REGISTRYINDEX, OUTFIT_METATABLE);
198 if (lua_rawequal(L, -1, -2))
221 lua_pushboolean(L,1);
223 lua_pushboolean(L,0);
255 lua_rawseti( L, -2, i+1 );
276 lua_pushstring(L, _(o->
name));
296 lua_pushstring(L, o->
name);
380 lua_pushnumber(L, o->
mass);
396 double heatup = luaL_checknumber( L, 2 );
399 double heat = ((800.-CONST_SPACE_STAR_TEMP)*
C +
400 STEEL_HEAT_CONDUCTIVITY * ((800.-CONST_SPACE_STAR_TEMP) * area)) /
402 lua_pushnumber( L, heat );
441 lua_pushstring(L,o->
limit);
475 lua_pushnumber(L, o->
price);
513 int noname = lua_toboolean(L,3);
521static int getprop( lua_State *L,
int prop )
524 lua_pushboolean(L, outfit_isProp(o, prop));
539 return getprop( L, OUTFIT_PROP_UNIQUE );
551 return getprop( L, OUTFIT_PROP_WEAP_FRIENDLYFIRE );
563 return getprop( L, OUTFIT_PROP_WEAP_POINTDEFENSE );
575 return getprop( L, OUTFIT_PROP_WEAP_MISS_SHIPS );
587 return getprop( L, OUTFIT_PROP_WEAP_MISS_ASTEROIDS );
619 const char *str = luaL_optstring(L,2,NULL);
620 int internal = lua_toboolean(L,3);
641 double eps, dps, disable, shots;
642 double mod_energy, mod_damage, mod_shots;
649 if (o->
slot.
type != OUTFIT_SLOT_WEAPON)
656 if (o->
type == OUTFIT_TYPE_BEAM) {
657 mod_energy = p->stats.fwd_energy;
658 mod_damage = p->stats.fwd_damage;
659 mod_shots = 1. / p->stats.fwd_firerate;
662 mod_energy = p->stats.tur_energy;
663 mod_damage = p->stats.tur_damage;
664 mod_shots = 1. / p->stats.tur_firerate;
673 mod_shots = shots / (shots + mod_shots *
outfit_delay(o));
677 return NLUA_ERROR(L, _(
"Outfit has invalid damage type."));
678 mod_damage *= 0.5*(sdmg+admg);
680 dps = mod_shots * mod_damage * dmg->
damage;
681 disable = mod_shots * mod_damage * dmg->
disable;
683 lua_pushnumber( L, dps );
684 lua_pushnumber( L, disable );
685 lua_pushnumber( L, eps );
692 case OUTFIT_TYPE_BOLT:
693 mod_energy = p->stats.fwd_energy;
694 mod_damage = p->stats.fwd_damage;
695 mod_shots = 1. / p->stats.fwd_firerate;
697 case OUTFIT_TYPE_TURRET_BOLT:
698 mod_energy = p->stats.tur_energy;
699 mod_damage = p->stats.tur_damage;
700 mod_shots = 1. / p->stats.tur_firerate;
702 case OUTFIT_TYPE_LAUNCHER:
703 case OUTFIT_TYPE_TURRET_LAUNCHER:
705 mod_damage = p->stats.launch_damage;
706 mod_shots = 1. / p->stats.launch_rate;
708 case OUTFIT_TYPE_BEAM:
709 case OUTFIT_TYPE_TURRET_BEAM:
727 mod_damage *= 0.5*(sdmg+admg);
729 dps = shots * mod_damage * dmg->
damage;
730 disable = shots * mod_damage * dmg->
disable;
733 lua_pushnumber( L, dps );
734 lua_pushnumber( L, disable );
735 lua_pushnumber( L, eps );
742 lua_pushboolean( L, o->
u.
lau.
ai!=AMMO_AI_UNGUIDED );
748#define SETFIELD( name, value ) \
749 lua_pushnumber( L, value ); \
750 lua_setfield( L, -2, name )
751#define SETFIELDI( name, value ) \
752 lua_pushinteger( L, value ); \
753 lua_setfield( L, -2, name )
754#define SETFIELDB( name, value ) \
755 lua_pushboolean( L, value ); \
756 lua_setfield( L, -2, name )
768 case OUTFIT_TYPE_AFTERBURNER:
779 case OUTFIT_TYPE_FIGHTER_BAY:
781 lua_setfield( L, -2,
"ship" );
787 case OUTFIT_TYPE_TURRET_BOLT:
788 SETFIELDB(
"isturret", 1 );
790 case OUTFIT_TYPE_BOLT:
807 case OUTFIT_TYPE_TURRET_BEAM:
808 SETFIELDB(
"isturret", 1 );
810 case OUTFIT_TYPE_BEAM:
826 case OUTFIT_TYPE_TURRET_LAUNCHER:
827 SETFIELDB(
"isturret", 1 );
829 case OUTFIT_TYPE_LAUNCHER:
837 SETFIELD(
"arc", o->
u.
lau.
arc );
846 SETFIELDB(
"seek", o->
u.
lau.
ai!=AMMO_AI_UNGUIDED );
847 SETFIELDB(
"smart", o->
u.
lau.
ai==AMMO_AI_SMART );
876 lua_rawseti( L, -2, i+1 );
895 lua_pushstring(L,o->
tags[i]);
896 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_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_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.
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.
int outfit_isToggleable(const Outfit *o)
Checks if outfit can be toggled.
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.
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.
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.
Core damage that an outfit does.
const struct Ship_ * ship
A ship outfit, depends radically on the type.
OutfitAfterburnerData afb
The representation of an in-game pilot.
Represents ship statistics, properties ship can use.