//Check that a node can be created here private int GetTerrainCost(int x, int y) { //Check the boundary if (!_boundary.Contains(x, y)) { return(-1); } TerrainPoint node = _terrain.Get(x, y); if (node.IsEmpty) { return(0); } return(-1); }
//Check the terrain between the two points private bool CheckTerrain(Point a, Point b) { if (_terrain.Count == 0) { return(true); } int start; int end; if (a.X == b.X) { if (a.Y < b.Y) { start = a.Y; end = b.Y; } else { start = b.Y; end = a.Y; } } else { if (a.X < b.X) { start = a.X; end = b.X; } else { start = b.X; end = a.X; } } //Round the start and end onto the grid start = Convert.ToInt32(start / _grain) * _grain; end = Convert.ToInt32(end / _grain) * _grain; //Round the other coordinate of the pair int div = (a.X == b.X) ? a.X : a.Y; div = Convert.ToInt32(div / _grain) * _grain; //Get the starting movement cost TerrainPoint node = _terrain.Get(div, start); int cost = (node.IsEmpty) ? 0 : -1; //Loop through the terrain checking for a node with movement cost for (int i = start; i < end; i += _grain) { node = new TerrainPoint(); if (a.X == b.X) { node = _terrain.Get(div, i); } else { node = _terrain.Get(i, div); } if (!node.IsEmpty) { return(false); } } return(true); }