]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/waypoints.qc
Merge branch 'master' into terencehill/bot_waypoints
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / waypoints.qc
index 2399da8ab38a5b0ce34fecf5b5438c63b4b55ae8..24f6ba8cb76b75c0cd2ed6ba80071c49c5b5a50a 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)
@@ -350,7 +357,13 @@ void waypoint_setupmodel(entity wp)
                        wp.colormod = '1 1 0'; // yellow
                else if (wp.wpflags & WAYPOINTFLAG_SUPPORT)
                        wp.colormod = '0 1 0'; // green
-               else if (wp.wpflags & WAYPOINTFLAG_NORELINK)
+               else if (wp.wpflags & WAYPOINTFLAG_CUSTOM_JP)
+                       wp.colormod = '1 0.5 0'; // orange
+               else if (wp.wpflags & WAYPOINTFLAG_TELEPORT)
+                       wp.colormod = '1 0.5 0'; // orange
+               else if (wp.wpflags & WAYPOINTFLAG_LADDER)
+                       wp.colormod = '1 0.5 0'; // orange
+               else if (wp.wpflags & WAYPOINTFLAG_JUMP)
                        wp.colormod = '1 0.5 0'; // orange
                else if (wp.wpflags & WAYPOINTFLAG_CROUCH)
                        wp.colormod = '0 1 1'; // cyan
@@ -410,7 +423,7 @@ entity waypoint_spawn(vector m1, vector m2, float f)
        // spawn only one destination waypoint for teleports teleporting player to the exact same spot
        // otherwise links loaded from file would be applied only to the first destination
        // waypoint since link format doesn't specify waypoint entities but just positions
-       if((f & WAYPOINTFLAG_GENERATED) && !(f & (WAYPOINTFLAG_NORELINK | WAYPOINTFLAG_PERSONAL)) && m1 == m2)
+       if((f & WAYPOINTFLAG_GENERATED) && !(f & (WPFLAGMASK_NORELINK | WAYPOINTFLAG_PERSONAL)) && m1 == m2)
        {
                IL_EACH(g_waypoints, boxesoverlap(m1, m2, it.absmin, it.absmax),
                {
@@ -498,19 +511,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 & WAYPOINTFLAG_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)
@@ -526,14 +560,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)
        {
@@ -582,13 +625,13 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
        if (jp)
        {
                e = NULL;
-               IL_EACH(g_waypoints, it.wpflags & WAYPOINTFLAG_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;
                });
                if (!e)
-                       e = waypoint_spawn(jp.absmin - PL_MAX_CONST + '1 1 1', jp.absmax - PL_MIN_CONST + '-1 -1 -1', WAYPOINTFLAG_TELEPORT | WAYPOINTFLAG_NORELINK);
+                       e = waypoint_spawn(jp.absmin - PL_MAX_CONST + '1 1 1', jp.absmax - PL_MIN_CONST + '-1 -1 -1', WAYPOINTFLAG_TELEPORT);
                if (!pl.wp_locked)
                        pl.wp_locked = e;
        }
@@ -602,7 +645,7 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
                        LOG_INFOF("Error: can't spawn a %s waypoint over an existent waypoint of a different type\n", (is_jump_wp) ? "Jump" : "Support");
                        return;
                }
-               e = waypoint_spawn(org, org, type_flag | WAYPOINTFLAG_NORELINK);
+               e = waypoint_spawn(org, org, type_flag);
                if (!pl.wp_locked)
                        pl.wp_locked = e;
        }
@@ -625,7 +668,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 & WAYPOINTFLAG_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;
@@ -757,9 +800,6 @@ 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)
@@ -809,7 +849,7 @@ void waypoint_remove_fromeditor(entity pl)
 
        if (waypoint_has_hardwiredlinks(e))
        {
-               LOG_INFO("Can't remove a waypoint with hardwired links, remove them with \"wpeditor hardwire\" first\n");
+               LOG_INFO("Can't remove a waypoint with hardwired links, remove links with \"wpeditor hardwire\" first\n");
                return;
        }
 
@@ -827,6 +867,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)
@@ -845,7 +886,7 @@ void waypoint_remove_fromeditor(entity pl)
 
 void waypoint_removelink(entity from, entity to)
 {
-       if (from == to || (from.wpflags & WAYPOINTFLAG_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;
@@ -1030,7 +1071,7 @@ void waypoint_addlink_customcost(entity from, entity to, float c)
 {
        if (from == to || waypoint_islinked(from, to))
                return;
-       if (c == -1 && (from.wpflags & WAYPOINTFLAG_NORELINK) && !(from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)))
+       if (c == -1 && (from.wpflags & WPFLAGMASK_NORELINK) && !(from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)))
                return;
 
        if(c == -1)
@@ -1073,7 +1114,7 @@ void waypoint_addlink_customcost(entity from, entity to, float c)
 
 void waypoint_addlink(entity from, entity to)
 {
-       if ((from.wpflags & WAYPOINTFLAG_NORELINK) && !(from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)))
+       if ((from.wpflags & WPFLAGMASK_NORELINK) && !(from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)))
                waypoint_addlink_for_custom_jumppad(from, to);
        else
                waypoint_addlink_customcost(from, to, -1);
@@ -1102,9 +1143,9 @@ void waypoint_think(entity this)
        {
                if (boxesoverlap(this.absmin, this.absmax, it.absmin, it.absmax))
                {
-                       if (!(this.wpflags & WAYPOINTFLAG_NORELINK))
+                       if (!(this.wpflags & WPFLAGMASK_NORELINK))
                                waypoint_addlink(this, it);
-                       if (!(it.wpflags & WAYPOINTFLAG_NORELINK))
+                       if (!(it.wpflags & WPFLAGMASK_NORELINK))
                                waypoint_addlink(it, this);
                }
                else
@@ -1214,7 +1255,7 @@ void waypoint_schedulerelink(entity wp)
        wp.enemy = NULL;
        if (!(wp.wpflags & WAYPOINTFLAG_PERSONAL))
                wp.owner = NULL;
-       if (!(wp.wpflags & WAYPOINTFLAG_NORELINK))
+       if (!(wp.wpflags & WPFLAGMASK_NORELINK))
                waypoint_clearlinks(wp);
        // schedule an actual relink on next frame
        setthink(wp, waypoint_think);
@@ -1466,7 +1507,8 @@ void waypoint_load_hardwiredlinks()
 
                        if(!found)
                        {
-                               LOG_INFO("NOTICE: Can not find origin waypoint for the hardwired link ", s, ". Path skipped");
+                               s = strcat(((is_special) ? "special link " : "hardwired link "), s);
+                               LOG_INFO("NOTICE: Can not find origin waypoint of the ", s, ". Path skipped");
                                continue;
                        }
                }
@@ -1487,7 +1529,8 @@ void waypoint_load_hardwiredlinks()
 
                if(!found)
                {
-                       LOG_INFO("NOTICE: Can not find destination waypoint for the hardwired link ", s, ". Path skipped");
+                       s = strcat(((is_special) ? "special link " : "hardwired link "), s);
+                       LOG_INFO("NOTICE: Can not find destination waypoint of the ", s, ". Path skipped");
                        continue;
                }
 
@@ -1497,7 +1540,7 @@ void waypoint_load_hardwiredlinks()
                {
                        waypoint_addlink(wp_from, wp_to);
                        waypoint_mark_hardwiredlink(wp_from, wp_to);
-               } else if (wp_from.wpflags & WAYPOINTFLAG_NORELINK
+               } else if (wp_from.wpflags & WPFLAGMASK_NORELINK
                        && (wp_from.wpflags & (WAYPOINTFLAG_JUMP | WAYPOINTFLAG_SUPPORT)
                                || (wp_from.wpisbox && wp_from.wpflags & WAYPOINTFLAG_TELEPORT)))
                {
@@ -1729,7 +1772,7 @@ void waypoint_saveall()
 float waypoint_loadall()
 {
        string s;
-       float file, cwp, cwb, fl;
+       int file, cwp, cwb, fl;
        vector m1, m2;
        cwp = 0;
        cwb = 0;
@@ -1796,6 +1839,8 @@ float waypoint_loadall()
                if (!s)
                        break;
                fl = stof(s);
+               if (fl & WAYPOINTFLAG_NORELINK__DEPRECATED)
+                       fl &= ~WAYPOINTFLAG_NORELINK__DEPRECATED;
                waypoint_spawn(m1, m2, fl);
                if (m1 == m2)
                        cwp = cwp + 1;
@@ -1808,6 +1853,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
@@ -1822,16 +1868,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")));
        }
 
@@ -1899,7 +1947,7 @@ void waypoint_spawnforteleporter_boxes(entity e, int teleport_flag, vector org1,
 {
        entity w;
        entity dw;
-       w = waypoint_spawn(org1, org2, WAYPOINTFLAG_GENERATED | teleport_flag | WAYPOINTFLAG_NORELINK);
+       w = waypoint_spawn(org1, org2, WAYPOINTFLAG_GENERATED | teleport_flag);
        dw = waypoint_spawn(destination1, destination2, WAYPOINTFLAG_GENERATED);
        // one way link to the destination
        w.wp00_original = dw;
@@ -2022,15 +2070,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()
@@ -2045,8 +2096,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);
@@ -2156,7 +2205,7 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en
                }
 
                float bestdist = maxdist;
-               IL_EACH(g_waypoints, it != wp && !(it.wpflags & WAYPOINTFLAG_NORELINK),
+               IL_EACH(g_waypoints, it != wp && !(it.wpflags & WPFLAGMASK_NORELINK),
                {
                        float d = vlen(wp.origin - it.origin) + vlen(it.origin - porg);
                        if(d < bestdist)
@@ -2254,7 +2303,6 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en
 }
 
 // automatically create missing waypoints
-.entity botframe_autowaypoints_lastwp0, botframe_autowaypoints_lastwp1;
 void botframe_autowaypoints_fix(entity p, float walkfromwp, .entity fld)
 {
        float r = botframe_autowaypoints_fix_from(p, walkfromwp, p.(fld), fld);
@@ -2350,6 +2398,8 @@ LABEL(next)
        });
 }
 
+//.entity botframe_autowaypoints_lastwp0;
+.entity botframe_autowaypoints_lastwp1;
 void botframe_autowaypoints()
 {
        FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && !IS_DEAD(it), {