]> 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 f5c3b9f7b9a83cf370db3033efbc05991272260f..d2d0aa15c86a2aa02399c3058fb57f6eb7668e7d 100644 (file)
@@ -350,7 +350,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
@@ -363,6 +369,29 @@ void waypoint_setupmodel(entity wp)
                wp.model = "";
 }
 
+string waypoint_get_type_name(entity wp)
+{
+       if (wp.wpflags & WAYPOINTFLAG_ITEM) return "^1Item waypoint";
+       else if (wp.wpflags & WAYPOINTFLAG_CROUCH) return "^5Crouch waypoint";
+       else if (wp.wpflags & WAYPOINTFLAG_JUMP) return "^xf80Jump waypoint";
+       else if (wp.wpflags & WAYPOINTFLAG_SUPPORT) return "^2Support waypoint";
+       else if (waypoint_has_hardwiredlinks(wp)) return "^x80fHardwired waypoint";
+       else if (wp.wpflags & WAYPOINTFLAG_LADDER) return "^3Ladder waypoint";
+       else if (wp.wpflags & WAYPOINTFLAG_TELEPORT)
+       {
+               if (!wp.wpisbox) return "^3Warpzone waypoint";
+               else if (wp.wpflags & WAYPOINTFLAG_CUSTOM_JP) return "^3Custom jumppad waypoint";
+               else
+               {
+                       IL_EACH(g_jumppads, boxesoverlap(wp.absmin, wp.absmax, it.absmin, it.absmax),
+                               { return "^3Jumppad waypoint"; });
+                       return "^3Teleport waypoint";
+               }
+       }
+
+       return "^7Waypoint";
+}
+
 entity waypoint_get(vector m1, vector m2)
 {
        if (m1 == m2)
@@ -387,7 +416,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),
                {
@@ -464,7 +493,7 @@ vector start_wp_origin;
 bool start_wp_is_hardwired;
 bool start_wp_is_support;
 
-void waypoint_clear_start_wp(entity pl, bool warn)
+void waypoint_clear_start_wp_globals(entity pl, bool warn)
 {
        start_wp_is_spawned = false;
        start_wp_origin = '0 0 0';
@@ -478,7 +507,7 @@ void waypoint_clear_start_wp(entity pl, bool warn)
 void waypoint_start_hardwiredlink(entity pl)
 {
        entity wp = pl.nearestwaypoint;
-       if ((!start_wp_is_spawned || start_wp_is_hardwired) && wp && !(wp.wpflags & WAYPOINTFLAG_NORELINK))
+       if ((!start_wp_is_spawned || start_wp_is_hardwired) && wp && !(wp.wpflags & WPFLAGMASK_NORELINK))
        {
                start_wp_is_hardwired = true;
                start_wp_is_spawned = true;
@@ -505,7 +534,7 @@ 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;
-               if (!start_wp_is_support)
+               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;
@@ -559,37 +588,27 @@ 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;
        }
-       else if (is_jump_wp)
-       {
-               entity wp_found = waypoint_get(org, org);
-               if (wp_found && !(wp_found.wpflags & WAYPOINTFLAG_JUMP))
-               {
-                       LOG_INFO("Error: can't spawn a jump waypoint over an existent waypoint of a different type\n");
-                       return;
-               }
-               e = waypoint_spawn(org, org, WAYPOINTFLAG_JUMP | WAYPOINTFLAG_NORELINK);
-               if (!pl.wp_locked)
-                       pl.wp_locked = e;
-       }
-       else if (is_support_wp)
+       else if (is_jump_wp || is_support_wp)
        {
+               int type_flag = (is_jump_wp) ? WAYPOINTFLAG_JUMP : WAYPOINTFLAG_SUPPORT;
+
                entity wp_found = waypoint_get(org, org);
-               if (wp_found && !(wp_found.wpflags & WAYPOINTFLAG_SUPPORT))
+               if (wp_found && !(wp_found.wpflags & type_flag))
                {
-                       LOG_INFO("Error: can't spawn a support waypoint over an existent waypoint of a different type\n");
+                       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, WAYPOINTFLAG_SUPPORT | WAYPOINTFLAG_NORELINK);
+               e = waypoint_spawn(org, org, type_flag);
                if (!pl.wp_locked)
                        pl.wp_locked = e;
        }
@@ -599,7 +618,7 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
        {
                LOG_INFOF("Couldn't spawn waypoint at %v\n", org);
                if (start_wp_is_spawned)
-                       waypoint_clear_start_wp(pl, true);
+                       waypoint_clear_start_wp_globals(pl, true);
                return;
        }
 
@@ -612,7 +631,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;
@@ -621,7 +640,7 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
                {
                        // should not happen
                        LOG_INFOF("Couldn't find start waypoint at %v\n", start_org);
-                       waypoint_clear_start_wp(pl, true);
+                       waypoint_clear_start_wp_globals(pl, true);
                        return;
                }
                if (start_wp_is_hardwired)
@@ -639,20 +658,20 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
                                {
                                        LOG_INFO("Error: hardwired links can be created only between 2 existing (and unconnected) waypoints.\n");
                                        waypoint_remove(e);
-                                       waypoint_clear_start_wp(pl, true);
+                                       waypoint_clear_start_wp_globals(pl, true);
                                        waypoint_spawn_fromeditor(pl, at_crosshair, is_jump_wp, is_crouch_wp, is_support_wp);
                                        return;
                                }
                                if (start_wp == e)
                                {
                                        LOG_INFO("Error: start and destination waypoints coincide.\n");
-                                       waypoint_clear_start_wp(pl, true);
+                                       waypoint_clear_start_wp_globals(pl, true);
                                        return;
                                }
                                if (waypoint_islinked(start_wp, e))
                                {
                                        LOG_INFO("Error: waypoints are already linked.\n");
-                                       waypoint_clear_start_wp(pl, true);
+                                       waypoint_clear_start_wp_globals(pl, true);
                                        return;
                                }
                                waypoint_addlink(start_wp, e);
@@ -668,7 +687,7 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
                                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);
+                                       waypoint_clear_start_wp_globals(pl, true);
                                        return;
                                }
                                // clear all links to e
@@ -685,13 +704,9 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
        if (!(jp || is_jump_wp || is_support_wp || start_wp_is_hardwired))
                waypoint_schedulerelink(e);
 
-       string wp_type_str = "Waypoint";
-       if (is_crouch_wp)               wp_type_str = "Crouch waypoint";
-       else if (is_jump_wp)    wp_type_str = "Jump waypoint";
-       else if (is_support_wp) wp_type_str = "Support waypoint";
-       else if (jp)                    wp_type_str = "Custom jumppad waypoint";
+       string wp_type_str = waypoint_get_type_name(e);
 
-       bprint(strcat(wp_type_str, " spawned at ", vtos(e.origin), "\n"));
+       bprint(strcat(wp_type_str, "^7 spawned at ", vtos(e.origin), "\n"));
 
        if (start_wp_is_spawned)
        {
@@ -742,15 +757,12 @@ void waypoint_spawn_fromeditor(entity pl, bool at_crosshair, bool is_jump_wp, bo
        }
        else if (start_wp_is_spawned)
        {
-               waypoint_clear_start_wp(pl, false);
+               waypoint_clear_start_wp_globals(pl, false);
        }
 }
 
 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)
@@ -794,13 +806,13 @@ void waypoint_remove_fromeditor(entity pl)
        if (e.wpflags & WAYPOINTFLAG_GENERATED)
        {
                if (start_wp_is_spawned)
-                       waypoint_clear_start_wp(pl, true);
+                       waypoint_clear_start_wp_globals(pl, true);
                return;
        }
 
        if (waypoint_has_hardwiredlinks(e))
        {
-               LOG_INFO("^1Warning: ^7Removal of hardwired waypoints is not allowed in the editor. Please remove links from/to this waypoint (", vtos(e.origin), ") by hand from maps/", mapname, ".waypoints.hardwired\n");
+               LOG_INFO("Can't remove a waypoint with hardwired links, remove them with \"wpeditor hardwire\" first\n");
                return;
        }
 
@@ -831,12 +843,12 @@ void waypoint_remove_fromeditor(entity pl)
        }
 
        if (start_wp_is_spawned)
-               waypoint_clear_start_wp(pl, true);
+               waypoint_clear_start_wp_globals(pl, true);
 }
 
 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;
@@ -1021,7 +1033,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)
@@ -1064,7 +1076,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);
@@ -1093,9 +1105,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
@@ -1205,7 +1217,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);
@@ -1488,7 +1500,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)))
                {
@@ -1720,7 +1732,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;
@@ -1787,6 +1799,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;
@@ -1890,7 +1904,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;
@@ -2072,11 +2086,12 @@ void botframe_showwaypointlinks()
                                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));
+                                       string wp_type_str = waypoint_get_type_name(wp);
+                                       str = sprintf("\necho Entity %d: %s^7, flags: %d, origin: %s\n", etof(wp), wp_type_str, 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));
+                                       str = sprintf("Entity %d: %s^7\nflags: %d\norigin: %s", etof(wp), wp_type_str, 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');
@@ -2146,7 +2161,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)
@@ -2244,7 +2259,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);
@@ -2340,6 +2354,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), {