[Add] Pilot "jump" hook.
This commit is contained in:
parent
338a41a8e4
commit
a42c21da4e
@ -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++)
|
||||||
|
@ -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;
|
||||||
@ -779,9 +798,10 @@ static int hook_pilot(lua_State* L) {
|
|||||||
else LLUA_INVALID_PARAMETER();
|
else LLUA_INVALID_PARAMETER();
|
||||||
|
|
||||||
/* Check to see if hook_type is valid. */
|
/* Check to see if hook_type is valid. */
|
||||||
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;
|
||||||
|
@ -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. */
|
||||||
|
@ -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. */
|
||||||
|
Loading…
Reference in New Issue
Block a user