From 26ce7b5e1c3e6f8c7eaf359e14faaedf9954e470 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 25 Jun 2015 17:24:34 +0100 Subject: [PATCH] Fix incorrect uses of Map.Bounds. --- OpenRA.Mods.Common/Traits/World/BridgeLayer.cs | 12 +++--------- OpenRA.Mods.Common/Traits/World/DomainIndex.cs | 7 +++++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs b/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs index 6f5fc6d4d2..85579f6c36 100644 --- a/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs @@ -50,15 +50,9 @@ namespace OpenRA.Mods.Common.Traits } // Loop through the map looking for templates to overlay - for (var i = w.Map.Bounds.Left; i < w.Map.Bounds.Right; i++) - { - for (var j = w.Map.Bounds.Top; j < w.Map.Bounds.Bottom; j++) - { - var cell = new CPos(i, j); - if (bridgeTypes.ContainsKey(w.Map.MapTiles.Value[cell].Type)) - ConvertBridgeToActor(w, cell); - } - } + foreach (var cell in w.Map.AllCells) + if (bridgeTypes.ContainsKey(w.Map.MapTiles.Value[cell].Type)) + ConvertBridgeToActor(w, cell); // Link adjacent (long)-bridges so that artwork is updated correctly foreach (var b in w.Actors.SelectMany(a => a.TraitsImplementing())) diff --git a/OpenRA.Mods.Common/Traits/World/DomainIndex.cs b/OpenRA.Mods.Common/Traits/World/DomainIndex.cs index b2db3f00ec..d716461489 100644 --- a/OpenRA.Mods.Common/Traits/World/DomainIndex.cs +++ b/OpenRA.Mods.Common/Traits/World/DomainIndex.cs @@ -159,6 +159,9 @@ namespace OpenRA.Mods.Common.Traits bool CanTraverseTile(World world, CPos p) { + if (!map.Contains(p)) + return false; + var terrainOffset = world.Map.GetTerrainIndex(p); return (movementClass & (1 << terrainOffset)) > 0; } @@ -172,7 +175,7 @@ namespace OpenRA.Mods.Common.Traits var visited = new CellLayer(map); var toProcess = new Queue(); - toProcess.Enqueue(new CPos(map.Bounds.Left, map.Bounds.Top)); + toProcess.Enqueue(MPos.Zero.ToCPos(map)); // Flood-fill over each domain while (toProcess.Count != 0) @@ -209,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits // Don't crawl off the map, or add already-visited cells var neighbors = CVec.Directions.Select(d => n + d) - .Where(p => map.Contains(p) && !visited[p]); + .Where(p => visited.Contains(p) && !visited[p]); foreach (var neighbor in neighbors) domainQueue.Enqueue(neighbor);