]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/navigation.qc
Fix bots waiting for a teamed item to spawn again once they got it (e.g. megas and...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / navigation.qc
index 857d6222f83a1387f8c449e8e8bca578937ff01b..d0061b90068efbcade910b2332e20c5aff9198b5 100644 (file)
@@ -1,5 +1,7 @@
 #include "navigation.qh"
 
+#include <server/defs.qh>
+#include <server/miscfunctions.qh>
 #include "cvars.qh"
 
 #include "bot.qh"
@@ -20,7 +22,7 @@ void navigation_dynamicgoal_init(entity this, bool initially_static)
        this.navigation_dynamicgoal = true;
        this.bot_basewaypoint = this.nearestwaypoint;
        if(initially_static)
-               this.nearestwaypointtimeout = time + 1000000000;
+               this.nearestwaypointtimeout = -1;
        else
                this.nearestwaypointtimeout = time;
 }
@@ -34,7 +36,7 @@ void navigation_dynamicgoal_unset(entity this)
 {
        if(this.bot_basewaypoint)
                this.nearestwaypoint = this.bot_basewaypoint;
-       this.nearestwaypointtimeout = time + 1000000000;
+       this.nearestwaypointtimeout = -1;
 }
 
 // rough simulation of walking from one point to another to test if a path
@@ -48,9 +50,9 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float m
        float dist;
        float totaldist;
        float stepdist;
-       float yaw;
        float ignorehazards;
        float swimming;
+       entity tw_ladder = NULL;
 
        if(autocvar_bot_debug_tracewalk)
        {
@@ -92,7 +94,6 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float m
        }
 
        // Movement loop
-       yaw = vectoyaw(move);
        move = end - org;
        for (;;)
        {
@@ -137,14 +138,14 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float m
                        if (trace_fraction < 1)
                        {
                                swimming = true;
-                               org = trace_endpos - normalize(org - trace_endpos) * stepdist;
+                               org = trace_endpos + normalize(org - trace_endpos) * stepdist;
                                for (; org.z < end.z + e.maxs.z; org.z += stepdist)
                                {
-                                               if(autocvar_bot_debug_tracewalk)
-                                                       debugnode(e, org);
+                                       if(autocvar_bot_debug_tracewalk)
+                                               debugnode(e, org);
 
-                                       if(pointcontents(org) == CONTENT_EMPTY)
-                                                       break;
+                                       if(pointcontents(org) == CONTENT_EMPTY)
+                                               break;
                                }
 
                                if(pointcontents(org + '0 0 1') != CONTENT_EMPTY)
@@ -182,8 +183,14 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float m
                                                if(autocvar_bot_debug_tracewalk)
                                                        debugnodestatus(trace_endpos, DEBUG_NODE_WARNING);
 
-                                               // check for doors
+                                               IL_EACH(g_ladders, it.classname == "func_ladder",
+                                                       { it.solid = SOLID_BSP; });
+
                                                traceline( org, move, movemode, e);
+
+                                               IL_EACH(g_ladders, it.classname == "func_ladder",
+                                                       { it.solid = SOLID_TRIGGER; });
+
                                                if ( trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
                                                {
                                                        vector nextmove;
@@ -195,6 +202,24 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float m
                                                                move = nextmove;
                                                        }
                                                }
+                                               else if (trace_ent.classname == "func_ladder")
+                                               {
+                                                       tw_ladder = trace_ent;
+                                                       vector ladder_bottom = trace_endpos - dir * m2.x;
+                                                       vector ladder_top = ladder_bottom;
+                                                       ladder_top.z = trace_ent.absmax.z + (-m1.z + 1);
+                                                       tracebox(ladder_bottom, m1, m2, ladder_top, movemode, e);
+                                                       if (trace_fraction < 1 || trace_startsolid)
+                                                       {
+                                                               if(autocvar_bot_debug_tracewalk)
+                                                                       debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
+
+                                                               return false; // failed
+                                                       }
+                                                       org = ladder_top + dir * m2.x;
+                                                       move = org + dir * stepdist;
+                                                       continue;
+                                               }
                                                else
                                                {
                                                        if(autocvar_bot_debug_tracewalk)
@@ -234,6 +259,16 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float m
 
                        org = trace_endpos;
                }
+
+               if(tw_ladder && org.z < tw_ladder.absmax.z)
+               {
+                       // stop tracewalk if destination height is lower than the top of the ladder
+                       // otherwise bot can't easily figure out climbing direction
+                       if(autocvar_bot_debug_tracewalk)
+                               debugnodestatus(org, DEBUG_NODE_FAIL);
+
+                       return false;
+               }
        }
 
        //print("tracewalk: ", vtos(start), " did not arrive at ", vtos(end), " but at ", vtos(org), "\n");
@@ -253,7 +288,6 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float m
 void navigation_clearroute(entity this)
 {
        //print("bot ", etos(this), " clear\n");
-       this.navigation_hasgoals = false;
        this.goalentity = NULL;
        this.goalcurrent = NULL;
        this.goalstack01 = NULL;
@@ -821,7 +855,11 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
        }
        else
        {
-               if ((!e.nearestwaypoint || e.navigation_dynamicgoal) && time > e.nearestwaypointtimeout)
+               if(autocvar_g_waypointeditor && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
+                       e.nearestwaypoint = NULL;
+
+               if ((!e.nearestwaypoint || e.navigation_dynamicgoal)
+                       && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
                {
                        nwp = navigation_findnearestwaypoint(e, true);
                        if(nwp)
@@ -842,6 +880,8 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
 
                        if(e.navigation_dynamicgoal)
                                e.nearestwaypointtimeout = time + 2;
+                       else if(autocvar_g_waypointeditor)
+                               e.nearestwaypointtimeout = time + 3 + random() * 2;
                }
                nwp = e.nearestwaypoint;
        }
@@ -866,13 +906,11 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
 // adds an item to the the goal stack with the path to a given item
 bool navigation_routetogoal(entity this, entity e, vector startposition)
 {
-       this.goalentity = e;
-
        // if there is no goal, just exit
        if (!e)
                return false;
 
-       this.navigation_hasgoals = true;
+       this.goalentity = e;
 
        // put the entity on the goal stack
        //print("routetogoal ", etos(e), "\n");
@@ -1027,7 +1065,6 @@ void navigation_goalrating_start(entity this)
 
        this.navigation_jetpack_goal = NULL;
        navigation_bestrating = -1;
-       this.navigation_hasgoals = false;
        navigation_clearroute(this);
        navigation_bestgoal = NULL;
        navigation_markroutes(this, NULL);
@@ -1043,16 +1080,13 @@ void navigation_goalrating_end(entity this)
        LOG_DEBUG("best goal ", this.goalcurrent.classname);
 
        // If the bot got stuck then try to reach the farthest waypoint
-       if (!this.navigation_hasgoals)
-       if (autocvar_bot_wander_enable)
+       if (!this.goalentity && autocvar_bot_wander_enable)
        {
                if (!(this.aistatus & AI_STATUS_STUCK))
                {
                        LOG_DEBUG(this.netname, " cannot walk to any goal");
                        this.aistatus |= AI_STATUS_STUCK;
                }
-
-               this.navigation_hasgoals = false; // Reset this value
        }
 }