From 33b343ef3166f7c2640ac2e732363c478ba14d7c Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Sat, 15 Feb 2020 16:12:45 -0600 Subject: [PATCH] Added Pre(Un)Morph and Post(Un)Morph functions. - cls: The other class's cast type which the actor is transitioning from/to. --- wadsrc/static/zscript/actors/morph.zs | 13 +++++++++++++ .../static/zscript/actors/player/player_morph.zs | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/wadsrc/static/zscript/actors/morph.zs b/wadsrc/static/zscript/actors/morph.zs index b48bb98d4..8dbfb3862 100644 --- a/wadsrc/static/zscript/actors/morph.zs +++ b/wadsrc/static/zscript/actors/morph.zs @@ -28,6 +28,12 @@ extend class Actor return null, 0, 0; } + // [MC] Called when an actor morphs, on both the previous form (passive) and present form (!passive). + // 'cls' points to the other class they transitioned from/to. + virtual void PreMorph(Class cls) {} + virtual void PostMorph(Class cls) {} + virtual void PreUnmorph(Class cls) {} + virtual void PostUnmorph(Class cls) {} //=========================================================================== // @@ -105,6 +111,11 @@ extend class Actor } let morphed = MorphedMonster(Spawn (spawntype, Pos, NO_REPLACE)); + + // Use GetClass in the event someone actually allows replacements. + PreMorph(morphed.GetClass()); + morphed.PreMorph(GetClass()); + Substitute (morphed); if ((style & MRF_TRANSFERTRANSLATION) && !morphed.bDontTranslate) { @@ -140,6 +151,8 @@ extend class Actor let eflash = Spawn(enter_flash ? enter_flash : (class)("TeleportFog"), Pos + (0, 0, gameinfo.TELEFOGHEIGHT), ALLOW_REPLACE); if (eflash) eflash.target = morphed; + PostMorph(morphed.GetClass()); + morphed.PostMorph(GetClass()); return true; } } diff --git a/wadsrc/static/zscript/actors/player/player_morph.zs b/wadsrc/static/zscript/actors/player/player_morph.zs index 87ee90ac9..2a4437159 100644 --- a/wadsrc/static/zscript/actors/player/player_morph.zs +++ b/wadsrc/static/zscript/actors/player/player_morph.zs @@ -138,6 +138,11 @@ extend class PlayerPawn } let morphed = PlayerPawn(Spawn (spawntype, Pos, NO_REPLACE)); + + // Use GetClass in the event someone actually allows replacements. + PreMorph(morphed.GetClass()); + morphed.PreMorph(GetClass()); + EndAllPowerupEffects(); Substitute(morphed); if ((style & MRF_TRANSFERTRANSLATION) && !morphed.bDontTranslate) @@ -211,6 +216,8 @@ extend class PlayerPawn morphed.ScoreIcon = ScoreIcon; // [GRB] if (eflash) eflash.target = morphed; + PostMorph(morphed.GetClass()); + morphed.PostMorph(GetClass()); return true; } @@ -249,6 +256,9 @@ extend class PlayerPawn player.morphTics = 2*TICRATE; return false; } + PreUnmorph(altmo.GetClass()); + altmo.PreUnmorph(GetClass()); + // No longer using tracer as morph storage. That is what 'alternative' is for. // If the tracer has changed on the morph, change the original too. altmo.target = target; @@ -395,6 +405,8 @@ extend class PlayerPawn beastweap.Destroy (); } } + PostUnmorph(altmo.GetClass()); + altmo.PostUnmorph(GetClass()); Destroy (); // Restore playerclass armor to its normal amount. let hxarmor = HexenArmor(altmo.FindInventory('HexenArmor')); @@ -544,6 +556,8 @@ class MorphedMonster : Actor UnmorphTime = level.time + 5*TICRATE; // Next try in 5 seconds return false; } + PreUnmorph(unmorphed.GetClass()); + unmorphed.PreUnmorph(GetClass()); unmorphed.Angle = Angle; unmorphed.target = target; unmorphed.bShadow = bShadow; @@ -563,6 +577,8 @@ class MorphedMonster : Actor unmorphed.args[4] = args[4]; unmorphed.CopyFriendliness (self, true); unmorphed.bUnmorphed = false; + PostUnmorph(unmorphed.GetClass()); + unmorphed.PostUnmorph(GetClass()); UnmorphedMe = NULL; Substitute(unmorphed); Destroy ();