]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/bot.qc
Fix crash when g_maxplayers smaller than current amount of active players
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / bot.qc
index d9d05773e42b949b1b19522cd1c5246bee1cb7b0..2552cc4bab6827799f66f90244b715f9e2b5c52e 100644 (file)
@@ -41,6 +41,8 @@
 #include <lib/warpzone/common.qh>
 #include <lib/warpzone/util_server.qh>
 
+STATIC_INIT(bot) { bot_calculate_stepheightvec(); }
+
 // TODO: remove this function! its only purpose is to update these fields since bot_setnameandstuff is called before ClientState
 void bot_setclientfields(entity this)
 {
@@ -578,7 +580,7 @@ void bot_calculate_stepheightvec()
        jumpstepheightvec = stepheightvec + jumpheight_vec * 0.85; // reduce it a bit to make the jumps easy
 }
 
-float bot_fixcount()
+bool bot_fixcount()
 {
        int activerealplayers = 0;
        int realplayers = 0;
@@ -593,7 +595,6 @@ float bot_fixcount()
                });
        }
 
-       //int player_limit = GetPlayerLimit(); // TODO: use this instead of maxclients!
        int bots;
        // But don't remove bots immediately on level change, as the real players
        // usually haven't rejoined yet
@@ -608,8 +609,9 @@ float bot_fixcount()
                // add bots to reach minplayers if needed
                bots = max(minbots, minplayers - activerealplayers);
                // cap bots to the max players allowed by the server
-               if(autocvar_g_maxplayers)
-                       bots = min(bots, autocvar_g_maxplayers - activerealplayers);
+               int player_limit = GetPlayerLimit();
+               if(player_limit)
+                       bots = min(bots, max(player_limit - activerealplayers, 0));
                bots = min(bots, maxclients - realplayers);
 
                if(bots > minbots)
@@ -632,7 +634,7 @@ float bot_fixcount()
                                return false;
                        }
                }
-               while (currentbots > bots)
+               while (currentbots > bots && bots >= 0)
                        bot_removenewest();
        }