diff --git a/src/d_player.h b/src/d_player.h index 89b10f38a..50b6e96c8 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -133,9 +133,6 @@ public: double UseRange; // [NS] Distance at which player can +use double AirCapacity; // Multiplier for air supply underwater. - // [CW] Fades for when you are being damaged. - PalEntry DamageFade; - // Everything below this point is only used by scripted code or through the scripted variable interface. int RunHealth; TObjPtr InvFirst; // first inventory item displayed on inventory bar @@ -143,6 +140,9 @@ public: double SideMove1, SideMove2; double HexenArmor[5]; + // [CW] Fades for when you are being damaged. + PalEntry DamageFade; + // [SP] ViewBob Multiplier double ViewBob; double curBob; @@ -512,8 +512,6 @@ public: // you are 100% sure the context already implies the layer exists. DPSprite *GetPSprite(PSPLayers layer); - bool GetPainFlash(FName type, PalEntry *color) const; - // [Nash] set player FOV void SetFOV(float fov); bool HasWeaponsInSlot(int slot) const; diff --git a/src/namedef.h b/src/namedef.h index e7c2688b4..c905ee6fe 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -1040,6 +1040,7 @@ xx(Face) xx(Slot) xx(SoundClass) xx(ViewBob) +xx(DamageFade) xx(BlueCard) xx(YellowCard) diff --git a/src/p_user.cpp b/src/p_user.cpp index eaafa2e7a..ba7912bda 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -567,24 +567,28 @@ DEFINE_ACTION_FUNCTION(FPlayerClass, GetColorSetName) // //========================================================================== -bool player_t::GetPainFlash(FName type, PalEntry *color) const +static int GetPainFlash(AActor *info, int type) { - PClass *info = mo->GetClass(); - // go backwards through the list and return the first item with a // matching damage type for an ancestor of our class. // This will always return the best fit because any parent class // must be processed before its children. for (int i = PainFlashes.Size() - 1; i >= 0; i--) { - if (std::get<1>(PainFlashes[i]) == type && - std::get<0>(PainFlashes[i])->IsAncestorOf(info)) + if (std::get<1>(PainFlashes[i]) == ENamedName(type) && + std::get<0>(PainFlashes[i])->IsAncestorOf(info->GetClass())) { - *color = std::get<2>(PainFlashes[i]); - return true; + return std::get<2>(PainFlashes[i]); } } - return false; + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(APlayerPawn, GetPainFlashForType, GetPainFlash) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(type); + ACTION_RETURN_INT(GetPainFlash(self, type)); } //=========================================================================== diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 0d6f4b319..a9b802336 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -1609,14 +1609,14 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, damagescreencolor, Cfs, PlayerPawn) if (PROP_PARM_COUNT < 3) // Because colors count as 2 parms { color.a = 255; - defaults->DamageFade = color; + defaults->IntVar(NAME_DamageFade) = color; } else if (PROP_PARM_COUNT < 4) { PROP_DOUBLE_PARM(a, 2); color.a = uint8_t(255 * clamp(a, 0.f, 1.f)); - defaults->DamageFade = color; + defaults->IntVar(NAME_DamageFade) = color; } else { diff --git a/src/v_blend.cpp b/src/v_blend.cpp index 7069affe3..b0cd1c060 100644 --- a/src/v_blend.cpp +++ b/src/v_blend.cpp @@ -124,8 +124,13 @@ void V_AddPlayerBlend (player_t *CPlayer, float blend[4], float maxinvalpha, int BPART(gameinfo.pickupcolor)/255.f, cnt > 128 ? 0.5f : cnt / 255.f, blend); } - PalEntry painFlash = CPlayer->mo->DamageFade; - CPlayer->GetPainFlash(CPlayer->mo->DamageTypeReceived, &painFlash); + PalEntry painFlash = 0; + IFVIRTUALPTR(CPlayer->mo, APlayerPawn, GetPainFlash) + { + VMValue param = CPlayer->mo; + VMReturn ret((int*)&painFlash.d); + VMCall(func, ¶m, 1, &ret, 1); + } if (painFlash.a != 0) { diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index ca927ae0d..c5441ed68 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -2303,7 +2303,19 @@ class PlayerPawn : Actor native } return p1 * (1. - ticfrac) + p2 * ticfrac; } + + //---------------------------------------------------------------------------- + // + // + // + //---------------------------------------------------------------------------- + virtual clearscope color GetPainFlash() const + { + Color painFlash = GetPainFlashForType(DamageTypeReceived); + if (painFlash == 0) painFlash = DamageFade; + return painFlash; + } //---------------------------------------------------------------------------- // @@ -2319,6 +2331,7 @@ class PlayerPawn : Actor native native void CheckUse(); native void CheckWeaponButtons(); native void MarkPlayerSounds(); + private native clearscope Color GetPainFlashForType(Name type); } extend class Actor