Map.Contains check grid type once.

This commit is contained in:
Vapre
2021-07-23 23:12:17 +02:00
committed by abcdefg30
parent dcaa658678
commit 2e6f444285

View File

@@ -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));
}