[Bots]: I misread std::string docs (#943)

This commit is contained in:
Edo 2023-04-19 15:53:07 +02:00 committed by GitHub
parent ed059c280a
commit 70be263918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 16 deletions

View File

@ -6,8 +6,8 @@
#include "GSC/Script.hpp" #include "GSC/Script.hpp"
// From Quake-III // From Quake-III
#define ANGLE2SHORT(x) ((int)((x) * (USHRT_MAX + 1) / 360.0f) & USHRT_MAX) #define ANGLE2SHORT(x) ((int)((x) * (USHRT_MAX + 1) / 360.0f) & USHRT_MAX)
#define SHORT2ANGLE(x) ((x)* (360.0f / (USHRT_MAX + 1))) #define SHORT2ANGLE(x) ((x)* (360.0f / (USHRT_MAX + 1)))
namespace Components namespace Components
{ {
@ -61,16 +61,6 @@ namespace Components
std::ranges::shuffle(BotNames, gen); std::ranges::shuffle(BotNames, gen);
} }
std::string Bots::TruncBotString(const std::string& input, const std::size_t length)
{
if (length > input.size())
{
return input;
}
return input.substr(length);
}
void Bots::LoadBotNames() void Bots::LoadBotNames()
{ {
FileSystem::File bots("bots.txt"); FileSystem::File bots("bots.txt");
@ -102,14 +92,13 @@ namespace Components
// Only start copying over from non-null characters (otherwise it can be "<=") // Only start copying over from non-null characters (otherwise it can be "<=")
if ((pos + 1) < entry.size()) if ((pos + 1) < entry.size())
{ {
clanAbbrev = entry.substr(pos + 1); clanAbbrev = entry.substr(pos + 1, ClanTags::MAX_CLAN_NAME_LENGTH - 1);
} }
entry = entry.substr(0, pos); entry = entry.substr(0, pos);
} }
entry = TruncBotString(entry, MAX_NAME_LENGTH - 1); entry = entry.substr(0, MAX_NAME_LENGTH - 1);
clanAbbrev = TruncBotString(clanAbbrev, ClanTags::MAX_CLAN_NAME_LENGTH - 1);
BotNames.emplace_back(entry, clanAbbrev); BotNames.emplace_back(entry, clanAbbrev);
} }

View File

@ -17,7 +17,6 @@ namespace Components
static const Game::dvar_t* sv_replaceBots; static const Game::dvar_t* sv_replaceBots;
static void RandomizeBotNames(); static void RandomizeBotNames();
static std::string TruncBotString(const std::string& input, std::size_t length);
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);