]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix goal distance check not working when bot finds an obstruction above current goal
authorterencehill <piuntn@gmail.com>
Tue, 26 Sep 2017 14:30:43 +0000 (16:30 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 28 Sep 2017 00:01:04 +0000 (02:01 +0200)
qcsrc/server/bot/default/havocbot/havocbot.qc
qcsrc/server/bot/default/navigation.qc
qcsrc/server/bot/default/navigation.qh

index 56da186b82c485de22a0c65751f0566f61ab0d8b..a921a5bf9e3ddc018987c5ff10d07b3c355ccd15 100644 (file)
@@ -429,12 +429,12 @@ void havocbot_bunnyhop(entity this, vector dir)
 // return true when bot isn't getting closer to the current goal
 bool havocbot_checkgoaldistance(entity this, vector gco)
 {
-       float curr_dist = vlen(this.origin - gco);
-       float curr_dist_2d = vlen(vec2(this.origin - gco));
+       float curr_dist_z = max(20, fabs(this.origin.z - gco.z));
+       float curr_dist_2d = max(20, vlen(vec2(this.origin - gco)));
        float distance_time = this.goalcurrent_distance_time;
        if(distance_time < 0)
                distance_time = -distance_time;
-       if(curr_dist > this.goalcurrent_distance && curr_dist_2d > this.goalcurrent_distance_2d)
+       if(curr_dist_z >= this.goalcurrent_distance_z && curr_dist_2d >= this.goalcurrent_distance_2d)
        {
                if(!distance_time)
                        this.goalcurrent_distance_time = time;
@@ -444,7 +444,7 @@ 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 - 10);
+               this.goalcurrent_distance_z = max(20, curr_dist_z - 10);
                this.goalcurrent_distance_2d = max(20, curr_dist_2d - 10);
                this.goalcurrent_distance_time = 0;
        }
@@ -849,7 +849,8 @@ void havocbot_movetogoal(entity this)
                        }
 
                        // if bot for some reason doesn't get close to the current goal find another one
-                       if(!this.jumppadcount && !IS_PLAYER(this.goalcurrent) && !(this.goalcurrent.bot_pickup_respawning && this.goalcurrent_distance < 50))
+                       if(!this.jumppadcount && !IS_PLAYER(this.goalcurrent))
+                       if(!(this.goalcurrent.bot_pickup_respawning && this.goalcurrent_distance_z < 50 && this.goalcurrent_distance_2d < 50))
                        if(havocbot_checkgoaldistance(this, gco))
                        {
                                if(this.goalcurrent_distance_time < 0) // can't get close for the second time
@@ -871,7 +872,7 @@ void havocbot_movetogoal(entity this)
 
                                // give bot only another chance to prevent bot getting stuck
                                // in case it thinks it can walk but actually can't
-                               this.goalcurrent_distance = FLOAT_MAX;
+                               this.goalcurrent_distance_z = FLOAT_MAX;
                                this.goalcurrent_distance_2d = FLOAT_MAX;
                                this.goalcurrent_distance_time = -time; // mark second try
                        }
index 6c48bfd5a5bd6fdb9feeee77f2bda90cd4f4a8f7..11f78edf6f2ba9d5b59c21507ab747d7d7b57443 100644 (file)
@@ -604,7 +604,8 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float e
 void navigation_clearroute(entity this)
 {
        this.goalcurrent_prev = this.goalcurrent;
-       this.goalcurrent_distance = 10000000;
+       this.goalcurrent_distance_2d = FLOAT_MAX;
+       this.goalcurrent_distance_z = FLOAT_MAX;
        this.goalcurrent_distance_time = 0;
        //print("bot ", etos(this), " clear\n");
        this.goalentity = NULL;
@@ -651,7 +652,8 @@ void navigation_clearroute(entity this)
 void navigation_pushroute(entity this, entity e)
 {
        this.goalcurrent_prev = this.goalcurrent;
-       this.goalcurrent_distance = 10000000;
+       this.goalcurrent_distance_2d = FLOAT_MAX;
+       this.goalcurrent_distance_z = FLOAT_MAX;
        this.goalcurrent_distance_time = 0;
        //print("bot ", etos(this), " push ", etos(e), "\n");
        if(this.goalstack31 == this.goalentity)
@@ -696,7 +698,8 @@ void navigation_pushroute(entity this, entity e)
 void navigation_poproute(entity this)
 {
        this.goalcurrent_prev = this.goalcurrent;
-       this.goalcurrent_distance = 10000000;
+       this.goalcurrent_distance_2d = FLOAT_MAX;
+       this.goalcurrent_distance_z = FLOAT_MAX;
        this.goalcurrent_distance_time = 0;
        //print("bot ", etos(this), " pop\n");
        if(this.goalcurrent == this.goalentity)
index ca770f8692f4becc52a569a0e22b75983f9fd4c3..c60d3bb44dd27a102f4f1b00a8a0dc90730a1dda 100644 (file)
@@ -25,7 +25,7 @@ entity navigation_bestgoal;
 .entity goalstack28, goalstack29, goalstack30, goalstack31;
 
 .entity goalcurrent_prev;
-.float goalcurrent_distance;
+.float goalcurrent_distance_z;
 .float goalcurrent_distance_2d;
 .float goalcurrent_distance_time;