From 0399cf17fe8d2873b3cde1e5b2c61cbf6f6356a6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 27 Sep 2022 18:58:37 +0200 Subject: [PATCH] - floatified cerberusBurnSeqCallback2 --- source/games/blood/src/aicerber.cpp | 97 +++++++++++++---------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/source/games/blood/src/aicerber.cpp b/source/games/blood/src/aicerber.cpp index 678bf51bb..113152926 100644 --- a/source/games/blood/src/aicerber.cpp +++ b/source/games/blood/src/aicerber.cpp @@ -55,6 +55,9 @@ AISTATE cerberus4Burn = { kAiStateChase, 6, nCerberusBurnClient2, 60, NULL, NULL AISTATE cerberus139890 = { kAiStateOther, 7, -1, 120, NULL, aiMoveTurn, NULL, &cerberusChase }; AISTATE cerberus1398AC = { kAiStateOther, 7, -1, 120, NULL, aiMoveTurn, NULL, &cerberusChase }; +static constexpr double Cerberus_XYOff = 350. / 16; +static constexpr double Cerberus_ZOff = 100. / 256; + void cerberusBiteSeqCallback(int, DBloodActor* actor) { if (!(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax)) { @@ -67,8 +70,8 @@ void cerberusBiteSeqCallback(int, DBloodActor* actor) DVector3 vec; vec.XY() = actor->spr.angle.ToVector() * 64; vec.Z = target->spr.pos.Z - actor->spr.pos.Z; - actFireVector(actor, 350 / 16., -100 / 256., vec, kVectorCerberusHack); - actFireVector(actor, -350 / 16., 0, vec, kVectorCerberusHack); + actFireVector(actor, Cerberus_XYOff, -Cerberus_ZOff, vec, kVectorCerberusHack); + actFireVector(actor, -Cerberus_XYOff, 0, vec, kVectorCerberusHack); actFireVector(actor, 0, 0, vec, kVectorCerberusHack); } @@ -125,11 +128,11 @@ void cerberusBurnSeqCallback(int, DBloodActor* actor) } switch (actor->spr.type) { case kDudeCerberusTwoHead: - actFireMissile(actor, -350 / 16., 0, Aim, kMissileFireballCerberus); - actFireMissile(actor, 350 / 16., -100 / 256., Aim, kMissileFireballCerberus); + actFireMissile(actor, -Cerberus_XYOff, 0, Aim, kMissileFireballCerberus); + actFireMissile(actor, Cerberus_XYOff, -Cerberus_ZOff, Aim, kMissileFireballCerberus); break; case kDudeCerberusOneHead: - actFireMissile(actor, 350 / 16., -100 / 256., Aim, kMissileFireballCerberus); + actFireMissile(actor, Cerberus_XYOff, -Cerberus_ZOff, Aim, kMissileFireballCerberus); break; } } @@ -138,77 +141,67 @@ void cerberusBurnSeqCallback2(int, DBloodActor* actor) { if (!actor->ValidateTarget(__FUNCTION__)) return; DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); - int height = pDudeInfo->eyeHeight * actor->spr.yrepeat; + double height = pDudeInfo->eyeHeight * actor->spr.yrepeat * REPEAT_SCALE * 0.25; + + auto pos = actor->spr.pos.plusZ(height); + + DVector3 Aim, Aim2; + Aim2.XY() = Aim.XY() = actor->spr.angle.ToVector(); + Aim.Z = actor->dudeSlope / 16384.; + Aim2.Z = 0; + double nClosest = 0x7fffffff; - int x = actor->int_pos().X; - int y = actor->int_pos().Y; - int z = height; // ??? - TARGETTRACK tt1 = { 0x10000, 0x10000, 0x100, 0x55, 0x1aaaaa }; - Aim aim; - int ax, ay, az; - aim.dx = ax = bcos(actor->int_ang()); - aim.dy = ay = bsin(actor->int_ang()); - aim.dz = actor->dudeSlope; - az = 0; - int nClosest = 0x7fffffff; BloodStatIterator it(kStatDude); while (auto actor2 = it.Next()) { if (actor == actor2 || !(actor2->spr.flags & 8)) continue; - int x2 = actor2->int_pos().X; - int y2 = actor2->int_pos().Y; - int z2 = actor2->int_pos().Z; - int nDist = approxDist(x2 - x, y2 - y); - if (nDist == 0 || nDist > 0x2800) + + auto pos2 = actor2->spr.pos; + double nDist = (pos2 - pos).Length(); + if (nDist == 0 || nDist > 0x280) continue; - if (tt1.at10) - { - int t = DivScale(nDist, tt1.at10, 12); - x2 += (actor->int_vel().X * t) >> 12; - y2 += (actor->int_vel().Y * t) >> 12; - z2 += (actor->int_vel().Z * t) >> 8; - } - int tx = x + MulScale(Cos(actor->int_ang()), nDist, 30); - int ty = y + MulScale(Sin(actor->int_ang()), nDist, 30); - int tz = z + MulScale(actor->dudeSlope, nDist, 10); - int tsr = MulScale(9460, nDist, 10); - int top, bottom; + + pos += actor2->vel * nDist * (65536. / 0x1aaaaa); + + DVector3 tvec = pos; + tvec.XY() += actor->spr.angle.ToVector() * nDist; + tvec.Z += actor->dudeSlope / 16384. * nDist; + double tsr = nDist * 9.23828125; + double top, bottom; GetActorExtents(actor2, &top, &bottom); - if (tz - tsr > bottom || tz + tsr < top) + if (tvec.Z - tsr > bottom || tvec.Z + tsr < top) continue; - int dx = (tx - x2) >> 4; - int dy = (ty - y2) >> 4; - int dz = (tz - z2) >> 8; - int nDist2 = ksqrt(dx * dx + dy * dy + dz * dz); + double nDist2 = (tvec - pos2).Length(); if (nDist2 < nClosest) { - int nAngle = getangle(x2 - x, y2 - y); - int nDeltaAngle = ((nAngle - actor->int_ang() + 1024) & 2047) - 1024; - if (abs(nDeltaAngle) <= tt1.at8) + DAngle nAngle = VecToAngle(pos2.XY() - pos.XY()); + DAngle nDeltaAngle = absangle(nAngle, actor->spr.angle); + if (nDeltaAngle <= DAngle45) { DUDEINFO* pDudeInfo2 = getDudeInfo(actor2->spr.type); - int height1 = (pDudeInfo2->aimHeight * actor2->spr.yrepeat) << 2; - int tz1 = (z2 - height1) - z; - if (cansee(x, y, z, actor->sector(), x2, y2, z2, actor2->sector())) + double height1 = (pDudeInfo2->aimHeight * actor2->spr.yrepeat) * REPEAT_SCALE; + double tz1 = actor2->spr.pos.Z - height - actor->spr.pos.Z; + + if (cansee(pos, actor->sector(), pos2, actor2->sector())) { nClosest = nDist2; - aim.dx = bcos(nAngle); - aim.dy = bsin(nAngle); - aim.dz = DivScale(tz1, nDist, 10); + Aim.XY() = nAngle.ToVector(); + Aim.Z = tz1 / nDist; } else - aim.dz = tz1; + Aim.Z = tz1 / 64.; } } } switch (actor->spr.type) { + case kDudeCerberusTwoHead: - actFireMissile(actor, 350, -100, aim.dx, aim.dy, -aim.dz, kMissileFlameHound); - actFireMissile(actor, -350, 0, ax, ay, az, kMissileFlameHound); + actFireMissile(actor, Cerberus_XYOff, -Cerberus_ZOff, Aim, kMissileFlameHound); + actFireMissile(actor, -Cerberus_XYOff, 0, Aim2, kMissileFlameHound); break; case kDudeCerberusOneHead: - actFireMissile(actor, 350, -100, aim.dx, aim.dy, -aim.dz, kMissileFlameHound); + actFireMissile(actor, Cerberus_XYOff, -Cerberus_ZOff, Aim, kMissileFlameHound); break; } }