diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 3767d51456..719e8eec89 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -155,7 +155,6 @@ namespace OpenRA [FieldLoader.Ignore] public List PlayerDefinitions = new List(); [FieldLoader.Ignore] public List ActorDefinitions = new List(); - [FieldLoader.Ignore] public List SmudgeDefinitions = new List(); // Binary map data [FieldLoader.Ignore] public byte TileFormat = 2; @@ -268,7 +267,6 @@ namespace OpenRA PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players"); ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors"); - SmudgeDefinitions = MiniYaml.NodesOrEmpty(yaml, "Smudges"); MapTiles = Exts.Lazy(LoadMapTiles); MapResources = Exts.Lazy(LoadResourceTiles); @@ -445,7 +443,6 @@ namespace OpenRA root.Add(new MiniYamlNode("Players", null, PlayerDefinitions)); root.Add(new MiniYamlNode("Actors", null, ActorDefinitions)); - root.Add(new MiniYamlNode("Smudges", null, SmudgeDefinitions)); root.Add(new MiniYamlNode("Rules", null, RuleDefinitions)); root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions)); root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions)); diff --git a/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs b/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs index 6239d63d5a..ff5013f7b0 100644 --- a/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs @@ -18,6 +18,12 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { + public struct MapSmudge + { + public string Type; + public int Depth; + } + [Desc("Attach this to the world actor.", "Order of the layers defines the Z sorting.")] public class SmudgeLayerInfo : ITraitInfo { @@ -36,6 +42,33 @@ namespace OpenRA.Mods.Common.Traits [PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName; + [FieldLoader.LoadUsing("LoadInitialSmudges")] + public readonly Dictionary InitialSmudges; + + public static object LoadInitialSmudges(MiniYaml yaml) + { + MiniYaml smudgeYaml; + var nd = yaml.ToDictionary(); + var smudges = new Dictionary(); + if (nd.TryGetValue("InitialSmudges", out smudgeYaml)) + { + foreach (var node in smudgeYaml.Nodes) + { + try + { + var cell = FieldLoader.GetValue("key", node.Key); + var parts = node.Value.Value.Split(','); + var type = parts[0]; + var depth = FieldLoader.GetValue("depth", parts[1]); + smudges.Add(cell, new MapSmudge { Type = type, Depth = depth }); + } + catch { } + } + } + + return smudges; + } + public object Create(ActorInitializer init) { return new SmudgeLayer(init.Self, this); } } @@ -85,28 +118,21 @@ namespace OpenRA.Mods.Common.Traits render = new TerrainSpriteLayer(w, wr, sheet, blendMode, wr.Palette(Info.Palette), wr.World.Type != WorldType.Editor); // Add map smudges - foreach (var s in w.Map.SmudgeDefinitions) + foreach (var kv in Info.InitialSmudges) { - var name = s.Key; - var vals = name.Split(' '); - var type = vals[0]; - - if (!smudges.ContainsKey(type)) + var s = kv.Value; + if (!smudges.ContainsKey(s.Type)) continue; - var loc = vals[1].Split(','); - var cell = new CPos(Exts.ParseIntegerInvariant(loc[0]), Exts.ParseIntegerInvariant(loc[1])); - var depth = Exts.ParseIntegerInvariant(vals[2]); - var smudge = new Smudge { - Type = type, - Depth = depth, - Sprite = smudges[type][depth] + Type = s.Type, + Depth = s.Depth, + Sprite = smudges[s.Type][s.Depth] }; - tiles.Add(cell, smudge); - render.Update(cell, smudge.Sprite); + tiles.Add(kv.Key, smudge); + render.Update(kv.Key, smudge.Sprite); } } diff --git a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs index b64cfe17c9..1c0b73a4cb 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs @@ -273,14 +273,40 @@ namespace OpenRA.Mods.Common.UtilityCommands static void LoadSmudges(IniFile file, string section, int mapSize, Map map) { + var scorches = new List(); + var craters = new List(); foreach (var s in file.GetSection(section, true)) { // loc=type,loc,depth var parts = s.Value.Split(','); var loc = Exts.ParseIntegerInvariant(parts[1]); - var key = "{0} {1},{2} {3}".F(parts[0].ToLowerInvariant(), loc % mapSize, loc / mapSize, Exts.ParseIntegerInvariant(parts[2])); - map.SmudgeDefinitions.Add(new MiniYamlNode(key, "")); + var type = parts[0].ToLowerInvariant(); + var key = "{0},{1}".F(loc % mapSize, loc / mapSize); + var value = "{0},{1}".F(type, parts[2]); + var node = new MiniYamlNode(key, value); + if (type.StartsWith("sc")) + scorches.Add(node); + else if (type.StartsWith("cr")) + craters.Add(node); } + + var worldNode = new MiniYamlNode("World", new MiniYaml("", new List())); + if (scorches.Any()) + { + var initialScorches = new MiniYamlNode("InitialSmudges", new MiniYaml("", scorches)); + var smudgeLayer = new MiniYamlNode("SmudgeLayer@SCORCH", new MiniYaml("", new List() { initialScorches })); + worldNode.Value.Nodes.Add(smudgeLayer); + } + + if (craters.Any()) + { + var initialCraters = new MiniYamlNode("InitialSmudges", new MiniYaml("", craters)); + var smudgeLayer = new MiniYamlNode("SmudgeLayer@CRATER", new MiniYaml("", new List() { initialCraters })); + worldNode.Value.Nodes.Add(smudgeLayer); + } + + if (worldNode.Value.Nodes.Any()) + map.RuleDefinitions.Add(worldNode); } // TODO: fix this -- will have bitrotted pretty badly.