Esempio n. 1
0
 public PathingNode(HexVector pPosition, float pDistanceFromEnd, PathingNode pOrigin) : this(pPosition, pDistanceFromEnd)
 {
     Origin = pOrigin;
 }
Esempio n. 2
0
 public Hex(HexVector pPosition)
 {
     position = pPosition;
 }
Esempio n. 3
0
 //Constructors
 public PathingNode(HexVector pPosition, float pDistanceFromEnd)
 {
     CurrentPosition    = pPosition;
     fltDistanceFromEnd = pDistanceFromEnd;
 }
Esempio n. 4
0
 public PathingHex(HexVector pPosition, bool pObstacle) : this(pPosition, pObstacle, 0)
 {
 }
Esempio n. 5
0
 public PathingHex(HexVector pPosition, bool pObstacle, int pHeight) : base(pPosition)
 {
     blnObstacle = pObstacle;
     intHeight   = pHeight;
 }
Esempio n. 6
0
 //Constructor
 public PathingHex(HexVector pPosition) : this(pPosition, false, 0)
 {
 }
Esempio n. 7
0
 //Functions
 public Path FindPath(HexVector pStart, HexVector pEnd)
 {
     return(FindPath(pStart, pEnd, int.MaxValue));
 }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        public override bool Equals(object obj)
        {
            HexVector other = (HexVector)obj;

            return(other.X == X && other.Y == Y && other.Z == Z);
        }
Esempio n. 10
0
 //Functions
 public HexVector Add(HexVector pAdd)
 {
     return(new HexVector(X + pAdd.X, Y + pAdd.Y));
 }