]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
initial auto WP mode
authorRudolf Polzer <divverent@xonotic.org>
Sun, 28 Aug 2011 16:23:26 +0000 (18:23 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Sun, 28 Aug 2011 16:23:26 +0000 (18:23 +0200)
qcsrc/server/bot/bot.qc
qcsrc/server/bot/waypoints.qc
qcsrc/server/bot/waypoints.qh

index 94a17d8f1494b34573bef5a15bf98c6d0c6224e4..c9a54c7f6a79100f2a63323260d00369cd7e0aa2 100644 (file)
@@ -674,6 +674,9 @@ void bot_serverframe()
        if (autocvar_g_waypointeditor)
                botframe_showwaypointlinks();
 
+       if (autocvar_g_waypointeditor_auto)
+               botframe_autowaypoints();
+
        if(time > bot_cvar_nextthink)
        {
                if(currentbots>0)
index 8aea49be512d0b6f7dfd42e8b5d40f73585ef73f..eb08b38c5d68db83ff35bb2bed7a0492161b61ac 100644 (file)
@@ -876,3 +876,71 @@ void botframe_showwaypointlinks()
                player = find(player, classname, "player");
        }
 };
+
+// automatically create missing waypoints
+.float lastwaypointtime0;
+.float lastwaypointtime1;
+void botframe_autowaypoints_fix(entity p, float walkfromwp, .float last)
+{
+       float t;
+       entity wp;
+       vector o;
+       float tmin, tmax;
+       vector save;
+       
+       wp = navigation_findnearestwaypoint(p, walkfromwp);
+       if(wp)
+               return;
+
+       tmin = 0;
+       tmax = 1;
+       for(;;)
+       {
+               t = (tmin + tmax) * 0.5;
+               o = antilag_takebackorigin(p, time - t);
+               save = p.origin;
+               setorigin(p, o);
+               wp = navigation_findnearestwaypoint(p, walkfromwp);
+               setorigin(p, save);
+               if(wp)
+               {
+                       if(walkfromwp)
+                       {
+                               if(tracewalk(p, o, PL_MIN, PL_MAX, p.origin, bot_navigation_movemode))
+                                       break;
+                       }
+                       else
+                       {
+                               if(tracewalk(p, p.origin, PL_MIN, PL_MAX, o, bot_navigation_movemode))
+                                       break;
+                       }
+                       // if we get here: o has a nearest waypoint, but can't reach us
+                       // i.e. move towards current location
+                       tmax = t;
+               }
+               else
+               {
+                       // if we get here: o has no nearest waypoint
+                       // i.e. move closer to to the past
+                       tmin = t;
+               }
+               if(tmax - tmin < 0.01)
+               {
+                       print("Cannot link waypoints - didn't find a good new WP position\n");
+                       return;
+               }
+       }
+
+       waypoint_schedulerelink(waypoint_spawn(o, o, 0));
+       p.last = max(1, time - t);
+}
+void botframe_autowaypoints()
+{
+       entity p;
+       entity wp0, wp1;
+       FOR_EACH_REALPLAYER(p)
+       {
+               botframe_autowaypoints_fix(p, FALSE, lastwaypointtime0);
+               botframe_autowaypoints_fix(p, TRUE, lastwaypointtime1);
+       }
+}
index 9c84de84bb5132085cb8e32bf3c3e12f13f4789a..17e1f4e98437e49d13d300ee0374108e10c9fe3a 100644 (file)
@@ -57,3 +57,5 @@ entity waypoint_spawn(vector m1, vector m2, float f);
 entity waypoint_spawnpersonal(vector position);
 
 vector waypoint_fixorigin(vector position);
+
+void botframe_autowaypoints();