]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/waypoints.qc
Bot waypoints: fix creation of a jump / support link from wp A to wp B breaking hardw...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / waypoints.qc
index bb53d61e02345e6af13142e2ad7e8eddbf0daa44..7a40f18e8df56f6e1eacf6e0f242b08b316ee9e6 100644 (file)
@@ -260,6 +260,13 @@ vector waypoint_getSymmetricalPoint(vector org, int ctf_flags)
        return new_org;
 }
 
+void crosshair_trace_waypoints(entity pl);
+void waypoint_lock(entity pl)
+{
+       crosshair_trace_waypoints(pl);
+       pl.wp_locked = trace_ent;
+}
+
 bool waypoint_has_hardwiredlinks(entity wp)
 {
        if (!wp)
@@ -334,6 +341,18 @@ void waypoint_unmark_hardwiredlink(entity wp_from, entity wp_to)
        return;
 }
 
+void waypoint_restore_hardwiredlinks(entity wp)
+{
+       if (wp.wphw00) waypoint_addlink(wp, wp.wphw00);
+       if (wp.wphw01) waypoint_addlink(wp, wp.wphw01);
+       if (wp.wphw02) waypoint_addlink(wp, wp.wphw02);
+       if (wp.wphw03) waypoint_addlink(wp, wp.wphw03);
+       if (wp.wphw04) waypoint_addlink(wp, wp.wphw04);
+       if (wp.wphw05) waypoint_addlink(wp, wp.wphw05);
+       if (wp.wphw06) waypoint_addlink(wp, wp.wphw06);
+       if (wp.wphw07) waypoint_addlink(wp, wp.wphw07);
+}
+
 void waypoint_setupmodel(entity wp)
 {
        if (autocvar_g_waypointeditor)
@@ -504,19 +523,40 @@ void waypoint_clear_start_wp_globals(entity pl, bool warn)
                LOG_INFO("^xf80Start waypoint has been cleared.\n");
 }
 
-void waypoint_start_hardwiredlink(entity pl)
+void waypoint_start_hardwiredlink(entity pl, bool at_crosshair)
 {
        entity wp = pl.nearestwaypoint;
-       if ((!start_wp_is_spawned || start_wp_is_hardwired) && wp && !(wp.wpflags & WPFLAGMASK_NORELINK))
+       if (at_crosshair)
+       {
+               crosshair_trace_waypoints(pl);
+               wp = trace_ent;
+       }
+       string err = "";
+       if (start_wp_is_spawned && !start_wp_is_hardwired)
+               err = "can't hardwire while in the process of creating a special link";
+       else if (!wp)
+       {
+               if (at_crosshair)
+                       err = "couldn't find any waypoint at crosshair";
+               else
+                       err = "couldn't find any waypoint nearby";
+       }
+       else if (wp.wpflags & WPFLAGMASK_NORELINK)
+               err = "can't hardwire a waypoint with special links";
+
+       if (err == "")
        {
                start_wp_is_hardwired = true;
                start_wp_is_spawned = true;
                start_wp_origin = wp.origin;
                pl.wp_locked = wp;
-               LOG_INFOF("^x80fNearest waypoint %s marked as hardwired link origin.\n", vtos(wp.origin));
+               LOG_INFOF("^x80fWaypoint %s marked as hardwired link origin.\n", vtos(wp.origin));
        }
        else
+       {
                start_wp_is_hardwired = false;
+               LOG_INFO("Error: ", err, "\n");
+       }
 }
 
 void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bool is_crouch_wp, bool is_support_wp)
@@ -532,14 +572,23 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
        vector org = pl.origin;
        if (at_crosshair)
        {
-               crosshair_trace(pl);
-               org = trace_endpos - eZ * PL_MIN_CONST.z;
+               crosshair_trace_waypoints(pl);
+               org = trace_endpos;
+               if (!trace_ent)
+                       org.z -= PL_MIN_CONST.z;
                if (!(start_wp_is_hardwired || 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 && !start_wp_is_spawned && trace_ent)
+               {
+                       if (trace_ent.wpflags & (WAYPOINTFLAG_JUMP))
+                               is_jump_wp = true;
+                       else if (trace_ent.wpflags & (WAYPOINTFLAG_SUPPORT))
+                               is_support_wp = true;
+               }
        }
        if (jp || is_jump_wp || is_support_wp)
        {
@@ -588,7 +637,7 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
        if (jp)
        {
                e = NULL;
-               IL_EACH(g_waypoints, it.wpflags & WPFLAGMASK_NORELINK
+               IL_EACH(g_waypoints, (it.wpflags & WPFLAGMASK_NORELINK)
                        && boxesoverlap(org + PL_MIN_CONST, org + PL_MAX_CONST, it.absmin, it.absmax),
                {
                        e = it; break;
@@ -631,7 +680,7 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
        entity start_wp = NULL;
        if (start_wp_is_spawned)
        {
-               IL_EACH(g_waypoints, (start_wp_is_hardwired || it.wpflags & WPFLAGMASK_NORELINK)
+               IL_EACH(g_waypoints, (start_wp_is_hardwired || (it.wpflags & WPFLAGMASK_NORELINK))
                        && boxesoverlap(start_org, start_org, it.absmin, it.absmax),
                {
                        start_wp = it; break;
@@ -830,6 +879,7 @@ void waypoint_remove_fromeditor(entity pl)
        }
 
        bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
+       te_explosion(e.origin);
        waypoint_remove(e);
 
        if (sym && wp_sym)
@@ -848,7 +898,7 @@ void waypoint_remove_fromeditor(entity pl)
 
 void waypoint_removelink(entity from, entity to)
 {
-       if (from == to || (from.wpflags & WPFLAGMASK_NORELINK && !(from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT))))
+       if (from == to || ((from.wpflags & WPFLAGMASK_NORELINK) && !(from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT))))
                return;
 
        entity fromwp31_prev = from.wp31;
@@ -977,7 +1027,7 @@ float waypoint_gettravelcost(vector from, vector to, entity from_ent, entity to_
        if (submerged_from && submerged_to)
                return waypoint_getlinearcost_underwater(vlen(to - from));
 
-       if (from_ent.wpflags & WAYPOINTFLAG_CROUCH && to_ent.wpflags & WAYPOINTFLAG_CROUCH)
+       if ((from_ent.wpflags & WAYPOINTFLAG_CROUCH) && (to_ent.wpflags & WAYPOINTFLAG_CROUCH))
                return waypoint_getlinearcost_crouched(vlen(to - from));
 
        float c = waypoint_getlinearcost(vlen(to - from));
@@ -986,7 +1036,7 @@ float waypoint_gettravelcost(vector from, vector to, entity from_ent, entity to_
        if(height > jumpheight_vec.z && autocvar_sv_gravity > 0)
        {
                float height_cost; // fall cost
-               if (boolean(from_ent.wpflags & WAYPOINTFLAG_JUMP))
+               if (from_ent.wpflags & WAYPOINTFLAG_JUMP)
                        height_cost = jumpheight_time + sqrt((height + jumpheight_vec.z) / (autocvar_sv_gravity / 2));
                else
                        height_cost = sqrt(height / (autocvar_sv_gravity / 2));
@@ -1000,7 +1050,7 @@ float waypoint_gettravelcost(vector from, vector to, entity from_ent, entity to_
                return (c + waypoint_getlinearcost_underwater(vlen(to - from))) / 2;
 
        // consider half path crouched
-       if (from_ent.wpflags & WAYPOINTFLAG_CROUCH || to_ent.wpflags & WAYPOINTFLAG_CROUCH)
+       if ((from_ent.wpflags & WAYPOINTFLAG_CROUCH) || (to_ent.wpflags & WAYPOINTFLAG_CROUCH))
                return (c + waypoint_getlinearcost_crouched(vlen(to - from))) / 2;
 
        return c;
@@ -1132,14 +1182,14 @@ void waypoint_think(entity this)
                        vector m1 = PL_MIN_CONST;
                        vector m2 = PL_MAX_CONST;
 
-                       if (this.wpflags & WAYPOINTFLAG_CROUCH || it.wpflags & WAYPOINTFLAG_CROUCH)
+                       if ((this.wpflags & WAYPOINTFLAG_CROUCH) || (it.wpflags & WAYPOINTFLAG_CROUCH))
                        {
                                m1 = PL_CROUCH_MIN_CONST;
                                m2 = PL_CROUCH_MAX_CONST;
                                // links from crouch wp to normal wp (and viceversa) are very short to avoid creating many links
                                // that would be wasted due to rough travel cost calculation (the longer link is, the higher cost is)
                                // links from crouch wp to crouch wp can be as long as normal links
-                               if (!(this.wpflags & WAYPOINTFLAG_CROUCH && it.wpflags & WAYPOINTFLAG_CROUCH))
+                               if (!((this.wpflags & WAYPOINTFLAG_CROUCH) && (it.wpflags & WAYPOINTFLAG_CROUCH)))
                                        maxdist = 100;
                        }
 
@@ -1153,7 +1203,7 @@ 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) // forbid outgoing links
+                       if (this.wpisbox || (this.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)) // forbid outgoing links
                                || it.SUPPORT_WP) // forbid incoming links
                        {
                                relink_walkculled += 0.5;
@@ -1167,7 +1217,7 @@ void waypoint_think(entity this)
                        }
 
                        // reverse direction
-                       if (it.wpisbox || it.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT) // forbid incoming links
+                       if (it.wpisbox || (it.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)) // forbid incoming links
                                || this.SUPPORT_WP) // forbid outgoing links
                        {
                                relink_walkculled += 0.5;
@@ -1181,6 +1231,11 @@ void waypoint_think(entity this)
                        }
                }
        });
+
+       // waypoint_clearlinks preserves references to old hardwired links (.wphwXX links)
+       // so they can be restored here when a wp is spawned over an existing one
+       waypoint_restore_hardwiredlinks(this);
+
        navigation_testtracewalk = 0;
        this.wplinked = true;
        this.dphitcontentsmask = dphitcontentsmask_save;
@@ -1203,6 +1258,8 @@ void waypoint_clearlinks(entity wp)
        wp.wp16mincost = wp.wp17mincost = wp.wp18mincost = wp.wp19mincost = wp.wp20mincost = wp.wp21mincost = wp.wp22mincost = wp.wp23mincost = f;
        wp.wp24mincost = wp.wp25mincost = wp.wp26mincost = wp.wp27mincost = wp.wp28mincost = wp.wp29mincost = wp.wp30mincost = wp.wp31mincost = f;
 
+       // don't remove references to hardwired links (.wphwXX fields)
+
        wp.wplinked = false;
 }
 
@@ -1503,7 +1560,7 @@ void waypoint_load_hardwiredlinks()
                        waypoint_addlink(wp_from, wp_to);
                        waypoint_mark_hardwiredlink(wp_from, wp_to);
                } else if (wp_from.wpflags & WPFLAGMASK_NORELINK
-                       && (wp_from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)
+                       && ((wp_from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT))
                                || (wp_from.wpisbox && wp_from.wpflags & WAYPOINTFLAG_TELEPORT)))
                {
                        waypoint_addlink(wp_from, wp_to);
@@ -1801,8 +1858,7 @@ float waypoint_loadall()
                if (!s)
                        break;
                fl = stof(s);
-               if (fl & WAYPOINTFLAG_NORELINK__DEPRECATED)
-                       fl &= ~WAYPOINTFLAG_NORELINK__DEPRECATED;
+               fl &= ~WAYPOINTFLAG_NORELINK__DEPRECATED;
                waypoint_spawn(m1, m2, fl);
                if (m1 == m2)
                        cwp = cwp + 1;
@@ -1815,6 +1871,7 @@ float waypoint_loadall()
 
        if (autocvar_g_waypointeditor && autocvar_g_waypointeditor_symmetrical_allowload)
        {
+               string sym_str = "";
                cvar_set("g_waypointeditor_symmetrical", ftos(sym));
                if (sym == 1 && sym_param3 < 2)
                        cvar_set("g_waypointeditor_symmetrical_order", "0"); // make sure this is reset if not loaded
@@ -1829,16 +1886,18 @@ float waypoint_loadall()
                                cvar_set("g_waypointeditor_symmetrical_origin", params);
                        }
                        cvar_set("g_waypointeditor_symmetrical_order", ftos(sym_param3));
-                       LOG_INFO("Waypoint editor: loaded symmetry ", ftos(sym), " with origin ", params, " and order ", ftos(sym_param3));
+                       sym_str = strcat(ftos(sym), " with origin ", params, " and order ", ftos(sym_param3));
                }
                else if (sym == -2)
                {
                        string params = strcat(ftos(sym_param1), " ", ftos(sym_param2));
                        cvar_set("g_waypointeditor_symmetrical_axis", params);
-                       LOG_INFO("Waypoint editor: loaded symmetry ", ftos(sym), " with axis ", params);
+                       sym_str = strcat(ftos(sym), " with axis ", params);
                }
                else
-                       LOG_INFO("Waypoint editor: loaded symmetry ", ftos(sym));
+                       sym_str = ftos(sym);
+               if (sym_str != "")
+                       LOG_INFO("Waypoint editor: loaded symmetry ", sym_str);
                LOG_INFO(strcat("g_waypointeditor_symmetrical", " has been set to ", cvar_string("g_waypointeditor_symmetrical")));
        }
 
@@ -1986,7 +2045,7 @@ void waypoint_showlink(entity wp1, entity wp2, int display_type)
        if (!(wp1 && wp2))
                return;
 
-       if (waypoint_is_hardwiredlink(wp1, wp2) || wp1.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT | WAYPOINTFLAG_CUSTOM_JP))
+       if (waypoint_is_hardwiredlink(wp1, wp2) || (wp1.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT | WAYPOINTFLAG_CUSTOM_JP)))
                te_beam(NULL, wp1.origin, wp2.origin);
        else if (display_type == 1)
                te_lightning2(NULL, wp1.origin, wp2.origin);
@@ -2029,15 +2088,18 @@ void crosshair_trace_waypoints(entity pl)
                        setsize(it, '-16 -16 -16', '16 16 16');
        });
 
-       crosshair_trace(pl);
+       WarpZone_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;
+       else if (!trace_ent.wpisbox)
+               trace_endpos = trace_ent.origin;
 }
 
 void botframe_showwaypointlinks()
@@ -2052,8 +2114,6 @@ void botframe_showwaypointlinks()
                        it.wp_aimed = NULL;
                if (wasfreed(it.wp_locked))
                        it.wp_locked = NULL;
-               if (PHYS_INPUT_BUTTON_USE(it))
-                       it.wp_locked = it.wp_aimed;
                entity head = it.wp_locked;
                if (!head)
                        head = navigation_findnearestwaypoint(it, false);