From 2e6f444285771b9b2735e4ae5fc1e37f8e8ed122 Mon Sep 17 00:00:00 2001 From: Vapre Date: Fri, 23 Jul 2021 23:12:17 +0200 Subject: [PATCH] Map.Contains check grid type once. --- OpenRA.Game/Map/Map.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 896a28a94c..9739028a14 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -788,16 +788,21 @@ 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 RectangularIsometric coordinate system, - // so we pre-filter these to avoid returning the wrong result - if (Grid.Type == MapGridType.RectangularIsometric && cell.X < cell.Y) - return false; - - // If the mod uses flat & rectangular maps, ToMPos and Contains(MPos) create unnecessary cost. - // Just check if CPos is within map bounds. - if (Grid.MaximumTerrainHeight == 0 && Grid.Type == MapGridType.Rectangular) - return Bounds.Contains(cell.X, cell.Y); + if (Grid.Type == MapGridType.RectangularIsometric) + { + // .ToMPos() returns the same result if the X and Y coordinates + // are switched. X < Y is invalid in the RectangularIsometric coordinate system, + // so we pre-filter these to avoid returning the wrong result + if (cell.X < cell.Y) + return false; + } + else + { + // If the mod uses flat & rectangular maps, ToMPos and Contains(MPos) create unnecessary cost. + // Just check if CPos is within map bounds. + if (Grid.MaximumTerrainHeight == 0) + return Bounds.Contains(cell.X, cell.Y); + } return Contains(cell.ToMPos(this)); }