diff --git a/source/common/utility/vectors.h b/source/common/utility/vectors.h index b8a563ca8..86fc98b12 100644 --- a/source/common/utility/vectors.h +++ b/source/common/utility/vectors.h @@ -237,6 +237,12 @@ struct TVector2 { return X*X + Y*Y; } + + double Sum() const + { + return abs(X) + abs(Y); + } + // Return a unit vector facing the same direction as this one TVector2 Unit() const @@ -601,6 +607,12 @@ struct TVector3 { return X*X + Y*Y + Z*Z; } + + double Sum() const + { + return abs(X) + abs(Y) + abs(Z); + } + // Return a unit vector facing the same direction as this one TVector3 Unit() const @@ -900,6 +912,12 @@ struct TVector4 { return X*X + Y*Y + Z*Z + W*W; } + + double Sum() const + { + return abs(X) + abs(Y) + abs(Z) + abs(W); + } + // Return a unit vector facing the same direction as this one TVector4 Unit() const diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 62e78db2d..1363a41cd 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -4928,7 +4928,7 @@ DAngle furthestangle(DDukeActor *actor, int angs) { hitscan(actor->spr.pos.plusZ(-8), actor->sector(), DVector3(j.ToVector() * 1024, 0), hit, CLIPMASK1); - d = abs(hit.hitpos.X - actor->spr.pos.X) + abs(hit.hitpos.Y - actor->spr.pos.Y); + d = (hit.hitpos.XY() - actor->spr.pos.XY()).Sum(); if (d > greatestd) { @@ -4960,8 +4960,8 @@ int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, DVector2& pos) { hitscan(tosee->spr.pos.plusZ(-16), tosee->sector(), vec3_t(bcos(j), bsin(j), 16384 - (krand() & 32767)), hit, CLIPMASK1); - double d = abs(hit.hitpos.X - tosee->spr.pos.X) + abs(hit.hitpos.Y - tosee->spr.pos.Y); - double da = abs(hit.hitpos.X - actor->spr.pos.X) + abs(hit.hitpos.Y - actor->spr.pos.Y); + double d = (hit.hitpos.XY() - tosee->spr.pos.XY()).Sum(); + double da = (hit.hitpos.XY() - actor->spr.pos.XY()).Sum(); if (d < da && hit.hitSector) if (cansee(hit.hitpos, hit.hitSector, actor->spr.pos.plusZ(-16), actor->sector())) diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 0b6010982..eca85363f 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -227,7 +227,7 @@ int findplayer(const DDukeActor* actor, double* d) if (ud.multimode < 2) { - if (d) *d = abs(ps[myconnectindex].opos.X - s.X) + abs(ps[myconnectindex].opos.Y - s.Y) + abs(ps[myconnectindex].opos.Z - s.Z + 28); + if (d) *d = (ps[myconnectindex].opos - s).plusZ(28).Sum(); return myconnectindex; } @@ -236,7 +236,7 @@ int findplayer(const DDukeActor* actor, double* d) for (j = connecthead; j >= 0; j = connectpoint2[j]) { - x = abs(ps[j].opos.X - s.X) + abs(ps[j].opos.Y - s.Y) + abs(ps[j].opos.Z - s.Z + 28); + x = (ps[j].opos - s).plusZ(28).Sum(); if (x < closest && ps[j].GetActor()->spr.extra > 0) { closest_player = j; @@ -265,7 +265,7 @@ int findotherplayer(int p, double* d) for (j = connecthead; j >= 0; j = connectpoint2[j]) if (p != j && ps[j].GetActor()->spr.extra > 0) { - x = abs(ps[j].opos.X - ps[p].pos.X) + abs(ps[j].opos.Y - ps[p].pos.Y) + abs(ps[j].opos.Z - ps[p].pos.Z); + x = (ps[j].opos - ps[p].pos).Sum(); if (x < closest) {