From 39044086fb669690aa01fcd55a36430e9c85b50f Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Fri, 26 May 2023 12:37:11 +0200 Subject: [PATCH] make bots revive allies or search for an ally if they need a revive themself in battle royale --- qcsrc/common/gamemodes/gamemode/br/sv_br.qc | 76 +++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/qcsrc/common/gamemodes/gamemode/br/sv_br.qc b/qcsrc/common/gamemodes/gamemode/br/sv_br.qc index 4ce1f29d3..41bbcbe08 100644 --- a/qcsrc/common/gamemodes/gamemode/br/sv_br.qc +++ b/qcsrc/common/gamemodes/gamemode/br/sv_br.qc @@ -1031,6 +1031,82 @@ MUTATOR_HOOKFUNCTION(br, SV_StartFrame) } } +void(entity this) havocbot_role_br_reviving; +void(entity this) havocbot_role_br_generic; + +bool squad_needs_revive(entity this) +{ + for(entity member = this.br_squad.br_squad_first; member; member = member.br_squad_next) + { + if(IS_DEAD(member) || !IS_PLAYER(member)) + continue; + + if(STAT(BLEEDING, member)) + return true; + } + + return false; +} + +void havocbot_goalrating_br_findplayers(entity this, float ratingscale) +{ + if(!IN_SQUAD(this)) + return; + + for(entity member = this.br_squad.br_squad_first; member; member = member.br_squad_next) + { + if(IS_DEAD(member) || !IS_PLAYER(member) || (member == this)) + continue; + + // either wants to be revived by another player or wants to revive another player + if(STAT(BLEEDING, member) != STAT(BLEEDING, this)) + navigation_routerating(this, member, ratingscale, 100000); + } +} + +void havocbot_role_br_reviving(entity this) +{ + if(IS_DEAD(this)) + return; + + if(!squad_needs_revive(this)) + { + LOG_TRACE("changing role to generic"); + this.havocbot_role = havocbot_role_br_generic; + navigation_goalrating_timeout_force(this); + return; + } + + navigation_goalrating_start(this); + havocbot_goalrating_br_findplayers(this, 20000); + navigation_goalrating_end(this); +} + +void havocbot_role_br_generic(entity this) +{ + if(IS_DEAD(this)) + return; + + if(squad_needs_revive(this)) + { + LOG_TRACE("changing role to reviving"); + this.havocbot_role = havocbot_role_br_reviving; + return; + } + + havocbot_role_generic(this); +} + +MUTATOR_HOOKFUNCTION(br, HavocBot_ChooseRole) +{ + entity bot = M_ARGV(0, entity); + + if(!IS_DEAD(bot)) + bot.havocbot_role = havocbot_role_br_generic; + + return true; +} + float br_CalculatePlayerDropAngle(entity this) { if(this.velocity.z < 0) -- 2.39.2