Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions RLBotCS/ManagerTools/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private T GetEnum<T>(TomlTable table, string key, T fallback)
return res;
throw new InvalidCastException(
$"{_context.ToStringWithEnd(key)} has invalid value \"{raw}\". "
+ $"Find valid values on https:/wiki.rlbot.org."
+ $"Find valid values on https://wiki.rlbot.org."
);
}
else
Expand Down Expand Up @@ -199,7 +199,7 @@ private PlayerClass GetAgentType(TomlTable table)
default:
throw new InvalidCastException(
$"{_context.ToStringWithEnd(Fields.AgentType)} has invalid value \"{raw}\". "
+ $"Find valid values on https:/wiki.rlbot.org."
+ $"Find valid values on https://wiki.rlbot.org."
);
}
}
Expand Down
58 changes: 29 additions & 29 deletions RLBotCS/ManagerTools/MatchStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ public void OnMapSpawn(string mapName, PlayerSpawner spawner)
}
}

private static string DedupName(string name, Dictionary<string, int> nameCounts)
{
if (nameCounts.TryGetValue(name, out int count))
{
nameCounts[name] = ++count;
name += $" ({count + 1})";
}
else
{
nameCounts[name] = 0;
}

return name;
}

private void PreprocessMatch(MatchConfigurationT matchConfig)
{
Dictionary<string, int> playerNames = [];
Expand All @@ -138,43 +153,28 @@ private void PreprocessMatch(MatchConfigurationT matchConfig)
foreach (var player in matchConfig.PlayerConfigurations)
{
// De-duplicating similar names. Overwrites original value.

if (player.Variety.Value is CustomBotT config)
switch (player.Variety.Value)
{
string playerName = config.Name ?? "";
if (playerNames.TryGetValue(playerName, out int value))
{
playerNames[playerName] = ++value;
config.Name = playerName + $" ({value + 1})";
}
else
{
playerNames[playerName] = 0;
config.Name = playerName;
}
case CustomBotT config:
string playerName = config.Name ?? "";
config.Name = DedupName(playerName, playerNames);

if (config.Hivemind)
{
_hivemindNameMap[config.Name] = playerName;
}
if (config.Hivemind)
{
_hivemindNameMap[config.Name] = playerName;
}
break;
case PsyonixBotT config:
config.Name = DedupName(config.Name ?? "", playerNames);
break;
}
}

Dictionary<string, int> scriptNames = [];
foreach (var scriptConfig in matchConfig.ScriptConfigurations)
foreach (var script in matchConfig.ScriptConfigurations)
{
// De-duplicating similar names. Overwrites original value.
string scriptName = scriptConfig.Name ?? "";
if (scriptNames.TryGetValue(scriptName, out int value))
{
scriptNames[scriptName] = ++value;
scriptConfig.Name = scriptName + $" ({value})";
}
else
{
scriptNames[scriptName] = 0;
scriptConfig.Name = scriptName;
}
script.Name = DedupName(script.Name ?? "", scriptNames);
}
}

Expand Down