- scriptified APlayerPawn's DamageFade handling.

This commit is contained in:
Christoph Oelckers 2019-01-03 12:47:34 +01:00
parent 2bd72478ee
commit badacbb968
6 changed files with 38 additions and 17 deletions

View file

@ -133,9 +133,6 @@ public:
double UseRange; // [NS] Distance at which player can +use double UseRange; // [NS] Distance at which player can +use
double AirCapacity; // Multiplier for air supply underwater. 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. // Everything below this point is only used by scripted code or through the scripted variable interface.
int RunHealth; int RunHealth;
TObjPtr<AActor*> InvFirst; // first inventory item displayed on inventory bar TObjPtr<AActor*> InvFirst; // first inventory item displayed on inventory bar
@ -143,6 +140,9 @@ public:
double SideMove1, SideMove2; double SideMove1, SideMove2;
double HexenArmor[5]; double HexenArmor[5];
// [CW] Fades for when you are being damaged.
PalEntry DamageFade;
// [SP] ViewBob Multiplier // [SP] ViewBob Multiplier
double ViewBob; double ViewBob;
double curBob; double curBob;
@ -512,8 +512,6 @@ public:
// you are 100% sure the context already implies the layer exists. // you are 100% sure the context already implies the layer exists.
DPSprite *GetPSprite(PSPLayers layer); DPSprite *GetPSprite(PSPLayers layer);
bool GetPainFlash(FName type, PalEntry *color) const;
// [Nash] set player FOV // [Nash] set player FOV
void SetFOV(float fov); void SetFOV(float fov);
bool HasWeaponsInSlot(int slot) const; bool HasWeaponsInSlot(int slot) const;

View file

@ -1040,6 +1040,7 @@ xx(Face)
xx(Slot) xx(Slot)
xx(SoundClass) xx(SoundClass)
xx(ViewBob) xx(ViewBob)
xx(DamageFade)
xx(BlueCard) xx(BlueCard)
xx(YellowCard) xx(YellowCard)

View file

@ -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 // go backwards through the list and return the first item with a
// matching damage type for an ancestor of our class. // matching damage type for an ancestor of our class.
// This will always return the best fit because any parent class // This will always return the best fit because any parent class
// must be processed before its children. // must be processed before its children.
for (int i = PainFlashes.Size() - 1; i >= 0; i--) for (int i = PainFlashes.Size() - 1; i >= 0; i--)
{ {
if (std::get<1>(PainFlashes[i]) == type && if (std::get<1>(PainFlashes[i]) == ENamedName(type) &&
std::get<0>(PainFlashes[i])->IsAncestorOf(info)) std::get<0>(PainFlashes[i])->IsAncestorOf(info->GetClass()))
{ {
*color = std::get<2>(PainFlashes[i]); return std::get<2>(PainFlashes[i]);
return true;
} }
} }
return false; return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(APlayerPawn, GetPainFlashForType, GetPainFlash)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(type);
ACTION_RETURN_INT(GetPainFlash(self, type));
} }
//=========================================================================== //===========================================================================

View file

@ -1609,14 +1609,14 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, damagescreencolor, Cfs, PlayerPawn)
if (PROP_PARM_COUNT < 3) // Because colors count as 2 parms if (PROP_PARM_COUNT < 3) // Because colors count as 2 parms
{ {
color.a = 255; color.a = 255;
defaults->DamageFade = color; defaults->IntVar(NAME_DamageFade) = color;
} }
else if (PROP_PARM_COUNT < 4) else if (PROP_PARM_COUNT < 4)
{ {
PROP_DOUBLE_PARM(a, 2); PROP_DOUBLE_PARM(a, 2);
color.a = uint8_t(255 * clamp<double>(a, 0.f, 1.f)); color.a = uint8_t(255 * clamp<double>(a, 0.f, 1.f));
defaults->DamageFade = color; defaults->IntVar(NAME_DamageFade) = color;
} }
else else
{ {

View file

@ -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); BPART(gameinfo.pickupcolor)/255.f, cnt > 128 ? 0.5f : cnt / 255.f, blend);
} }
PalEntry painFlash = CPlayer->mo->DamageFade; PalEntry painFlash = 0;
CPlayer->GetPainFlash(CPlayer->mo->DamageTypeReceived, &painFlash); IFVIRTUALPTR(CPlayer->mo, APlayerPawn, GetPainFlash)
{
VMValue param = CPlayer->mo;
VMReturn ret((int*)&painFlash.d);
VMCall(func, &param, 1, &ret, 1);
}
if (painFlash.a != 0) if (painFlash.a != 0)
{ {

View file

@ -2303,7 +2303,19 @@ class PlayerPawn : Actor native
} }
return p1 * (1. - ticfrac) + p2 * ticfrac; 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 CheckUse();
native void CheckWeaponButtons(); native void CheckWeaponButtons();
native void MarkPlayerSounds(); native void MarkPlayerSounds();
private native clearscope Color GetPainFlashForType(Name type);
} }
extend class Actor extend class Actor