15#include "nlua_pilot.h"
20#include "damagetype.h"
23#include "land_outfits.h"
26#include "nlua_asteroid.h"
27#include "nlua_canvas.h"
28#include "nlua_colour.h"
29#include "nlua_commodity.h"
30#include "nlua_faction.h"
32#include "nlua_outfit.h"
33#include "nlua_pilotoutfit.h"
36#include "nlua_system.h"
41#include "pilot_heat.h"
43#include "player_autonav.h"
56static int pilotL_getFriendOrFoe( lua_State *L,
int friend );
61 int bypass_cpu,
int bypass_slot );
62static int luaL_checkweapset( lua_State *L,
int idx );
156static int pilotL_disable( lua_State *L );
379 {
"disable", pilotL_disable },
501 if ( lua_isnone( L, 2 ) )
504 state = lua_toboolean( L, 2 );
508 pilot_setFlag( p, flag );
510 pilot_rmFlag( p, flag );
537 return *( (LuaPilot *)lua_touserdata( L, ind ) );
550 luaL_typerror( L, ind, PILOT_METATABLE );
564 NLUA_ERROR( L, _(
"Pilot is invalid." ) );
578 LuaPilot *p = (LuaPilot *)lua_newuserdata( L,
sizeof( LuaPilot ) );
580 luaL_getmetatable( L, PILOT_METATABLE );
581 lua_setmetatable( L, -2 );
595 if ( lua_getmetatable( L, ind ) == 0 )
597 lua_getfield( L, LUA_REGISTRYINDEX, PILOT_METATABLE );
600 if ( lua_rawequal( L, -1, -2 ) )
621 int ignore_rules, guerilla;
623 JumpPoint *jump = NULL;
628 ignore_rules = lua_toboolean( L, 2 );
629 guerilla = lua_toboolean( L, 3 );
635 else if ( jump != NULL )
686 const char *pilotname, *ai;
698 pilot_clearFlagsRaw( flags );
710 pilotname = luaL_optstring( L, 4, _( ship->
name ) );
715 a = RNGF() * 2. * M_PI;
723 pilot_setFlagRaw( flags, PILOT_TAKEOFF );
724 a = RNGF() * 2. * M_PI;
725 r = RNGF() * spob->
radius;
726 vec2_cset( &vp, spob->
pos.
x + r * cos( a ), spob->
pos.
y + r * sin( a ) );
727 a = RNGF() * 2. * M_PI;
731 else if ( lua_isnoneornil( L, 3 ) ) {
734 if ( lua_isboolean( L, 3 ) && lua_toboolean( L, 3 ) )
740 if ( spob != NULL ) {
741 pilot_setFlagRaw( flags, PILOT_TAKEOFF );
742 a = RNGF() * 2. * M_PI;
743 r = RNGF() * spob->
radius;
744 vec2_cset( &vp, spob->
pos.
x + r * cos( a ),
745 spob->
pos.
y + r * sin( a ) );
747 a = RNGF() * 2. * M_PI;
750 NLUA_INVALID_PARAMETER( L, 3 );
756 !jp_isFlag(
cur_system->jumps[i].returnJump, JP_EXITONLY ) ) {
761 if ( jump == NULL ) {
765 _(
"Ship '%s' jumping in from non-adjacent system '%s' to "
775 _(
"Ship '%s' attempting to jump in from '%s', but '%s' has "
783 if ( lua_gettop( L ) >= 5 && !lua_isnil( L, 5 ) ) {
784 if ( !lua_istable( L, 5 ) )
786 L, _(
"'parameters' should be a table of options or omitted!" ) );
787 lua_getfield( L, 5,
"ai" );
788 ai = luaL_optstring( L, -1, NULL );
791 lua_getfield( L, 5,
"naked" );
792 if ( lua_toboolean( L, -1 ) )
793 pilot_setFlagRaw( flags, PILOT_NO_OUTFITS );
796 lua_getfield( L, 5,
"stealth" );
797 if ( lua_toboolean( L, -1 ) )
798 pilot_setFlagRaw( flags, PILOT_STEALTH );
803 if ( jump != NULL ) {
805 pilot_setFlagRaw( flags, PILOT_HYP_END );
809 a = angle_clean( a );
812 p =
pilot_create( ship, pilotname, lf, ai, a, &vp, &vv, flags, 0, 0 );
814 if ( jump == NULL ) {
816 p->timer[0] = p->tcontrol;
820 if ( ( jump != NULL ) && pilot_isFlagRaw( flags, PILOT_STEALTH ) ) {
859 if ( pilot_isPlayer( p ) )
886 pilot_setFlag( p, PILOT_EXPLODED );
888 if ( !pilot_isFlag( p, PILOT_EXPLODED ) ) {
889 lua_pushboolean( L, 0 );
894 if ( pilot_isPlayer( p ) )
900 lua_pushboolean( L, 1 );
908 if ( pilot_isFlag( pi, PILOT_DELETE ) || pilot_isFlag( pi, PILOT_DEAD ) ||
909 pilot_isFlag( pi, PILOT_HIDE ) )
929 if ( lua_istable( L, 1 ) ) {
931 while ( lua_next( L, 1 ) != 0 ) {
973static void toggleSpawn(
int f,
int b )
1003 int b = !lua_toboolean( L, 2 );
1006 if ( !lua_isnoneornil( L, 1 ) ) {
1007 if ( lua_istable( L, 1 ) ) {
1009 while ( lua_next( L, 1 ) != 0 ) {
1016 else if ( lua_isboolean( L, 1 ) )
1019 NLUA_INVALID_PARAMETER( L, 1 );
1047 int d = lua_toboolean( L, 2 );
1061 while ( lua_next( L, 1 ) != 0 ) {
1073 for (
int j = 0; j <
array_size( factions ); j++ ) {
1074 if ( (
pilot_stack[i]->faction == factions[j] ) &&
1078 lua_rawseti( L, -2, k++ );
1085 }
else if ( ( lua_isnil( L, 1 ) ) || ( lua_gettop( L ) == 0 ) ) {
1093 lua_rawseti( L, -2, k++ );
1097 NLUA_INVALID_PARAMETER( L, 1 );
1102static int getFriendOrFoeTest(
const Pilot *p,
const Pilot *plt,
int friend,
1103 double dd,
int inrange,
int dis,
int fighters,
1104 const vec2 *v, LuaFaction lf )
1107 if ( pilot_isFlag( plt, PILOT_DELETE ) )
1111 if ( ( p != NULL ) && ( p->id == plt->
id ) )
1115 if ( !fighters && pilot_isFlag( plt, PILOT_CARRIED ) )
1119 if ( ( dd >= 0. ) && vec2_dist2( &plt->
solid.
pos, v ) > dd )
1123 if ( dis && pilot_isDisabled( plt ) )
1151 if ( ( p != NULL ) && inrange &&
friend ) {
1162static int pilotL_getFriendOrFoe( lua_State *L,
int friend )
1168 int inrange, dis, fighters;
1177 else if ( lua_isstring( L, 1 ) )
1181 dist = luaL_optnumber( L, 2, -1. );
1184 dis = lua_toboolean( L, 5 );
1185 fighters = lua_toboolean( L, 6 );
1191 dist = luaL_optnumber( L, 2, -1. );
1192 v = luaL_optvector( L, 3, &p->solid.pos );
1193 inrange = !lua_toboolean( L, 4 );
1194 dis = lua_toboolean( L, 5 );
1195 fighters = lua_toboolean( L, 6 );
1207 if ( dist >= 0. && dist < INFINITY ) {
1213 qt = pilot_collideQuery( x - r, y - r, x + r, y + r );
1214 for (
int i = 0; i < il_size( qt ); i++ ) {
1217 if ( getFriendOrFoeTest( p, plt,
friend, dd, inrange, dis, fighters, v,
1220 lua_rawseti( L, -2, k++ );
1227 if ( getFriendOrFoeTest( p, plt,
friend, dd, inrange, dis, fighters, v,
1230 lua_rawseti( L, -2, k++ );
1261 return pilotL_getFriendOrFoe( L, 1 );
1287 return pilotL_getFriendOrFoe( L, 0 );
1309 int dis = lua_toboolean( L, 2 );
1318 if ( pilot_isFlag(
pilot_stack[i], PILOT_DELETE ) )
1328 lua_rawseti( L, -2, k++ );
1350 double d = luaL_checknumber( L, 2 );
1351 int dis = lua_toboolean( L, 3 );
1362 qt = pilot_collideQuery( x - r, y - r, x + r, y + r );
1365 for (
int i = 0; i < il_size( qt ); i++ ) {
1369 if ( pilot_isFlag( p, PILOT_DELETE ) )
1372 if ( pilot_isFlag( p, PILOT_HIDE ) )
1375 if ( dis && pilot_isDisabled( p ) )
1379 if ( vec2_dist2( v, &p->solid.pos ) >
d )
1383 lua_rawseti( L, -2, k++ );
1403 lua_pushboolean( L, p1 == p2 );
1422 lua_pushstring( L, p->name );
1424 lua_pushstring( L,
"(inexistent pilot)" );
1440 lua_pushstring( L, p->name );
1457 lua_pushnumber( L, p->id );
1480 else if ( pilot_isFlag( p, PILOT_DEAD ) || pilot_isFlag( p, PILOT_HIDE ) )
1486 lua_pushboolean( L, exists );
1522 if ( lua_isnoneornil( L, 2 ) )
1526 if ( pilot_isPlayer( p ) )
1547 if ( p->nav_asteroid < 0 )
1550 la.parent = p->nav_anchor;
1551 la.id = p->nav_asteroid;
1569 p->nav_anchor = la->parent;
1570 p->nav_asteroid = la->id;
1604 lua_pushboolean( L, 1 );
1605 lua_pushboolean( L, 1 );
1606 }
else if ( ret == 0 ) {
1607 lua_pushboolean( L, 0 );
1608 lua_pushboolean( L, 0 );
1610 lua_pushboolean( L, 1 );
1611 lua_pushboolean( L, 0 );
1619 lua_pushboolean( L, 1 );
1624 lua_pushboolean( L, 1 );
1638 if ( pilot_isPlayer( p ) ) {
1640 lua_pushboolean( L, pilot_isFlag( t, PILOT_PLAYER_SCANNED ) );
1656 lua_pushboolean( L, pilot_isWithPlayer( p ) );
1673 if ( p->target == 0 )
1677 if ( p->nav_spob < 0 )
1683 if ( p->nav_hyperspace < 0 )
1686 LuaSystem ls =
cur_system->jumps[p->nav_hyperspace].targetid;
1705 if ( p->nav_spob < 0 )
1725 if ( p->nav_hyperspace < 0 )
1749 if ( !lua_isnoneornil( L, 2 ) ) {
1753 L, _(
"Jump source system doesn't match current system!" ) );
1761 return NLUA_ERROR( L, _(
"Jump destination system not found!" ) );
1764 if ( pilot_isPlayer( p ) ) {
1767 map_select( NULL, 0 );
1769 map_select(
cur_system->jumps[jumpid].target, 0 );
1771 p->nav_hyperspace = jumpid;
1799 lua_pushnumber( L, ++( *k ) );
1805 lua_pushstring( L,
"outfit" );
1807 lua_rawset( L, -3 );
1811 double delay, firemod, enermod;
1817 lua_pushstring( L,
"cooldown" );
1818 has_beamid = ( slot->u.
beamid > 0 );
1820 lua_pushnumber( L, 0. );
1823 lua_pushnumber( L,
CLAMP( 0., 1., 1. - delay ) );
1825 lua_rawset( L, -3 );
1828 lua_pushstring( L,
"charge" );
1832 lua_pushnumber( L,
CLAMP( 0., 1., 1. - delay ) );
1833 lua_rawset( L, -3 );
1835 double delay, firemod, enermod;
1837 lua_pushstring( L,
"cooldown" );
1841 lua_pushnumber( L,
CLAMP( 0., 1., 1. - slot->
timer / delay ) );
1843 lua_pushnumber( L, 1. );
1844 lua_rawset( L, -3 );
1848 if ( is_lau || is_fb ) {
1849 lua_pushstring( L,
"left" );
1851 lua_rawset( L, -3 );
1854 lua_pushstring( L,
"left_p" );
1857 lua_rawset( L, -3 );
1863 lua_pushstring( L,
"lockon" );
1865 lua_pushnumber( L, 1. );
1868 lua_rawset( L, -3 );
1872 lua_pushstring( L,
"in_arc" );
1874 lua_rawset( L, -3 );
1877 lua_pushstring( L,
"active" );
1878 lua_pushboolean( L, slot->
flags & PILOTOUTFIT_ISON );
1879 lua_rawset( L, -3 );
1882 lua_pushstring( L,
"heat" );
1884 lua_rawset( L, -3 );
1887 lua_pushstring( L,
"type" );
1889 lua_rawset( L, -3 );
1892 lua_pushinteger( L, slot->
weapset + 1 );
1893 lua_setfield( L, -2,
"weapset" );
1897 if ( dmg != NULL ) {
1898 lua_pushstring( L,
"dtype" );
1900 lua_rawset( L, -3 );
1905 lua_pushstring( L,
"track" );
1906 if ( target != NULL )
1911 lua_pushnumber( L, -1 );
1912 lua_rawset( L, -3 );
1916 lua_rawset( L, -3 );
1932 lua_pushboolean( L, p->autoweap );
1984 if ( lua_gettop( L ) > 1 ) {
1985 id = luaL_checkinteger( L, 2 ) - 1;
1986 id =
CLAMP( 0, PILOT_WEAPON_SETS,
id );
1992 target = ( p->target != p->id ) ?
pilot_get( p->target ) : NULL;
2001 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
2008 for (
int i = 0; i <
array_size( po_list ); i++ ) {
2017static int luaL_checkweapset( lua_State *L,
int idx )
2019 int ws = luaL_checkinteger( L, idx ) - 1;
2020 if ( ( ws < 0 ) || ( ws > 9 ) )
2021 return NLUA_ERROR( L, _(
"Invalid weapon set '%d'!" ), idx );
2027 if ( lua_isnumber( L, idx ) ) {
2028 const int slotid = lua_tointeger( L, idx );
2029 if ( ( slotid < 1 ) || ( slotid >
array_size( p->outfits ) ) ) {
2032 _(
"Pilot '%s' with ship '%s' does not have a slot with id '%d'!" ),
2033 p->name, _( p->ship->name ), slotid );
2037 return p->outfits[slotid - 1];
2040 const char *slotname = luaL_checkstring( L, idx );
2044 L, _(
"Pilot '%s' with ship '%s' does not have named slot '%s'!" ),
2045 p->name, _( p->ship->name ), slotname );
2063 int id = luaL_checkweapset( L, 2 );
2069 lua_rawseti( L, -2, i + 1 );
2086 int id = luaL_checkweapset( L, 2 );
2087 const char *type = luaL_checkstring( L, 3 );
2089 if ( strcmp( type,
"toggle" ) == 0 )
2090 typeid = WEAPSET_TYPE_TOGGLE;
2091 else if ( strcmp( type,
"hold" ) == 0 )
2092 typeid = WEAPSET_TYPE_HOLD;
2094 return NLUA_ERROR( L, _(
"Invalid weapon set type '%s'!" ), type );
2111 int id = luaL_checkweapset( L, 2 );
2129 int id = luaL_checkweapset( L, 2 );
2130 const char *type = luaL_checkstring( L, 3 );
2131 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
2133 if ( pos->
outfit == NULL )
2135 if ( ( strcmp( pos->
outfit->
name, type ) == 0 ) ||
2155 int id = luaL_checkweapset( L, 2 );
2173 if ( lua_isnoneornil( L, 2 ) ) {
2174 for (
int i = 0; i < PILOT_WEAPON_SETS; i++ )
2177 int id = luaL_checkweapset( L, 2 );
2210 double heat, heat_mean, heat_peak, nweapons;
2220 if ( lua_gettop( L ) > 1 ) {
2221 id = luaL_checkinteger( L, 2 ) - 1;
2222 id =
CLAMP( 0, PILOT_WEAPON_SETS,
id );
2232 for (
int i = 0; i < n; i++ ) {
2235 all ? p->outfits[i] : p->outfits[po_list[i].
slotid];
2247 if ( heat > heat_peak )
2253 heat_mean /= nweapons;
2255 lua_pushnumber( L, heat_mean );
2256 lua_pushnumber( L, heat_peak );
2273 int inrange = lua_toboolean( L, 3 );
2274 if ( lua_isnoneornil( L, 2 ) ) {
2275 for (
int i = 0; i < PILOT_WEAPON_SETS; i++ )
2278 int id = luaL_checkweapset( L, 2 );
2297 int id = luaL_checkinteger( L, 2 );
2360 sort = lua_toboolean( L, 2 );
2370 outfits = p->outfits;
2372 for (
int i = 0; i <
array_size( outfits ); i++ ) {
2375 if ( pos->
outfit == NULL )
2377 if ( !( pos->
flags & PILOTOUTFIT_ACTIVE ) )
2384 for (
int j = 0; j < i; j++ ) {
2397 lua_pushnumber( L, ++k );
2401 lua_pushstring( L,
"outfit" );
2403 lua_rawset( L, -3 );
2406 lua_pushstring( L,
"type" );
2408 lua_rawset( L, -3 );
2411 lua_pushstring( L,
"heat" );
2415 lua_rawset( L, -3 );
2417 lua_pushstring( L,
"active" );
2418 lua_pushboolean( L, pos->
flags & PILOTOUTFIT_ISON );
2419 lua_rawset( L, -3 );
2422 if ( outfits[i]->weapset != -1 ) {
2423 lua_pushstring( L,
"weapset" );
2424 lua_pushnumber( L, outfits[i]->weapset + 1 );
2425 lua_rawset( L, -3 );
2429 switch ( pos->
state ) {
2430 case PILOT_OUTFIT_OFF:
2433 case PILOT_OUTFIT_WARMUP:
2441 lua_pushstring( L,
"warmup" );
2442 lua_pushnumber( L,
d );
2443 lua_rawset( L, -3 );
2445 case PILOT_OUTFIT_ON:
2452 else if ( !isinf( pos->
stimer ) )
2456 lua_pushstring( L,
"duration" );
2457 lua_pushnumber( L,
d );
2458 lua_rawset( L, -3 );
2460 case PILOT_OUTFIT_COOLDOWN:
2465 if (
d > 0. && !isinf( pos->
stimer ) )
2469 lua_pushstring( L,
"cooldown" );
2470 lua_pushnumber( L,
d );
2471 lua_rawset( L, -3 );
2477 lua_pushstring( L,
"state" );
2478 lua_pushstring( L, str );
2479 lua_rawset( L, -3 );
2482 lua_rawset( L, -3 );
2514 if ( s1->
id < s2->
id )
2516 else if ( s1->
id > s2->
id )
2539 const char *type = luaL_optstring( L, 2, NULL );
2540 int skip_locked = lua_toboolean( L, 3 );
2541 OutfitSlotType ost = OUTFIT_SLOT_NULL;
2544 if ( type != NULL ) {
2545 if ( strcmp( type,
"all" ) == 0 )
2547 else if ( strcmp( type,
"structure" ) == 0 )
2548 ost = OUTFIT_SLOT_STRUCTURE;
2549 else if ( strcmp( type,
"utility" ) == 0 )
2550 ost = OUTFIT_SLOT_UTILITY;
2551 else if ( strcmp( type,
"weapon" ) == 0 )
2552 ost = OUTFIT_SLOT_WEAPON;
2553 else if ( strcmp( type,
"intrinsic" ) == 0 ) {
2557 return NLUA_ERROR( L, _(
"Unknown slot type '%s'" ), type );
2563 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
2565 if ( p->outfits[i]->outfit == NULL )
2569 if ( ( ost != OUTFIT_SLOT_NULL ) &&
2570 ( p->outfits[i]->outfit->slot.type != ost ) )
2574 if ( skip_locked && p->outfits[i]->sslot->locked )
2579 lua_rawseti( L, -2, j++ );
2583 for (
int i = 0; i <
array_size( p->outfit_intrinsic ); i++ ) {
2585 lua_rawseti( L, -2, j++ );
2606 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
2607 if ( p->outfits[i]->outfit == NULL )
2608 lua_pushboolean( L, 0 );
2611 lua_rawseti( L, -2, i + 1 );
2632 for (
int i = 1;; i++ ) {
2636 lua_rawgeti( L, 2, i );
2637 if ( lua_isnil( L, -1 ) ) {
2645 _(
"Trying to equip more outfits than slots available on pilot "
2653 if ( !lua_toboolean( L, -1 ) )
2657 s = p->outfits[i - 1];
2662 lua_pushboolean( L, !ret );
2678 int id = luaL_checkinteger( L, 2 ) - 1;
2679 if ( id < 0 || id >=
array_size( p->outfits ) )
2680 return NLUA_ERROR( L, _(
"Pilot '%s' outfit ID '%d' is out of range!" ),
2683 if ( p->outfits[
id]->outfit != NULL )
2690static int outfitToggle( lua_State *L,
Pilot *p,
int id,
int activate )
2692 if ( id < 0 || id >=
array_size( p->outfits ) )
2693 return NLUA_ERROR( L, _(
"Pilot '%s' outfit ID '%d' is out of range!" ),
2703 if ( ( activate && ( po->
state != PILOT_OUTFIT_OFF ) ) ||
2704 ( !activate && ( po->
state != PILOT_OUTFIT_ON ) ) )
2707 int ret = po->
flags & PILOTOUTFIT_ISON_TOGGLE;
2709 po->
flags |= PILOTOUTFIT_ISON_TOGGLE;
2712 po->
flags &= PILOTOUTFIT_ISON_TOGGLE;
2729 int activate = lua_toboolean( L, 3 );
2733 if ( ( pilot_isDisabled( p ) ) || ( pilot_isFlag( p, PILOT_COOLDOWN ) ) )
2736 if ( lua_istable( L, 2 ) ) {
2739 while ( lua_next( L, 1 ) != 0 ) {
2740 n += outfitToggle( L, p, luaL_checkinteger( L, -1 ) - 1, activate );
2745 n = outfitToggle( L, p, luaL_checkinteger( L, 2 ) - 1, activate );
2751 lua_pushboolean( L, n );
2767 int id = luaL_checkinteger( L, 2 ) - 1;
2768 if ( id < 0 || id >=
array_size( p->outfits ) )
2769 return NLUA_ERROR( L, _(
"Pilot '%s' outfit ID '%d' is out of range!" ),
2772 if ( p->outfits[
id]->outfit != NULL )
2773 lua_pushboolean( L, p->outfits[
id]->state == PILOT_OUTFIT_OFF );
2775 lua_pushboolean( L, 0 );
2792 const char *name = luaL_checkstring( L, 2 );
2796 p->name = strdup( name );
2845 lua_pushboolean( L, ( VMOD( p->solid.vel ) < MIN_VEL_ERR ) );
2861 lua_pushnumber( L, p->ew_signature );
2877 lua_pushnumber( L, p->solid.dir );
2893 lua_pushnumber( L, p->heat_T );
2909 lua_pushnumber( L, p->solid.mass );
2923 lua_pushnumber( L, p->accel );
2939 lua_pushnumber( L, p->speed );
2954 lua_pushnumber( L, solid_maxspeed( &p->solid, p->speed, p->accel ) );
2968 lua_pushnumber( L, p->turn * 180. / M_PI );
3048 char message[STRMAX_SHORT];
3051 lua_pushboolean( L, worthy );
3052 lua_pushstring( L, message );
3075 p->solid.pos = *vec;
3078 if ( pilot_isPlayer( p ) )
3100 p->solid.vel = *vec;
3119 double d = luaL_checknumber( L, 2 );
3122 p->solid.dir = angle_clean(
d );
3147 if ( lua_isstring( L, 1 ) ) {
3148 const char *s = luaL_checkstring( L, 1 );
3149 const char *msg = luaL_checkstring( L, 2 );
3150 const char *col = luaL_optstring( L, 3, NULL );
3153 ( ( col == NULL ) ?
'N' : col[0] ), s, msg );
3158 const char *msg = luaL_checkstring( L, 2 );
3159 int ignore_int = lua_toboolean( L, 3 );
3195 if ( lua_isstring( L, 1 ) ) {
3197 const char *msg, *col;
3204 s = luaL_checkstring( L, 1 );
3205 if ( lua_isstring( L, 2 ) ) {
3206 msg = luaL_checkstring( L, 2 );
3207 col = luaL_optstring( L, 3, NULL );
3208 raw = lua_toboolean( L, 4 );
3211 if ( target !=
player.p->id )
3213 msg = luaL_checkstring( L, 3 );
3214 col = luaL_optstring( L, 4, NULL );
3215 raw = lua_toboolean( L, 5 );
3220 player_message( _(
"#%c%s>#0 %s" ), ( ( col == NULL ) ?
'N' : col[0] ),
3224 ( ( col == NULL ) ?
'N' : col[0] ), s, msg );
3231 int ignore_int, raw;
3235 if ( lua_isstring( L, 2 ) ) {
3237 msg = luaL_checkstring( L, 2 );
3238 ignore_int = lua_toboolean( L, 3 );
3239 raw = lua_toboolean( L, 4 );
3242 msg = luaL_checkstring( L, 3 );
3243 ignore_int = lua_toboolean( L, 4 );
3244 raw = lua_toboolean( L, 5 );
3254 if ( target == 0 || target == PLAYER_ID ) {
3305 if ( lua_isnone( L, 2 ) )
3308 state = lua_toboolean( L, 2 );
3336 if ( lua_isnone( L, 2 ) )
3339 state = lua_toboolean( L, 2 );
3521 lua_pushboolean( L, pilot_isDisabled( p ) );
3540static int pilotL_disable( lua_State *L )
3542 NLUA_DEPRECATED( L,
"disable" );
3560 int permanent = !lua_toboolean( L, 2 );
3564 p->stress = p->armour;
3568 pilot_setFlag( p, PILOT_DISABLED_PERM );
3570 pilot_rmFlag( p, PILOT_DISABLED_PERM );
3588 lua_pushboolean( L, pilot_isFlag( p, PILOT_COOLDOWN ) );
3589 lua_pushboolean( L, pilot_isFlag( p, PILOT_COOLDOWN_BRAKE ) );
3609 if ( lua_isnone( L, 2 ) )
3612 state = lua_toboolean( L, 2 );
3634 pilot_rmFlag( p, PILOT_COOLDOWN_BRAKE );
3687 int bypass_cpu,
int bypass_slot )
3696 if ( bypass_slot ) {
3699 }
else if ( bypass_cpu ) {
3725 if ( pilot_isPlayer( p ) )
3756 int q, added, bypass_cpu, bypass_slot, slotid;
3761 q = luaL_optinteger( L, 3, 1 );
3762 bypass_cpu = lua_toboolean( L, 4 );
3763 bypass_slot = lua_toboolean( L, 5 );
3768 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
3780 else if ( ret == 0 )
3803 if ( pilot_isPlayer( p ) )
3807 lua_pushnumber( L, added );
3810 lua_pushinteger( L, slotid + 1 );
3856 int ret, added, bypass_cpu, bypass_slot;
3862 s = luaL_checkslot( L, p, 3 );
3863 bypass_cpu = lua_toboolean( L, 4 );
3864 bypass_slot = lua_toboolean( L, 5 );
3870 added = ( ret > 0 );
3885 if ( pilot_isPlayer( p ) )
3889 lua_pushboolean( L, added );
3918 int q, removed, matched = 0;
3923 q = luaL_optinteger( L, 3, 1 );
3925 if ( lua_isstring( L, 2 ) ) {
3926 const char *outfit = luaL_checkstring( L, 2 );
3930 if ( strcmp( outfit,
"all" ) == 0 ) {
3931 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
3932 if ( p->outfits[i]->sslot->required )
3934 if ( p->outfits[i]->sslot->locked )
3943 else if ( strcmp( outfit,
"cores" ) == 0 ) {
3944 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
3945 if ( !p->outfits[i]->sslot->required )
3954 else if ( strcmp( outfit,
"intrinsic" ) == 0 ) {
3955 for (
int i = 0; i <
array_size( p->outfit_intrinsic ); i++ ) {
3971 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
3977 if ( p->outfits[i]->outfit != o )
3988 if (
player.p != NULL &&
player.p == p && removed > 0 )
3991 lua_pushnumber( L, removed );
4026 lua_pushboolean( L, ret );
4049 lua_pushboolean( L, ret );
4052 if ( pilot_isPlayer( p ) )
4086 lua_pushnumber( L, p->fuel );
4106 if ( lua_isboolean( L, 2 ) ) {
4107 if ( lua_toboolean( L, 2 ) )
4108 p->fuel = p->fuel_max;
4111 }
else if ( lua_isnumber( L, 2 ) ) {
4112 p->fuel =
CLAMP( 0, p->fuel_max, lua_tonumber( L, 2 ) );
4114 NLUA_INVALID_PARAMETER( L, 2 );
4117 lua_pushnumber( L, p->fuel );
4129 ss_free( p->intrinsic_stats );
4130 p->intrinsic_stats = NULL;
4155 if ( !lua_istable( L, 2 ) ) {
4156 name = luaL_checkstring( L, 2 );
4157 value = luaL_checknumber( L, 3 );
4158 replace = lua_toboolean( L, 4 );
4159 p->intrinsic_stats = ss_statsSetList(
4164 replace = lua_toboolean( L, 4 );
4167 while ( lua_next( L, 2 ) != 0 ) {
4168 name = luaL_checkstring( L, -2 );
4169 value = luaL_checknumber( L, -1 );
4170 p->intrinsic_stats = ss_statsSetList(
4195 const char *name = luaL_optstring( L, 2, NULL );
4196 int internal = lua_toboolean( L, 3 );
4214 p->ship_stats = NULL;
4237 if ( p->ship->lua_env == LUA_NOREF )
4238 return NLUA_ERROR( L,
4239 _(
"Trying to set ship property of pilot '%s' flying "
4240 "ship '%s' with no ship Lua enabled!" ),
4241 p->name, p->ship->name );
4244 if ( !lua_istable( L, 2 ) ) {
4245 name = luaL_checkstring( L, 2 );
4246 value = luaL_checknumber( L, 3 );
4248 ss_statsSetList( p->ship_stats,
ss_typeFromName( name ), value, 1, 0 );
4254 while ( lua_next( L, 2 ) != 0 ) {
4255 name = luaL_checkstring( L, -2 );
4256 value = luaL_checknumber( L, -1 );
4258 ss_statsSetList( p->ship_stats,
ss_typeFromName( name ), value, 1, 0 );
4282 const char *name = luaL_optstring( L, 2, NULL );
4283 int internal = lua_toboolean( L, 3 );
4304 int keepdebuffs = lua_toboolean( L, 2 );
4305 int keepbuffs = lua_toboolean( L, 3 );
4306 int keepothers = lua_toboolean( L, 4 );
4307 if ( !keepdebuffs && !keepbuffs && !keepothers )
4330 const char *effectname = luaL_checkstring( L, 2 );
4331 double duration = luaL_optnumber( L, 3, -1. );
4332 double scale = luaL_optnumber( L, 4, 1. );
4334 if ( efx != NULL ) {
4335 if ( !
effect_add( &p->effects, efx, duration, scale, p->id ) )
4337 lua_pushboolean( L, 1 );
4339 lua_pushboolean( L, 0 );
4356 if ( lua_isnumber( L, 2 ) ) {
4357 int idx = lua_tointeger( L, 2 );
4361 const char *effectname = luaL_checkstring( L, 2 );
4362 int all = lua_toboolean( L, 3 );
4364 if ( efx != NULL ) {
4382 const char *effectname = luaL_checkstring( L, 2 );
4383 for (
int i = 0; i <
array_size( p->effects ); i++ ) {
4384 const Effect *e = &p->effects[i];
4385 if ( strcmp( effectname, e->
data->
name ) != 0 )
4387 lua_pushboolean( L, 1 );
4390 lua_pushboolean( L, 0 );
4406 for (
int i = 0; i <
array_size( p->effects ); i++ ) {
4407 const Effect *e = &p->effects[i];
4410 lua_pushstring( L, e->
data->
name );
4411 lua_setfield( L, -2,
"name" );
4413 lua_pushnumber( L, e->
timer );
4414 lua_setfield( L, -2,
"timer" );
4416 lua_pushnumber( L, e->
timer );
4417 lua_setfield( L, -2,
"strength" );
4420 lua_setfield( L, -2,
"duration" );
4423 lua_setfield( L, -2,
"icon" );
4426 lua_pushboolean( L, 1 );
4427 lua_setfield( L, -2,
"buff" );
4431 lua_pushboolean( L, 1 );
4432 lua_setfield( L, -2,
"debuff" );
4435 lua_rawseti( L, -2, i + 1 );
4450 if ( p->ai == NULL )
4452 lua_pushstring( L, p->ai->name );
4470 const char *str = luaL_checkstring( L, 2 );
4477 lua_pushboolean( L, ret );
4509 kelvins = luaL_checknumber( L, 2 );
4510 setOutfits = !lua_toboolean( L, 3 );
4513 kelvins =
MAX( kelvins, CONST_SPACE_STAR_TEMP );
4516 p->heat_T = kelvins;
4520 for (
int i = 0; i <
array_size( p->outfits ); i++ )
4521 p->outfits[i]->heat_T = kelvins;
4552 a = luaL_optnumber( L, 2, 100. * p->armour / p->armour_max );
4553 s = luaL_optnumber( L, 3, 100. * p->shield / p->shield_max );
4554 st = luaL_optnumber( L, 4, 0. );
4561 p->armour = a * p->armour_max;
4562 p->shield = s * p->shield_max;
4563 p->stress =
st * p->armour;
4566 if ( p->armour > 0. ) {
4567 pilot_rmFlag( p, PILOT_DISABLED );
4568 pilot_rmFlag( p, PILOT_DEAD );
4569 pilot_rmFlag( p, PILOT_DEATH_SOUND );
4570 pilot_rmFlag( p, PILOT_EXPLODED );
4571 pilot_rmFlag( p, PILOT_DELETE );
4572 if ( pilot_isPlayer( p ) )
4573 player_rmFlag( PLAYER_DESTROYED );
4575 pilot_rmFlag( p, PILOT_DISABLED_PERM );
4605 a = luaL_optnumber( L, 2, p->armour );
4606 s = luaL_optnumber( L, 3, p->shield );
4607 st = luaL_optnumber( L, 4, p->stress );
4610 p->armour =
CLAMP( 0., p->armour_max, a );
4611 p->shield =
CLAMP( 0., p->shield_max, s );
4612 p->stress =
CLAMP( 0., p->armour_max,
st );
4615 if ( p->armour > 0. ) {
4616 pilot_rmFlag( p, PILOT_DISABLED );
4617 pilot_rmFlag( p, PILOT_DEAD );
4618 pilot_rmFlag( p, PILOT_DEATH_SOUND );
4619 pilot_rmFlag( p, PILOT_EXPLODED );
4620 pilot_rmFlag( p, PILOT_DELETE );
4621 if ( pilot_isPlayer( p ) )
4622 player_rmFlag( PLAYER_DESTROYED );
4624 pilot_rmFlag( p, PILOT_DISABLED_PERM );
4649 a = luaL_optnumber( L, 2, 0. );
4650 s = luaL_optnumber( L, 3, 0. );
4653 p->armour =
CLAMP( 0., p->armour_max, p->armour + a );
4654 p->shield =
CLAMP( 0., p->shield_max, p->shield + s );
4679 double e = luaL_checknumber( L, 2 );
4680 int absolute = lua_toboolean( L, 3 );
4683 p->energy =
CLAMP( 0., p->energy_max, e );
4685 p->energy = ( e / 100. ) * p->energy_max;
4701 double e = luaL_checknumber( L, 2 );
4702 p->energy =
CLAMP( 0., p->energy_max, p->energy + e );
4735 if ( lua_isnone( L, 2 ) )
4738 disable = lua_toboolean( L, 2 );
4742 pilot_setFlag( p, PILOT_NOBOARD );
4744 pilot_rmFlag( p, PILOT_NOBOARD );
4765 if ( lua_isnone( L, 2 ) )
4768 nodisable = lua_toboolean( L, 2 );
4772 pilot_setFlag( p, PILOT_NODISABLE );
4774 pilot_rmFlag( p, PILOT_NODISABLE );
4796 double s = luaL_checknumber( L, 2 );
4801 pilot_setFlag( p, PILOT_HASSPEEDLIMIT );
4803 pilot_rmFlag( p, PILOT_HASSPEEDLIMIT );
4828 int absolute = lua_toboolean( L, 2 );
4831 lua_pushnumber( L, p->armour );
4832 lua_pushnumber( L, p->shield );
4835 L, ( p->armour_max > 0. ) ? p->armour / p->armour_max * 100. : 0. );
4837 L, ( p->shield_max > 0. ) ? p->shield / p->shield_max * 100. : 0. );
4839 lua_pushnumber( L,
MIN( 1., p->stress / p->armour ) * 100. );
4840 lua_pushboolean( L, pilot_isDisabled( p ) );
4859 int absolute = lua_toboolean( L, 2 );
4861 lua_pushnumber( L, p->armour );
4864 L, ( p->armour_max > 0. ) ? p->armour / p->armour_max * 100. : 0. );
4883 int absolute = lua_toboolean( L, 2 );
4885 lua_pushnumber( L, p->shield );
4888 L, ( p->shield_max > 0. ) ? p->shield / p->shield_max * 100. : 0. );
4907 int absolute = lua_toboolean( L, 2 );
4909 lua_pushnumber( L, p->stress );
4912 L, ( p->armour > 0. ) ?
MIN( 1., p->stress / p->armour ) * 100. : 0. );
4930 int absolute = lua_toboolean( L, 2 );
4932 lua_pushnumber( L, p->energy );
4935 L, ( p->energy_max > 0. ) ? p->energy / p->energy_max * 100. : 0. );
4951 lua_pushnumber( L, p->lockons );
4955#define PUSH_DOUBLE( L, name, value ) \
4956 lua_pushstring( L, name ); \
4957 lua_pushnumber( L, value ); \
4959#define PUSH_INT( L, name, value ) \
4960 lua_pushstring( L, name ); \
4961 lua_pushinteger( L, value ); \
5002 PUSH_DOUBLE( L,
"cpu", p->cpu );
5003 PUSH_INT( L,
"cpu_max", p->cpu_max );
5004 PUSH_INT( L,
"crew", (
int)round( p->crew ) );
5005 PUSH_INT( L,
"fuel", p->fuel );
5006 PUSH_INT( L,
"fuel_max", p->fuel_max );
5007 PUSH_INT( L,
"fuel_consumption", p->fuel_consumption );
5008 PUSH_DOUBLE( L,
"mass", p->solid.mass );
5010 PUSH_DOUBLE( L,
"accel", p->accel );
5011 PUSH_DOUBLE( L,
"speed", p->speed );
5012 PUSH_DOUBLE( L,
"turn", p->turn * 180. / M_PI );
5013 PUSH_DOUBLE( L,
"speed_max",
5014 solid_maxspeed( &p->solid, p->speed, p->accel ) );
5016 PUSH_DOUBLE( L,
"absorb", p->dmg_absorb );
5017 PUSH_DOUBLE( L,
"armour", p->armour_max );
5018 PUSH_DOUBLE( L,
"shield", p->shield_max );
5019 PUSH_DOUBLE( L,
"energy", p->energy_max );
5020 PUSH_DOUBLE( L,
"armour_regen", p->armour_regen );
5021 PUSH_DOUBLE( L,
"shield_regen", p->shield_regen );
5022 PUSH_DOUBLE( L,
"energy_regen", p->energy_regen );
5024 PUSH_DOUBLE( L,
"ew_detection", p->ew_detection );
5025 PUSH_DOUBLE( L,
"ew_signature", p->ew_signature );
5026 PUSH_DOUBLE( L,
"ew_stealth", p->ew_stealth );
5027 PUSH_DOUBLE( L,
"jump_delay",
5054 const char *str = luaL_optstring( L, 2, NULL );
5055 int internal = lua_toboolean( L, 3 );
5069 if ( pilot_isFlag( p, PILOT_STEALTH ) )
5070 lua_pushnumber( L, p->ew_stealth );
5072 lua_pushnumber( L, p->ew_detection );
5106 lua_pushnumber( L, quantity );
5128 int quantity = luaL_checknumber( L, 3 );
5131 return NLUA_ERROR( L, _(
"Quantity must be positive for pilot.cargoAdd "
5132 "(if removing, use pilot.cargoRm)" ) );
5136 lua_pushnumber( L, quantity );
5140static int pilotL_cargoRmHelper( lua_State *L,
int jet )
5149 if ( lua_isstring( L, 2 ) ) {
5150 const char *str = lua_tostring( L, 2 );
5153 if ( strcmp( str,
"all" ) == 0 ) {
5155 lua_pushnumber( L, quantity );
5162 quantity = luaL_checknumber( L, 3 );
5165 return NLUA_ERROR( L, _(
"Quantity must be positive for pilot.cargoRm "
5166 "(if adding, use pilot.cargoAdd)" ) );
5174 lua_pushnumber( L, quantity );
5196 return pilotL_cargoRmHelper( L, 0 );
5213 return pilotL_cargoRmHelper( L, 1 );
5239 for (
int i = 0; i <
array_size( p->commodities ); i++ ) {
5245 lua_pushstring( L,
"name" );
5247 lua_rawset( L, -3 );
5249 lua_pushstring( L,
"c" );
5251 lua_rawset( L, -3 );
5253 lua_pushstring( L,
"q" );
5255 lua_rawset( L, -3 );
5257 lua_pushstring( L,
"m" );
5258 lua_pushboolean( L, pc->
id );
5259 lua_rawset( L, -3 );
5261 lua_rawseti( L, -2, i + 1 );
5278 lua_pushnumber( L, p->credits );
5294 lua_pushnumber( L,
pilot_worth( p, lua_toboolean( L, 2 ) ) );
5331 lua_pushstring( L, str );
5359 { .name =
"stealth", .id = PILOT_STEALTH },
5360 { .name =
"refueling", .id = PILOT_REFUELING },
5361 { .name =
"invisible", .id = PILOT_INVISIBLE },
5362 { .name =
"disabled", .id = PILOT_DISABLED },
5363 { .name =
"disabled_perm", .id = PILOT_DISABLED_PERM },
5364 { .name =
"landing", .id = PILOT_LANDING },
5365 { .name =
"takingoff", .id = PILOT_TAKEOFF },
5366 { .name =
"jumpprep", .id = PILOT_HYP_PREP },
5367 { .name =
"jumpingin", .id = PILOT_HYP_END },
5368 { .name =
"jumpingout", .id = PILOT_HYPERSPACE },
5369 { .name =
"manualcontrol", .id = PILOT_MANUAL_CONTROL },
5370 { .name =
"carried", .id = PILOT_CARRIED },
5371 { .name =
"hailing", .id = PILOT_HAILING },
5372 { .name =
"bribed", .id = PILOT_BRIBED },
5373 { .name =
"boardable", .id = PILOT_BOARDABLE },
5374 { .name =
"nojump", .id = PILOT_NOJUMP },
5375 { .name =
"noland", .id = PILOT_NOLAND },
5376 { .name =
"nodeath", .id = PILOT_NODEATH },
5377 { .name =
"nodisable", .id = PILOT_NODISABLE },
5378 { .name =
"visible", .id = PILOT_VISIBLE },
5379 { .name =
"visplayer", .id = PILOT_VISPLAYER },
5380 { .name =
"hilight", .id = PILOT_HILIGHT },
5381 { .name =
"norender", .id = PILOT_NORENDER },
5382 { .name =
"hide", .id = PILOT_HIDE },
5383 { .name =
"invincible", .id = PILOT_INVINCIBLE },
5384 { .name =
"invinc_player", .id = PILOT_INVINC_PLAYER },
5385 { .name =
"friendly", .id = PILOT_FRIENDLY },
5386 { .name =
"hostile", .id = PILOT_HOSTILE },
5387 { .name =
"combat", .id = PILOT_COMBAT },
5426 const char *name = luaL_optstring( L, 2, NULL );
5428 if ( name != NULL ) {
5429 for (
int i = 0;
pL_flags[i].name != NULL; i++ )
5430 if ( strcmp(
pL_flags[i].name, name ) == 0 ) {
5431 lua_pushboolean( L, pilot_isFlag( p,
pL_flags[i].
id ) );
5435 NLUA_WARN( L, _(
"Tried to access unknown flag '%s' for pilot '%s'!" ),
5443 for (
int i = 0;
pL_flags[i].name != NULL; i++ ) {
5444 lua_pushboolean( L, pilot_isFlag( p,
pL_flags[i].
id ) );
5445 lua_setfield( L, -2,
pL_flags[i].name );
5491 lua_pushnumber( L, PILOT_SIZE_APPROX * 0.5 * p->ship->size );
5507 lua_pushinteger( L, p->ship->points );
5523 lua_pushboolean( L, p->task == 0 );
5557 int enable, cleartasks;
5561 if ( lua_isnone( L, 2 ) )
5564 enable = lua_toboolean( L, 2 );
5565 if ( lua_isnone( L, 3 ) )
5566 cleartasks = enable ^ pilot_isFlag( p, PILOT_MANUAL_CONTROL );
5568 cleartasks = lua_toboolean( L, 3 );
5571 int isp = pilot_isPlayer( p );
5575 pilot_setFlag( p, PILOT_MANUAL_CONTROL );
5579 pilot_rmFlag( p, PILOT_MANUAL_CONTROL );
5580 if ( pilot_isPlayer( p ) )
5610 if ( p->ai == NULL )
5611 return NLUA_ERROR( L, _(
"Pilot '%s' does not have an AI!" ), p->name );
5612 lua_rawgeti( L, LUA_REGISTRYINDEX, p->lua_mem );
5628 if ( p->lua_ship_mem == LUA_NOREF ) {
5629 lua_newtable(
naevL );
5630 p->lua_ship_mem = luaL_ref(
naevL, LUA_REGISTRYINDEX );
5632 lua_rawgeti( L, LUA_REGISTRYINDEX, p->lua_ship_mem );
5646 if ( p->ai == NULL )
5648 lua_pushstring( L, p->ai->name );
5665 lua_pushstring( L, t->
name );
5666 if ( t->
dat != LUA_NOREF ) {
5667 lua_rawgeti( L, LUA_REGISTRYINDEX, t->
dat );
5689 lua_pushstring( L, t->
name );
5691 lua_pushstring( L, t->
subtask->name );
5712 for (
Task *t = p->task; t != NULL; t = t->
next ) {
5715 lua_pushstring( L, t->name );
5716 lua_rawseti( L, -2, n++ );
5733 if ( t && ( t->
dat != LUA_NOREF ) ) {
5734 lua_rawgeti( L, LUA_REGISTRYINDEX, t->
dat );
5768 const char *task = luaL_checkstring( L, 2 );
5770 if ( pilot_isPlayer( p ) && !pilot_isFlag( p, PILOT_MANUAL_CONTROL ) )
5774 if ( !lua_isnoneornil( L, 3 ) ) {
5775 lua_pushvalue( L, 3 );
5776 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
5796 L, _(
"Trying to pop task when there are no tasks on the stack." ) );
5813 double amount = luaL_optinteger( L, 3, 100 );
5814 pilot_rmFlag( p, PILOT_HYP_PREP );
5815 pilot_rmFlag( p, PILOT_HYP_BRAKE );
5816 pilot_rmFlag( p, PILOT_HYP_BEGIN );
5817 pilot_setFlag( p, PILOT_REFUELING );
5819 p->refuel_amount = amount;
5831 if ( !pilot_isFlag( p, PILOT_MANUAL_CONTROL ) ) {
5832 NLUA_ERROR( L, _(
"Pilot '%s' is not on manual control." ), p->name );
5839 NLUA_ERROR( L, _(
"Failed to create new task for pilot '%s'." ),
5873 int brake, compensate;
5879 if ( lua_isnone( L, 3 ) )
5882 brake = lua_toboolean( L, 3 );
5883 if ( lua_isnone( L, 4 ) )
5886 compensate = lua_toboolean( L, 4 );
5893 tsk =
"moveto_nobrake";
5895 tsk =
"moveto_nobrake_raw";
5899 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
5933 towards = lua_toboolean( L, 3 );
5945 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
5988 accurate = lua_toboolean( L, 3 );
5991 if ( accurate == 0 )
5997 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6024 if ( !lua_isnoneornil( L, 2 ) ) {
6036 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6065 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6094 if ( lua_isnoneornil( L, 3 ) ) {
6097 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6099 if ( lua_isboolean( L, 3 ) ) {
6100 int nojump = lua_toboolean( L, 3 );
6102 pilotL_newtask( L, p, ( nojump ) ?
"runaway_nojump" :
"runaway" );
6104 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6110 lua_rawseti( L, -2, 1 );
6112 lua_rawseti( L, -2, 2 );
6113 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6119 lua_rawseti( L, -2, 1 );
6121 lua_rawseti( L, -2, 2 );
6122 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6124 NLUA_INVALID_PARAMETER( L, 3 );
6141 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6188 noshoot = lua_toboolean( L, 3 );
6201 if ( jp->target != ss )
6205 if ( jp_isFlag( jp, JP_EXITONLY ) )
6207 L, _(
"Pilot '%s' can't jump out exit only jump '%s'" ), p->name,
6212 lj.
destid = jp->targetid;
6214 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6218 return NLUA_ERROR( L,
6219 _(
"System '%s' is not adjacent to current system '%s'" ),
6237 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6290 if ( lua_isnoneornil( L, 2 ) )
6294 noshoot = lua_toboolean( L, 3 );
6302 if ( pnt != NULL ) {
6311 return NLUA_ERROR( L, _(
"Spob '%s' not found in system '%s'" ),
6315 if ( p->id == PLAYER_ID )
6319 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
6344 if ( lua_isnone( L, 2 ) )
6347 enable = lua_toboolean( L, 2 );
6356 pilot_setFlag( p, PILOT_HAILING );
6359 pilot_rmFlag( p, PILOT_HAILING );
6382 if ( lua_isnoneornil( L, 1 ) )
6386 type = luaL_checkstring( L, 3 );
6387 data = lua_gettop( L ) > 3 ? 4 : 0;
6389 if ( !lua_istable( L, 2 ) ) {
6394 while ( lua_next( L, 2 ) != 0 ) {
6416 if ( p->dockpilot != 0 ) {
6418 if ( ( l == NULL ) || pilot_isFlag( l, PILOT_DEAD ) ) {
6437 if ( p->parent != 0 ) {
6439 if ( ( l == NULL ) || pilot_isFlag( l, PILOT_DEAD ) ) {
6466 if ( prev_leader != NULL ) {
6470 if ( e->
id != p->id )
6472 if ( e->
type != ESCORT_TYPE_MERCENARY )
6475 _(
"Trying to change the leader of pilot '%s' that is a "
6476 "deployed fighter or part of the player fleet!" ),
6483 NLUA_WARN( L, _(
"Pilot '%s' not found in followers of '%s'" ),
6484 p->name, prev_leader->
name );
6488 if ( lua_isnoneornil( L, 2 ) ) {
6495 if ( p->id == leader->
id )
6497 L, _(
"Trying to set pilot '%s' to be their own leader!" ),
6500 if ( ( leader->
parent != 0 ) && ( leader->
parent != p->id ) ) {
6502 if ( leader_leader != NULL )
6503 leader = leader_leader;
6506 p->parent = leader->
id;
6510 if ( dockslot != NULL ) {
6521 for (
int i =
array_size( p->escorts ) - 1; i >= 0; i-- ) {
6522 const Escort_t *e = &p->escorts[i];
6524 if ( e->
type != ESCORT_TYPE_MERCENARY )
6535 if ( pe->
id == p->parent ) {
6564 int ignorefighters = lua_toboolean( L, 2 );
6568 for (
int i = 0; i <
array_size( p->escorts ); i++ ) {
6571 if ( ( pe == NULL ) || pilot_isFlag( pe, PILOT_DEAD ) ||
6572 pilot_isFlag( pe, PILOT_HIDE ) )
6575 if ( ignorefighters && pilot_isFlag( pe, PILOT_CARRIED ) )
6579 lua_rawseti( L, -2, idx++ );
6603 return poly_view( &p->ship->polygon, p->solid.dir );
6623 poly_rotate( &rpoly, &a->polygon->views[0], (
float)a->ang );
6624 int ret =
CollidePolygon( getCollPoly( p ), &p->solid.pos, &rpoly,
6625 &a->sol.pos, &crash );
6637 if ( pilot_isFlag( t, PILOT_INVINCIBLE ) )
6641 if ( pilot_isFlag( t, PILOT_LANDING ) || pilot_isFlag( t, PILOT_TAKEOFF ) ||
6642 pilot_isFlag( t, PILOT_NONTARGETABLE ) )
6649 int ret =
CollidePolygon( getCollPoly( p ), &p->solid.pos, getCollPoly( t ),
6677 dmg.
damage = luaL_checknumber( L, 2 );
6678 dmg.
disable = luaL_optnumber( L, 3, 0. );
6679 dmg.
penetration = luaL_optnumber( L, 4, 0. ) / 100.;
6681 parent = ( lua_isnoneornil( L, 6 ) ) ? NULL :
luaL_validpilot( L, 6 );
6683 damage =
pilot_hit( p, NULL, parent, &dmg, NULL, LUA_NOREF, 1 );
6684 if ( parent != NULL )
6687 lua_pushnumber( L, damage );
6741 e = luaL_optnumber( L, 3, 1. );
6744 m2 = luaL_checknumber( L, 2 );
6746 x2 = luaL_optvector( L, 4, x1 );
6747 e = luaL_optnumber( L, 5, 1. );
6752 double vx = ( m1 * v1->x + m2 * v2->x ) / ( m1 + m2 );
6753 double vy = ( m1 * v1->y + m2 * v2->y ) / ( m1 + m2 );
6754 vec2_cset( &p1->
solid.
vel, vx, vy );
6756 vec2_cset( &p2->
solid.
vel, vx, vy );
6761 double norm =
pow2( x1->
x - x2->
x ) +
pow2( x1->
y - x2->
y );
6762 double a1 = -e * ( 2. * m2 ) / ( m1 + m2 );
6764 a1 *= ( ( v1->x - v2->x ) * ( x1->
x - x2->
x ) +
6765 ( v1->y - v2->y ) * ( x1->
y - x2->
y ) ) /
6768 vec2_cadd( &p1->
solid.
vel, a1 * ( x1->
x - x2->
x ), a1 * ( x1->
y - x2->
y ) );
6770 double a2 = -e * ( 2. * m1 ) / ( m2 + m1 );
6772 a2 *= ( ( v2->x - v1->x ) * ( x2->
x - x1->
x ) +
6773 ( v2->y - v1->y ) * ( x2->
y - x1->
y ) ) /
6775 vec2_cadd( &p2->
solid.
vel, a2 * ( x2->
x - x1->
x ),
6776 a2 * ( x2->
y - x1->
y ) );
6782 double vx = ( m1 * v1->x + m2 * v2->x ) / ( m1 + m2 );
6783 double vy = ( m1 * v1->y + m2 * v2->y ) / ( m1 + m2 );
6784 vec2_cset( &p1->
solid.
vel, e * v1->
x + ( 1. - e ) * vx,
6785 e * v1->y + ( 1. - e ) * vy );
6787 vec2_cset( &p2->
solid.
vel, e * v2->
x + ( 1. - e ) * vx,
6788 e * v2->y + ( 1. - e ) * vy );
6812 if ( spob_hasService( spb, SPOB_SERVICE_INHABITED ) &&
6823 if ( ( pi->
ai == NULL ) || ( pi->
id == p->id ) ||
6824 ( pilot_isFlag( pi, PILOT_DEAD ) ) ||
6825 ( pilot_isFlag( pi, PILOT_DELETE ) ) )
6833 double d = vec2_dist2( &p->solid.pos, &pi->
solid.
pos );
6872 const char *str = luaL_checkstring( L, 2 );
6890 const char *str = luaL_checkstring( L, 2 );
6892 if ( p->shipvar == NULL )
6908 const char *str = luaL_checkstring( L, 2 );
6921 int size = luaL_optinteger( L, 2, 512 );
6923 ship_gfxComm( p->ship, size, p->tilt, p->solid.dir, &L_default );
6924 if ( tex == NULL ) {
6925 NLUA_WARN( L, _(
"Unable to get ship comm graphic for '%s'." ),
6950 if ( canvas_new( &lc, w, h ) )
6951 return NLUA_ERROR( L, _(
"Error setting up framebuffer!" ) );
6958 eg = p->engine_glow;
6959 p->engine_glow = ( eg > 0.5 ) ? 1.0 : 0.0;
6961 p->engine_glow = eg;
6963 lua_pushcanvas( L, lc );
6986 if ( ( lc->
tex->
w < w ) || ( lc->
tex->
h < h ) )
6989 _(
"Canvas is too small to fully render '%s': %.0f x %.0f < %d x %d" ),
6990 p->name, lc->
tex->
w, lc->
tex->
h, w, h );
6997 eg = p->engine_glow;
6998 p->engine_glow = ( eg > 0.5 ) ? 1.0 : 0.0;
7000 p->engine_glow = eg;
7002 lua_pushnumber( L, w );
7003 lua_pushnumber( L, h );
Task * ai_newtask(lua_State *L, Pilot *p, const char *func, int subtask, int pos)
Creates a new AI task.
Task * ai_curTask(Pilot *pilot)
Gets the current running task.
void ai_refuel(Pilot *refueler, unsigned int target)
Has a pilot attempt to refuel the other.
void ai_cleartasks(Pilot *p)
Clears the pilot's tasks.
void ai_getDistress(const Pilot *p, const Pilot *distressed, const Pilot *attacker)
Sends a distress signal to a pilot.
void ai_destroy(Pilot *p)
Destroys the ai part of the pilot.
int ai_pinit(Pilot *p, const char *ai)
Initializes the pilot in the ai.
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_copy(basic_type, ptr_array)
Returns a shallow copy of the input array.
#define array_end(array)
Returns a pointer to the end of the reserved memory space.
#define array_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_begin(array)
Returns a pointer to the beginning of the reserved memory space.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void cam_update(double dt)
Updates the camera.
void poly_rotate(CollPolyView *rpolygon, const CollPolyView *ipolygon, float theta)
Rotates a polygon.
int CollidePolygon(const CollPolyView *at, const vec2 *ap, const CollPolyView *bt, const vec2 *bp, vec2 *crash)
Checks whether or not two polygons collide. /!\ The function is not symmetric: the points of polygon ...
int dtype_get(const char *name)
Gets the id of a dtype based on name.
const char * dtype_damageTypeToStr(int type)
Gets the human readable string from damage type.
int effect_rmType(Effect **efxlist, const EffectData *efx, int all)
Removes an effect type from an effect list.
int effect_rm(Effect **efxlist, int idx)
Removes an effect from an effect list by index.
int effect_add(Effect **efxlist, const EffectData *efx, double duration, double strength, unsigned int parent)
Adds an effect to an effect list.
void effect_clearSpecific(Effect **efxlist, int debuffs, int buffs, int others)
Clears specific types of effects.
const EffectData * effect_get(const char *name)
Gets an effect by name.
void effect_clear(Effect **efxlist)
Clears an effect list, removing all active effects.
int escort_addList(Pilot *p, const Ship *ship, EscortType_t type, unsigned int id, int persist)
Adds an escort to the escort list of a pilot.
void escort_rmListIndex(Pilot *p, int i)
Remove from escorts list.
int areEnemies(int a, int b)
Checks whether two factions are enemies.
int areAllies(int a, int b)
Checks whether two factions are allies or not.
void gui_setShip(void)
Player just upgraded their ship or modified it.
void gui_setNav(void)
Player just changed their nav computer target.
void player_message(const char *fmt,...)
Adds a mesg to the queue to be displayed on screen.
void outfits_updateEquipmentOutfits(void)
Updates the outfitter and equipment outfit image arrays.
int lvar_addArray(lvar **arr, const lvar *new_var, int sort)
Adds a var to a var array.
void lvar_rmArray(lvar **arr, lvar *rm_var)
Removes a var from a var array.
lvar * lvar_get(const lvar *arr, const char *str)
Gets a lua var by name.
lvar lvar_tovar(lua_State *L, const char *name, int idx)
Gets a lua variable from an index from a lua state.
int lvar_push(lua_State *L, const lvar *v)
Pushes a lua var to a lua state.
Header file with generic functions and naev-specifics.
int nlua_loadAsteroid(nlua_env env)
Loads the asteroid library.
int lua_isasteroid(lua_State *L, int ind)
Checks to see if ind is a asteroid.
LuaAsteroid_t * luaL_checkasteroid(lua_State *L, int ind)
Gets asteroid at index or raises error if there is no asteroid at index.
LuaAsteroid_t * lua_pushasteroid(lua_State *L, LuaAsteroid_t asteroid)
Pushes a asteroid on the stack.
Asteroid * luaL_validasteroid(lua_State *L, int ind)
Gets asteroid at index raising an error if type doesn't match.
glColour * lua_pushcolour(lua_State *L, glColour colour)
Pushes a colour on the stack.
Commodity ** lua_pushcommodity(lua_State *L, Commodity *commodity)
Pushes a commodity on the stack.
Commodity * luaL_validcommodity(lua_State *L, int ind)
Makes sure the commodity is valid or raises a Lua error.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
LuaFaction luaL_validfaction(lua_State *L, int ind)
Gets faction (or faction name) at index, raising an error if type isn't a valid faction.
int lua_isfaction(lua_State *L, int ind)
Checks to see if ind is a faction.
LuaFaction lua_tofaction(lua_State *L, int ind)
Gets faction at index.
LuaJump * luaL_checkjump(lua_State *L, int ind)
Gets jump at index raising an error if isn't a jump.
LuaJump * lua_pushjump(lua_State *L, LuaJump jump)
Pushes a jump on the stack.
int lua_isjump(lua_State *L, int ind)
Checks to see if ind is a jump.
LuaJump * lua_tojump(lua_State *L, int ind)
This module allows you to handle the jumps from Lua.
const Outfit * luaL_validoutfit(lua_State *L, int ind)
Makes sure the outfit is valid or raises a Lua error.
const Outfit ** lua_pushoutfit(lua_State *L, const Outfit *outfit)
Pushes a outfit on the stack.
static int pilotL_setVisible(lua_State *L)
Marks the pilot as always visible for other pilots.
static int pilotL_weapsetAmmo(lua_State *L)
Gets the ammo left of a weapon set.
static int pilotL_setHealthAbs(lua_State *L)
Sets the health of a pilot in absolute value.
static int pilotL_intrinsicGet(lua_State *L)
Allows getting an intrinsic stats of a pilot, or gets all of them if name is not specified.
static int pilotL_getVisible(lua_State *L)
Gets visible pilots to a pilot.
static int pilotL_isStopped(lua_State *L)
Checks to see if a pilot is stopped.
static int pilotL_clone(lua_State *L)
Clones a pilot. It will share nearly all properties including outfits.
static int pilotL_setHide(lua_State *L)
Sets the pilot's hide status.
static int pilotL_calcStats(lua_State *L)
Forces a recomputation of the pilots' stats.
static int pilotL_weapsetAddType(lua_State *L)
Adds an outfit to a pilot's weapon set.
static int pilotL_refuel(lua_State *L)
Tries to refuel a pilot.
static int pilotL_eq(lua_State *L)
Checks to see if pilot and p are the same.
static int pilotL_moveto(lua_State *L)
Makes the pilot move to a position.
static int pilotL_hailPlayer(lua_State *L)
Marks the pilot as hailing the player.
static int pilotL_setEnergy(lua_State *L)
Sets the energy of a pilot.
static int pilotL_setFriendly(lua_State *L)
Controls the pilot's friendliness towards the player.
static int pilotL_cargoJet(lua_State *L)
Tries to remove a cargo from a pilot's ship and jet it into space.
static int pilotL_outfitRm(lua_State *L)
Removes an outfit from a pilot.
static int pilotL_outfitRmIntrinsic(lua_State *L)
Removes an intrinsic outfit from the pilot.
static int pilotL_actives(lua_State *L)
Gets the active outfits and their states of the pilot.
static int pilotL_cargoFree(lua_State *L)
Gets the free cargo space the pilot has.
static int pilotL_weapsetRm(lua_State *L)
Removes an outfit from a pilot's weapon set.
static int pilotL_setNoLand(lua_State *L)
Enables or disables landing for a pilot.
static int pilotL_targetAsteroid(lua_State *L)
Gets the asteroid target of the pilot.
static int pilotL_setActiveBoard(lua_State *L)
Allows the pilot to be boarded when not disabled.
static int pilotL_brake(lua_State *L)
Makes the pilot brake.
static int pilotL_withPlayer(lua_State *L)
Checks to see if pilot is with player.
static int pilotL_canHyperspace(lua_State *L)
Checks to see if the pilot can currently hyperspace (as in has target jump and is in range).
static int pilotL_spaceworthy(lua_State *L)
Checks the pilot's spaceworthiness.
static int pilotL_render(lua_State *L)
Renders the pilot to a canvas.
static int pilotL_runaway(lua_State *L)
Makes the pilot runaway from another pilot.
static int pilotL_land(lua_State *L)
Tells the pilot to land.
static int pilotL_weapsetList(lua_State *L)
Get a list of all the outfits in a weapon set.
LuaPilot lua_topilot(lua_State *L, int ind)
Lua bindings to interact with pilots.
static int pilotL_memory(lua_State *L)
Gets a pilots memory table.
LuaPilot * lua_pushpilot(lua_State *L, LuaPilot pilot)
Pushes a pilot on the stack.
static int pilotL_choosePoint(lua_State *L)
Returns a suitable jumpin spot for a given pilot. Lua usage parameter: point = pilot....
static int pilotL_setNoClear(lua_State *L)
Enables or disables making the the pilot exempt from pilot.clear().
static int pilotL_canSpawn(lua_State *L)
Returns if pilots can can spawn naturally in the current system.
static int pilotL_setNoJump(lua_State *L)
Enables or disables a pilot's hyperspace engine.
static int pilotL_setLeader(lua_State *L)
Set a pilots leader.
static int pilotL_taskclear(lua_State *L)
Clears all the tasks of the pilot.
static int pilotL_nav(lua_State *L)
Gets the nav target of the pilot.
static int pilotL_credits(lua_State *L)
Handles the pilots credits.
static int pilotL_weapsetAuto(lua_State *L)
Makes the pilot's weapons get automatically set.
static int pilotL_taskdata(lua_State *L)
Gets the data of the task the pilot is currently doing.
static int pilotL_setInvisible(lua_State *L)
Sets the pilot's invisibility status.
static int pilotL_exists(lua_State *L)
Checks to see if pilot is still in the system and alive.
static int pilotL_disabled(lua_State *L)
Gets the disabled state of a pilot.
static int pilotL_hasIllegal(lua_State *L)
Checks to see if the pilot has illegal stuff to a faction.
static int pilotL_setTemp(lua_State *L)
Sets the temperature of a pilot.
static int pilotL_clearSelect(lua_State *L)
Removes all pilots belonging to a faction from the system.
static int pilotL_outfitRmSlot(lua_State *L)
Removes an outfit from a pilot's named slot.
Pilot * luaL_validpilot(lua_State *L, int ind)
Makes sure the pilot is valid or raises a Lua error.
static int pilotL_tostring(lua_State *L)
Gets the pilot's current (translated) name or notes it is inexistent.
static int pilotL_toggleSpawn(lua_State *L)
Disables or enables pilot spawning in the current system.
static int pilotL_getEnergy(lua_State *L)
Gets the pilot's energy.
static int pilotL_points(lua_State *L)
Gets the points the pilot costs.
static int pilotL_weapsetType(lua_State *L)
Sets the type of a weapon set for a pilot.
static int pilotL_getShield(lua_State *L)
Gets the pilot's shield.
static int pilotL_msg(lua_State *L)
Sends a message to another pilot.
static int pilotL_setBribed(lua_State *L)
Makes pilot act as if bribed by the player.
static int pilotL_cargoRm(lua_State *L)
Tries to remove cargo from the pilot's ship.
static int pilotL_knockback(lua_State *L)
Knocks back a pilot. It can either accept two pilots, or a pilot and an element represented by mass,...
static int pilotL_hookClear(lua_State *L)
Clears the pilot's hooks.
static int pilotL_setNoRender(lua_State *L)
Sets the pilot's norender status.
static int pilotL_taskname(lua_State *L)
Gets the name of the task the pilot is currently doing.
static int pilotL_intrinsicReset(lua_State *L)
Resets the intrinsic stats of a pilot.
static int pilotL_pushtask(lua_State *L)
Pushes a new task to the pilot's AI.
static int pilotL_mothership(lua_State *L)
Gets a pilots mothership (only exists for deployed pilots). Guaranteed to exist or will be nil.
static int pilotL_getHealth(lua_State *L)
Gets the pilot's health.
static int pilotL_cargoAdd(lua_State *L)
Tries to add cargo to the pilot's ship.
static int pilot_outfitAddSlot(Pilot *p, const Outfit *o, PilotOutfitSlot *s, int bypass_cpu, int bypass_slot)
Adds an outfit to a specific slot.
static int pilotL_damage(lua_State *L)
Damages a pilot.
static int pilotL_ai(lua_State *L)
Gets the pilot's AI.
static int pilotL_shippropGet(lua_State *L)
Allows getting an ship property stats of a pilot, or gets all of them if name is not specified.
static int pilotL_cooldownCycle(lua_State *L)
Makes the pilot do an instant full cooldown cycle.
static int pilotL_velocity(lua_State *L)
Gets the pilot's velocity.
static int pilotL_weapsetSetInrange(lua_State *L)
Sets whether a pilot's weapon set does inrange checks.
static int pilotL_reputation(lua_State *L)
Get the reputation the player has with the pilot's faction.
static int pilotL_comm(lua_State *L)
Sends a message to the target or player if no target is passed.
static int pilotL_tryStealth(lua_State *L)
Tries to make the pilot stealth.
static int pilotL_fillAmmo(lua_State *L)
Fills up the pilot's ammo.
static const luaL_Reg pilotL_methods[]
static int pilotL_setHealth(lua_State *L)
Sets the health of a pilot.
static int pilotL_getInrange(lua_State *L)
Gets visible pilots to a pilot within a certain distance.
static int pilotL_changeAI(lua_State *L)
Changes the pilot's AI.
static int pilotL_setTarget(lua_State *L)
Sets the pilot target of the pilot.
static int pilotL_getEnemies(lua_State *L)
Gets hostile pilots to a pilot (or faction) within a certain distance.
static int pilotL_name(lua_State *L)
Gets the pilot's current (translated) name.
static int pilotL_getColour(lua_State *L)
Gets the pilot's colour based on hostility or friendliness to the player.
static int pilotL_scandone(lua_State *L)
Checks to see if a pilot is done scanning its target.
static Task * pilotL_newtask(lua_State *L, Pilot *p, const char *task)
Does a new task.
static int pilotL_shipvarPeek(lua_State *L)
Peeks at a ship variable.
static int pilotL_getShipStat(lua_State *L)
Gets a shipstat from a Pilot by name, or a table containing all the ship stats if not specified.
static int pilotL_setNoDisable(lua_State *L)
Sets the ability of the pilot to be disabled.
static int pilotL_colourChar(lua_State *L)
Gets the pilot's colour character based on hostility or friendliness to the player....
static int pilotL_cargoHas(lua_State *L)
Checks to see how many tonnes of a specific type of cargo the pilot has.
static int pilotL_setFuel(lua_State *L)
Sets the fuel of a pilot.
static int pilotL_stealth(lua_State *L)
Tells the pilot to try to stealth.
static int pilotL_navJump(lua_State *L)
Gets the nav jump target of the pilot.
static int pilotL_outfits(lua_State *L)
Gets a mapping of outfit slot IDs and outfits of a pilot.
static int pilotL_outfitSlot(lua_State *L)
Checks to see outfit a pilot has in a slot.
static int pilotL_outfitsList(lua_State *L)
Gets the outfits of a pilot.
static int pilotL_ainame(lua_State *L)
Gets the name of the task the pilot is currently doing.
static int outfit_compareActive(const void *slot1, const void *slot2)
qsort compare function for active outfits.
static int pilotL_shipvarPop(lua_State *L)
Pops a ship variable.
static int pilotL_setCooldown(lua_State *L)
Starts or stops a pilot's cooldown mode.
static int pilotL_face(lua_State *L)
Makes the pilot face a target.
static int pilotL_clear(lua_State *L)
Clears the current system of pilots. Used for epic battles and such.
static int pilotL_shippropSet(lua_State *L)
Allows setting ship property stats of a pilot.
static int pilotL_rename(lua_State *L)
Changes the pilot's name.
static int pilotL_getStress(lua_State *L)
Gets the pilot's stress.
static int pilotL_mass(lua_State *L)
Gets the mass of a pilot.
static int pilotL_navSpob(lua_State *L)
Gets the nav spob target of the pilot.
static const struct pL_flag pL_flags[]
static int pilotL_collisionTest(lua_State *L)
Tests to see if two ships collide.
static int pilotL_setHostile(lua_State *L)
Controls the pilot's hostility towards the player.
static int pilotL_outfitsEquip(lua_State *L)
Equips a pilot with a set of outfits.
static int pilotL_getAllies(lua_State *L)
Gets friendly pilots to a pilot (or faction) within a certain distance.
static int pilotL_dir(lua_State *L)
Gets the pilot's direction.
static int pilotL_setPosition(lua_State *L)
Sets the pilot's position.
static int pilotL_attack(lua_State *L)
Makes the pilot attack another pilot.
static int pilotL_setFlagWrapper(lua_State *L, int flag)
Wrapper to simplify flag setting stuff.
int nlua_loadPilot(nlua_env env)
Loads the pilot library.
static int pilotL_getArmour(lua_State *L)
Gets the pilot's armour.
static int pilotL_setSpeedLimit(lua_State *L)
Limits the speed of a pilot.
static int pilotL_navJumpSet(lua_State *L)
Sets the hyperspace navigation target for the pilot.
static int pilotL_weapsetCleanup(lua_State *L)
Cleans up a weapon set. This removes all properties of the weapon set and resets it.
static int pilotL_control(lua_State *L)
Sets manual control of the pilot.
static int pilotL_followers(lua_State *L)
Get all of a pilots followers.
static int pilotL_autoweap(lua_State *L)
Gets if a pilot is using automatically set weapon sets.
static int pilotL_outfitToggle(lua_State *L)
Toggles an outfit.
static int pilotL_setNoBoard(lua_State *L)
Sets the ability to board the pilot.
static int pilotL_leader(lua_State *L)
Gets a pilots leader. Guaranteed to exist or will be nil.
static int pilotL_outfitGet(lua_State *L)
Gets a pilot's outfit by ID.
static int pilotL_temp(lua_State *L)
Gets the temperature of a pilot.
static int pilotL_getFuel(lua_State *L)
Gets the amount of fuel the pilot has.
static int pilotL_destealth(lua_State *L)
Tries to make the pilot stealth.
static int pilotL_effectHas(lua_State *L)
Checks to see if a player has an instance of an effect active. Lua function parameter: Pilot p Pilot ...
static int pilotL_weapsetHeat(lua_State *L)
Gets heat information for a weapon set.
static int pilotL_setHilight(lua_State *L)
Makes pilot stand out on radar and the likes.
static int pilotL_shipvarPush(lua_State *L)
Pushes a ship variable.
static int pilotL_areAllies(lua_State *L)
Checks to see if two pilots are allies.
static int pilotL_outfitAddIntrinsic(lua_State *L)
Adds an intrinsic outfit to the pilot.
static int pilotL_addHealth(lua_State *L)
Adds health to a pilot.
static int pilotL_getLockon(lua_State *L)
Gets the lockons on the pilot.
static int pilotL_radius(lua_State *L)
Gets the rough radius of the ship, useful for collision stuff.
static int pilotL_getDetectedDistance(lua_State *L)
Gets the distance that a pilot can be currently detect at.
static int pilotL_effectRm(lua_State *L)
Removes an effect from the pilot.
static int pilotL_setDisable(lua_State *L)
Disables a pilot.
static int pilotL_remove(lua_State *L)
Removes a pilot without explosions or anything.
static int pilotL_intrinsicSet(lua_State *L)
Allows setting intrinsic stats of a pilot.
static int pilotL_kill(lua_State *L)
Kills a pilot.
static int pilotL_setFaction(lua_State *L)
Sets the pilot's faction.
static int pilotL_worth(lua_State *L)
Gets the worth of a pilot (total value of ship and outfits).
int lua_ispilot(lua_State *L, int ind)
Checks to see if ind is a pilot.
static int pilotL_outfitReady(lua_State *L)
Sees if an outfit is ready to use.
static int pilotL_signature(lua_State *L)
Gets the pilot's signature.
static int pilotL_position(lua_State *L)
Gets the pilot's position.
static int pilotL_explode(lua_State *L)
Removes a pilot as if it exploded.
static int pilotL_renderComm(lua_State *L)
Renders the pilot communication image.
static int pilotL_getStats(lua_State *L)
Gets stats of the pilot.
static int pilotL_poptask(lua_State *L)
Pops the current task from the pilot's AI.
static int pilotL_gather(lua_State *L)
Makes the pilot gather stuff.
static int pilotL_setInvincPlayer(lua_State *L)
Sets the pilot's invincibility status towards the player.
static int pilotL_cargoList(lua_State *L)
Lists the cargo the pilot has.
static int pilotL_setNoDeath(lua_State *L)
Makes it so the pilot never dies, stays at 1. armour.
static int pilotL_speed_max(lua_State *L)
Gets the maximum speed of a pilot.
static int pilotL_id(lua_State *L)
Gets the ID of the pilot. Guaranteed to be unique per pilot and not repeating over time (with the exc...
static int pilotL_getHostile(lua_State *L)
Returns whether the pilot is hostile to the player.
static int pilotL_board(lua_State *L)
Makes the pilot board another pilot.
static int pilotL_broadcast(lua_State *L)
Makes the pilot broadcast a message.
static int pilotL_cooldown(lua_State *L)
Gets a pilot's cooldown state.
static int pilotL_setDir(lua_State *L)
Sets the pilot's direction.
static int pilotL_weapsetAdd(lua_State *L)
Adds an outfit to a pilot's weapon set.
static int pilotL_accel(lua_State *L)
Gets the accel of a pilot.
static int pilotL_task(lua_State *L)
Gets the name and data of a pilot's current task.
static int pilotL_distress(lua_State *L)
Sends a distress single from the pilot.
static int pilotL_shipmemory(lua_State *L)
Gets a pilots ship memory table.
static int weapsetItem(lua_State *L, int *k, Pilot *p, const PilotOutfitSlot *slot, const Pilot *target)
Sets up an item in a weapon set.
static int pilotL_areEnemies(lua_State *L)
Checks to see if two pilots are enemies.
static int pilotL_setVelocity(lua_State *L)
Sets the pilot's velocity.
static int pilotL_taskstack(lua_State *L)
Gets the name of all the pilot's current tasks (not subtasks).
static int pilotL_inrange(lua_State *L)
Checks to see if a target pilot is in range of a pilot.
static int pilotL_setInvincible(lua_State *L)
Sets the pilot's invincibility status.
LuaPilot luaL_checkpilot(lua_State *L, int ind)
Gets pilot at index or raises error if there is no pilot at index.
static int pilotL_outfitAdd(lua_State *L)
Adds an outfit to a pilot.
static int pilotL_follow(lua_State *L)
Makes the pilot follow another pilot.
static int pilotL_effectAdd(lua_State *L)
Adds an effect to a pilot.
static int pilotL_outfitAddSlot(lua_State *L)
Adds an outfit to a pilot by slot name.
static int pilotL_ship(lua_State *L)
Gets the pilot's ship.
static int pilotL_flags(lua_State *L)
Gets the pilot's flags.
static int pilotL_addEnergy(lua_State *L)
Adds (or subtracts) energy to a pilot.
static int pilotL_hyperspace(lua_State *L)
Tells the pilot to hyperspace.
static int pilotL_speed(lua_State *L)
Gets the speed of a pilot.
static int pilotL_getPilots(lua_State *L)
Gets the pilots available in the system by a certain criteria.
static int pilotL_setVisplayer(lua_State *L)
Marks the pilot as always visible for the player.
static int pilotL_effectGet(lua_State *L)
Gets the effects on a pilot.
static int pilotL_faction(lua_State *L)
Gets the pilot's faction.
static int pilotL_shippropReset(lua_State *L)
Resets the ship property stats of a pilot.
static int pilotL_setTargetAsteroid(lua_State *L)
Sets the pilot's asteroid target.
static int pilotL_renderTo(lua_State *L)
Renders the pilot to a canvas.
static int pilotL_target(lua_State *L)
Gets the pilot target of the pilot.
static int pilotL_weapset(lua_State *L)
Gets the weapset weapon of the pilot.
static int pilotL_idle(lua_State *L)
Checks to see if the pilot is idle.
static int pilotL_effectClear(lua_State *L)
Clears the effect on a pilot.
static int pilotL_add(lua_State *L)
Adds a ship with an AI and faction to the system (instead of a predefined fleet).
static int pilotL_turn(lua_State *L)
Gets the turn of a pilot.
const Ship ** lua_pushship(lua_State *L, const Ship *ship)
Pushes a ship on the stack.
int nlua_loadShip(nlua_env env)
Loads the ship library.
const Ship * luaL_validship(lua_State *L, int ind)
Makes sure the ship is valid or raises a Lua error.
LuaSpob lua_tospob(lua_State *L, int ind)
This module allows you to handle the spobs from Lua.
LuaSpob * lua_pushspob(lua_State *L, LuaSpob spob)
Pushes a spob on the stack.
Spob * luaL_validspob(lua_State *L, int ind)
Gets a spob directly.
int lua_isspob(lua_State *L, int ind)
Checks to see if ind is a spob.
LuaSystem * lua_pushsystem(lua_State *L, LuaSystem sys)
Pushes a system on the stack.
StarSystem * luaL_validsystem(lua_State *L, int ind)
Gets system (or system name) at index raising an error if type doesn't match.
LuaSystem lua_tosystem(lua_State *L, int ind)
Lua system module.
int lua_issystem(lua_State *L, int ind)
Checks to see if ind is a system.
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
int lua_isvector(lua_State *L, int ind)
Checks to see if ind is a vector.
vec2 * luaL_checkvector(lua_State *L, int ind)
Gets vector at index making sure type is valid.
vec2 * lua_tovector(lua_State *L, int ind)
Represents a 2D vector in Lua.
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
double ntime_convertSeconds(ntime_t t)
Converts the time to seconds.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
int outfit_isBeam(const Outfit *o)
Checks if outfit is a beam type weapon.
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.
const char * outfit_getTypeBroad(const Outfit *o)
Gets the outfit's broad type.
int outfit_fitsSlot(const Outfit *o, const OutfitSlot *s)
Checks to see if an outfit fits a slot.
int outfit_isFighterBay(const Outfit *o)
Checks if outfit is a fighter bay.
int outfit_isAfterburner(const Outfit *o)
Checks if outfit is an afterburner.
const char * outfit_getType(const Outfit *o)
Gets the outfit's specific type.
int outfit_isMod(const Outfit *o)
Checks if outfit is a ship modification.
const Damage * outfit_damage(const Outfit *o)
Gets the outfit's damage.
double outfit_duration(const Outfit *o)
Gets the outfit's duration.
double outfit_cooldown(const Outfit *o)
Gets the outfit's cooldown.
int outfit_isBolt(const Outfit *o)
Checks if outfit is bolt type weapon.
double outfit_delay(const Outfit *o)
Gets the outfit's delay.
int outfit_fitsSlotType(const Outfit *o, const OutfitSlot *s)
Checks to see if an outfit fits a slot type (ignoring size).
char pilot_getFactionColourChar(const Pilot *p)
Gets the faction colour char, works like faction_reputationColourChar but for a pilot.
void pilot_choosePoint(vec2 *vp, Spob **spob, JumpPoint **jump, int lf, int ignore_rules, int guerilla)
Finds a spawn point for a pilot.
int pilot_isHostile(const Pilot *p)
Checks to see if pilot is hostile to the player.
void pilot_updateDisable(Pilot *p, unsigned int shooter)
Handles pilot disabling. Set or unset the disable status depending on health and stress values.
void pilot_cooldown(Pilot *p, int dochecks)
Begins active cooldown, reducing hull and outfit temperatures.
void pilot_renderFramebuffer(Pilot *p, GLuint fbo, double fw, double fh, const Lighting *L)
Renders a pilot to a framebuffer.
void pilot_rmHostile(Pilot *p)
Unmarks a pilot as hostile to player.
int pilot_validEnemy(const Pilot *p, const Pilot *target)
Checks to see if a pilot is a valid enemy for another pilot.
int pilot_areEnemies(const Pilot *p, const Pilot *target)
Like areEnemies but for pilots.
void pilots_clear(void)
Clears all the pilots except the player and clear-exempt pilots.
Pilot * pilot_getTarget(Pilot *p)
Gets the target of a pilot using a fancy caching system.
void pilot_msg(const Pilot *p, const Pilot *receiver, const char *type, unsigned int idx)
Sends a message.
void pilot_dead(Pilot *p, unsigned int killer)
Pilot is dead, now will slowly explode.
void pilot_cooldownEnd(Pilot *p, const char *reason)
Terminates active cooldown.
credits_t pilot_modCredits(Pilot *p, credits_t amount)
Modifies the amount of credits the pilot has.
unsigned int pilot_getNearestEnemy(const Pilot *p)
Gets the nearest enemy to the pilot.
void pilot_setFriendly(Pilot *p)
Marks pilot as friendly to player.
int pilot_validTarget(const Pilot *p, const Pilot *target)
Checks to see if a pilot is a valid target for another pilot.
PilotOutfitSlot * pilot_getDockSlot(Pilot *p)
Gets the dock slot of the pilot.
int pilot_hasIllegal(const Pilot *p, int faction)
Checks to see if the pilot has illegal stuf to a faction.
void pilot_setCommMsg(Pilot *p, const char *s)
Sets the overhead communication message of the pilot.
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
ntime_t pilot_hyperspaceDelay(const Pilot *p)
Calculates the hyperspace delay for a pilot.
void pilot_broadcast(Pilot *p, const char *msg, int ignore_int)
Has the pilot broadcast a message.
void pilot_setHostile(Pilot *p)
Marks pilot as hostile to player.
const glColour * pilot_getColour(const Pilot *p)
Gets a pilot's colour.
static Pilot ** pilot_stack
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
int pilot_canTarget(const Pilot *p)
Same as pilot_validTarget but without the range check.
credits_t pilot_worth(const Pilot *p, int count_unique)
Gets the price or worth of a pilot in credits.
void pilot_rmFriendly(Pilot *p)
Unmarks a pilot as friendly to player.
int pilot_areAllies(const Pilot *p, const Pilot *target)
Like areAllies but for pilots.
int pilot_getJumps(const Pilot *p)
Gets the amount of jumps the pilot has left.
void pilot_delete(Pilot *p)
Deletes a pilot.
double pilot_hit(Pilot *p, const Solid *w, const Pilot *pshooter, const Damage *dmg, const Outfit *outfit, int lua_mem, int reset)
Damages the pilot.
Pilot * pilot_create(const Ship *ship, const char *name, int faction, const char *ai, const double dir, const vec2 *pos, const vec2 *vel, const PilotFlags flags, unsigned int dockpilot, int dockslot)
Creates a new pilot.
void pilot_sample_trails(Pilot *p, int none)
Updates the given pilot's trail emissions.
void pilot_setTarget(Pilot *p, unsigned int id)
Sets the target of the pilot.
unsigned int pilot_clone(const Pilot *ref)
Clones an existing pilot.
int pilot_cargoRmAll(Pilot *pilot, int cleanup)
Gets rid of all cargo from pilot. Can remove mission cargo.
int pilot_cargoFree(const Pilot *p)
Gets the pilot's free cargo space.
int pilot_cargoRm(Pilot *pilot, const Commodity *cargo, int quantity)
Tries to get rid of quantity cargo from pilot.
int pilot_cargoOwned(const Pilot *pilot, const Commodity *cargo)
Gets how many of the commodity a pilot has.
int pilot_cargoJet(Pilot *p, const Commodity *cargo, int quantity, int simulate)
Tries to get rid of quantity cargo from pilot, jetting it into space.
int pilot_cargoAdd(Pilot *pilot, const Commodity *cargo, int quantity, unsigned int id)
Tries to add quantity of cargo to pilot.
int pilot_inRangePilot(const Pilot *p, const Pilot *target, double *dist2)
Check to see if a pilot is in sensor range of another.
int pilot_ewScanCheck(const Pilot *p)
Checks to see if a scan is done.
int pilot_inRangeSpob(const Pilot *p, int target)
Check to see if a spob is in sensor range of the pilot.
void pilot_destealth(Pilot *p)
Destealths a pilot.
double pilot_ewWeaponTrack(const Pilot *p, const Pilot *t, double trackmin, double trackmax)
Calculates the weapon lead (1. is 100%, 0. is 0%)..
int pilot_inRangeAsteroid(const Pilot *p, int ast, int fie)
Check to see if an asteroid is in sensor range of the pilot.
double pilot_sensorRange(void)
Returns the default sensor range for the current system.
int pilot_inRange(const Pilot *p, double x, double y)
Check to see if a position is in range of the pilot.
int pilot_stealth(Pilot *p)
Stealths a pilot.
double pilot_heatEfficiencyMod(double T, double Tb, double Tc)
Returns a 0:1 modifier representing efficiency (1. being normal).
double pilot_heatFirePercent(double T)
Returns a 0:2 level of fire, 0:1 is the accuracy point, 1:2 is fire rate point.
void pilot_clearHooks(Pilot *p)
Clears the pilots hooks.
int pilot_runHook(Pilot *p, int hook_type)
Tries to run a pilot hook if he has it.
int pilot_rmOutfit(Pilot *pilot, PilotOutfitSlot *s)
Removes an outfit from the pilot.
void pilot_updateMass(Pilot *pilot)
Updates the pilot stats after mass change.
int pilot_maxAmmoO(const Pilot *p, const Outfit *o)
Gets the maximum available ammo for a pilot for a specific outfit.
void pilot_calcStats(Pilot *pilot)
Recalculates the pilot's stats based on his outfits.
void pilot_fillAmmo(Pilot *pilot)
Fills pilot's ammo completely.
int pilot_addAmmo(Pilot *pilot, PilotOutfitSlot *s, int quantity)
Adds some ammo to the pilot stock.
int pilot_rmOutfitRaw(Pilot *pilot, PilotOutfitSlot *s)
Removes an outfit from the pilot without doing any checks.
int pilot_outfitLInit(const Pilot *pilot, PilotOutfitSlot *po)
Runs the pilot's Lua outfits init script for an outfit.
PilotOutfitSlot * pilot_getSlotByName(Pilot *pilot, const char *name)
Gets the outfit slot by name.
int pilot_reportSpaceworthy(const Pilot *p, char *buf, int bufSize)
Pilot safety report - makes sure stats are safe.
int pilot_addOutfitTest(Pilot *pilot, const Outfit *outfit, const PilotOutfitSlot *s, int warn)
Tests to see if an outfit can be added.
int pilot_addOutfitRaw(Pilot *pilot, const Outfit *outfit, PilotOutfitSlot *s)
Adds an outfit to the pilot, ignoring CPU or other limits.
int pilot_rmOutfitIntrinsic(Pilot *pilot, const Outfit *outfit)
Removes an outfit from an intrinsic slot.
int pilot_addOutfitIntrinsic(Pilot *pilot, const Outfit *outfit)
Adds an outfit as an intrinsic slot.
void pilot_weapSetAdd(Pilot *p, int id, const PilotOutfitSlot *o)
Adds an outfit to a weapon set.
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.
void pilot_weapSetInrange(Pilot *p, int id, int inrange)
Changes the weapon set inrange property.
void pilot_weapSetCleanup(Pilot *p, int id)
Cleans up a weapon set.
void pilot_weapSetRm(Pilot *p, int id, const PilotOutfitSlot *o)
Removes a slot from a weapon set.
double pilot_weapSetAmmo(Pilot *p, int id)
Gets the ammo of the current pilot weapon set.
PilotWeaponSetOutfit * pilot_weapSetList(Pilot *p, int id)
Lists the items in a pilot weapon set.
void pilot_weapSetUpdateOutfitState(Pilot *p)
Updates the local state of all the pilot's outfits based on the weapon sets.
void pilot_weaponAuto(Pilot *p)
Tries to automatically set and create the pilot's weapon set.
const char * pilot_weapSetName(Pilot *p, int id)
Gets the name of a weapon set.
void pilot_weapSetType(Pilot *p, int id, WeaponSetType type)
Changes the weapon sets mode.
void player_hailStart(void)
Starts the hail sounds and aborts autoNav.
void player_targetSet(unsigned int id)
Sets the player's target.
void player_targetHyperspaceSet(int id, int nomsg)
Sets the player's hyperspace target.
void player_destroyed(void)
Player blew up in a fireball.
void player_autonavAbort(const char *reason)
Aborts autonav.
glTexture * ship_gfxComm(const Ship *s, int size, double tilt, double dir, const Lighting *Lscene)
Loads the ship's comm graphic.
void ss_free(ShipStatList *ll)
Frees a list of ship stats.
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.
ShipStatsType ss_typeFromName(const char *name)
Gets the type from the name.
int ss_statsInit(ShipStats *stats)
Initializes a stat structure.
void spob_distress(Spob *spb, const Pilot *p, const Pilot *attacker)
Spob is receiving distress from a pilot about an attacker.
int space_canHyperspace(const Pilot *p)
Checks to make sure if pilot is far enough away to hyperspace.
double system_getReputation(const StarSystem *sys, int faction)
Gets the local reputation of the player in a system or returns 0.
StarSystem * system_getIndex(int id)
Get the system by its index.
int space_calcJumpInPos(const StarSystem *in, const StarSystem *out, vec2 *pos, vec2 *vel, double *dir, const Pilot *p)
Calculates the jump in pos for a pilot.
Represents a single asteroid.
Represents a polygon used for collision detection.
Core damage that an outfit does.
A ship outfit, depends radically on the type.
union Outfit::@264277167364127137334024361374356236341374052147 u
Stores a pilot commodity.
const Commodity * commodity
Stores an outfit the pilot has.
A pilot Weapon Set Outfit.
A weapon set represents a set of weapons that have an action.
PilotWeaponSetOutfit * slots
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,...
Abstraction for rendering sprite sheets.
Contains a mission variable.
Small struct to handle flags.
void weapon_clear(void)
Clears all the weapons, does NOT free the layers.
void weapon_hitAI(Pilot *p, const Pilot *shooter, double dmg)
Informs the AI if needed that it's been hit.