From ba2d499e5d900e5857db7ceea61ccb05ff1a01c9 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Jun 2015 22:49:10 +0100 Subject: [PATCH] Fix a bug in Map/CellLayer.Contains. --- OpenRA.Game/Map/CellLayer.cs | 6 ++++++ OpenRA.Game/Map/Map.cs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/OpenRA.Game/Map/CellLayer.cs b/OpenRA.Game/Map/CellLayer.cs index 311c47c21f..6825ecb439 100644 --- a/OpenRA.Game/Map/CellLayer.cs +++ b/OpenRA.Game/Map/CellLayer.cs @@ -127,6 +127,12 @@ namespace OpenRA public bool Contains(CPos cell) { + // .ToMPos() returns the same result if the X and Y coordinates + // are switched. X < Y is invalid in the Diamond coordinate system, + // so we pre-filter these to avoid returning the wrong result + if (Shape == TileShape.Diamond && cell.X < cell.Y) + return false; + return Contains(cell.ToMPos(Shape)); } diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index a3d1fb7c7f..c733e3d90e 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -630,6 +630,12 @@ namespace OpenRA public bool Contains(CPos cell) { + // .ToMPos() returns the same result if the X and Y coordinates + // are switched. X < Y is invalid in the Diamond coordinate system, + // so we pre-filter these to avoid returning the wrong result + if (TileShape == TileShape.Diamond && cell.X < cell.Y) + return false; + return Contains(cell.ToMPos(this)); }