Correct Contains check in BridgeLayer.

This commit is contained in:
Paul Chote
2015-07-27 18:22:34 +01:00
parent 0b5b612757
commit 3a7300810c

View File

@@ -27,14 +27,12 @@ namespace OpenRA.Mods.Common.Traits
class BridgeLayer : IWorldLoaded class BridgeLayer : IWorldLoaded
{ {
readonly BridgeLayerInfo info; readonly BridgeLayerInfo info;
readonly World world;
Dictionary<ushort, Pair<string, int>> bridgeTypes = new Dictionary<ushort, Pair<string, int>>(); Dictionary<ushort, Pair<string, int>> bridgeTypes = new Dictionary<ushort, Pair<string, int>>();
CellLayer<Bridge> bridges; CellLayer<Bridge> bridges;
public BridgeLayer(Actor self, BridgeLayerInfo info) public BridgeLayer(Actor self, BridgeLayerInfo info)
{ {
this.info = info; this.info = info;
this.world = self.World;
} }
public void WorldLoaded(World w, WorldRenderer wr) public void WorldLoaded(World w, WorldRenderer wr)
@@ -81,6 +79,7 @@ namespace OpenRA.Mods.Common.Traits
}).Trait<Bridge>(); }).Trait<Bridge>();
var subTiles = new Dictionary<CPos, byte>(); var subTiles = new Dictionary<CPos, byte>();
var mapTiles = w.Map.MapTiles.Value;
// For each subtile in the template // For each subtile in the template
for (byte ind = 0; ind < template.Size.X * template.Size.Y; ind++) for (byte ind = 0; ind < template.Size.X * template.Size.Y; ind++)
@@ -89,8 +88,7 @@ namespace OpenRA.Mods.Common.Traits
var subtile = new CPos(ni + ind % template.Size.X, nj + ind / template.Size.X); var subtile = new CPos(ni + ind % template.Size.X, nj + ind / template.Size.X);
// This isn't the bridge you're looking for // This isn't the bridge you're looking for
if (!w.Map.Contains(subtile) || w.Map.MapTiles.Value[subtile].Type != tile || if (!mapTiles.Contains(subtile) || mapTiles[subtile].Type != tile || mapTiles[subtile].Index != ind)
w.Map.MapTiles.Value[subtile].Index != ind)
continue; continue;
subTiles.Add(subtile, ind); subTiles.Add(subtile, ind);
@@ -103,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits
// Used to check for neighbouring bridges // Used to check for neighbouring bridges
public Bridge GetBridge(CPos cell) public Bridge GetBridge(CPos cell)
{ {
if (!world.Map.Contains(cell)) if (!bridges.Contains(cell))
return null; return null;
return bridges[cell]; return bridges[cell];