From 1c9396cd6c301c44dd1579be795bace19e6f3cfd Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 23 Feb 2013 03:25:33 +0000 Subject: [PATCH] - Properly transfer powerups between morphed and unmorphed actors by calling EndEffect() on the powerups before they transfer ownership, then calling InitEffect() on them after they transfer ownership. SVN r4162 (trunk) --- src/g_shared/a_artifacts.h | 3 +++ src/g_shared/a_morph.cpp | 50 +++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/g_shared/a_artifacts.h b/src/g_shared/a_artifacts.h index b8c66bb40..0efd64ab8 100644 --- a/src/g_shared/a_artifacts.h +++ b/src/g_shared/a_artifacts.h @@ -30,6 +30,9 @@ protected: virtual void InitEffect (); virtual void DoEffect (); virtual void EndEffect (); + + friend void EndAllPowerupEffects(AInventory *item); + friend void InitAllPowerupEffects(AInventory *item); }; // An artifact is an item that gives the player a powerup when activated. diff --git a/src/g_shared/a_morph.cpp b/src/g_shared/a_morph.cpp index 0058c996b..836cf41e7 100644 --- a/src/g_shared/a_morph.cpp +++ b/src/g_shared/a_morph.cpp @@ -74,6 +74,7 @@ bool P_MorphPlayer (player_t *activator, player_t *p, const PClass *spawntype, i } morphed = static_cast(Spawn (spawntype, actor->x, actor->y, actor->z, NO_REPLACE)); + EndAllPowerupEffects(actor->Inventory); DObject::StaticPointerSubstitution (actor, morphed); if ((actor->tid != 0) && (style & MORPH_NEWTIDBEHAVIOUR)) { @@ -144,6 +145,7 @@ bool P_MorphPlayer (player_t *activator, player_t *p, const PClass *spawntype, i } item = next; } + InitAllPowerupEffects(morphed->Inventory); morphed->ActivateMorphWeapon (); if (p->camera == actor) { @@ -201,10 +203,8 @@ bool P_UndoPlayerMorph (player_t *activator, player_t *player, int unmorphflag, } pmo->player = NULL; - mo->ObtainInventory (pmo); - DObject::StaticPointerSubstitution (pmo, mo); // Remove the morph power if the morph is being undone prematurely. - for (AInventory *item = mo->Inventory, *next = NULL; item != NULL; item = next) + for (AInventory *item = pmo->Inventory, *next = NULL; item != NULL; item = next) { next = item->Inventory; if (item->IsKindOf(RUNTIME_CLASS(APowerMorph))) @@ -213,6 +213,9 @@ bool P_UndoPlayerMorph (player_t *activator, player_t *player, int unmorphflag, item->Destroy(); } } + EndAllPowerupEffects(pmo->Inventory); + mo->ObtainInventory (pmo); + DObject::StaticPointerSubstitution (pmo, mo); if ((pmo->tid != 0) && (player->MorphStyle & MORPH_NEWTIDBEHAVIOUR)) { mo->tid = pmo->tid; @@ -235,6 +238,7 @@ bool P_UndoPlayerMorph (player_t *activator, player_t *player, int unmorphflag, mo->flags2 = (mo->flags2 & ~MF2_FLY) | (pmo->flags2 & MF2_FLY); mo->flags3 = (mo->flags3 & ~MF3_GHOST) | (pmo->flags3 & MF3_GHOST); mo->Score = pmo->Score; + InitAllPowerupEffects(mo->Inventory); const PClass *exit_flash = player->MorphExitFlash; bool correctweapon = !!(player->MorphStyle & MORPH_LOSEACTUALWEAPON); @@ -538,6 +542,46 @@ bool P_MorphedDeath(AActor *actor, AActor **morphed, int *morphedstyle, int *mor return false; } +//=========================================================================== +// +// EndAllPowerupEffects +// +// Calls EndEffect() on every Powerup in the inventory list. +// +//=========================================================================== + +void EndAllPowerupEffects(AInventory *item) +{ + while (item != NULL) + { + if (item->IsKindOf(RUNTIME_CLASS(APowerup))) + { + static_cast(item)->EndEffect(); + } + item = item->Inventory; + } +} + +//=========================================================================== +// +// InitAllPowerupEffects +// +// Calls InitEffect() on every Powerup in the inventory list. +// +//=========================================================================== + +void InitAllPowerupEffects(AInventory *item) +{ + while (item != NULL) + { + if (item->IsKindOf(RUNTIME_CLASS(APowerup))) + { + static_cast(item)->InitEffect(); + } + item = item->Inventory; + } +} + // Base class for morphing projectiles -------------------------------------- IMPLEMENT_CLASS(AMorphProjectile)