19#include "nlua_player.h"
31#include "land_outfits.h"
33#include "map_overlay.h"
37#include "nlua_colour.h"
38#include "nlua_commodity.h"
40#include "nlua_outfit.h"
41#include "nlua_pilot.h"
44#include "nlua_system.h"
50#include "player_autonav.h"
51#include "player_fleet.h"
52#include "player_gui.h"
53#include "player_inventory.h"
59#define PLAYER_CHECK() \
60 if ( player.p == NULL ) \
295 lua_pushstring( L,
player.name );
310 lua_pushstring( L,
player.p->name );
331 money =
CLAMP( CREDITS_MIN, CREDITS_MAX,
332 (credits_t)round( luaL_checknumber( L, 1 ) ) );
334 if ( lua_isstring( L, 2 ) ) {
336 reason = lua_tostring( L, 2 );
338 nohooks = lua_toboolean( L, 2 );
344 p[0].
type = HOOK_PARAM_NUMBER;
345 p[0].u.num = (double)money;
346 if ( reason != NULL ) {
347 p[1].type = HOOK_PARAM_STRING;
350 p[1].type = HOOK_PARAM_NIL;
352 p[2].type = HOOK_PARAM_SENTINEL;
373 credits_t creds = (
player.p == NULL ) ? 0 :
player.p->credits;
376 int decimals = luaL_optinteger( L, 1, -1 );
379 lua_pushnumber( L, creds );
380 if ( decimals >= 0 ) {
381 char buf[ECON_CRED_STRLEN];
383 lua_pushstring( L, buf );
406 int decimals = luaL_optinteger( L, 1, -1 );
417 wealth += po[i].q * po[i].o->price;
422 lua_pushnumber( L, wealth );
423 if ( decimals >= 0 ) {
424 char buf[ECON_CRED_STRLEN];
426 lua_pushstring( L, buf );
444 const char *str = luaL_checkstring( L, 1 );
445 int display = lua_toboolean( L, 2 );
501 str = luaL_checkstring( L, 1 );
502 duration = luaL_optnumber( L, 2, 10. );
503 fontsize = luaL_optinteger( L, 3, OMSG_FONT_DEFAULT_SIZE );
504 col = luaL_optcolour( L, 4, &cWhite );
507 if ( duration < DOUBLE_TOL )
511 id = omsg_add( str, duration, fontsize, col );
512 lua_pushnumber( L,
id );
536 id = luaL_checklong( L, 1 );
537 str = luaL_checkstring( L, 2 );
538 duration = luaL_checknumber( L, 3 );
541 if ( duration < DOUBLE_TOL )
545 ret = omsg_change(
id, str, duration );
546 lua_pushboolean( L, !ret );
559 unsigned int id = luaL_checklong( L, 1 );
575 if ( lua_gettop( L ) == 0 )
578 b = lua_toboolean( L, 1 );
581 player_rmFlag( PLAYER_NOSAVE );
583 player_setFlag( PLAYER_NOSAVE );
627 lua_pushnumber( L, 0 );
645 lua_pushnumber( L, 0 );
646 lua_pushnumber( L, 0 );
648 lua_pushnumber( L,
player.p->fuel );
649 lua_pushnumber( L,
player.p->fuel_consumption );
667 if ( lua_gettop( L ) > 0 ) {
668 double f = luaL_checknumber( L, 1 );
690 lua_pushboolean( L, player_isFlag( PLAYER_AUTONAV ) );
691 lua_pushnumber( L,
player.speed_autonav );
700 double speed = luaL_optnumber( L, 1, -1 );
701 double sound = luaL_optnumber( L, 2, speed );
706 player.speed_autonav = speed;
726 if ( pilot_isFlag(
player.p, PILOT_HYP_PREP ) ||
727 pilot_isFlag(
player.p, PILOT_HYP_BEGIN ) ||
728 pilot_isFlag(
player.p, PILOT_HYPERSPACE ) ) {
729 WARN( _(
"Unable to set autonav target while jumping!" ) );
732 map_select( sys, lua_toboolean( L, 2 ) );
746 const vec2 *pos = luaL_optvector( L, 1, NULL );
750 ovr_autonavPos( pos->
x, pos->
y );
767 const StarSystem *dest;
771 dest = map_getDestination( &jumps );
777 lua_pushnumber( L, jumps );
792 StarSystem *
const *path = map_getRoute();
794 for (
int i = 0; i <
array_size( path ); i++ ) {
797 lua_rawseti( L, -2, i + 1 );
815 const char *str = luaL_optstring( L, 1, NULL );
832 double timer = luaL_optnumber( L, 1, 0. );
872 lua_pushnumber( L,
player.speed / conf.game_speed );
888 double speed = luaL_optnumber( L, 1, -1 );
889 double sound = luaL_optnumber( L, 2, speed );
892 player.speed = speed * conf.game_speed *
player.speed_autonav;
925 const char *abort_msg;
935 b = lua_toboolean( L, 1 );
936 if ( !lua_isnoneornil( L, 2 ) ) {
937 if ( !lua_istable( L, 2 ) )
938 return NLUA_ERROR( L, _(
"Second parameter to cinematics should be a "
939 "table of options or omitted!" ) );
941 lua_getfield( L, 2,
"abort" );
942 if ( !lua_isnil( L, -1 ) )
943 abort_msg = luaL_checkstring( L, -1 );
946 lua_getfield( L, 2,
"gui" );
947 f_gui = lua_toboolean( L, -1 );
950 lua_getfield( L, 2,
"no2x" );
951 f_2x = lua_toboolean( L, -1 );
954 lua_getfield( L, 2,
"speed" );
955 speed = luaL_optnumber( L, -1, 1. );
970 player_setFlag( PLAYER_CINEMATICS );
972 player_setFlag( PLAYER_CINEMATICS_GUI );
974 player_setFlag( PLAYER_CINEMATICS_2X );
983 player_rmFlag( PLAYER_CINEMATICS );
984 player_rmFlag( PLAYER_CINEMATICS_GUI );
985 player_rmFlag( PLAYER_CINEMATICS_2X );
999 lua_pushboolean( L, player_isFlag( PLAYER_CINEMATICS ) );
1013 double spfx_mod = luaL_checknumber( L, 1 );
1043 case PLAYER_BOARD_IMPOSSIBLE:
1044 lua_pushstring( L,
"impossible" );
1046 case PLAYER_BOARD_RETRY:
1047 lua_pushstring( L,
"retry" );
1049 case PLAYER_BOARD_OK:
1050 lua_pushstring( L,
"ok" );
1053 lua_pushstring( L,
"error" );
1083 lua_pushboolean( L,
landed );
1100 return NLUA_ERROR( L, _(
"Player must be landed to force takeoff." ) );
1102 return NLUA_ERROR( L,
1103 _(
"Player must be spaceworthy to force takeoff!" ) );
1122 case PLAYER_LAND_DENIED:
1123 lua_pushstring( L,
"impossible" );
1125 case PLAYER_LAND_OK:
1126 lua_pushstring( L,
"ok" );
1128 case PLAYER_LAND_AGAIN:
1129 lua_pushstring( L,
"retry" );
1132 lua_pushstring( L,
"error" );
1153 if ( sysname == NULL )
1154 return NLUA_ERROR( L, _(
"Spob '%s' is not in a system!" ), spob->
name );
1159 if ( strcmp( sysname,
cur_system->name ) != 0 ) {
1161 pilot_rmFlag(
player.p, PILOT_HYPERSPACE );
1162 pilot_rmFlag(
player.p, PILOT_HYP_BEGIN );
1163 pilot_rmFlag(
player.p, PILOT_HYP_BRAKE );
1164 pilot_rmFlag(
player.p, PILOT_HYP_PREP );
1193 if ( spob->
lua_land != LUA_NOREF ) {
1198 if ( nlua_pcall( spob->
lua_env, 2, 0 ) ) {
1199 NLUA_WARN( L, _(
"Spob '%s' failed to run '%s':\n%s" ), spob->
name,
1200 "land", lua_tostring(
naevL, -1 ) );
1201 lua_pop(
naevL, 1 );
1230 const char *str = NULL;
1232 if ( lua_gettop( L ) > 0 ) {
1233 b = lua_toboolean( L, 1 );
1234 if ( lua_isstring( L, 2 ) )
1235 str = lua_tostring( L, 2 );
1240 player_rmFlag( PLAYER_NOLAND );
1242 player_setFlag( PLAYER_NOLAND );
1272 return NLUA_ERROR( L,
1273 _(
"Must be landed to set the active land window." ) );
1275 str = luaL_checkstring( L, 1 );
1276 if ( strcasecmp( str,
"main" ) == 0 )
1277 win = LAND_WINDOW_MAIN;
1278 else if ( strcasecmp( str,
"bar" ) == 0 )
1279 win = LAND_WINDOW_BAR;
1280 else if ( strcasecmp( str,
"missions" ) == 0 )
1281 win = LAND_WINDOW_MISSION;
1282 else if ( strcasecmp( str,
"outfits" ) == 0 )
1283 win = LAND_WINDOW_OUTFITS;
1284 else if ( strcasecmp( str,
"shipyard" ) == 0 )
1285 win = LAND_WINDOW_SHIPYARD;
1286 else if ( strcasecmp( str,
"equipment" ) == 0 )
1287 win = LAND_WINDOW_EQUIPMENT;
1288 else if ( strcasecmp( str,
"commodity" ) == 0 )
1289 win = LAND_WINDOW_COMMODITY;
1291 NLUA_INVALID_PARAMETER( L, 1 );
1296 lua_pushboolean( L, !ret );
1314 lua_pushboolean( L, ret == 0 );
1319 lua_pushboolean( L, ret == 0 );
1322 NLUA_INVALID_PARAMETER( L, 1 );
1338static PlayerShip_t *playerL_shipvarShip( lua_State *L,
int idx )
1340 if ( lua_isnoneornil( L, idx ) )
1359 const char *str = luaL_checkstring( L, 1 );
1379 const char *str = luaL_checkstring( L, 1 );
1399 const char *str = luaL_checkstring( L, 1 );
1417 if (
player.p == NULL ) {
1424 for (
int i = 0; i <
array_size( ships ); i++ ) {
1427 lua_pushstring( L, ships[i].p->name );
1428 lua_setfield( L, -2,
"name" );
1431 lua_setfield( L, -2,
"ship" );
1433 lua_pushboolean( L, ships[i].deployed );
1434 lua_setfield( L, -2,
"deployed" );
1436 lua_rawseti( L, -2, i + 1 );
1453 if (
player.p == NULL ) {
1464 str = luaL_optstring( L, 1, NULL );
1471 if ( ( str == NULL ) || ( strcmp( str,
player.p->name ) == 0 ) )
1474 for (
int i = 0; i <
array_size( ships ); i++ ) {
1475 if ( strcmp( str, ships[i].p->name ) == 0 ) {
1483 return NLUA_ERROR( L, _(
"Player does not own a ship named '%s'" ), str );
1487 for (
int i = 0; i <
array_size( p->outfits ); i++ ) {
1488 if ( p->outfits[i]->outfit == NULL )
1493 lua_rawseti( L, -2, j++ );
1512 const char *str = luaL_optstring( L, 1, NULL );
1515 if ( ( str == NULL ) || ( strcmp( str,
player.p->name ) == 0 ) )
1518 for (
int i = 0; i <
array_size( ships ); i++ ) {
1519 if ( strcmp( str, ships[i].p->name ) == 0 ) {
1526 return NLUA_ERROR( L, _(
"Player does not own a ship named '%s'" ), str );
1531 lua_setfield( L, -2,
"time_played" );
1534 lua_setfield( L, -2,
"acquired" );
1537 lua_setfield( L, -2,
"acquired_date" );
1540 lua_setfield( L, -2,
"dmg_done_shield" );
1543 lua_setfield( L, -2,
"dmg_done_armour" );
1546 lua_setfield( L, -2,
"dmg_done" );
1549 lua_setfield( L, -2,
"dmg_taken_shield" );
1552 lua_setfield( L, -2,
"dmg_taken_armour" );
1555 lua_setfield( L, -2,
"dmg_taken" );
1558 lua_setfield( L, -2,
"jumped_times" );
1561 lua_setfield( L, -2,
"landed_times" );
1564 lua_setfield( L, -2,
"death_counter" );
1566 for (
int i = 0; i < SHIP_CLASS_TOTAL; i++ )
1568 lua_pushinteger( L, destroyed );
1569 lua_setfield( L, -2,
"ships_destroyed" );
1585 const char *shipname = luaL_checkstring( L, 1 );
1586 int deploy = lua_toboolean( L, 2 );
1606 if (
player.p == NULL ) {
1612 int unequipped_only = lua_toboolean( L, 1 );
1617 for (
int i = 0; i <
array_size( outfits ); i++ ) {
1619 lua_rawseti( L, -2, n++ );
1622 if ( !unequipped_only ) {
1623 for (
int i = 0; i <
array_size( pstack ); i++ ) {
1624 for (
int j = 0; j <
array_size( pstack[i].p->outfits ); j++ ) {
1627 for (
int k = 0; k <
array_size( outfits ); k++ ) {
1628 if ( outfits[k].o == o ) {
1635 lua_rawseti( L, -2, n++ );
1658 if (
player.p == NULL ) {
1659 lua_pushnumber( L, 0. );
1664 int q, unequipped_only;
1668 unequipped_only = lua_toboolean( L, 2 );
1671 if ( unequipped_only )
1675 lua_pushnumber( L, q );
1696 int q = luaL_optinteger( L, 2, 1 );
1721 int q = luaL_optinteger( L, 2, 1 );
1724 if ( lua_isstring( L, 1 ) ) {
1725 const char *str = luaL_checkstring( L, 1 );
1727 if ( strcmp( str,
"all" ) == 0 ) {
1731 for (
int i = 0; i <
array_size( poutfits ); i++ )
1734 for (
int i = 0; i <
array_size( outfits ); i++ ) {
1782 const char *name = luaL_optstring( L, 2, _( s->
name ) );
1783 const char *acquired = luaL_optstring( L, 3, NULL );
1784 int noname = lua_toboolean( L, 4 );
1788 }
while ( new_ship == NULL );
1790 lua_pushstring( L, new_ship->
p->
name );
1814 const char *str = luaL_checkstring( L, 1 );
1815 int ignore_cargo = lua_toboolean( L, 2 );
1816 const char *cur =
player.p->name;
1818 if ( lua_toboolean( L, 3 ) )
1836 if (
player.p == NULL ) {
1848 misn_pushMissionData( L, md );
1850 if ( pm->
title != NULL ) {
1851 lua_pushstring( L, pm->
title );
1852 lua_setfield( L, -2,
"title" );
1854 if ( pm->
desc != NULL ) {
1855 lua_pushstring( L, pm->
desc );
1856 lua_setfield( L, -2,
"desc" );
1858 if ( pm->
reward != NULL ) {
1859 lua_pushstring( L, pm->
reward );
1860 lua_setfield( L, -2,
"reward" );
1863 lua_setfield( L, -2,
"chance" );
1865 lua_setfield( L, -2,
"priority" );
1868 lua_setfield( L, -2,
"chapter" );
1872 lua_setfield( L, -2,
"cond" );
1876 lua_setfield( L, -2,
"done" );
1880 lua_setfield( L, -2,
"spob" );
1884 lua_setfield( L, -2,
"system" );
1886 if ( mis_isFlag( md, MISSION_UNIQUE ) ) {
1887 lua_pushboolean( L, 1 );
1888 lua_setfield( L, -2,
"unique" );
1893 lua_pushboolean( L, 1 );
1894 lua_setfield( L, -2, md->
tags[k] );
1896 lua_setfield( L, -2,
"tags" );
1897 lua_rawseti( L, -2, j++ );
1916 const char *str = luaL_checkstring( L, 1 );
1919 return NLUA_ERROR( L, _(
"Mission '%s' not found in stack" ), str );
1922 lua_pushinteger( L, n );
1924 lua_pushboolean( L, 0 );
1942 const char *str = luaL_checkstring( L, 1 );
1945 return NLUA_ERROR( L, _(
"Mission '%s' not found in stack" ), str );
1958 if (
player.p == NULL ) {
1964 for (
int i = 0; i <
array_size( done ); i++ ) {
1966 lua_rawseti( L, -2, i + 1 );
1984 const char *str = luaL_checkstring( L, 1 );
1987 return NLUA_ERROR( L, _(
"Event '%s' not found in stack" ), str );
2005 const char *str = luaL_checkstring( L, 1 );
2008 return NLUA_ERROR( L, _(
"Event '%s' not found in stack" ), str );
2021 if (
player.p == NULL ) {
2027 for (
int i = 0; i <
array_size( done ); i++ ) {
2028 event_toLuaTable( L, done[i] );
2029 lua_rawseti( L, -2, i + 1 );
2058 for (
int i = 0; i <
array_size( gui ); i++ ) {
2059 lua_pushstring( L, gui[i] );
2060 lua_rawseti( L, -2, i + 1 );
2074 const char *name = luaL_checkstring( L, 1 );
2076 return NLUA_ERROR( L, _(
"GUI '%s' does not exist!" ), name );
2078 player.gui = strdup( name );
2092 if (
player.p == NULL ) {
2099 for (
int i = 0; i <
array_size( pstack ); i++ ) {
2108 if ( ps->
p == NULL )
2109 lua_pushboolean( L, 0 );
2112 lua_rawseti( L, -2, n++ );
2126 lua_pushinteger( L, 0 );
2142 if (
player.p == NULL ) {
2143 lua_pushinteger( L, 0 );
2159 lua_pushinteger( L, 0 );
2178 lua_pushinteger( L, 0 );
2195 int q = luaL_checkinteger( L, 2 );
2197 lua_pushinteger( L, 0 );
2214 int q = luaL_checkinteger( L, 2 );
2216 lua_pushinteger( L, 0 );
2234 int q = luaL_checkinteger( L, 2 );
2236 lua_pushinteger( L, 0 );
2253 if (
player.p == NULL ) {
2260 for (
int i = 0; i <
array_size( call ); i++ ) {
2269 lua_setfield( L, -2,
"c" );
2271 lua_pushinteger( L, q );
2272 lua_setfield( L, -2,
"q" );
2274 lua_rawseti( L, -2, ++n );
2290 if (
player.p == NULL ) {
2296 for (
int i = 0; i <
array_size( inv ); i++ ) {
2300 lua_pushstring( L, pi->
name );
2301 lua_setfield( L, -2,
"name" );
2303 lua_pushinteger( L, pi->
quantity );
2304 lua_setfield( L, -2,
"quantity" );
2306 lua_rawseti( L, -2, i + 1 );
2321 const char *name = luaL_checkstring( L, 1 );
2322 int q = luaL_optinteger( L, 2, 1 );
2324 lua_pushinteger( L, 0 );
2340 const char *name = luaL_checkstring( L, 1 );
2341 int q = luaL_optinteger( L, 2, 1 );
2343 lua_pushinteger( L, 0 );
2358 const char *name = luaL_checkstring( L, 1 );
2360 lua_pushinteger( L, 0 );
2393 const char *name, *pntname;
2394 int no_simulate, silent;
2398 return NLUA_ERROR( L, _(
"Can not teleport the player while landed!" ) );
2401 L, _(
"Can not teleport the player while the comm is open!" ) );
2404 L, _(
"Can not teleport the player while they are boarded!" ) );
2407 pilot_rmFlag(
player.p, PILOT_LANDING );
2419 return NLUA_ERROR( L, _(
"Spob '%s' does not belong to a system." ),
2423 else if ( lua_isstring( L, 1 ) ) {
2424 const char *sysname;
2425 name = lua_tostring( L, 1 );
2427 if ( sysname == NULL ) {
2434 L, _(
"'%s' is not a valid teleportation target." ), name );
2437 return NLUA_ERROR( L, _(
"Spob '%s' does not belong to a system." ),
2442 NLUA_INVALID_PARAMETER( L, 1 );
2444 no_simulate = lua_toboolean( L, 2 );
2445 silent = lua_toboolean( L, 3 );
2449 return NLUA_ERROR( L, _(
"System '%s' does not exist." ), name );
2458 pilot_rmFlag(
player.p, PILOT_HYPERSPACE );
2459 pilot_rmFlag(
player.p, PILOT_HYP_BEGIN );
2460 pilot_rmFlag(
player.p, PILOT_HYP_BRAKE );
2461 pilot_rmFlag(
player.p, PILOT_HYP_PREP );
2505 if ( p->parent == PLAYER_ID ) {
2506 memcpy( &p->solid.pos, &
player.p->solid.pos,
sizeof(
vec2 ) );
2507 vec2_padd( &p->solid.pos, 200. + 200. * RNGF(), 2. * M_PI * RNGF() );
2525 lua_pushnumber( L,
dt_mod );
2543 lua_pushnumber( L,
player.fleet_capacity );
2544 lua_pushnumber( L,
player.fleet_used );
2546 for (
int i = 0; i <
array_size( pships ); i++ ) {
2547 if ( !pships[i].deployed )
2551 lua_pushboolean( L, ( nships == 0 ) ||
2565 player.fleet_capacity = luaL_checkinteger( L, 1 );
2578 lua_pushstring( L,
player.chapter );
2591 const char *str = luaL_checkstring( L, 1 );
2593 player.chapter = strdup( str );
2612 const char *caption = luaL_checkstring( L, 1 );
2613 int priority = luaL_optinteger( L, 3, 5 );
2614 const char *key = luaL_optstring( L, 4,
"" );
2615 luaL_checktype( L, 2, LUA_TFUNCTION );
2616 lua_pushvalue( L, 2 );
2617 id = info_buttonRegister( caption, priority, SDL_GetKeyFromName( key ) );
2618 lua_pushinteger( L,
id );
2630 int id = luaL_checkinteger( L, 1 );
2631 int ret = info_buttonUnregister(
id );
2633 NLUA_WARN( L, _(
"Failed to unregister info button with id '%d'!" ),
id );
2646 player.discover_off = !lua_toboolean( L, 1 );
2660 const char *savename = luaL_optstring( L, 1,
"autosave" );
2661 Spob *savespob = NULL;
2662 Spob *prevspob = NULL;
2663 if ( !lua_isnoneornil( L, 2 ) )
2666 if ( !
landed && ( savespob == NULL ) )
2667 return NLUA_ERROR( L, _(
"Unable to save when not landed and land spob "
2668 "is not specified!" ) );
2669 else if (
landed && ( savespob != NULL ) )
2670 return NLUA_ERROR( L, _(
"Unable to save when landed and land_spob does "
2671 "not match landed spob!" ) );
2673 if ( savespob != NULL ) {
2678 if ( savespob != NULL )
2694 const char *filename =
2695 luaL_checkstring( L, 1 );
2696 if ( strcmp( filename,
"autosave" ) == 0 )
2697 return NLUA_ERROR( L, _(
"Can not back up save to 'autosave'." ) );
2698 snprintf( file,
sizeof( file ),
"saves/%s/autosave.ns",
player.name );
2699 snprintf( backup,
sizeof( backup ),
"saves/%s/%s.ns",
player.name,
2713 player_setFlag( PLAYER_DESTROYED );
2735 lua_setfield( L, -2,
"name" );
2738 lua_setfield( L, -2,
"ship" );
2741 lua_setfield( L, -2,
"shipname" );
2744 lua_setfield( L, -2,
"acquired" );
2747 lua_setfield( L, -2,
"gui" );
2750 lua_setfield( L, -2,
"credits" );
2753 lua_setfield( L, -2,
"date" );
2756 lua_setfield( L, -2,
"system" );
2759 vec2_cset( &v, x, y );
2761 lua_setfield( L, -2,
"position" );
2765 lua_setfield( L, -2,
"mission" );
2770 lua_setfield( L, -2,
"event" );
2774 lua_setfield( L, -2,
"chapter" );
2777 lua_setfield( L, -2,
"spob_lua_default" );
2780 lua_setfield( L, -2,
"dtype_default" );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#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’.
int player_tryBoard(int noisy)
Attempt to board the player's target.
int player_isBoarded(void)
Gets if the player is boarded.
void board_unboard(void)
Forces unboarding of the pilot.
void cam_vel(double vx, double vy)
Sets the camera velocity.
int comm_openPilot(unsigned int pilot)
Opens the communication dialogue with a pilot.
int comm_openSpob(Spob *spob)
Opens a communication dialogue with a spob.
int comm_isOpen(void)
Check to see if the comm window is open.
void comm_queueClose(void)
Queues a close command when possible.
Commodity * commodity_getAll(void)
Gets all the commodities.
void credits2str(char *str, credits_t credits, int decimals)
Converts credits to a usable string for displaying.
int event_alreadyRunning(int data)
Check to see if an event is already running.
int event_dataID(const char *evdata)
Gets the event data id from name.
void events_trigger(EventTrigger_t trigger)
Runs all the events matching a trigger.
void gui_clearMessages(void)
Clears the GUI messages.
const char * gui_pick(void)
Determines which GUI should be used.
int gui_exists(const char *name)
Checks to see if a GUI exists.
int gui_load(const char *name)
Attempts to load the actual GUI.
void gui_reload(void)
Reloads the GUI.
void player_messageRaw(const char *str)
Adds a mesg to the queue to be displayed on screen.
void player_messageToggle(int enable)
Toggles if player should receive messages.
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
int hooks_run(const char *stack)
Runs all the hooks of stack.
void land_queueTakeoff(void)
Queue a takeoff.
int land_setWindow(int window)
Sets the land window tab.
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.
Mission ** player_missions
const MissionData * mission_getFromName(const char *name)
Gets mission data from a name.
int mission_alreadyRunning(const MissionData *misn)
Checks to see if mission is already running.
void missions_run(MissionAvailability loc, int faction, const Spob *pnt, const StarSystem *sys)
Runs missions matching location, all Lua side and one-shot.
int mission_getID(const char *name)
Gets id from mission name.
const MissionData * mission_get(int id)
Gets a MissionData based on ID.
Header file with generic functions and naev-specifics.
int ndata_copyIfExists(const char *file1, const char *file2)
Copy a file, if it exists.
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.
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.
LuaPilot * lua_pushpilot(lua_State *L, LuaPilot pilot)
Pushes a pilot on the stack.
Pilot * luaL_validpilot(lua_State *L, int ind)
Makes sure the pilot is valid or raises a Lua error.
int lua_ispilot(lua_State *L, int ind)
Checks to see if ind is a pilot.
static int playerL_shipDeploy(lua_State *L)
Sets the deployed status of a player's ship.
static int playerL_outfitAdd(lua_State *L)
Adds an outfit to the player's outfit list.
static int playerL_evtActive(lua_State *L)
Checks to see if the player has an event active.
static int playerL_shipvarPush(lua_State *L)
Pushes a ship variable.
static int playerL_shipMetadata(lua_State *L)
Gets meta-data about one of the player's ships.
static int playerL_unboard(lua_State *L)
Unboards the player from its boarded target.
static int playerL_fleetCargoAdd(lua_State *L)
Tries to add an amount of commodity to the player's fleet.
static int playerL_fleetCapacitySet(lua_State *L)
Sets the fleet capacity of the player.
static int playerL_fleetCargoRm(lua_State *L)
Tries to remove an amount of commodity to the player's fleet.
static int playerL_missions(lua_State *L)
Gets the list of the player's active missions.
static int playerL_inventoryRm(lua_State *L)
Removes an item to the player's in-game inventory.
static int playerL_msg(lua_State *L)
Sends the player an in-game message.
static int playerL_cinematicsCheck(lua_State *L)
Checks to see if the game is in cinematics mode.
static int playerL_inventory(lua_State *L)
Gets the contents of the player's inventory.
static int playerL_autonavSetPos(lua_State *L)
Indicates the player where their autonav target position is.
static int playerL_shipSwap(lua_State *L)
Swaps the player's current ship with a ship they own by name.
static int playerL_credits(lua_State *L)
Gets how many credits the player has on him.
static int playerL_outfits(lua_State *L)
Gets all the outfits the player owns.
static int playerL_saveBackup(lua_State *L)
Backs up the player's last autosave with a custom name.
static int playerL_dt_default(lua_State *L)
Gets the current time modifier for the player.
static int playerL_pay(lua_State *L)
Pays the player an amount of money.
static int playerL_shipname(lua_State *L)
Gets the player's ship's name (given by the player).
static int playerL_autonavEnd(lua_State *L)
Ends the autonav system. You probably want to use player.autonavAbort instead of this.
static int playerL_setSpeed(lua_State *L)
Sets the game speed directly.
static int playerL_fuel(lua_State *L)
Gets the amount of fuel a player has.
static int playerL_canDiscover(lua_State *L)
Global toggle to whether or not the player can discover space objects and jumps. Meant to be used wit...
static int playerL_autonavSetSpeed(lua_State *L)
Sets the autonav speed.
static int playerL_isLanded(lua_State *L)
Checks to see if the player is landed or not.
static int playerL_autonavSetTarget(lua_State *L)
Set the autonav target system to travel to.
static int playerL_autonavRoute(lua_State *L)
Gets the player's autonav route.
static int playerL_infoButtonUnregister(lua_State *L)
Unregisters a button in the info window.
static int playerL_landAllow(lua_State *L)
Allows or disallows the player to land.
static int playerL_damageSPFX(lua_State *L)
Applies the damage effects to the player.
static int playerL_ships(lua_State *L)
Gets the names of the player's ships.
static int playerL_evtDoneList(lua_State *L)
Gets a list of all the events the player has done.
static int playerL_takeoff(lua_State *L)
Forces the player to take off if they are landed.
static int playerL_cinematics(lua_State *L)
Puts the game in cinematics mode or back to regular mode.
static int playerL_fleetCapacity(lua_State *L)
Gets the fleet capacity (and used) of the player.
static int playerL_inventoryAdd(lua_State *L)
Adds an item to the player's in-game inventory.
static int playerL_commClose(lua_State *L)
Forces the player to close comm if they are chatting.
static int playerL_autonavAbort(lua_State *L)
Stops the players autonav if active.
static int playerL_speed(lua_State *L)
Gets the current speed of the player.
static int playerL_gui(lua_State *L)
Gets the player's current GUI.
static int playerL_jumps(lua_State *L)
Gets a player's jump range based on their remaining fuel.
static int playerL_fleetCargoJet(lua_State *L)
Tries to remove an amount of commodity to the player's fleet and jettisons it into space.
static const luaL_Reg playerL_methods[]
static int playerL_landWindow(lua_State *L)
Sets the active land window.
static int playerL_outfitRm(lua_State *L)
Removes an outfit from the player's outfit list.
static int playerL_refuel(lua_State *L)
Refuels the player.
static int playerL_tryLand(lua_State *L)
Tries to make the player land.
static int playerL_msgToggle(lua_State *L)
Clears the player's message buffer.
static int playerL_dt_mod(lua_State *L)
Gets the dt_mod of the player, which multiplies all time stuff.
static int playerL_tryBoard(lua_State *L)
Tries to make the player board their target.
static int playerL_teleport(lua_State *L)
Teleports the player to a new spob or system (only if not landed).
static int playerL_getPilot(lua_State *L)
Gets the player's associated pilot.
int nlua_loadPlayer(nlua_env env)
Loads the player Lua library.
static int playerL_chapterSet(lua_State *L)
Sets the player's current chapter.
static int playerL_infoButtonRegister(lua_State *L)
Registers a button in the info window.
static int playerL_shipvarPeek(lua_State *L)
Peeks at a ship variable.
static int playerL_omsgRm(lua_State *L)
Removes an overlay message.
static int playerL_omsgChange(lua_State *L)
Changes an overlay message.
static int playerL_start(lua_State *L)
Gets information about the player's starting point.
static int playerL_fleetList(lua_State *L)
Lists the ships in the player's fleet.
static int playerL_misnDoneList(lua_State *L)
Gets a list of all the missions the player has done.
static int playerL_fleetCargoList(lua_State *L)
Gets the list of all the cargos in the player's fleet.
static int playerL_chapter(lua_State *L)
Gets the player's current chapter.
static int playerL_getname(lua_State *L)
Lua bindings to interact with the player.
static int playerL_omsgAdd(lua_State *L)
Adds an overlay message.
static int playerL_fleetCargoUsed(lua_State *L)
Gets the amount of cargo space used in the player's fleet.
static int playerL_fleetCargoFree(lua_State *L)
Gets the amount of cargo space free in the player's fleet.
static int playerL_outfitNum(lua_State *L)
Gets the number of outfits the player owns in their list (excludes equipped on ships).
static int playerL_inventoryOwned(lua_State *L)
Checks to see how much of an item the player has in their inventory.
static int playerL_shipAdd(lua_State *L)
Gives the player a new ship.
static int playerL_allowSave(lua_State *L)
Sets player save ability.
static int playerL_guiList(lua_State *L)
Lists the GUIs the player can use.
static int playerL_guiSet(lua_State *L)
Sets the player's GUI.
static int playerL_autonavReset(lua_State *L)
Resets the game speed without disabling autonav.
static int playerL_evtDone(lua_State *L)
Checks to see if player has done an event.
static int playerL_getPosition(lua_State *L)
Gets the player's position.
static int playerL_land(lua_State *L)
Automagically lands the player on a spob.
static int playerL_fleetCargoOwned(lua_State *L)
Gets the amount of cargo space used by a specific commodity in the player's fleet.
static int playerL_misnActive(lua_State *L)
Checks to see if the player has a mission active.
static int playerL_wealth(lua_State *L)
Gets how many credits the player owns both directly, and in the form of assets (ships,...
static int playerL_autonav(lua_State *L)
Checks to see if the player has autonav enabled.
static int playerL_msgClear(lua_State *L)
Clears the player's message buffer.
static int playerL_misnDone(lua_State *L)
Checks to see if player has done a mission.
static int playerL_commOpen(lua_State *L)
Opens communication with a pilot or spob.
static int playerL_save(lua_State *L)
Saves the game.
static int playerL_autonavDest(lua_State *L)
Gets the player's long term autonav destination.
static int playerL_shipvarPop(lua_State *L)
Pops a ship variable.
static int playerL_screenshot(lua_State *L)
Takes a screenshot (same as the keyboard action).
static int playerL_fleetCargoMissionFree(lua_State *L)
Gets the free space for mission cargos on the player's ship. This can be less than the amount of free...
static int playerL_gameover(lua_State *L)
Gives the player a game over message.
static int playerL_shipOutfits(lua_State *L)
Gets the outfits for one of the player's ships.
const Ship ** lua_pushship(lua_State *L, const Ship *ship)
Pushes a ship on the stack.
const Ship * luaL_validship(lua_State *L, int ind)
Makes sure the ship is valid or raises a Lua error.
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.
int lua_issystem(lua_State *L, int ind)
Checks to see if ind is a system.
ntime_t * lua_pushtime(lua_State *L, ntime_t time)
Pushes a time on the stack.
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
void gl_setDefViewport(int x, int y, int w, int h)
Sets the default viewport.
void pause_setSpeed(double mod)
Adjusts the game's dt modifier.
void pilot_setCommMsg(Pilot *p, const char *s)
Sets the overhead communication message of the pilot.
static Pilot ** pilot_stack
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
credits_t pilot_worth(const Pilot *p, int count_unique)
Gets the price or worth of a pilot in credits.
int pilot_getJumps(const Pilot *p)
Gets the amount of jumps the pilot has left.
void pilot_clearTrails(Pilot *p)
Resets the trails for a pilot.
void pilot_destealth(Pilot *p)
Destealths a pilot.
void pilot_outfitLOnjumpin(Pilot *pilot)
Runs Lua outfits when pilot jumps into a system.
void pilot_calcStats(Pilot *pilot)
Recalculates the pilot's stats based on his outfits.
int pilot_isSpaceworthy(const Pilot *p)
Pilot safety check - makes sure stats are safe.
void pilot_afterburnOver(Pilot *p)
Deactivates the afterburner.
int pilot_outfitOffAll(Pilot *p)
Disables all active outfits for a pilot.
int player_eventAlreadyDone(int id)
Checks to see if player has already completed a event.
int player_rmOutfit(const Outfit *o, int quantity)
Remove an outfit from the player's outfit stack.
void player_swapShip(const char *shipname, int move_cargo)
Swaps player's current ship with their ship named shipname.
int player_addOutfit(const Outfit *o, int quantity)
Adds an outfit to the player outfit stack.
void player_resetSpeed(void)
Resets the player speed stuff.
const PlayerShip_t * player_getShipStack(void)
Gets the array (array.h) of the player's ships.
PlayerShip_t * player_newShip(const Ship *ship, const char *def_name, int trade, const char *acquired, int noname)
Creates a new ship for player.
void player_rmShip(const char *shipname)
Removes one of the player's ships.
int player_outfitOwnedTotal(const Outfit *o)
PlayerShip_t * player_getPlayerShip(const char *shipname)
Gets a specific ship.
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
int player_missionAlreadyDone(int id)
Checks to see if player has already completed a mission.
credits_t player_modCredits(credits_t amount)
Modifies the amount of credits the player has.
int * player_eventsDoneList(void)
Gets a list of all the events the player has done.
void player_accelOver(void)
Done accelerating.
int player_land(int loud)
Try to land or target closest spob if no land target.
int player_outfitOwned(const Outfit *o)
Gets how many of the outfit the player owns.
void player_targetClearAll(void)
Clears all player targets: hyperspace, spob, asteroid, etc...
void player_nolandMsg(const char *str)
Sets the no land message.
const PlayerOutfit_t * player_getOutfits(void)
Gets an array (array.h) of the player's outfits.
void player_screenshot(void)
Takes a screenshot.
int * player_missionsDoneList(void)
Gets a list of all the missions the player has done.
void player_autonavEnd(void)
Ends the autonav.
void player_autonavReset(double s)
Resets the game speed without disabling autonav.
void player_autonavAbort(const char *reason)
Aborts autonav.
int pfleet_cargoFree(void)
Gets the total amount of free cargo space in the player's fleet.
int pfleet_cargoOwned(const Commodity *com)
Gets the total amount of a commodity type owned by the player's fleet.
int pfleet_cargoAdd(const Commodity *com, int q)
Adds some cargo to the player's fleet.
int pfleet_cargoRm(const Commodity *com, int q, int jet)
Removes some cargo from the player's fleet.
int pfleet_cargoMissionFree(void)
Gets the free mission cargo space in the player's fleet.
int pfleet_cargoUsed(void)
Gets the total cargo space used by the player's fleet.
void pfleet_update(void)
Updates the used fleet capacity of the player.
const char ** player_guiList(void)
Gets the list of GUIs.
int player_inventoryAdd(const char *name, int amount)
Adds an item to the player inventory.
int player_inventoryRemove(const char *name, int amount)
Removes an item from the player inventory.
const PlayerItem * player_inventory(void)
Gets the whole player inventory.
int player_inventoryAmount(const char *name)
Gets the amount of an item the player has.
int save_all_with_name(const char *name)
Saves the current game.
const Ship * ship_get(const char *name)
Gets a ship based on its name.
void sound_setSpeed(double s)
Sets the speed to play the sound at.
void space_init(const char *sysname, int do_simulate)
Initializes the system.
void space_gfxUnload(StarSystem *sys)
Unloads all the graphics for a star system.
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
StarSystem * system_getIndex(int id)
Get the system by its index.
int spob_index(const Spob *p)
Gets the ID of a spob.
const char * system_existsCase(const char *sysname)
Checks to see if a system exists case insensitively.
StarSystem * system_get(const char *sysname)
Get the system from its name.
const char * spob_getSystemName(const char *spobname)
Get the name of a system from a spobname.
void space_queueLand(Spob *pnt)
Cues a spob to be landed on. This is not done immediately, but when the engine thinks it is ok to do.
void spob_luaInitMem(const Spob *spob)
Initializes the memory fo a spob.
int system_index(const StarSystem *sys)
Gets the index of a star system.
void spfx_shake(double mod)
Increases the current rumble level.
void spfx_damage(double mod)
Increases the current damage level.
const char * start_acquired(void)
Gets the module's starting ship was acquired.
const char * start_event(void)
Gets the starting event of the player.
const char * start_mission(void)
Gets the starting mission of the player.
void start_position(double *x, double *y)
Gets the starting position of the player.
const char * start_chapter(void)
Gets the player's starting chapter.
const char * start_name(void)
Gets the module name.
const char * start_dtype_default(void)
Gets the default damage type.
const char * start_ship(void)
Gets the module player starting ship.
ntime_t start_date(void)
Gets the starting date.
const char * start_spob_lua_default(void)
Gets the default spob Lua file.
const char * start_shipname(void)
Gets the module's starting ship's name.
const char * start_gui(void)
Gets the module's starting ship was acquired.
const char * start_system(void)
Gets the starting system name.
unsigned int start_credits(void)
Gets the player's starting credits.
The actual hook parameter.
Represents an active mission.
A ship outfit, depends radically on the type.
The representation of an in-game pilot.
PilotOutfitSlot ** outfits
Represents an item in the player inventory.
unsigned int death_counter
unsigned int landed_times
unsigned int ships_destroyed[SHIP_CLASS_TOTAL]
unsigned int jumped_times
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Contains a mission variable.