diff --git a/OpenRA.Game/GameRules/Ruleset.cs b/OpenRA.Game/GameRules/Ruleset.cs index cdda718822..86c5fb5211 100644 --- a/OpenRA.Game/GameRules/Ruleset.cs +++ b/OpenRA.Game/GameRules/Ruleset.cs @@ -27,6 +27,7 @@ namespace OpenRA public readonly IReadOnlyDictionary Voices; public readonly IReadOnlyDictionary Notifications; public readonly IReadOnlyDictionary Music; + public readonly ITerrainInfo TerrainInfo; public readonly TileSet TileSet; public readonly SequenceProvider Sequences; public readonly IReadOnlyDictionary ModelSequences; @@ -46,6 +47,7 @@ namespace OpenRA Voices = voices; Notifications = notifications; Music = music; + TerrainInfo = tileSet; TileSet = tileSet; Sequences = sequences; ModelSequences = modelSequences; diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index e960177a4b..4287087ffb 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -283,7 +283,7 @@ namespace OpenRA /// Initializes a new map created by the editor or importer. /// The map will not receive a valid UID until after it has been saved and reloaded. /// - public Map(ModData modData, TileSet tileset, int width, int height) + public Map(ModData modData, ITerrainInfo terrainInfo, int width, int height) { this.modData = modData; var size = new Size(width, height); @@ -293,7 +293,7 @@ namespace OpenRA Author = "Your name here"; MapSize = new int2(size); - Tileset = tileset.Id; + Tileset = terrainInfo.Id; // Empty rules that can be added to by the importers. // Will be dropped on save if nothing is added to it @@ -310,7 +310,7 @@ namespace OpenRA Tiles.CellEntryChanged += UpdateRamp; } - Tiles.Clear(tileset.DefaultTerrainTile); + Tiles.Clear(terrainInfo.DefaultTerrainTile); PostInit(); } @@ -431,14 +431,14 @@ namespace OpenRA CustomTerrain[uv] = byte.MaxValue; // Replace invalid tiles and cache ramp state - var tileset = Rules.TileSet; + var terrainInfo = Rules.TerrainInfo; foreach (var uv in AllCells.MapCoords) { - if (!tileset.TryGetTileInfo(Tiles[uv], out var info)) + if (!terrainInfo.TryGetTerrainInfo(Tiles[uv], out var info)) { ReplacedInvalidTerrainTiles[uv.ToCPos(this)] = Tiles[uv]; - Tiles[uv] = tileset.DefaultTerrainTile; - info = tileset.GetTileInfo(tileset.DefaultTerrainTile); + Tiles[uv] = terrainInfo.DefaultTerrainTile; + info = terrainInfo.GetTerrainInfo(terrainInfo.DefaultTerrainTile); } Ramp[uv] = info.RampType; @@ -449,7 +449,7 @@ namespace OpenRA void UpdateRamp(CPos cell) { - Ramp[cell] = Rules.TileSet.GetTileInfo(Tiles[cell]).RampType; + Ramp[cell] = Rules.TerrainInfo.GetTerrainInfo(Tiles[cell]).RampType; } void InitializeCellProjection() @@ -536,8 +536,7 @@ namespace OpenRA // The original games treat the top of cliffs the same way as the bottom // This information isn't stored in the map data, so query the offset from the tileset var temp = inverse.MaxBy(uv => uv.V); - var terrain = Tiles[temp]; - return (byte)(Height[temp] - Rules.TileSet.Templates[terrain.Type][terrain.Index].Height); + return (byte)(Height[temp] - Rules.TerrainInfo.GetTerrainInfo(Tiles[temp]).Height); } // Try the next cell down if this is a cliff face @@ -673,8 +672,8 @@ namespace OpenRA public (Color Left, Color Right) GetTerrainColorPair(MPos uv) { Color left, right; - var tileset = Rules.TileSet; - var type = tileset.GetTileInfo(Tiles[uv]); + var terrainInfo = Rules.TerrainInfo; + var type = terrainInfo.GetTerrainInfo(Tiles[uv]); if (type.MinColor != type.MaxColor) { left = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor); @@ -683,9 +682,9 @@ namespace OpenRA else left = right = type.MinColor; - if (tileset.MinHeightColorBrightness != 1.0f || tileset.MaxHeightColorBrightness != 1.0f) + if (terrainInfo.MinHeightColorBrightness != 1.0f || terrainInfo.MaxHeightColorBrightness != 1.0f) { - var scale = float2.Lerp(tileset.MinHeightColorBrightness, tileset.MaxHeightColorBrightness, Height[uv] * 1f / Grid.MaximumTerrainHeight); + var scale = float2.Lerp(terrainInfo.MinHeightColorBrightness, terrainInfo.MaxHeightColorBrightness, Height[uv] * 1f / Grid.MaximumTerrainHeight); left = Color.FromArgb((int)(scale * left.R).Clamp(0, 255), (int)(scale * left.G).Clamp(0, 255), (int)(scale * left.B).Clamp(0, 255)); right = Color.FromArgb((int)(scale * right.R).Clamp(0, 255), (int)(scale * right.G).Clamp(0, 255), (int)(scale * right.B).Clamp(0, 255)); } @@ -1071,8 +1070,7 @@ namespace OpenRA if (terrainIndex == InvalidCachedTerrainIndex) { var custom = CustomTerrain[uv]; - terrainIndex = cachedTerrainIndexes[uv] = - custom != byte.MaxValue ? custom : Rules.TileSet.GetTerrainIndex(Tiles[uv]); + terrainIndex = cachedTerrainIndexes[uv] = custom != byte.MaxValue ? custom : Rules.TerrainInfo.GetTerrainInfo(Tiles[uv]).TerrainType; } return (byte)terrainIndex; @@ -1080,7 +1078,7 @@ namespace OpenRA public TerrainTypeInfo GetTerrainInfo(CPos cell) { - return Rules.TileSet[GetTerrainIndex(cell)]; + return Rules.TerrainInfo.TerrainTypes[GetTerrainIndex(cell)]; } public CPos Clamp(CPos cell) diff --git a/OpenRA.Game/Map/TileSet.cs b/OpenRA.Game/Map/TileSet.cs index 4d6338c12a..a6189def17 100644 --- a/OpenRA.Game/Map/TileSet.cs +++ b/OpenRA.Game/Map/TileSet.cs @@ -18,6 +18,22 @@ using OpenRA.Traits; namespace OpenRA { + public interface ITerrainInfo + { + string Id { get; } + TerrainTypeInfo[] TerrainTypes { get; } + TerrainTileInfo GetTerrainInfo(TerrainTile r); + bool TryGetTerrainInfo(TerrainTile r, out TerrainTileInfo info); + byte GetTerrainIndex(string type); + byte GetTerrainIndex(TerrainTile r); + TerrainTile DefaultTerrainTile { get; } + + Color[] HeightDebugColors { get; } + IEnumerable RestrictedPlayerColors { get; } + float MinHeightColorBrightness { get; } + float MaxHeightColorBrightness { get; } + } + public class TerrainTileInfo { [FieldLoader.Ignore] @@ -54,7 +70,7 @@ namespace OpenRA readonly TerrainTileInfo[] tileInfo; - public TerrainTemplateInfo(TileSet tileSet, MiniYaml my) + public TerrainTemplateInfo(ITerrainInfo terrainInfo, MiniYaml my) { FieldLoader.Load(this, my); @@ -66,12 +82,12 @@ namespace OpenRA foreach (var node in nodes) { if (!int.TryParse(node.Key, out var key)) - throw new YamlException("Tileset `{0}` template `{1}` defines a frame `{2}` that is not a valid integer.".F(tileSet.Id, Id, node.Key)); + throw new YamlException("Tileset `{0}` template `{1}` defines a frame `{2}` that is not a valid integer.".F(terrainInfo.Id, Id, node.Key)); if (key < 0 || key >= tileInfo.Length) - throw new YamlException("Tileset `{0}` template `{1}` references frame {2}, but only [0..{3}] are valid for a {4}x{5} Size template.".F(tileSet.Id, Id, key, tileInfo.Length - 1, Size.X, Size.Y)); + throw new YamlException("Tileset `{0}` template `{1}` references frame {2}, but only [0..{3}] are valid for a {4}x{5} Size template.".F(terrainInfo.Id, Id, key, tileInfo.Length - 1, Size.X, Size.Y)); - tileInfo[key] = LoadTileInfo(tileSet, node.Value); + tileInfo[key] = LoadTileInfo(terrainInfo, node.Value); } } else @@ -82,30 +98,30 @@ namespace OpenRA foreach (var node in nodes) { if (!int.TryParse(node.Key, out var key)) - throw new YamlException("Tileset `{0}` template `{1}` defines a frame `{2}` that is not a valid integer.".F(tileSet.Id, Id, node.Key)); + throw new YamlException("Tileset `{0}` template `{1}` defines a frame `{2}` that is not a valid integer.".F(terrainInfo.Id, Id, node.Key)); if (key != i++) - throw new YamlException("Tileset `{0}` template `{1}` is missing a definition for frame {2}.".F(tileSet.Id, Id, i - 1)); + throw new YamlException("Tileset `{0}` template `{1}` is missing a definition for frame {2}.".F(terrainInfo.Id, Id, i - 1)); - tileInfo[key] = LoadTileInfo(tileSet, node.Value); + tileInfo[key] = LoadTileInfo(terrainInfo, node.Value); } } } - static TerrainTileInfo LoadTileInfo(TileSet tileSet, MiniYaml my) + static TerrainTileInfo LoadTileInfo(ITerrainInfo terrainInfo, MiniYaml my) { var tile = new TerrainTileInfo(); FieldLoader.Load(tile, my); // Terrain type must be converted from a string to an index - tile.GetType().GetField("TerrainType").SetValue(tile, tileSet.GetTerrainIndex(my.Value)); + tile.GetType().GetField("TerrainType").SetValue(tile, terrainInfo.GetTerrainIndex(my.Value)); // Fall back to the terrain-type color if necessary - var overrideColor = tileSet.TerrainInfo[tile.TerrainType].Color; - if (tile.MinColor == default(Color)) + var overrideColor = terrainInfo.TerrainTypes[tile.TerrainType].Color; + if (tile.MinColor == default) tile.GetType().GetField("MinColor").SetValue(tile, overrideColor); - if (tile.MaxColor == default(Color)) + if (tile.MaxColor == default) tile.GetType().GetField("MaxColor").SetValue(tile, overrideColor); return tile; @@ -124,7 +140,7 @@ namespace OpenRA } } - public class TileSet + public class TileSet : ITerrainInfo { public const string TerrainPaletteInternalName = "terrain"; @@ -245,6 +261,14 @@ namespace OpenRA return info != null; } - public TerrainTile DefaultTerrainTile { get { return new TerrainTile(Templates.First().Key, 0); } } + string ITerrainInfo.Id { get { return Id; } } + TerrainTypeInfo[] ITerrainInfo.TerrainTypes { get { return TerrainInfo; } } + TerrainTileInfo ITerrainInfo.GetTerrainInfo(TerrainTile r) { return GetTileInfo(r); } + bool ITerrainInfo.TryGetTerrainInfo(TerrainTile r, out TerrainTileInfo info) { return TryGetTileInfo(r, out info); } + Color[] ITerrainInfo.HeightDebugColors { get { return HeightDebugColors; } } + IEnumerable ITerrainInfo.RestrictedPlayerColors { get { return TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color); } } + float ITerrainInfo.MinHeightColorBrightness { get { return MinHeightColorBrightness; } } + float ITerrainInfo.MaxHeightColorBrightness { get { return MaxHeightColorBrightness; } } + TerrainTile ITerrainInfo.DefaultTerrainTile { get { return new TerrainTile(Templates.First().Key, 0); } } } } diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs index 365eef0841..9449410e71 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs @@ -88,8 +88,8 @@ namespace OpenRA.Mods.Common.Widgets return false; var tile = world.Map.Tiles[cell]; - var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile); - var terrainType = world.Map.Rules.TileSet.TerrainInfo[tileInfo.TerrainType]; + var tileInfo = world.Map.Rules.TerrainInfo.GetTerrainInfo(tile); + var terrainType = world.Map.Rules.TerrainInfo.TerrainTypes[tileInfo.TerrainType]; if (mapResources[cell].Type == ResourceType.ResourceType) return false; diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index 48b6d8326f..dde2984eb9 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -386,8 +386,7 @@ namespace OpenRA.Mods.Common.Server // Pick a random color for the bot var validator = server.ModData.Manifest.Get(); - var tileset = server.Map.Rules.TileSet; - var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color); + var terrainColors = server.Map.Rules.TerrainInfo.RestrictedPlayerColors; var playerColors = server.LobbyInfo.Clients.Select(c => c.Color) .Concat(server.Map.Players.Players.Values.Select(p => p.Color)); bot.Color = bot.PreferredColor = validator.RandomPresetColor(server.Random, terrainColors, playerColors); @@ -1105,8 +1104,7 @@ namespace OpenRA.Mods.Common.Server server.SendOrderTo(connectionToEcho, "Message", message); }; - var tileset = server.Map.Rules.TileSet; - var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color).ToList(); + var terrainColors = server.Map.Rules.TerrainInfo.RestrictedPlayerColors; var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color) .Concat(server.Map.Players.Players.Values.Select(p => p.Color)).ToList(); diff --git a/OpenRA.Mods.Common/Traits/AppearsOnMapPreview.cs b/OpenRA.Mods.Common/Traits/AppearsOnMapPreview.cs index 73d83c870b..d865348be8 100644 --- a/OpenRA.Mods.Common/Traits/AppearsOnMapPreview.cs +++ b/OpenRA.Mods.Common/Traits/AppearsOnMapPreview.cs @@ -28,14 +28,13 @@ namespace OpenRA.Mods.Common.Traits void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer) { - var tileSet = map.Rules.TileSet; - Color color; if (!string.IsNullOrEmpty(Terrain)) { - color = tileSet[tileSet.GetTerrainIndex(Terrain)].Color; + var terrainInfo = map.Rules.TerrainInfo; + color = terrainInfo.TerrainTypes[terrainInfo.GetTerrainIndex(Terrain)].Color; } - else if (Color != default(Color)) + else if (Color != default) { color = Color; } diff --git a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs index 8e8a12c7f9..58afdeb2ca 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs @@ -173,10 +173,10 @@ namespace OpenRA.Mods.Common.Traits protected override void TraitEnabled(Actor self) { - var tileset = world.Map.Rules.TileSet; - resourceTypeIndices = new BitArray(tileset.TerrainInfo.Length); // Big enough + var terrainInfo = world.Map.Rules.TerrainInfo; + resourceTypeIndices = new BitArray(terrainInfo.TerrainTypes.Length); // Big enough foreach (var t in world.Map.Rules.Actors["world"].TraitInfos()) - resourceTypeIndices.Set(tileset.GetTerrainIndex(t.TerrainType), true); + resourceTypeIndices.Set(terrainInfo.GetTerrainIndex(t.TerrainType), true); foreach (var building in Info.BuildingQueues) builders.Add(new BaseBuilderQueueManager(this, building, player, playerPower, playerResources, resourceTypeIndices)); diff --git a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs index 66268d3b39..ee21b15210 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs @@ -77,8 +77,7 @@ namespace OpenRA.Mods.Common.Traits { bridgeLayer.Add(self); - var tileSet = self.World.Map.Rules.TileSet; - var terrainIndex = tileSet.GetTerrainIndex(Info.TerrainType); + var terrainIndex = self.World.Map.Rules.TerrainInfo.GetTerrainIndex(Info.TerrainType); UpdateTerrain(self, terrainIndex); KillInvalidActorsInFootprint(self); } diff --git a/OpenRA.Mods.Common/Traits/ChangesTerrain.cs b/OpenRA.Mods.Common/Traits/ChangesTerrain.cs index bd6f564976..6ea3ee35d8 100644 --- a/OpenRA.Mods.Common/Traits/ChangesTerrain.cs +++ b/OpenRA.Mods.Common/Traits/ChangesTerrain.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits { var cell = self.Location; var map = self.World.Map; - var terrain = map.Rules.TileSet.GetTerrainIndex(info.TerrainType); + var terrain = map.Rules.TerrainInfo.GetTerrainIndex(info.TerrainType); previousTerrain = map.CustomTerrain[cell]; map.CustomTerrain[cell] = terrain; } diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs index edf1ee4106..8f5f6b6467 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits public class GrantConditionOnTerrain : ITick { readonly GrantConditionOnTerrainInfo info; - readonly TileSet tileSet; + readonly TerrainTypeInfo[] terrainTypes; int conditionToken = Actor.InvalidConditionToken; string cachedTerrain; @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info) { this.info = info; - tileSet = init.World.Map.Rules.TileSet; + terrainTypes = init.World.Map.Rules.TerrainInfo.TerrainTypes; } void ITick.Tick(Actor self) @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits // The terrain type may change between ticks without the actor moving var currentTerrain = cell.Layer == 0 ? self.World.Map.GetTerrainInfo(cell).Type : - tileSet[self.World.GetCustomMovementLayers()[cell.Layer].GetTerrainIndex(cell)].Type; + terrainTypes[self.World.GetCustomMovementLayers()[cell.Layer].GetTerrainIndex(cell)].Type; var wantsGranted = info.TerrainTypes.Contains(currentTerrain); if (currentTerrain != cachedTerrain) diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs index f75dcc3cd1..9776ff7955 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits { this.info = info; rotationBuffer = new uint[info.RotationRange]; - tilesetId = world.Map.Rules.TileSet.Id; + tilesetId = world.Map.Rules.TerrainInfo.Id; validTileset = IsValidTileset(); } diff --git a/OpenRA.Mods.Common/Traits/Player/PlayerRadarTerrain.cs b/OpenRA.Mods.Common/Traits/Player/PlayerRadarTerrain.cs index 9fdb107c1c..41a315f1a3 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlayerRadarTerrain.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlayerRadarTerrain.cs @@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits var custom = map.CustomTerrain[uv]; if (custom != byte.MaxValue) { - var c = map.Rules.TileSet[custom].Color.ToArgb(); + var c = map.Rules.TerrainInfo.TerrainTypes[custom].Color.ToArgb(); return (c, c); } diff --git a/OpenRA.Mods.Common/Traits/Radar/RadarColorFromTerrain.cs b/OpenRA.Mods.Common/Traits/Radar/RadarColorFromTerrain.cs index 039b4c2de5..82466d7ea7 100644 --- a/OpenRA.Mods.Common/Traits/Radar/RadarColorFromTerrain.cs +++ b/OpenRA.Mods.Common/Traits/Radar/RadarColorFromTerrain.cs @@ -21,8 +21,8 @@ namespace OpenRA.Mods.Common.Traits.Radar public Color GetColorFromTerrain(World world) { - var tileSet = world.Map.Rules.TileSet; - return tileSet[tileSet.GetTerrainIndex(Terrain)].Color; + var terrainInfo = world.Map.Rules.TerrainInfo; + return terrainInfo.TerrainTypes[terrainInfo.GetTerrainIndex(Terrain)].Color; } public override object Create(ActorInitializer init) { return new RadarColorFromTerrain(init.Self, this); } diff --git a/OpenRA.Mods.Common/Traits/World/CliffBackImpassabilityLayer.cs b/OpenRA.Mods.Common/Traits/World/CliffBackImpassabilityLayer.cs index 6ef2f683c9..0432f17c2e 100644 --- a/OpenRA.Mods.Common/Traits/World/CliffBackImpassabilityLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/CliffBackImpassabilityLayer.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits public void WorldLoaded(World w, WorldRenderer wr) { - var tileType = w.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType); + var tileType = w.Map.Rules.TerrainInfo.GetTerrainIndex(info.TerrainType); // Units are allowed behind cliffs *only* if they are part of a tunnel portal var tunnelPortals = w.WorldActor.Info.TraitInfos() diff --git a/OpenRA.Mods.Common/Traits/World/DomainIndex.cs b/OpenRA.Mods.Common/Traits/World/DomainIndex.cs index 5856dcce34..35c07ca98f 100644 --- a/OpenRA.Mods.Common/Traits/World/DomainIndex.cs +++ b/OpenRA.Mods.Common/Traits/World/DomainIndex.cs @@ -23,13 +23,11 @@ namespace OpenRA.Mods.Common.Traits public class DomainIndex : IWorldLoaded { - TileSet tileSet; Dictionary domainIndexes; public void WorldLoaded(World world, WorldRenderer wr) { domainIndexes = new Dictionary(); - tileSet = world.Map.Rules.TileSet; var locomotors = world.WorldActor.TraitsImplementing().Where(l => !string.IsNullOrEmpty(l.Info.Name)); var movementClasses = locomotors.Select(t => t.MovementClass).Distinct(); diff --git a/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs index 9374faac08..f95e4c564f 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits for (var x = 0; x < TerrainTemplate.Size.X; x++) { var tile = new TerrainTile(TerrainTemplate.Id, (byte)i++); - if (!world.Map.Rules.TileSet.TryGetTileInfo(tile, out var tileInfo)) + if (!world.Map.Rules.TerrainInfo.TryGetTerrainInfo(tile, out var tileInfo)) continue; var sprite = terrainRenderer.TileSprite(tile, 0); diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs index 65a3b3ce4f..188a3f4f7f 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs @@ -26,7 +26,6 @@ namespace OpenRA.Mods.Common.Traits public class EditorResourceLayer : IResourceLayer, IWorldLoaded, INotifyActorDisposing { protected readonly Map Map; - protected readonly TileSet Tileset; protected readonly Dictionary Resources; protected readonly CellLayer Tiles; @@ -45,8 +44,6 @@ namespace OpenRA.Mods.Common.Traits return; Map = self.World.Map; - Tileset = self.World.Map.Rules.TileSet; - Tiles = new CellLayer(Map); Resources = self.TraitsImplementing() .ToDictionary(r => r.Info.ResourceType, r => r); @@ -82,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits Density = CalculateCellDensity(type, cell) }; - newTerrain = Tileset.GetTerrainIndex(type.Info.TerrainType); + newTerrain = Map.Rules.TerrainInfo.GetTerrainIndex(type.Info.TerrainType); } // Nothing has changed diff --git a/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs b/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs index 702c513159..c802203803 100644 --- a/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits map = self.World.Map; cellCenters = new CellLayer(map); terrainIndices = new CellLayer(map); - terrainIndices.Clear(map.Rules.TileSet.GetTerrainIndex(info.ImpassableTerrainType)); + terrainIndices.Clear(map.Rules.TerrainInfo.GetTerrainIndex(info.ImpassableTerrainType)); } public void WorldLoaded(World world, WorldRenderer wr) @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits { enabled = true; - var terrain = map.Rules.TileSet.GetTerrainIndex(tti.TerrainType); + var terrain = map.Rules.TerrainInfo.GetTerrainIndex(tti.TerrainType); foreach (var c in tti.BridgeCells()) { var uv = c.ToMPos(map); diff --git a/OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs b/OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs index 45357b94d5..9ac5eccb26 100644 --- a/OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/JumpjetActorLayer.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits public JumpjetActorLayer(Actor self, JumpjetActorLayerInfo info) { map = self.World.Map; - terrainIndex = self.World.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType); + terrainIndex = self.World.Map.Rules.TerrainInfo.GetTerrainIndex(info.TerrainType); height = new CellLayer(map); var cellHeight = self.World.Map.CellHeightStep.Length; foreach (var c in map.AllCells) diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index a0b885a7d7..c651e11d22 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -161,10 +161,10 @@ namespace OpenRA.Mods.Common.Traits sharesCell = info.SharesCell; world = self.World; - var tileSet = world.Map.Rules.TileSet; - terrainInfos = new LocomotorInfo.TerrainInfo[tileSet.TerrainInfo.Length]; + var terrainInfo = world.Map.Rules.TerrainInfo; + terrainInfos = new LocomotorInfo.TerrainInfo[terrainInfo.TerrainTypes.Length]; for (var i = 0; i < terrainInfos.Length; i++) - if (!info.TerrainSpeeds.TryGetValue(tileSet.TerrainInfo[i].Type, out terrainInfos[i])) + if (!info.TerrainSpeeds.TryGetValue(terrainInfo.TerrainTypes[i].Type, out terrainInfos[i])) terrainInfos[i] = LocomotorInfo.TerrainInfo.Impassable; MovementClass = (uint)terrainInfos.Select(ti => ti.Cost < short.MaxValue).ToBits(); diff --git a/OpenRA.Mods.Common/Traits/World/PaletteFromFile.cs b/OpenRA.Mods.Common/Traits/World/PaletteFromFile.cs index df1a390960..f6df7a10d9 100644 --- a/OpenRA.Mods.Common/Traits/World/PaletteFromFile.cs +++ b/OpenRA.Mods.Common/Traits/World/PaletteFromFile.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits get { // Only expose the palette if it is available for the shellmap's tileset (which is a requirement for its use). - if (info.Tileset == null || info.Tileset == world.Map.Rules.TileSet.Id) + if (info.Tileset == null || info.Tileset == world.Map.Rules.TerrainInfo.Id) yield return info.Name; } } diff --git a/OpenRA.Mods.Common/Traits/World/PaletteFromGimpOrJascFile.cs b/OpenRA.Mods.Common/Traits/World/PaletteFromGimpOrJascFile.cs index 2c39f98b60..c93b63ddcc 100644 --- a/OpenRA.Mods.Common/Traits/World/PaletteFromGimpOrJascFile.cs +++ b/OpenRA.Mods.Common/Traits/World/PaletteFromGimpOrJascFile.cs @@ -130,8 +130,8 @@ namespace OpenRA.Mods.Common.Traits get { // Only expose the palette if it is available for the shellmap's tileset (which is a requirement for its use). - if ((info.Tilesets.Count == 0 || info.Tilesets.Contains(world.Map.Rules.TileSet.Id)) - && !info.ExcludeTilesets.Contains(world.Map.Rules.TileSet.Id)) + if ((info.Tilesets.Count == 0 || info.Tilesets.Contains(world.Map.Rules.TerrainInfo.Id)) + && !info.ExcludeTilesets.Contains(world.Map.Rules.TerrainInfo.Id)) yield return info.Name; } } diff --git a/OpenRA.Mods.Common/Traits/World/PaletteFromPng.cs b/OpenRA.Mods.Common/Traits/World/PaletteFromPng.cs index 68172c3d30..eab000b9a9 100644 --- a/OpenRA.Mods.Common/Traits/World/PaletteFromPng.cs +++ b/OpenRA.Mods.Common/Traits/World/PaletteFromPng.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits get { // Only expose the palette if it is available for the shellmap's tileset (which is a requirement for its use). - if (info.Tileset == null || info.Tileset == world.Map.Rules.TileSet.Id) + if (info.Tileset == null || info.Tileset == world.Map.Rules.TerrainInfo.Id) yield return info.Name; } } diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs index f80f31b75b..1be2637a4f 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs @@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Traits ResourceLayerContents CreateResourceCell(ResourceType t, CPos cell) { - world.Map.CustomTerrain[cell] = world.Map.Rules.TileSet.GetTerrainIndex(t.Info.TerrainType); + world.Map.CustomTerrain[cell] = world.Map.Rules.TerrainInfo.GetTerrainIndex(t.Info.TerrainType); ++resCells; return new ResourceLayerContents diff --git a/OpenRA.Mods.Common/Traits/World/ResourceType.cs b/OpenRA.Mods.Common/Traits/World/ResourceType.cs index e08bb0352a..67402dc6af 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceType.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceType.cs @@ -65,8 +65,8 @@ namespace OpenRA.Mods.Common.Traits void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos, Color)> destinationBuffer) { - var tileSet = map.Rules.TileSet; - var color = tileSet[tileSet.GetTerrainIndex(TerrainType)].Color; + var terrainInfo = map.Rules.TerrainInfo; + var color = terrainInfo.TerrainTypes[terrainInfo.GetTerrainIndex(TerrainType)].Color; for (var i = 0; i < map.MapSize.X; i++) { diff --git a/OpenRA.Mods.Common/Traits/World/SubterraneanActorLayer.cs b/OpenRA.Mods.Common/Traits/World/SubterraneanActorLayer.cs index 316c986c5b..17920550e8 100644 --- a/OpenRA.Mods.Common/Traits/World/SubterraneanActorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/SubterraneanActorLayer.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits public SubterraneanActorLayer(Actor self, SubterraneanActorLayerInfo info) { map = self.World.Map; - terrainIndex = self.World.Map.Rules.TileSet.GetTerrainIndex(info.TerrainType); + terrainIndex = self.World.Map.Rules.TerrainInfo.GetTerrainIndex(info.TerrainType); height = new CellLayer(map); foreach (var c in map.AllCells) { diff --git a/OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs b/OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs index f8a4f04fd1..5f0b52f7ce 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs @@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Traits yield break; var map = wr.World.Map; - var tileSet = wr.World.Map.Rules.TileSet; - var colors = tileSet.HeightDebugColors; + var colors = wr.World.Map.Rules.TerrainInfo.HeightDebugColors; var mouseCell = wr.Viewport.ViewToWorld(Viewport.LastMousePos).ToMPos(wr.World.Map); foreach (var uv in wr.Viewport.AllVisibleCells.CandidateMapCoords) diff --git a/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs b/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs index 0ff10c0188..361b993dff 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits map = self.World.Map; cellCenters = new CellLayer(map); terrainIndices = new CellLayer(map); - terrainIndices.Clear(map.Rules.TileSet.GetTerrainIndex(info.ImpassableTerrainType)); + terrainIndices.Clear(map.Rules.TerrainInfo.GetTerrainIndex(info.ImpassableTerrainType)); } public void WorldLoaded(World world, WorldRenderer wr) @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits { enabled = true; - var terrain = map.Rules.TileSet.GetTerrainIndex(tti.TerrainType); + var terrain = map.Rules.TerrainInfo.GetTerrainIndex(tti.TerrainType); foreach (var c in tti.TunnelCells()) { var uv = c.ToMPos(map); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs index b277e23523..e6dfc3c86b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ownersDropDown.Text = selectedOwner.Name; ownersDropDown.TextColor = selectedOwner.Color; - var tileSetId = world.Map.Rules.TileSet.Id; + var tileSetId = world.Map.Rules.TerrainInfo.Id; var allActorsTemp = new List(); foreach (var a in mapRules.Actors.Values) { @@ -209,7 +209,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic catch { Log.Write("debug", "Map editor ignoring actor {0}, because of missing sprites for tileset {1}.", - actor.Name, World.Map.Rules.TileSet.Id); + actor.Name, World.Map.Rules.TerrainInfo.Id); continue; } } diff --git a/OpenRA.Mods.D2k/Traits/World/BuildableTerrainLayer.cs b/OpenRA.Mods.D2k/Traits/World/BuildableTerrainLayer.cs index 095fce8894..14d502ed8c 100644 --- a/OpenRA.Mods.D2k/Traits/World/BuildableTerrainLayer.cs +++ b/OpenRA.Mods.D2k/Traits/World/BuildableTerrainLayer.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.D2k.Traits if (!strength.Contains(cell)) return; - world.Map.CustomTerrain[cell] = world.Map.Rules.TileSet.GetTerrainIndex(tile); + world.Map.CustomTerrain[cell] = world.Map.Rules.TerrainInfo.GetTerrainIndex(tile); strength[cell] = info.MaxStrength; dirty[cell] = tile; }