public PathingNode(HexVector pPosition, float pDistanceFromEnd, PathingNode pOrigin) : this(pPosition, pDistanceFromEnd) { Origin = pOrigin; }
public Hex(HexVector pPosition) { position = pPosition; }
//Constructors public PathingNode(HexVector pPosition, float pDistanceFromEnd) { CurrentPosition = pPosition; fltDistanceFromEnd = pDistanceFromEnd; }
public PathingHex(HexVector pPosition, bool pObstacle) : this(pPosition, pObstacle, 0) { }
public PathingHex(HexVector pPosition, bool pObstacle, int pHeight) : base(pPosition) { blnObstacle = pObstacle; intHeight = pHeight; }
//Constructor public PathingHex(HexVector pPosition) : this(pPosition, false, 0) { }
//Functions public Path FindPath(HexVector pStart, HexVector pEnd) { return(FindPath(pStart, pEnd, int.MaxValue)); }
public Path FindPath(HexVector pStart, HexVector pEnd, int pMaxHeightDifference) { //Check if start and end exist if (Exists(pStart) && Exists(pEnd)) { //Variables List <HexVector> arrClosed = new List <HexVector>(); //List of all positions that are already checked List <PathingNode> arrOpen = new List <PathingNode>(); //List of all positions that are not checked but are neightbours of checked hexes arrOpen.Add(new PathingNode(pStart, HexVector.Distance(pStart, pEnd))); //Loop until path found while (arrOpen.Count > 0) { //Take lowest cost node PathingNode CurrentNode = arrOpen[0]; for (int intN = 1; intN < arrOpen.Count; intN++) { if ((arrOpen[intN].Cost < CurrentNode.Cost) || (arrOpen[intN].Cost == CurrentNode.Cost && arrOpen[intN].CostFromEnd < CurrentNode.CostFromEnd)) { CurrentNode = arrOpen[intN]; } } arrOpen.Remove(CurrentNode); arrClosed.Add(CurrentNode.Position); //Test if path is found if (CurrentNode.Position.Equals(pEnd)) { return(new Path(CurrentNode)); } //Get neighbours List <HexTemplateType> arrNeighbours = base.GetNeighbours(CurrentNode.Position); foreach (HexTemplateType thisHex in arrNeighbours) { if (thisHex.IsObstacle || arrClosed.Contains(thisHex.Position) || Mathf.Abs(Get(CurrentNode.Position).Height - thisHex.Height) > pMaxHeightDifference) { continue; } else { //Search if node already exists PathingNode neighbourNode = null; neighbourNode = arrOpen.Find(h => (h.Position.Equals(thisHex.Position))); if (neighbourNode == null) { //Make a node for the new hex float fltDistanceToEnd = HexVector.Distance(thisHex.Position, pEnd); neighbourNode = new PathingNode(thisHex.Position, fltDistanceToEnd, CurrentNode); arrOpen.Add(neighbourNode); } else { //update the found hex's origin neighbourNode.OriginNode = CurrentNode; } } } } return(null); } return(null); }
public override bool Equals(object obj) { HexVector other = (HexVector)obj; return(other.X == X && other.Y == Y && other.Z == Z); }
//Functions public HexVector Add(HexVector pAdd) { return(new HexVector(X + pAdd.X, Y + pAdd.Y)); }