diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 4287087ffb..c757ebf841 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -1020,33 +1020,6 @@ namespace OpenRA ProjectedCells = new ProjectedCellRegion(this, tl, br).ToArray(); } - public void FixOpenAreas() - { - var r = new Random(); - var tileset = Rules.TileSet; - - for (var j = Bounds.Top; j < Bounds.Bottom; j++) - { - for (var i = Bounds.Left; i < Bounds.Right; i++) - { - var type = Tiles[new MPos(i, j)].Type; - var index = Tiles[new MPos(i, j)].Index; - if (!tileset.Templates.ContainsKey(type)) - { - Console.WriteLine("Unknown Tile ID {0}".F(type)); - continue; - } - - var template = tileset.Templates[type]; - if (!template.PickAny) - continue; - - index = (byte)r.Next(0, template.TilesCount); - Tiles[new MPos(i, j)] = new TerrainTile(type, index); - } - } - } - public byte GetTerrainIndex(CPos cell) { const short InvalidCachedTerrainIndex = -1; diff --git a/OpenRA.Game/Map/TileSet.cs b/OpenRA.Game/Map/TileSet.cs index a6189def17..6b4afbba9c 100644 --- a/OpenRA.Game/Map/TileSet.cs +++ b/OpenRA.Game/Map/TileSet.cs @@ -14,6 +14,7 @@ using System.IO; using System.Linq; using OpenRA.FileSystem; using OpenRA.Primitives; +using OpenRA.Support; using OpenRA.Traits; namespace OpenRA @@ -34,6 +35,11 @@ namespace OpenRA float MaxHeightColorBrightness { get; } } + public interface ITerrainInfoNotifyMapCreated : ITerrainInfo + { + void MapCreated(Map map); + } + public class TerrainTileInfo { [FieldLoader.Ignore] @@ -140,7 +146,7 @@ namespace OpenRA } } - public class TileSet : ITerrainInfo + public class TileSet : ITerrainInfo, ITerrainInfoNotifyMapCreated { public const string TerrainPaletteInternalName = "terrain"; @@ -270,5 +276,22 @@ namespace OpenRA float ITerrainInfo.MinHeightColorBrightness { get { return MinHeightColorBrightness; } } float ITerrainInfo.MaxHeightColorBrightness { get { return MaxHeightColorBrightness; } } TerrainTile ITerrainInfo.DefaultTerrainTile { get { return new TerrainTile(Templates.First().Key, 0); } } + + void ITerrainInfoNotifyMapCreated.MapCreated(Map map) + { + // Randomize PickAny tile variants + var r = new MersenneTwister(); + for (var j = map.Bounds.Top; j < map.Bounds.Bottom; j++) + { + for (var i = map.Bounds.Left; i < map.Bounds.Right; i++) + { + var type = map.Tiles[new MPos(i, j)].Type; + if (!Templates.TryGetValue(type, out var template) || !template.PickAny) + continue; + + map.Tiles[new MPos(i, j)] = new TerrainTile(type, (byte)r.Next(0, template.TilesCount)); + } + } + } } } diff --git a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs index a7c6cd3e7e..56ea987367 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs @@ -99,7 +99,8 @@ namespace OpenRA.Mods.Common.UtilityCommands Map.PlayerDefinitions = MapPlayers.ToMiniYaml(); } - Map.FixOpenAreas(); + if (Map.Rules.TerrainInfo is ITerrainInfoNotifyMapCreated notifyMapCreated) + notifyMapCreated.MapCreated(Map); var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap"; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs index 3d196df2a5..70e9174360 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs @@ -62,7 +62,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic map.SetBounds(tl, br); map.PlayerDefinitions = new MapPlayers(map.Rules, 0).ToMiniYaml(); - map.FixOpenAreas(); + + if (map.Rules.TerrainInfo is ITerrainInfoNotifyMapCreated notifyMapCreated) + notifyMapCreated.MapCreated(map); Action afterSave = uid => {