]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/waypoints.qc
Bot waypoints: allow to lock the currently aimed waypoint with the use key (keeping...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / waypoints.qc
index 8fc4829a5d2a4bfb75084619c7c8c9feb376f764..65a75e304b6d575026aecc9a4a121301fe20d51b 100644 (file)
@@ -363,16 +363,16 @@ void waypoint_removelink(entity from, entity to)
        switch (waypoint_getlinknum(from, to))
        {
                // fallthrough all the way
-               case 00: from.wp00 = from.wp01; from.wp00mincost = from.wp01mincost;
-               case 01: from.wp01 = from.wp02; from.wp01mincost = from.wp02mincost;
-               case 02: from.wp02 = from.wp03; from.wp02mincost = from.wp03mincost;
-               case 03: from.wp03 = from.wp04; from.wp03mincost = from.wp04mincost;
-               case 04: from.wp04 = from.wp05; from.wp04mincost = from.wp05mincost;
-               case 05: from.wp05 = from.wp06; from.wp05mincost = from.wp06mincost;
-               case 06: from.wp06 = from.wp07; from.wp06mincost = from.wp07mincost;
-               case 07: from.wp07 = from.wp08; from.wp07mincost = from.wp08mincost;
-               case 08: from.wp08 = from.wp09; from.wp08mincost = from.wp09mincost;
-               case 09: from.wp09 = from.wp10; from.wp09mincost = from.wp10mincost;
+               case  0: from.wp00 = from.wp01; from.wp00mincost = from.wp01mincost;
+               case  1: from.wp01 = from.wp02; from.wp01mincost = from.wp02mincost;
+               case  2: from.wp02 = from.wp03; from.wp02mincost = from.wp03mincost;
+               case  3: from.wp03 = from.wp04; from.wp03mincost = from.wp04mincost;
+               case  4: from.wp04 = from.wp05; from.wp04mincost = from.wp05mincost;
+               case  5: from.wp05 = from.wp06; from.wp05mincost = from.wp06mincost;
+               case  6: from.wp06 = from.wp07; from.wp06mincost = from.wp07mincost;
+               case  7: from.wp07 = from.wp08; from.wp07mincost = from.wp08mincost;
+               case  8: from.wp08 = from.wp09; from.wp08mincost = from.wp09mincost;
+               case  9: from.wp09 = from.wp10; from.wp09mincost = from.wp10mincost;
                case 10: from.wp10 = from.wp11; from.wp10mincost = from.wp11mincost;
                case 11: from.wp11 = from.wp12; from.wp11mincost = from.wp12mincost;
                case 12: from.wp12 = from.wp13; from.wp12mincost = from.wp13mincost;
@@ -403,9 +403,9 @@ void waypoint_removelink(entity from, entity to)
 
 int waypoint_getlinknum(entity from, entity to)
 {
-       if (from.wp00 == to) return 00; if (from.wp01 == to) return 01; if (from.wp02 == to) return 02; if (from.wp03 == to) return 03;
-       if (from.wp04 == to) return 04; if (from.wp05 == to) return 05; if (from.wp06 == to) return 06; if (from.wp07 == to) return 07;
-       if (from.wp08 == to) return 08; if (from.wp09 == to) return 09; if (from.wp10 == to) return 10; if (from.wp11 == to) return 11;
+       if (from.wp00 == to) return  0; if (from.wp01 == to) return  1; if (from.wp02 == to) return  2; if (from.wp03 == to) return  3;
+       if (from.wp04 == to) return  4; if (from.wp05 == to) return  5; if (from.wp06 == to) return  6; if (from.wp07 == to) return  7;
+       if (from.wp08 == to) return  8; if (from.wp09 == to) return  9; if (from.wp10 == to) return 10; if (from.wp11 == to) return 11;
        if (from.wp12 == to) return 12; if (from.wp13 == to) return 13; if (from.wp14 == to) return 14; if (from.wp15 == to) return 15;
        if (from.wp16 == to) return 16; if (from.wp17 == to) return 17; if (from.wp18 == to) return 18; if (from.wp19 == to) return 19;
        if (from.wp20 == to) return 20; if (from.wp21 == to) return 21; if (from.wp22 == to) return 22; if (from.wp23 == to) return 23;
@@ -1401,6 +1401,25 @@ void waypoint_showlinks_from(entity wp, int display_type)
        waypoint_showlink(wp.wp15, wp, display_type); waypoint_showlink(wp.wp31, wp, display_type);
 }
 
+void crosshair_trace_waypoints(entity pl)
+{
+       IL_EACH(g_waypoints, true, {
+               it.solid = SOLID_BSP;
+               if (!it.wpisbox)
+                       setsize(it, '-16 -16 -16', '16 16 16');
+       });
+
+       crosshair_trace(pl);
+
+       IL_EACH(g_waypoints, true, {
+               it.solid = SOLID_TRIGGER;
+               if (!it.wpisbox)
+                       setsize(it, '0 0 0', '0 0 0');
+       });
+       if (trace_ent.classname != "waypoint")
+               trace_ent = NULL;
+}
+
 void botframe_showwaypointlinks()
 {
        if (time < botframe_waypointeditorlightningtime)
@@ -1409,10 +1428,14 @@ void botframe_showwaypointlinks()
        FOREACH_CLIENT(IS_PLAYER(it) && !it.isbot,
        {
                int display_type = 0;
-               entity head = navigation_findnearestwaypoint(it, false);
+               if (PHYS_INPUT_BUTTON_USE(it))
+                       it.wp_locked = it.wp_aimed;
+               entity head = it.wp_locked;
+               if (!head)
+                       head = navigation_findnearestwaypoint(it, false);
                it.nearestwaypoint = head; // mainly useful for debug
                it.nearestwaypointtimeout = time + 2; // while I'm at it...
-               if (IS_ONGROUND(it) || it.waterlevel > WATERLEVEL_NONE)
+               if (IS_ONGROUND(it) || it.waterlevel > WATERLEVEL_NONE || it.wp_locked)
                        display_type = 1; // default
                else if(head && (head.wphardwired))
                        display_type = 2; // only hardwired
@@ -1431,6 +1454,29 @@ void botframe_showwaypointlinks()
                                        waypoint_showlinks_from(head, display_type);
                        }
                }
+               string str;
+               entity wp = NULL;
+               if (vdist(vec2(it.velocity), <, autocvar_sv_maxspeed * 1.1))
+               {
+                       crosshair_trace_waypoints(it);
+                       if (trace_ent)
+                       {
+                               wp = trace_ent;
+                               if (wp != it.wp_aimed)
+                               {
+                                       str = sprintf("\necho ^2WP info^7: entity: %d, flags: %d, origin: '%s'\n", etof(wp), wp.wpflags, vtos(wp.origin));
+                                       if (wp.wpisbox)
+                                               str = strcat(str, sprintf("echo \" absmin: '%s', absmax: '%s'\"\n", vtos(wp.absmin), vtos(wp.absmax)));
+                                       stuffcmd(it, str);
+                                       str = sprintf("entity: %d\nflags: %d\norigin: \'%s\'", etof(wp), wp.wpflags, vtos(wp.origin));
+                                       if (wp.wpisbox)
+                                               str = strcat(str, sprintf(" \nabsmin: '%s'\nabsmax: '%s'", vtos(wp.absmin), vtos(wp.absmax)));
+                                       debug_text_3d(wp.origin, str, 0, 7, '0 0 0');
+                               }
+                       }
+               }
+               if (it.wp_aimed != wp)
+                       it.wp_aimed = wp;
        });
 }