Skip to content

Commit

Permalink
Fix hivemind auto launching
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Oct 19, 2024
1 parent ce22870 commit d73a3ff
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions RLBotCS/ManagerTools/MatchStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ int rlbotSocketsPort

private MatchSettingsT? _deferredMatchSettings;
private MatchSettingsT? _matchSettings;
private Dictionary<string, string> _hivemindNameMap = new();
private int _expectedConnections;
private int _connectionReadies;

Expand Down Expand Up @@ -92,6 +93,7 @@ public void MapSpawned(string MapName)
private void PreprocessMatch(MatchSettingsT matchSettings)
{
Dictionary<string, int> playerNames = [];
_hivemindNameMap.Clear();

foreach (var playerConfig in matchSettings.PlayerConfigurations)
{
Expand All @@ -108,6 +110,9 @@ private void PreprocessMatch(MatchSettingsT matchSettings)
playerConfig.Name = playerName;
}

if (playerConfig.Hivemind)
_hivemindNameMap[playerConfig.Name] = playerName;

if (playerConfig.SpawnId == 0)
playerConfig.SpawnId = playerConfig.Name.GetHashCode();

Expand All @@ -116,18 +121,19 @@ private void PreprocessMatch(MatchSettingsT matchSettings)
playerConfig.AgentId ??= "";
}

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

Expand Down Expand Up @@ -162,7 +168,7 @@ private void StartBots(MatchSettingsT matchSettings)
+ "_"
+ playerConfig.RunCommand
+ "_"
+ playerConfig.Name
+ _hivemindNameMap[playerConfig.Name]
+ "_"
+ playerConfig.Team;

Expand All @@ -175,6 +181,8 @@ private void StartBots(MatchSettingsT matchSettings)
}
}

_hivemindNameMap.Clear();

_connectionReadies = 0;
_expectedConnections = matchSettings.ScriptConfigurations.Count + processes.Count;

Expand Down

0 comments on commit d73a3ff

Please sign in to comment.