From b6c21c3da4bd048987753836aa73c3dd11345c1e Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 21 Jul 2019 18:07:14 +0200 Subject: [PATCH] Bot waypoints: remove all incoming links from waypoints with a support waypoint; make support waypoints for jumppad waypoints fully working (allowing to fix overlapping jumppads of runningman) --- qcsrc/server/bot/default/navigation.qh | 2 + qcsrc/server/bot/default/waypoints.qc | 56 +++++++++++++++++++++----- qcsrc/server/bot/default/waypoints.qh | 4 ++ qcsrc/server/command/cmd.qc | 1 + 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/qcsrc/server/bot/default/navigation.qh b/qcsrc/server/bot/default/navigation.qh index 73df404519..026d326b9e 100644 --- a/qcsrc/server/bot/default/navigation.qh +++ b/qcsrc/server/bot/default/navigation.qh @@ -30,6 +30,8 @@ entity navigation_bestgoal; .float goalcurrent_distance_2d; .float goalcurrent_distance_time; +// final goal (item, object or player) is also saved in this field +.entity goalentity; .float goalentity_lock_timeout; .bool goalentity_shouldbefrozen; diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index a8890519db..f5c3b9f7b9 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -505,11 +505,12 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo { crosshair_trace(pl); org = trace_endpos - eZ * PL_MIN_CONST.z; - IL_EACH(g_jumppads, boxesoverlap(org + PL_MIN_CONST, org + PL_MAX_CONST, it.absmin, it.absmax), - { - jp = it; - break; - }); + if (!start_wp_is_support) + IL_EACH(g_jumppads, boxesoverlap(org + PL_MIN_CONST, org + PL_MAX_CONST, it.absmin, it.absmax), + { + jp = it; + break; + }); } if (jp || is_jump_wp || is_support_wp) { @@ -661,7 +662,24 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo } } else + { + if (start_wp_is_support) + { + if (e.SUPPORT_WP) + { + LOG_INFOF("Waypoint %v has already a support waypoint, delete it first.\n", e.origin); + waypoint_clear_start_wp(pl, true); + return; + } + // clear all links to e + IL_EACH(g_waypoints, it != e, + { + if (waypoint_islinked(it, e) && !waypoint_is_hardwiredlink(it, e)) + waypoint_removelink(it, e); + }); + } waypoint_addlink(start_wp, e); + } } if (!(jp || is_jump_wp || is_support_wp || start_wp_is_hardwired)) @@ -730,8 +748,16 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo void waypoint_remove(entity wp) { + if (wp.SUPPORT_WP) + waypoint_remove(wp.SUPPORT_WP); // remove support waypoint too + IL_EACH(g_waypoints, it != wp, { + if (it.SUPPORT_WP == wp) + { + it.SUPPORT_WP = NULL; + waypoint_schedulerelink(it); // restore incoming links + } if (waypoint_islinked(it, wp)) { if (waypoint_is_hardwiredlink(it, wp)) @@ -1042,6 +1068,9 @@ void waypoint_addlink(entity from, entity to) waypoint_addlink_for_custom_jumppad(from, to); else waypoint_addlink_customcost(from, to, -1); + + if (from.wpflags & WAYPOINTFLAG_SUPPORT) + to.SUPPORT_WP = from; } // relink this spawnfunc_waypoint @@ -1064,8 +1093,10 @@ void waypoint_think(entity this) { if (boxesoverlap(this.absmin, this.absmax, it.absmin, it.absmax)) { - waypoint_addlink(this, it); - waypoint_addlink(it, this); + if (!(this.wpflags & WAYPOINTFLAG_NORELINK)) + waypoint_addlink(this, it); + if (!(it.wpflags & WAYPOINTFLAG_NORELINK)) + waypoint_addlink(it, this); } else { @@ -1110,8 +1141,11 @@ void waypoint_think(entity this) //traceline(this.origin, it.origin, false, NULL); //if (trace_fraction == 1) - if (this.wpisbox || this.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)) + if (this.wpisbox || this.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT) // forbid outgoing links + || it.SUPPORT_WP) // forbid incoming links + { relink_walkculled += 0.5; + } else { if (tracewalk(this, sv, m1, m2, ev2, ev2_height, MOVE_NOMONSTERS)) @@ -1120,8 +1154,12 @@ void waypoint_think(entity this) relink_walkculled += 0.5; } - if (it.wpisbox || it.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)) + // reverse direction + if (it.wpisbox || it.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT) // forbid incoming links + || this.SUPPORT_WP) // forbid outgoing links + { relink_walkculled += 0.5; + } else { if (tracewalk(this, ev, m1, m2, sv2, sv2_height, MOVE_NOMONSTERS)) diff --git a/qcsrc/server/bot/default/waypoints.qh b/qcsrc/server/bot/default/waypoints.qh index 713f6f8d03..b418030294 100644 --- a/qcsrc/server/bot/default/waypoints.qh +++ b/qcsrc/server/bot/default/waypoints.qh @@ -43,6 +43,10 @@ float botframe_cachedwaypointlinks; .vector wpnearestpoint; +// holds reference to the support waypoint, if any +.entity goalentity; +#define SUPPORT_WP goalentity + /* * Functions */ diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index 2d87f61cd0..e599231c65 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -255,6 +255,7 @@ void ClientCommand_wpeditor(entity caller, int request, int argc) sprint(caller, " ^5spawn crosshair^7: spawns a waypoint at crosshair's position (useful to spawn custom jumppad waypoints (spawn another waypoint to create destination))\n"); sprint(caller, " ^5spawn jump^7: spawns a jump waypoint (spawn another waypoint to create destination)\n"); sprint(caller, " ^5spawn crouch^7: spawns a crouch waypoint\n"); + sprint(caller, " ^5spawn support^7: spawns a support waypoint (spawn another waypoint to create destination from which all incoming links are removed), useful to replace links to preblematic jumppad/teleport waypoints\n"); sprint(caller, " ^5hardwire^7: marks the nearest waypoint as origin of a new hardwired link (spawn another waypoint over an existing one to create destination)\n"); sprint(caller, " ^5symorigin get|set\n"); sprint(caller, " ^5symorigin get|set p1 p2 ... pX\n"); -- 2.39.2