public void SetExitPathNodes() { for (int x = X - 1; x <= X + Type.Size; x++) { if (x < 0 || x > Rts.map.Width - 1) { continue; } for (int y = Y - 1; y <= Y + Type.Size; y++) { if (y < 0 || y > Rts.map.Height - 1) { continue; } PathNode pathNode = Rts.pathFinder.PathNodes[y, x]; if (pathNode.Tile.Walkable && !pathNode.Blocked) { exitPathNodes.Add(Rts.pathFinder.PathNodes[y, x]); } } } //foreach (PathNode pathNode in exitPathNodes) for (int i = 0; i < exitPathNodes.Count;) { PathNode pathNode = exitPathNodes[i]; bool good = false; foreach (PathNode neighbor in pathNode.Neighbors) { if (OccupiedPathNodes.Contains(neighbor)) { good = true; } } if (!good) { exitPathNodes.Remove(pathNode); } else { i++; } } }
void setOccupiedPathNodes() { for (int x = X; x < X + size; x++) { for (int y = Y; y < Y + size; y++) { PathNode node = Rts.pathFinder.PathNodes[y, x]; if (Intersects(node.Tile)) { OccupiedPathNodes.Add(node); node.Blocked = true; node.Blocker = this; } } } if (type.CutCorners) { OccupiedPathNodes.Remove(Rts.pathFinder.PathNodes[Y, X]); Rts.pathFinder.PathNodes[Y, X].Blocked = false; Rts.pathFinder.PathNodes[Y, X].Blocker = null; exitPathNodes.Add(Rts.pathFinder.PathNodes[Y, X]); OccupiedPathNodes.Remove(Rts.pathFinder.PathNodes[Y, X + size - 1]); Rts.pathFinder.PathNodes[Y, X + size - 1].Blocked = false; Rts.pathFinder.PathNodes[Y, X + size - 1].Blocker = null; exitPathNodes.Add(Rts.pathFinder.PathNodes[Y, X + size - 1]); OccupiedPathNodes.Remove(Rts.pathFinder.PathNodes[Y + size - 1, X]); Rts.pathFinder.PathNodes[Y + size - 1, X].Blocked = false; Rts.pathFinder.PathNodes[Y + size - 1, X].Blocker = null; exitPathNodes.Add(Rts.pathFinder.PathNodes[Y + size - 1, X]); OccupiedPathNodes.Remove(Rts.pathFinder.PathNodes[Y + size - 1, X + size - 1]); Rts.pathFinder.PathNodes[Y + size - 1, X + size - 1].Blocked = false; Rts.pathFinder.PathNodes[Y + size - 1, X + size - 1].Blocker = null; exitPathNodes.Add(Rts.pathFinder.PathNodes[Y + size - 1, X + size - 1]); } }
void setExitPathNodes() { for (int x = X - 1; x <= X + type.Size; x++) { if (x < 0 || x > Rts.map.Width - 1) { continue; } for (int y = Y - 1; y <= Y + type.Size; y++) { if (y < 0 || y > Rts.map.Height - 1) { continue; } if (Rts.pathFinder.PathNodes[y, x].Tile.Walkable && !Rts.pathFinder.PathNodes[y, x].Blocked) { exitPathNodes.Add(Rts.pathFinder.PathNodes[y, x]); } } } //foreach (PathNode pathNode in exitPathNodes) for (int i = 0; i < exitPathNodes.Count;) { PathNode pathNode = exitPathNodes[i]; bool good = false; foreach (PathNode neighbor in pathNode.Neighbors) { if (OccupiedPathNodes.Contains(neighbor)) { good = true; } } if (!good) { exitPathNodes.Remove(pathNode); } else { i++; } } /*for (int x = X - 1; x <= X + type.Size; x++) * { * if (x < 0 || x > Map.Width - 1) * continue; * * if (!(Y - 1 < 0) && PathFinder.PathNodes[Y - 1, x].Tile.Walkable && !PathFinder.PathNodes[Y - 1, x].Blocked) * exitPathNodes.Add(PathFinder.PathNodes[Y - 1, x]); * * if (x == X - 1 || x == X + type.Size) * { * for (int y = Y; y <= Y + type.Size; y++) * { * if (y < 0 || y > Map.Height - 1) * continue; * * if (PathFinder.PathNodes[y, x].Tile.Walkable && !PathFinder.PathNodes[y, x].Blocked) * exitPathNodes.Add(PathFinder.PathNodes[y, x]); * } * } * * if (!(Y + type.Size > Map.Height - 1) && PathFinder.PathNodes[Y + type.Size, x].Tile.Walkable && !PathFinder.PathNodes[Y + type.Size, x].Blocked) * exitPathNodes.Add(PathFinder.PathNodes[Y + type.Size, x]); * }*/ }