diff --git a/src/hook.c b/src/hook.c index 214b6da..a6c3fb4 100644 --- a/src/hook.c +++ b/src/hook.c @@ -180,7 +180,7 @@ void hook_cleanup(void) { static int hook_needSave(Hook* h) { int i; char* nosave[] = { - "death", "board", "disable", /* Pilot hooks. */ + "death", "board", "disable", "jump", /* Pilot hooks. */ "end" }; for(i = 0; strcmp(nosave[i], "end") != 0; i++) diff --git a/src/misn_lua.c b/src/misn_lua.c index 0cdf8cc..08ed006 100644 --- a/src/misn_lua.c +++ b/src/misn_lua.c @@ -764,6 +764,25 @@ static int hook_enter(lua_State* L) { return 0; } +/** + * @fn static int hook_pilot(lua_State* L) + * @ingroup HOOK + * + * @brief number pilot(number pilot, string type, string func) + * + * Hooks the function to a specific pilot. + * + * You can hook to different actions. At the moment hook system only supports: + * -- "death" : Triggered when pilot dies. + * -- "board" : Triggered when pilot is boarded. + * -- "disable" : Triggered when pilot is disabled. + * -- "jump" : Triggered when pilot jumps to hyperspace. + * + * @param pilot Pilot identifier to hook. + * @param typer One of the supported hook types. + * @param func Function to run when hook is triggered. + * @return Hook identifier. + */ static int hook_pilot(lua_State* L) { LLUA_MIN_ARGS(2); unsigned int h, p; @@ -779,9 +798,10 @@ static int hook_pilot(lua_State* L) { else LLUA_INVALID_PARAMETER(); /* Check to see if hook_type is valid. */ - if(strcmp(hook_type, "death")==0) type = PILOT_HOOK_DEATH; - else if(strcmp(hook_type, "board")==0) type = PILOT_HOOK_BOARD; - else if(strcmp(hook_type, "disable")==0) type = PILOT_HOOK_DISABLE; + if(strcmp(hook_type, "death")==0) type = PILOT_HOOK_DEATH; + else if(strcmp(hook_type, "board")==0) type = PILOT_HOOK_BOARD; + else if(strcmp(hook_type, "disable")==0) type = PILOT_HOOK_DISABLE; + else if(strcmp(hook_type, "jump")==0) type = PILOT_HOOK_JUMP; else { /* Hook type not valid. */ LLUA_DEBUG("Invalid pilot hook type: '%s'", hook_type); return 0; diff --git a/src/pilot.c b/src/pilot.c index 3cfede1..fb0452c 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -693,8 +693,10 @@ static void pilot_hyperspace(Pilot* p) { if(SDL_GetTicks() > p->ptimer) { if(p == player) { player_brokeHyperspace(); - } else - pilot_setFlag(p, PILOT_DELETE); /* Set flag to delete pilot. */ + } else { + if(p->hook_type == PILOT_HOOK_JUMP) + hook_runID(p->hook); + } return; } /* Keep accelerating - hyperspace uses much bigger accel. */ diff --git a/src/pilot.h b/src/pilot.h index 0a5ed8b..d2bf55e 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -25,6 +25,7 @@ #define PILOT_HOOK_DEATH 1 /**< Pilot died. */ #define PILOT_HOOK_BOARD 2 /**< Pilot got boarded. */ #define PILOT_HOOK_DISABLE 3 /**< Pilot got disabled. */ +#define PILOT_HOOK_JUMP 4 /**< Pilot jumped. */ /* Flags. */ #define pilot_isFlag(p,f) (p->flags & (f)) /**< Check if flag f is set on pilot p. */