Exemple #1
0
 public List<PathFindingSystem.PFNode> FindPath(Vector2 v2StartPos, Vector2 v2EndPos)
 {
     if (this.lxNodes.Count == 0)
     {
         return null;
     }
     PathFindingSystem.PFNode xStart = this.FindClosestWithVision(v2StartPos);
     PathFindingSystem.PFNode xEnd = this.FindClosestWithVision(v2EndPos);
     if (xStart == null || xEnd == null)
     {
         return null;
     }
     bool bFoundGoal = false;
     List<PathFindingSystem.WorkNode> Open = new List<PathFindingSystem.WorkNode>();
     List<PathFindingSystem.WorkNode> Closed = new List<PathFindingSystem.WorkNode>();
     List<PathFindingSystem.PFNode> lxPath = new List<PathFindingSystem.PFNode>();
     Open.Add(new PathFindingSystem.WorkNode(xStart));
     while (!bFoundGoal)
     {
         PathFindingSystem.WorkNode xCur = Open[0];
         if (xCur.xOwnedNode == xEnd)
         {
             PathFindingSystem.PFNode arg_68_0 = xCur.xOwnedNode;
             while (true)
             {
                 lxPath.Add(xCur.xOwnedNode);
                 if (xCur.xOwnedNode == xStart)
                 {
                     break;
                 }
                 xCur = xCur.xShortestPathNode;
             }
             lxPath.Reverse();
             if (lxPath.Count > 1 && !Program.game._CollisionMaster_RayCastVsStatic(lxPath[1].v2Position, v2StartPos, 2f, 3, Utility.CreateIntMask(new int[]
             {
                 30
             })))
             {
                 lxPath.RemoveAt(0);
             }
             return lxPath;
         }
         PathFindingSystem.PFNode xToOpen = null;
         float fMinDist = 0f;
         for (int i = 0; i < xCur.xOwnedNode.lxConnectedNodes.Count; i++)
         {
             if (this.GetNodeFromList(Closed, xCur.xOwnedNode.lxConnectedNodes[i].xTo) == null)
             {
                 PathFindingSystem.WorkNode xFound;
                 if ((xFound = this.GetNodeFromList(Open, xCur.xOwnedNode.lxConnectedNodes[i].xTo)) != null)
                 {
                     xFound.CompareNode(xCur);
                 }
                 else if (xToOpen == null)
                 {
                     xToOpen = xCur.xOwnedNode.lxConnectedNodes[i].xTo;
                     fMinDist = Vector2.DistanceSquared(v2EndPos, xToOpen.v2Position);
                 }
                 else
                 {
                     float fThis = Vector2.DistanceSquared(v2EndPos, xCur.xOwnedNode.lxConnectedNodes[i].xTo.v2Position);
                     if (fMinDist > fThis)
                     {
                         fMinDist = fThis;
                         xToOpen = xCur.xOwnedNode.lxConnectedNodes[i].xTo;
                     }
                 }
             }
         }
         if (xToOpen != null)
         {
             PathFindingSystem.WorkNode add = new PathFindingSystem.WorkNode(xToOpen);
             add.CompareNode(xCur);
             Open.Insert(0, add);
         }
         else
         {
             Closed.Add(xCur);
             Open.RemoveAt(0);
             if (Open.Count == 0)
             {
                 return null;
             }
         }
     }
     return lxPath;
 }
Exemple #2
0
 public void CompareNode(PathFindingSystem.WorkNode xNewNode)
 {
     if (this.xShortestPathNode == null)
     {
         this.xShortestPathNode = xNewNode;
         this.fShortestPath = xNewNode.fShortestPath + Vector2.Distance(xNewNode.xOwnedNode.v2Position, this.xShortestPathNode.xOwnedNode.v2Position);
         return;
     }
     float fDistance = Vector2.Distance(xNewNode.xOwnedNode.v2Position, this.xShortestPathNode.xOwnedNode.v2Position);
     if (xNewNode.fShortestPath + fDistance < this.fShortestPath)
     {
         this.fShortestPath = xNewNode.fShortestPath + fDistance;
         this.xShortestPathNode = xNewNode;
     }
 }