- Exhumed: Change updatePlayerTarget() to do an early return instead of nested branches.

This commit is contained in:
Mitchell Richters 2023-03-26 09:45:01 +11:00
parent 77bcea409b
commit 8d1531ba78

View file

@ -703,8 +703,8 @@ void AIPlayer::Damage(RunListEvent* ev)
void updatePlayerTarget(Player* const pPlayer)
{
const auto pRa = &Ra[pPlayer->nPlayer];
const auto pPlayerActor = pPlayer->pActor;
const auto pRa = &Ra[pPlayer->nPlayer];
const auto nAngVect = (-pPlayerActor->spr.Angles.Yaw).ToVector();
DExhumedActor* bestTarget = nullptr;
@ -717,8 +717,9 @@ void updatePlayerTarget(Player* const pPlayer)
const bool validstatnum = (itActor->spr.statnum > 0) && (itActor->spr.statnum < 150);
const bool validsprcstat = itActor->spr.cstat & CSTAT_SPRITE_BLOCK_ALL;
if (validstatnum && validsprcstat && itActor != pPlayerActor)
{
if (!validstatnum || !validsprcstat || itActor == pPlayerActor)
continue;
const DVector2 delta = itActor->spr.pos.XY() - pPlayerActor->spr.pos.XY();
const double fwd = abs((nAngVect.X * delta.Y) + (delta.X * nAngVect.Y));
const double side = abs((nAngVect.X * delta.X) - (delta.Y * nAngVect.Y));
@ -744,17 +745,15 @@ void updatePlayerTarget(Player* const pPlayer)
}
}
}
}
if (bestTarget)
{
if (pPlayer->nPlayer == nLocalPlayer) nCreepyTimer = kCreepyCount;
if (pPlayer->nPlayer == nLocalPlayer)
nCreepyTimer = kCreepyCount;
if (!cansee(pPlayerActor->spr.pos, pPlayerActor->sector(), bestTarget->spr.pos.plusZ(-GetActorHeight(bestTarget)), bestTarget->sector()))
{
bestTarget = nullptr;
}
}
pPlayer->pTarget = pRa->pTarget = bestTarget;
}