diff --git a/src/k_kart.c b/src/k_kart.c index 4403dd4a..946aeacd 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -21,6 +21,7 @@ #include "k_kart.h" #include "f_finale.h" #include "lua_hud.h" // For Lua hud checks +#include "lua_hook.h" // For MobjDamage and ShouldDamage // SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H: // gamespeed is cc (0 for easy, 1 for normal, 2 for hard) @@ -1842,8 +1843,24 @@ void K_SpawnBattlePoints(player_t *source, player_t *victim, UINT8 amount) pt->color = source->skincolor; } -void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, boolean trapitem) +void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, boolean trapitem, mobj_t *inflictor) { + + // PS: Inflictor is unused for all purposes here and is actually only ever relevant to Lua. It may be nil too. +#ifdef HAVE_BLUA + boolean force = false; // Used to check if Lua ShouldDamage should get us damaged reguardless of flashtics or heck knows what. + UINT8 shouldForce = LUAh_ShouldDamage(player->mo, inflictor, source, 1); + if (P_MobjWasRemoved(player->mo)) + return; // mobj was removed (in theory that shouldn't happen) + if (shouldForce == 1) + force = true; + else if (shouldForce == 2) + return; +#else + static const boolean force = false; +#endif + + UINT8 scoremultiply = 1; if (!trapitem && G_BattleGametype()) { @@ -1860,10 +1877,16 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, boolean trapitem || player->kartstuff[k_invincibilitytimer] > 0 || player->kartstuff[k_growshrinktimer] > 0 || player->kartstuff[k_hyudorotimer] > 0 || (G_BattleGametype() && ((player->kartstuff[k_bumper] <= 0 && player->kartstuff[k_comebacktimer]) || player->kartstuff[k_comebackmode] == 1))) { - K_DoInstashield(player); - return; + if (!force) // if shoulddamage force, we go THROUGH that. + { + K_DoInstashield(player); + return; + } } - + + if (LUAh_MobjDamage(player->mo, inflictor, source, 1)) + return; + if (source && source != player->mo && source->player) K_PlayHitEmSound(source); @@ -2029,6 +2052,20 @@ void K_SquishPlayer(player_t *player, mobj_t *source) void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor) // A bit of a hack, we just throw the player up higher here and extend their spinout timer { + +#ifdef HAVE_BLUA + boolean force = false; // Used to check if Lua ShouldDamage should get us damaged reguardless of flashtics or heck knows what. + UINT8 shouldForce = LUAh_ShouldDamage(player->mo, inflictor, source, 1); + if (P_MobjWasRemoved(player->mo)) + return; // mobj was removed (in theory that shouldn't happen) + if (shouldForce == 1) + force = true; + else if (shouldForce == 2) + return; + +#else + static const boolean force = false; +#endif UINT8 scoremultiply = 1; if (G_BattleGametype()) { @@ -2045,10 +2082,16 @@ void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor) // A b ||*/player->kartstuff[k_invincibilitytimer] > 0 || player->kartstuff[k_growshrinktimer] > 0 || player->kartstuff[k_hyudorotimer] > 0 || (G_BattleGametype() && ((player->kartstuff[k_bumper] <= 0 && player->kartstuff[k_comebacktimer]) || player->kartstuff[k_comebackmode] == 1))) { - K_DoInstashield(player); - return; + if (!force) // ShouldDamage can bypass that, again. + { + K_DoInstashield(player); + return; + } } - + + if (LUAh_MobjDamage(player->mo, inflictor, source, 1)) + return; + if (source && source != player->mo && source->player) K_PlayHitEmSound(source); @@ -3181,7 +3224,7 @@ static void K_DoShrink(player_t *user) // Wipeout K_DropItems(&players[i]); - K_SpinPlayer(&players[i], user->mo, 1, false); + K_SpinPlayer(&players[i], user->mo, 1, false, NULL); // P_RingDamage P_DoPlayerPain(&players[i], user->mo, user->mo); diff --git a/src/k_kart.h b/src/k_kart.h index 8f8cd100..72a03e97 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -28,7 +28,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd); void K_KartPlayerAfterThink(player_t *player); void K_DoInstashield(player_t *player); void K_SpawnBattlePoints(player_t *source, player_t *victim, UINT8 amount); -void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, boolean trapitem); +void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, boolean trapitem, mobj_t *inflictor); void K_SquishPlayer(player_t *player, mobj_t *source); void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor); void K_StealBumper(player_t *player, player_t *victim, boolean force); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 1c14093c..6eb998f7 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2191,12 +2191,15 @@ static int lib_kSpinPlayer(lua_State *L) mobj_t *source = NULL; INT32 type = (INT32)luaL_optinteger(L, 3, 0); boolean trapitem = lua_optboolean(L, 4); + mobj_t *inflictor = NULL; NOHUD if (!player) return LUA_ErrInvalid(L, "player_t"); if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) source = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); - K_SpinPlayer(player, source, type, trapitem); + if (!lua_isnone(L, 5) && lua_isuserdata(L, 5)) + inflictor = *((mobj_t **)luaL_checkudata(L, 5, META_MOBJ)); + K_SpinPlayer(player, source, type, trapitem, inflictor); return 0; } diff --git a/src/p_inter.c b/src/p_inter.c index baae2701..7838db2c 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -590,7 +590,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) P_RemoveMobj(special); } else - K_SpinPlayer(player, special, 0, false); + K_SpinPlayer(player, special, 0, false, NULL); return; /*case MT_EERIEFOG: special->frame &= ~FF_TRANS80; @@ -3243,6 +3243,11 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da return true; } +#ifdef HAVE_BLUA // Add this back here for ACTUAL NORMAL DAMAGE. The funny shit is that the player is barely ever "actually" damaged. + if (LUAh_MobjDamage(target, inflictor, source, damage)) + return true; +#endif + if (!force && inflictor && (inflictor->flags & MF_FIRE)) { if ((player->powers[pw_shield] & SH_NOSTACK) == SH_ELEMENTAL) @@ -3275,8 +3280,11 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da P_KillPlayer(player, source, damage); else if (player->kartstuff[k_invincibilitytimer] > 0 || player->kartstuff[k_growshrinktimer] > 0 || player->powers[pw_flashing]) { - K_DoInstashield(player); - return false; + if (!force) // shoulddamage bypasses all of that. + { + K_DoInstashield(player); + return false; + } } else { @@ -3285,7 +3293,7 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da || inflictor->type == MT_SMK_THWOMP || inflictor->player)) { player->kartstuff[k_sneakertimer] = 0; - K_SpinPlayer(player, source, 1, false); + K_SpinPlayer(player, source, 1, false, inflictor); damage = player->mo->health - 1; P_RingDamage(player, inflictor, source, damage); P_PlayerRingBurst(player, 5); @@ -3297,7 +3305,7 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da } else { - K_SpinPlayer(player, source, 0, false); + K_SpinPlayer(player, source, 0, false, inflictor); } return true; } diff --git a/src/p_map.c b/src/p_map.c index ba6e6454..c33a2dd5 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -882,7 +882,7 @@ static boolean PIT_CheckThing(mobj_t *thing) if (tmthing->state == &states[S_MINEEXPLOSION1]) K_ExplodePlayer(thing->player, tmthing->target, tmthing); else - K_SpinPlayer(thing->player, tmthing->target, 0, false); + K_SpinPlayer(thing->player, tmthing->target, 0, false, tmthing); } return true; // This doesn't collide with anything, but we want it to effect the player anyway. @@ -915,7 +915,7 @@ static boolean PIT_CheckThing(mobj_t *thing) if (thing->type == MT_PLAYER) { // Player Damage - K_SpinPlayer(thing->player, tmthing->target, 0, (tmthing->type == MT_BANANA || tmthing->type == MT_BANANA_SHIELD)); + K_SpinPlayer(thing->player, tmthing->target, 0, (tmthing->type == MT_BANANA || tmthing->type == MT_BANANA_SHIELD), tmthing); // This Item Damage if (tmthing->eflags & MFE_VERTICALFLIP) @@ -1061,7 +1061,7 @@ static boolean PIT_CheckThing(mobj_t *thing) return true; // Player Damage - K_SpinPlayer(tmthing->player, thing->target, 0, (thing->type == MT_BANANA || thing->type == MT_BANANA_SHIELD)); + K_SpinPlayer(tmthing->player, thing->target, 0, (thing->type == MT_BANANA || thing->type == MT_BANANA_SHIELD), tmthing); // Other Item Damage if (thing->eflags & MFE_VERTICALFLIP) @@ -1091,7 +1091,7 @@ static boolean PIT_CheckThing(mobj_t *thing) if (thing->state == &states[S_MINEEXPLOSION1]) K_ExplodePlayer(tmthing->player, thing->target, thing); else - K_SpinPlayer(tmthing->player, thing->target, 0, false); + K_SpinPlayer(tmthing->player, thing->target, 0, false, tmthing); return true; } @@ -1423,7 +1423,7 @@ static boolean PIT_CheckThing(mobj_t *thing) // Make sure they aren't able to damage you ANYWHERE along the Z axis, you have to be TOUCHING the person. && !(thing->z + thing->height < tmthing->z || thing->z > tmthing->z + tmthing->height)) { - + if (tmthing->scale > thing->scale + (mapheaderinfo[gamemap-1]->mobj_scale/8)) // SRB2kart - Handle squishes first! K_SquishPlayer(thing->player, tmthing); else if (thing->scale > tmthing->scale + (mapheaderinfo[gamemap-1]->mobj_scale/8)) @@ -1543,7 +1543,7 @@ static boolean PIT_CheckThing(mobj_t *thing) if (G_BattleGametype() && tmthing->player->kartstuff[k_pogospring]) { K_StealBumper(tmthing->player, thing->player, false); - K_SpinPlayer(thing->player, tmthing, 0, false); + K_SpinPlayer(thing->player, tmthing, 0, false, tmthing); } } else if (P_IsObjectOnGround(tmthing) && thing->momz < 0) @@ -1552,7 +1552,7 @@ static boolean PIT_CheckThing(mobj_t *thing) if (G_BattleGametype() && thing->player->kartstuff[k_pogospring]) { K_StealBumper(thing->player, tmthing->player, false); - K_SpinPlayer(tmthing->player, thing, 0, false); + K_SpinPlayer(tmthing->player, thing, 0, false, thing); } } else @@ -1563,12 +1563,12 @@ static boolean PIT_CheckThing(mobj_t *thing) if (thing->player->kartstuff[k_sneakertimer] && !(tmthing->player->kartstuff[k_sneakertimer])) { K_StealBumper(thing->player, tmthing->player, false); - K_SpinPlayer(tmthing->player, thing, 0, false); + K_SpinPlayer(tmthing->player, thing, 0, false, tmthing); } else if (tmthing->player->kartstuff[k_sneakertimer] && !(thing->player->kartstuff[k_sneakertimer])) { K_StealBumper(tmthing->player, thing->player, false); - K_SpinPlayer(thing->player, tmthing, 0, false); + K_SpinPlayer(thing->player, tmthing, 0, false, thing); } } diff --git a/src/p_spec.c b/src/p_spec.c index 6ac325cd..27345fe5 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4033,7 +4033,7 @@ DoneSection2: case 7: // SRB2kart 190117 - Oil Slick (deprecated) if (roversector || P_MobjReadyToTrigger(player->mo, sector)) { - K_SpinPlayer(player, NULL, 0, false); + K_SpinPlayer(player, NULL, 0, false, NULL); } break; diff --git a/src/p_user.c b/src/p_user.c index b2849c85..b0caec59 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -7764,7 +7764,7 @@ void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius) continue; if (mo->type == MT_PLAYER) // Players wipe out in Kart - K_SpinPlayer(mo->player, source, 0, false); + K_SpinPlayer(mo->player, source, 0, false, inflictor); //} else P_DamageMobj(mo, inflictor, source, 1000);