From 445bb0b99b9bd35b7a9092bb8a6bfdf608f39669 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 22 Apr 2019 00:29:47 -0400 Subject: [PATCH] New IntermissionThinker hook --- src/lua_hook.h | 3 +++ src/lua_hooklib.c | 23 +++++++++++++++++++++++ src/y_inter.c | 11 ++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 126e7e40..e61acdf1 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -51,6 +51,7 @@ enum hook { hook_PlayerExplode, //SRB2KART hook_PlayerSquish, //SRB2KART hook_PlayerCmd, //SRB2KART + hook_IntermissionThinker, //SRB2KART hook_MAX // last hook }; @@ -99,4 +100,6 @@ boolean LUAh_PlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source); boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd); // Allows to write to player cmd before the game does anything with them. +void LUAh_IntermissionThinker(void); // Hook for Y_Ticker + #endif diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 5a95877e..c15d13a0 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -62,6 +62,7 @@ const char *const hookNames[hook_MAX+1] = { "PlayerExplode", "PlayerSquish", "PlayerCmd", + "IntermissionThinker", NULL }; @@ -420,6 +421,28 @@ void LUAh_ThinkFrame(void) } } +// Hook for Y_Ticker +void LUAh_IntermissionThinker(void) +{ + hook_p hookp; + if (!gL || !(hooksAvailable[hook_IntermissionThinker/8] & (1<<(hook_IntermissionThinker%8)))) + return; + + for (hookp = roothook; hookp; hookp = hookp->next) + if (hookp->type == hook_IntermissionThinker) + { + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + if (lua_pcall(gL, 0, 0, 0)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + } + } +} + + // Hook for mobj collisions UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which) { diff --git a/src/y_inter.c b/src/y_inter.c index 095b4ad3..18c6ab33 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -40,6 +40,7 @@ #include "g_input.h" // PLAYER1INPUTDOWN #include "k_kart.h" // colortranslations #include "console.h" // cons_menuhighlight +#include "lua_hook.h" // IntermissionThinker hook #ifdef HWRENDER #include "hardware/hw_main.h" @@ -574,13 +575,17 @@ void Y_Ticker(void) if (paused || P_AutoPause()) return; +#ifdef HAVE_BLUA + LUAh_IntermissionThinker(); +#endif + intertic++; // Team scramble code for team match and CTF. - // Don't do this if we're going to automatically scramble teams next round. + // Don't do this if we' + // If we run out re going to automatically scramble teams next round. /*if (G_GametypeHasTeams() && cv_teamscramble.value && !cv_scrambleonchange.value && server) - { - // If we run out of time in intermission, the beauty is that + {of time in intermission, the beauty is that // the P_Ticker() team scramble code will pick it up. if ((intertic % (TICRATE/7)) == 0) P_DoTeamscrambling();