From 2f2ac42ff1d218d7146a40ae66591a194856947f Mon Sep 17 00:00:00 2001 From: terencehill Date: Tue, 18 Mar 2025 20:20:37 +0100 Subject: [PATCH] Bot waypoints: round positions to the nearest .0 or .5 so that waypoints are in exactly the same position after save/load It gets rid of 2 "Waypoint stuck" warnings (with developer 1) on Implosion at map start With this change waypoints can be tested with the exact player bbox size and can be spawned even in extremely narrow places --- qcsrc/server/bot/default/waypoints.qc | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index 22a825528..e530a3c9e 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -455,17 +455,34 @@ entity waypoint_spawn(vector m1, vector m2, float f) w.wpflags = f; w.solid = SOLID_TRIGGER; w.createdtime = time; - setorigin(w, (m1 + m2) * 0.5); - setsize(w, m1 - w.origin, m2 - w.origin); + if (m1 == m2) + { + // Since waypoint_saveall saves waypoint positions with one decimal place anyway, positions + // here are rounded to the nearest .0 or .5 (1/2), which is the only float that can be + // represented with exactly one decimal place, so that waypoints are in exactly the + // same position after save/load and the waypoint test always gives the same result + vector org = m1; + // same as org.x = rint(org.x * 2) / 2; but this formula should be safer for huge numbers + org.x = floor(org.x); if (m1.x - org.x >= 0.25) org.x += (m1.x - org.x < 0.75) ? 0.5 : 1; + org.y = floor(org.y); if (m1.y - org.y >= 0.25) org.y += (m1.y - org.y < 0.75) ? 0.5 : 1; + org.z = floor(org.z); if (m1.z - org.z >= 0.25) org.z += (m1.z - org.z < 0.75) ? 0.5 : 1; + setorigin(w, org); + } + else // box-shaped waypoint + { + setorigin(w, (m1 + m2) * 0.5); + setsize(w, m1 - w.origin, m2 - w.origin); + } if (w.size) w.wpisbox = true; if(!w.wpisbox) { + // test if there's room for a player in the waypoint position if (f & WAYPOINTFLAG_CROUCH) - setsize(w, PL_CROUCH_MIN_CONST - '1 1 0', PL_CROUCH_MAX_CONST + '1 1 0'); + setsize(w, PL_CROUCH_MIN_CONST, PL_CROUCH_MAX_CONST); else - setsize(w, PL_MIN_CONST - '1 1 0', PL_MAX_CONST + '1 1 0'); + setsize(w, PL_MIN_CONST, PL_MAX_CONST); if(!move_out_of_solid(w)) { if(!(f & WAYPOINTFLAG_GENERATED)) -- 2.39.5