From 42cb8a74ea8e10e3ce8d2ee851a0e255e14b4369 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 9 Sep 2022 18:37:10 +0200 Subject: [PATCH] - Exhumed radius damage and rat --- source/games/exhumed/src/aistuff.h | 2 +- source/games/exhumed/src/rat.cpp | 11 ++++---- source/games/exhumed/src/runlist.cpp | 41 ++++++++++------------------ 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index 707464e55..c4bb97631 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -379,7 +379,7 @@ struct RunListEvent int nDamage, nRun; int nRadialDamage; // Radial damage needs a bit more info. - int nDamageRadius; + double nDamageRadius; DExhumedActor* pRadialActor; bool isRadialEvent() const { return nMessage == 1; } diff --git a/source/games/exhumed/src/rat.cpp b/source/games/exhumed/src/rat.cpp index 4abfbe76c..be5e43f38 100644 --- a/source/games/exhumed/src/rat.cpp +++ b/source/games/exhumed/src/rat.cpp @@ -189,6 +189,7 @@ void AIRat::Draw(RunListEvent* ev) void AIRat::Tick(RunListEvent* ev) { + constexpr double CHECK_DIST = 50/16.; auto pActor = ev->pObjActor; if (!pActor) return; @@ -224,10 +225,9 @@ void AIRat::Tick(RunListEvent* ev) return; } - int xVal = abs(pActor->int_pos().X - pTarget->int_pos().X); - int yVal = abs(pActor->int_pos().Y - pTarget->int_pos().Y); + auto delta = pActor->spr.pos.XY() - pTarget->spr.pos.XY(); - if (xVal > 50 || yVal > 50) + if (abs(delta.X) > CHECK_DIST || abs(delta.Y) >= CHECK_DIST) { pActor->nAction = 2; pActor->nFrame = 0; @@ -277,10 +277,9 @@ void AIRat::Tick(RunListEvent* ev) MoveCreature(pActor); - int xVal = abs(pActor->int_pos().X - pTarget->int_pos().X); - int yVal = abs(pActor->int_pos().Y - pTarget->int_pos().Y); + auto delta = pActor->spr.pos.XY() - pTarget->spr.pos.XY(); - if (xVal >= 50 || yVal >= 50) + if (abs(delta.X) > CHECK_DIST || abs(delta.Y) >= CHECK_DIST) { pActor->nCount--; if (pActor->nCount < 0) diff --git a/source/games/exhumed/src/runlist.cpp b/source/games/exhumed/src/runlist.cpp index fc7bb73f7..876a71199 100644 --- a/source/games/exhumed/src/runlist.cpp +++ b/source/games/exhumed/src/runlist.cpp @@ -38,7 +38,7 @@ int word_966BE = 0; int ChannelList = -1; int ChannelLast = -1; -int nDamageRadius; +double nDamageRadius; int nRadialDamage; int RunChain; int NewRun; @@ -1604,36 +1604,23 @@ int runlist_CheckRadialDamage(DExhumedActor* pActor) return 0; } - int x = (pActor->int_pos().X - pRadialActor->int_pos().X) >> 8; - int y = (pActor->int_pos().Y - pRadialActor->int_pos().Y) >> 8; - int z = (pActor->int_pos().Z - pRadialActor->int_pos().Z) >> 12; - - if (abs(x) > nDamageRadius) { - return 0; - } - - if (abs(y) > nDamageRadius) { - return 0; - } - - if (abs(z) > nDamageRadius) { - return 0; - } + auto pos = (pActor->spr.pos - pRadialActor->spr.pos) / 16.; int edi = 0; - uint32_t xDiff = abs(x); - uint32_t yDiff = abs(y); + if (abs(pos.X) > nDamageRadius) { + return 0; + } - uint32_t sqrtNum = xDiff * xDiff + yDiff * yDiff; + if (abs(pos.Y) > nDamageRadius) { + return 0; + } - if (sqrtNum > INT_MAX) - { - DPrintf(DMSG_WARNING, "%s %d: overflow\n", __func__, __LINE__); - sqrtNum = INT_MAX; - } + if (abs(pos.Z) > nDamageRadius) { + return 0; + } - int nDist = ksqrt(sqrtNum); + double nDist = pos.XY().Length(); if (nDist < nDamageRadius) { @@ -1646,14 +1633,14 @@ int runlist_CheckRadialDamage(DExhumedActor* pActor) pActor->spr.pos.plusZ(-32), pActor->sector())) { - edi = (nRadialDamage * (nDamageRadius - nDist)) / nDamageRadius; + edi = int((nRadialDamage * (nDamageRadius - nDist)) / (nDamageRadius)); if (edi < 0) { edi = 0; } else if (edi > 20) { - int nAngle = getangle(x, y); + int nAngle = getangle(pos); pActor->add_int_xvel( (edi * bcos(nAngle)) >> 3); pActor->add_int_yvel((edi * bsin(nAngle)) >> 3);