naev 0.12.5
nlua_hook.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 <stdio.h>
13#include <stdlib.h>
14
15#include "naev.h"
17
18#include "nlua_hook.h"
19
20#include "array.h"
21#include "event.h"
22#include "hook.h"
23#include "mission.h"
24#include "nlua_evt.h"
25#include "nlua_misn.h"
26#include "nlua_pilot.h"
27#include "nlua_time.h"
28#include "nluadef.h"
29
30/* Hook methods. */
31static int hookL_rm( lua_State *L );
32static int hookL_load( lua_State *L );
33static int hookL_land( lua_State *L );
34static int hookL_info( lua_State *L );
35static int hookL_takeoff( lua_State *L );
36static int hookL_jumpout( lua_State *L );
37static int hookL_jumpin( lua_State *L );
38static int hookL_enter( lua_State *L );
39static int hookL_hail( lua_State *L );
40static int hookL_hail_spob( lua_State *L );
41static int hookL_board( lua_State *L );
42static int hookL_timer( lua_State *L );
43static int hookL_timerClear( lua_State *L );
44static int hookL_date( lua_State *L );
45static int hookL_commbuy( lua_State *L );
46static int hookL_commsell( lua_State *L );
47static int hookL_commjettison( lua_State *L );
48static int hookL_gather( lua_State *L );
49static int hookL_outfitbuy( lua_State *L );
50static int hookL_outfitsell( lua_State *L );
51static int hookL_shipbuy( lua_State *L );
52static int hookL_shipsell( lua_State *L );
53static int hookL_shipswap( lua_State *L );
54static int hookL_equip( lua_State *L );
55static int hookL_input( lua_State *L );
56static int hookL_mouse( lua_State *L );
57static int hookL_safe( lua_State *L );
58static int hookL_update( lua_State *L );
59static int hookL_renderbg( lua_State *L );
60static int hookL_renderfg( lua_State *L );
61static int hookL_rendertop( lua_State *L );
62static int hookL_mission_done( lua_State *L );
63static int hookL_event_done( lua_State *L );
64static int hookL_standing( lua_State *L );
65static int hookL_discover( lua_State *L );
66static int hookL_asteroidScan( lua_State *L );
67static int hookL_pay( lua_State *L );
68static int hookL_custom( lua_State *L );
69static int hookL_pilot( lua_State *L );
70
71static const luaL_Reg hookL_methods[] = {
72 { "rm", hookL_rm },
73 { "load", hookL_load },
74 { "land", hookL_land },
75 { "info", hookL_info },
76 { "takeoff", hookL_takeoff },
77 { "jumpout", hookL_jumpout },
78 { "jumpin", hookL_jumpin },
79 { "enter", hookL_enter },
80 { "hail", hookL_hail },
81 { "hail_spob", hookL_hail_spob },
82 { "board", hookL_board },
83 { "timer", hookL_timer },
84 { "timerClear", hookL_timerClear },
85 { "date", hookL_date },
86 { "gather", hookL_gather },
87 { "comm_buy", hookL_commbuy },
88 { "comm_sell", hookL_commsell },
89 { "comm_jettison", hookL_commjettison },
90 { "outfit_buy", hookL_outfitbuy },
91 { "outfit_sell", hookL_outfitsell },
92 { "equip", hookL_equip },
93 { "ship_buy", hookL_shipbuy },
94 { "ship_sell", hookL_shipsell },
95 { "ship_swap", hookL_shipswap },
96 { "input", hookL_input },
97 { "mouse", hookL_mouse },
98 { "safe", hookL_safe },
99 { "update", hookL_update },
100 { "renderbg", hookL_renderbg },
101 { "renderfg", hookL_renderfg },
102 { "rendertop", hookL_rendertop },
103 { "mission_done", hookL_mission_done },
104 { "event_done", hookL_event_done },
105 { "standing", hookL_standing },
106 { "discover", hookL_discover },
107 { "asteroid_scan", hookL_asteroidScan },
108 { "pay", hookL_pay },
109 { "custom", hookL_custom },
110 { "pilot", hookL_pilot },
111 { 0, 0 } };
112
113/*
114 * Prototypes.
115 */
116static int hookL_setarg( unsigned int hook, int ind );
117static unsigned int hookL_generic( lua_State *L, const char *stack, double ms,
118 int pos, ntime_t date, int arg );
119
125int nlua_loadHook( nlua_env env )
126{
127 nlua_register( env, "hook", hookL_methods, 0 );
128 return 0;
129}
130
151
160static int hookL_rm( lua_State *L )
161{
162 /* Remove the hook. */
163 long h = luaL_optlong( L, 1, -1 );
164 /* ... Or do a no-op if caller passes nil. */
165 if ( h < 0 )
166 return 0;
167 hook_rm( (unsigned int)h );
168 return 0;
169}
170
178static int hookL_setarg( unsigned int hook, int ind )
179{
180 nlua_env env = hook_env( hook );
181
182 /* Create if necessary the actual hook argument table. */
183 nlua_getenv( naevL, env, "mem" ); /* t */
184 lua_getfield( naevL, -1, "__hook_arg" ); /* t, t */
185 if ( lua_isnil( naevL, -1 ) ) { /* t, nil */
186 lua_pop( naevL, 1 ); /* t */
187 lua_newtable( naevL ); /* t, t */
188 lua_pushvalue( naevL, -1 ); /* t, t, t */
189 lua_setfield( naevL, -3, "__hook_arg" ); /* t, t */
190 }
191 lua_pushinteger( naevL, hook ); /*t, t, k */
192 lua_pushvalue( naevL, ind ); /*t, t, k, v */
193 lua_settable( naevL, -3 ); /*t, t */
194 lua_pop( naevL, 2 ); /* */
195 return 0;
196}
197
201void hookL_unsetarg( unsigned int hook )
202{
203 nlua_env env = hook_env( hook );
204
205 if ( env == LUA_NOREF )
206 return;
207
208 nlua_getenv( naevL, env, "mem" ); /* t */
209 lua_getfield( naevL, -1, "__hook_arg" ); /* t, t */
210 if ( !lua_isnil( naevL, -1 ) ) {
211 lua_pushinteger( naevL, hook ); /* t, h */
212 lua_pushnil( naevL ); /* t, h, n */
213 lua_settable( naevL, -3 ); /* t */
214 }
215 lua_pop( naevL, 2 );
216}
217
224int hookL_getarg( unsigned int hook )
225{
226 nlua_env env = hook_env( hook );
227
228 if ( env == LUA_NOREF )
229 return 0;
230
231 nlua_getenv( naevL, env, "mem" ); /* t */
232 lua_getfield( naevL, -1, "__hook_arg" ); /* t, t */
233 if ( !lua_isnil( naevL, -1 ) ) { /* t, t */
234 lua_pushinteger( naevL, hook ); /* t, t, k */
235 lua_gettable( naevL, -2 ); /* t, t, v */
236 lua_remove( naevL, -2 ); /* t, v */
237 }
238 lua_remove( naevL, -2 ); /* v */
239 return 1;
240}
241
256static unsigned int hookL_generic( lua_State *L, const char *stack, double sec,
257 int pos, ntime_t date, int arg )
258{
259 const char *func;
260 unsigned int h;
261 Event_t *running_event;
262 Mission *running_mission;
263
264 /* Last parameter must be function to hook */
265 func = luaL_checkstring( L, pos );
266
267 /* Get stuff. */
268 running_event = event_getFromLua( L );
269 running_mission = misn_getFromLua( L );
270
271 if ( running_mission != NULL ) {
272 int i;
273 /* make sure mission is a player mission */
274 for ( i = 0; i < array_size( player_missions ); i++ )
275 if ( player_missions[i]->id == running_mission->id )
276 break;
277 if ( i >= array_size( player_missions ) ) {
278 NLUA_WARN( L, _( "Mission not in stack trying to hook, forgot to run "
279 "misn.accept()?" ) );
280 return 0;
281 }
282
283 if ( stack != NULL )
284 h = hook_addMisn( running_mission->id, func, stack );
285 else if ( date != 0 )
286 h = hook_addDateMisn( running_mission->id, func, date );
287 else
288 h = hook_addTimerMisn( running_mission->id, func, sec );
289 } else if ( running_event != NULL ) {
290 if ( stack != NULL )
291 h = hook_addEvent( running_event->id, func, stack );
292 else if ( date != 0 )
293 h = hook_addDateEvt( running_event->id, func, date );
294 else
295 h = hook_addTimerEvt( running_event->id, func, sec );
296 } else
297 return NLUA_ERROR(
298 L, _( "Attempting to set a hook outside of a mission or event." ) );
299
300 if ( h == 0 )
301 return NLUA_ERROR( L, _( "No hook target was set." ) );
302
303 /* Check parameter. */
304 if ( !lua_isnoneornil( L, arg ) )
305 hookL_setarg( h, arg );
306
307 return h;
308}
309
333static int hookL_land( lua_State *L )
334{
335 unsigned int h;
336
337 if ( lua_isstring( L, 2 ) ) {
338 const char *where = luaL_checkstring( L, 2 );
339 /* TODO validity checking? */
340 h = hookL_generic( L, where, 0., 1, 0, 3 );
341 } else
342 h = hookL_generic( L, "land", 0., 1, 0, 2 );
343
344 lua_pushinteger( L, h );
345 return 1;
346}
347
371static int hookL_info( lua_State *L )
372{
373 unsigned int h;
374
375 if ( lua_isstring( L, 2 ) ) {
376 char buf[STRMAX_SHORT];
377 const char *where = luaL_checkstring( L, 2 );
378 snprintf( buf, sizeof( buf ), "info_%s", where );
379 /* TODO validity checking? */
380 h = hookL_generic( L, buf, 0., 1, 0, 3 );
381 } else
382 h = hookL_generic( L, "info", 0., 1, 0, 2 );
383
384 lua_pushinteger( L, h );
385 return 1;
386}
387
398static int hookL_load( lua_State *L )
399{
400 unsigned int h = hookL_generic( L, "load", 0., 1, 0, 2 );
401 lua_pushinteger( L, h );
402 return 1;
403}
404
413static int hookL_takeoff( lua_State *L )
414{
415 unsigned int h = hookL_generic( L, "takeoff", 0., 1, 0, 2 );
416 lua_pushinteger( L, h );
417 return 1;
418}
419
428static int hookL_jumpout( lua_State *L )
429{
430 unsigned int h = hookL_generic( L, "jumpout", 0., 1, 0, 2 );
431 lua_pushinteger( L, h );
432 return 1;
433}
434
443static int hookL_jumpin( lua_State *L )
444{
445 unsigned int h = hookL_generic( L, "jumpin", 0., 1, 0, 2 );
446 lua_pushinteger( L, h );
447 return 1;
448}
449
459static int hookL_enter( lua_State *L )
460{
461 unsigned int h = hookL_generic( L, "enter", 0., 1, 0, 2 );
462 lua_pushinteger( L, h );
463 return 1;
464}
465
476static int hookL_hail_spob( lua_State *L )
477{
478 unsigned int h = hookL_generic( L, "hail_spob", 0., 1, 0, 2 );
479 lua_pushinteger( L, h );
480 return 1;
481}
482
493static int hookL_hail( lua_State *L )
494{
495 unsigned int h = hookL_generic( L, "hail", 0., 1, 0, 2 );
496 lua_pushinteger( L, h );
497 return 1;
498}
499
510static int hookL_board( lua_State *L )
511{
512 unsigned int h = hookL_generic( L, "board", 0., 1, 0, 2 );
513 lua_pushinteger( L, h );
514 return 1;
515}
516
528static int hookL_timer( lua_State *L )
529{
530 double s = luaL_checknumber( L, 1 );
531 unsigned int h = hookL_generic( L, NULL, s, 2, 0, 3 );
532 lua_pushinteger( L, h );
533 return 1;
534}
535
542static int hookL_timerClear( lua_State *L )
543{
544 const Event_t *running_event;
545 const Mission *running_mission;
546
547 /* Get stuff. */
548 running_event = event_getFromLua( L );
549 running_mission = misn_getFromLua( L );
550
551 if ( running_mission != NULL )
552 hook_clearMissionTimers( running_mission->id );
553 else if ( running_event != NULL )
554 hook_clearEventTimers( running_event->id );
555 else
556 return NLUA_ERROR(
557 L, _( "Attempting to set a hook outside of a mission or event." ) );
558
559 return 0;
560}
561
577static int hookL_date( lua_State *L )
578{
579 ntime_t t = luaL_validtime( L, 1 );
580 unsigned int h = hookL_generic( L, NULL, 0., 2, t, 3 );
581 lua_pushinteger( L, h );
582 return 1;
583}
584
595static int hookL_commbuy( lua_State *L )
596{
597 unsigned int h = hookL_generic( L, "comm_buy", 0., 1, 0, 2 );
598 lua_pushinteger( L, h );
599 return 1;
600}
601
612static int hookL_commsell( lua_State *L )
613{
614 unsigned int h = hookL_generic( L, "comm_sell", 0., 1, 0, 2 );
615 lua_pushinteger( L, h );
616 return 1;
617}
618
629static int hookL_commjettison( lua_State *L )
630{
631 unsigned int h = hookL_generic( L, "comm_jettison", 0., 1, 0, 2 );
632 lua_pushinteger( L, h );
633 return 1;
634}
635
647static int hookL_gather( lua_State *L )
648{
649 unsigned int h = hookL_generic( L, "gather", 0., 1, 0, 2 );
650 lua_pushinteger( L, h );
651 return 1;
652}
653
664static int hookL_outfitbuy( lua_State *L )
665{
666 unsigned int h = hookL_generic( L, "outfit_buy", 0., 1, 0, 2 );
667 lua_pushinteger( L, h );
668 return 1;
669}
670
681static int hookL_outfitsell( lua_State *L )
682{
683 unsigned int h = hookL_generic( L, "outfit_sell", 0., 1, 0, 2 );
684 lua_pushinteger( L, h );
685 return 1;
686}
687
696static int hookL_equip( lua_State *L )
697{
698 unsigned int h = hookL_generic( L, "equip", 0., 1, 0, 2 );
699 lua_pushinteger( L, h );
700 return 1;
701}
702
713static int hookL_shipbuy( lua_State *L )
714{
715 unsigned int h = hookL_generic( L, "ship_buy", 0., 1, 0, 2 );
716 lua_pushinteger( L, h );
717 return 1;
718}
719
731static int hookL_shipsell( lua_State *L )
732{
733 unsigned int h = hookL_generic( L, "ship_sell", 0., 1, 0, 2 );
734 lua_pushinteger( L, h );
735 return 1;
736}
737
749static int hookL_shipswap( lua_State *L )
750{
751 unsigned int h = hookL_generic( L, "ship_swap", 0., 1, 0, 2 );
752 lua_pushinteger( L, h );
753 return 1;
754}
755
768static int hookL_input( lua_State *L )
769{
770 unsigned int h = hookL_generic( L, "input", 0., 1, 0, 2 );
771 lua_pushinteger( L, h );
772 return 1;
773}
774
787static int hookL_mouse( lua_State *L )
788{
789 unsigned int h = hookL_generic( L, "mouse", 0., 1, 0, 2 );
790 lua_pushinteger( L, h );
791 return 1;
792}
793
806static int hookL_standing( lua_State *L )
807{
808 unsigned int h = hookL_generic( L, "standing", 0., 1, 0, 2 );
809 lua_pushinteger( L, h );
810 return 1;
811}
812
828static int hookL_discover( lua_State *L )
829{
830 unsigned int h = hookL_generic( L, "discover", 0., 1, 0, 2 );
831 lua_pushinteger( L, h );
832 return 1;
833}
834
846static int hookL_asteroidScan( lua_State *L )
847{
848 unsigned int h = hookL_generic( L, "asteroid_scan", 0., 1, 0, 2 );
849 lua_pushinteger( L, h );
850 return 1;
851}
852
865static int hookL_pay( lua_State *L )
866{
867 unsigned int h = hookL_generic( L, "pay", 0., 1, 0, 2 );
868 lua_pushinteger( L, h );
869 return 1;
870}
871
884static int hookL_safe( lua_State *L )
885{
886 unsigned int h = hookL_generic( L, "safe", 0., 1, 0, 2 );
887 lua_pushinteger( L, h );
888 return 1;
889}
890
907static int hookL_update( lua_State *L )
908{
909 unsigned int h = hookL_generic( L, "update", 0., 1, 0, 2 );
910 lua_pushinteger( L, h );
911 return 1;
912}
913
923static int hookL_renderbg( lua_State *L )
924{
925 unsigned int h = hookL_generic( L, "renderbg", 0., 1, 0, 2 );
926 lua_pushinteger( L, h );
927 return 1;
928}
929
939static int hookL_renderfg( lua_State *L )
940{
941 unsigned int h = hookL_generic( L, "renderfg", 0., 1, 0, 2 );
942 lua_pushinteger( L, h );
943 return 1;
944}
945
955static int hookL_rendertop( lua_State *L )
956{
957 unsigned int h = hookL_generic( L, "rendertop", 0., 1, 0, 2 );
958 lua_pushinteger( L, h );
959 return 1;
960}
961
971static int hookL_mission_done( lua_State *L )
972{
973 unsigned int h = hookL_generic( L, "mission_done", 0., 1, 0, 2 );
974 lua_pushinteger( L, h );
975 return 1;
976}
977
987static int hookL_event_done( lua_State *L )
988{
989 unsigned int h = hookL_generic( L, "event_done", 0., 1, 0, 2 );
990 lua_pushinteger( L, h );
991 return 1;
992}
993
1005static int hookL_custom( lua_State *L )
1006{
1007 const char *hookname = luaL_checkstring( L, 1 );
1008 unsigned int h = hookL_generic( L, hookname, 0., 2, 0, 3 );
1009 lua_pushinteger( L, h );
1010 return 1;
1011}
1012
1079static int hookL_pilot( lua_State *L )
1080{
1081 unsigned int h;
1082 LuaPilot p;
1083 int type;
1084 const char *hook_type;
1085 char buf[64]; /* Large enough buffer to hold any of the allowed hook-type
1086 names. */
1087
1088 /* Parameters. */
1089 if ( lua_ispilot( L, 1 ) )
1090 p = luaL_checkpilot( L, 1 );
1091 else if ( lua_isnil( L, 1 ) )
1092 p = 0;
1093 else
1094 return NLUA_ERROR(
1095 L,
1096 _( "Invalid parameter #1 for hook.pilot, expecting pilot or nil." ) );
1097 hook_type = luaL_checkstring( L, 2 );
1098
1099 /* Check to see if hook_type is valid */
1100 if ( strcmp( hook_type, "creation" ) == 0 )
1101 type = PILOT_HOOK_CREATION;
1102 else if ( strcmp( hook_type, "death" ) == 0 )
1103 type = PILOT_HOOK_DEATH;
1104 else if ( strcmp( hook_type, "exploded" ) == 0 )
1105 type = PILOT_HOOK_EXPLODED;
1106 else if ( strcmp( hook_type, "boarding" ) == 0 )
1107 type = PILOT_HOOK_BOARDING;
1108 else if ( strcmp( hook_type, "boardall" ) == 0 )
1109 type = PILOT_HOOK_BOARD_ALL;
1110 else if ( strcmp( hook_type, "board" ) == 0 )
1111 type = PILOT_HOOK_BOARD;
1112 else if ( strcmp( hook_type, "disable" ) == 0 )
1113 type = PILOT_HOOK_DISABLE;
1114 else if ( strcmp( hook_type, "undisable" ) == 0 )
1115 type = PILOT_HOOK_UNDISABLE;
1116 else if ( strcmp( hook_type, "jump" ) == 0 )
1117 type = PILOT_HOOK_JUMP;
1118 else if ( strcmp( hook_type, "hail" ) == 0 )
1119 type = PILOT_HOOK_HAIL;
1120 else if ( strcmp( hook_type, "land" ) == 0 )
1121 type = PILOT_HOOK_LAND;
1122 else if ( strcmp( hook_type, "attacked" ) == 0 )
1123 type = PILOT_HOOK_ATTACKED;
1124 else if ( strcmp( hook_type, "discovered" ) == 0 )
1125 type = PILOT_HOOK_DISCOVERED;
1126 else if ( strcmp( hook_type, "scan" ) == 0 )
1127 type = PILOT_HOOK_SCAN;
1128 else if ( strcmp( hook_type, "scanned" ) == 0 )
1129 type = PILOT_HOOK_SCANNED;
1130 else if ( strcmp( hook_type, "idle" ) == 0 )
1131 type = PILOT_HOOK_IDLE;
1132 else if ( strcmp( hook_type, "lockon" ) == 0 )
1133 type = PILOT_HOOK_LOCKON;
1134 else if ( strcmp( hook_type, "stealth" ) == 0 )
1135 type = PILOT_HOOK_STEALTH;
1136 else /* hook_type not valid */
1137 return NLUA_ERROR( L, _( "Invalid pilot hook type: '%s'" ), hook_type );
1138
1139#ifdef DEBUGGING
1140 if ( ( type == PILOT_HOOK_CREATION ) && ( p != 0 ) )
1141 return NLUA_ERROR( L, _( "'creation' pilot hook can not be set on a "
1142 "specific pilot, only globally." ) );
1143#endif /* DEBUGGING */
1144
1145 /* actually add the hook */
1146 snprintf( buf, sizeof( buf ), "p_%s", hook_type );
1147 h = hookL_generic( L, buf, 0., 3, 0, 4 );
1148 if ( p == 0 )
1149 pilots_addGlobalHook( type, h );
1150 else
1151 pilot_addHook( pilot_get( p ), type, h );
1152
1153 lua_pushinteger( L, h );
1154 return 1;
1155}
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:179
unsigned int hook_addTimerEvt(unsigned int parent, const char *func, double ms)
Adds a new event type hook timer.
Definition hook.c:596
nlua_env hook_env(unsigned int hook)
Gets the lua env for a hook.
Definition hook.c:1069
unsigned int hook_addEvent(unsigned int parent, const char *func, const char *stack)
Adds a new event type hook.
Definition hook.c:550
void hook_rm(unsigned int id)
Removes a hook.
Definition hook.c:846
void hook_clearEventTimers(unsigned int parent)
Clears the timer hooks for an event.
Definition hook.c:1212
unsigned int hook_addTimerMisn(unsigned int parent, const char *func, double ms)
Adds a new mission type hook timer hook.
Definition hook.c:571
unsigned int hook_addMisn(unsigned int parent, const char *func, const char *stack)
Adds a new mission type hook.
Definition hook.c:529
void hook_clearMissionTimers(unsigned int parent)
Clears the timer hooks for a mission.
Definition hook.c:1199
Mission ** player_missions
Definition mission.c:45
Header file with generic functions and naev-specifics.
lua_State * naevL
Definition nlua.c:54
Event_t * event_getFromLua(lua_State *L)
Gets the current running event from user data.
Definition nlua_evt.c:103
static int hookL_date(lua_State *L)
Hooks a date change with custom resolution.
Definition nlua_hook.c:577
static int hookL_rm(lua_State *L)
Lua bindings to manipulate hooks.
Definition nlua_hook.c:160
static int hookL_discover(lua_State *L)
Hooks the function to when the player discovers an spob, jump point or the likes.
Definition nlua_hook.c:828
static int hookL_load(lua_State *L)
Hooks the function to the player loading the game (starts landed).
Definition nlua_hook.c:398
static int hookL_custom(lua_State *L)
Hook run once at the end of the next frame regardless when manually triggered. Can be triggered manua...
Definition nlua_hook.c:1005
static int hookL_hail(lua_State *L)
Hooks the function to the player hailing any ship (not a spob).
Definition nlua_hook.c:493
void hookL_unsetarg(unsigned int hook)
Unsets a Lua argument.
Definition nlua_hook.c:201
static int hookL_gather(lua_State *L)
Hooks the function to the player gatehring any sort of commodity in space.
Definition nlua_hook.c:647
static int hookL_renderfg(lua_State *L)
Hook that runs during rendering the foreground (just below the gui stuff). Meant to be only for rende...
Definition nlua_hook.c:939
static int hookL_shipbuy(lua_State *L)
Hooks the function to the player buying any sort of ship.
Definition nlua_hook.c:713
static int hookL_timer(lua_State *L)
Hooks a timer.
Definition nlua_hook.c:528
static int hookL_pilot(lua_State *L)
Hooks the function to a specific pilot.
Definition nlua_hook.c:1079
static int hookL_outfitbuy(lua_State *L)
Hooks the function to the player buying any sort of outfit.
Definition nlua_hook.c:664
static int hookL_hail_spob(lua_State *L)
Hooks the function to the player hailing any spob.
Definition nlua_hook.c:476
static unsigned int hookL_generic(lua_State *L, const char *stack, double ms, int pos, ntime_t date, int arg)
Creates a mission hook to a certain stack.
Definition nlua_hook.c:256
static int hookL_input(lua_State *L)
Hooks the function to the player pressing any input.
Definition nlua_hook.c:768
int nlua_loadHook(nlua_env env)
Loads the hook Lua library.
Definition nlua_hook.c:125
static int hookL_asteroidScan(lua_State *L)
Hooks the function to when the player scans an asteroid.
Definition nlua_hook.c:846
static int hookL_jumpin(lua_State *L)
Hooks the function to the player jumping (after changing systems).
Definition nlua_hook.c:443
static int hookL_info(lua_State *L)
Hooks the function to the info menu.
Definition nlua_hook.c:371
static int hookL_board(lua_State *L)
Hooks the function to the player boarding any ship.
Definition nlua_hook.c:510
static int hookL_rendertop(lua_State *L)
Hook that runs during rendering aove everything. Meant to be as an alternative to doing post-processi...
Definition nlua_hook.c:955
static int hookL_setarg(unsigned int hook, int ind)
Sets a Lua argument for a hook.
Definition nlua_hook.c:178
static int hookL_equip(lua_State *L)
Hooks the function to the player equipping or deequipping any outfit.
Definition nlua_hook.c:696
static int hookL_commsell(lua_State *L)
Hooks the function to the player selling any sort of commodity.
Definition nlua_hook.c:612
static int hookL_safe(lua_State *L)
Hook run once at the end of the next frame regardless of anything that can happen.
Definition nlua_hook.c:884
static int hookL_shipsell(lua_State *L)
Hooks the function to the player selling any sort of ship.
Definition nlua_hook.c:731
static int hookL_land(lua_State *L)
Hooks the function to the player landing.
Definition nlua_hook.c:333
static int hookL_standing(lua_State *L)
Hooks the function to any faction standing change.
Definition nlua_hook.c:806
static const luaL_Reg hookL_methods[]
Definition nlua_hook.c:71
static int hookL_takeoff(lua_State *L)
Hooks the function to the player taking off.
Definition nlua_hook.c:413
static int hookL_commjettison(lua_State *L)
Hooks the function to the player jettisoning any sort of commodity.
Definition nlua_hook.c:629
static int hookL_commbuy(lua_State *L)
Hooks the function to the player buying any sort of commodity.
Definition nlua_hook.c:595
static int hookL_outfitsell(lua_State *L)
Hooks the function to the player selling any sort of outfit.
Definition nlua_hook.c:681
static int hookL_event_done(lua_State *L)
Hook that runs when a event is complete. The entire event information table is passed similar to play...
Definition nlua_hook.c:987
static int hookL_shipswap(lua_State *L)
Hooks the function to the player swapping their ship.
Definition nlua_hook.c:749
static int hookL_pay(lua_State *L)
Hooks the function to when the player receives or loses money through player.pay() (the Lua function ...
Definition nlua_hook.c:865
static int hookL_renderbg(lua_State *L)
Hook that runs during rendering the background (just above the static background stuff)....
Definition nlua_hook.c:923
int hookL_getarg(unsigned int hook)
Gets a Lua argument for a hook.
Definition nlua_hook.c:224
static int hookL_enter(lua_State *L)
Hooks the function to the player entering a system (triggers when taking off too).
Definition nlua_hook.c:459
static int hookL_mission_done(lua_State *L)
Hook that runs when a mission is complete. The entire mission information table is passed similar to ...
Definition nlua_hook.c:971
static int hookL_mouse(lua_State *L)
Hooks the function to the player clicking the mouse.
Definition nlua_hook.c:787
static int hookL_jumpout(lua_State *L)
Hooks the function to the player jumping (before changing systems).
Definition nlua_hook.c:428
static int hookL_update(lua_State *L)
Hook run at the end of each frame when the update routine is run (game is not paused,...
Definition nlua_hook.c:907
static int hookL_timerClear(lua_State *L)
Clear all timers added by hook.timer. This only affects timers created by the mission or event callin...
Definition nlua_hook.c:542
Mission * misn_getFromLua(lua_State *L)
Gets the mission that's being currently run in Lua.
Definition nlua_misn.c:180
int lua_ispilot(lua_State *L, int ind)
Checks to see if ind is a pilot.
Definition nlua_pilot.c:591
LuaPilot luaL_checkpilot(lua_State *L, int ind)
Gets pilot at index or raises error if there is no pilot at index.
Definition nlua_pilot.c:546
ntime_t luaL_validtime(lua_State *L, int ind)
Gets a time directly.
Definition nlua_time.c:112
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
Definition pilot.c:640
void pilots_addGlobalHook(int type, unsigned int hook)
Adds a pilot global hook.
Definition pilot_hook.c:139
void pilot_addHook(Pilot *pilot, int type, unsigned int hook)
Adds a hook to the pilot.
Definition pilot_hook.c:116
Activated event structure.
Definition event.h:12
unsigned int id
Definition event.h:13
Represents an active mission.
Definition mission.h:83
unsigned int id
Definition mission.h:86