Skip to content

Commit

Permalink
Add Pre/PostTeleport virtuals, for special handling of actor teleport…
Browse files Browse the repository at this point in the history
…ation.
  • Loading branch information
Marisa Kirisame authored and coelckers committed Sep 2, 2020
1 parent 53199e4 commit e0aa8db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/playsim/p_teleport.cpp
Expand Up @@ -148,6 +148,19 @@ bool P_Teleport (AActor *thing, DVector3 pos, DAngle angle, int flags)
pos.Z = floorheight;
}
}
// [MK] notify thing of incoming teleport, check for an early cancel
// if it returns false
{
int nocancel = 1;
IFVIRTUALPTR(thing, AActor, PreTeleport)
{
VMValue params[] = { thing, pos.X, pos.Y, pos.Z, angle.Degrees, flags };
VMReturn ret;
ret.IntAt(&nocancel);
VMCall(func, params, countof(params), &ret, 1);
}
if ( !nocancel ) return false;
}
if (!P_TeleportMove (thing, pos, false))
{
return false;
Expand Down Expand Up @@ -213,6 +226,14 @@ bool P_Teleport (AActor *thing, DVector3 pos, DAngle angle, int flags)
// killough 10/98: kill all bobbing velocity too
if (player) player->Vel.Zero();
}
// [MK] notify thing of successful teleport
{
IFVIRTUALPTR(thing, AActor, PostTeleport)
{
VMValue params[] = { thing, pos.X, pos.Y, pos.Z, angle.Degrees, flags };
VMCall(func, params, countof(params), nullptr, 1);
}
}
return true;
}

Expand Down
5 changes: 5 additions & 0 deletions wadsrc/static/zscript/actors/actor.zs
Expand Up @@ -588,6 +588,11 @@ class Actor : Thinker native

// called on getting a secret, return false to disable default "secret found" message/sound
virtual bool OnGiveSecret(bool printmsg, bool playsound) { return true; }

// called before and after triggering a teleporter
// return false in PreTeleport() to cancel the action early
virtual bool PreTeleport( Vector3 destpos, double destangle, int flags ) { return true; }
virtual void PostTeleport( Vector3 destpos, double destangle, int flags ) {}

native virtual bool OkayToSwitchTarget(Actor other);
native static class<Actor> GetReplacement(class<Actor> cls);
Expand Down

0 comments on commit e0aa8db

Please sign in to comment.