]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
If for some reason bot doesn't get close to the current goal find another one. It...
authorterencehill <piuntn@gmail.com>
Thu, 16 Feb 2017 00:57:50 +0000 (01:57 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 16 Feb 2017 01:03:45 +0000 (02:03 +0100)
qcsrc/server/bot/default/havocbot/havocbot.qc

index 17f3a80b3f48db0cdb5b73b56e279788a34833b7..db5d635b4a481b90025d7c67f5050d5ab5bd5a89 100644 (file)
@@ -419,6 +419,9 @@ void havocbot_bunnyhop(entity this, vector dir)
 #endif
 }
 
+.entity goalcurrent_prev;
+.float goalcurrent_distance;
+.float goalcurrent_distance_time;
 void havocbot_movetogoal(entity this)
 {
        vector destorg;
@@ -783,6 +786,36 @@ void havocbot_movetogoal(entity this)
                                }
                        }
 
+                       // if bot for some reason doesn't get close to the current goal find another one
+                       float curr_dist = vlen(this.origin - this.goalcurrent.origin);
+                       if(this.goalcurrent != this.goalcurrent_prev)
+                       {
+                               this.goalcurrent_prev = this.goalcurrent;
+                               this.goalcurrent_distance = curr_dist;
+                               this.goalcurrent_distance_time = 0;
+                       }
+                       else if(curr_dist > this.goalcurrent_distance)
+                       {
+                               if(!this.goalcurrent_distance_time)
+                                       this.goalcurrent_distance_time = time;
+                               else if (time - this.goalcurrent_distance_time > 0.5)
+                               {
+                                       if(IS_ONGROUND(this))
+                                       {
+                                               this.goalcurrent_prev = NULL;
+                                               navigation_clearroute(this);
+                                               this.bot_strategytime = 0;
+                                               return;
+                                       }
+                               }
+                       }
+                       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_time = 0;
+                       }
+
                        // avoiding dangers and obstacles
                        offset = (vdist(this.velocity - eZ * this.velocity.z, >, 32) ? this.velocity * 0.5 : v_forward * 32);
                        vector dst_ahead = this.origin + offset;