From: terencehill Date: Sat, 10 Jun 2017 01:11:22 +0000 (+0200) Subject: Make bots head to coords of destination entity closer to bot's origin instead of... X-Git-Tag: xonotic-v0.8.5~2378^2~131 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2c9d00aef58a46268df4bf80a101cf6a90447fc4;p=xonotic%2Fxonotic-data.pk3dir.git Make bots head to coords of destination entity closer to bot's origin instead of destination entity's center coords, so they match the ones used by tracewalk to link waypoints. It actually fixes bot bumping into borders of certain teleports / jumppads when it heads to them with odd angles (e.g. heading to a Darkzone teleport from one side) --- diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 8bbe34919..06cf57992 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -44,7 +44,6 @@ void havocbot_ai(entity this) this.havocbot_role(this); // little too far down the rabbit hole } - // TODO: tracewalk() should take care of this job (better path finding under water) // if we don't have a goal and we're under water look for a waypoint near the "shore" and push it if(!(IS_DEAD(this) || STAT(FROZEN, this))) if(!this.goalcurrent) @@ -139,7 +138,9 @@ void havocbot_ai(entity this) vector now,v,next;//,heading; float aimdistance,skillblend,distanceblend,blend; - next = now = ( (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5) - (this.origin + this.view_ofs); + + SET_DESTCOORDS(this.goalcurrent, this.origin, now); + next = now = now - (this.origin + this.view_ofs); aimdistance = vlen(now); //heading = this.velocity; //dprint(this.goalstack01.classname,etos(this.goalstack01),"\n"); @@ -306,7 +307,7 @@ void havocbot_bunnyhop(entity this, vector dir) this.bot_timelastseengoal = 0; } - gco = (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5; + SET_DESTCOORDS(this.goalcurrent, this.origin, gco); bunnyhopdistance = vlen(this.origin - gco); // Run only to visible goals @@ -439,8 +440,6 @@ void havocbot_movetogoal(entity this) vector diff; vector dir; vector flatdir; - vector m1; - vector m2; vector evadeobstacle; vector evadelava; float maxspeed; @@ -752,12 +751,7 @@ void havocbot_movetogoal(entity this) if(autocvar_bot_debug_goalstack) debuggoalstack(this); - m1 = this.goalcurrent.origin + this.goalcurrent.mins; - m2 = this.goalcurrent.origin + this.goalcurrent.maxs; - destorg = this.origin; - destorg.x = bound(m1_x, destorg.x, m2_x); - destorg.y = bound(m1_y, destorg.y, m2_y); - destorg.z = bound(m1_z, destorg.z, m2_z); + SET_DESTCOORDS(this.goalcurrent, this.origin, destorg); // in case bot ends up inside the teleport waypoint without touching // the teleport itself, head to the teleport origin @@ -1284,7 +1278,9 @@ float havocbot_moveto(entity this, vector pos) debuggoalstack(this); // Heading - vector dir = ( ( this.goalcurrent.absmin + this.goalcurrent.absmax ) * 0.5 ) - (this.origin + this.view_ofs); + vector dir; + SET_DESTCOORDS(this.goalcurrent, this.origin, dir); + dir = dir - (this.origin + this.view_ofs); dir.z = 0; bot_aimdir(this, dir, -1); diff --git a/qcsrc/server/bot/default/navigation.qh b/qcsrc/server/bot/default/navigation.qh index f1fcae0fc..4731e67ba 100644 --- a/qcsrc/server/bot/default/navigation.qh +++ b/qcsrc/server/bot/default/navigation.qh @@ -48,6 +48,20 @@ entity navigation_bestgoal; #define navigation_item_addlink(from_wp, to_item) \ waypoint_addlink_customcost(to_item, from_wp, waypoint_getlinkcost(from_wp, to_item)) +// if ent is a box waypoint or an item v is set to coords of ent that are closer to org +// (but v.z is set to the middle coord of ent) +#define SET_DESTCOORDS(ent, org, v) MACRO_BEGIN { \ + if ((ent.classname != "waypoint") || ent.wpisbox) { \ + vector wm1 = ent.origin + ent.mins; \ + vector wm2 = ent.origin + ent.maxs; \ + v.x = bound(wm1.x, org.x, wm2.x); \ + v.y = bound(wm1.y, org.y, wm2.y); \ + v.z = (wm2.z - wm1.z) / 2; \ + } else { \ + v = ent.origin; \ + } \ +} MACRO_END + // if ent is a box waypoint or an item v is set to coords of ent that are closer to org // (but v.z is set to the lowest coord of ent), v_height is set to ent's height #define SET_TRACEWALK_DESTCOORDS(ent, org, v, v_height) MACRO_BEGIN { \