Skip to content

Commit

Permalink
Clear the path instead of advancing the node when crossing portals.
Browse files Browse the repository at this point in the history
- If an actor crosses back over a portal because they're blocked, it will result in false positives.
- Fixed nodes not being targeted for aim direction.
  • Loading branch information
MajorCooke authored and madame-rachelle committed Mar 5, 2024
1 parent 257ddb5 commit d71af36
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
22 changes: 15 additions & 7 deletions src/playsim/p_enemy.cpp
Expand Up @@ -951,13 +951,13 @@ void P_DoNewChaseDir (AActor *actor, double deltax, double deltay)
//
//=============================================================================

void P_NewChaseDir(AActor * actor)
void DoNewChaseDir(AActor * actor, bool node)
{
DVector2 delta;

actor->strafecount = 0;

if ((actor->flags5&MF5_CHASEGOAL || actor->goal == actor->target) && actor->goal!=NULL)
if ((node || actor->flags5&MF5_CHASEGOAL || actor->goal == actor->target) && actor->goal != nullptr)
{
delta = actor->Vec2To(actor->goal);
}
Expand Down Expand Up @@ -1096,6 +1096,11 @@ void P_NewChaseDir(AActor * actor)

}

void P_NewChaseDir(AActor* actor)
{
DoNewChaseDir(actor, false);
}

//=============================================================================
//
// P_RandomChaseDir
Expand Down Expand Up @@ -2579,7 +2584,11 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi
}

// [RH] Don't attack if just moving toward goal
if (actor->target == actor->goal || (actor->flags5&MF5_CHASEGOAL && actor->goal != nullptr))
static const PClass* nodeCls = PClass::FindClass(NAME_PathNode);
bool pnode = (actor->goal && nodeCls->IsAncestorOf(actor->goal->GetClass()));

if (!pnode &&
(actor->target == actor->goal || (actor->flags5&MF5_CHASEGOAL && actor->goal)))
{
AActor * savedtarget = actor->target;
actor->target = actor->goal;
Expand Down Expand Up @@ -2727,8 +2736,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi

if (sight == 0)
{
static const PClass* nodeCls = PClass::FindClass(NAME_PathNode);
if (actor->goal && !(actor->goal->flags & MF_AMBUSH) && nodeCls->IsAncestorOf(actor->goal->GetClass()))
if (pnode && !(actor->goal->flags & MF_AMBUSH))
{
AActor* temp = actor->target;
actor->target = actor->goal;
Expand Down Expand Up @@ -2766,7 +2774,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi
// chase towards player
if ((--actor->movecount < 0 && !(flags & CHF_NORANDOMTURN)) || (!P_SmartMove(actor) && !(flags & CHF_STOPIFBLOCKED)))
{
P_NewChaseDir(actor);
DoNewChaseDir(actor, pnode);
}
// if the move was illegal, reset it
// (copied from A_SerpentChase - it applies to everything with CANTLEAVEFLOORPIC!)
Expand All @@ -2782,7 +2790,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi
}
}
if (!(flags & CHF_STOPIFBLOCKED))
P_NewChaseDir(actor);
DoNewChaseDir(actor, pnode);
}
}
else if (dontmove && actor->movecount > 0) actor->movecount--;
Expand Down
11 changes: 6 additions & 5 deletions src/playsim/p_map.cpp
Expand Up @@ -2536,8 +2536,8 @@ bool P_TryMove(AActor *thing, const DVector2 &pos,


// Check for crossed portals
bool portalcrossed;
portalcrossed = false;
bool portalcrossed, nodecall;
nodecall = portalcrossed = false;

while (true)
{
Expand Down Expand Up @@ -2582,6 +2582,7 @@ bool P_TryMove(AActor *thing, const DVector2 &pos,
thing->Prev += port->mDisplacement;
thing->LinkToWorld(&ctx);
P_FindFloorCeiling(thing);
thing->ClearPath();
portalcrossed = true;
tm.portalstep = false;
tm.pos += port->mDisplacement;
Expand Down Expand Up @@ -2611,9 +2612,9 @@ bool P_TryMove(AActor *thing, const DVector2 &pos,
P_TranslatePortalVXVY(ld, thing->Vel.X, thing->Vel.Y);
P_TranslatePortalAngle(ld, thing->Angles.Yaw);
thing->LinkToWorld(&ctx);
P_FindFloorCeiling(thing);
P_FindFloorCeiling(thing);
thing->ClearPath();
thing->ClearInterpolation();
thing->CallReachedNode(thing->goal);
portalcrossed = true;
tm.portalstep = false;
}
Expand Down Expand Up @@ -2770,7 +2771,7 @@ bool P_TryMove(AActor *thing, const DVector2 &pos,
thing->Sector = thing->Level->PointInSector(thing->Pos());
thing->PrevPortalGroup = thing->Sector->PortalGroup;
thing->LinkToWorld(&ctx);

thing->ClearPath();
P_FindFloorCeiling(thing);
}

Expand Down
16 changes: 11 additions & 5 deletions wadsrc/static/zscript/actors/actor.zs
Expand Up @@ -802,10 +802,13 @@ class Actor : Thinker native
native clearscope bool CanPathfind() const;
virtual void ReachedNode(Actor mo)
{
if (!mo && !goal)
return;
if (!mo)
{
if (!goal)
return;
mo = goal;
}

mo = goal;
let node = PathNode(mo);
if (!node || !target || (!bKEEPPATH && CheckSight(target)))
{
Expand Down Expand Up @@ -835,7 +838,7 @@ class Actor : Thinker native

if (i >= end)
ClearPath();

}

// Return true to mark the node as ineligible for constructing a path along.
Expand All @@ -847,12 +850,15 @@ class Actor : Thinker native
// STANDSTILL flag is used to require the actor to be bigger instead of smaller.
double r = node.Scale.X;
double h = node.Scale.Y;

if (r <= 0.0 && h <= 0.0)
return false;

// Perfect fit.
if (radius == r && height == h)
return false;

if ((0.0 < r && r < radius) || (0.0 < h && h < height))
if ((r < radius) || (h < height))
return !node.bSTANDSTILL;

return false;
Expand Down

0 comments on commit d71af36

Please sign in to comment.