[Add] Pilot "jump" hook.

This commit is contained in:
Allanis 2013-11-12 00:42:31 +00:00
parent 338a41a8e4
commit a42c21da4e
4 changed files with 29 additions and 6 deletions

View File

@ -180,7 +180,7 @@ void hook_cleanup(void) {
static int hook_needSave(Hook* h) { static int hook_needSave(Hook* h) {
int i; int i;
char* nosave[] = { char* nosave[] = {
"death", "board", "disable", /* Pilot hooks. */ "death", "board", "disable", "jump", /* Pilot hooks. */
"end" }; "end" };
for(i = 0; strcmp(nosave[i], "end") != 0; i++) for(i = 0; strcmp(nosave[i], "end") != 0; i++)

View File

@ -764,6 +764,25 @@ static int hook_enter(lua_State* L) {
return 0; 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) { static int hook_pilot(lua_State* L) {
LLUA_MIN_ARGS(2); LLUA_MIN_ARGS(2);
unsigned int h, p; unsigned int h, p;
@ -782,6 +801,7 @@ static int hook_pilot(lua_State* L) {
if(strcmp(hook_type, "death")==0) type = PILOT_HOOK_DEATH; 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, "board")==0) type = PILOT_HOOK_BOARD;
else if(strcmp(hook_type, "disable")==0) type = PILOT_HOOK_DISABLE; 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. */ else { /* Hook type not valid. */
LLUA_DEBUG("Invalid pilot hook type: '%s'", hook_type); LLUA_DEBUG("Invalid pilot hook type: '%s'", hook_type);
return 0; return 0;

View File

@ -693,8 +693,10 @@ static void pilot_hyperspace(Pilot* p) {
if(SDL_GetTicks() > p->ptimer) { if(SDL_GetTicks() > p->ptimer) {
if(p == player) { if(p == player) {
player_brokeHyperspace(); player_brokeHyperspace();
} else } else {
pilot_setFlag(p, PILOT_DELETE); /* Set flag to delete pilot. */ if(p->hook_type == PILOT_HOOK_JUMP)
hook_runID(p->hook);
}
return; return;
} }
/* Keep accelerating - hyperspace uses much bigger accel. */ /* Keep accelerating - hyperspace uses much bigger accel. */

View File

@ -25,6 +25,7 @@
#define PILOT_HOOK_DEATH 1 /**< Pilot died. */ #define PILOT_HOOK_DEATH 1 /**< Pilot died. */
#define PILOT_HOOK_BOARD 2 /**< Pilot got boarded. */ #define PILOT_HOOK_BOARD 2 /**< Pilot got boarded. */
#define PILOT_HOOK_DISABLE 3 /**< Pilot got disabled. */ #define PILOT_HOOK_DISABLE 3 /**< Pilot got disabled. */
#define PILOT_HOOK_JUMP 4 /**< Pilot jumped. */
/* Flags. */ /* Flags. */
#define pilot_isFlag(p,f) (p->flags & (f)) /**< Check if flag f is set on pilot p. */ #define pilot_isFlag(p,f) (p->flags & (f)) /**< Check if flag f is set on pilot p. */