]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/navigation.qc
Merge branch 'terencehill/bot_waypoints' into terencehill/bot_ai
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / navigation.qc
index 8e326fe1bb32297d338332c4847aed73fc50f3f8..3754897bda3fe5ff2554409d318933ad3e11e38a 100644 (file)
@@ -95,8 +95,8 @@ vector get_closer_dest(entity ent, vector org)
        vector dest = '0 0 0';
        if ((ent.classname != "waypoint") || ent.wpisbox)
        {
-               vector wm1 = ent.origin + ent.mins - eZ * (PL_MAX_CONST.z - 1);
-               vector wm2 = ent.origin + ent.maxs - eZ * (PL_MIN_CONST.z + 1);
+               vector wm1 = ent.origin + ent.mins;
+               vector wm2 = ent.origin + ent.maxs;
                dest.x = bound(wm1.x, org.x, wm2.x);
                dest.y = bound(wm1.y, org.y, wm2.y);
                dest.z = bound(wm1.z, org.z, wm2.z);
@@ -110,8 +110,8 @@ void set_tracewalk_dest(entity ent, vector org, bool fix_player_dest)
 {
        if ((ent.classname != "waypoint") || ent.wpisbox)
        {
-               vector wm1 = ent.origin + ent.mins - eZ * (PL_MAX_CONST.z - 1);
-               vector wm2 = ent.origin + ent.maxs - eZ * (PL_MIN_CONST.z + 1);
+               vector wm1 = ent.origin + ent.mins;
+               vector wm2 = ent.origin + ent.maxs;
                if (IS_PLAYER(ent) || IS_MONSTER(ent))
                {
                        // move destination point out of player bbox otherwise tracebox always fails
@@ -159,8 +159,8 @@ vector set_tracewalk_dest_2(entity ent, vector org)
        vector closer_dest = '0 0 0';
        if ((ent.classname != "waypoint") || ent.wpisbox)
        {
-               vector wm1 = ent.origin + ent.mins - eZ * (PL_MAX_CONST.z - 1);
-               vector wm2 = ent.origin + ent.maxs - eZ * (PL_MIN_CONST.z + 1);
+               vector wm1 = ent.origin + ent.mins;
+               vector wm2 = ent.origin + ent.maxs;
                closer_dest.x = bound(wm1.x, org.x, wm2.x);
                closer_dest.y = bound(wm1.y, org.y, wm2.y);
                closer_dest.z = bound(wm1.z, org.z, wm2.z);
@@ -1474,13 +1474,21 @@ bool navigation_routetogoal(entity this, entity e, vector startposition)
                // often path can be optimized by not adding the nearest waypoint
                if (this.goalentity.navigation_dynamicgoal || autocvar_g_waypointeditor)
                {
-                       set_tracewalk_dest(this.goalentity, nearest_wp.enemy.origin, true);
-                       if (trace_ent == this || (vdist(tracewalk_dest - nearest_wp.enemy.origin, <, 1050)
-                               && vlen2(tracewalk_dest - nearest_wp.enemy.origin) < vlen2(nearest_wp.origin - nearest_wp.enemy.origin)
-                               && tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this),
-                               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode)))
+                       if (nearest_wp.enemy.wpcost < autocvar_bot_ai_strategyinterval_movingtarget)
                        {
-                               e = nearest_wp.enemy;
+                               if (vdist(vec2(this.goalentity.origin - nearest_wp.origin), <, 32))
+                                       e = nearest_wp.enemy;
+                               else
+                               {
+                                       set_tracewalk_dest(this.goalentity, nearest_wp.enemy.origin, true);
+                                       if (trace_ent == this || (vdist(tracewalk_dest - nearest_wp.enemy.origin, <, 1050)
+                                               && vlen2(tracewalk_dest - nearest_wp.enemy.origin) < vlen2(nearest_wp.origin - nearest_wp.enemy.origin)
+                                               && tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this),
+                                               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode)))
+                                       {
+                                               e = nearest_wp.enemy;
+                                       }
+                               }
                        }
                }
                else if(navigation_item_islinked(nearest_wp.enemy, this.goalentity))
@@ -1587,6 +1595,12 @@ int navigation_poptouchedgoals(entity this)
                if(this.lastteleporttime > 0
                        && time - this.lastteleporttime < ((this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL) ? 2 : 0.15))
                {
+                       if (this.jumppadcount && !boxesoverlap(this.goalcurrent.absmin, this.goalcurrent.absmax,
+                               this.lastteleport_origin + STAT(PL_MIN, this), this.lastteleport_origin + STAT(PL_MAX, this)))
+                       {
+                               return;
+                       }
+
                        if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
                        if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
                        {
@@ -1658,10 +1672,16 @@ int navigation_poptouchedgoals(entity this)
 entity navigation_get_really_close_waypoint(entity this)
 {
        entity wp = this.goalcurrent;
-       if(!wp || vdist(wp.origin - this.origin, >, 50))
+       if(!wp)
                wp = this.goalcurrent_prev;
        if(!wp)
                return NULL;
+       if(wp != this.goalcurrent_prev && vdist(wp.origin - this.origin, >, 50))
+       {
+               wp = this.goalcurrent_prev;
+               if(!wp)
+                       return NULL;
+       }
        if(wp.classname != "waypoint")
        {
                wp = wp.nearestwaypoint;
@@ -1670,6 +1690,7 @@ entity navigation_get_really_close_waypoint(entity this)
        }
        if(vdist(wp.origin - this.origin, >, 50))
        {
+               wp = NULL;
                IL_EACH(g_waypoints, !(it.wpflags & WAYPOINTFLAG_TELEPORT),
                {
                        if(vdist(it.origin - this.origin, <, 50))
@@ -1678,6 +1699,8 @@ entity navigation_get_really_close_waypoint(entity this)
                                break;
                        }
                });
+               if(!wp)
+                       return NULL;
        }
        if(wp.wpflags & WAYPOINTFLAG_TELEPORT)
                return NULL;