From 34158189655e4cb4a5d26c4a7f465df4bf05431e Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 28 Aug 2011 18:23:26 +0200 Subject: [PATCH 1/1] initial auto WP mode --- qcsrc/server/bot/bot.qc | 3 ++ qcsrc/server/bot/waypoints.qc | 68 +++++++++++++++++++++++++++++++++++ qcsrc/server/bot/waypoints.qh | 2 ++ 3 files changed, 73 insertions(+) diff --git a/qcsrc/server/bot/bot.qc b/qcsrc/server/bot/bot.qc index 94a17d8f1..c9a54c7f6 100644 --- a/qcsrc/server/bot/bot.qc +++ b/qcsrc/server/bot/bot.qc @@ -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) diff --git a/qcsrc/server/bot/waypoints.qc b/qcsrc/server/bot/waypoints.qc index 8aea49be5..eb08b38c5 100644 --- a/qcsrc/server/bot/waypoints.qc +++ b/qcsrc/server/bot/waypoints.qc @@ -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); + } +} diff --git a/qcsrc/server/bot/waypoints.qh b/qcsrc/server/bot/waypoints.qh index 9c84de84b..17e1f4e98 100644 --- a/qcsrc/server/bot/waypoints.qh +++ b/qcsrc/server/bot/waypoints.qh @@ -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(); -- 2.39.2