From 79bfdd90162ef0e085642084c2c1fdfb4d4b7d66 Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 10 Feb 2017 16:26:10 +0100 Subject: [PATCH] Allow bots to roam on the map even if there's no item to pick up (playing CA or with g_pickup_items 0). It fixes #1844 --- qcsrc/server/bot/api.qh | 1 + qcsrc/server/bot/default/havocbot/roles.qc | 30 ++++++++++++++++++- qcsrc/server/bot/default/navigation.qc | 6 ++++ qcsrc/server/bot/default/navigation.qh | 3 ++ .../mutators/mutator/gamemode_domination.qc | 2 +- .../mutators/mutator/gamemode_freezetag.qc | 4 +-- .../mutators/mutator/gamemode_keepaway.qc | 2 +- 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/qcsrc/server/bot/api.qh b/qcsrc/server/bot/api.qh index 97104ef37..b0f457df4 100644 --- a/qcsrc/server/bot/api.qh +++ b/qcsrc/server/bot/api.qh @@ -66,6 +66,7 @@ entity find_bot_by_number(float number); void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius); void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius); +void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius); entity navigation_findnearestwaypoint(entity ent, float walkfromwp); void navigation_goalrating_end(entity this); diff --git a/qcsrc/server/bot/default/havocbot/roles.qc b/qcsrc/server/bot/default/havocbot/roles.qc index 27710bf08..6b9537651 100644 --- a/qcsrc/server/bot/default/havocbot/roles.qc +++ b/qcsrc/server/bot/default/havocbot/roles.qc @@ -13,6 +13,34 @@ .void(entity this) havocbot_previous_role; .void(entity this) havocbot_role; +void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius) +{ + // rate waypoints only if there's no alternative goal + if(navigation_bestgoal) + return; + + float f; + float range = 500; + sradius = max(range, (0.5 + random() * 0.5) * sradius); + while(sradius > 100) + { + IL_EACH(g_waypoints, vdist(it.origin - org, <, sradius) + && vdist(it.origin - org, >, max(100, sradius - range)), + { + if(vdist(it.origin - this.wp_goal_prev0.origin, <, range * 1.5)) + f = 0.1; + else if(vdist(it.origin - this.wp_goal_prev1.origin, <, range * 1.5)) + f = 0.1; + else + f = 0.5 + random() * 0.5; + navigation_routerating(this, it, ratingscale * f, 2000); + }); + if(navigation_bestgoal) + break; + sradius -= range; + } +}; + void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius) { float rating, d, discard, friend_distance, enemy_distance; @@ -175,7 +203,7 @@ void havocbot_role_generic(entity this) navigation_goalrating_start(this); havocbot_goalrating_items(this, 10000, this.origin, 10000); havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000); - //havocbot_goalrating_waypoints(1, this.origin, 1000); + havocbot_goalrating_waypoints(this, 1, this.origin, 3000); navigation_goalrating_end(this); } } diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 742213a89..2638958f5 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -875,6 +875,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; diff --git a/qcsrc/server/bot/default/navigation.qh b/qcsrc/server/bot/default/navigation.qh index ad0177665..e5097563c 100644 --- a/qcsrc/server/bot/default/navigation.qh +++ b/qcsrc/server/bot/default/navigation.qh @@ -24,6 +24,9 @@ entity navigation_bestgoal; .entity goalstack28, goalstack29, goalstack30, goalstack31; .entity nearestwaypoint; +.entity wp_goal_prev0; +.entity wp_goal_prev1; + .float nearestwaypointtimeout; .float navigation_hasgoals; .float lastteleporttime; diff --git a/qcsrc/server/mutators/mutator/gamemode_domination.qc b/qcsrc/server/mutators/mutator/gamemode_domination.qc index c236ab8a2..cffb60cb1 100644 --- a/qcsrc/server/mutators/mutator/gamemode_domination.qc +++ b/qcsrc/server/mutators/mutator/gamemode_domination.qc @@ -409,7 +409,7 @@ void havocbot_role_dom(entity this) havocbot_goalrating_controlpoints(this, 10000, this.origin, 15000); havocbot_goalrating_items(this, 8000, this.origin, 8000); //havocbot_goalrating_enemyplayers(this, 3000, this.origin, 2000); - //havocbot_goalrating_waypoints(1, this.origin, 1000); + havocbot_goalrating_waypoints(this, 1, this.origin, 3000); navigation_goalrating_end(this); } } diff --git a/qcsrc/server/mutators/mutator/gamemode_freezetag.qc b/qcsrc/server/mutators/mutator/gamemode_freezetag.qc index 2310ab4e6..515c9da94 100644 --- a/qcsrc/server/mutators/mutator/gamemode_freezetag.qc +++ b/qcsrc/server/mutators/mutator/gamemode_freezetag.qc @@ -270,7 +270,7 @@ void havocbot_role_ft_offense(entity this) havocbot_goalrating_items(this, 10000, this.origin, 10000); havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000); havocbot_goalrating_freeplayers(this, 9000, this.origin, 10000); - //havocbot_goalrating_waypoints(1, this.origin, 1000); + havocbot_goalrating_waypoints(this, 1, this.origin, 3000); navigation_goalrating_end(this); } } @@ -299,7 +299,7 @@ void havocbot_role_ft_freeing(entity this) havocbot_goalrating_items(this, 8000, this.origin, 10000); havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000); havocbot_goalrating_freeplayers(this, 20000, this.origin, 10000); - //havocbot_goalrating_waypoints(1, this.origin, 1000); + havocbot_goalrating_waypoints(this, 1, this.origin, 3000); navigation_goalrating_end(this); } } diff --git a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc index 7677bdab5..07c015f25 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc @@ -231,7 +231,7 @@ void havocbot_role_ka_carrier(entity this) navigation_goalrating_start(this); havocbot_goalrating_items(this, 10000, this.origin, 10000); havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000); - //havocbot_goalrating_waypoints(1, this.origin, 1000); + havocbot_goalrating_waypoints(this, 1, this.origin, 3000); navigation_goalrating_end(this); } -- 2.39.2