Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions src/game/server/neo/bot/neo_bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,72 @@ const char* GetRandomBotName(void)
static const char* nameList[] =
{
"Deej",
"Ed",
"0edit",
"Filter Decay",
"Gato",
"Grey",
"Glasseater",
"Ivy",
"Operation Ivy",
"KillahMo",
"pushBAK",
"Tatsur0",
"rain",
"The Major",
"Wolf",
"Sanjuro Executive",
"Grumpy Old Man",
"Biodroid Prototype",
"TGR",
"Jinball",
"Pequod",
"The Chimpanzee",
"Marchenko",
"Jeff",
"M.A.W.S.",
"Tin Soldier",
"SUKKIT",
"Supaman",
"Hadaly",
"Komatsu Lifthelper",
"HE Specialist",
"Left Leaner",
"Super Class A Hacker",
"and You",
};

return nameList[RandomInt(0, ARRAYSIZE(nameList) - 1)];
const int nameCount = ARRAYSIZE(nameList);

CUtlVector<int> availableList;
for (int i = 0; i < nameCount; ++i)
{
availableList.AddToTail(i);
}

for (int j = 1; j <= gpGlobals->maxClients && availableList.Count() > 0; ++j)
{
auto player = UTIL_PlayerByIndex(j);
if (!player)
{
continue;
}

for (int k = availableList.Count() - 1; k >= 0; --k)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be an optimization nit, but it might be cleaner to use a hashmap to check if a name was used, instead of using a double nest of for loops.

Something like:

CUtlStringMap<bool> usedNames;
for (int j = 1; j <= gpGlobals->maxClients; ++j) {
    auto player = UTIL_PlayerByIndex(j);
    if (player) {
        usedNames.Insert(player->GetPlayerName(), true);
    }
}

{
if (V_stristr(player->GetPlayerName(), nameList[availableList[k]]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine for the current list, but if we ever add more short names like "Ed" to the list, a partial match could potentially lead to an accidental collision. Changing "Ed" to "0edit" made this case even more rare, but up to you if you think this would be worth being more explicit about.

A more explicit string comparison would be along the lines of:

if (V_stricmp(playerName, nameList[availableList[k]]) == 0)

An exact match could also be faster than a substring match, but I'd be surprised if it makes a difference here.

{
availableList.FastRemove(k);
}
}
}

if (availableList.Count() == 0)
{
return nameList[RandomInt(0, nameCount - 1)];
}

return nameList[availableList[RandomInt(0, availableList.Count() - 1)]];

//return nameList[RandomInt(0, ARRAYSIZE(nameList) - 1)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you come back with another commit, might be worth cleaning up this previous line.

}


Expand Down
Loading