From: terencehill Date: Tue, 26 Sep 2017 14:30:43 +0000 (+0200) Subject: Fix goal distance check not working when bot finds an obstruction above current goal X-Git-Tag: xonotic-v0.8.5~2378^2~50 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=77277d7ceffdf9be4166540f1f26cb7604e3bba8;p=xonotic%2Fxonotic-data.pk3dir.git Fix goal distance check not working when bot finds an obstruction above current goal --- diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 56da186b8..a921a5bf9 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -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 } diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 6c48bfd5a..11f78edf6 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -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) diff --git a/qcsrc/server/bot/default/navigation.qh b/qcsrc/server/bot/default/navigation.qh index ca770f869..c60d3bb44 100644 --- a/qcsrc/server/bot/default/navigation.qh +++ b/qcsrc/server/bot/default/navigation.qh @@ -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;