From f26717954eddcf8407cc796d508fe3252cb00fc0 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Nov 2024 19:10:49 +0100 Subject: [PATCH] change those to fit rest of style --- src/k_kart.c | 12 ++++++------ src/lua_hook.h | 20 +++++++++----------- src/lua_hooklib.c | 34 +++++++++++++++++----------------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 14f9cc580..2950dcccb 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -2312,7 +2312,7 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto UINT8 scoremultiply = 1; // PS: Inflictor is unused for all purposes here and is actually only ever relevant to Lua. It may be nil too. boolean force = false; // Used to check if Lua ShouldSpin should get us damaged reguardless of flashtics or heck knows what. - UINT8 shouldForce = LUAh_ShouldSpin(player, inflictor, source); + UINT8 shouldForce = LUA_HookShouldSpin(player, inflictor, source); if (P_MobjWasRemoved(player->mo)) return; // mobj was removed (in theory that shouldn't happen) @@ -2345,7 +2345,7 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto } } - if (LUAh_PlayerSpin(player, inflictor, source)) // Let Lua do its thing or overwrite if it wants to. Make sure to let any possible instashield happen because we didn't get "damaged" in this case. + if (LUA_HookPlayerSpin(player, inflictor, source)) // Let Lua do its thing or overwrite if it wants to. Make sure to let any possible instashield happen because we didn't get "damaged" in this case. return; if (source && source != player->mo && source->player) @@ -2453,7 +2453,7 @@ void K_SquishPlayer(player_t *player, mobj_t *source, mobj_t *inflictor) UINT8 scoremultiply = 1; // PS: Inflictor is unused for all purposes here and is actually only ever relevant to Lua. It may be nil too. boolean force = false; // Used to check if Lua ShouldSquish should get us damaged reguardless of flashtics or heck knows what. - UINT8 shouldForce = LUAh_ShouldSquish(player, inflictor, source); + UINT8 shouldForce = LUA_HookShouldSquish(player, inflictor, source); if (P_MobjWasRemoved(player->mo)) return; // mobj was removed (in theory that shouldn't happen) if (shouldForce == 1) @@ -2483,7 +2483,7 @@ void K_SquishPlayer(player_t *player, mobj_t *source, mobj_t *inflictor) } } - if (LUAh_PlayerSquish(player, inflictor, source)) // Let Lua do its thing or overwrite if it wants to. Make sure to let any possible instashield happen because we didn't get "damaged" in this case. + if (LUA_HookPlayerSquish(player, inflictor, source)) // Let Lua do its thing or overwrite if it wants to. Make sure to let any possible instashield happen because we didn't get "damaged" in this case. return; player->kartstuff[k_sneakertimer] = 0; @@ -2564,7 +2564,7 @@ void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor) // A b fixed_t upgoer; UINT8 scoremultiply = 1; boolean force = false; // Used to check if Lua ShouldExplode should get us damaged reguardless of flashtics or heck knows what. - UINT8 shouldForce = LUAh_ShouldExplode(player, inflictor, source); + UINT8 shouldForce = LUA_HookShouldExplode(player, inflictor, source); if (P_MobjWasRemoved(player->mo)) return; // mobj was removed (in theory that shouldn't happen) @@ -2597,7 +2597,7 @@ void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor) // A b } } - if (LUAh_PlayerExplode(player, inflictor, source)) // Same thing. Also make sure to let Instashield happen blah blah + if (LUA_HookPlayerExplode(player, inflictor, source)) // Same thing. Also make sure to let Instashield happen blah blah return; if (source && source != player->mo && source->player) diff --git a/src/lua_hook.h b/src/lua_hook.h index 3ca4b8f35..4a322d504 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -115,15 +115,13 @@ int LUA_HookPlayerCanDamage(player_t *, mobj_t *); void LUA_HookPlayerQuit(player_t *, int); int LUA_HookPlayerCmd(player_t *, ticcmd_t *); int LUA_HookMusicChange(const char *oldname, struct MusicChange *); + +int LUA_HookShouldSpin(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be spun out? +int LUA_HookShouldExplode(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be exploded? +int LUA_HookShouldSquish(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be squished? + +boolean LUA_HookPlayerSpin(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_SpinPlayer. Allows Lua to execute code and/or overwrite its behavior. +boolean LUA_HookPlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_ExplodePlayer. Allows Lua to execute code and/or overwrite its behavior. +boolean LUA_HookPlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_SquishPlayer. Allows Lua to execute code and/or overwrite its behavior. + int LUA_HookKey(INT32 keycode, int hooktype); // Hooks for key events - - -// No clue what to do about these - -UINT8 LUAh_ShouldSpin(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be spun out? -UINT8 LUAh_ShouldExplode(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be exploded? -UINT8 LUAh_ShouldSquish(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be squished? - -boolean LUAh_PlayerSpin(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_SpinPlayer. Allows Lua to execute code and/or overwrite its behavior. -boolean LUAh_PlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_ExplodePlayer. Allows Lua to execute code and/or overwrite its behavior. -boolean LUAh_PlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_SquishPlayer. Allows Lua to execute code and/or overwrite its behavior. diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 2209803e6..4e83e23ee 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -965,17 +965,6 @@ int LUA_HookMusicChange(const char *oldname, struct MusicChange *param) return hook.status; } -int LUA_HookKey(INT32 keycode, int hooktype) -{ - Hook_State hook; - if (prepare_hook(&hook, 0, hooktype)) - { - lua_pushinteger(gL, keycode); - call_hooks(&hook, 1, 0, res_true); - } - return hook.status; -} - static int kartdamage_hook ( player_t *player, @@ -996,37 +985,48 @@ static int kartdamage_hook } // Hook for K_SpinPlayer. Determines if yes or no we should get damaged reguardless of circumstances. -UINT8 LUAh_ShouldSpin(player_t *player, mobj_t *inflictor, mobj_t *source) +int LUA_HookShouldSpin(player_t *player, mobj_t *inflictor, mobj_t *source) { return kartdamage_hook(player, inflictor, source, HOOK(ShouldSpin), res_force); } // Hook for K_ExplodePlayer. Determines if yes or no we should get damaged reguardless of circumstances. -UINT8 LUAh_ShouldExplode(player_t *player, mobj_t *inflictor, mobj_t *source) +int LUA_HookShouldExplode(player_t *player, mobj_t *inflictor, mobj_t *source) { return kartdamage_hook(player, inflictor, source, HOOK(ShouldExplode), res_force); } // Hook for K_SquishPlayer. Determines if yes or no we should get damaged reguardless of circumstances. -UINT8 LUAh_ShouldSquish(player_t *player, mobj_t *inflictor, mobj_t *source) +int LUA_HookShouldSquish(player_t *player, mobj_t *inflictor, mobj_t *source) { return kartdamage_hook(player, inflictor, source, HOOK(ShouldSquish), res_force); } // Hook for K_SpinPlayer. This is used when the player has actually been spun out, but before anything has actually been done. This allows Lua to overwrite the behavior or to just perform actions. -boolean LUAh_PlayerSpin(player_t *player, mobj_t *inflictor, mobj_t *source) +boolean LUA_HookPlayerSpin(player_t *player, mobj_t *inflictor, mobj_t *source) { return kartdamage_hook(player, inflictor, source, HOOK(PlayerSpin), res_true); } // Hook for K_SquishPlayer. This is used when the player has actually been spun out, but before anything has actually been done. This allows Lua to overwrite the behavior or to just perform actions. -boolean LUAh_PlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source) +boolean LUA_HookPlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source) { return kartdamage_hook(player, inflictor, source, HOOK(PlayerSquish), res_true); } // Hook for K_ExplodePlayer. This is used when the player has actually been spun out, but before anything has actually been done. This allows Lua to overwrite the behavior or to just perform actions. -boolean LUAh_PlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source) +boolean LUA_HookPlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source) { return kartdamage_hook(player, inflictor, source, HOOK(PlayerExplode), res_true); } + +int LUA_HookKey(INT32 keycode, int hooktype) +{ + Hook_State hook; + if (prepare_hook(&hook, 0, hooktype)) + { + lua_pushinteger(gL, keycode); + call_hooks(&hook, 1, 0, res_true); + } + return hook.status; +}