]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
make bots revive allies or search for an ally if they need a revive themself in battl...
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Fri, 26 May 2023 10:37:11 +0000 (12:37 +0200)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Fri, 26 May 2023 11:31:28 +0000 (13:31 +0200)
qcsrc/common/gamemodes/gamemode/br/sv_br.qc

index 4ce1f29d31c9cc99ff67f515c5a23f47d1ea0647..41bbcbe08b5b00e3f929948336d7f0d27f478036 100644 (file)
@@ -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)