From 31cec0c17fd6f36e656ce366dc0eb23279711767 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Tue, 2 Nov 2021 23:14:07 +0100 Subject: [PATCH] Fix a crash in the TSResourceLayer neighbour validation --- OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs b/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs index 53f8ae1359..5a0fedac0a 100644 --- a/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs @@ -74,6 +74,9 @@ namespace OpenRA.Mods.Cnc.Traits bool IsValidResourceNeighbour(CPos cell, CPos neighbour) { + if (!Map.Contains(neighbour)) + return false; + // Non-vein resources are not allowed in the cardinal neighbours to // an already existing vein cell return Content[neighbour].Type != info.VeinType; @@ -81,6 +84,9 @@ namespace OpenRA.Mods.Cnc.Traits bool IsValidVeinNeighbour(CPos cell, CPos neighbour) { + if (!Map.Contains(neighbour)) + return false; + // Cell is automatically valid if it contains a veinhole actor if (veinholeCells.Contains(neighbour)) return true; @@ -112,8 +118,7 @@ namespace OpenRA.Mods.Cnc.Traits // Ensure there is space for the vein border tiles (not needed on ramps) var check = resourceType == info.VeinType ? (Func)IsValidVeinNeighbour : IsValidResourceNeighbour; - var blockedByNeighbours = Map.Ramp[cell] == 0 && !Common.Util.ExpandFootprint(cell, false) - .All(c => check(cell, c)); + var blockedByNeighbours = Map.Ramp[cell] == 0 && !Common.Util.ExpandFootprint(cell, false).All(c => check(cell, c)); return !blockedByNeighbours && (resourceType == info.VeinType || !BuildingInfluence.AnyBuildingAt(cell)); }