From 6990a46dafde9feb76e231cf14c3e4af5ad9839a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 16 Jan 2017 22:27:49 +0100 Subject: [PATCH] - scriptified PowerStrength. This revealed an interesting bug: When the berserk fadout formula was changed in 2005 the result was essentially broken, resulting in values around 7000 - it only worked by happenstance because the lower 8 bits of the resulting values just happened to work to some degree and never overflowed. But the resulting fade was far too weak and a slightly different handling of the color composition code for the VM made it break down entirely. This restores the pre-2005 formula but weakened intensity which now comes a lot closer to how it is supposed to look. --- src/g_inventory/a_artifacts.cpp | 65 -------------------- src/g_inventory/a_artifacts.h | 11 ---- src/g_shared/shared_hud.cpp | 4 +- src/s_advsound.cpp | 1 + src/scripting/codegeneration/codegen.cpp | 3 +- wadsrc/static/zscript/inventory/powerups.txt | 51 ++++++++++++++- 6 files changed, 54 insertions(+), 81 deletions(-) diff --git a/src/g_inventory/a_artifacts.cpp b/src/g_inventory/a_artifacts.cpp index bb6d76fc3..0cd4828b1 100644 --- a/src/g_inventory/a_artifacts.cpp +++ b/src/g_inventory/a_artifacts.cpp @@ -540,71 +540,6 @@ void APowerInvulnerable::EndEffect () } } -// Strength (aka Berserk) Powerup -------------------------------------------- - -IMPLEMENT_CLASS(APowerStrength, false, false) - -//=========================================================================== -// -// APowerStrength :: HandlePickup -// -//=========================================================================== - -bool APowerStrength::HandlePickup (AInventory *item) -{ - if (item->GetClass() == GetClass()) - { // Setting EffectTics to 0 will force Powerup's HandlePickup() - // method to reset the tic count so you get the red flash again. - EffectTics = 0; - } - return Super::HandlePickup (item); -} - -//=========================================================================== -// -// APowerStrength :: InitEffect -// -//=========================================================================== - -void APowerStrength::InitEffect () -{ - Super::InitEffect(); -} - -//=========================================================================== -// -// APowerStrength :: DoEffect -// -//=========================================================================== - -void APowerStrength::Tick () -{ - // Strength counts up to diminish the fade. - assert(EffectTics < (INT_MAX - 1)); // I can't see a game lasting nearly two years, but... - EffectTics += 2; - Super::Tick(); -} - -//=========================================================================== -// -// APowerStrength :: GetBlend -// -//=========================================================================== - -PalEntry APowerStrength::GetBlend () -{ - // slowly fade the berserk out - int cnt = 12 - (EffectTics >> 6); - - if (cnt > 0) - { - cnt = (cnt + 7) >> 3; - return PalEntry (BlendColor.a*cnt*255/9, - BlendColor.r, BlendColor.g, BlendColor.b); - } - return 0; -} - // Speed Powerup ------------------------------------------------------------- IMPLEMENT_CLASS(APowerSpeed, false, false) diff --git a/src/g_inventory/a_artifacts.h b/src/g_inventory/a_artifacts.h index fb0a29a0f..f947e18d5 100644 --- a/src/g_inventory/a_artifacts.h +++ b/src/g_inventory/a_artifacts.h @@ -66,17 +66,6 @@ protected: virtual void EndEffect () override; }; -class APowerStrength : public APowerup -{ - DECLARE_CLASS (APowerStrength, APowerup) -public: - PalEntry GetBlend (); -protected: - virtual void InitEffect () override; - virtual void Tick () override; - virtual bool HandlePickup (AInventory *item) override; -}; - class APowerSpeed : public APowerup { DECLARE_CLASS (APowerSpeed, APowerup) diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index b645ac511..839582d34 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -297,8 +297,8 @@ static void DrawHealth(player_t *CPlayer, int x, int y) CR_BLUE; const bool haveBerserk = hud_berserk_health - && NULL != berserkpic - && NULL != CPlayer->mo->FindInventory< APowerStrength >(); + && nullptr != berserkpic + && nullptr != CPlayer->mo->FindInventory(PClass::FindActor(NAME_PowerStrength)); DrawImageToBox(haveBerserk ? berserkpic : healthpic, x, y, 31, 17); DrawHudNumber(HudFont, fontcolor, health, x + 33, y + 17); diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index 085f1869e..952a40d09 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -2127,6 +2127,7 @@ CCMD (soundlist) { Printf ("%3d. %s **not present**\n", i, sfx->name.GetChars()); } + Printf(" PitchMask = %d\n", sfx->PitchMask); } } diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index 1eefba216..47a10f95d 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -5921,8 +5921,7 @@ FxExpression *FxMemberIdentifier::Resolve(FCompileContext& ctx) { Object->ValueType = TypeColorStruct; } - - else if (Object->ValueType->IsKindOf(RUNTIME_CLASS(PPointer))) + if (Object->ValueType->IsKindOf(RUNTIME_CLASS(PPointer))) { auto ptype = static_cast(Object->ValueType)->PointedType; if (ptype->IsKindOf(RUNTIME_CLASS(PStruct))) diff --git a/wadsrc/static/zscript/inventory/powerups.txt b/wadsrc/static/zscript/inventory/powerups.txt index f31c88f77..b744bfc97 100644 --- a/wadsrc/static/zscript/inventory/powerups.txt +++ b/wadsrc/static/zscript/inventory/powerups.txt @@ -58,7 +58,13 @@ class PowerInvulnerable : Powerup native } } -class PowerStrength : Powerup native +//=========================================================================== +// +// Strength +// +//=========================================================================== + +class PowerStrength : Powerup { Default { @@ -66,6 +72,49 @@ class PowerStrength : Powerup native Powerup.Color "ff 00 00", 0.5; +INVENTORY.HUBPOWER } + + override bool HandlePickup (Inventory item) + { + if (item.GetClass() == GetClass()) + { // Setting EffectTics to 0 will force Powerup's HandlePickup() + // method to reset the tic count so you get the red flash again. + EffectTics = 0; + } + return Super.HandlePickup (item); + } + + //=========================================================================== + // + // APowerStrength :: DoEffect + // + //=========================================================================== + + override void Tick () + { + // Strength counts up to diminish the fade. + EffectTics += 2; + Super.Tick(); + } + + //=========================================================================== + // + // APowerStrength :: GetBlend + // + //=========================================================================== + + override color GetBlend () + { + // slowly fade the berserk out + int cnt = 128 - (EffectTics>>3); + + if (cnt > 0) + { + return Color(BlendColor.a*cnt/256, + BlendColor.r, BlendColor.g, BlendColor.b); + } + return 0; + } + } //===========================================================================