From 554573bcb35b515329f943bf715a5c459b96a066 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 14 Jan 2007 08:58:07 +0000 Subject: [PATCH] - Adjusted AlterWeaponSprite so that it properly handles multiple invisibility powerups at the same time. SVN r450 (trunk) --- docs/rh-log.txt | 4 ++ src/g_shared/a_artifacts.cpp | 84 +++++++++++++++++++++++++++++++++--- src/g_shared/a_artifacts.h | 6 ++- src/g_shared/a_pickups.cpp | 5 ++- src/g_shared/a_pickups.h | 2 +- src/thingdef.cpp | 2 +- 6 files changed, 90 insertions(+), 13 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 96d4edffd..5e9bfbb2c 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,7 @@ +January 13, 2007 (Changes by Graf Zahl) +- Adjusted AlterWeaponSprite so that it properly handles multiple + invisibility powerups at the same time. + January 13, 2007 - Integrated the fatal error display into the text logger. Next: Figure out how to do all this fancy new startup window stuff with GTK+ diff --git a/src/g_shared/a_artifacts.cpp b/src/g_shared/a_artifacts.cpp index f772b6f1c..ec97cc62a 100644 --- a/src/g_shared/a_artifacts.cpp +++ b/src/g_shared/a_artifacts.cpp @@ -454,8 +454,9 @@ void APowerInvulnerable::EndEffect () // //=========================================================================== -void APowerInvulnerable::AlterWeaponSprite (vissprite_t *vis) +int APowerInvulnerable::AlterWeaponSprite (vissprite_t *vis) { + int changed = Inventory == NULL? false : Inventory->AlterWeaponSprite(vis); if (Owner != NULL) { if (mode == NAME_Ghost && !(Owner->flags & MF_SHADOW)) @@ -464,6 +465,7 @@ void APowerInvulnerable::AlterWeaponSprite (vissprite_t *vis) if (wp_alpha != FIXED_MAX) vis->alpha = wp_alpha; } } + return changed; } // Strength (aka Berserk) Powerup -------------------------------------------- @@ -574,6 +576,19 @@ void APowerInvisibility::EndEffect () Owner->flags3 &= ~MF3_GHOST; Owner->RenderStyle = STYLE_Normal; Owner->alpha = OPAQUE; + + // Check whether there are other invisibility items and refresh their effect. + // If this isn't done there will be one incorrectly drawn frame when this + // item expires. + AInventory *item = Owner->Inventory; + while (item != NULL) + { + if (item->IsKindOf(RUNTIME_CLASS(APowerInvisibility)) && item != this) + { + static_cast(item)->InitEffect(); + } + item = item->Inventory; + } } } @@ -583,18 +598,23 @@ void APowerInvisibility::EndEffect () // //=========================================================================== -void APowerInvisibility::AlterWeaponSprite (vissprite_t *vis) +int APowerInvisibility::AlterWeaponSprite (vissprite_t *vis) { - if (Inventory != NULL) - { - Inventory->AlterWeaponSprite (vis); - } + int changed = Inventory == NULL? false : Inventory->AlterWeaponSprite(vis); // Blink if the powerup is wearing off - if (EffectTics < 4*32 && !(EffectTics & 8)) + if (changed == 0 && EffectTics < 4*32 && !(EffectTics & 8)) { vis->RenderStyle = STYLE_Normal; + return 1; } + else if (changed == 1) + { + // something else set the weapon sprite back to opaque but this item is still active. + vis->alpha = FRACUNIT/5; + vis->RenderStyle = STYLE_OptFuzzy; + } + return -1; // This item is valid so another one shouldn't reset the translucency } // Ghost Powerup (Heretic's version of invisibility) ------------------------- @@ -617,6 +637,31 @@ void APowerGhost::InitEffect () Owner->RenderStyle = STYLE_Translucent; } +//=========================================================================== +// +// APowerGhost :: AlterWeaponSprite +// +//=========================================================================== + +int APowerGhost::AlterWeaponSprite (vissprite_t *vis) +{ + int changed = Inventory == NULL? false : Inventory->AlterWeaponSprite(vis); + + // Blink if the powerup is wearing off + if (changed == 0 && EffectTics < 4*32 && !(EffectTics & 8)) + { + vis->RenderStyle = STYLE_Normal; + return 1; + } + else if (changed == 1) + { + // something else set the weapon sprite back to opaque but this item is still active. + vis->alpha = HR_SHADOW; + vis->RenderStyle = STYLE_Translucent; + } + return -1; // This item is valid so another one shouldn't reset the translucency +} + // Shadow Powerup (Strife's version of invisibility) ------------------------- IMPLEMENT_STATELESS_ACTOR (APowerShadow, Any, -1, 0) @@ -637,6 +682,31 @@ void APowerShadow::InitEffect () Owner->RenderStyle = STYLE_Translucent; } +//=========================================================================== +// +// APowerShadow :: AlterWeaponSprite +// +//=========================================================================== + +int APowerShadow::AlterWeaponSprite (vissprite_t *vis) +{ + int changed = Inventory == NULL? false : Inventory->AlterWeaponSprite(vis); + + // Blink if the powerup is wearing off + if (changed == 0 && EffectTics < 4*32 && !(EffectTics & 8)) + { + vis->RenderStyle = STYLE_Normal; + return 1; + } + else if (changed == 1) + { + // something else set the weapon sprite back to opaque but this item is still active. + vis->alpha = TRANSLUC25; + vis->RenderStyle = STYLE_Translucent; + } + return -1; // This item is valid so another one shouldn't reset the translucency +} + // Ironfeet Powerup ---------------------------------------------------------- IMPLEMENT_STATELESS_ACTOR (APowerIronFeet, Any, -1, 0) diff --git a/src/g_shared/a_artifacts.h b/src/g_shared/a_artifacts.h index fdb4885b2..734d1be7a 100644 --- a/src/g_shared/a_artifacts.h +++ b/src/g_shared/a_artifacts.h @@ -69,7 +69,7 @@ protected: void InitEffect (); void DoEffect (); void EndEffect (); - void AlterWeaponSprite (vissprite_t *vis); + int AlterWeaponSprite (vissprite_t *vis); }; class APowerStrength : public APowerup @@ -90,7 +90,7 @@ protected: void InitEffect (); void DoEffect (); void EndEffect (); - void AlterWeaponSprite (vissprite_t *vis); + int AlterWeaponSprite (vissprite_t *vis); }; class APowerGhost : public APowerInvisibility @@ -98,6 +98,7 @@ class APowerGhost : public APowerInvisibility DECLARE_STATELESS_ACTOR (APowerGhost, APowerInvisibility) protected: void InitEffect (); + int AlterWeaponSprite (vissprite_t *vis); }; class APowerShadow : public APowerInvisibility @@ -105,6 +106,7 @@ class APowerShadow : public APowerInvisibility DECLARE_STATELESS_ACTOR (APowerShadow, APowerInvisibility) protected: void InitEffect (); + int AlterWeaponSprite (vissprite_t *vis); }; class APowerIronFeet : public APowerup diff --git a/src/g_shared/a_pickups.cpp b/src/g_shared/a_pickups.cpp index 1bc01075d..fea1cc555 100644 --- a/src/g_shared/a_pickups.cpp +++ b/src/g_shared/a_pickups.cpp @@ -768,12 +768,13 @@ void AInventory::AbsorbDamage (int damage, FName damageType, int &newdamage) // //=========================================================================== -void AInventory::AlterWeaponSprite (vissprite_t *vis) +int AInventory::AlterWeaponSprite (vissprite_t *vis) { if (Inventory != NULL) { - Inventory->AlterWeaponSprite (vis); + return Inventory->AlterWeaponSprite (vis); } + return 0; } //=========================================================================== diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index afe4ae578..e877bfa64 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -151,7 +151,7 @@ public: virtual void OwnerDied (); virtual void AbsorbDamage (int damage, FName damageType, int &newdamage); - virtual void AlterWeaponSprite (vissprite_t *vis); + virtual int AlterWeaponSprite (vissprite_t *vis); virtual PalEntry GetBlend (); diff --git a/src/thingdef.cpp b/src/thingdef.cpp index bb7228d26..77f690caf 100644 --- a/src/thingdef.cpp +++ b/src/thingdef.cpp @@ -2619,7 +2619,7 @@ static void ActorMass (AActor *defaults, Baggage &bag) static void ActorXScale (AActor *defaults, Baggage &bag) { SC_MustGetFloat(); - defaults->scaleY = FLOAT2FIXED(sc_Float); + defaults->scaleX = FLOAT2FIXED(sc_Float); } //==========================================================================