26#include "nlua_pilot.h"
117static unsigned int hookL_generic( lua_State *L,
const char *stack,
double ms,
118 int pos, ntime_t date,
int arg );
163 long h = luaL_optlong( L, 1, -1 );
183 nlua_getenv(
naevL, env,
"mem" );
184 lua_getfield(
naevL, -1,
"__hook_arg" );
185 if ( lua_isnil(
naevL, -1 ) ) {
187 lua_newtable(
naevL );
188 lua_pushvalue(
naevL, -1 );
189 lua_setfield(
naevL, -3,
"__hook_arg" );
191 lua_pushinteger(
naevL, hook );
192 lua_pushvalue(
naevL, ind );
193 lua_settable(
naevL, -3 );
205 if ( env == LUA_NOREF )
208 nlua_getenv(
naevL, env,
"mem" );
209 lua_getfield(
naevL, -1,
"__hook_arg" );
210 if ( !lua_isnil(
naevL, -1 ) ) {
211 lua_pushinteger(
naevL, hook );
212 lua_pushnil(
naevL );
213 lua_settable(
naevL, -3 );
228 if ( env == LUA_NOREF )
231 nlua_getenv(
naevL, env,
"mem" );
232 lua_getfield(
naevL, -1,
"__hook_arg" );
233 if ( !lua_isnil(
naevL, -1 ) ) {
234 lua_pushinteger(
naevL, hook );
235 lua_gettable(
naevL, -2 );
236 lua_remove(
naevL, -2 );
238 lua_remove(
naevL, -2 );
256static unsigned int hookL_generic( lua_State *L,
const char *stack,
double sec,
257 int pos, ntime_t date,
int arg )
265 func = luaL_checkstring( L, pos );
271 if ( running_mission != NULL ) {
278 NLUA_WARN( L, _(
"Mission not in stack trying to hook, forgot to run "
279 "misn.accept()?" ) );
285 else if ( date != 0 )
286 h = hook_addDateMisn( running_mission->
id, func, date );
289 }
else if ( running_event != NULL ) {
292 else if ( date != 0 )
293 h = hook_addDateEvt( running_event->
id, func, date );
298 L, _(
"Attempting to set a hook outside of a mission or event." ) );
301 return NLUA_ERROR( L, _(
"No hook target was set." ) );
304 if ( !lua_isnoneornil( L, arg ) )
337 if ( lua_isstring( L, 2 ) ) {
338 const char *where = luaL_checkstring( L, 2 );
344 lua_pushinteger( L, h );
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 );
384 lua_pushinteger( L, h );
401 lua_pushinteger( L, h );
416 lua_pushinteger( L, h );
431 lua_pushinteger( L, h );
446 lua_pushinteger( L, h );
462 lua_pushinteger( L, h );
478 unsigned int h =
hookL_generic( L,
"hail_spob", 0., 1, 0, 2 );
479 lua_pushinteger( L, h );
496 lua_pushinteger( L, h );
513 lua_pushinteger( L, h );
530 double s = luaL_checknumber( L, 1 );
532 lua_pushinteger( L, h );
545 const Mission *running_mission;
551 if ( running_mission != NULL )
553 else if ( running_event != NULL )
557 L, _(
"Attempting to set a hook outside of a mission or event." ) );
581 lua_pushinteger( L, h );
597 unsigned int h =
hookL_generic( L,
"comm_buy", 0., 1, 0, 2 );
598 lua_pushinteger( L, h );
614 unsigned int h =
hookL_generic( L,
"comm_sell", 0., 1, 0, 2 );
615 lua_pushinteger( L, h );
631 unsigned int h =
hookL_generic( L,
"comm_jettison", 0., 1, 0, 2 );
632 lua_pushinteger( L, h );
650 lua_pushinteger( L, h );
666 unsigned int h =
hookL_generic( L,
"outfit_buy", 0., 1, 0, 2 );
667 lua_pushinteger( L, h );
683 unsigned int h =
hookL_generic( L,
"outfit_sell", 0., 1, 0, 2 );
684 lua_pushinteger( L, h );
699 lua_pushinteger( L, h );
715 unsigned int h =
hookL_generic( L,
"ship_buy", 0., 1, 0, 2 );
716 lua_pushinteger( L, h );
733 unsigned int h =
hookL_generic( L,
"ship_sell", 0., 1, 0, 2 );
734 lua_pushinteger( L, h );
751 unsigned int h =
hookL_generic( L,
"ship_swap", 0., 1, 0, 2 );
752 lua_pushinteger( L, h );
771 lua_pushinteger( L, h );
790 lua_pushinteger( L, h );
808 unsigned int h =
hookL_generic( L,
"standing", 0., 1, 0, 2 );
809 lua_pushinteger( L, h );
830 unsigned int h =
hookL_generic( L,
"discover", 0., 1, 0, 2 );
831 lua_pushinteger( L, h );
848 unsigned int h =
hookL_generic( L,
"asteroid_scan", 0., 1, 0, 2 );
849 lua_pushinteger( L, h );
868 lua_pushinteger( L, h );
887 lua_pushinteger( L, h );
910 lua_pushinteger( L, h );
925 unsigned int h =
hookL_generic( L,
"renderbg", 0., 1, 0, 2 );
926 lua_pushinteger( L, h );
941 unsigned int h =
hookL_generic( L,
"renderfg", 0., 1, 0, 2 );
942 lua_pushinteger( L, h );
957 unsigned int h =
hookL_generic( L,
"rendertop", 0., 1, 0, 2 );
958 lua_pushinteger( L, h );
973 unsigned int h =
hookL_generic( L,
"mission_done", 0., 1, 0, 2 );
974 lua_pushinteger( L, h );
989 unsigned int h =
hookL_generic( L,
"event_done", 0., 1, 0, 2 );
990 lua_pushinteger( L, h );
1007 const char *hookname = luaL_checkstring( L, 1 );
1009 lua_pushinteger( L, h );
1084 const char *hook_type;
1091 else if ( lua_isnil( L, 1 ) )
1096 _(
"Invalid parameter #1 for hook.pilot, expecting pilot or nil." ) );
1097 hook_type = luaL_checkstring( L, 2 );
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;
1137 return NLUA_ERROR( L, _(
"Invalid pilot hook type: '%s'" ), hook_type );
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." ) );
1146 snprintf( buf,
sizeof( buf ),
"p_%s", hook_type );
1153 lua_pushinteger( L, h );
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
unsigned int hook_addTimerEvt(unsigned int parent, const char *func, double ms)
Adds a new event type hook timer.
nlua_env hook_env(unsigned int hook)
Gets the lua env for a hook.
unsigned int hook_addEvent(unsigned int parent, const char *func, const char *stack)
Adds a new event type hook.
void hook_rm(unsigned int id)
Removes a hook.
void hook_clearEventTimers(unsigned int parent)
Clears the timer hooks for an event.
unsigned int hook_addTimerMisn(unsigned int parent, const char *func, double ms)
Adds a new mission type hook timer hook.
unsigned int hook_addMisn(unsigned int parent, const char *func, const char *stack)
Adds a new mission type hook.
void hook_clearMissionTimers(unsigned int parent)
Clears the timer hooks for a mission.
Mission ** player_missions
Header file with generic functions and naev-specifics.
Event_t * event_getFromLua(lua_State *L)
Gets the current running event from user data.
static int hookL_date(lua_State *L)
Hooks a date change with custom resolution.
static int hookL_rm(lua_State *L)
Lua bindings to manipulate hooks.
static int hookL_discover(lua_State *L)
Hooks the function to when the player discovers an spob, jump point or the likes.
static int hookL_load(lua_State *L)
Hooks the function to the player loading the game (starts landed).
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...
static int hookL_hail(lua_State *L)
Hooks the function to the player hailing any ship (not a spob).
void hookL_unsetarg(unsigned int hook)
Unsets a Lua argument.
static int hookL_gather(lua_State *L)
Hooks the function to the player gatehring any sort of commodity in space.
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...
static int hookL_shipbuy(lua_State *L)
Hooks the function to the player buying any sort of ship.
static int hookL_timer(lua_State *L)
Hooks a timer.
static int hookL_pilot(lua_State *L)
Hooks the function to a specific pilot.
static int hookL_outfitbuy(lua_State *L)
Hooks the function to the player buying any sort of outfit.
static int hookL_hail_spob(lua_State *L)
Hooks the function to the player hailing any spob.
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.
static int hookL_input(lua_State *L)
Hooks the function to the player pressing any input.
int nlua_loadHook(nlua_env env)
Loads the hook Lua library.
static int hookL_asteroidScan(lua_State *L)
Hooks the function to when the player scans an asteroid.
static int hookL_jumpin(lua_State *L)
Hooks the function to the player jumping (after changing systems).
static int hookL_info(lua_State *L)
Hooks the function to the info menu.
static int hookL_board(lua_State *L)
Hooks the function to the player boarding any ship.
static int hookL_rendertop(lua_State *L)
Hook that runs during rendering aove everything. Meant to be as an alternative to doing post-processi...
static int hookL_setarg(unsigned int hook, int ind)
Sets a Lua argument for a hook.
static int hookL_equip(lua_State *L)
Hooks the function to the player equipping or deequipping any outfit.
static int hookL_commsell(lua_State *L)
Hooks the function to the player selling any sort of commodity.
static int hookL_safe(lua_State *L)
Hook run once at the end of the next frame regardless of anything that can happen.
static int hookL_shipsell(lua_State *L)
Hooks the function to the player selling any sort of ship.
static int hookL_land(lua_State *L)
Hooks the function to the player landing.
static int hookL_standing(lua_State *L)
Hooks the function to any faction standing change.
static const luaL_Reg hookL_methods[]
static int hookL_takeoff(lua_State *L)
Hooks the function to the player taking off.
static int hookL_commjettison(lua_State *L)
Hooks the function to the player jettisoning any sort of commodity.
static int hookL_commbuy(lua_State *L)
Hooks the function to the player buying any sort of commodity.
static int hookL_outfitsell(lua_State *L)
Hooks the function to the player selling any sort of outfit.
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...
static int hookL_shipswap(lua_State *L)
Hooks the function to the player swapping their ship.
static int hookL_pay(lua_State *L)
Hooks the function to when the player receives or loses money through player.pay() (the Lua function ...
static int hookL_renderbg(lua_State *L)
Hook that runs during rendering the background (just above the static background stuff)....
int hookL_getarg(unsigned int hook)
Gets a Lua argument for a hook.
static int hookL_enter(lua_State *L)
Hooks the function to the player entering a system (triggers when taking off too).
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 ...
static int hookL_mouse(lua_State *L)
Hooks the function to the player clicking the mouse.
static int hookL_jumpout(lua_State *L)
Hooks the function to the player jumping (before changing systems).
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,...
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...
Mission * misn_getFromLua(lua_State *L)
Gets the mission that's being currently run in Lua.
int lua_ispilot(lua_State *L, int ind)
Checks to see if ind is a pilot.
LuaPilot luaL_checkpilot(lua_State *L, int ind)
Gets pilot at index or raises error if there is no pilot at index.
ntime_t luaL_validtime(lua_State *L, int ind)
Gets a time directly.
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
void pilots_addGlobalHook(int type, unsigned int hook)
Adds a pilot global hook.
void pilot_addHook(Pilot *pilot, int type, unsigned int hook)
Adds a hook to the pilot.
Activated event structure.
Represents an active mission.