public int GetDistanceSquaredToArea(XPoint2 pnt, RMArea area, int minDist) { Debug.Assert(area.Built, "GetDistanceSquaredToArea() does not work for unbuilt areas"); int sizeX = Map.GetLength(0), sizeY = Map.GetLength(1); XRectangle range = area.ActiveArea; range.RestrictToWithin(new XRectangle(pnt.X, pnt.Y, 1, 1)); range.Inflate(minDist); range.RestrictToWithin(new XRectangle(0, 0, sizeX, sizeY)); int minDist2 = int.MaxValue; for (int x = range.Left; x < range.Right; ++x) { for (int y = range.Top; y < range.Bottom; ++y) { int dx = x - pnt.X, dy = y - pnt.Y; int dist2 = dx * dx + dy * dy; if (dist2 > minDist * minDist) { continue; } var tile = Map[x, y]; if (tile != null) { while (tile != area && tile.Parent != null) { tile = tile.Parent; } } if (tile == area) { if (dist2 < minDist2) { minDist2 = dist2; } } } } return(minDist2); }
public void SetTileArea(XPoint2 pnt, RMArea area) { Map[pnt.X, pnt.Y] = area; }