]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Bot waypoints: remove all incoming links from waypoints with a support waypoint;...
authorterencehill <piuntn@gmail.com>
Sun, 21 Jul 2019 16:07:14 +0000 (18:07 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 21 Jul 2019 16:07:14 +0000 (18:07 +0200)
qcsrc/server/bot/default/navigation.qh
qcsrc/server/bot/default/waypoints.qc
qcsrc/server/bot/default/waypoints.qh
qcsrc/server/command/cmd.qc

index 73df40451918f414f8945b854eb879c2662f9580..026d326b9e6fba8524b95a73862eb284e3f06d86 100644 (file)
@@ -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;
 
index a8890519dbd72e5e0700923cbc996a4b03c4ece1..f5c3b9f7b9a83cf370db3033efbc05991272260f 100644 (file)
@@ -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))
index 713f6f8d03ffde1dcbd1cb575517480be3af150c..b418030294faddb2901c158e5e1459ea2d72aec5 100644 (file)
@@ -43,6 +43,10 @@ float botframe_cachedwaypointlinks;
 
 .vector wpnearestpoint;
 
+// holds reference to the support waypoint, if any
+.entity goalentity;
+#define SUPPORT_WP goalentity
+
 /*
  * Functions
  */
index 2d87f61cd066f47f85220253bce59cdb0420edef..e599231c6586d80acb81c44c15c2ec18b956f53e 100644 (file)
@@ -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");