diff --git a/OpenRA.Game/Map/CellLayer.cs b/OpenRA.Game/Map/CellLayer.cs index 6f5112307e..311c47c21f 100644 --- a/OpenRA.Game/Map/CellLayer.cs +++ b/OpenRA.Game/Map/CellLayer.cs @@ -125,10 +125,25 @@ namespace OpenRA return GetEnumerator(); } + public bool Contains(CPos cell) + { + return Contains(cell.ToMPos(Shape)); + } + public bool Contains(MPos uv) { return bounds.Contains(uv.U, uv.V); } + + public CPos Clamp(CPos uv) + { + return Clamp(uv.ToMPos(Shape)).ToCPos(Shape); + } + + public MPos Clamp(MPos uv) + { + return uv.Clamp(new Rectangle(0, 0, Size.Width - 1, Size.Height - 1)); + } } // Helper functions diff --git a/OpenRA.Game/Map/CellRegion.cs b/OpenRA.Game/Map/CellRegion.cs index bae6d7e0bd..7920498a0a 100644 --- a/OpenRA.Game/Map/CellRegion.cs +++ b/OpenRA.Game/Map/CellRegion.cs @@ -217,6 +217,9 @@ namespace OpenRA { return GetEnumerator(); } + + public MPos TopLeft { get { return r.mapTopLeft; } } + public MPos BottomRight { get { return r.mapBottomRight; } } } } } diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 142d169a37..a3d1fb7c7f 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -772,6 +772,12 @@ namespace OpenRA return cell.ToMPos(this).Clamp(bounds).ToCPos(this); } + public MPos Clamp(MPos uv) + { + var bounds = new Rectangle(Bounds.X, Bounds.Y, Bounds.Width - 1, Bounds.Height - 1); + return uv.Clamp(bounds); + } + public CPos ChooseRandomCell(MersenneTwister rand) { var x = rand.Next(Bounds.Left, Bounds.Right);