]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/bot.qc
Merge branch 'terencehill/ca_bots_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / bot.qc
index 753c1867ee685ee5ce05c50d83ac0454464ffbe6..ed9070f9cdd60821538da821afdceab6a2405cab 100644 (file)
 #include "../../antilag.qh"
 #include "../../autocvars.qh"
 #include "../../campaign.qh"
-#include "../../cl_client.qh"
+#include "../../client.qh"
 #include "../../constants.qh"
 #include "../../defs.qh"
 #include "../../race.qh"
 #include <common/t_items.qh>
 
-#include "../../mutators/all.qh"
+#include "../../mutators/_mod.qh"
 
 #include "../../weapons/accuracy.qh"
 
 #include <common/physics/player.qh>
 #include <common/constants.qh>
+#include <common/net_linked.qh>
 #include <common/mapinfo.qh>
 #include <common/teams.qh>
 #include <common/util.qh>
 
-#include <common/weapons/all.qh>
+#include <server/scores_rules.qh>
+
+#include <common/weapons/_all.qh>
 
 #include <lib/csqcmodel/sv_model.qh>
 
@@ -69,6 +72,7 @@ void bot_think(entity this)
 
        if (!IS_PLAYER(this) || (autocvar_g_campaign && !campaign_bots_may_start))
        {
+               this.movement = '0 0 0';
                this.bot_nextthink = time + 0.5;
                return;
        }
@@ -115,6 +119,7 @@ void bot_think(entity this)
        // if dead, just wait until we can respawn
        if (IS_DEAD(this))
        {
+               this.movement = '0 0 0';
                if (this.deadflag == DEAD_DEAD)
                {
                        PHYS_INPUT_BUTTON_JUMP(this) = true; // press jump to respawn
@@ -175,7 +180,7 @@ void bot_setnameandstuff(entity this)
                                        break;
                                }
                        ));
-                       RandomSelection_Add(NULL, 0, readfile, 1, prio);
+                       RandomSelection_AddString(readfile, 1, prio);
                }
                readfile = RandomSelection_chosen_string;
                fclose(file);
@@ -335,9 +340,8 @@ void bot_custom_weapon_priority_setup()
 
 void bot_endgame()
 {
-       entity e;
-       //dprint("bot_endgame\n");
-       e = bot_list;
+       bot_relinkplayerlist();
+       entity e = bot_list;
        while (e)
        {
                setcolor(e, e.bot_preferredcolors);
@@ -370,7 +374,7 @@ void bot_relinkplayerlist()
                        ++currentbots;
                }
        });
-       LOG_TRACE(strcat("relink: ", ftos(currentbots), " bots seen.\n"));
+       LOG_TRACE("relink: ", ftos(currentbots), " bots seen.");
        bot_strategytoken = bot_list;
        bot_strategytoken_taken = true;
 }
@@ -394,7 +398,7 @@ void bot_clientdisconnect(entity this)
        this.playerskin_freeme = string_null;
        if(this.bot_cmd_current)
                delete(this.bot_cmd_current);
-       if(bot_waypoint_queue_owner==this)
+       if(bot_waypoint_queue_owner == this)
                bot_waypoint_queue_owner = NULL;
 }
 
@@ -434,7 +438,7 @@ void bot_removefromlargestteam()
        int bestcount = 0;
 
        int bcount = 0;
-       FOREACH_ENTITY_FLOAT(isbot, true,
+       FOREACH_CLIENT(it.isbot,
        {
                ++bcount;
 
@@ -484,7 +488,7 @@ void bot_removenewest()
        entity best = NULL;
        int bcount = 0;
 
-       FOREACH_ENTITY_FLOAT(isbot, true,
+       FOREACH_CLIENT(it.isbot,
        {
                ++bcount;
 
@@ -526,14 +530,14 @@ void autoskill(float factor)
        LOG_TRACE("best bot got ", ftos(bestbot), "; ");
        if(bestbot < 0 || bestplayer < 0)
        {
-               LOG_TRACE("not doing anything\n");
+               LOG_TRACE("not doing anything");
                // don't return, let it reset all counters below
        }
        else if(bestbot <= bestplayer * factor - 2)
        {
                if(autocvar_skill < 17)
                {
-                       LOG_TRACE("2 frags difference, increasing skill\n");
+                       LOG_TRACE("2 frags difference, increasing skill");
                        cvar_set("skill", ftos(autocvar_skill + 1));
                        bprint("^2SKILL UP!^7 Now at level ", ftos(autocvar_skill), "\n");
                }
@@ -542,14 +546,14 @@ void autoskill(float factor)
        {
                if(autocvar_skill > 0)
                {
-                       LOG_TRACE("2 frags difference, decreasing skill\n");
+                       LOG_TRACE("2 frags difference, decreasing skill");
                        cvar_set("skill", ftos(autocvar_skill - 1));
                        bprint("^1SKILL DOWN!^7 Now at level ", ftos(autocvar_skill), "\n");
                }
        }
        else
        {
-               LOG_TRACE("not doing anything\n");
+               LOG_TRACE("not doing anything");
                return;
                // don't reset counters, wait for them to accumulate
        }
@@ -627,9 +631,42 @@ float bot_fixcount()
        return true;
 }
 
+void bot_remove_from_bot_list(entity this)
+{
+       entity e = bot_list;
+       entity prev_bot = NULL;
+       while (e)
+       {
+               if(e == this)
+               {
+                       if(!prev_bot)
+                               bot_list = this.nextbot;
+                       else
+                               prev_bot.nextbot = this.nextbot;
+                       if(bot_strategytoken == this)
+                       {
+                               bot_strategytoken = this.nextbot;
+                               bot_strategytoken_taken = true;
+                       }
+                       this.nextbot = NULL;
+                       break;
+               }
+               prev_bot = e;
+               e = e.nextbot;
+       }
+}
+
+void bot_clear(entity this)
+{
+       bot_remove_from_bot_list(this);
+       if(bot_waypoint_queue_owner == this)
+               bot_waypoint_queue_owner = NULL;
+       this.aistatus &= ~AI_STATUS_STUCK; // otherwise bot_waypoint_queue_owner will be set again to this by navigation_unstuck
+}
+
 void bot_serverframe()
 {
-       if (intermission_running)
+       if (gameover)
                return;
 
        if (time < 2)