diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 459daae61..ede812fa6 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -1448,7 +1448,8 @@ bool queball(DDukeActor *actor, int pocket, int queball, int stripeball) DukeStatIterator it(STAT_DEFAULT); while (auto aa = it.Next()) { - if (aa->spr.picnum == pocket && ldist(aa, actor) < 52) + double dist = (aa->spr.pos.XY() - actor->spr.pos.XY()).Length(); + if (aa->spr.picnum == pocket && dist < 3.25) { deletesprite(actor); return false; @@ -1709,8 +1710,8 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p if (actor->temp_data[0] != 2 && actor->temp_data[0] != 3 && Owner) { - int l = ldist(Owner, actor); - if (l <= 1524) + double dist = (Owner->spr.pos.XY() - actor->spr.pos.XY()).Length(); + if (dist <= 96) { a = actor->int_ang(); actor->vel.X *= 0.5; @@ -1719,13 +1720,13 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p if (actor->temp_data[0] == 1 || actor->temp_data[0] == 4) // Found a locator and going with it { - double dist = (Owner->spr.pos - actor->spr.pos).Length(); + dist = (Owner->spr.pos - actor->spr.pos).Length(); - if (dist <= 1524/16.) { if (actor->temp_data[0] == 1) actor->temp_data[0] = 0; else actor->temp_data[0] = 5; } + if (dist <= 96) { if (actor->temp_data[0] == 1) actor->temp_data[0] = 0; else actor->temp_data[0] = 5; } else { // Control speed here - if (dist > 1524 / 16.) { if (actor->vel.X < 16) actor->vel.X += 2.; } + if (dist > 96) { if (actor->vel.X < 16) actor->vel.X += 2.; } else { if(actor->vel.X > 0) actor->vel.X -= 1; @@ -2127,11 +2128,14 @@ bool money(DDukeActor* actor, int BLOODPOOL) while (auto aa = it.Next()) { if (aa->spr.picnum == BLOODPOOL) - if (ldist(actor, aa) < 348) + { + double dist = (aa->spr.pos.XY() - actor->spr.pos.XY()).Length(); + if (dist < 348/16.) { actor->spr.pal = 2; break; } + } } } return true; @@ -2754,9 +2758,9 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6) } auto Owner = actor->GetOwner(); - int j = ldist(Owner, actor); + double dist = (Owner->spr.pos.XY() - actor->spr.pos.XY()).LengthSquared(); - if (j < 1024) + if (dist < 64*64) { if (st == 6) if (Owner->spr.hitag & 1) diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index f48bcc595..ca1333ca5 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -2296,8 +2296,8 @@ static void greenslime(DDukeActor *actor) else { actor->temp_data[0] = -1; - x = ldist(actor, s5); - if (x < 768) { + double dist = (actor->spr.pos.XY() - s5->spr.pos.XY()).LengthSquared(); + if (dist < 48*48) { s5->spr.xrepeat = 0; } } @@ -2314,7 +2314,8 @@ static void greenslime(DDukeActor *actor) { if (actorflag(a2, SFLAG_GREENSLIMEFOOD)) { - if (ldist(actor, a2) < 768 && (abs(actor->int_pos().Z - a2->int_pos().Z) < 8192)) //Gulp them + double dist = (actor->spr.pos.XY() - a2->spr.pos.XY()).LengthSquared(); + if (dist < 48*48 && (abs(actor->spr.pos.Z - a2->spr.pos.Z) < 16)) //Gulp them { actor->temp_actor = a2; actor->temp_data[0] = -2; @@ -3248,11 +3249,11 @@ static void handle_se28(DDukeActor* actor) act2->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE; spawn(act2, SMALLSMOKE); - int x; + double x; int p = findplayer(actor, &x); auto psa = ps[p].GetActor(); - x = ldist(psa, act2); - if (x < 768) + double dist = (psa->spr.pos.XY() - act2->spr.pos.XY()).LengthSquared(); + if (dist < 49*48) { if (S_CheckActorSoundPlaying(psa, DUKE_LONGTERM_PAIN) < 1) S_PlayActorSound(DUKE_LONGTERM_PAIN, psa); diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index d68ea3413..d476ab3dd 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -208,8 +208,12 @@ void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, double interp int sqb = getangle(OwnerAc->spr.pos.XY() - t->pos.XY()); if (abs(getincangle(sqa, sqb)) > 512) - if (ldist(OwnerAc, t) < ldist(ps[screenpeek].GetActor(), OwnerAc)) + { + double dist1 = (OwnerAc->spr.pos.XY() - t->pos.XY()).LengthSquared(); + double dist2 = (OwnerAc->spr.pos.XY() - ps[screenpeek].GetActor()->spr.pos.XY()).LengthSquared(); + if (dist1 < dist2) t->xrepeat = t->yrepeat = 0; + } } continue; case BURNING: diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index 2efde9bc8..b20f2d8a4 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -203,8 +203,12 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, double interp int sqb = getangle(OwnerAc->spr.pos.XY() - t->pos.XY()); if (abs(getincangle(sqa, sqb)) > 512) - if (ldist(OwnerAc, t) < ldist(ps[screenpeek].GetActor(), OwnerAc)) + { + double dist1 = (OwnerAc->spr.pos.XY() - t->pos.XY()).LengthSquared(); + double dist2 = (OwnerAc->spr.pos.XY() - ps[screenpeek].GetActor()->spr.pos.XY()).LengthSquared(); + if (dist1 < dist2) t->xrepeat = t->yrepeat = 0; + } } continue; case BURNING: diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 261024f5a..02b7909cb 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -2909,8 +2909,8 @@ int ParseState::parse(void) int lType; int lMaxDist; int lVarID; - int lTemp; - int lDist; + double lTemp; + double lDist; insptr++; @@ -2919,14 +2919,14 @@ int ParseState::parse(void) lVarID = *(insptr++); DDukeActor* lFound = nullptr; - lDist = 32767; // big number + lDist = 1000000; // big number DukeStatIterator it(STAT_ACTOR); while (auto actj = it.Next()) { if (actj->spr.picnum == lType) { - lTemp = ldist(g_ac, actj); + lTemp = (g_ac->spr.pos.XY() - actj->spr.pos.XY()).Length(); if (lTemp < lMaxDist) { if (lTemp < lDist) @@ -2952,8 +2952,8 @@ int ParseState::parse(void) int lMaxDistVar; int lMaxDist; int lVarID; - int lTemp; - int lDist; + double lTemp; + double lDist; insptr++; @@ -2962,14 +2962,14 @@ int ParseState::parse(void) lVarID = *(insptr++); lMaxDist = GetGameVarID(lMaxDistVar, g_ac, g_p).safeValue(); DDukeActor* lFound = nullptr; - lDist = 32767; // big number + lDist = 1000000; // big number DukeStatIterator it(STAT_ACTOR); while (auto actj = it.Next()) { if (actj->spr.picnum == lType) { - lTemp = ldist(g_ac, actj); + lTemp = (g_ac->spr.pos.XY() - actj->spr.pos.XY()).Length(); if (lTemp < lMaxDist) { if (lTemp < lDist)