From 847088c7727f9316b98c34068e21956ea7c0d461 Mon Sep 17 00:00:00 2001 From: terencehill Date: Mon, 20 Nov 2017 16:33:51 +0100 Subject: [PATCH] Bot AI: Optimize path finding CPU cost when bot switches to certain CTF/Keepaway roles. Also fix compilation unit test --- qcsrc/server/bot/api.qh | 3 +++ qcsrc/server/mutators/mutator/gamemode_assault.qh | 3 --- qcsrc/server/mutators/mutator/gamemode_ctf.qc | 9 ++++++--- qcsrc/server/mutators/mutator/gamemode_keepaway.qc | 4 ++-- qcsrc/server/utils.qh | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/qcsrc/server/bot/api.qh b/qcsrc/server/bot/api.qh index 1e29a25fc..c503f605d 100644 --- a/qcsrc/server/bot/api.qh +++ b/qcsrc/server/bot/api.qh @@ -32,6 +32,8 @@ float skill; .float(entity player, entity item) bot_pickupevalfunc; .string cleanname; .float havocbot_role_timeout; +.void(entity this) havocbot_role; +.void(entity this) havocbot_previous_role; .float isbot; // true if this client is actually a bot .float lastteleporttime; .float navigation_hasgoals; @@ -77,6 +79,7 @@ vector havocbot_middlepoint; float havocbot_middlepoint_radius; vector havocbot_symmetryaxis_equation; +.float goalentity_lock_timeout; .float ignoregoaltime; .entity ignoregoal; diff --git a/qcsrc/server/mutators/mutator/gamemode_assault.qh b/qcsrc/server/mutators/mutator/gamemode_assault.qh index f437d98b5..ea714e6a2 100644 --- a/qcsrc/server/mutators/mutator/gamemode_assault.qh +++ b/qcsrc/server/mutators/mutator/gamemode_assault.qh @@ -31,9 +31,6 @@ const int HAVOCBOT_AST_ROLE_OFFENSE = 4; .int havocbot_role_flags; .float havocbot_attack_time; -.void(entity this) havocbot_role; -.void(entity this) havocbot_previous_role; - void(entity this) havocbot_role_ast_defense; void(entity this) havocbot_role_ast_offense; diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index ae26c7e39..3c714ad53 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -2034,7 +2034,8 @@ void havocbot_role_ctf_setrole(entity bot, int role) bot.havocbot_role = havocbot_role_ctf_carrier; bot.havocbot_role_timeout = 0; bot.havocbot_cantfindflag = time + 10; - navigation_goalrating_timeout_force(bot); + if (bot.havocbot_previous_role != bot.havocbot_role) + navigation_goalrating_timeout_force(bot); break; case HAVOCBOT_CTF_ROLE_DEFENSE: s = "defense"; @@ -2056,14 +2057,16 @@ void havocbot_role_ctf_setrole(entity bot, int role) bot.havocbot_previous_role = bot.havocbot_role; bot.havocbot_role = havocbot_role_ctf_retriever; bot.havocbot_role_timeout = time + 10; - navigation_goalrating_timeout_force(bot); + if (bot.havocbot_previous_role != bot.havocbot_role) + navigation_goalrating_timeout_expire(bot, 2); break; case HAVOCBOT_CTF_ROLE_ESCORT: s = "escort"; bot.havocbot_previous_role = bot.havocbot_role; bot.havocbot_role = havocbot_role_ctf_escort; bot.havocbot_role_timeout = time + 30; - navigation_goalrating_timeout_force(bot); + if (bot.havocbot_previous_role != bot.havocbot_role) + navigation_goalrating_timeout_expire(bot, 2); break; } LOG_TRACE(bot.netname, " switched to ", s); diff --git a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc index aeca28fa3..badae12c2 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc @@ -246,7 +246,7 @@ void havocbot_role_ka_carrier(entity this) if (!this.ballcarried) { this.havocbot_role = havocbot_role_ka_collector; - navigation_goalrating_timeout_force(this); + navigation_goalrating_timeout_expire(this, 2); } } @@ -269,7 +269,7 @@ void havocbot_role_ka_collector(entity this) if (this.ballcarried) { this.havocbot_role = havocbot_role_ka_carrier; - navigation_goalrating_timeout_force(this); + navigation_goalrating_timeout_expire(this, 2); } } diff --git a/qcsrc/server/utils.qh b/qcsrc/server/utils.qh index a0b7b5965..097685abf 100644 --- a/qcsrc/server/utils.qh +++ b/qcsrc/server/utils.qh @@ -22,7 +22,7 @@ const string STR_OBSERVER = "observer"; #define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE) #define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET) -#define IS_MOVABLE(v) (((IS_PLAYER(v) || IS_MONSTER(v)) && !STAT(FROZEN, v)) || IS_VEHICLE(v)) +#define IS_MOVABLE(v) ((IS_PLAYER(v) || IS_MONSTER(v)) && !STAT(FROZEN, v)) // NOTE: FOR_EACH_CLIENTSLOT deprecated! Use the following instead: FOREACH_CLIENTSLOT(true, { code; }); // NOTE: FOR_EACH_CLIENT deprecated! Use the following instead: FOREACH_CLIENT(true, { code; }); -- 2.39.2