Merge branch 'master' into 'master'
authorterencehill <piuntn@gmail.com>
Sat, 16 Feb 2019 23:08:47 +0000 (23:08 +0000)
committerterencehill <piuntn@gmail.com>
Sat, 16 Feb 2019 23:08:47 +0000 (23:08 +0000)
Fix crash when g_maxplayers smaller than current amount of active players

See merge request xonotic/xonotic-data.pk3dir!637

1  2 
qcsrc/server/bot/default/bot.qc

index 03f539383e5bd2e1471b3bab1ae482f03c1a0303,2552cc4bab6827799f66f90244b715f9e2b5c52e..3911d596dc51859afd8058272ec394bf402014a7
@@@ -215,13 -215,13 +215,13 @@@ void bot_setnameandstuff(entity this
  
        prio = 6;
  
 -      #define READSKILL(f, w, r) MACRO_BEGIN \
 +      #define READSKILL(f, w, r) MACRO_BEGIN \
                if(argv(prio) != "") \
                        this.f = stof(argv(prio)) * w; \
                else \
                        this.f = (!autocvar_g_campaign) * (2 * random() - 1) * r * w; \
                prio++; \
 -      MACRO_END
 +      MACRO_END
        //print(bot_name, ": ping=", argv(9), "\n");
  
        READSKILL(havocbot_keyboardskill, 0.5, 0.5); // keyboard skill
@@@ -604,8 -604,6 +604,8 @@@ bool bot_fixcount(
        else if ((realplayers || autocvar_bot_join_empty || (currentbots > 0 && time < 5)))
        {
                int minplayers = max(0, floor(autocvar_minplayers));
 +              if (teamplay)
 +                      minplayers = max(0, floor(autocvar_minplayers_per_team) * AvailableTeams());
                int minbots = max(0, floor(autocvar_bot_number));
  
                // add bots to reach minplayers if needed
                // cap bots to the max players allowed by the server
                int player_limit = GetPlayerLimit();
                if(player_limit)
-                       bots = min(bots, player_limit - activerealplayers);
+                       bots = min(bots, max(player_limit - activerealplayers, 0));
                bots = min(bots, maxclients - realplayers);
  
                if(bots > minbots)
                                return false;
                        }
                }
-               while (currentbots > bots)
+               while (currentbots > bots && bots >= 0)
                        bot_removenewest();
        }