From ce331a28e89e0202267a761017dd16320180fbbb Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 17 May 2014 01:30:00 +1200 Subject: [PATCH] Use CellLayer for custom terrain. --- OpenRA.Game/Map/Map.cs | 8 ++++---- OpenRA.Game/Traits/World/ResourceLayer.cs | 6 +++--- OpenRA.Mods.RA/Bridge.cs | 4 ++-- OpenRA.Mods.RA/Buildings/LaysTerrain.cs | 4 ++-- OpenRA.Mods.RA/World/BuildableTerrainLayer.cs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 4fc1858558..d1afb17bd9 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -113,7 +113,7 @@ namespace OpenRA [FieldLoader.Ignore] public Lazy[,]> MapTiles; [FieldLoader.Ignore] public Lazy[,]> MapResources; - [FieldLoader.Ignore] public int[,] CustomTerrain; + [FieldLoader.Ignore] public CellLayer CustomTerrain; [FieldLoader.Ignore] Lazy rules; public Ruleset Rules { get { return rules != null ? rules.Value : null; } } @@ -257,9 +257,9 @@ namespace OpenRA var br = new CPos(Bounds.Right - 1, Bounds.Bottom - 1); Cells = new CellRegion(tl, br); - CustomTerrain = new int[MapSize.X, MapSize.Y]; + CustomTerrain = new CellLayer(this); foreach (var cell in Cells) - CustomTerrain[cell.X, cell.Y] = -1; + CustomTerrain[cell] = -1; } public Ruleset PreloadRules() @@ -548,7 +548,7 @@ namespace OpenRA public int GetTerrainIndex(CPos cell) { - var custom = CustomTerrain[cell.X, cell.Y]; + var custom = CustomTerrain[cell]; var tileSet = Rules.TileSets[Tileset]; return custom != -1 ? custom : tileSet.GetTerrainIndex(MapTiles.Value[cell.X, cell.Y]); } diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index ccddaa948d..223491949f 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -151,7 +151,7 @@ namespace OpenRA.Traits CellContents CreateResourceCell(ResourceType t, CPos cell) { - world.Map.CustomTerrain[cell.X, cell.Y] = world.TileSet.GetTerrainIndex(t.Info.TerrainType); + world.Map.CustomTerrain[cell] = world.TileSet.GetTerrainIndex(t.Info.TerrainType); return new CellContents { @@ -190,7 +190,7 @@ namespace OpenRA.Traits if (--c.Density < 0) { content[cell] = EmptyCell; - world.Map.CustomTerrain[cell.X, cell.Y] = -1; + world.Map.CustomTerrain[cell] = -1; } else content[cell] = c; @@ -209,7 +209,7 @@ namespace OpenRA.Traits // Clear cell content[cell] = EmptyCell; - world.Map.CustomTerrain[cell.X, cell.Y] = -1; + world.Map.CustomTerrain[cell] = -1; if (!dirty.Contains(cell)) dirty.Add(cell); diff --git a/OpenRA.Mods.RA/Bridge.cs b/OpenRA.Mods.RA/Bridge.cs index aa34689d44..fc87dc4927 100644 --- a/OpenRA.Mods.RA/Bridge.cs +++ b/OpenRA.Mods.RA/Bridge.cs @@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA // Set the initial custom terrain types foreach (var c in footprint.Keys) - self.World.Map.CustomTerrain[c.X, c.Y] = GetTerrainType(c); + self.World.Map.CustomTerrain[c] = GetTerrainType(c); } int GetTerrainType(CPos cell) @@ -204,7 +204,7 @@ namespace OpenRA.Mods.RA // Update map foreach (var c in footprint.Keys) - self.World.Map.CustomTerrain[c.X, c.Y] = GetTerrainType(c); + self.World.Map.CustomTerrain[c] = GetTerrainType(c); // If this bridge repair operation connects two pathfinding domains, // update the domain index. diff --git a/OpenRA.Mods.RA/Buildings/LaysTerrain.cs b/OpenRA.Mods.RA/Buildings/LaysTerrain.cs index 02e3391b4c..f079df6807 100755 --- a/OpenRA.Mods.RA/Buildings/LaysTerrain.cs +++ b/OpenRA.Mods.RA/Buildings/LaysTerrain.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Buildings continue; // Don't place under other buildings or custom terrain - if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c.X, c.Y] != -1) + if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != -1) continue; var index = Game.CosmeticRandom.Next(template.TilesCount); @@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA.Buildings continue; // Don't place under other buildings or custom terrain - if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c.X, c.Y] != -1) + if (bi.GetBuildingAt(c) != self || map.CustomTerrain[c] != -1) continue; layer.AddTile(c, new TileReference(template.Id, (byte)i)); diff --git a/OpenRA.Mods.RA/World/BuildableTerrainLayer.cs b/OpenRA.Mods.RA/World/BuildableTerrainLayer.cs index 4a07267f9f..fdca2da8cc 100644 --- a/OpenRA.Mods.RA/World/BuildableTerrainLayer.cs +++ b/OpenRA.Mods.RA/World/BuildableTerrainLayer.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA public void AddTile(CPos cell, TileReference tile) { - map.CustomTerrain[cell.X, cell.Y] = tileset.GetTerrainIndex(tile); + map.CustomTerrain[cell] = tileset.GetTerrainIndex(tile); // Terrain tiles define their origin at the topleft var s = theater.TileSprite(tile);