Added Pre(Un)Morph and Post(Un)Morph functions.

- cls: The other class's cast type which the actor is transitioning from/to.
This commit is contained in:
Major Cooke 2020-02-15 16:12:45 -06:00 committed by Christoph Oelckers
parent fcf004ec39
commit 33b343ef31
2 changed files with 29 additions and 0 deletions

View file

@ -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<Actor> cls) {}
virtual void PostMorph(Class<Actor> cls) {}
virtual void PreUnmorph(Class<Actor> cls) {}
virtual void PostUnmorph(Class<Actor> 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<Actor>)("TeleportFog"), Pos + (0, 0, gameinfo.TELEFOGHEIGHT), ALLOW_REPLACE);
if (eflash)
eflash.target = morphed;
PostMorph(morphed.GetClass());
morphed.PostMorph(GetClass());
return true;
}
}

View file

@ -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 ();