diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 59a7b0750..73a228663 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -55,8 +55,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS -TObjPtr bestTarget; - IMPLEMENT_CLASS(DExhumedActor, false, true) IMPLEMENT_POINTERS_START(DExhumedActor) IMPLEMENT_POINTER(pTarget) @@ -86,7 +84,6 @@ static void markgcroots() MarkSnake(); MarkRunlist(); - GC::Mark(bestTarget); GC::Mark(pSpiritSprite); } @@ -287,6 +284,71 @@ void DoGameOverScene(bool finallevel) // //--------------------------------------------------------------------------- +static void updatePlayerTarget(const int nPlayer) +{ + const auto pPlayer = &PlayerList[nPlayer]; + const auto pRa = &Ra[nPlayer]; + const auto pPlayerActor = pPlayer->pActor; + const auto nAngVect = (-pPlayerActor->spr.Angles.Yaw).ToVector(); + + DExhumedActor* bestTarget = nullptr; + double bestclose = 20; + double bestside = 30000; + + ExhumedSpriteIterator it; + while (const auto itActor = it.Next()) + { + 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) + { + 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)); + + if (!side) + continue; + + const double close = fwd * 32 / side; + if (side < 1000 / 16. && side < bestside && close < 10) + { + bestTarget = itActor; + bestclose = close; + bestside = side; + } + else if (side < 30000 / 16.) + { + const double t = bestclose - close; + if (t > 3 || (side < bestside && abs(t) < 5)) + { + bestTarget = itActor; + bestclose = close; + bestside = side; + } + } + } + } + + if (bestTarget) + { + if (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; +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + static void GameMove(void) { UpdateInterpolations(); @@ -481,11 +543,9 @@ void GameInterface::Ticker() updatePlayerVelocity(pPlayer); updatePlayerInventory(pPlayer); updatePlayerWeapon(pPlayer); + updatePlayerTarget(i); } - // this setup needs rewriting to work for all players in an MP game. - PlayerList[nLocalPlayer].pTarget = Ra[nLocalPlayer].pTarget = bestTarget; - GameMove(); PlayClock += 4; @@ -610,10 +670,6 @@ void DeleteActor(DExhumedActor* actor) return; } - if (actor == bestTarget) { - bestTarget = nullptr; - } - UnlinkIgnitedAnim(actor); actor->Destroy(); } @@ -731,8 +787,7 @@ void SerializeState(FSerializer& arc) InitEnergyTile(); } - arc ("besttarget", bestTarget) - ("creaturestotal", nCreaturesTotal) + arc ("creaturestotal", nCreaturesTotal) ("creatureskilled", nCreaturesKilled) ("freeze", nFreeze) ("snakecam", nSnakeCam) diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index cf3b3edda..37c393216 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -74,18 +74,6 @@ static void analyzesprites(tspriteArray& tsprites, const DVector3& view, double } } - auto pPlayerActor = PlayerList[nLocalPlayer].pActor; - - double bestclose = 20; - double bestside = 30000; - - - bestTarget = nullptr; - - auto pSector =pPlayerActor->sector(); - - DAngle nAngle = -pPlayerActor->spr.Angles.Yaw; - for (int nTSprite = int(tsprites.Size()-1); nTSprite >= 0; nTSprite--) { auto pTSprite = tsprites.get(nTSprite); @@ -117,54 +105,10 @@ static void analyzesprites(tspriteArray& tsprites, const DVector3& view, double RunListEvent ev{}; ev.pTSprite = pTSprite; runlist_SignalRun(pActor->spr.lotag - 1, nTSprite, &ExhumedAI::Draw, &ev); - - if ((pActor->spr.statnum < 150) && (pActor->spr.cstat & CSTAT_SPRITE_BLOCK_ALL) && (pActor != pPlayerActor)) - { - DVector2 delta = pActor->spr.pos.XY() - view.XY(); - - double vcos = nAngle.Cos(); - double vsin = nAngle.Sin(); - - - double fwd = ((vcos * delta.Y) + (delta.X * vsin)); - double side = abs((vcos * delta.X) - (delta.Y * vsin)); - - if (!side) - continue; - - double close = (abs(fwd) * 32) / side; - if (side < 1000 / 16. && side < bestside && close < 10) - { - bestTarget = pActor; - bestclose = close; - bestside = side; - } - else if (side < 30000 / 16.) - { - double t = bestclose - close; - if (t > 3 || (side < bestside && abs(t) < 5)) - { - bestclose = close; - bestside = side; - bestTarget = pActor; - } - } - } - } - } - auto targ = bestTarget; - if (targ != nullptr) - { - nCreepyTimer = kCreepyCount; - - if (!cansee(view, pSector, targ->spr.pos.plusZ(-GetActorHeight(targ)), targ->sector())) - { - bestTarget = nullptr; } } mytspriteArray = nullptr; - } //--------------------------------------------------------------------------- diff --git a/source/games/exhumed/src/view.h b/source/games/exhumed/src/view.h index 5770874a5..dd38091b4 100644 --- a/source/games/exhumed/src/view.h +++ b/source/games/exhumed/src/view.h @@ -22,7 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS extern bool bSubTitles; -extern TObjPtr bestTarget; extern bool bCamera; void DrawStatusBar();