]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/navigation.qc
Merge branch 'Mario/bd_tweak' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / navigation.qc
index d6bb2195f64ea9d4a3248f88bc5ec2f55e668f6f..2cfc6d33a83189009a866fbd8e7a690636e7eab4 100644 (file)
@@ -232,6 +232,7 @@ void navigation_clearroute(entity this)
 {
        //print("bot ", etos(this), " clear\n");
        this.navigation_hasgoals = false;
+       this.goalentity = NULL;
        this.goalcurrent = NULL;
        this.goalstack01 = NULL;
        this.goalstack02 = NULL;
@@ -275,6 +276,8 @@ void navigation_clearroute(entity this)
 void navigation_pushroute(entity this, entity e)
 {
        //print("bot ", etos(this), " push ", etos(e), "\n");
+       if(this.goalstack31 == this.goalentity)
+               this.goalentity = NULL;
        this.goalstack31 = this.goalstack30;
        this.goalstack30 = this.goalstack29;
        this.goalstack29 = this.goalstack28;
@@ -315,6 +318,8 @@ void navigation_pushroute(entity this, entity e)
 void navigation_poproute(entity this)
 {
        //print("bot ", etos(this), " pop\n");
+       if(this.goalcurrent == this.goalentity)
+               this.goalentity = NULL;
        this.goalcurrent = this.goalstack01;
        this.goalstack01 = this.goalstack02;
        this.goalstack02 = this.goalstack03;
@@ -643,15 +648,54 @@ void navigation_markroutes_inverted(entity fixed_source_waypoint)
 // updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
 void navigation_routerating(entity this, entity e, float f, float rangebias)
 {
-       entity nwp;
-       vector o;
        if (!e)
                return;
 
        if(e.blacklisted)
                return;
 
-       o = (e.absmin + e.absmax) * 0.5;
+       if (IS_PLAYER(e))
+       {
+               bool rate_wps = false;
+               if((e.flags & FL_INWATER) || (e.flags & FL_PARTIALGROUND))
+                       rate_wps = true;
+
+               if(!IS_ONGROUND(e))
+               {
+                       traceline(e.origin, e.origin + '0 0 -1500', true, NULL);
+                       int t = pointcontents(trace_endpos + '0 0 1');
+                       if(t != CONTENT_SOLID )
+                       {
+                               if(t == CONTENT_WATER || t == CONTENT_SLIME || t == CONTENT_LAVA)
+                                       rate_wps = true;
+                               else if(tracebox_hits_trigger_hurt(e.origin, e.mins, e.maxs, trace_endpos))
+                                       return;
+                       }
+               }
+
+               if(rate_wps)
+               {
+                       entity theEnemy = e;
+                       entity best_wp = NULL;
+                       float best_dist = 10000;
+                       IL_EACH(g_waypoints, vdist(it.origin - theEnemy.origin, <, 500)
+                               && vdist(it.origin - this.origin, >, 100)
+                               && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
+                       {
+                               float dist = vlen(it.origin - theEnemy.origin);
+                               if (dist < best_dist)
+                               {
+                                       best_wp = it;
+                                       best_dist = dist;
+                               }
+                       });
+                       if (!best_wp)
+                               return;
+                       e = best_wp;
+               }
+       }
+
+       vector o = (e.absmin + e.absmax) * 0.5;
 
        //print("routerating ", etos(e), " = ", ftos(f), " - ", ftos(rangebias), "\n");
 
@@ -744,6 +788,7 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
                }
        }
 
+       entity nwp;
        //te_wizspike(e.origin);
        //bprint(etos(e));
        //bprint("\n");
@@ -837,6 +882,12 @@ bool navigation_routetogoal(entity this, entity e, vector startposition)
        //print("routetogoal ", etos(e), "\n");
        navigation_pushroute(this, e);
 
+       if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
+       {
+               this.wp_goal_prev1 = this.wp_goal_prev0;
+               this.wp_goal_prev0 = e;
+       }
+
        if(g_jetpack)
        if(e==this.navigation_jetpack_goal)
                return true;
@@ -876,9 +927,6 @@ void navigation_poptouchedgoals(entity this)
        m1 = org + this.mins;
        m2 = org + this.maxs;
 
-       while(this.goalcurrent && wasfreed(this.goalcurrent))
-               navigation_poproute(this);
-
        if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
        {
                // make sure jumppad is really hit, don't rely on distance based checks
@@ -897,13 +945,6 @@ void navigation_poptouchedgoals(entity this)
                }
        }
 
-       if(this.goalcurrent.bot_pickup_respawning)
-       {
-               if(!this.goalcurrent.solid)
-                       return;
-               this.goalcurrent.bot_pickup_respawning = false;
-       }
-
        // If for some reason the bot is closer to the next goal, pop the current one
        if(this.goalstack01 && !wasfreed(this.goalstack01))
        if(vlen2(this.goalcurrent.origin - this.origin) > vlen2(this.goalstack01.origin - this.origin))
@@ -920,16 +961,11 @@ void navigation_poptouchedgoals(entity this)
                // personality property
        }
 
-       // HACK: remove players/bots as goals, they can lead a bot to unexpected places (cliffs, lava, etc)
-       // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
-       if(IS_PLAYER(this.goalcurrent))
-               navigation_poproute(this);
-
        // Loose goal touching check when running
        if(this.aistatus & AI_STATUS_RUNNING)
-       if(this.speed >= autocvar_sv_maxspeed) // if -really- running
        if(this.goalcurrent.classname=="waypoint")
        if(!(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT))
+       if(vlen(this.velocity - eZ * this.velocity.z) >= autocvar_sv_maxspeed) // if -really- running
        {
                if(vdist(this.origin - this.goalcurrent.origin, <, 150))
                {
@@ -949,8 +985,18 @@ void navigation_poptouchedgoals(entity this)
                }
        }
 
-       while (this.goalcurrent && boxesoverlap(m1, m2, this.goalcurrent.absmin, this.goalcurrent.absmax))
+       while (this.goalcurrent && !IS_PLAYER(this.goalcurrent))
        {
+               vector gc_min = this.goalcurrent.absmin;
+               vector gc_max = this.goalcurrent.absmax;
+               if(this.goalcurrent.classname == "waypoint")
+               {
+                       gc_min = this.goalcurrent.origin - '1 1 1' * 12;
+                       gc_max = this.goalcurrent.origin + '1 1 1' * 12;
+               }
+               if(!boxesoverlap(m1, m2, gc_min, gc_max))
+                       break;
+
                if((this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT))
                        break;