naev 0.11.5
nlua_player.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
10#include <lauxlib.h>
11#include <lua.h>
12#include <math.h>
13#include <stdio.h>
14#include <stdlib.h>
15
16#include "naev.h"
19#include "nlua_player.h"
20
21#include "array.h"
22#include "board.h"
23#include "comm.h"
24#include "event.h"
25#include "gui.h"
26#include "gui_omsg.h"
27#include "hook.h"
28#include "info.h"
29#include "land.h"
30#include "land_outfits.h"
31#include "log.h"
32#include "map.h"
33#include "map_overlay.h"
34#include "menu.h"
35#include "mission.h"
36#include "ndata.h"
37#include "nlua_colour.h"
38#include "nlua_commodity.h"
39#include "nlua_outfit.h"
40#include "nlua_pilot.h"
41#include "nlua_spob.h"
42#include "nlua_ship.h"
43#include "nlua_system.h"
44#include "nlua_time.h"
45#include "nlua_vec2.h"
46#include "nlua_misn.h"
47#include "nluadef.h"
48#include "nstring.h"
49#include "pause.h"
50#include "player.h"
51#include "player_fleet.h"
52#include "player_inventory.h"
53#include "player_gui.h"
54#include "save.h"
55#include "start.h"
56
57#define PLAYER_CHECK() if (player.p == NULL) return 0
58
59/* Player methods. */
60static int playerL_getname( lua_State *L );
61static int playerL_shipname( lua_State *L );
62static int playerL_pay( lua_State *L );
63static int playerL_credits( lua_State *L );
64static int playerL_wealth( lua_State *L );
65static int playerL_msg( lua_State *L );
66static int playerL_msgClear( lua_State *L );
67static int playerL_msgToggle( lua_State *L );
68static int playerL_omsgAdd( lua_State *L );
69static int playerL_omsgChange( lua_State *L );
70static int playerL_omsgRm( lua_State *L );
71static int playerL_allowSave( lua_State *L );
72/* Faction stuff. */
73static int playerL_getPosition( lua_State *L );
74static int playerL_getPilot( lua_State *L );
75/* Fuel stuff. */
76static int playerL_jumps( lua_State *L );
77static int playerL_fuel( lua_State *L );
78static int playerL_refuel( lua_State *L );
79static int playerL_autonav( lua_State *L );
80static int playerL_autonavSetPos( lua_State *L );
81static int playerL_autonavDest( lua_State *L );
82static int playerL_autonavAbort( lua_State *L );
83static int playerL_autonavReset( lua_State *L );
84static int playerL_autonavEnd( lua_State *L );
85/* Cinematics. */
86static int playerL_dt_default( lua_State *L );
87static int playerL_speed( lua_State *L );
88static int playerL_setSpeed( lua_State *L );
89static int playerL_cinematics( lua_State *L );
90static int playerL_cinematicsCheck( lua_State *L );
91static int playerL_damageSPFX( lua_State *L );
92static int playerL_screenshot( lua_State *L );
93/* Board stuff. */
94static int playerL_tryBoard( lua_State *L );
95static int playerL_unboard( lua_State *L );
96/* Land stuff. */
97static int playerL_isLanded( lua_State *L );
98static int playerL_takeoff( lua_State *L );
99static int playerL_tryLand( lua_State *L );
100static int playerL_land( lua_State *L );
101static int playerL_landAllow( lua_State *L );
102static int playerL_landWindow( lua_State *L );
103/* Hail stuff. */
104static int playerL_commclose( lua_State *L );
105/* Shipvars. */
106static int playerL_shipvarPeek( lua_State *L );
107static int playerL_shipvarPush( lua_State *L );
108static int playerL_shipvarPop( lua_State *L );
109/* Outfit and ship management stuff. */
110static int playerL_ships( lua_State *L );
111static int playerL_shipOutfits( lua_State *L );
112static int playerL_shipMetadata( lua_State *L );
113static int playerL_shipDeploy( lua_State *L );
114static int playerL_outfits( lua_State *L );
115static int playerL_outfitNum( lua_State *L );
116static int playerL_outfitAdd( lua_State *L );
117static int playerL_outfitRm( lua_State *L );
118static int playerL_shipAdd( lua_State *L );
119static int playerL_shipSwap( lua_State *L );
120/* Mission/event management stuff. */
121static int playerL_missions( lua_State *L );
122static int playerL_misnActive( lua_State *L );
123static int playerL_misnDone( lua_State *L );
124static int playerL_misnDoneList( lua_State *L );
125static int playerL_evtActive( lua_State *L );
126static int playerL_evtDone( lua_State *L );
127static int playerL_evtDoneList( lua_State *L );
128/* Handle GUI. */
129static int playerL_gui( lua_State *L );
130static int playerL_guiList( lua_State *L );
131static int playerL_guiSet( lua_State *L );
132/* Fleet stuff. */
133static int playerL_fleetList( lua_State *L );
134static int playerL_fleetCargoFree( lua_State *L );
135static int playerL_fleetCargoUsed( lua_State *L );
136static int playerL_fleetCargoOwned( lua_State *L );
137static int playerL_fleetCargoAdd( lua_State *L );
138static int playerL_fleetCargoRm( lua_State *L );
139static int playerL_fleetCargoJet( lua_State *L );
140static int playerL_fleetCargoList( lua_State *L );
141/* Inventory. */
142static int playerL_inventory( lua_State *L );
143static int playerL_inventoryAdd( lua_State *L );
144static int playerL_inventoryRm( lua_State *L );
145static int playerL_inventoryOwned( lua_State *L );
146/* Misc stuff. */
147static int playerL_teleport( lua_State *L );
148static int playerL_dt_mod( lua_State *L );
149static int playerL_fleetCapacity( lua_State *L );
150static int playerL_fleetCapacitySet( lua_State *L );
151static int playerL_chapter( lua_State *L );
152static int playerL_chapterSet( lua_State *L );
153static int playerL_infoButtonRegister( lua_State *L );
154static int playerL_infoButtonUnregister( lua_State *L );
155static int playerL_canDiscover( lua_State *L );
156static int playerL_save( lua_State *L );
157static int playerL_saveBackup( lua_State *L );
158static int playerL_gameover( lua_State *L );
159static int playerL_start( lua_State *L );
160static const luaL_Reg playerL_methods[] = {
161 { "name", playerL_getname },
162 { "ship", playerL_shipname },
163 { "pay", playerL_pay },
164 { "credits", playerL_credits },
165 { "wealth", playerL_wealth },
166 { "msg", playerL_msg },
167 { "msgClear", playerL_msgClear },
168 { "msgToggle", playerL_msgToggle },
169 { "omsgAdd", playerL_omsgAdd },
170 { "omsgChange", playerL_omsgChange },
171 { "omsgRm", playerL_omsgRm },
172 { "allowSave", playerL_allowSave },
173 { "pos", playerL_getPosition },
174 { "pilot", playerL_getPilot },
175 { "jumps", playerL_jumps },
176 { "fuel", playerL_fuel },
177 { "refuel", playerL_refuel },
178 { "autonav", playerL_autonav },
179 { "autonavSetPos", playerL_autonavSetPos },
180 { "autonavDest", playerL_autonavDest },
181 { "autonavAbort", playerL_autonavAbort },
182 { "autonavReset", playerL_autonavReset },
183 { "autonavEnd", playerL_autonavEnd },
184 { "dt_default", playerL_dt_default },
185 { "speed", playerL_speed },
186 { "setSpeed", playerL_setSpeed },
187 { "cinematics", playerL_cinematics },
188 { "cinematicsCheck", playerL_cinematicsCheck },
189 { "damageSPFX", playerL_damageSPFX },
190 { "screenshot", playerL_screenshot },
191 { "tryBoard", playerL_tryBoard },
192 { "unboard", playerL_unboard },
193 { "isLanded", playerL_isLanded },
194 { "takeoff", playerL_takeoff },
195 { "tryLand", playerL_tryLand },
196 { "land", playerL_land },
197 { "landAllow", playerL_landAllow },
198 { "landWindow", playerL_landWindow },
199 { "commClose", playerL_commclose },
200 { "shipvarPeek", playerL_shipvarPeek },
201 { "shipvarPush", playerL_shipvarPush },
202 { "shipvarPop", playerL_shipvarPop },
203 { "ships", playerL_ships },
204 { "shipOutfits", playerL_shipOutfits },
205 { "shipMetadata", playerL_shipMetadata },
206 { "shipDeploy", playerL_shipDeploy },
207 { "outfits", playerL_outfits },
208 { "outfitNum", playerL_outfitNum },
209 { "outfitAdd", playerL_outfitAdd },
210 { "outfitRm", playerL_outfitRm },
211 { "shipAdd", playerL_shipAdd },
212 { "shipSwap", playerL_shipSwap },
213 { "missions", playerL_missions },
214 { "misnActive", playerL_misnActive },
215 { "misnDone", playerL_misnDone },
216 { "misnDoneList", playerL_misnDoneList },
217 { "evtActive", playerL_evtActive },
218 { "evtDone", playerL_evtDone },
219 { "evtDoneList", playerL_evtDoneList },
220 { "gui", playerL_gui },
221 { "guiList", playerL_guiList },
222 { "guiSet", playerL_guiSet },
223 { "fleetList", playerL_fleetList },
224 { "fleetCargoFree", playerL_fleetCargoFree },
225 { "fleetCargoUsed", playerL_fleetCargoUsed },
226 { "fleetCargoOwned", playerL_fleetCargoOwned },
227 { "fleetCargoAdd", playerL_fleetCargoAdd },
228 { "fleetCargoRm", playerL_fleetCargoRm },
229 { "fleetCargoJet", playerL_fleetCargoJet },
230 { "fleetCargoList", playerL_fleetCargoList },
231 { "inventory", playerL_inventory },
232 { "inventoryAdd", playerL_inventoryAdd },
233 { "inventoryRm", playerL_inventoryRm },
234 { "inventoryOwned", playerL_inventoryOwned },
235 { "teleport", playerL_teleport },
236 { "dt_mod", playerL_dt_mod },
237 { "fleetCapacity", playerL_fleetCapacity },
238 { "fleetCapacitySet", playerL_fleetCapacitySet },
239 { "chapter", playerL_chapter },
240 { "chapterSet", playerL_chapterSet },
241 { "infoButtonRegister", playerL_infoButtonRegister },
242 { "infoButtonUnregister", playerL_infoButtonUnregister },
243 { "canDiscover", playerL_canDiscover },
244 { "save", playerL_save },
245 { "saveBackup", playerL_saveBackup },
246 { "gameover", playerL_gameover },
247 { "start", playerL_start },
248 {0,0}
249};
255int nlua_loadPlayer( nlua_env env )
256{
257 nlua_register(env, "player", playerL_methods, 0);
258 return 0;
259}
260
278static int playerL_getname( lua_State *L )
279{
280 PLAYER_CHECK();
281 lua_pushstring(L,player.name);
282 return 1;
283}
292static int playerL_shipname( lua_State *L )
293{
294 PLAYER_CHECK();
295 lua_pushstring(L,player.p->name);
296 return 1;
297}
307static int playerL_pay( lua_State *L )
308{
309 PLAYER_CHECK();
310
311 credits_t money;
312 int nohooks;
313 const char *reason;
314
315 money = CLAMP( CREDITS_MIN, CREDITS_MAX, (credits_t)round(luaL_checknumber(L,1)) );
316 player_modCredits( money );
317 if (lua_isstring(L,2)) {
318 nohooks = 0;
319 reason = lua_tostring(L,2);
320 }
321 else {
322 nohooks = lua_toboolean(L,2);
323 reason = NULL;
324 }
325
326 if (!nohooks) {
327 HookParam p[3];
328 p[0].type = HOOK_PARAM_NUMBER;
329 p[0].u.num = (double)money;
330 if (reason != NULL) {
331 p[1].type = HOOK_PARAM_STRING;
332 p[1].u.str = reason;
333 }
334 else {
335 p[1].type = HOOK_PARAM_NIL;
336 }
337 p[2].type = HOOK_PARAM_SENTINEL;
338 hooks_runParam( "pay", p );
339 }
340
341 return 0;
342}
343
355static int playerL_credits( lua_State *L )
356{
357 credits_t creds = (player.p==NULL) ? 0 : player.p->credits;
358
359 /* Parse parameters. */
360 int decimals = luaL_optinteger(L,1,-1);
361
362 /* Push return. */
363 lua_pushnumber(L, creds);
364 if (decimals >= 0) {
365 char buf[ ECON_CRED_STRLEN ];
366 credits2str( buf, creds, decimals );
367 lua_pushstring(L, buf);
368 return 2;
369 }
370 return 1;
371}
372
384static int playerL_wealth( lua_State *L )
385{
386 credits_t wealth;
387 /* Parse parameters. */
388 int decimals = luaL_optinteger(L,1,-1);
389
390 if (player.p != NULL) {
391 const PlayerShip_t *ps = player_getShipStack();
392 const PlayerOutfit_t *po = player_getOutfits();
393 wealth = player.p->credits + pilot_worth( player.p, 0 );
394
395 /* Compute total wealth. */
396 for (int i=0; i<array_size(ps); i++)
397 wealth += pilot_worth( ps[i].p, 0 );
398 for (int i=0; i<array_size(po); i++)
399 wealth += po[i].q * po[i].o->price;
400 }
401 else
402 wealth = 0;
403
404 /* Push return. */
405 lua_pushnumber(L, wealth);
406 if (decimals >= 0) {
407 char buf[ ECON_CRED_STRLEN ];
408 credits2str( buf, wealth, decimals );
409 lua_pushstring(L, buf);
410 return 2;
411 }
412 return 1;
413}
414
422static int playerL_msg( lua_State *L )
423{
424 PLAYER_CHECK();
425
426 const char *str = luaL_checkstring(L,1);
427 int display = lua_toboolean(L,2);
429 if (display)
430 pilot_setCommMsg( player.p, str );
431
432 return 0;
433}
439static int playerL_msgClear( lua_State *L )
440{
441 (void) L;
442 PLAYER_CHECK();
444 return 0;
445}
452static int playerL_msgToggle( lua_State *L )
453{
454 PLAYER_CHECK();
455 player_messageToggle( lua_toboolean(L,1) );
456 return 0;
457}
469static int playerL_omsgAdd( lua_State *L )
470{
471 const char *str;
472 double duration;
473 unsigned int id;
474 int fontsize;
475 const glColour *col;
476
477 PLAYER_CHECK();
478
479 /* Input. */
480 str = luaL_checkstring(L,1);
481 duration = luaL_optnumber(L,2,10.);
482 fontsize = luaL_optinteger(L,3,OMSG_FONT_DEFAULT_SIZE);
483 col = luaL_optcolour(L,4,&cWhite);
484
485 /* Infinity. */
486 if (duration < 1e-10)
487 duration = INFINITY;
488
489 /* Output. */
490 id = omsg_add( str, duration, fontsize, col );
491 lua_pushnumber( L, id );
492 return 1;
493}
504static int playerL_omsgChange( lua_State *L )
505{
506 const char *str;
507 double duration;
508 unsigned int id;
509 int ret;
510
511 PLAYER_CHECK();
512
513 /* Input. */
514 id = luaL_checklong(L,1);
515 str = luaL_checkstring(L,2);
516 duration = luaL_checknumber(L,3);
517
518 /* Infinity. */
519 if (duration < 1e-10)
520 duration = INFINITY;
521
522 /* Output. */
523 ret = omsg_change( id, str, duration );
524 lua_pushboolean(L,!ret);
525 return 1;
526}
534static int playerL_omsgRm( lua_State *L )
535{
536 PLAYER_CHECK();
537 unsigned int id = luaL_checklong(L,1);
538 omsg_rm( id );
539 return 0;
540}
548static int playerL_allowSave( lua_State *L )
549{
550 PLAYER_CHECK();
551 unsigned int b;
552 if (lua_gettop(L)==0)
553 b = 1;
554 else
555 b = lua_toboolean(L, 1);
556
557 if (b)
558 player_rmFlag(PLAYER_NOSAVE);
559 else
560 player_setFlag(PLAYER_NOSAVE);
561 return 0;
562}
563
572static int playerL_getPosition( lua_State *L )
573{
574 PLAYER_CHECK();
576 return 1;
577}
578
585static int playerL_getPilot( lua_State *L )
586{
587 /* No need to run check here or stuff that depends on player.pilot() working will fail. */
588 lua_pushpilot(L, PLAYER_ID);
589 return 1;
590}
591
600static int playerL_jumps( lua_State *L )
601{
602 if (player.p == NULL)
603 lua_pushnumber(L, 0);
604 else
605 lua_pushnumber(L, pilot_getJumps(player.p));
606 return 1;
607}
608
618static int playerL_fuel( lua_State *L )
619{
620 if (player.p == NULL) {
621 lua_pushnumber(L,0);
622 lua_pushnumber(L,0);
623 }
624 else {
625 lua_pushnumber(L,player.p->fuel);
626 lua_pushnumber(L,player.p->fuel_consumption);
627 }
628 return 2;
629}
630
640static int playerL_refuel( lua_State *L )
641{
642 PLAYER_CHECK();
643
644 if (lua_gettop(L) > 0) {
645 double f = luaL_checknumber(L,1);
646 player.p->fuel += f;
647 }
648 else
650
651 /* Make sure value is valid. */
653
654 return 0;
655}
656
664static int playerL_autonav( lua_State *L )
665{
666 PLAYER_CHECK();
667 lua_pushboolean( L, player_isFlag( PLAYER_AUTONAV ) );
668 return 1;
669}
670
677static int playerL_autonavSetPos( lua_State *L )
678{
679 const vec2 *pos = luaL_optvector(L,1,NULL);
680 if (pos==NULL)
681 ovr_autonavClear();
682 else
683 ovr_autonavPos( pos->x, pos->y );
684 return 0;
685}
686
696static int playerL_autonavDest( lua_State *L )
697{
698 LuaSystem ls;
699 StarSystem *dest;
700 int jumps;
701
702 /* Get destination. */
703 dest = map_getDestination( &jumps );
704 if (dest == NULL)
705 return 0;
706
707 ls = system_index( dest );
708 lua_pushsystem( L, ls );
709 lua_pushnumber( L, jumps );
710 return 2;
711}
712
723static int playerL_autonavAbort( lua_State *L )
724{
725 const char *str = luaL_optstring(L,1,NULL);
726 player_autonavAbort( str );
727 return 0;
728}
729
738static int playerL_autonavReset( lua_State *L )
739{
740 double timer = luaL_optnumber(L,1,0.);
741 player_autonavReset( timer );
742 return 0;
743}
744
751static int playerL_autonavEnd( lua_State *L )
752{
753 (void) L;
755 return 0;
756}
757
758static int playerL_dt_default( lua_State *L )
759{
760 lua_pushnumber( L, player_dt_default() );
761 return 1;
762}
763
764static int playerL_speed( lua_State *L )
765{
766 lua_pushnumber( L, player.speed );
767 return 1;
768}
769
778static int playerL_setSpeed( lua_State *L )
779{
780 double speed = luaL_optnumber( L, 1, -1 );
781 double sound = luaL_optnumber( L, 2, speed );
782 int noset = lua_toboolean( L, 3 );
783
784 if (speed > 0.) {
785 if (!noset)
786 player.speed = speed;
787 pause_setSpeed( speed );
788 sound_setSpeed( sound );
789 }
790 else {
791 if (!noset)
792 player.speed = 1.;
794 }
795
796 return 0;
797}
798
815static int playerL_cinematics( lua_State *L )
816{
817 int b, f_gui, f_2x;
818 const char *abort_msg;
819 double speed;
820
821 /* Defaults. */
822 abort_msg= NULL;
823 f_gui = 0;
824 f_2x = 0;
825 speed = 1.;
826
827 /* Parse parameters. */
828 b = lua_toboolean( L, 1 );
829 if (!lua_isnoneornil(L,2)) {
830 if (!lua_istable(L,2))
831 return NLUA_ERROR( L, _("Second parameter to cinematics should be a table of options or omitted!") );
832
833 lua_getfield( L, 2, "abort" );
834 if (!lua_isnil( L, -1 ))
835 abort_msg = luaL_checkstring( L, -1 );
836 lua_pop( L, 1 );
837
838 lua_getfield( L, 2, "gui" );
839 f_gui = lua_toboolean(L, -1);
840 lua_pop( L, 1 );
841
842 lua_getfield( L, 2, "no2x" );
843 f_2x = lua_toboolean(L, -1);
844 lua_pop( L, 1 );
845
846 lua_getfield( L, 2, "speed" );
847 speed = luaL_optnumber(L,-1,1.);
848 lua_pop( L, 1 );
849 }
850
851 if (b) {
852 /* Reset speeds. This will override the player's ship base speed. */
853 player.speed = speed;
854 sound_setSpeed( speed );
855 pause_setSpeed( speed );
856
857 /* Get rid of stuff that could be bothersome. */
858 player_autonavAbort( abort_msg );
859 ovr_setOpen(0);
860
861 /* Handle options. */
862 player_setFlag( PLAYER_CINEMATICS );
863 if (!f_gui)
864 player_setFlag( PLAYER_CINEMATICS_GUI );
865 if (f_2x)
866 player_setFlag( PLAYER_CINEMATICS_2X );
867
868 /* Redo viewport. */
870 }
871 else {
872 /* Reset speed properly to player speed. */
874
875 /* Clean up flags. */
876 player_rmFlag( PLAYER_CINEMATICS );
877 player_rmFlag( PLAYER_CINEMATICS_GUI );
878 player_rmFlag( PLAYER_CINEMATICS_2X );
879
880 /* Reload GUI. */
881 gui_reload();
882 }
883
884 return 0;
885}
886
890static int playerL_cinematicsCheck( lua_State *L )
891{
892 lua_pushboolean( L, player_isFlag( PLAYER_CINEMATICS ) );
893 return 1;
894}
895
902static int playerL_damageSPFX( lua_State *L )
903{
904 double spfx_mod = luaL_checknumber(L,1);
905 spfx_shake( spfx_mod );
906 spfx_damage( spfx_mod );
907 return 0;
908}
909
915static int playerL_screenshot( lua_State *L )
916{
917 (void) L;
919 return 0;
920}
921
929static int playerL_tryBoard( lua_State *L )
930{
931 int ret = player_tryBoard( lua_toboolean(L,1) );
932 switch (ret) {
933 case PLAYER_BOARD_IMPOSSIBLE:
934 lua_pushstring(L,"impossible");
935 break;
936 case PLAYER_BOARD_RETRY:
937 lua_pushstring(L,"retry");
938 break;
939 case PLAYER_BOARD_OK:
940 lua_pushstring(L,"ok");
941 break;
942 default:
943 lua_pushstring(L,"error");
944 break;
945 }
946 return 1;
947}
948
958static int playerL_unboard( lua_State *L )
959{
960 (void) L;
962 return 0;
963}
964
971static int playerL_isLanded( lua_State *L )
972{
973 lua_pushboolean( L, landed );
974 return 1;
975}
976
985static int playerL_takeoff( lua_State *L )
986{
987 PLAYER_CHECK();
988
989 if (!landed)
990 return NLUA_ERROR(L,_("Player must be landed to force takeoff."));
992 return NLUA_ERROR(L,_("Player must be spaceworthy to force takeoff!"));
993
995
996 return 0;
997}
998
1006static int playerL_tryLand( lua_State *L )
1007{
1008 int ret = player_land( lua_toboolean(L,1) );
1009 switch (ret) {
1010 case PLAYER_LAND_DENIED:
1011 lua_pushstring(L,"impossible");
1012 break;
1013 case PLAYER_LAND_OK:
1014 lua_pushstring(L,"ok");
1015 break;
1016 case PLAYER_LAND_AGAIN:
1017 lua_pushstring(L,"retry");
1018 break;
1019 default:
1020 lua_pushstring(L,"error");
1021 break;
1022 }
1023 return 1;
1024}
1025
1034static int playerL_land( lua_State *L )
1035{
1036 PLAYER_CHECK();
1037
1038 Spob *spob = luaL_validspob(L,1);
1039 const char *sysname = spob_getSystem( spob->name );
1040 if (sysname == NULL)
1041 return NLUA_ERROR(L,_("Spob '%s' is not in a system!"), spob->name);
1042
1043 /* Unboard just in case. */
1044 board_unboard();
1045
1046 if (strcmp(sysname,cur_system->name) != 0) {
1047 /* Refer to playerL_teleport for the voodoo that happens here. */
1048 pilot_rmFlag( player.p, PILOT_HYPERSPACE );
1049 pilot_rmFlag( player.p, PILOT_HYP_BEGIN );
1050 pilot_rmFlag( player.p, PILOT_HYP_BRAKE );
1051 pilot_rmFlag( player.p, PILOT_HYP_PREP );
1054
1056
1058
1059 space_init( sysname, 0 );
1060
1061 ovr_initAlpha();
1062 }
1063 player.p->solid.pos = spob->pos; /* Set position to target. */
1064
1065 /* End autonav. */
1067
1068 /* Stop afterburning. */
1070 /* Stop accelerating. */
1072 /* Stop stealth. */
1074
1075 /* Stop all on outfits. */
1076 if (pilot_outfitOffAll( player.p ) > 0)
1078
1079 /* Do whatever the spob wants to do. */
1080 if (spob->lua_land != LUA_NOREF) {
1081 spob_luaInitMem( spob );
1082 lua_rawgeti(naevL, LUA_REGISTRYINDEX, spob->lua_land); /* f */
1083 lua_pushspob( naevL, spob_index(spob) );
1084 lua_pushpilot( naevL, player.p->id );
1085 if (nlua_pcall( spob->lua_env, 2, 0 )) {
1086 WARN(_("Spob '%s' failed to run '%s':\n%s"), spob->name, "land", lua_tostring(naevL,-1));
1087 lua_pop(naevL,1);
1088 }
1089
1090 return 0;
1091 }
1092
1093 space_queueLand( spob );
1094 return 0;
1095}
1096
1111static int playerL_landAllow( lua_State *L )
1112{
1113 int b;
1114 const char *str = NULL;
1115
1116 if (lua_gettop(L) > 0) {
1117 b = lua_toboolean(L,1);
1118 if (lua_isstring(L,2))
1119 str = lua_tostring(L,2);
1120 }
1121 else
1122 b = 1;
1123
1124 if (b)
1125 player_rmFlag( PLAYER_NOLAND );
1126 else {
1127 player_setFlag( PLAYER_NOLAND );
1128 player_nolandMsg( str );
1129 }
1130 return 0;
1131}
1132
1150static int playerL_landWindow( lua_State *L )
1151{
1152 int ret;
1153 const char *str;
1154 int win;
1155
1156 if (!landed)
1157 return NLUA_ERROR(L, _("Must be landed to set the active land window."));
1158
1159 str = luaL_checkstring(L,1);
1160 if (strcasecmp(str,"main")==0)
1161 win = LAND_WINDOW_MAIN;
1162 else if (strcasecmp(str,"bar")==0)
1163 win = LAND_WINDOW_BAR;
1164 else if (strcasecmp(str,"missions")==0)
1165 win = LAND_WINDOW_MISSION;
1166 else if (strcasecmp(str,"outfits")==0)
1167 win = LAND_WINDOW_OUTFITS;
1168 else if (strcasecmp(str,"shipyard")==0)
1169 win = LAND_WINDOW_SHIPYARD;
1170 else if (strcasecmp(str,"equipment")==0)
1171 win = LAND_WINDOW_EQUIPMENT;
1172 else if (strcasecmp(str,"commodity")==0)
1173 win = LAND_WINDOW_COMMODITY;
1174 else
1175 NLUA_INVALID_PARAMETER(L,1);
1176
1177 /* Sets the window. */
1178 ret = land_setWindow( win );
1179
1180 lua_pushboolean( L, !ret );
1181 return 1;
1182}
1183
1189static int playerL_commclose( lua_State *L )
1190{
1191 (void) L;
1193 return 0;
1194}
1195
1196static PlayerShip_t *playerL_shipvarShip( lua_State *L, int idx )
1197{
1198 if (lua_isnoneornil(L,idx))
1199 return &player.ps;
1200 return player_getPlayerShip( luaL_checkstring(L,idx) );
1201}
1202
1212static int playerL_shipvarPeek( lua_State *L )
1213{
1214 PLAYER_CHECK();
1215 const char *str = luaL_checkstring(L,1);
1216 PlayerShip_t *ps = playerL_shipvarShip(L,2);
1217 const lvar *var = lvar_get( ps->p->shipvar, str );
1218 if (var != NULL)
1219 return lvar_push( L, var );
1220 return 0;
1221}
1222
1231static int playerL_shipvarPush( lua_State *L )
1232{
1233 PLAYER_CHECK();
1234 const char *str = luaL_checkstring(L,1);
1235 lvar var = lvar_tovar( L, str, 2 );
1236 PlayerShip_t *ps = playerL_shipvarShip(L,3);
1237 if (ps->p->shipvar==NULL)
1238 ps->p->shipvar = array_create( lvar );
1239 lvar_addArray( &ps->p->shipvar, &var, 1 );
1240 return 0;
1241}
1242
1250static int playerL_shipvarPop( lua_State *L )
1251{
1252 PLAYER_CHECK();
1253 const char *str = luaL_checkstring(L,1);
1254 PlayerShip_t *ps = playerL_shipvarShip(L,2);
1255 lvar *var = lvar_get( ps->p->shipvar, str );
1256 if (var != NULL)
1257 lvar_rmArray( &ps->p->shipvar, var );
1258 return 0;
1259}
1260
1269static int playerL_ships( lua_State *L )
1270{
1271 if (player.p == NULL) {
1272 lua_newtable(L);
1273 return 1;
1274 }
1275
1276 const PlayerShip_t *ships = player_getShipStack();
1277 lua_newtable(L); /* t */
1278 for (int i=0; i<array_size(ships); i++) {
1279 lua_newtable(L); /* t, k, t */
1280
1281 lua_pushstring(L, ships[i].p->name); /* t, k, t, s */
1282 lua_setfield(L, -2, "name"); /* t, k, t */
1283
1284 lua_pushship(L, ships[i].p->ship); /* t, k, t, s */
1285 lua_setfield(L, -2, "ship"); /* t, k, t */
1286
1287 lua_pushboolean(L, ships[i].deployed); /* t, k, t, s */
1288 lua_setfield(L, -2, "deployed"); /* t, k, t */
1289
1290 lua_rawseti(L, -2, i+1); /* t */
1291 }
1292 return 1;
1293}
1294
1304static int playerL_shipOutfits( lua_State *L )
1305{
1306 if (player.p == NULL) {
1307 lua_newtable(L);
1308 return 1;
1309 }
1310
1311 const char *str;
1312 int j;
1313 const PlayerShip_t *ships;
1314 Pilot *p;
1315
1316 /* Get name. */
1317 str = luaL_optstring(L, 1, NULL);
1318 ships = player_getShipStack();
1319
1320 /* Get outfit. */
1321 lua_newtable(L);
1322
1323 p = NULL;
1324 if ((str==NULL) || (strcmp(str, player.p->name)==0))
1325 p = player.p;
1326 else {
1327 for (int i=0; i<array_size(ships); i++) {
1328 if (strcmp(str, ships[i].p->name)==0) {
1329 p = ships[i].p;
1330 break;
1331 }
1332 }
1333 }
1334
1335 if (p == NULL)
1336 return NLUA_ERROR( L, _("Player does not own a ship named '%s'"), str );
1337
1338 lua_newtable( L );
1339 j = 1;
1340 for (int i=0; i<array_size(p->outfits); i++) {
1341 if (p->outfits[i]->outfit == NULL)
1342 continue;
1343
1344 /* Set the outfit. */
1345 lua_pushoutfit( L, p->outfits[i]->outfit );
1346 lua_rawseti( L, -2, j++ );
1347 }
1348
1349 return 1;
1350}
1351
1359static int playerL_shipMetadata( lua_State *L )
1360{
1361 PLAYER_CHECK();
1362
1363 int destroyed = 0;
1364 const char *str = luaL_optstring(L, 1, NULL);
1365 const PlayerShip_t *ships = player_getShipStack();
1366 const PlayerShip_t *ps = NULL;
1367 if ((str==NULL) || (strcmp(str, player.p->name)==0))
1368 ps = &player.ps;
1369 else {
1370 for (int i=0; i<array_size(ships); i++) {
1371 if (strcmp(str, ships[i].p->name)==0) {
1372 ps = &ships[i];
1373 break;
1374 }
1375 }
1376 }
1377 if (ps == NULL)
1378 return NLUA_ERROR( L, _("Player does not own a ship named '%s'"), str );
1379
1380 lua_newtable(L);
1381
1382 lua_pushnumber( L, ps->time_played );
1383 lua_setfield( L, -2, "time_played" );
1384
1385 lua_pushstring( L, ps->acquired );
1386 lua_setfield( L, -2, "acquired" );
1387
1388 lua_pushtime( L, ps->acquired_date );
1389 lua_setfield( L, -2, "acquired_date" );
1390
1391 lua_pushnumber( L, ps->dmg_done_shield );
1392 lua_setfield( L, -2, "dmg_done_shield" );
1393
1394 lua_pushnumber( L, ps->dmg_done_armour );
1395 lua_setfield( L, -2, "dmg_done_armour" );
1396
1397 lua_pushnumber( L, ps->dmg_done_shield+ps->dmg_done_armour );
1398 lua_setfield( L, -2, "dmg_done" );
1399
1400 lua_pushnumber( L, ps->dmg_taken_shield );
1401 lua_setfield( L, -2, "dmg_taken_shield" );
1402
1403 lua_pushnumber( L, ps->dmg_taken_armour );
1404 lua_setfield( L, -2, "dmg_taken_armour" );
1405
1406 lua_pushnumber( L, ps->dmg_taken_shield+ps->dmg_taken_armour );
1407 lua_setfield( L, -2, "dmg_taken" );
1408
1409 lua_pushinteger( L, ps->jumped_times );
1410 lua_setfield( L, -2, "jumped_times" );
1411
1412 lua_pushinteger( L, ps->landed_times );
1413 lua_setfield( L, -2, "landed_times" );
1414
1415 lua_pushinteger( L, ps->death_counter );
1416 lua_setfield( L, -2, "death_counter" );
1417
1418 for (int i=0; i<SHIP_CLASS_TOTAL; i++)
1419 destroyed += ps->ships_destroyed[i];
1420 lua_pushinteger( L, destroyed );
1421 lua_setfield( L, -2, "ships_destroyed" );
1422
1423 return 1;
1424}
1425
1433static int playerL_shipDeploy( lua_State *L )
1434{
1435 PLAYER_CHECK();
1436 const char *shipname = luaL_checkstring(L,1);
1437 int deploy = lua_toboolean(L,2);
1438 PlayerShip_t *ps = player_getPlayerShip( shipname );
1439 ps->deployed = deploy;
1440 return 0;
1441}
1442
1454static int playerL_outfits( lua_State *L )
1455{
1456 if (player.p == NULL) {
1457 lua_newtable(L);
1458 return 1;
1459 }
1460
1461 const PlayerOutfit_t *outfits = player_getOutfits();
1462 int unequipped_only = lua_toboolean(L, 1);
1463 const PlayerShip_t* pstack = player_getShipStack();
1464 int n = 1;
1465 /* Set up and get owned outfits. */
1466 lua_newtable(L);
1467 for (int i=0; i<array_size(outfits); i++) {
1468 lua_pushoutfit(L, outfits[i].o );
1469 lua_rawseti(L, -2, n++);
1470 }
1471 /* Add all outfits on player ships. */
1472 if (!unequipped_only) {
1473 for (int i=0; i<array_size(pstack); i++) {
1474 for (int j=0; j<array_size(pstack[i].p->outfits); j++) {
1475 const Outfit *o = pstack[i].p->outfits[j]->outfit;
1476 int found = 0;
1477 for (int k=0; k<array_size(outfits); k++) {
1478 if (outfits[k].o==o) {
1479 found = 1;
1480 break;
1481 }
1482 }
1483 if (found) {
1484 lua_pushoutfit(L, o);
1485 lua_rawseti(L, -2, n++);
1486 }
1487 }
1488 }
1489 }
1490 return 1;
1491}
1492
1503static int playerL_outfitNum( lua_State *L )
1504{
1505 if (player.p==NULL) {
1506 lua_pushnumber(L,0.);
1507 return 1;
1508 }
1509
1510 const Outfit *o;
1511 int q, unequipped_only;
1512
1513 /* Handle parameters. */
1514 o = luaL_validoutfit(L, 1);
1515 unequipped_only = lua_toboolean(L, 2);
1516
1517 /* Count the outfit. */
1518 if (unequipped_only)
1519 q = player_outfitOwned( o );
1520 else
1521 q = player_outfitOwnedTotal( o );
1522 lua_pushnumber( L, q );
1523
1524 return 1;
1525}
1536static int playerL_outfitAdd( lua_State *L )
1537{
1538 PLAYER_CHECK();
1539
1540 /* Handle parameters. */
1541 const Outfit *o = luaL_validoutfit(L, 1);
1542 int q = luaL_optinteger(L, 2, 1);
1543
1544 /* Add the outfits. */
1545 player_addOutfit( o, q );
1546
1547 /* Update equipment list. */
1549
1550 return 0;
1551}
1563static int playerL_outfitRm( lua_State *L )
1564{
1565 const Outfit *o;
1566 int q = luaL_optinteger(L, 2, 1);
1567
1568 /* Handle special case it's "all". */
1569 if (lua_isstring(L, 1)) {
1570 const char *str = luaL_checkstring(L, 1);
1571
1572 if (strcmp(str,"all")==0) {
1573 const PlayerOutfit_t *poutfits = player_getOutfits();
1574 const Outfit **outfits = array_create_size( const Outfit*, array_size( poutfits ) );
1575 for (int i=0; i<array_size(poutfits); i++)
1576 array_push_back( &outfits, poutfits[i].o );
1577
1578 for (int i=0; i<array_size(outfits); i++) {
1579 o = outfits[i];
1580 q = player_outfitOwned(o);
1581 player_rmOutfit(o, q);
1582 }
1583 /* Clean up. */
1584 array_free(outfits);
1585
1586 /* Update equipment list. */
1588 return 0;
1589 }
1590 }
1591
1592 /* Usual case. */
1593 o = luaL_validoutfit(L, 1);
1594 player_rmOutfit( o, q );
1595
1596 /* Update equipment list. */
1598
1599 return 0;
1600}
1601
1616static int playerL_shipAdd( lua_State *L )
1617{
1618 PlayerShip_t *new_ship;
1619 /* Handle parameters. */
1620 const Ship *s = luaL_validship(L, 1);
1621 const char *name = luaL_optstring(L, 2, _(s->name));
1622 const char *acquired = luaL_optstring(L, 3, NULL);
1623 int noname = lua_toboolean(L, 4);
1624 /* Add the ship, look in case it's cancelled. */
1625 do {
1626 new_ship = player_newShip( s, name, 0, acquired, noname );
1627 } while (new_ship == NULL);
1628 /* Return the new name. */
1629 lua_pushstring( L, new_ship->p->name );
1630 return 1;
1631}
1632
1644static int playerL_shipSwap( lua_State *L )
1645{
1646 PLAYER_CHECK();
1647
1648 const char *str = luaL_checkstring(L,1);
1649 int ignore_cargo= lua_toboolean(L,2);
1650 const char *cur = player.p->name;
1651 player_swapShip( str, !ignore_cargo );
1652 if (lua_toboolean(L,3))
1653 player_rmShip( cur );
1654
1655 return 0;
1656}
1657
1666static int playerL_missions( lua_State *L )
1667{
1668 if (player.p == NULL) {
1669 lua_newtable(L);
1670 return 1;
1671 }
1672 int j = 1;
1673 lua_newtable(L);
1674 for (int i=0; i<array_size(player_missions); i++) {
1675 const Mission *pm = player_missions[i];
1676 const MissionData *md = pm->data;
1677 if (pm->id == 0)
1678 continue;
1679
1680 misn_pushMissionData( L, md );
1681 /* Add player mission-specific data. */
1682 if (pm->title != NULL) {
1683 lua_pushstring( L, pm->title );
1684 lua_setfield(L,-2,"title");
1685 }
1686 if (pm->desc != NULL) {
1687 lua_pushstring( L, pm->desc );
1688 lua_setfield(L,-2,"desc");
1689 }
1690 if (pm->reward != NULL) {
1691 lua_pushstring( L, pm->reward );
1692 lua_setfield(L,-2,"reward");
1693 }
1694 lua_rawseti( L, -2, j++ );
1695 }
1696 return 1;
1697}
1698
1708static int playerL_misnActive( lua_State *L )
1709{
1710 PLAYER_CHECK();
1711 const char *str = luaL_checkstring(L,1);
1712 const MissionData *misn = mission_getFromName( str );
1713 if (misn == NULL)
1714 return NLUA_ERROR(L, _("Mission '%s' not found in stack"), str);
1715 int n = mission_alreadyRunning( misn );
1716 if (n > 0)
1717 lua_pushinteger( L, n );
1718 else
1719 lua_pushboolean( L, 0 );
1720 return 1;
1721}
1722
1733static int playerL_misnDone( lua_State *L )
1734{
1735 PLAYER_CHECK();
1736 const char *str = luaL_checkstring(L, 1);
1737 int id = mission_getID( str );
1738 if (id == -1)
1739 return NLUA_ERROR(L, _("Mission '%s' not found in stack"), str);
1740 lua_pushboolean( L, player_missionAlreadyDone( id ) );
1741 return 1;
1742}
1743
1750static int playerL_misnDoneList( lua_State *L )
1751{
1752 if (player.p == NULL) {
1753 lua_newtable(L);
1754 return 1;
1755 }
1756 const int *done = player_missionsDoneList();
1757 lua_newtable(L);
1758 for (int i=0; i<array_size(done); i++) {
1759 mission_toLuaTable( L, mission_get( done[i] ) );
1760 lua_rawseti(L,-2,i+1);
1761 }
1762 return 1;
1763}
1764
1774static int playerL_evtActive( lua_State *L )
1775{
1776 PLAYER_CHECK();
1777 const char *str= luaL_checkstring(L,1);
1778 int evtid = event_dataID( str );
1779 if (evtid < 0)
1780 return NLUA_ERROR(L, _("Event '%s' not found in stack"), str);
1781 lua_pushboolean( L, event_alreadyRunning( evtid ) );
1782 return 1;
1783}
1784
1795static int playerL_evtDone( lua_State *L )
1796{
1797 PLAYER_CHECK();
1798 const char *str = luaL_checkstring(L, 1);
1799 int id = event_dataID( str );
1800 if (id == -1)
1801 return NLUA_ERROR(L, _("Event '%s' not found in stack"), str);
1802 lua_pushboolean( L, player_eventAlreadyDone( id ) );
1803 return 1;
1804}
1805
1812static int playerL_evtDoneList( lua_State *L )
1813{
1814 if (player.p == NULL) {
1815 lua_newtable(L);
1816 return 1;
1817 }
1818 const int *done = player_eventsDoneList();
1819 lua_newtable(L);
1820 for (int i=0; i<array_size(done); i++) {
1821 event_toLuaTable( L, done[i] );
1822 lua_rawseti(L,-2,i+1);
1823 }
1824 return 1;
1825}
1826
1833static int playerL_gui( lua_State *L )
1834{
1835 lua_pushstring(L,gui_pick());
1836 return 1;
1837}
1838
1845static int playerL_guiList( lua_State *L )
1846{
1847 const char **gui = player_guiList();
1848
1849 lua_newtable(L);
1850 for (int i=0; i<array_size(gui); i++) {
1851 lua_pushstring( L, gui[i] );
1852 lua_rawseti( L, -2, i+1 );
1853 }
1854
1855 return 1;
1856}
1857
1864static int playerL_guiSet( lua_State *L )
1865{
1866 const char *name = luaL_checkstring(L,1);
1867 if (!gui_exists(name))
1868 return NLUA_ERROR(L,_("GUI '%s' does not exist!"),name);
1869 free( player.gui );
1870 player.gui = strdup(name);
1871 gui_load( gui_pick() );
1872 return 0;
1873}
1874
1881static int playerL_fleetList( lua_State *L )
1882{
1883 if (player.p == NULL) {
1884 lua_newtable(L);
1885 return 1;
1886 }
1887 int n = 1;
1888 const PlayerShip_t* pstack = player_getShipStack();
1889 lua_newtable(L);
1890 for (int i=0; i<array_size(pstack); i++) {
1891 const PlayerShip_t *ps = &pstack[i];
1892 if (!ps->deployed)
1893 continue;
1894 /* We can avoid the spaceWorthy check as they will be set to false due to not having a pilot. */
1895 /*if (!!pilot_isSpaceworthy(ps->p))
1896 continue;*/
1897
1898 if (ps->p==NULL)
1899 lua_pushboolean( L, 0 );
1900 else
1901 lua_pushpilot( L, ps->p->id );
1902 lua_rawseti( L, -2, n++ );
1903 }
1904 return 1;
1905}
1906
1913static int playerL_fleetCargoFree( lua_State *L )
1914{
1915 if (player.p==NULL)
1916 lua_pushinteger(L,0);
1917 else
1918 lua_pushinteger( L, pfleet_cargoFree() );
1919 return 1;
1920}
1921
1928static int playerL_fleetCargoUsed( lua_State *L )
1929{
1930 if (player.p==NULL)
1931 lua_pushinteger(L,0);
1932 else
1933 lua_pushinteger( L, pfleet_cargoUsed() );
1934 return 1;
1935}
1936
1944static int playerL_fleetCargoOwned( lua_State *L )
1945{
1946 const Commodity *c = luaL_validcommodity( L, 1 );
1947 if (player.p==NULL)
1948 lua_pushinteger(L,0);
1949 else
1950 lua_pushinteger( L, pfleet_cargoOwned( c ) );
1951 return 1;
1952}
1953
1962static int playerL_fleetCargoAdd( lua_State *L )
1963{
1964 const Commodity *c = luaL_validcommodity( L, 1 );
1965 int q = luaL_checkinteger( L, 2 );
1966 if (player.p==NULL)
1967 lua_pushinteger(L,0);
1968 else
1969 lua_pushinteger( L, pfleet_cargoAdd( c, q ) );
1970 return 1;
1971}
1972
1981static int playerL_fleetCargoRm( lua_State *L )
1982{
1983 const Commodity *c = luaL_validcommodity( L, 1 );
1984 int q = luaL_checkinteger( L, 2 );
1985 if (player.p==NULL)
1986 lua_pushinteger(L,0);
1987 else
1988 lua_pushinteger( L, pfleet_cargoRm( c, q, 0 ) );
1989 return 1;
1990}
1991
2000static int playerL_fleetCargoJet( lua_State *L )
2001{
2002 const Commodity *c = luaL_validcommodity( L, 1 );
2003 int q = luaL_checkinteger( L, 2 );
2004 if (player.p==NULL)
2005 lua_pushinteger(L,0);
2006 else
2007 lua_pushinteger( L, pfleet_cargoRm( c, q, 1 ) );
2008 return 1;
2009}
2010
2019static int playerL_fleetCargoList( lua_State *L )
2020{
2021 if (player.p==NULL) {
2022 lua_newtable(L);
2023 return 1;
2024 }
2025 Commodity *call = commodity_getAll();
2026 int n = 0;
2027 lua_newtable(L); /* t */
2028 for (int i=0; i<array_size(call); i++) {
2029 Commodity *c = &call[i];
2030 int q = pfleet_cargoOwned( c );
2031 if (q <= 0)
2032 continue;
2033
2034 lua_newtable(L); /* t, t */
2035
2036 lua_pushcommodity( L, c ); /* t, t, c */
2037 lua_setfield( L, -2, "c" ); /* t, t */
2038
2039 lua_pushinteger( L, q ); /* t, t, q */
2040 lua_setfield( L, -2, "q" ); /* t, t */
2041
2042 lua_rawseti( L, -2, ++n ); /* t */
2043 }
2044 return 1;
2045}
2046
2055static int playerL_inventory( lua_State *L )
2056{
2057 if (player.p==NULL) {
2058 lua_newtable(L);
2059 return 1;
2060 }
2061 const PlayerItem *inv = player_inventory();
2062 lua_newtable(L);
2063 for (int i=0; i<array_size(inv); i++) {
2064 const PlayerItem *pi = &inv[i];
2065 lua_newtable(L);
2066
2067 lua_pushstring(L,pi->name);
2068 lua_setfield(L,-2,"name");
2069
2070 lua_pushinteger(L,pi->quantity);
2071 lua_setfield(L,-2,"quantity");
2072
2073 lua_rawseti(L,-2,i+1);
2074 }
2075 return 1;
2076}
2077
2086static int playerL_inventoryAdd( lua_State *L )
2087{
2088 const char *name = luaL_checkstring(L,1);
2089 int q = luaL_optinteger(L,2,1);
2090 if (player.p==NULL)
2091 lua_pushinteger( L, 0 );
2092 else
2093 lua_pushinteger( L, player_inventoryAdd( name, q ) );
2094 return 1;
2095}
2096
2105static int playerL_inventoryRm( lua_State *L )
2106{
2107 const char *name = luaL_checkstring(L,1);
2108 int q = luaL_optinteger(L,2,1);
2109 if (player.p==NULL)
2110 lua_pushinteger( L, 0 );
2111 else
2112 lua_pushinteger( L, player_inventoryRemove( name, q ) );
2113 return 1;
2114}
2115
2123static int playerL_inventoryOwned( lua_State *L )
2124{
2125 const char *name = luaL_checkstring(L,1);
2126 if (player.p==NULL)
2127 lua_pushinteger( L, 0 );
2128 else
2129 lua_pushinteger( L, player_inventoryAmount( name ) );
2130 return 1;
2131}
2132
2149static int playerL_teleport( lua_State *L )
2150{
2151 PLAYER_CHECK();
2152 Spob *pnt;
2153 const char *name, *pntname;
2154 int no_simulate, silent;
2155
2156 /* Must not be landed. */
2157 if (landed)
2158 return NLUA_ERROR(L,_("Can not teleport the player while landed!"));
2159 if (comm_isOpen())
2160 return NLUA_ERROR(L,_("Can not teleport the player while the comm is open!"));
2161 if (player_isBoarded())
2162 return NLUA_ERROR(L,_("Can not teleport the player while they are boarded!"));
2163 pnt = NULL;
2164
2165 /* Get a system. */
2166 if (lua_issystem(L,1)) {
2167 const StarSystem *sys = luaL_validsystem(L,1);
2168 name = system_getIndex(sys->id)->name;
2169 }
2170 /* Get a spob. */
2171 else if (lua_isspob(L,1)) {
2172 pnt = luaL_validspob(L,1);
2173 name = spob_getSystem( pnt->name );
2174 if (name == NULL)
2175 return NLUA_ERROR( L, _("Spob '%s' does not belong to a system."), pnt->name );
2176 }
2177 /* Get destination from string. */
2178 else if (lua_isstring(L,1)) {
2179 const char *sysname;
2180 name = lua_tostring(L,1);
2181 sysname = system_existsCase( name );
2182 if (sysname == NULL) {
2183 /* No system found, assume destination string is the name of a spob. */
2184 pntname = name;
2185 name = spob_getSystem( pntname );
2186 pnt = spob_get( pntname );
2187 if (pnt == NULL)
2188 return NLUA_ERROR( L, _("'%s' is not a valid teleportation target."), name );
2189
2190 if (name == NULL)
2191 return NLUA_ERROR( L, _("Spob '%s' does not belong to a system."), pntname );
2192 }
2193 else
2194 name = sysname;
2195 }
2196 else
2197 NLUA_INVALID_PARAMETER(L,1);
2198
2199 no_simulate = lua_toboolean(L,2);
2200 silent = lua_toboolean(L,3);
2201
2202 /* Check if system exists. */
2203 if (system_get( name ) == NULL)
2204 return NLUA_ERROR( L, _("System '%s' does not exist."), name );
2205
2206 /* Unboard just in case. */
2207 board_unboard();
2208
2209 /* Jump out hook is run first. */
2210 hooks_run( "jumpout" );
2211
2212 /* Just in case remove hyperspace flags. */
2213 pilot_rmFlag( player.p, PILOT_HYPERSPACE );
2214 pilot_rmFlag( player.p, PILOT_HYP_BEGIN );
2215 pilot_rmFlag( player.p, PILOT_HYP_BRAKE );
2216 pilot_rmFlag( player.p, PILOT_HYP_PREP );
2217 /* Don't follow anything. */
2220
2221 /* Free graphics. */
2223
2224 /* Reset targets when teleporting.
2225 * Both of these functions invoke gui_setNav(), which updates jump and
2226 * spob targets simultaneously. Thus, invalid reads may arise and the
2227 * target reset must be done prior to calling space_init and destroying
2228 * the old system. */
2230
2231 /* Hide messages if not needed. */
2232 if (silent)
2233 player_messageToggle(0); /* space_init will reset it, so no need to. */
2234
2235 /* Go to the new system. */
2236 space_init( name, !no_simulate );
2237
2238 /* Map gets deformed when jumping this way. */
2239 map_clear();
2240
2241 /* Initialize alpha as needed. */
2242 ovr_initAlpha();
2243
2244 /* Run hooks - order is important. */
2246 hooks_run( "jumpin" );
2247 hooks_run( "enter" );
2248 events_trigger( EVENT_TRIGGER_ENTER );
2249 missions_run( MIS_AVAIL_ENTER, -1, NULL, NULL );
2250
2251 /* Move to spob. */
2252 if (pnt != NULL)
2253 player.p->solid.pos = pnt->pos;
2254
2255 /* Move all escorts to new position. */
2256 Pilot *const* pilot_stack = pilot_getAll();
2257 for (int i=0; i<array_size(pilot_stack); i++) {
2258 Pilot *p = pilot_stack[i];
2259 if (p->parent == PLAYER_ID) {
2260 memcpy( &p->solid.pos, &player.p->solid.pos, sizeof(vec2) );
2261 vec2_padd( &p->solid.pos, 200.+200.*RNGF(), 2.*M_PI*RNGF() );
2262
2263 /* Clean up trails. */
2264 pilot_clearTrails( p );
2265 }
2266 }
2267
2268 return 0;
2269}
2270
2277static int playerL_dt_mod( lua_State *L )
2278{
2279 lua_pushnumber(L,dt_mod);
2280 return 1;
2281}
2282
2291static int playerL_fleetCapacity( lua_State *L )
2292{
2293 int nships = 0;
2294 const PlayerShip_t *pships;
2295 pfleet_update();
2296 lua_pushnumber(L,player.fleet_capacity);
2297 lua_pushnumber(L,player.fleet_used);
2298 pships = player_getShipStack();
2299 for (int i=0; i<array_size(pships); i++) {
2300 if (!pships[i].deployed)
2301 continue;
2302 nships++;
2303 }
2304 lua_pushboolean(L, (nships==0) || (player.fleet_used <= player.fleet_capacity));
2305 return 3;
2306}
2307
2314static int playerL_fleetCapacitySet( lua_State *L )
2315{
2316 player.fleet_capacity = luaL_checkinteger(L,1);
2317 return 0;
2318}
2319
2326static int playerL_chapter( lua_State *L )
2327{
2328 lua_pushstring( L, player.chapter );
2329 return 1;
2330}
2331
2338static int playerL_chapterSet( lua_State *L )
2339{
2340 const char *str = luaL_checkstring(L,1);
2341 free( player.chapter );
2342 player.chapter = strdup(str);
2343 return 0;
2344}
2345
2356static int playerL_infoButtonRegister( lua_State *L )
2357{
2358 int id;
2359 const char *caption = luaL_checkstring( L, 1 );
2360 int priority = luaL_optinteger( L, 3, 5 );
2361 const char *key = luaL_optstring( L, 4, "" );
2362 luaL_checktype( L, 2, LUA_TFUNCTION );
2363 lua_pushvalue( L, 2 );
2364 id = info_buttonRegister( caption, priority, SDL_GetKeyFromName( key ) );
2365 lua_pushinteger( L, id );
2366 return 1;
2367}
2368
2375static int playerL_infoButtonUnregister( lua_State *L )
2376{
2377 int id = luaL_checkinteger(L,1);
2378 int ret = info_buttonUnregister( id );
2379 if (ret != 0)
2380 WARN(_("Failed to unregister info button with id '%d'!"), id);
2381 return 0;
2382}
2383
2390static int playerL_canDiscover( lua_State *L )
2391{
2392 player.discover_off = !lua_toboolean(L,1);
2393 return 0;
2394}
2395
2403static int playerL_save( lua_State *L )
2404{
2405 const char *savename = luaL_optstring( L, 1, "autosave" );
2406 Spob *savespob = NULL;
2407 Spob *prevspob = NULL;
2408 if (!lua_isnoneornil(L,2))
2409 savespob = luaL_validspob(L,2);
2410
2411 if (!landed && (savespob==NULL))
2412 return NLUA_ERROR(L,_("Unable to save when not landed and land spob is not specified!"));
2413 else if (landed && (savespob!=NULL))
2414 return NLUA_ERROR(L,_("Unable to save when landed and land_spob does not match landed spob!"));
2415
2416 if (savespob != NULL) {
2417 prevspob = land_spob;
2418 land_spob = savespob;
2419 }
2420 lua_pushboolean( L, save_all_with_name( savename ) );
2421 if (savespob != NULL)
2422 land_spob = prevspob;
2423
2424 return 1;
2425}
2426
2434static int playerL_saveBackup( lua_State *L )
2435{
2436 char file[PATH_MAX], backup[PATH_MAX];
2437 const char *filename = luaL_checkstring(L,1); /* TODO sanitize path and such. */
2438 if (strcmp(filename,"autosave")==0)
2439 return NLUA_ERROR(L,_("Can not back up save to 'autosave'."));
2440 snprintf( file, sizeof(file), "saves/%s/autosave.ns", player.name );
2441 snprintf( backup, sizeof(backup), "saves/%s/%s.ns", player.name, filename );
2442 lua_pushboolean( L, ndata_copyIfExists(file, backup) );
2443 return 1;
2444}
2445
2451static int playerL_gameover( lua_State *L )
2452{
2453 (void) L;
2454 player_setFlag( PLAYER_DESTROYED );
2455 menu_death();
2456 return 0;
2457}
2458
2465static int playerL_start( lua_State *L )
2466{
2467 double x, y;
2468 vec2 v;
2469 lua_newtable(L);
2470
2471 lua_pushstring( L, start_name() );
2472 lua_setfield( L, -2, "name" );
2473
2475 lua_setfield( L, -2, "ship" );
2476
2477 lua_pushstring( L, start_shipname() );
2478 lua_setfield( L, -2, "shipname" );
2479
2480 lua_pushstring( L, start_acquired() );
2481 lua_setfield( L, -2, "acquired" );
2482
2483 lua_pushstring( L, start_gui() );
2484 lua_setfield( L, -2, "gui" );
2485
2486 lua_pushinteger( L, start_credits() );
2487 lua_setfield( L, -2, "credits" );
2488
2489 lua_pushtime( L, start_date() );
2490 lua_setfield( L, -2, "date" );
2491
2493 lua_setfield( L, -2, "system" );
2494
2495 start_position( &x, &y );
2496 vec2_cset( &v, x, y );
2497 lua_pushvector( L, v );
2498 lua_setfield( L, -2, "position" );
2499
2500 if (start_mission() != NULL) {
2501 lua_pushstring( L, start_mission() );
2502 lua_setfield( L, -2, "mission" );
2503 }
2504
2505 if (start_event() != NULL) {
2506 lua_pushstring( L, start_event() );
2507 lua_setfield( L, -2, "event" );
2508 }
2509
2510 lua_pushstring( L, start_chapter() );
2511 lua_setfield( L, -2, "chapter" );
2512
2513 lua_pushstring( L, start_spob_lua_default() );
2514 lua_setfield( L, -2, "spob_lua_default" );
2515
2516 lua_pushstring( L, start_dtype_default() );
2517 lua_setfield( L, -2, "dtype_default" );
2518
2519 return 1;
2520}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition array.h:158
#define array_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
Definition array.h:102
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:168
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
Definition array.h:129
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Definition array.h:93
int player_tryBoard(int noisy)
Attempt to board the player's target.
Definition board.c:152
int player_isBoarded(void)
Gets if the player is boarded.
Definition board.c:42
void board_unboard(void)
Forces unboarding of the pilot.
Definition board.c:208
int comm_isOpen(void)
Check to see if the comm window is open.
Definition comm.c:51
void comm_queueClose(void)
Queues a close command when possible.
Definition comm.c:59
Commodity * commodity_getAll(void)
Gets all the commodities.
Definition commodity.c:116
void credits2str(char *str, credits_t credits, int decimals)
Converts credits to a usable string for displaying.
Definition commodity.c:59
int event_alreadyRunning(int data)
Check to see if an event is already running.
Definition event.c:302
int event_dataID(const char *evdata)
Gets the event data id from name.
Definition event.c:745
void events_trigger(EventTrigger_t trigger)
Runs all the events matching a trigger.
Definition event.c:319
void gui_clearMessages(void)
Clears the GUI messages.
Definition gui.c:986
const char * gui_pick(void)
Determines which GUI should be used.
Definition gui.c:1844
int gui_exists(const char *name)
Checks to see if a GUI exists.
Definition gui.c:1863
int gui_load(const char *name)
Attempts to load the actual GUI.
Definition gui.c:1876
void gui_reload(void)
Reloads the GUI.
Definition gui.c:1756
void player_messageRaw(const char *str)
Adds a mesg to the queue to be displayed on screen.
Definition gui.c:298
void player_messageToggle(int enable)
Toggles if player should receive messages.
Definition gui.c:288
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
Definition hook.c:979
int hooks_run(const char *stack)
Runs all the hooks of stack.
Definition hook.c:999
Handles the info menu.
void land_queueTakeoff(void)
Queue a takeoff.
Definition land.c:143
int land_setWindow(int window)
Sets the land window tab.
Definition land.c:1110
int landed
Definition land.c:75
Spob * land_spob
Definition land.c:83
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.
Definition lvar.c:161
void lvar_rmArray(lvar **arr, lvar *rm_var)
Removes a var from a var array.
Definition lvar.c:188
lvar * lvar_get(const lvar *arr, const char *str)
Gets a lua var by name.
Definition lvar.c:39
lvar lvar_tovar(lua_State *L, const char *name, int idx)
Gets a lua variable from an index from a lua state.
Definition lvar.c:84
int lvar_push(lua_State *L, const lvar *v)
Pushes a lua var to a lua state.
Definition lvar.c:54
Handles the important game menus.
Mission ** player_missions
Definition mission.c:47
const MissionData * mission_getFromName(const char *name)
Gets mission data from a name.
Definition mission.c:125
int mission_alreadyRunning(const MissionData *misn)
Checks to see if mission is already running.
Definition mission.c:225
void missions_run(MissionAvailability loc, int faction, const Spob *pnt, const StarSystem *sys)
Runs missions matching location, all Lua side and one-shot.
Definition mission.c:321
int mission_getID(const char *name)
Gets id from mission name.
Definition mission.c:100
const MissionData * mission_get(int id)
Gets a MissionData based on ID.
Definition mission.c:116
Header file with generic functions and naev-specifics.
#define CLAMP(a, b, x)
Definition naev.h:41
#define PATH_MAX
Definition naev.h:50
int ndata_copyIfExists(const char *file1, const char *file2)
Copy a file, if it exists.
Definition ndata.c:303
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.
Definition nlua_pilot.c:563
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_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_isLanded(lua_State *L)
Checks to see if the player is landed or not.
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_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_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_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.
Definition nlua_ship.c:166
const Ship * luaL_validship(lua_State *L, int ind)
Makes sure the ship is valid or raises a Lua error.
Definition nlua_ship.c:141
LuaSpob * lua_pushspob(lua_State *L, LuaSpob spob)
Pushes a spob on the stack.
Definition nlua_spob.c:201
Spob * luaL_validspob(lua_State *L, int ind)
Gets a spob directly.
Definition nlua_spob.c:174
int lua_isspob(lua_State *L, int ind)
Checks to see if ind is a spob.
Definition nlua_spob.c:216
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.
Definition nlua_time.c:126
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
Definition nlua_vec2.c:145
void gl_setDefViewport(int x, int y, int w, int h)
Sets the default viewport.
Definition opengl.c:597
glInfo gl_screen
Definition opengl.c:51
void pause_setSpeed(double mod)
Adjusts the game's dt modifier.
Definition pause.c:64
double dt_mod
Definition pause.c:23
void pilot_setCommMsg(Pilot *p, const char *s)
Sets the overhead communication message of the pilot.
Definition pilot.c:1096
static Pilot ** pilot_stack
Definition pilot.c:61
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
Definition pilot.c:94
credits_t pilot_worth(const Pilot *p, int count_unique)
Gets the price or worth of a pilot in credits.
Definition pilot.c:4096
int pilot_getJumps(const Pilot *p)
Gets the amount of jumps the pilot has left.
Definition pilot.c:1273
void pilot_clearTrails(Pilot *p)
Resets the trails for a pilot.
Definition pilot.c:3383
void pilot_destealth(Pilot *p)
Destealths a pilot.
Definition pilot_ew.c:552
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.
Definition player.c:3014
int player_rmOutfit(const Outfit *o, int quantity)
Remove an outfit from the player's outfit stack.
Definition player.c:2890
void player_swapShip(const char *shipname, int move_cargo)
Swaps player's current ship with their ship named shipname.
Definition player.c:526
int player_addOutfit(const Outfit *o, int quantity)
Adds an outfit to the player outfit stack.
Definition player.c:2828
void player_resetSpeed(void)
Resets the player speed stuff.
Definition player.c:1448
const PlayerShip_t * player_getShipStack(void)
Gets the array (array.h) of the player's ships.
Definition player.c:2644
PlayerShip_t * player_newShip(const Ship *ship, const char *def_name, int trade, const char *acquired, int noname)
Creates a new ship for player.
Definition player.c:410
void player_rmShip(const char *shipname)
Removes one of the player's ships.
Definition player.c:705
int player_outfitOwnedTotal(const Outfit *o)
Definition player.c:2754
PlayerShip_t * player_getPlayerShip(const char *shipname)
Gets a specific ship.
Definition player.c:2703
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
Definition player.c:1913
int player_missionAlreadyDone(int id)
Checks to see if player has already completed a mission.
Definition player.c:2961
credits_t player_modCredits(credits_t amount)
Modifies the amount of credits the player has.
Definition player.c:975
int * player_eventsDoneList(void)
Gets a list of all the events the player has done.
Definition player.c:3028
void player_accelOver(void)
Done accelerating.
Definition player.c:2127
int player_land(int loud)
Try to land or target closest spob if no land target.
Definition player.c:1579
Player_t player
Definition player.c:74
int player_outfitOwned(const Outfit *o)
Gets how many of the outfit the player owns.
Definition player.c:2722
void player_targetClearAll(void)
Clears all player targets: hyperspace, spob, asteroid, etc...
Definition player.c:2241
void player_nolandMsg(const char *str)
Sets the no land message.
Definition player.c:1743
const PlayerOutfit_t * player_getOutfits(void)
Gets an array (array.h) of the player's outfits.
Definition player.c:2782
void player_screenshot(void)
Takes a screenshot.
Definition player.c:2319
int * player_missionsDoneList(void)
Gets a list of all the missions the player has done.
Definition player.c:2975
void player_autonavEnd(void)
Ends the 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_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.
Definition player_gui.c:103
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.
static const double c[]
Definition rng.c:264
int save_all_with_name(const char *name)
Saves the current game.
Definition save.c:105
const Ship * ship_get(const char *name)
Gets a ship based on its name.
Definition ship.c:87
void sound_setSpeed(double s)
Sets the speed to play the sound at.
Definition sound.c:1152
void space_init(const char *sysname, int do_simulate)
Initializes the system.
Definition space.c:1549
void space_gfxUnload(StarSystem *sys)
Unloads all the graphics for a star system.
Definition space.c:2127
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
Definition space.c:1051
StarSystem * system_getIndex(int id)
Get the system by its index.
Definition space.c:989
int spob_index(const Spob *p)
Gets the ID of a spob.
Definition space.c:1099
const char * system_existsCase(const char *sysname)
Checks to see if a system exists case insensitively.
Definition space.c:890
StarSystem * system_get(const char *sysname)
Get the system from its name.
Definition space.c:960
const char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
Definition space.c:1025
StarSystem * cur_system
Definition space.c:106
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.
Definition space.c:4364
void spob_luaInitMem(const Spob *spob)
Initializes the memory fo a spob.
Definition space.c:1986
int system_index(const StarSystem *sys)
Gets the index of a star system.
Definition space.c:1000
void spfx_shake(double mod)
Increases the current rumble level.
Definition spfx.c:898
void spfx_damage(double mod)
Increases the current damage level.
Definition spfx.c:918
const char * start_acquired(void)
Gets the module's starting ship was acquired.
Definition start.c:204
const char * start_event(void)
Gets the starting event of the player.
Definition start.c:269
const char * start_mission(void)
Gets the starting mission of the player.
Definition start.c:260
void start_position(double *x, double *y)
Gets the starting position of the player.
Definition start.c:250
const char * start_chapter(void)
Gets the player's starting chapter.
Definition start.c:278
const char * start_name(void)
Gets the module name.
Definition start.c:177
const char * start_dtype_default(void)
Gets the default damage type.
Definition start.c:296
const char * start_ship(void)
Gets the module player starting ship.
Definition start.c:186
ntime_t start_date(void)
Gets the starting date.
Definition start.c:231
const char * start_spob_lua_default(void)
Gets the default spob Lua file.
Definition start.c:287
const char * start_shipname(void)
Gets the module's starting ship's name.
Definition start.c:195
const char * start_gui(void)
Gets the module's starting ship was acquired.
Definition start.c:213
const char * start_system(void)
Gets the starting system name.
Definition start.c:240
unsigned int start_credits(void)
Gets the player's starting credits.
Definition start.c:222
Represents a commodity.
Definition commodity.h:43
The actual hook parameter.
Definition hook.h:38
Static mission data.
Definition mission.h:62
Represents an active mission.
Definition mission.h:81
unsigned int id
Definition mission.h:83
char * reward
Definition mission.h:88
char * desc
Definition mission.h:87
char * title
Definition mission.h:86
const MissionData * data
Definition mission.h:82
A ship outfit, depends radically on the type.
Definition outfit.h:328
const Outfit * outfit
Definition pilot.h:112
The representation of an in-game pilot.
Definition pilot.h:217
unsigned int id
Definition pilot.h:218
lvar * shipvar
Definition pilot.h:385
credits_t credits
Definition pilot.h:325
PilotOutfitSlot ** outfits
Definition pilot.h:300
double fuel_max
Definition pilot.h:259
Solid solid
Definition pilot.h:227
double fuel
Definition pilot.h:260
char * name
Definition pilot.h:219
double fuel_consumption
Definition pilot.h:261
Represents an item in the player inventory.
Wrapper for outfits.
Definition player.h:65
Player ship.
Definition player.h:73
time_t acquired_date
Definition player.h:85
double time_played
Definition player.h:83
double dmg_done_armour
Definition player.h:87
unsigned int death_counter
Definition player.h:93
double dmg_taken_armour
Definition player.h:89
int deployed
Definition player.h:80
double dmg_taken_shield
Definition player.h:88
unsigned int landed_times
Definition player.h:92
Pilot * p
Definition player.h:74
unsigned int ships_destroyed[SHIP_CLASS_TOTAL]
Definition player.h:90
char * acquired
Definition player.h:84
unsigned int jumped_times
Definition player.h:91
double dmg_done_shield
Definition player.h:86
Pilot * p
Definition player.h:101
PlayerShip_t ps
Definition player.h:102
char * name
Definition player.h:103
int fleet_used
Definition player.h:125
char * gui
Definition player.h:119
char * chapter
Definition player.h:111
int fleet_capacity
Definition player.h:126
double speed
Definition player.h:110
int discover_off
Definition player.h:113
Represents a space ship.
Definition ship.h:94
char * name
Definition ship.h:95
vec2 pos
Definition physics.h:49
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Definition space.h:89
int lua_land
Definition space.h:144
nlua_env lua_env
Definition space.h:138
char * name
Definition space.h:91
vec2 pos
Definition space.h:94
int nw
Definition opengl.h:47
int nh
Definition opengl.h:48
Contains a mission variable.
Definition lvar.h:24
Represents a 2d vector.
Definition vec2.h:32
double y
Definition vec2.h:34
double x
Definition vec2.h:33