diff --git a/DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs b/DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs index 28002e817..10a48a3a2 100644 --- a/DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs +++ b/DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs @@ -1557,7 +1557,11 @@ private void WriteMap(PlayerHouseInfo[] houseInfos) IniFile globalCodeIni = new IniFile(SafePath.CombineFilePath(ProgramConstants.GamePath, "INI", "Map Code", "GlobalCode.ini")); - MapCodeHelper.ApplyMapCode(mapIni, GameMode.GetMapRulesIniFile()); + foreach (IniFile iniFile in GameMode.GetMapRulesIniFiles(RandomSeed)) + { + MapCodeHelper.ApplyMapCode(mapIni, iniFile); + } + MapCodeHelper.ApplyMapCode(mapIni, globalCodeIni); if (isMultiplayer) diff --git a/DXMainClient/Domain/Multiplayer/GameMode.cs b/DXMainClient/Domain/Multiplayer/GameMode.cs index bad2b5d69..bdaa1d93a 100644 --- a/DXMainClient/Domain/Multiplayer/GameMode.cs +++ b/DXMainClient/Domain/Multiplayer/GameMode.cs @@ -3,6 +3,7 @@ using Rampastring.Tools; using System; using System.Collections.Generic; +using System.Linq; namespace DTAClient.Domain.Multiplayer { @@ -66,6 +67,8 @@ public GameMode(string name) public int MinPlayersOverride { get; private set; } = -1; private string mapCodeININame; + private List randomizedMapCodeININames; + private int randomizedMapCodesCount; private string forcedOptionsSection; @@ -92,6 +95,8 @@ public void Initialize() MinPlayersOverride = forcedOptionsIni.GetIntValue(Name, "MinPlayersOverride", -1); forcedOptionsSection = forcedOptionsIni.GetStringValue(Name, "ForcedOptions", string.Empty); mapCodeININame = forcedOptionsIni.GetStringValue(Name, "MapCodeININame", Name + ".ini"); + randomizedMapCodeININames = forcedOptionsIni.GetStringValue(Name, "RandomizedMapCodeININames", string.Empty).Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); + randomizedMapCodesCount = forcedOptionsIni.GetIntValue(Name, "RandomizedMapCodesCount", 1); string[] disallowedSides = forcedOptionsIni .GetStringValue(Name, "DisallowedPlayerSides", string.Empty) @@ -153,9 +158,24 @@ public void ApplySpawnIniCode(IniFile spawnIni) spawnIni.SetStringValue("Settings", key.Key, key.Value); } - public IniFile GetMapRulesIniFile() + public List GetMapRulesIniFiles(int randomSeed) { - return new IniFile(SafePath.CombineFilePath(ProgramConstants.GamePath, BASE_INI_PATH, mapCodeININame)); + var mapRules = new List() { new IniFile(SafePath.CombineFilePath(ProgramConstants.GamePath, BASE_INI_PATH, mapCodeININame)) }; + if (randomizedMapCodeININames.Count == 0) + return mapRules; + + Random random = new Random(randomSeed); + Dictionary randomOrder = new(); + foreach (string name in randomizedMapCodeININames) + { + randomOrder[name] = random.Next(); + } + + mapRules.AddRange( + from iniName in randomizedMapCodeININames.OrderBy(x => randomOrder[x]).Take(randomizedMapCodesCount) + select new IniFile(SafePath.CombineFilePath(ProgramConstants.GamePath, BASE_INI_PATH, iniName))); + + return mapRules; } protected bool Equals(GameMode other) => string.Equals(Name, other?.Name, StringComparison.InvariantCultureIgnoreCase);