crashfix: prevent division by zero when spawning too many bots

This commit is contained in:
Ramok
2025-05-30 14:26:24 +02:00
committed by GitHub
parent 76f540b426
commit 35228f6d9b
2 changed files with 5 additions and 9 deletions

View File

@@ -69,4 +69,6 @@ static inline void InitBotNames()
PlayerBotNames.push_back(L"AllyJax"); PlayerBotNames.push_back(L"AllyJax");
PlayerBotNames.push_back(L"secret_pommes"); PlayerBotNames.push_back(L"secret_pommes");
PlayerBotNames.push_back(L"Twin1"); PlayerBotNames.push_back(L"Twin1");
std::shuffle(PlayerBotNames.begin(), PlayerBotNames.end(), std::default_random_engine((unsigned int)time(0)));
} }

View File

@@ -232,21 +232,15 @@ public:
} }
else else
{ {
if (Fortnite_Version < 11) if (Fortnite_Version < 11 || PlayerBotNames.empty())
{ {
BotNumWStr = std::to_wstring(CurrentBotNum++ + 200); BotNumWStr = std::to_wstring(CurrentBotNum++ + 200);
NewName = (std::format(L"Anonymous[{}]", BotNumWStr)).c_str(); NewName = (std::format(L"Anonymous[{}]", BotNumWStr)).c_str();
} }
else else
{ {
if (!PlayerBotNames.empty()) NewName = PlayerBotNames.back();
{ PlayerBotNames.pop_back();
// std::shuffle(PlayerBotNames.begin(), PlayerBotNames.end(), std::default_random_engine((unsigned int)time(0)));
int RandomIndex = std::rand() % (PlayerBotNames.size() - 1);
NewName = PlayerBotNames[RandomIndex];
PlayerBotNames.erase(PlayerBotNames.begin() + RandomIndex);
}
} }
} }