namespace Holo.Virtual.Rooms.Pathfinding { using Holo.Virtual.Rooms; using System; using System.Collections; public class DenDribbelaerPathfinder { private Heap Closed = new Heap(); private mapNode Goal; private int maxX; private int maxY; private Heap Open = new Heap(); private double[,] squareHeights; private virtualRoom.squareState[,] squareStates; private bool[,] squareUnitFlags; private mapNode Start; private ArrayList Successors = new ArrayList(); public DenDribbelaerPathfinder(virtualRoom.squareState[,] squareStates, double[,] squareHeights, bool[,] squareUnitFlags) { this.squareStates = squareStates; this.squareHeights = squareHeights; this.squareUnitFlags = squareUnitFlags; this.maxX = squareUnitFlags.GetLength(1) - 1; this.maxY = squareUnitFlags.GetLength(0) - 1; } public Coord getNext(int X, int Y, int goalX, int goalY) { if ((X == goalX) && (Y == goalY)) { return new Coord(-1, 0); } int num = (this.maxX * this.maxY) ^ 2; int num2 = 0; ArrayList list = new ArrayList(); this.Goal = new mapNode(goalX, goalY, 0.0, null, null, null); this.Start = new mapNode(X, Y, 0.0, null, this.Goal, null); this.Goal.Start = this.Goal; this.Start.Start = this.Start; this.Open.Add(this.Start); while (this.Open.Count > 0) { if (num2 >= num) { return new Coord(-1, 0); } num2++; mapNode parent = (mapNode) this.Open.Pop(); if ((parent.X == this.Goal.X) && (parent.Y == this.Goal.Y)) { while (parent != null) { list.Insert(0, parent); parent = parent.Parent; } break; } foreach (mapNode node2 in parent.Successors(this)) { mapNode node3 = null; if (this.Open.Contains(node2)) { node3 = (mapNode) this.Open[this.Open.IndexOf(node2)]; if (node2.totalCost > node3.totalCost) { continue; } } mapNode node4 = null; if (this.Closed.Contains(node2)) { node4 = (mapNode) this.Closed[this.Closed.IndexOf(node2)]; if (node2.totalCost > node4.totalCost) { continue; } } this.Open.Remove(node2); this.Closed.Remove(node2); this.Open.Push(node2); } this.Closed.Add(parent); } if (list.Count == 0) { return new Coord(-1, 0); } mapNode node5 = (mapNode) list[1]; return new Coord(node5.X, node5.Y); } public dribbelaerPath getPath(int X, int Y, int goalX, int goalY) { if ((X == goalX) && (Y == goalY)) { return null; } int num = (this.maxX * this.maxY) ^ 2; int num2 = 0; dribbelaerPath path = new dribbelaerPath(); this.Goal = new mapNode(goalX, goalY, 0.0, null, null, null); this.Start = new mapNode(X, Y, 0.0, null, this.Goal, null); this.Goal.Start = this.Goal; this.Start.Start = this.Start; this.Open.Add(this.Start); while (this.Open.Count > 0) { if (num2 >= num) { return null; } num2++; mapNode o = (mapNode) this.Open.Pop(); if ((o.X == this.Goal.X) && (o.Y == this.Goal.Y)) { while (o != null) { path.Coords.Push(new Coord(o.X, o.Y)); o = o.Parent; } break; } foreach (mapNode node2 in o.Successors(this)) { mapNode node3 = null; if (this.Open.Contains(node2)) { node3 = (mapNode) this.Open[this.Open.IndexOf(node2)]; if (node2.totalCost > node3.totalCost) { continue; } } mapNode node4 = null; if (this.Closed.Contains(node2)) { node4 = (mapNode) this.Closed[this.Closed.IndexOf(node2)]; if (node2.totalCost > node4.totalCost) { continue; } } this.Open.Remove(node2); this.Closed.Remove(node2); this.Open.Push(node2); } this.Closed.Add(o); } if (path.Coords.Count == 0) { return null; } return path; } public bool Passable(int X, int Y, int goalX, int goalY) { try { if (this.squareUnitFlags[goalX, goalY] || ((this.squareStates[goalX, goalY] != virtualRoom.squareState.Open) && (this.squareStates[goalX, goalY] != virtualRoom.squareState.Rug))) { return false; } return true; } catch { return false; } } } }