[Bots]: Load more than 18 names from bots.txt (#850)

This commit is contained in:
Edo 2023-03-18 22:08:23 +00:00 committed by GitHub
parent b766d5c5b4
commit 4b8cd96851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 28 deletions

View File

@ -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)

View File

@ -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();
}
}
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: <bot> 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: <bot> BotWeapon(<str>);
{
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: <bot> BotAction(<str action>);
{
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: <bot> BotMovement(<int>, <int>);
{
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([]

View File

@ -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();