Add support for diamond cell grids.

This commit is contained in:
Paul Chote
2014-06-30 11:25:39 +12:00
parent af0e948a67
commit a30c8b53a7
11 changed files with 191 additions and 82 deletions

View File

@@ -23,25 +23,26 @@ namespace OpenRA
// Corners of the region
public readonly CPos TopLeft;
public readonly CPos BottomRight;
readonly TileShape shape;
// Corners in map coordinates
// Defined for forward compatibility with diagonal cell grids
// These will only equal TopLeft and BottomRight for TileShape.Rectangular
readonly CPos mapTopLeft;
readonly CPos mapBottomRight;
public CellRegion(CPos topLeft, CPos bottomRight)
public CellRegion(TileShape shape, CPos topLeft, CPos bottomRight)
{
this.shape = shape;
TopLeft = topLeft;
BottomRight = bottomRight;
mapTopLeft = TopLeft;
mapBottomRight = BottomRight;
mapTopLeft = Map.CellToMap(shape, TopLeft);
mapBottomRight = Map.CellToMap(shape, BottomRight);
}
public bool Contains(CPos cell)
{
// Defined for forward compatibility with diagonal cell grids
var uv = cell;
var uv = Map.CellToMap(shape, cell);
return uv.X >= mapTopLeft.X && uv.X <= mapBottomRight.X && uv.Y >= mapTopLeft.Y && uv.Y <= mapBottomRight.Y;
}
@@ -93,7 +94,7 @@ namespace OpenRA
v = r.mapTopLeft.Y;
}
public CPos Current { get { return new CPos(u, v); } }
public CPos Current { get { return Map.MapToCell(r.shape, new CPos(u, v)); } }
object IEnumerator.Current { get { return Current; } }
public void Dispose() { }
}