diff --git a/OpenRA.Game/Graphics/Theater.cs b/OpenRA.Game/Graphics/Theater.cs index b80625d627..2406867f64 100644 --- a/OpenRA.Game/Graphics/Theater.cs +++ b/OpenRA.Game/Graphics/Theater.cs @@ -168,10 +168,7 @@ namespace OpenRA.Graphics for (var x = 0; x < template.Size.X; x++) { var tile = new TerrainTile(template.Id, (byte)(i++)); - var tileInfo = tileset.GetTileInfo(tile); - - // Empty tile - if (tileInfo == null) + if (!tileset.TryGetTileInfo(tile, out var tileInfo)) continue; var sprite = TileSprite(tile); diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index a7f51e3228..c1958f55f4 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -450,8 +450,7 @@ namespace OpenRA void UpdateRamp(CPos cell) { - var tile = Rules.TileSet.GetTileInfo(Tiles[cell]); - Ramp[cell] = tile != null ? tile.RampType : (byte)0; + Ramp[cell] = Rules.TileSet.GetTileInfo(Tiles[cell]).RampType; } void InitializeCellProjection() @@ -677,25 +676,20 @@ namespace OpenRA Color left, right; var tileset = Rules.TileSet; var type = tileset.GetTileInfo(Tiles[uv]); - if (type != null) + if (type.MinColor != type.MaxColor) { - if (type.MinColor != type.MaxColor) - { - left = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor); - right = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor); - } - else - left = right = type.MinColor; - - if (tileset.MinHeightColorBrightness != 1.0f || tileset.MaxHeightColorBrightness != 1.0f) - { - var scale = float2.Lerp(tileset.MinHeightColorBrightness, tileset.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)); - } + left = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor); + right = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor); } else - left = right = Color.Black; + left = right = type.MinColor; + + if (tileset.MinHeightColorBrightness != 1.0f || tileset.MaxHeightColorBrightness != 1.0f) + { + var scale = float2.Lerp(tileset.MinHeightColorBrightness, tileset.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)); + } return (left, right); } diff --git a/OpenRA.Game/Map/TileSet.cs b/OpenRA.Game/Map/TileSet.cs index eb8e9ade42..4d6338c12a 100644 --- a/OpenRA.Game/Map/TileSet.cs +++ b/OpenRA.Game/Map/TileSet.cs @@ -221,25 +221,16 @@ namespace OpenRA public byte GetTerrainIndex(TerrainTile r) { - if (!Templates.TryGetValue(r.Type, out var tpl)) - return defaultWalkableTerrainIndex; - - if (tpl.Contains(r.Index)) - { - var tile = tpl[r.Index]; - if (tile != null && tile.TerrainType != byte.MaxValue) - return tile.TerrainType; - } + var tile = Templates[r.Type][r.Index]; + if (tile.TerrainType != byte.MaxValue) + return tile.TerrainType; return defaultWalkableTerrainIndex; } public TerrainTileInfo GetTileInfo(TerrainTile r) { - if (!Templates.TryGetValue(r.Type, out var tpl)) - return null; - - return tpl.Contains(r.Index) ? tpl[r.Index] : null; + return Templates[r.Type][r.Index]; } public bool TryGetTileInfo(TerrainTile r, out TerrainTileInfo info) diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs index b2a98414c0..365eef0841 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs @@ -89,9 +89,6 @@ namespace OpenRA.Mods.Common.Widgets var tile = world.Map.Tiles[cell]; var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile); - if (tileInfo == null) - return false; - var terrainType = world.Map.Rules.TileSet.TerrainInfo[tileInfo.TerrainType]; if (mapResources[cell].Type == ResourceType.ResourceType) diff --git a/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs index 42fb5f436d..aff10d8da4 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs @@ -78,10 +78,7 @@ namespace OpenRA.Mods.Common.Traits for (var x = 0; x < TerrainTemplate.Size.X; x++) { var tile = new TerrainTile(TerrainTemplate.Id, (byte)i++); - var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile); - - // Empty tile - if (tileInfo == null) + if (!world.Map.Rules.TileSet.TryGetTileInfo(tile, out var tileInfo)) continue; var sprite = wr.Theater.TileSprite(tile, 0); diff --git a/OpenRA.Mods.Common/Widgets/TerrainTemplatePreviewWidget.cs b/OpenRA.Mods.Common/Widgets/TerrainTemplatePreviewWidget.cs index bb2e9510a9..a9f889f7cd 100644 --- a/OpenRA.Mods.Common/Widgets/TerrainTemplatePreviewWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TerrainTemplatePreviewWidget.cs @@ -81,10 +81,7 @@ namespace OpenRA.Mods.Common.Widgets for (var x = 0; x < Template.Size.X; x++) { var tile = new TerrainTile(Template.Id, (byte)(i++)); - var tileInfo = tileset.GetTileInfo(tile); - - // Empty tile - if (tileInfo == null) + if (!tileset.TryGetTileInfo(tile, out var tileInfo)) continue; var sprite = worldRenderer.Theater.TileSprite(tile, 0);