[Bots]: Add back random bot names dvar (#876)

This commit is contained in:
Edo 2023-03-25 23:14:31 +00:00 committed by GitHub
parent 8284f89777
commit e539701d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -12,6 +12,8 @@ namespace Components
{ {
std::vector<Bots::botData> Bots::BotNames; std::vector<Bots::botData> Bots::BotNames;
Dvar::Var Bots::SVRandomBotNames;
struct BotMovementInfo struct BotMovementInfo
{ {
std::int32_t buttons; // Actions std::int32_t buttons; // Actions
@ -48,6 +50,13 @@ namespace Components
{ "activate", Game::CMD_BUTTON_ACTIVATE }, { "activate", Game::CMD_BUTTON_ACTIVATE },
}; };
void Bots::RandomizeBotNames()
{
std::random_device rd;
std::mt19937 gen(rd());
std::ranges::shuffle(BotNames, gen);
}
void Bots::LoadBotNames() void Bots::LoadBotNames()
{ {
FileSystem::File bots("bots.txt"); FileSystem::File bots("bots.txt");
@ -87,6 +96,11 @@ namespace Components
BotNames.emplace_back(entry, clanAbbrev); BotNames.emplace_back(entry, clanAbbrev);
} }
if (SVRandomBotNames.get<bool>())
{
RandomizeBotNames();
}
} }
int Bots::BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port) int Bots::BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port)
@ -351,6 +365,8 @@ namespace Components
Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick(); Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick();
SVRandomBotNames = Dvar::Register<bool>("sv_RandomBotNames", false, Game::DVAR_NONE, "Randomize the bots' names");
// Reset BotMovementInfo.active when client is dropped // Reset BotMovementInfo.active when client is dropped
Events::OnClientDisconnect([](const int clientNum) Events::OnClientDisconnect([](const int clientNum)
{ {

View File

@ -11,6 +11,9 @@ namespace Components
using botData = std::pair< std::string, std::string>; using botData = std::pair< std::string, std::string>;
static std::vector<botData> BotNames; static std::vector<botData> BotNames;
static Dvar::Var SVRandomBotNames;
static void RandomizeBotNames();
static void LoadBotNames(); static void LoadBotNames();
static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port); static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port);