]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/havocbot/havocbot.qc
Bot AI: anticipate search of a new goal when bot touches a waypoint and search time...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / havocbot / havocbot.qc
index 306f3a05e835697394474c16febcc0f9dcb01164..69549f8e356b6ece5b1fd5e145258887c34ed540 100644 (file)
@@ -138,7 +138,7 @@ void havocbot_ai(entity this)
                this.aistatus |= AI_STATUS_ROAMING;
                this.aistatus &= ~AI_STATUS_ATTACKING;
 
-               vector v, now, next;
+               vector v = '0 0 0', now, next;
                float aimdistance,skillblend,distanceblend,blend;
 
                SET_DESTCOORDS(this.goalcurrent, this.origin, v);
@@ -286,7 +286,7 @@ void havocbot_bunnyhop(entity this, vector dir)
        float bunnyhopdistance;
        vector deviation;
        float maxspeed;
-       vector gco, gno;
+       vector gco = '0 0 0', gno;
 
        // Don't jump when attacking
        if(this.aistatus & AI_STATUS_ATTACKING)
@@ -430,7 +430,8 @@ void havocbot_bunnyhop(entity this, vector dir)
 bool havocbot_checkgoaldistance(entity this, vector gco)
 {
        float curr_dist = vlen(this.origin - gco);
-       if(curr_dist > this.goalcurrent_distance)
+       float curr_dist_2d = vlen(vec2(this.origin - gco));
+       if(curr_dist > this.goalcurrent_distance && curr_dist_2d > this.goalcurrent_distance_2d)
        {
                if(!this.goalcurrent_distance_time)
                        this.goalcurrent_distance_time = time;
@@ -440,7 +441,8 @@ bool havocbot_checkgoaldistance(entity this, vector gco)
        else
        {
                // reduce it a little bit so it works even with very small approaches to the goal
-               this.goalcurrent_distance = max(20, curr_dist - 15);
+               this.goalcurrent_distance = max(20, curr_dist - 10);
+               this.goalcurrent_distance_2d = max(20, curr_dist_2d - 10);
                this.goalcurrent_distance_time = 0;
        }
        return false;
@@ -448,7 +450,7 @@ bool havocbot_checkgoaldistance(entity this, vector gco)
 
 void havocbot_movetogoal(entity this)
 {
-       vector destorg;
+       vector destorg = '0 0 0';
        vector diff;
        vector dir;
        vector flatdir;
@@ -734,23 +736,32 @@ void havocbot_movetogoal(entity this)
                                this.goalentity.bot_pickup_respawning = false;
                        else if(time < this.goalentity.scheduledrespawntime - 10) // item already taken (by someone else)
                        {
-                               this.goalentity.bot_pickup_respawning = false;
-                               navigation_clearroute(this);
-                               this.bot_strategytime = 0;
-                               return;
+                               if(checkpvs(this.origin, this.goalentity))
+                               {
+                                       this.goalentity.bot_pickup_respawning = false;
+                                       navigation_clearroute(this);
+                                       this.bot_strategytime = 0;
+                                       return;
+                               }
                        }
                        else if(this.goalentity == this.goalcurrent)
                                locked_goal = true; // wait for item to respawn
                }
-               else if(!this.goalentity.solid)
+               else if(!this.goalentity.solid && !boxesoverlap(this.goalentity.absmin, this.goalentity.absmax, this.absmin, this.absmax))
                {
-                       navigation_clearroute(this);
-                       this.bot_strategytime = 0;
-                       return;
+                       if(checkpvs(this.origin, this.goalentity))
+                       {
+                               navigation_clearroute(this);
+                               this.bot_strategytime = 0;
+                               return;
+                       }
                }
        }
        if(!locked_goal)
-               navigation_poptouchedgoals(this);
+       {
+               if(navigation_poptouchedgoals(this) && this.bot_strategytime < time + 1)
+                       this.bot_strategytime = 0;
+       }
 
        // if ran out of goals try to use an alternative goal or get a new strategy asap
        if(this.goalcurrent == NULL)
@@ -1287,7 +1298,7 @@ float havocbot_moveto(entity this, vector pos)
                        debuggoalstack(this);
 
                // Heading
-               vector dir;
+               vector dir = '0 0 0';
                SET_DESTCOORDS(this.goalcurrent, this.origin, dir);
                dir = dir - (this.origin + this.view_ofs);
                dir.z = 0;