28#include "nlua_pilot.h"
118static unsigned int hookL_generic( lua_State *L,
const char* stack,
double ms,
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 );
255static unsigned int hookL_generic( lua_State *L,
const char* stack,
double sec,
int pos, ntime_t date,
int arg )
263 func = luaL_checkstring(L,pos);
269 if (running_mission != NULL) {
276 WARN(_(
"Mission not in stack trying to hook, forgot to run misn.accept()?"));
283 h = hook_addDateMisn( running_mission->
id, func, date );
287 else if (running_event != NULL) {
291 h = hook_addDateEvt( running_event->
id, func, date );
296 return NLUA_ERROR(L,_(
"Attempting to set a hook outside of a mission or event."));
299 return NLUA_ERROR(L,_(
"No hook target was set."));
302 if (!lua_isnoneornil(L,arg))
334 if (lua_isstring(L,2)) {
335 const char *where = luaL_checkstring(L, 2);
342 lua_pushinteger( L, h );
372 if (lua_isstring(L,2)) {
373 char buf[STRMAX_SHORT];
374 const char *where = luaL_checkstring(L, 2);
375 snprintf( buf,
sizeof(buf),
"info_%s", where );
382 lua_pushinteger( L, h );
399 lua_pushinteger( L, h );
414 lua_pushinteger( L, h );
429 lua_pushinteger( L, h );
444 lua_pushinteger( L, h );
460 lua_pushinteger( L, h );
476 unsigned int h =
hookL_generic( L,
"hail_spob", 0., 1, 0, 2 );
477 lua_pushinteger( L, h );
494 lua_pushinteger( L, h );
511 lua_pushinteger( L, h );
528 double s = luaL_checknumber( L, 1 );
530 lua_pushinteger( L, h );
551 lua_pushinteger( L, h );
567 unsigned int h =
hookL_generic( L,
"comm_buy", 0., 1, 0, 2 );
568 lua_pushinteger( L, h );
584 unsigned int h =
hookL_generic( L,
"comm_sell", 0., 1, 0, 2 );
585 lua_pushinteger( L, h );
601 unsigned int h =
hookL_generic( L,
"comm_jettison", 0., 1, 0, 2 );
602 lua_pushinteger( L, h );
619 lua_pushinteger( L, h );
635 unsigned int h =
hookL_generic( L,
"outfit_buy", 0., 1, 0, 2 );
636 lua_pushinteger( L, h );
652 unsigned int h =
hookL_generic( L,
"outfit_sell", 0., 1, 0, 2 );
653 lua_pushinteger( L, h );
668 lua_pushinteger( L, h );
684 unsigned int h =
hookL_generic( L,
"ship_buy", 0., 1, 0, 2 );
685 lua_pushinteger( L, h );
701 unsigned int h =
hookL_generic( L,
"ship_sell", 0., 1, 0, 2 );
702 lua_pushinteger( L, h );
718 unsigned int h =
hookL_generic( L,
"ship_swap", 0., 1, 0, 2 );
719 lua_pushinteger( L, h );
739 lua_pushinteger( L, h );
756 lua_pushinteger( L, h );
774 unsigned int h =
hookL_generic( L,
"standing", 0., 1, 0, 2 );
775 lua_pushinteger( L, h );
795 unsigned int h =
hookL_generic( L,
"discover", 0., 1, 0, 2 );
796 lua_pushinteger( L, h );
812 unsigned int h =
hookL_generic( L,
"asteroid_scan", 0., 1, 0, 2 );
813 lua_pushinteger( L, h );
831 lua_pushinteger( L, h );
848 lua_pushinteger( L, h );
868 lua_pushinteger( L, h );
882 unsigned int h =
hookL_generic( L,
"renderbg", 0., 1, 0, 2 );
883 lua_pushinteger( L, h );
897 unsigned int h =
hookL_generic( L,
"renderfg", 0., 1, 0, 2 );
898 lua_pushinteger( L, h );
912 unsigned int h =
hookL_generic( L,
"rendertop", 0., 1, 0, 2 );
913 lua_pushinteger( L, h );
927 unsigned int h =
hookL_generic( L,
"mission_done", 0., 1, 0, 2 );
928 lua_pushinteger( L, h );
942 unsigned int h =
hookL_generic( L,
"event_done", 0., 1, 0, 2 );
943 lua_pushinteger( L, h );
958 const char *hookname = luaL_checkstring(L,1);
960 lua_pushinteger( L, h );
1038 const char *hook_type;
1044 else if (lua_isnil(L,1))
1047 return NLUA_ERROR(L, _(
"Invalid parameter #1 for hook.pilot, expecting pilot or nil."));
1048 hook_type = luaL_checkstring(L,2);
1051 if (strcmp(hook_type,
"creation")==0) type = PILOT_HOOK_CREATION;
1052 else if (strcmp(hook_type,
"death")==0) type = PILOT_HOOK_DEATH;
1053 else if (strcmp(hook_type,
"exploded")==0) type = PILOT_HOOK_EXPLODED;
1054 else if (strcmp(hook_type,
"boarding")==0) type = PILOT_HOOK_BOARDING;
1055 else if (strcmp(hook_type,
"boardall")==0) type = PILOT_HOOK_BOARD_ALL;
1056 else if (strcmp(hook_type,
"board")==0) type = PILOT_HOOK_BOARD;
1057 else if (strcmp(hook_type,
"disable")==0) type = PILOT_HOOK_DISABLE;
1058 else if (strcmp(hook_type,
"undisable")==0)type = PILOT_HOOK_UNDISABLE;
1059 else if (strcmp(hook_type,
"jump")==0) type = PILOT_HOOK_JUMP;
1060 else if (strcmp(hook_type,
"hail")==0) type = PILOT_HOOK_HAIL;
1061 else if (strcmp(hook_type,
"land")==0) type = PILOT_HOOK_LAND;
1062 else if (strcmp(hook_type,
"attacked")==0) type = PILOT_HOOK_ATTACKED;
1063 else if (strcmp(hook_type,
"discovered")==0)type = PILOT_HOOK_DISCOVERED;
1064 else if (strcmp(hook_type,
"scan")==0) type = PILOT_HOOK_SCAN;
1065 else if (strcmp(hook_type,
"scanned")==0) type = PILOT_HOOK_SCANNED;
1066 else if (strcmp(hook_type,
"idle")==0) type = PILOT_HOOK_IDLE;
1067 else if (strcmp(hook_type,
"lockon")==0) type = PILOT_HOOK_LOCKON;
1068 else if (strcmp(hook_type,
"stealth")==0) type = PILOT_HOOK_STEALTH;
1070 return NLUA_ERROR(L, _(
"Invalid pilot hook type: '%s'"), hook_type);
1073 if ((type == PILOT_HOOK_CREATION) && (p!=0))
1074 return NLUA_ERROR( L, _(
"'creation' pilot hook can not be set on a specific pilot, only globally.") );
1078 snprintf( buf,
sizeof(buf),
"p_%s", hook_type );
1085 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.
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.
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,...
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.