15#include "nlua_pilot.h"
20#include "damagetype.h"
24#include "land_outfits.h"
28#include "nlua_asteroid.h"
29#include "nlua_canvas.h"
30#include "nlua_colour.h"
32#include "nlua_commodity.h"
33#include "nlua_faction.h"
35#include "nlua_pilotoutfit.h"
36#include "nlua_outfit.h"
39#include "nlua_system.h"
44#include "pilot_heat.h"
59static int pilotL_getFriendOrFoe( lua_State *L,
int friend );
64static int luaL_checkweapset( lua_State *L,
int idx );
491 state = lua_toboolean(L, 2);
495 pilot_setFlag( p, flag );
497 pilot_rmFlag( p, flag );
524 return *((LuaPilot*) lua_touserdata(L,ind));
537 luaL_typerror(L, ind, PILOT_METATABLE);
551 NLUA_ERROR(L,_(
"Pilot is invalid."));
565 LuaPilot *p = (LuaPilot*) lua_newuserdata(L,
sizeof(LuaPilot));
567 luaL_getmetatable(L, PILOT_METATABLE);
568 lua_setmetatable(L, -2);
582 if (lua_getmetatable(L,ind)==0)
584 lua_getfield(L, LUA_REGISTRYINDEX, PILOT_METATABLE);
587 if (lua_rawequal(L, -1, -2))
607 int ignore_rules, guerilla;
609 JumpPoint *jump = NULL;
614 ignore_rules = lua_toboolean(L,2);
615 guerilla = lua_toboolean(L,3);
621 else if (jump != NULL)
661 const char *pilotname, *ai;
673 pilot_clearFlagsRaw( flags );
685 pilotname = luaL_optstring( L, 4, _(ship->
name) );
690 a = RNGF() * 2.*M_PI;
699 pilot_setFlagRaw( flags, PILOT_TAKEOFF );
700 a = RNGF() * 2. * M_PI;
701 r = RNGF() * spob->
radius;
703 spob->
pos.
x + r * cos(a),
704 spob->
pos.
y + r * sin(a) );
705 a = RNGF() * 2.*M_PI;
709 else if (lua_isnoneornil(L,3)) {
712 if (lua_isboolean(L,3) && lua_toboolean(L,3))
719 pilot_setFlagRaw( flags, PILOT_TAKEOFF );
720 a = RNGF() * 2. * M_PI;
721 r = RNGF() * spob->
radius;
723 spob->
pos.
x + r * cos(a),
724 spob->
pos.
y + r * sin(a) );
726 a = RNGF() * 2.*M_PI;
730 NLUA_INVALID_PARAMETER(L,3);
736 && !jp_isFlag(
cur_system->jumps[i].returnJump, JP_EXITONLY )) {
743 WARN(_(
"Ship '%s' jumping in from non-adjacent system '%s' to '%s'."),
748 WARN(_(
"Ship '%s' attempting to jump in from '%s', but '%s' has no jump points."),
755 if (lua_gettop( L ) >= 5 && !lua_isnil( L, 5 )) {
756 if (!lua_istable( L, 5 ))
757 return NLUA_ERROR( L, _(
"'parameters' should be a table of options or omitted!") );
758 lua_getfield( L, 5,
"ai" );
759 ai = luaL_optstring( L, -1, NULL );
762 lua_getfield( L, 5,
"naked" );
763 if (lua_toboolean(L, -1))
764 pilot_setFlagRaw( flags, PILOT_NO_OUTFITS );
767 lua_getfield( L, 5,
"stealth" );
768 if (lua_toboolean(L, -1))
769 pilot_setFlagRaw( flags, PILOT_STEALTH );
776 pilot_setFlagRaw( flags, PILOT_HYP_END );
780 a = fmod( a, 2.*M_PI );
785 p =
pilot_create( ship, pilotname, lf, ai, a, &vp, &vv, flags, 0, 0 );
789 p->timer[0] = p->tcontrol;
793 if ((jump != NULL) && pilot_isFlagRaw( flags, PILOT_STEALTH )) {
831 if (pilot_isPlayer(p))
856 pilot_setFlag( p, PILOT_EXPLODED );
858 if (!pilot_isFlag( p, PILOT_EXPLODED )) {
859 lua_pushboolean(L,0);
864 if (pilot_isPlayer(p))
870 lua_pushboolean(L,1);
878 if (pilot_isFlag(pi, PILOT_DELETE) ||
879 pilot_isFlag(pi, PILOT_DEAD) ||
880 pilot_isFlag(pi, PILOT_HIDE))
899 if (lua_istable(L,1)) {
901 while (lua_next(L, 1) != 0) {
944void toggleSpawn(
int f,
int b )
971 int b = !lua_toboolean(L,2);
974 if (!lua_isnoneornil(L,1)) {
975 if (lua_istable(L,1)) {
977 while (lua_next(L, 1) != 0) {
985 else if (lua_isboolean(L,1))
988 NLUA_INVALID_PARAMETER(L,1);
1012 int d = lua_toboolean(L,2);
1027 while (lua_next(L, 1) != 0) {
1044 lua_rawseti(L,-2, k++);
1052 else if ((lua_isnil(L,1)) || (lua_gettop(L) == 0)) {
1060 lua_rawseti(L,-2,k++);
1065 NLUA_INVALID_PARAMETER(L,1);
1070static int getFriendOrFoeTest(
const Pilot *p,
const Pilot *plt,
int friend,
double dd,
int inrange,
int dis,
int fighters,
const vec2 *v, LuaFaction lf )
1073 if (pilot_isFlag(plt, PILOT_DELETE))
1077 if ((p!=NULL) && (p->id==plt->
id))
1081 if (!fighters && pilot_isFlag(plt, PILOT_CARRIED))
1086 vec2_dist2(&plt->
solid.
pos, v) > dd)
1090 if (dis && pilot_isDisabled(plt))
1122 if ((p!=NULL) && inrange &&
friend) {
1133static int pilotL_getFriendOrFoe( lua_State *L,
int friend )
1139 int inrange, dis, fighters;
1148 else if (lua_isstring(L,1))
1152 dist = luaL_optnumber(L,2,-1.);
1155 dis = lua_toboolean(L,5);
1156 fighters = lua_toboolean(L,6);
1162 dist = luaL_optnumber(L,2,-1.);
1163 v = luaL_optvector(L,3,&p->solid.pos);
1164 inrange = !lua_toboolean(L,4);
1165 dis = lua_toboolean(L,5);
1166 fighters = lua_toboolean(L,6);
1178 if (dist >= 0. && dist < INFINITY) {
1184 qt = pilot_collideQuery( x-r, y-r, x+r, y+r );
1185 for (
int i=0; i<il_size(qt); i++) {
1188 if (getFriendOrFoeTest( p, plt,
friend, dd, inrange, dis, fighters, v, lf )) {
1190 lua_rawseti(L,-2, k++);
1198 if (getFriendOrFoeTest( p, plt,
friend, dd, inrange, dis, fighters, v, lf )) {
1200 lua_rawseti(L,-2, k++);
1226 return pilotL_getFriendOrFoe( L, 1 );
1248 return pilotL_getFriendOrFoe( L, 0 );
1268 int dis = lua_toboolean(L,2);
1287 lua_rawseti(L,-2,k++);
1308 double d = luaL_checknumber(L,2);
1309 int dis = lua_toboolean(L,3);
1320 qt = pilot_collideQuery( x-r, y-r, x+r, y+r );
1323 for (
int i=0; i<il_size(qt); i++) {
1327 if (pilot_isFlag(p, PILOT_DELETE))
1330 if (pilot_isFlag(p, PILOT_HIDE))
1333 if (dis && pilot_isDisabled(p))
1337 if (vec2_dist2( v, &p->solid.pos ) >
d )
1341 lua_rawseti(L,-2,k++);
1361 lua_pushboolean(L, p1 == p2);
1379 lua_pushstring(L,p->name);
1381 lua_pushstring(L,
"(inexistent pilot)");
1397 lua_pushstring(L, p->name);
1413 lua_pushnumber(L, p->id);
1436 else if (pilot_isFlag( p, PILOT_DEAD ) || pilot_isFlag( p, PILOT_HIDE ))
1442 lua_pushboolean(L, exists);
1477 if (lua_isnoneornil(L,2))
1481 if (pilot_isPlayer(p))
1501 if (p->nav_asteroid < 0)
1504 la.parent = p->nav_anchor;
1505 la.id = p->nav_asteroid;
1523 p->nav_anchor = la->parent;
1524 p->nav_asteroid = la->id;
1556 lua_pushboolean(L,1);
1557 lua_pushboolean(L,1);
1559 else if (ret == 0) {
1560 lua_pushboolean(L,0);
1561 lua_pushboolean(L,0);
1564 lua_pushboolean(L,1);
1565 lua_pushboolean(L,0);
1574 lua_pushboolean(L,1);
1580 lua_pushboolean(L,1);
1608 lua_pushboolean(L, pilot_isWithPlayer(p));
1629 if (p->nav_spob < 0)
1635 if (p->nav_hyperspace < 0)
1638 LuaSystem ls =
cur_system->jumps[ p->nav_hyperspace ].targetid;
1657 if (p->nav_spob < 0)
1677 if (p->nav_hyperspace < 0)
1700 if (!lua_isnoneornil(L,2)) {
1703 return NLUA_ERROR(L,_(
"Jump source system doesn't match current system!"));
1711 return NLUA_ERROR(L,_(
"Jump destination system not found!"));
1714 if (pilot_isPlayer(p))
1715 map_select(
cur_system->jumps[jumpid].target, 0 );
1717 p->nav_hyperspace = jumpid;
1735 lua_pushinteger( L, p->active_set+1 );
1752 int id = luaL_checkweapset(L,2);
1767 int is_lau, is_fb, active;
1777 || is_lau || is_fb))
1786 lua_pushnumber(L,++(*k));
1792 lua_pushstring(L,
"outfit");
1798 double delay, firemod, enermod;
1804 lua_pushstring(L,
"cooldown");
1805 has_beamid = (slot->u.
beamid > 0);
1807 lua_pushnumber(L, 0.);
1810 lua_pushnumber( L,
CLAMP( 0., 1., 1. -delay ) );
1815 lua_pushstring(L,
"charge");
1819 lua_pushnumber( L,
CLAMP( 0., 1., 1. -delay ) );
1823 double delay, firemod, enermod;
1825 lua_pushstring(L,
"cooldown");
1829 lua_pushnumber( L,
CLAMP( 0., 1., 1. - slot->
timer / delay ) );
1831 lua_pushnumber( L, 1. );
1836 if (is_lau || is_fb) {
1837 lua_pushstring(L,
"left");
1842 lua_pushstring(L,
"left_p");
1850 lua_pushstring(L,
"lockon");
1852 lua_pushnumber(L, 1.);
1858 lua_pushstring(L,
"in_arc");
1864 lua_pushstring(L,
"level");
1865 lua_pushnumber(L, slot->
level+1);
1869 for (
int id=0;
id<PILOT_WEAPON_SETS;
id++) {
1875 if (po_list[i].slotid==slot->
id) {
1883 lua_pushstring(L,
"active");
1884 lua_pushboolean(L,active);
1888 lua_pushstring(L,
"heat");
1893 lua_pushstring(L,
"type");
1900 lua_pushstring(L,
"dtype");
1907 lua_pushstring(L,
"track");
1911 lua_pushnumber(L, -1);
1969 if (lua_gettop(L) > 1) {
1970 if (lua_isnumber(L,2))
1971 id = luaL_checkinteger(L,2) - 1;
1972 else if (lua_isboolean(L,2)) {
1973 all = lua_toboolean(L,2);
1977 NLUA_INVALID_PARAMETER(L,2);
1981 id =
CLAMP( 0, PILOT_WEAPON_SETS,
id );
1984 target = (p->target != p->id) ?
pilot_get(p->target) : NULL;
1993 for (
int i=0; i<
array_size(p->outfits); i++) {
2010static int luaL_checkweapset( lua_State *L,
int idx )
2012 int ws = luaL_checkinteger(L,idx)-1;
2013 if ((ws < 0) || (ws > 9))
2014 return NLUA_ERROR(L,_(
"Invalid weapon set '%d'!"),idx);
2020 if (lua_isnumber(L,idx)) {
2021 const int slotid = lua_tointeger(L,idx);
2022 if ((slotid < 1) || (slotid >
array_size(p->outfits))) {
2023 NLUA_ERROR(L,_(
"Pilot '%s' with ship '%s' does not have a slot with id '%d'!"), p->name, _(p->ship->name), slotid );
2027 return p->outfits[ slotid-1 ];
2030 const char *slotname = luaL_checkstring(L,idx);
2033 WARN(_(
"Pilot '%s' with ship '%s' does not have named slot '%s'!"), p->name, _(p->ship->name), slotname );
2050 int id = luaL_checkweapset(L,2);
2056 lua_rawseti( L, -2, i+1 );
2072 int id = luaL_checkweapset(L,2);
2073 const char *type = luaL_checkstring(L,3);
2075 if (strcmp(type,
"switch")==0)
2076 typeid = WEAPSET_TYPE_SWITCH;
2077 else if (strcmp(type,
"toggle")==0)
2078 typeid = WEAPSET_TYPE_TOGGLE;
2079 else if (strcmp(type,
"hold")==0)
2080 typeid = WEAPSET_TYPE_HOLD;
2082 return NLUA_ERROR(L,_(
"Invalid weapon set type '%s'!"),type);
2098 int id = luaL_checkweapset(L,2);
2100 int level = luaL_optinteger(L,4,0);
2116 int id = luaL_checkweapset(L,2);
2117 const char *type = luaL_checkstring(L,3);
2118 int level = luaL_optinteger(L,4,0);
2119 for (
int i=0; i<
array_size(p->outfits); i++) {
2142 int id = luaL_checkweapset(L,2);
2158 if (lua_isnoneornil(L,2)) {
2159 for (
int i=0; i<PILOT_WEAPON_SETS; i++)
2163 int id = luaL_checkweapset(L,2);
2195 double heat, heat_mean, heat_peak, nweapons;
2205 if (lua_gettop(L) > 1) {
2206 if (lua_isnumber(L,2))
2207 id = luaL_checkinteger(L,2) - 1;
2208 else if (lua_isboolean(L,2)) {
2209 all = lua_toboolean(L,2);
2213 NLUA_INVALID_PARAMETER(L,2);
2217 id =
CLAMP( 0, PILOT_WEAPON_SETS,
id );
2223 for (
int j=0; j<=PILOT_WEAPSET_MAX_LEVELS; j++) {
2225 int level_match = (j==PILOT_WEAPSET_MAX_LEVELS) ? -1 : j;
2228 for (
int i=0; i<n; i++) {
2236 level = all ? slot->
level : po_list[i].
level;
2239 if (level != level_match)
2250 if (heat > heat_peak)
2257 heat_mean /= nweapons;
2259 lua_pushnumber( L, heat_mean );
2260 lua_pushnumber( L, heat_peak );
2276 int inrange = lua_toboolean(L,3);
2277 if (lua_isnoneornil(L,2)) {
2278 for (
int i=0; i<PILOT_WEAPON_SETS; i++)
2282 int id = luaL_checkweapset(L,2);
2300 int id = luaL_optinteger( L, 2, p->active_set );
2301 int level = luaL_optinteger( L, 3, -1 );
2348 sort = lua_toboolean(L,2);
2358 outfits = p->outfits;
2373 lua_pushnumber(L,++k);
2377 lua_pushstring(L,
"outfit");
2382 lua_pushstring(L,
"type");
2387 lua_pushstring(L,
"heat");
2394 for (
int id=0;
id<PILOT_WEAPON_SETS;
id++) {
2400 if (po_list[j].slotid==o->
id) {
2408 lua_pushstring(L,
"active");
2409 lua_pushboolean(L,active);
2413 if (outfits[i]->weapset != -1) {
2414 lua_pushstring(L,
"weapset");
2415 lua_pushnumber(L, outfits[i]->weapset + 1);
2421 case PILOT_OUTFIT_OFF:
2424 case PILOT_OUTFIT_WARMUP:
2430 lua_pushstring(L,
"warmup");
2431 lua_pushnumber(L,
d );
2434 case PILOT_OUTFIT_ON:
2440 else if (!isinf(o->
stimer))
2445 lua_pushstring(L,
"duration");
2446 lua_pushnumber(L,
d );
2449 case PILOT_OUTFIT_COOLDOWN:
2453 if (
d>0. && !isinf(o->
stimer))
2458 lua_pushstring(L,
"cooldown");
2459 lua_pushnumber(L,
d );
2466 lua_pushstring(L,
"state");
2467 lua_pushstring(L,str);
2497 if (s1->
id < s2->
id)
2499 else if (s1->
id > s2->
id)
2519 const char *type = luaL_optstring(L,2,NULL);
2520 int skip_locked = lua_toboolean(L,3);
2521 OutfitSlotType ost = OUTFIT_SLOT_NULL;
2525 if (strcmp(type,
"all")==0)
2527 else if (strcmp(type,
"structure")==0)
2528 ost = OUTFIT_SLOT_STRUCTURE;
2529 else if (strcmp(type,
"utility")==0)
2530 ost = OUTFIT_SLOT_UTILITY;
2531 else if (strcmp(type,
"weapon")==0)
2532 ost = OUTFIT_SLOT_WEAPON;
2533 else if (strcmp(type,
"intrinsic")==0) {
2538 return NLUA_ERROR(L,_(
"Unknown slot type '%s'"), type);
2544 for (
int i=0; i<
array_size(p->outfits); i++) {
2546 if (p->outfits[i]->outfit == NULL)
2550 if ((ost!=OUTFIT_SLOT_NULL) && (p->outfits[i]->outfit->slot.type!=ost))
2554 if (skip_locked && p->outfits[i]->sslot->locked)
2559 lua_rawseti( L, -2, j++ );
2563 for (
int i=0; i<
array_size(p->outfit_intrinsic); i++) {
2565 lua_rawseti( L, -2, j++ );
2585 for (
int i=0; i<
array_size(p->outfits); i++) {
2586 if (p->outfits[i]->outfit == NULL)
2587 lua_pushboolean( L, 0 );
2590 lua_rawseti( L, -2, i+1 );
2609 for (
int i=1; ; i++) {
2614 if (lua_isnil(L,-1)) {
2620 WARN(_(
"Trying to equip more outfits than slots available on pilot '%s'!"), p->name);
2626 if (!lua_toboolean(L,-1))
2630 s = p->outfits[i-1];
2635 lua_pushboolean(L,!ret);
2651 int id = luaL_checkinteger(L,2)-1;
2653 return NLUA_ERROR(L, _(
"Pilot '%s' outfit ID '%d' is out of range!"), p->name,
id);
2655 if (p->outfits[
id]->outfit != NULL)
2662static int outfitToggle( lua_State *L,
Pilot *p,
int id,
int activate )
2665 return NLUA_ERROR(L, _(
"Pilot '%s' outfit ID '%d' is out of range!"), p->name,
id);
2674 if ((activate && (po->
state != PILOT_OUTFIT_OFF)) ||
2675 (!activate && (po->
state != PILOT_OUTFIT_ON)))
2694 int activate = lua_toboolean(L,3);
2698 if ((pilot_isDisabled(p)) || (pilot_isFlag(p, PILOT_COOLDOWN)))
2701 if (lua_istable(L,2)) {
2704 while (lua_next(L, 1) != 0) {
2705 n += outfitToggle( L, p, luaL_checkinteger(L,-1)-1, activate );
2711 n = outfitToggle( L, p, luaL_checkinteger(L,2)-1, activate );
2714 if (n>0 && pilot_isFlag(p,PILOT_STEALTH))
2716 else if (n>0 || pilotoutfit_modified)
2719 lua_pushboolean(L,n);
2735 int id = luaL_checkinteger(L,2)-1;
2737 return NLUA_ERROR(L, _(
"Pilot '%s' outfit ID '%d' is out of range!"), p->name,
id);
2739 if (p->outfits[
id]->outfit != NULL)
2740 lua_pushboolean( L, p->outfits[
id]->state==PILOT_OUTFIT_OFF );
2742 lua_pushboolean( L, 0 );
2759 const char *name = luaL_checkstring(L,2);
2763 p->name = strdup(name);
2812 lua_pushboolean(L,(VMOD(p->solid.vel) < MIN_VEL_ERR));
2828 lua_pushnumber( L, p->ew_signature );
2844 lua_pushnumber( L, p->solid.dir );
2860 lua_pushnumber( L, p->heat_T );
2876 lua_pushnumber( L, p->solid.mass );
2890 lua_pushnumber( L, p->accel );
2904 lua_pushnumber( L, p->speed );
2919 lua_pushnumber( L, solid_maxspeed( &p->solid, p->speed, p->accel ) );
2933 lua_pushnumber( L, p->turn * 180. / M_PI );
2999 char message[STRMAX_SHORT];
3002 lua_pushboolean( L, worthy );
3003 lua_pushstring( L, message );
3026 p->solid.pos = *vec;
3029 if (pilot_isPlayer(p))
3051 p->solid.vel = *vec;
3070 double d = luaL_checknumber(L,2);
3073 p->solid.dir = fmodf(
d, 2*M_PI );
3074 if (p->solid.dir < 0.)
3075 p->solid.dir += 2*M_PI;
3095 if (lua_isstring(L,1)) {
3096 const char *s = luaL_checkstring(L,1);
3097 const char *msg = luaL_checkstring(L,2);
3098 const char *col = luaL_optstring(L,3,NULL);
3100 player_message( _(
"#%cBroadcast %s>#0 \"%s\""), ((col==NULL)?
'N':col[0]), s, msg );
3106 const char *msg = luaL_checkstring(L,2);
3107 int ignore_int = lua_toboolean(L,3);
3134 if (lua_isstring(L,1)) {
3136 const char *msg, *col;
3143 s = luaL_checkstring(L,1);
3144 if (lua_isstring(L,2)) {
3145 msg = luaL_checkstring(L,2);
3146 col = luaL_optstring(L,3,NULL);
3147 raw = lua_toboolean(L,4);
3153 msg = luaL_checkstring(L,3);
3154 col = luaL_optstring(L,4,NULL);
3155 raw = lua_toboolean(L,5);
3160 player_message( _(
"#%c%s>#0 %s"), ((col==NULL)?
'N':col[0]), s, msg );
3162 player_message( _(
"#%cComm %s>#0 \"%s\""), ((col==NULL)?
'N':col[0]), s, msg );
3170 int ignore_int, raw;
3174 if (lua_isstring(L,2)) {
3176 msg = luaL_checkstring(L,2);
3177 ignore_int = lua_toboolean(L,3);
3178 raw = lua_toboolean(L,4);
3182 msg = luaL_checkstring(L,3);
3183 ignore_int = lua_toboolean(L,4);
3184 raw = lua_toboolean(L,5);
3194 if (target == 0 || target == PLAYER_ID) {
3245 if (lua_isnone(L,2))
3248 state = lua_toboolean(L, 2);
3276 if (lua_isnone(L,2))
3279 state = lua_toboolean(L, 2);
3475 int permanent = !lua_toboolean(L,2);
3479 p->stress = p->armour;
3483 pilot_setFlag(p, PILOT_DISABLED_PERM);
3485 pilot_rmFlag(p, PILOT_DISABLED_PERM);
3503 lua_pushboolean( L, pilot_isFlag(p, PILOT_COOLDOWN) );
3504 lua_pushboolean( L, pilot_isFlag(p, PILOT_COOLDOWN_BRAKE) );
3524 if (lua_isnone(L,2))
3527 state = lua_toboolean(L, 2);
3549 pilot_rmFlag(p, PILOT_COOLDOWN_BRAKE);
3606 if ((s->
outfit != NULL) &&
3615 else if (bypass_cpu) {
3641 if (pilot_isPlayer(p))
3667 int q, added, bypass_cpu, bypass_slot, slotid;
3672 q = luaL_optinteger(L,3,1);
3673 bypass_cpu = lua_toboolean(L,4);
3674 bypass_slot = lua_toboolean(L,5);
3679 for (
int i=0; i<
array_size(p->outfits); i++) {
3714 if (pilot_isPlayer(p))
3718 lua_pushnumber(L,added);
3721 lua_pushinteger(L,slotid+1);
3761 int ret, added, bypass_cpu, bypass_slot;
3767 s = luaL_checkslot( L, p, 3 );
3768 bypass_cpu = lua_toboolean(L,4);
3769 bypass_slot = lua_toboolean(L,5);
3790 if (pilot_isPlayer(p))
3794 lua_pushboolean(L,added);
3818 int q, removed, matched = 0;
3823 q = luaL_optinteger(L,3,1);
3825 if (lua_isstring(L,2)) {
3826 const char *outfit = luaL_checkstring(L,2);
3829 if (strcmp(outfit,
"all")==0) {
3830 for (
int i=0; i<
array_size(p->outfits); i++) {
3831 if (p->outfits[i]->sslot->required)
3833 if (p->outfits[i]->sslot->locked)
3842 else if (strcmp(outfit,
"cores")==0) {
3843 for (
int i=0; i<
array_size(p->outfits); i++) {
3844 if (!p->outfits[i]->sslot->required)
3859 for (
int i=0; i<
array_size(p->outfits); i++) {
3865 if (p->outfits[i]->outfit != o)
3879 lua_pushnumber( L, removed );
3911 lua_pushboolean( L, ret );
3932 lua_pushboolean(L,ret);
3935 if (pilot_isPlayer(p))
3968 lua_pushnumber(L, p->fuel);
3988 if (lua_isboolean(L,2)) {
3989 if (lua_toboolean(L,2))
3990 p->fuel = p->fuel_max;
3994 else if (lua_isnumber(L,2)) {
3995 p->fuel =
CLAMP( 0, p->fuel_max, lua_tonumber(L,2) );
3998 NLUA_INVALID_PARAMETER(L,2);
4001 lua_pushnumber(L, p->fuel);
4013 ss_free( p->intrinsic_stats );
4014 p->intrinsic_stats = NULL;
4037 if (!lua_istable(L,2)) {
4038 name = luaL_checkstring(L,2);
4039 value = luaL_checknumber(L,3);
4040 replace = lua_toboolean(L,4);
4041 p->intrinsic_stats = ss_statsSetList( p->intrinsic_stats,
ss_typeFromName(name), value, replace, 0 );
4045 replace = lua_toboolean(L,4);
4048 while (lua_next(L,2) != 0) {
4049 name = luaL_checkstring(L,-2);
4050 value = luaL_checknumber(L,-1);
4051 p->intrinsic_stats = ss_statsSetList( p->intrinsic_stats,
ss_typeFromName(name), value, replace, 0 );
4071 const char *name = luaL_optstring(L,2,NULL);
4072 int internal = lua_toboolean(L,3);
4091 p->ship_stats = NULL;
4113 if (p->ship->lua_env == LUA_NOREF)
4114 return NLUA_ERROR(L,_(
"Trying to set ship property of pilot '%s' flying ship '%s' with no ship Lua enabled!"), p->name, p->ship->name);
4117 if (!lua_istable(L,2)) {
4118 name = luaL_checkstring(L,2);
4119 value = luaL_checknumber(L,3);
4120 p->ship_stats = ss_statsSetList( p->ship_stats,
ss_typeFromName(name), value, 1, 0 );
4126 while (lua_next(L,2) != 0) {
4127 name = luaL_checkstring(L,-2);
4128 value = luaL_checknumber(L,-1);
4129 p->ship_stats = ss_statsSetList( p->ship_stats,
ss_typeFromName(name), value, 1, 0 );
4149 const char *name = luaL_optstring(L,2,NULL);
4150 int internal = lua_toboolean(L,3);
4171 int keepdebuffs = lua_toboolean(L,2);
4172 int keepbuffs = lua_toboolean(L,3);
4173 int keepothers = lua_toboolean(L,4);
4174 if (!keepdebuffs && !keepbuffs && !keepothers)
4195 const char *effectname = luaL_checkstring(L,2);
4196 double duration = luaL_optnumber(L,3,-1.);
4197 double scale = luaL_optnumber(L,4,1.);
4200 if (!
effect_add( &p->effects, efx, duration, scale, p->id ))
4202 lua_pushboolean(L,1);
4205 lua_pushboolean(L,0);
4220 if (lua_isnumber(L,2)) {
4221 int idx = lua_tointeger(L,2);
4226 const char *effectname = luaL_checkstring(L,2);
4227 int all = lua_toboolean(L,3);
4248 for (
int i=0; i<
array_size(p->effects); i++) {
4249 const Effect *e = &p->effects[i];
4253 lua_setfield(L,-2,
"name");
4255 lua_pushnumber(L,e->
timer);
4256 lua_setfield(L,-2,
"timer");
4258 lua_pushnumber(L,e->
timer);
4259 lua_setfield(L,-2,
"strength");
4262 lua_setfield(L,-2,
"duration");
4265 lua_setfield(L,-2,
"icon");
4268 lua_pushboolean(L,1);
4269 lua_setfield(L,-2,
"buff");
4273 lua_pushboolean(L,1);
4274 lua_setfield(L,-2,
"debuff");
4277 lua_rawseti(L,-2,i+1);
4294 lua_pushstring( L, p->ai->name );
4312 const char *str = luaL_checkstring(L,2);
4319 lua_pushboolean(L, ret);
4345 kelvins = luaL_checknumber(L, 2);
4346 setOutfits = !lua_toboolean(L,3);
4349 kelvins =
MAX(kelvins, CONST_SPACE_STAR_TEMP);
4352 p->heat_T = kelvins;
4356 for (
int i=0; i <
array_size(p->outfits); i++)
4357 p->outfits[i]->heat_T = kelvins;
4384 a = luaL_optnumber(L, 2, 100.*p->armour / p->armour_max);
4385 s = luaL_optnumber(L, 3, 100.*p->shield / p->shield_max);
4386 st = luaL_optnumber(L,4,0.);
4393 p->armour = a * p->armour_max;
4394 p->shield = s * p->shield_max;
4395 p->stress =
st * p->armour;
4398 if (p->armour > 0.) {
4399 pilot_rmFlag( p, PILOT_DISABLED );
4400 pilot_rmFlag( p, PILOT_DEAD );
4401 pilot_rmFlag( p, PILOT_DEATH_SOUND );
4402 pilot_rmFlag( p, PILOT_EXPLODED );
4403 pilot_rmFlag( p, PILOT_DELETE );
4404 if (pilot_isPlayer(p))
4405 player_rmFlag( PLAYER_DESTROYED );
4407 pilot_rmFlag( p, PILOT_DISABLED_PERM );
4433 a = luaL_optnumber(L, 2, p->armour);
4434 s = luaL_optnumber(L, 3, p->shield);
4435 st = luaL_optnumber(L,4,p->stress);
4438 p->armour =
CLAMP( 0., p->armour_max, a );
4439 p->shield =
CLAMP( 0., p->shield_max, s );
4440 p->stress =
CLAMP( 0., p->armour_max,
st );
4443 if (p->armour > 0.) {
4444 pilot_rmFlag( p, PILOT_DISABLED );
4445 pilot_rmFlag( p, PILOT_DEAD );
4446 pilot_rmFlag( p, PILOT_DEATH_SOUND );
4447 pilot_rmFlag( p, PILOT_EXPLODED );
4448 pilot_rmFlag( p, PILOT_DELETE );
4449 if (pilot_isPlayer(p))
4450 player_rmFlag( PLAYER_DESTROYED );
4452 pilot_rmFlag( p, PILOT_DISABLED_PERM );
4477 a = luaL_optnumber(L, 2, 0.);
4478 s = luaL_optnumber(L, 3, 0.);
4481 p->armour =
CLAMP( 0., p->armour_max, p->armour + a );
4482 p->shield =
CLAMP( 0., p->shield_max, p->shield + s );
4505 double e = luaL_checknumber(L,2);
4506 int absolute = lua_toboolean(L,3);
4509 p->energy =
CLAMP( 0., p->energy_max, e );
4511 p->energy = (e/100.) * p->energy_max;
4527 double e = luaL_checknumber(L,2);
4528 p->energy =
CLAMP( 0., p->energy_max, p->energy+e );
4561 if (lua_isnone(L,2))
4564 disable = lua_toboolean(L, 2);
4568 pilot_setFlag(p, PILOT_NOBOARD);
4570 pilot_rmFlag(p, PILOT_NOBOARD);
4591 if (lua_isnone(L,2))
4594 nodisable = lua_toboolean(L, 2);
4598 pilot_setFlag(p, PILOT_NODISABLE);
4600 pilot_rmFlag(p, PILOT_NODISABLE);
4621 double s = luaL_checknumber(L, 2);
4626 pilot_setFlag( p, PILOT_HASSPEEDLIMIT );
4628 pilot_rmFlag( p, PILOT_HASSPEEDLIMIT );
4650 int absolute = lua_toboolean(L,2);
4653 lua_pushnumber(L, p->armour );
4654 lua_pushnumber(L, p->shield );
4657 lua_pushnumber(L,(p->armour_max > 0.) ? p->armour / p->armour_max * 100. : 0. );
4658 lua_pushnumber(L,(p->shield_max > 0.) ? p->shield / p->shield_max * 100. : 0. );
4660 lua_pushnumber(L,
MIN( 1., p->stress / p->armour ) * 100. );
4661 lua_pushboolean(L, pilot_isDisabled(p));
4678 int absolute = lua_toboolean(L,2);
4680 lua_pushnumber(L, p->armour );
4682 lua_pushnumber(L,(p->armour_max > 0.) ? p->armour / p->armour_max * 100. : 0. );
4699 int absolute = lua_toboolean(L,2);
4701 lua_pushnumber(L, p->shield );
4703 lua_pushnumber(L,(p->shield_max > 0.) ? p->shield / p->shield_max * 100. : 0. );
4720 int absolute = lua_toboolean(L,2);
4722 lua_pushnumber(L, p->energy );
4724 lua_pushnumber(L, (p->energy_max > 0.) ? p->energy / p->energy_max * 100. : 0. );
4740 lua_pushnumber(L, p->lockons );
4744#define PUSH_DOUBLE( L, name, value ) \
4745lua_pushstring( L, name ); \
4746lua_pushnumber( L, value ); \
4748#define PUSH_INT( L, name, value ) \
4749lua_pushstring( L, name ); \
4750lua_pushinteger( L, value ); \
4791 PUSH_DOUBLE( L,
"cpu", p->cpu );
4792 PUSH_INT( L,
"cpu_max", p->cpu_max );
4793 PUSH_INT( L,
"crew", (
int)round( p->crew ) );
4794 PUSH_INT( L,
"fuel", p->fuel );
4795 PUSH_INT( L,
"fuel_max", p->fuel_max );
4796 PUSH_INT( L,
"fuel_consumption", p->fuel_consumption );
4797 PUSH_DOUBLE( L,
"mass", p->solid.mass );
4799 PUSH_DOUBLE( L,
"accel", p->accel );
4800 PUSH_DOUBLE( L,
"speed", p->speed );
4801 PUSH_DOUBLE( L,
"turn", p->turn*180./M_PI );
4802 PUSH_DOUBLE( L,
"speed_max", solid_maxspeed(&p->solid, p->speed, p->accel) );
4804 PUSH_DOUBLE( L,
"absorb", p->dmg_absorb );
4805 PUSH_DOUBLE( L,
"armour", p->armour_max );
4806 PUSH_DOUBLE( L,
"shield", p->shield_max );
4807 PUSH_DOUBLE( L,
"energy", p->energy_max );
4808 PUSH_DOUBLE( L,
"armour_regen", p->armour_regen );
4809 PUSH_DOUBLE( L,
"shield_regen", p->shield_regen );
4810 PUSH_DOUBLE( L,
"energy_regen", p->energy_regen );
4812 PUSH_DOUBLE( L,
"ew_detection", p->ew_detection );
4813 PUSH_DOUBLE( L,
"ew_signature", p->ew_signature );
4814 PUSH_DOUBLE( L,
"ew_stealth", p->ew_stealth );
4837 const char *str = luaL_optstring(L,2,NULL);
4838 int internal = lua_toboolean(L,3);
4852 if (pilot_isFlag(p,PILOT_STEALTH))
4853 lua_pushnumber( L, p->ew_stealth );
4855 lua_pushnumber( L, p->ew_detection );
4888 lua_pushnumber(L, quantity);
4910 int quantity = luaL_checknumber(L, 3);
4913 return NLUA_ERROR( L, _(
"Quantity must be positive for pilot.cargoAdd (if removing, use pilot.cargoRm)") );
4917 lua_pushnumber( L, quantity );
4921static int pilotL_cargoRmHelper( lua_State *L,
int jet )
4930 if (lua_isstring(L, 2)) {
4931 const char *str = lua_tostring(L, 2);
4934 if (strcmp(str,
"all") == 0) {
4936 lua_pushnumber(L, quantity);
4943 quantity = luaL_checknumber(L, 3);
4946 return NLUA_ERROR(L,_(
"Quantity must be positive for pilot.cargoRm (if adding, use pilot.cargoAdd)"));
4954 lua_pushnumber(L, quantity);
4975 return pilotL_cargoRmHelper( L, 0 );
4992 return pilotL_cargoRmHelper( L, 1 );
5016 for (
int i=0; i<
array_size(p->commodities); i++) {
5022 lua_pushstring(L,
"name");
5026 lua_pushstring(L,
"c");
5030 lua_pushstring(L,
"q");
5034 lua_pushstring(L,
"m");
5035 lua_pushboolean(L, pc->
id);
5038 lua_rawseti(L,-2,i+1);
5056 lua_pushnumber( L, p->credits );
5071 lua_pushnumber( L,
pilot_worth(p, lua_toboolean(L,2)) );
5105 lua_pushstring(L,str);
5133 { .name =
"stealth", .id = PILOT_STEALTH },
5134 { .name =
"refueling", .id = PILOT_REFUELING },
5135 { .name =
"invisible", .id = PILOT_INVISIBLE },
5136 { .name =
"disabled", .id = PILOT_DISABLED },
5137 { .name =
"landing", .id = PILOT_LANDING },
5138 { .name =
"takingoff", .id = PILOT_TAKEOFF },
5139 { .name =
"jumpprep", .id = PILOT_HYP_PREP },
5140 { .name =
"jumpingin", .id = PILOT_HYP_END },
5141 { .name =
"jumpingout", .id = PILOT_HYPERSPACE },
5142 { .name =
"manualcontrol", .id = PILOT_MANUAL_CONTROL },
5143 { .name =
"carried", .id = PILOT_CARRIED },
5144 { .name =
"hailing", .id = PILOT_HAILING },
5145 { .name =
"bribed", .id = PILOT_BRIBED },
5146 { .name =
"boardable", .id = PILOT_BOARDABLE },
5147 { .name =
"nojump", .id = PILOT_NOJUMP },
5148 { .name =
"noland", .id = PILOT_NOLAND },
5149 { .name =
"nodeath", .id = PILOT_NODEATH },
5150 { .name =
"nodisable", .id = PILOT_NODISABLE },
5151 { .name =
"visible", .id = PILOT_VISIBLE },
5152 { .name =
"visplayer", .id = PILOT_VISPLAYER },
5153 { .name =
"hilight", .id = PILOT_HILIGHT },
5154 { .name =
"norender", .id = PILOT_NORENDER },
5155 { .name =
"hide", .id = PILOT_HIDE },
5156 { .name =
"invincible", .id = PILOT_INVINCIBLE },
5157 { .name =
"invinc_player", .id = PILOT_INVINC_PLAYER },
5158 { .name =
"friendly", .id = PILOT_FRIENDLY },
5159 { .name =
"hostile", .id = PILOT_HOSTILE },
5160 { .name =
"combat", .id = PILOT_COMBAT },
5200 const char *name = luaL_optstring( L, 2, NULL );
5204 if (strcmp(
pL_flags[i].name,name)==0) {
5205 lua_pushboolean( L, pilot_isFlag( p,
pL_flags[i].
id ) );
5209 WARN(_(
"Tried to access unknown flag '%s' for pilot '%s'!"), name, p->name);
5217 lua_pushboolean( L, pilot_isFlag( p,
pL_flags[i].
id ) );
5218 lua_setfield(L, -2,
pL_flags[i].name);
5264 lua_pushnumber(L, PILOT_SIZE_APPROX * 0.5 * (p->ship->gfx_space->sw+p->ship->gfx_space->sh));
5280 lua_pushinteger(L, p->ship->points);
5296 lua_pushboolean(L, p->task==0);
5324 int enable, cleartasks;
5328 if (lua_isnone(L,2))
5331 enable = lua_toboolean(L, 2);
5332 if (lua_isnone(L,3))
5333 cleartasks = enable ^ pilot_isFlag(p, PILOT_MANUAL_CONTROL);
5335 cleartasks = lua_toboolean(L, 3);
5338 int isp = pilot_isPlayer(p);
5341 pilot_setFlag(p, PILOT_MANUAL_CONTROL);
5346 pilot_rmFlag(p, PILOT_MANUAL_CONTROL);
5347 if (pilot_isPlayer(p))
5378 return NLUA_ERROR(L,_(
"Pilot '%s' does not have an AI!"),p->name);
5379 lua_rawgeti( L, LUA_REGISTRYINDEX, p->lua_mem );
5395 if (p->lua_ship_mem == LUA_NOREF) {
5396 lua_newtable( naevL );
5397 p->lua_ship_mem = luaL_ref( naevL, LUA_REGISTRYINDEX );
5399 lua_rawgeti( L, LUA_REGISTRYINDEX, p->lua_ship_mem );
5415 lua_pushstring(L, p->ai->name);
5432 lua_pushstring(L, t->
name);
5433 if (t->
dat != LUA_NOREF) {
5434 lua_rawgeti(L, LUA_REGISTRYINDEX, t->
dat);
5455 lua_pushstring(L, t->
name);
5457 lua_pushstring(L, t->
subtask->name);
5478 for (
Task *t=p->task; t!=NULL; t=t->next) {
5481 lua_pushstring(L,t->name);
5482 lua_rawseti(L,-2,n++);
5499 if (t && (t->
dat != LUA_NOREF)) {
5500 lua_rawgeti(L, LUA_REGISTRYINDEX, t->
dat);
5534 const char *task = luaL_checkstring(L,2);
5536 if (pilot_isPlayer(p) && !pilot_isFlag(p,PILOT_MANUAL_CONTROL))
5540 if (!lua_isnoneornil(L,3)) {
5541 lua_pushvalue( L, 3 );
5542 t->
dat = luaL_ref( L, LUA_REGISTRYINDEX );
5561 return NLUA_ERROR(L, _(
"Trying to pop task when there are no tasks on the stack."));
5578 double amount = luaL_optinteger(L,3,100);
5579 pilot_rmFlag( p, PILOT_HYP_PREP);
5580 pilot_rmFlag( p, PILOT_HYP_BRAKE );
5581 pilot_rmFlag( p, PILOT_HYP_BEGIN);
5582 pilot_setFlag( p, PILOT_REFUELING);
5584 p->refuel_amount = amount;
5596 if (!pilot_isFlag( p, PILOT_MANUAL_CONTROL)) {
5597 NLUA_ERROR( L, _(
"Pilot '%s' is not on manual control."), p->name );
5604 NLUA_ERROR( L, _(
"Failed to create new task for pilot '%s'."), p->name );
5635 int brake, compensate;
5641 if (lua_isnone(L,3))
5644 brake = lua_toboolean(L,3);
5645 if (lua_isnone(L,4))
5648 compensate = lua_toboolean(L,4);
5656 tsk =
"moveto_nobrake";
5658 tsk =
"moveto_nobrake_raw";
5662 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5694 towards = lua_toboolean(L,3);
5707 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5750 accurate = lua_toboolean(L,3);
5759 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5785 if (!lua_isnoneornil(L,2)) {
5798 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5827 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5856 if (lua_isnoneornil(L,3)) {
5859 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5862 if (lua_isboolean(L,3)) {
5863 int nojump = lua_toboolean(L,3);
5866 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5873 lua_rawseti( L, -2, 1 );
5875 lua_rawseti( L, -2, 2 );
5876 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5883 lua_rawseti( L, -2, 1 );
5885 lua_rawseti( L, -2, 2 );
5886 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5889 NLUA_INVALID_PARAMETER(L,3);
5906 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5950 noshoot = lua_toboolean(L,3);
5963 if (jp->target != ss)
5967 if (jp_isFlag( jp, JP_EXITONLY ))
5968 return NLUA_ERROR( L, _(
"Pilot '%s' can't jump out exit only jump '%s'"), p->name, ss->name );
5972 lj.
destid = jp->targetid;
5974 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
5978 return NLUA_ERROR( L, _(
"System '%s' is not adjacent to current system '%s'"), ss->name,
cur_system->name );
5995 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
6033 if (lua_isnoneornil(L,2))
6037 noshoot = lua_toboolean(L,3);
6054 return NLUA_ERROR( L, _(
"Spob '%s' not found in system '%s'"), pnt->
name,
cur_system->name );
6057 if (p->id == PLAYER_ID)
6061 t->
dat = luaL_ref(L, LUA_REGISTRYINDEX);
6084 if (lua_isnone(L,2))
6087 enable = lua_toboolean(L,2);
6096 pilot_setFlag( p, PILOT_HAILING );
6100 pilot_rmFlag( p, PILOT_HAILING );
6122 if (lua_isnoneornil(L,1))
6126 type = luaL_checkstring(L,3);
6127 data = lua_gettop(L) > 3 ? 4 : 0;
6129 if (!lua_istable(L,2)) {
6135 while (lua_next(L, 2) != 0) {
6156 if (p->dockpilot != 0) {
6158 if ((l == NULL) || pilot_isFlag( l, PILOT_DEAD )) {
6179 if (p->parent != 0) {
6181 if ((l == NULL) || pilot_isFlag( l, PILOT_DEAD )) {
6210 if (prev_leader != NULL) {
6216 if (e->
type != ESCORT_TYPE_MERCENARY)
6217 return NLUA_ERROR(L,_(
"Trying to change the leader of pilot '%s' that is a deployed fighter or part of the player fleet!"), p->name);
6223 WARN(_(
"Pilot '%s' not found in followers of '%s'"), p->name, prev_leader->
name );
6227 if (lua_isnoneornil(L, 2)) {
6235 if (p->id == leader->
id)
6236 return NLUA_ERROR(L,_(
"Trying to set pilot '%s' to be their own leader!"),p->name);
6238 if ((leader->
parent != 0) && (leader->
parent != p->id)) {
6240 if (leader_leader != NULL)
6241 leader = leader_leader;
6244 p->parent = leader->
id;
6248 if (dockslot != NULL) {
6255 escort_addList( leader, p->ship, ESCORT_TYPE_MERCENARY, p->id, 0 );
6258 for (
int i=
array_size(p->escorts)-1; i>=0; i--) {
6259 const Escort_t *e = &p->escorts[i];
6261 if (e->
type != ESCORT_TYPE_MERCENARY)
6270 if (pe->
id == p->parent) {
6300 for (
int i=0; i <
array_size(p->escorts); i++) {
6303 if ((pe==NULL) || pilot_isFlag( pe, PILOT_DEAD ) || pilot_isFlag( pe, PILOT_HIDE ))
6306 lua_rawseti(L, -2, idx++);
6330 int k = p->ship->gfx_space->sx * p->tsy + p->tsx;
6331 return &p->ship->polygon[k];
6352 &rpoly, &a->sol.pos, &crash );
6364 if (pilot_isFlag( t, PILOT_INVINCIBLE ))
6368 if (pilot_isFlag( t, PILOT_LANDING) ||
6369 pilot_isFlag( t, PILOT_TAKEOFF ) ||
6370 pilot_isFlag( t, PILOT_NONTARGETABLE))
6404 dmg.
damage = luaL_checknumber(L,2);
6405 dmg.
disable = luaL_optnumber(L,3,0.);
6410 damage =
pilot_hit( p, NULL, parent, &dmg, NULL, LUA_NOREF, 1 );
6414 lua_pushnumber(L, damage);
6463 e = luaL_optnumber(L,3,1.);
6467 m2 = luaL_checknumber(L,2);
6469 x2 = luaL_optvector(L,4,x1);
6470 e = luaL_optnumber(L,5,1.);
6475 double vx = (m1*v1->x + m2*v2->x) / (m1+m2);
6476 double vy = (m1*v1->y + m2*v2->y) / (m1+m2);
6477 vec2_cset( &p1->
solid.
vel, vx, vy );
6479 vec2_cset( &p2->
solid.
vel, vx, vy );
6485 double a1 = -e * (2.*m2)/(m1+m2);
6487 a1 *= ((v1->x-v2->x)*(x1->
x-x2->
x) + (v1->y-v2->y)*(x1->
y-x2->
y)) / norm;
6489 vec2_cadd( &p1->
solid.
vel, a1*(x1->
x-x2->
x), a1*(x1->
y-x2->
y) );
6491 double a2 = -e * (2.*m1)/(m2+m1);
6493 a2 *= ((v2->x-v1->x)*(x2->
x-x1->
x) + (v2->y-v1->y)*(x2->
y-x1->
y)) / norm;
6494 vec2_cadd( &p2->
solid.
vel, a2*(x2->
x-x1->
x), a2*(x2->
y-x1->
y) );
6499 double vx = (m1*v1->x + m2*v2->x) / (m1+m2);
6500 double vy = (m1*v1->y + m2*v2->y) / (m1+m2);
6501 vec2_cset( &p1->
solid.
vel, e*v1->
x + (1.-e)*vx, e*v1->y + (1.-e)*vy );
6503 vec2_cset( &p2->
solid.
vel, e*v2->
x + (1.-e)*vx, e*v2->y + (1.-e)*vy );
6536 if (lua_gettop(L) > 0)
6537 state = lua_toboolean(L, 1);
6544 debug_setFlag(DEBUG_MARK_EMITTER);
6546 debug_rmFlag(DEBUG_MARK_EMITTER);
6549 return NLUA_ERROR(L, _(
"Requires a debug build."));
6568 const char *str = luaL_checkstring(L,2);
6586 const char *str = luaL_checkstring(L,2);
6588 if (p->shipvar==NULL)
6604 const char *str = luaL_checkstring(L,2);
6625 w = p->ship->gfx_space->sw;
6626 h = p->ship->gfx_space->sh;
6627 if (canvas_new( &lc, w, h ))
6628 return NLUA_ERROR( L, _(
"Error setting up framebuffer!"));
6633 lua_pushcanvas( L, lc );
6652 if ((lc->
tex->
w < p->ship->gfx_space->sw) || (lc->
tex->
h < p->ship->gfx_space->sh))
6653 WARN(_(
"Canvas is too small to fully render '%s': %.0f x %.0f < %.0f x %.0f"),
6655 p->ship->gfx_space->sw, p->ship->gfx_space->sh );
6660 lua_pushnumber( L, p->ship->gfx_space->sw );
6661 lua_pushnumber( L, p->ship->gfx_space->sh );
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_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_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
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_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void cam_update(double dt)
Updates the camera.
void RotatePolygon(CollPoly *rpolygon, CollPoly *ipolygon, float theta)
Rotates a polygon.
int CollidePolygon(const CollPoly *at, const vec2 *ap, const CollPoly *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_weapsetActive(lua_State *L)
Gets the ID (number from 1 to 10) of the current active weapset.
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_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_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_showEmitters(lua_State *L)
Toggles the emitter marker.
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_disable(lua_State *L)
Disables a pilot.
static int pilotL_weapsetSetInrange(lua_State *L)
Sets whether a pilot's weapon set does inrange checks.
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_weapsetSetActive(lua_State *L)
Sets the ID (number from 1 to 10) of the current active weapset.
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_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_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_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_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_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.
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_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.
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_getColourChar 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_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.
void pilot_renderFramebuffer(Pilot *p, GLuint fbo, double fw, double fh)
Renders a pilot to a framebuffer.
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.
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.
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.
int pilot_weapSetTypeCheck(Pilot *p, int id)
Checks the current weapon set type.
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.
PilotWeaponSet * pilot_weapSet(Pilot *p, int id)
Gets a weapon set from id.
PilotWeaponSetOutfit * pilot_weapSetList(Pilot *p, int id)
Lists the items in a pilot weapon set.
int pilot_outfitOn(Pilot *p, PilotOutfitSlot *o)
Enable a given active outfit.
double pilot_weapSetAmmo(Pilot *p, int id, int level)
Gets the ammo of the current pilot weapon set.
void pilot_weaponAuto(Pilot *p)
Tries to automatically set and create the pilot's weapon set.
void pilot_weapSetPress(Pilot *p, int id, int type)
Handles a weapon set press.
const char * pilot_weapSetName(Pilot *p, int id)
Gets the name of a weapon set.
int pilot_outfitOff(Pilot *p, PilotOutfitSlot *o)
Disables a given active outfit.
void pilot_weapSetType(Pilot *p, int id, WeaponSetType type)
Changes the weapon sets mode.
void pilot_weapSetAdd(Pilot *p, int id, const PilotOutfitSlot *o, int level)
Adds an outfit to a weapon set.
void player_hailStart(void)
Starts the hail sounds and aborts autoNav.
void player_targetSet(unsigned int id)
Sets the player's target.
void player_destroyed(void)
Player blew up in a fireball.
void player_autonavAbort(const char *reason)
Aborts autonav.
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.
int space_canHyperspace(const Pilot *p)
Checks to make sure if pilot is far enough away to hyperspace.
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.
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,...
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.