From 4b8cd96851b31398c03579c1799a79ed45d5f26d Mon Sep 17 00:00:00 2001 From: Edo Date: Sat, 18 Mar 2023 22:08:23 +0000 Subject: [PATCH] [Bots]: Load more than 18 names from bots.txt (#850) --- CHANGELOG.md | 1 + src/Components/Modules/Bots.cpp | 37 +++++++++------------------------ src/Components/Modules/Bots.hpp | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52eaa35c..7b8c6311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog v0.3.0](http://keepachangelog.com/en/0. - `banClient` and `muteClient` server commands do not apply to bots anymore (#730) - Remove `zb_prefer_disk_assets` Dvar (#772) - The max value of `perk_extendedMeleeRange`Dvar was increased (#782) +- Test Clients will receive names from the Xlabs Patreon website in addition to the names from the bots.txt file (#771) ### Fixed - Fix bug where`reloadmenus` command would not free resources used by custom menus (#740) diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 369e98f6..d6e2d2dc 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -25,7 +25,7 @@ namespace Components bool active; }; - static BotMovementInfo g_botai[18]; + static BotMovementInfo g_botai[Game::MAX_CLIENTS]; struct BotAction { @@ -83,15 +83,8 @@ namespace Components auto data = Utils::String::Split(bots.getBuffer(), '\n'); - auto i = 0; for (auto& entry : data) { - if (i >= 18) - { - // Only parse 18 names from the file - break; - } - // Take into account for CR line endings Utils::String::Replace(entry, "\r", ""); // Remove whitespace @@ -116,19 +109,15 @@ namespace Components entry = entry.substr(0, pos); } - BotNames.emplace_back(std::make_pair(entry, clanAbbrev)); - ++i; + BotNames.emplace_back(entry, clanAbbrev); } - if (i) - { - RandomizeBotNames(); - } + RandomizeBotNames(); } int Bots::BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port) { - static size_t botId = 0; // Loop over the BotNames vector + static std::size_t botId = 0; // Loop over the BotNames vector static bool loadedNames = false; // Load file only once std::string botName; std::string clanName; @@ -203,15 +192,14 @@ namespace Components Game::Scr_AddBool(Game::SV_IsTestClient(ent->s.number) != 0); } - void Bots::AddMethods() + void Bots::AddScriptMethods() { GSC::Script::AddMethMultiple(GScr_isTestClient, false, {"IsTestClient", "IsBot"}); // Usage: self IsTestClient(); GSC::Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: BotStop(); { const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); - - if (Game::SV_IsTestClient(ent->s.number) == 0) + if (!Game::SV_IsTestClient(ent->s.number)) { Game::Scr_Error("BotStop: Can only call on a bot!"); return; @@ -225,15 +213,13 @@ namespace Components GSC::Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: BotWeapon(); { const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); - - if (Game::SV_IsTestClient(ent->s.number) == 0) + if (!Game::SV_IsTestClient(ent->s.number)) { Game::Scr_Error("BotWeapon: Can only call on a bot!"); return; } const auto* weapon = Game::Scr_GetString(0); - if (!weapon || !*weapon) { g_botai[entref.entnum].weapon = 1; @@ -248,15 +234,13 @@ namespace Components GSC::Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: BotAction(); { const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); - - if (Game::SV_IsTestClient(ent->s.number) == 0) + if (!Game::SV_IsTestClient(ent->s.number)) { Game::Scr_Error("BotAction: Can only call on a bot!"); return; } const auto* action = Game::Scr_GetString(0); - if (!action) { Game::Scr_ParamError(0, "BotAction: Illegal parameter!"); @@ -289,8 +273,7 @@ namespace Components GSC::Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: BotMovement(, ); { const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref); - - if (Game::SV_IsTestClient(ent->s.number) == 0) + if (!Game::SV_IsTestClient(ent->s.number)) { Game::Scr_Error("BotMovement: Can only call on a bot!"); return; @@ -475,7 +458,7 @@ namespace Components Spawn(count); }); - AddMethods(); + AddScriptMethods(); // In case a loaded mod didn't call "BotStop" before the VM shutdown Events::OnVMShutdown([] diff --git a/src/Components/Modules/Bots.hpp b/src/Components/Modules/Bots.hpp index efa4d3a7..cc2629bc 100644 --- a/src/Components/Modules/Bots.hpp +++ b/src/Components/Modules/Bots.hpp @@ -21,7 +21,7 @@ namespace Components static void Spawn(unsigned int count); static void GScr_isTestClient(Game::scr_entref_t entref); - static void AddMethods(); + static void AddScriptMethods(); static void BotAiAction(Game::client_t* cl); static void SV_BotUserMove_Hk();