]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make bots head to coords of destination entity closer to bot's origin instead of...
authorterencehill <piuntn@gmail.com>
Sat, 10 Jun 2017 01:11:22 +0000 (03:11 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 10 Jun 2017 01:11:22 +0000 (03:11 +0200)
qcsrc/server/bot/default/havocbot/havocbot.qc
qcsrc/server/bot/default/navigation.qh

index 8bbe349193c1b4272e5dea9250d622c0af6e9c7d..06cf57992f5b707dc24711f2ecd166891ac183dc 100644 (file)
@@ -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);
 
index f1fcae0fc4c723b14cfef48a6a594859ab831bc9..4731e67babc016531af00b91e5592d761dad5832 100644 (file)
@@ -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 { \