From 0d841ab4df7fa3f4d3c700df76dd5e3c0a6e62c7 Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Tue, 7 Nov 2017 09:55:15 -0600 Subject: [PATCH] - Added DMG_NO_PAIN for DamageMobj. --- src/p_interaction.cpp | 21 +++++++++++++-------- src/p_local.h | 1 + wadsrc/static/zscript/constants.txt | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index edfe3f8b8c..4de850900d 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -903,8 +903,7 @@ void P_AutoUseStrifeHealth (player_t *player) static inline bool MustForcePain(AActor *target, AActor *inflictor) { - return (!(target->flags5 & MF5_NOPAIN) && inflictor != NULL && - (inflictor->flags6 & MF6_FORCEPAIN) && !(inflictor->flags5 & MF5_PAINLESS)); + return (inflictor && (inflictor->flags6 & MF6_FORCEPAIN)); } static inline bool isFakePain(AActor *target, AActor *inflictor, int damage) @@ -928,6 +927,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da bool invulpain = false; bool fakedPain = false; bool forcedPain = false; + bool noPain = false; int fakeDamage = 0; int holdDamage = 0; const int rawdamage = damage; @@ -940,9 +940,14 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da return 0; } - //Rather than unnecessarily call the function over and over again, let's be a little more efficient. - fakedPain = (isFakePain(target, inflictor, damage)); - forcedPain = (MustForcePain(target, inflictor)); + // Rather than unnecessarily call the function over and over again, let's be a little more efficient. + // But first, check and see if it's even needed, which it won't be if pain must not be triggered. + noPain = ((flags & DMG_NO_PAIN) || (target->flags5 & MF5_NOPAIN) || (inflictor && (inflictor->flags5 & MF5_PAINLESS))); + if (!noPain) + { + fakedPain = (isFakePain(target, inflictor, damage)); + forcedPain = (MustForcePain(target, inflictor)); + } // Spectral targets only take damage from spectral projectiles. if (target->flags4 & MF4_SPECTRAL && !telefragDamage) @@ -1306,7 +1311,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da { // player is invulnerable, so don't hurt him //Make sure no godmodes and NOPAIN flags are found first. //Then, check to see if the player has NODAMAGE or ALLOWPAIN, or inflictor has CAUSEPAIN. - if ((player->cheats & CF_GODMODE) || (player->cheats & CF_GODMODE2) || (player->mo->flags5 & MF5_NOPAIN)) + if ((flags & DMG_NO_PAIN) || (player->cheats & CF_GODMODE) || (player->cheats & CF_GODMODE2) || (player->mo->flags5 & MF5_NOPAIN)) return 0; else if ((((player->mo->flags7 & MF7_ALLOWPAIN) || (player->mo->flags5 & MF5_NODAMAGE)) || ((inflictor != NULL) && (inflictor->flags7 & MF7_CAUSEPAIN)))) { @@ -1333,7 +1338,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da if (damage <= 0) { // [MC] Godmode doesn't need checking here, it's already being handled above. - if ((target->flags5 & MF5_NOPAIN) || (inflictor && (inflictor->flags5 & MF5_PAINLESS))) + if (noPain) return 0; // If MF6_FORCEPAIN is set, make the player enter the pain state. @@ -1522,7 +1527,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da fakepain: //Needed so we can skip the rest of the above, but still obey the original rules. - if (!(target->flags5 & MF5_NOPAIN) && (inflictor == NULL || !(inflictor->flags5 & MF5_PAINLESS)) && + if (!noPain && (target->player != NULL || !G_SkillProperty(SKILLP_NoPain)) && !(target->flags & MF_SKULLFLY)) { painchance = target->PainChance; diff --git a/src/p_local.h b/src/p_local.h index c3fd295209..e4123cd512 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -437,6 +437,7 @@ enum EDmgFlags DMG_FOILBUDDHA = 128, DMG_NO_PROTECT = 256, DMG_USEANGLE = 512, + DMG_NO_PAIN = 1 << 10, }; diff --git a/wadsrc/static/zscript/constants.txt b/wadsrc/static/zscript/constants.txt index a8aea4123b..5dd6b778b0 100644 --- a/wadsrc/static/zscript/constants.txt +++ b/wadsrc/static/zscript/constants.txt @@ -913,6 +913,7 @@ enum EDmgFlags DMG_FOILBUDDHA = 128, DMG_NO_PROTECT = 256, DMG_USEANGLE = 512, + DMG_NO_PAIN = 1 << 10, } enum EReplace