]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/bot.qc
Autocvarize SVQC and CSQC. 20% less CPU usage of dedicated servers with bots. Large...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / bot.qc
index a784ef48b17542c38d9448ea3631ec344aa23654..581e3f0c758050dae69b33c9c983a98a4ba735c4 100644 (file)
@@ -33,17 +33,17 @@ void bot_think()
                return;
 
        self.flags &~= FL_GODMODE;
-       if(cvar("bot_god"))
+       if(autocvar_bot_god)
                self.flags |= FL_GODMODE;
 
-       self.bot_nextthink = self.bot_nextthink + cvar("bot_ai_thinkinterval") * pow(0.5, self.bot_aiskill);
+       self.bot_nextthink = self.bot_nextthink + autocvar_bot_ai_thinkinterval * pow(0.5, self.bot_aiskill);
        //if (self.bot_painintensity > 0)
        //      self.bot_painintensity = self.bot_painintensity - (skill + 1) * 40 * frametime;
 
        //self.bot_painintensity = self.bot_painintensity + self.bot_oldhealth - self.health;
        //self.bot_painintensity = bound(0, self.bot_painintensity, 100);
 
-       if (cvar("g_campaign") && !campaign_bots_may_start)
+       if (autocvar_g_campaign && !campaign_bots_may_start)
        {
                self.nextthink = time + 0.5;
                return;
@@ -112,21 +112,21 @@ void bot_setnameandstuff()
        string bot_name, bot_model, bot_skin, bot_shirt, bot_pants;
        string name, prefix, suffix;
 
-       if(cvar("g_campaign"))
+       if(autocvar_g_campaign)
        {
                prefix = "";
                suffix = "";
        }
        else
        {
-               prefix = cvar_string("bot_prefix");
-               suffix = cvar_string("bot_suffix");
+               prefix = autocvar_bot_prefix;
+               suffix = autocvar_bot_suffix;
        }
 
-       file = fopen(cvar_string("bot_config_file"), FILE_READ);
+       file = fopen(autocvar_bot_config_file, FILE_READ);
 
        if(file < 0)
-               print(strcat("Error: Can not open the bot configuration file '",cvar_string("bot_config_file"),"'\n"));
+               print(strcat("Error: Can not open the bot configuration file '",autocvar_bot_config_file,"'\n"));
        else
        {
                RandomSelection_Init();
@@ -177,7 +177,7 @@ void bot_setnameandstuff()
 
        prio = 6;
 
-       #define READSKILL(f,w,r) if(argv(prio) != "") self.f = stof(argv(prio)) * (w); else self.f = (!cvar("g_campaign")) * (2 * random() - 1) * (r) * (w); ++prio
+       #define READSKILL(f,w,r) if(argv(prio) != "") self.f = stof(argv(prio)) * (w); else self.f = (!autocvar_g_campaign) * (2 * random() - 1) * (r) * (w); ++prio
        //print(bot_name, ": ping=", argv(9), "\n");
 
        READSKILL(havocbot_keyboardskill, 0.5, 0.5); // keyboard skill
@@ -204,7 +204,7 @@ void bot_setnameandstuff()
        self.bot_preferredcolors = self.clientcolors;
 
        // pick the name
-       if (cvar("bot_usemodelnames"))
+       if (autocvar_bot_usemodelnames)
                name = bot_model;
        else
                name = bot_name;
@@ -241,15 +241,15 @@ void bot_custom_weapon_priority_setup()
 
        bot_custom_weapon = FALSE;
 
-       if(     cvar_string("bot_ai_custom_weapon_priority_far") == "" ||
-               cvar_string("bot_ai_custom_weapon_priority_mid") == "" ||
-               cvar_string("bot_ai_custom_weapon_priority_close") == "" ||
-               cvar_string("bot_ai_custom_weapon_priority_distances") == ""
+       if(     autocvar_bot_ai_custom_weapon_priority_far == "" ||
+               autocvar_bot_ai_custom_weapon_priority_mid == "" ||
+               autocvar_bot_ai_custom_weapon_priority_close == "" ||
+               autocvar_bot_ai_custom_weapon_priority_distances == ""
        )
                return;
 
        // Parse distances
-       tokens = tokenizebyseparator(cvar_string("bot_ai_custom_weapon_priority_distances")," ");
+       tokens = tokenizebyseparator(autocvar_bot_ai_custom_weapon_priority_distances," ");
 
        if (tokens!=2)
                return;
@@ -268,7 +268,7 @@ void bot_custom_weapon_priority_setup()
        bot_weapons_close[0] = -1;
 
        // Parse far distance weapon priorities
-       tokens = tokenizebyseparator(W_NumberWeaponOrder(cvar_string("bot_ai_custom_weapon_priority_far"))," ");
+       tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_far)," ");
 
        c = 0;
        for(i=0; i < tokens && c < WEP_COUNT; ++i){
@@ -282,7 +282,7 @@ void bot_custom_weapon_priority_setup()
                bot_weapons_far[c] = -1;
 
        // Parse mid distance weapon priorities
-       tokens = tokenizebyseparator(W_NumberWeaponOrder(cvar_string("bot_ai_custom_weapon_priority_mid"))," ");
+       tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_mid)," ");
 
        c = 0;
        for(i=0; i < tokens && c < WEP_COUNT; ++i){
@@ -296,7 +296,7 @@ void bot_custom_weapon_priority_setup()
                bot_weapons_mid[c] = -1;
 
        // Parse close distance weapon priorities
-       tokens = tokenizebyseparator(W_NumberWeaponOrder(cvar_string("bot_ai_custom_weapon_priority_close"))," ");
+       tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_close)," ");
 
        c = 0;
        for(i=0; i < tokens && i < WEP_COUNT; ++i){
@@ -498,20 +498,20 @@ void autoskill(float factor)
        }
        else if(bestbot <= bestplayer * factor - 2)
        {
-               if(cvar("skill") < 17)
+               if(autocvar_skill < 17)
                {
                        dprint("2 frags difference, increasing skill\n");
-                       cvar_set("skill", ftos(cvar("skill") + 1));
-                       bprint("^2SKILL UP!^7 Now at level ", ftos(cvar("skill")), "\n");
+                       cvar_set("skill", ftos(autocvar_skill + 1));
+                       bprint("^2SKILL UP!^7 Now at level ", ftos(autocvar_skill), "\n");
                }
        }
        else if(bestbot >= bestplayer * factor + 2)
        {
-               if(cvar("skill") > 0)
+               if(autocvar_skill > 0)
                {
                        dprint("2 frags difference, decreasing skill\n");
-                       cvar_set("skill", ftos(cvar("skill") - 1));
-                       bprint("^1SKILL DOWN!^7 Now at level ", ftos(cvar("skill")), "\n");
+                       cvar_set("skill", ftos(autocvar_skill - 1));
+                       bprint("^1SKILL DOWN!^7 Now at level ", ftos(autocvar_skill), "\n");
                }
        }
        else
@@ -536,13 +536,13 @@ void bot_serverframe()
        if (time < 2)
                return;
 
-       stepheightvec = cvar("sv_stepheight") * '0 0 1';
-       bot_navigation_movemode = ((cvar("bot_navigation_ignoreplayers")) ? MOVE_NOMONSTERS : MOVE_NORMAL);
+       stepheightvec = autocvar_sv_stepheight * '0 0 1';
+       bot_navigation_movemode = ((autocvar_bot_navigation_ignoreplayers) ? MOVE_NOMONSTERS : MOVE_NORMAL);
 
        if(time > autoskill_nextthink)
        {
                float a;
-               a = cvar("skill_auto");
+               a = autocvar_skill_auto;
                if(a)
                        autoskill(a);
                autoskill_nextthink = time + 5;
@@ -563,16 +563,16 @@ void bot_serverframe()
        // But don't remove bots immediately on level change, as the real players
        // usually haven't rejoined yet
        bots_would_leave = FALSE;
-       if (teams_matter && cvar("bot_vs_human") && (c3==-1 && c4==-1))
-               bots = min(ceil(fabs(cvar("bot_vs_human")) * activerealplayers), maxclients - realplayers);
-       else if ((realplayers || cvar("bot_join_empty") || (currentbots > 0 && time < 5)))
+       if (teams_matter && autocvar_bot_vs_human && (c3==-1 && c4==-1))
+               bots = min(ceil(fabs(autocvar_bot_vs_human) * activerealplayers), maxclients - realplayers);
+       else if ((realplayers || autocvar_bot_join_empty || (currentbots > 0 && time < 5)))
        {
                float realminplayers, minplayers;
-               realminplayers = cvar("minplayers");
+               realminplayers = autocvar_minplayers;
                minplayers = max(0, floor(realminplayers));
 
                float realminbots, minbots;
-               realminbots = cvar("bot_number");
+               realminbots = autocvar_bot_number;
                minbots = max(0, floor(realminbots));
 
                bots = min(max(minbots, minplayers - activerealplayers), maxclients - realplayers);
@@ -585,7 +585,7 @@ void bot_serverframe()
                bots = 0;
        }
 
-       bot_ignore_bots = cvar("bot_ignore_bots");
+       bot_ignore_bots = autocvar_bot_ignore_bots;
 
        // only add one bot per frame to avoid utter chaos
        if(time > botframe_nextthink)
@@ -606,11 +606,11 @@ void bot_serverframe()
 
        if(botframe_spawnedwaypoints)
        {
-               if(cvar("waypoint_benchmark"))
+               if(autocvar_waypoint_benchmark)
                        localcmd("quit\n");
        }
 
-       if (currentbots > 0 || cvar("g_waypointeditor"))
+       if (currentbots > 0 || autocvar_g_waypointeditor)
        if (botframe_spawnedwaypoints)
        {
                if(botframe_cachedwaypointlinks)
@@ -651,15 +651,15 @@ void bot_serverframe()
                if (botframe_nextdangertime < time)
                {
                        local float interval;
-                       interval = cvar("bot_ai_dangerdetectioninterval");
+                       interval = autocvar_bot_ai_dangerdetectioninterval;
                        if (botframe_nextdangertime < time - interval * 1.5)
                                botframe_nextdangertime = time;
                        botframe_nextdangertime = botframe_nextdangertime + interval;
-                       botframe_updatedangerousobjects(cvar("bot_ai_dangerdetectionupdates"));
+                       botframe_updatedangerousobjects(autocvar_bot_ai_dangerdetectionupdates);
                }
        }
 
-       if (cvar("g_waypointeditor"))
+       if (autocvar_g_waypointeditor)
                botframe_showwaypointlinks();
 
        if(time > bot_cvar_nextthink)