Ejemplo n.º 1
0
        public PathList[] GetPath(PathfinderNode[] StartNodes, PathfinderNode FinishNode, int Accuracy, int MinClearance)
        {
            int StartNodeCount = StartNodes.GetUpperBound(0) + 1;
            PathList[] Paths = new PathList[NodeLayerCount];
            PathfinderNode[,] LayerStartNodes = new PathfinderNode[NodeLayerCount, StartNodeCount];
            PathfinderNode[] LayerFinishNodes = new PathfinderNode[NodeLayerCount];
            int LayerNum = 0;
            PathfinderNode[] Destinations = new PathfinderNode[24];
            int DestinationCount = 0;
            bool FinishIsParent = default(bool);
            bool IsInaccurate;
            int[] CalcNodeCount = new int[24];
            sFloodRouteArgs FloodRouteArgs = new sFloodRouteArgs();
            int FinalLayer = 0;
            bool[] StartCanReach = new bool[StartNodeCount];
            PathfinderNode tmpNodeA = default(PathfinderNode);
            PathfinderNode tmpNodeB = default(PathfinderNode);
            int CanReachCount = 0;
            int FirstLayer = 0;
            Path[] BestPaths = new Path[24];
            float[] BestValues = new float[24];
            int PathNum = 0;
            bool StopMultiPathing = default(bool);
            bool[] Visit = NetworkLargeArrays.Nodes_Booleans;
            float[] NodeValues = NetworkLargeArrays.Nodes_ValuesA;
            PathfinderNode[] Nodes_Nodes = NetworkLargeArrays.Nodes_Nodes;
            Path StartPath = NetworkLargeArrays.Nodes_Path;
            int A = 0;
            int B = 0;
            int C = 0;
            int D = 0;
            int E = 0;

            FinalLayer = StartNodes[0].Layer.Network_LayerNum;
            LayerFinishNodes[FinalLayer] = FinishNode;
            B = FinalLayer;
            do
            {
                if ( LayerFinishNodes[B].ParentNode == null )
                {
                    FirstLayer = B;
                    break;
                }
                LayerFinishNodes[B + 1] = LayerFinishNodes[B].ParentNode;
                B++;
            } while ( true );
            for ( A = 0; A <= StartNodeCount - 1; A++ )
            {
                LayerStartNodes[FinalLayer, A] = StartNodes[A];
                B = FinalLayer;
                do
                {
                    if ( LayerStartNodes[B, A].ParentNode == null )
                    {
                        if ( LayerStartNodes[B, A] == LayerFinishNodes[B] )
                        {
                            StartCanReach[A] = true;
                            CanReachCount++;
                        }
                        break;
                    }
                    LayerStartNodes[B + 1, A] = LayerStartNodes[B, A].ParentNode;
                    B++;
                } while ( true );
            }
            if ( CanReachCount == 0 )
            {
                return null;
            }
            LayerNum = FirstLayer;
            Paths[LayerNum].Paths = new Path[0];
            Paths[LayerNum].Paths[0] = new Path();
            Paths[LayerNum].PathCount = 1;
            Paths[LayerNum].Paths[0].Nodes = new PathfinderNode[1];
            Paths[LayerNum].Paths[0].Nodes[0] = LayerFinishNodes[LayerNum];
            Paths[LayerNum].Paths[0].NodeCount = 1;
            int LastLayer = 0;
            do
            {
                LastLayer = LayerNum;
                LayerNum--;
                if ( LayerNum < FinalLayer )
                {
                    break;
                }
                else if ( StopMultiPathing )
                {
                    if ( Accuracy < 0 )
                    {
                        Debugger.Break();
                    }
                    for ( PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++ )
                    {
                        CalcNodeCount[PathNum] = Math.Min(Accuracy, Convert.ToInt32(Paths[LastLayer].Paths[PathNum].NodeCount - 1));
                    }
                    Destinations[0] = Paths[LastLayer].Paths[0].Nodes[CalcNodeCount[0]];
                    DestinationCount = 1;
                    FinishIsParent = true;
                    IsInaccurate = true;
                }
                else
                {
                    if ( Accuracy >= 0 )
                    {
                        for ( PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++ )
                        {
                            if ( Paths[LastLayer].Paths[PathNum].NodeCount > Accuracy )
                            {
                                StopMultiPathing = true;
                                break;
                            }
                        }
                    }
                    Destinations[0] = LayerFinishNodes[LayerNum];
                    if ( LayerNum == FinalLayer )
                    {
                        DestinationCount = 1;
                    }
                    else
                    {
                        for ( A = 0; A <= Destinations[0].ConnectionCount - 1; A++ )
                        {
                            Destinations[1 + A] = Destinations[0].Connections[A].GetOtherNode(Destinations[0]);
                        }
                        DestinationCount = 1 + Destinations[0].ConnectionCount;
                    }
                    for ( PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++ )
                    {
                        CalcNodeCount[PathNum] = Paths[LastLayer].Paths[PathNum].NodeCount - 1;
                    }
                    FinishIsParent = false;
                }
                for ( PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++ )
                {
                    for ( A = 0; A <= CalcNodeCount[PathNum]; A++ )
                    {
                        tmpNodeA = Paths[LastLayer].Paths[PathNum].Nodes[A];
                        for ( D = 0; D <= tmpNodeA.ConnectionCount - 1; D++ )
                        {
                            tmpNodeB = tmpNodeA.Connections[D].GetOtherNode(tmpNodeA);
                            for ( E = 0; E <= tmpNodeB.ConnectionCount - 1; E++ )
                            {
                                C = tmpNodeB.Connections[E].GetOtherNode(tmpNodeB).Layer_NodeNum;
                                Visit[C] = false;
                            }
                        }
                    }
                }
                for ( PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++ )
                {
                    for ( A = 0; A <= CalcNodeCount[PathNum]; A++ )
                    {
                        tmpNodeA = Paths[LastLayer].Paths[PathNum].Nodes[A];
                        C = tmpNodeA.Layer_NodeNum;
                        Visit[C] = true;
                        for ( E = 0; E <= tmpNodeA.NodeCount - 1; E++ )
                        {
                            C = tmpNodeA.Nodes[E].Layer_NodeNum;
                            NodeValues[C] = float.MaxValue;
                        }
                        for ( D = 0; D <= tmpNodeA.ConnectionCount - 1; D++ )
                        {
                            tmpNodeB = tmpNodeA.Connections[D].GetOtherNode(tmpNodeA);
                            C = tmpNodeB.Layer_NodeNum;
                            Visit[C] = true;
                            for ( E = 0; E <= tmpNodeB.NodeCount - 1; E++ )
                            {
                                C = tmpNodeB.Nodes[E].Layer_NodeNum;
                                NodeValues[C] = float.MaxValue;
                            }
                        }
                    }
                }
                FloodRouteArgs = new sFloodRouteArgs();
                FloodRouteArgs.CurrentPath = StartPath;
                FloodRouteArgs.FinishNodes = Destinations;
                FloodRouteArgs.FinishNodeCount = DestinationCount;
                FloodRouteArgs.FinishIsParent = FinishIsParent;
                FloodRouteArgs.Visit = Visit;
                FloodRouteArgs.NodeValues = NodeValues;
                FloodRouteArgs.SourceNodes = Nodes_Nodes;
                FloodRouteArgs.MinClearance = MinClearance;
                for ( A = 0; A <= DestinationCount - 1; A++ )
                {
                    BestPaths[A] = null;
                    BestValues[A] = float.MaxValue;
                }
                for ( A = 0; A <= StartNodeCount - 1; A++ )
                {
                    if ( StartCanReach[A] )
                    {
                        StartPath.NodeCount = 1;
                        StartPath.Nodes[0] = LayerStartNodes[LayerNum, A];
                        StartPath.Value = 0.0F;
                        FloodRouteArgs.BestPaths = new Path[DestinationCount];
                        FloodRoute(FloodRouteArgs);
                        for ( PathNum = 0; PathNum <= DestinationCount - 1; PathNum++ )
                        {
                            if ( FloodRouteArgs.BestPaths[PathNum] != null )
                            {
                                if ( FloodRouteArgs.BestPaths[PathNum].Value < BestValues[PathNum] )
                                {
                                    BestValues[PathNum] = FloodRouteArgs.BestPaths[PathNum].Value;
                                    BestPaths[PathNum] = FloodRouteArgs.BestPaths[PathNum];
                                }
                            }
                        }
                    }
                }
                Paths[LayerNum].Paths = new Path[DestinationCount];
                Paths[LayerNum].PathCount = 0;
                for ( PathNum = 0; PathNum <= DestinationCount - 1; PathNum++ )
                {
                    if ( BestPaths[PathNum] != null )
                    {
                        Paths[LayerNum].Paths[Paths[LayerNum].PathCount] = BestPaths[PathNum];
                        Paths[LayerNum].PathCount++;
                    }
                }
                Array.Resize(ref Paths[LayerNum].Paths, Paths[LayerNum].PathCount);
                if ( Paths[LayerNum].PathCount == 0 )
                {
                    return null;
                }
            } while ( true );
            return Paths;
        }
Ejemplo n.º 2
0
        public void FloodRoute(sFloodRouteArgs Args)
        {
            PathfinderNode CurrentNode = default(PathfinderNode);
            PathfinderNode ConnectedNode = default(PathfinderNode);
            int A = 0;
            int SourceNodeCount = 0;
            int SourceNodeNum = 0;
            PathfinderConnection tmpConnection = default(PathfinderConnection);
            float ResultValue = 0;
            Path BestPath = default(Path);
            PathfinderNode StartNode = default(PathfinderNode);
            int B = 0;
            float BestDist = 0;
            float Dist = 0;
            PathfinderNode BestNode = default(PathfinderNode);
            int C = 0;

            StartNode = Args.CurrentPath.Nodes[0];

            Args.SourceNodes[0] = StartNode;
            SourceNodeCount = 1;
            Args.NodeValues[StartNode.Layer_NodeNum] = 0.0F;

            SourceNodeNum = 0;
            while ( SourceNodeNum < SourceNodeCount )
            {
                CurrentNode = Args.SourceNodes[SourceNodeNum];
                for ( A = 0; A <= CurrentNode.ConnectionCount - 1; A++ )
                {
                    tmpConnection = CurrentNode.Connections[A];
                    ConnectedNode = tmpConnection.GetOtherNode(CurrentNode);
                    if ( ConnectedNode.ParentNode != null )
                    {
                        if ( Args.Visit[ConnectedNode.ParentNode.Layer_NodeNum] )
                        {
                            if ( ConnectedNode.Clearance >= Args.MinClearance )
                            {
                                ResultValue = Args.NodeValues[CurrentNode.Layer_NodeNum] + tmpConnection.Value;
                                if ( ResultValue < Args.NodeValues[ConnectedNode.Layer_NodeNum] )
                                {
                                    Args.NodeValues[ConnectedNode.Layer_NodeNum] = ResultValue;
                                    Args.SourceNodes[SourceNodeCount] = ConnectedNode;
                                    SourceNodeCount++;
                                }
                            }
                        }
                    }
                }
                SourceNodeNum++;
            }

            for ( A = 0; A <= Args.FinishNodeCount - 1; A++ )
            {
                if ( Args.FinishIsParent )
                {
                    BestNode = null;
                    BestDist = float.MaxValue;
                    for ( C = 0; C <= Args.FinishNodes[A].NodeCount - 1; C++ )
                    {
                        CurrentNode = Args.FinishNodes[A].Nodes[C];
                        Dist = Args.NodeValues[CurrentNode.Layer_NodeNum];
                        if ( Dist < BestDist )
                        {
                            BestDist = Dist;
                            BestNode = CurrentNode;
                        }
                    }
                    CurrentNode = BestNode;
                }
                else
                {
                    CurrentNode = Args.FinishNodes[A];
                }
                if ( CurrentNode == null )
                {
                    //no path
                    return;
                }
                SourceNodeCount = 0;
                BestDist = Args.NodeValues[CurrentNode.Layer_NodeNum];
                if ( BestDist == float.MaxValue )
                {
                    //no path
                    return;
                }
                do
                {
                    Args.SourceNodes[SourceNodeCount] = CurrentNode;
                    SourceNodeCount++;
                    if ( CurrentNode == StartNode )
                    {
                        break;
                    }
                    BestNode = null;
                    for ( B = 0; B <= CurrentNode.ConnectionCount - 1; B++ )
                    {
                        tmpConnection = CurrentNode.Connections[B];
                        ConnectedNode = tmpConnection.GetOtherNode(CurrentNode);
                        if ( ConnectedNode.ParentNode != null )
                        {
                            if ( Args.Visit[ConnectedNode.ParentNode.Layer_NodeNum] )
                            {
                                Dist = Args.NodeValues[ConnectedNode.Layer_NodeNum];
                                if ( Dist < BestDist )
                                {
                                    BestDist = Dist;
                                    BestNode = ConnectedNode;
                                }
                            }
                        }
                    }
                    if ( BestNode == null )
                    {
                        Args.BestPaths[A] = null;
                        return;
                    }
                    CurrentNode = BestNode;
                } while ( true );

                BestPath = new Path();
                Args.BestPaths[A] = BestPath;
                BestPath.Value = Args.NodeValues[Args.FinishNodes[A].Layer_NodeNum];
                BestPath.NodeCount = SourceNodeCount;
                BestPath.Nodes = new PathfinderNode[BestPath.NodeCount];
                for ( B = 0; B <= BestPath.NodeCount - 1; B++ )
                {
                    BestPath.Nodes[B] = Args.SourceNodes[SourceNodeCount - B - 1];
                }
            }
        }
Ejemplo n.º 3
0
 public PathList[] GetPath(PathfinderNode[] StartNodes, PathfinderNode FinishNode, int Accuracy, int MinClearance)
 {
     int num;
     int num4;
     int num9;
     int num13 = StartNodes.GetUpperBound(0) + 1;
     PathList[] listArray2 = new PathList[(this.NodeLayerCount - 1) + 1];
     PathfinderNode[,] nodeArray3 = new PathfinderNode[(this.NodeLayerCount - 1) + 1, (num13 - 1) + 1];
     PathfinderNode[] nodeArray2 = new PathfinderNode[(this.NodeLayerCount - 1) + 1];
     PathfinderNode[] nodeArray = new PathfinderNode[0x18];
     int[] numArray2 = new int[0x18];
     bool[] flagArray = new bool[(num13 - 1) + 1];
     Path[] pathArray = new Path[0x18];
     float[] numArray = new float[0x18];
     bool[] flagArray2 = this.NetworkLargeArrays.Nodes_Booleans;
     float[] numArray3 = this.NetworkLargeArrays.Nodes_ValuesA;
     PathfinderNode[] nodeArray4 = this.NetworkLargeArrays.Nodes_Nodes;
     Path path = this.NetworkLargeArrays.Nodes_Path;
     int index = StartNodes[0].Layer.Network_LayerNum;
     nodeArray2[index] = FinishNode;
     int num2 = index;
     while (true)
     {
         if (nodeArray2[num2].ParentNode == null)
         {
             num9 = num2;
             break;
         }
         nodeArray2[num2 + 1] = nodeArray2[num2].ParentNode;
         num2++;
     }
     int num14 = num13 - 1;
     for (num = 0; num <= num14; num++)
     {
         nodeArray3[index, num] = StartNodes[num];
         num2 = index;
         while (true)
         {
             if (nodeArray3[num2, num].ParentNode == null)
             {
                 if (nodeArray3[num2, num] == nodeArray2[num2])
                 {
                     flagArray[num] = true;
                     num4++;
                 }
                 break;
             }
             nodeArray3[num2 + 1, num] = nodeArray3[num2, num].ParentNode;
             num2++;
         }
     }
     if (num4 != 0)
     {
         int num11 = num9;
         listArray2[num11].Paths = new Path[] { new Path() };
         listArray2[num11].PathCount = 1;
         listArray2[num11].Paths[0].Nodes = new PathfinderNode[] { nodeArray2[num11] };
         listArray2[num11].Paths[0].NodeCount = 1;
         do
         {
             int num3;
             int num5;
             int num6;
             int num7;
             bool flag;
             int num12;
             bool flag3;
             PathfinderNode node;
             PathfinderNode otherNode;
             int num10 = num11;
             num11--;
             if (num11 < index)
             {
                 return listArray2;
             }
             if (flag3)
             {
                 if (Accuracy < 0)
                 {
                     Debugger.Break();
                 }
                 int num15 = listArray2[num10].PathCount - 1;
                 for (num12 = 0; num12 <= num15; num12++)
                 {
                     numArray2[num12] = Math.Min(Accuracy, listArray2[num10].Paths[num12].NodeCount - 1);
                 }
                 nodeArray[0] = listArray2[num10].Paths[0].Nodes[numArray2[0]];
                 num6 = 1;
                 flag = true;
             }
             else
             {
                 if (Accuracy >= 0)
                 {
                     int num16 = listArray2[num10].PathCount - 1;
                     for (num12 = 0; num12 <= num16; num12++)
                     {
                         if (listArray2[num10].Paths[num12].NodeCount > Accuracy)
                         {
                             flag3 = true;
                             break;
                         }
                     }
                 }
                 nodeArray[0] = nodeArray2[num11];
                 if (num11 == index)
                 {
                     num6 = 1;
                 }
                 else
                 {
                     int num17 = nodeArray[0].ConnectionCount - 1;
                     num = 0;
                     while (num <= num17)
                     {
                         nodeArray[1 + num] = nodeArray[0].Connections[num].GetOtherNode(nodeArray[0]);
                         num++;
                     }
                     num6 = 1 + nodeArray[0].ConnectionCount;
                 }
                 int num18 = listArray2[num10].PathCount - 1;
                 for (num12 = 0; num12 <= num18; num12++)
                 {
                     numArray2[num12] = listArray2[num10].Paths[num12].NodeCount - 1;
                 }
                 flag = false;
             }
             int num19 = listArray2[num10].PathCount - 1;
             for (num12 = 0; num12 <= num19; num12++)
             {
                 int num20 = numArray2[num12];
                 num = 0;
                 while (num <= num20)
                 {
                     node = listArray2[num10].Paths[num12].Nodes[num];
                     int num21 = node.ConnectionCount - 1;
                     num5 = 0;
                     while (num5 <= num21)
                     {
                         otherNode = node.Connections[num5].GetOtherNode(node);
                         int num22 = otherNode.ConnectionCount - 1;
                         num7 = 0;
                         while (num7 <= num22)
                         {
                             num3 = otherNode.Connections[num7].GetOtherNode(otherNode).Layer_NodeNum;
                             flagArray2[num3] = false;
                             num7++;
                         }
                         num5++;
                     }
                     num++;
                 }
             }
             int num23 = listArray2[num10].PathCount - 1;
             num12 = 0;
             while (num12 <= num23)
             {
                 int num24 = numArray2[num12];
                 num = 0;
                 while (num <= num24)
                 {
                     node = listArray2[num10].Paths[num12].Nodes[num];
                     num3 = node.Layer_NodeNum;
                     flagArray2[num3] = true;
                     int num25 = node.NodeCount - 1;
                     num7 = 0;
                     while (num7 <= num25)
                     {
                         num3 = node.Nodes[num7].Layer_NodeNum;
                         numArray3[num3] = float.MaxValue;
                         num7++;
                     }
                     int num26 = node.ConnectionCount - 1;
                     for (num5 = 0; num5 <= num26; num5++)
                     {
                         otherNode = node.Connections[num5].GetOtherNode(node);
                         num3 = otherNode.Layer_NodeNum;
                         flagArray2[num3] = true;
                         int num27 = otherNode.NodeCount - 1;
                         for (num7 = 0; num7 <= num27; num7++)
                         {
                             num3 = otherNode.Nodes[num7].Layer_NodeNum;
                             numArray3[num3] = float.MaxValue;
                         }
                     }
                     num++;
                 }
                 num12++;
             }
             sFloodRouteArgs args = new sFloodRouteArgs {
                 CurrentPath = path,
                 FinishNodes = nodeArray,
                 FinishNodeCount = num6,
                 FinishIsParent = flag,
                 Visit = flagArray2,
                 NodeValues = numArray3,
                 SourceNodes = nodeArray4,
                 MinClearance = MinClearance
             };
             int num28 = num6 - 1;
             for (num = 0; num <= num28; num++)
             {
                 pathArray[num] = null;
                 numArray[num] = float.MaxValue;
             }
             int num29 = num13 - 1;
             for (num = 0; num <= num29; num++)
             {
                 if (flagArray[num])
                 {
                     path.NodeCount = 1;
                     path.Nodes[0] = nodeArray3[num11, num];
                     path.Value = 0f;
                     args.BestPaths = new Path[(num6 - 1) + 1];
                     this.FloodRoute(ref args);
                     int num30 = num6 - 1;
                     num12 = 0;
                     while (num12 <= num30)
                     {
                         if ((args.BestPaths[num12] != null) && (args.BestPaths[num12].Value < numArray[num12]))
                         {
                             numArray[num12] = args.BestPaths[num12].Value;
                             pathArray[num12] = args.BestPaths[num12];
                         }
                         num12++;
                     }
                 }
             }
             listArray2[num11].Paths = new Path[(num6 - 1) + 1];
             listArray2[num11].PathCount = 0;
             int num31 = num6 - 1;
             for (num12 = 0; num12 <= num31; num12++)
             {
                 if (pathArray[num12] != null)
                 {
                     listArray2[num11].Paths[listArray2[num11].PathCount] = pathArray[num12];
                     PathList[] listArray3 = listArray2;
                     int num32 = num11;
                     listArray3[num32].PathCount++;
                 }
             }
             listArray2[num11].Paths = (Path[]) Utils.CopyArray((Array) listArray2[num11].Paths, new Path[(listArray2[num11].PathCount - 1) + 1]);
         }
         while (listArray2[num11].PathCount != 0);
     }
     return null;
 }
Ejemplo n.º 4
0
 public void FloodRoute(ref sFloodRouteArgs Args)
 {
     int num;
     PathfinderNode otherNode;
     PathfinderNode node3;
     PathfinderNode node4 = Args.CurrentPath.Nodes[0];
     Args.SourceNodes[0] = node4;
     int index = 1;
     Args.NodeValues[node4.Layer_NodeNum] = 0f;
     for (int i = 0; i < index; i++)
     {
         node3 = Args.SourceNodes[i];
         int num9 = node3.ConnectionCount - 1;
         num = 0;
         while (num <= num9)
         {
             PathfinderConnection connection = node3.Connections[num];
             otherNode = connection.GetOtherNode(node3);
             if (((otherNode.ParentNode != null) && Args.Visit[otherNode.ParentNode.Layer_NodeNum]) && (otherNode.Clearance >= Args.MinClearance))
             {
                 float num6 = Args.NodeValues[node3.Layer_NodeNum] + connection.Value;
                 if (num6 < Args.NodeValues[otherNode.Layer_NodeNum])
                 {
                     Args.NodeValues[otherNode.Layer_NodeNum] = num6;
                     Args.SourceNodes[index] = otherNode;
                     index++;
                 }
             }
             num++;
         }
     }
     int num10 = Args.FinishNodeCount - 1;
     for (num = 0; num <= num10; num++)
     {
         float maxValue;
         PathfinderNode node;
         float num5;
         if (Args.FinishIsParent)
         {
             node = null;
             maxValue = float.MaxValue;
             int num11 = Args.FinishNodes[num].NodeCount - 1;
             for (int j = 0; j <= num11; j++)
             {
                 node3 = Args.FinishNodes[num].Nodes[j];
                 num5 = Args.NodeValues[node3.Layer_NodeNum];
                 if (num5 < maxValue)
                 {
                     maxValue = num5;
                     node = node3;
                 }
             }
             node3 = node;
         }
         else
         {
             node3 = Args.FinishNodes[num];
         }
         if (node3 != null)
         {
             index = 0;
             maxValue = Args.NodeValues[node3.Layer_NodeNum];
             if (maxValue != float.MaxValue)
             {
                 int num2;
                 while (true)
                 {
                     Args.SourceNodes[index] = node3;
                     index++;
                     if (node3 == node4)
                     {
                         break;
                     }
                     node = null;
                     int num12 = node3.ConnectionCount - 1;
                     num2 = 0;
                     while (num2 <= num12)
                     {
                         otherNode = node3.Connections[num2].GetOtherNode(node3);
                         if ((otherNode.ParentNode != null) && Args.Visit[otherNode.ParentNode.Layer_NodeNum])
                         {
                             num5 = Args.NodeValues[otherNode.Layer_NodeNum];
                             if (num5 < maxValue)
                             {
                                 maxValue = num5;
                                 node = otherNode;
                             }
                         }
                         num2++;
                     }
                     if (node == null)
                     {
                         Args.BestPaths[num] = null;
                         continue;
                     }
                     node3 = node;
                 }
                 Path path = new Path();
                 Args.BestPaths[num] = path;
                 path.Value = Args.NodeValues[Args.FinishNodes[num].Layer_NodeNum];
                 path.NodeCount = index;
                 path.Nodes = new PathfinderNode[(path.NodeCount - 1) + 1];
                 int num13 = path.NodeCount - 1;
                 for (num2 = 0; num2 <= num13; num2++)
                 {
                     path.Nodes[num2] = Args.SourceNodes[(index - num2) - 1];
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        public PathList[] GetPath(PathfinderNode[] StartNodes, PathfinderNode FinishNode, int Accuracy, int MinClearance)
        {
            var StartNodeCount   = StartNodes.GetUpperBound(0) + 1;
            var Paths            = new PathList[NodeLayerCount];
            var LayerStartNodes  = new PathfinderNode[NodeLayerCount, StartNodeCount];
            var LayerFinishNodes = new PathfinderNode[NodeLayerCount];
            var LayerNum         = 0;
            var Destinations     = new PathfinderNode[24];
            var DestinationCount = 0;
            var FinishIsParent   = default(bool);
            var CalcNodeCount    = new int[24];
            var FloodRouteArgs   = new sFloodRouteArgs();
            var FinalLayer       = 0;
            var StartCanReach    = new bool[StartNodeCount];
            var tmpNodeA         = default(PathfinderNode);
            var tmpNodeB         = default(PathfinderNode);
            var CanReachCount    = 0;
            var FirstLayer       = 0;
            var BestPaths        = new Path[24];
            var BestValues       = new float[24];
            var PathNum          = 0;
            var StopMultiPathing = default(bool);
            var Visit            = NetworkLargeArrays.Nodes_Booleans;
            var NodeValues       = NetworkLargeArrays.Nodes_ValuesA;
            var Nodes_Nodes      = NetworkLargeArrays.Nodes_Nodes;
            var StartPath        = NetworkLargeArrays.Nodes_Path;
            var A = 0;
            var B = 0;
            var C = 0;
            var D = 0;
            var E = 0;

            FinalLayer = StartNodes[0].Layer.Network_LayerNum;
            LayerFinishNodes[FinalLayer] = FinishNode;
            B = FinalLayer;
            do
            {
                if (LayerFinishNodes[B].ParentNode == null)
                {
                    FirstLayer = B;
                    break;
                }
                LayerFinishNodes[B + 1] = LayerFinishNodes[B].ParentNode;
                B++;
            } while (true);
            for (A = 0; A <= StartNodeCount - 1; A++)
            {
                LayerStartNodes[FinalLayer, A] = StartNodes[A];
                B = FinalLayer;
                do
                {
                    if (LayerStartNodes[B, A].ParentNode == null)
                    {
                        if (LayerStartNodes[B, A] == LayerFinishNodes[B])
                        {
                            StartCanReach[A] = true;
                            CanReachCount++;
                        }
                        break;
                    }
                    LayerStartNodes[B + 1, A] = LayerStartNodes[B, A].ParentNode;
                    B++;
                } while (true);
            }
            if (CanReachCount == 0)
            {
                return(null);
            }
            LayerNum = FirstLayer;
            Paths[LayerNum].Paths              = new Path[0];
            Paths[LayerNum].Paths[0]           = new Path();
            Paths[LayerNum].PathCount          = 1;
            Paths[LayerNum].Paths[0].Nodes     = new PathfinderNode[1];
            Paths[LayerNum].Paths[0].Nodes[0]  = LayerFinishNodes[LayerNum];
            Paths[LayerNum].Paths[0].NodeCount = 1;
            var LastLayer = 0;

            do
            {
                LastLayer = LayerNum;
                LayerNum--;
                if (LayerNum < FinalLayer)
                {
                    break;
                }
                if (StopMultiPathing)
                {
                    if (Accuracy < 0)
                    {
                        Debugger.Break();
                    }
                    for (PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++)
                    {
                        CalcNodeCount[PathNum] = Math.Min(Accuracy, Convert.ToInt32(Paths[LastLayer].Paths[PathNum].NodeCount - 1));
                    }
                    Destinations[0]  = Paths[LastLayer].Paths[0].Nodes[CalcNodeCount[0]];
                    DestinationCount = 1;
                    FinishIsParent   = true;
                }
                else
                {
                    if (Accuracy >= 0)
                    {
                        for (PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++)
                        {
                            if (Paths[LastLayer].Paths[PathNum].NodeCount > Accuracy)
                            {
                                StopMultiPathing = true;
                                break;
                            }
                        }
                    }
                    Destinations[0] = LayerFinishNodes[LayerNum];
                    if (LayerNum == FinalLayer)
                    {
                        DestinationCount = 1;
                    }
                    else
                    {
                        for (A = 0; A <= Destinations[0].ConnectionCount - 1; A++)
                        {
                            Destinations[1 + A] = Destinations[0].Connections[A].GetOtherNode(Destinations[0]);
                        }
                        DestinationCount = 1 + Destinations[0].ConnectionCount;
                    }
                    for (PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++)
                    {
                        CalcNodeCount[PathNum] = Paths[LastLayer].Paths[PathNum].NodeCount - 1;
                    }
                    FinishIsParent = false;
                }
                for (PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++)
                {
                    for (A = 0; A <= CalcNodeCount[PathNum]; A++)
                    {
                        tmpNodeA = Paths[LastLayer].Paths[PathNum].Nodes[A];
                        for (D = 0; D <= tmpNodeA.ConnectionCount - 1; D++)
                        {
                            tmpNodeB = tmpNodeA.Connections[D].GetOtherNode(tmpNodeA);
                            for (E = 0; E <= tmpNodeB.ConnectionCount - 1; E++)
                            {
                                C        = tmpNodeB.Connections[E].GetOtherNode(tmpNodeB).Layer_NodeNum;
                                Visit[C] = false;
                            }
                        }
                    }
                }
                for (PathNum = 0; PathNum <= Paths[LastLayer].PathCount - 1; PathNum++)
                {
                    for (A = 0; A <= CalcNodeCount[PathNum]; A++)
                    {
                        tmpNodeA = Paths[LastLayer].Paths[PathNum].Nodes[A];
                        C        = tmpNodeA.Layer_NodeNum;
                        Visit[C] = true;
                        for (E = 0; E <= tmpNodeA.NodeCount - 1; E++)
                        {
                            C             = tmpNodeA.Nodes[E].Layer_NodeNum;
                            NodeValues[C] = float.MaxValue;
                        }
                        for (D = 0; D <= tmpNodeA.ConnectionCount - 1; D++)
                        {
                            tmpNodeB = tmpNodeA.Connections[D].GetOtherNode(tmpNodeA);
                            C        = tmpNodeB.Layer_NodeNum;
                            Visit[C] = true;
                            for (E = 0; E <= tmpNodeB.NodeCount - 1; E++)
                            {
                                C             = tmpNodeB.Nodes[E].Layer_NodeNum;
                                NodeValues[C] = float.MaxValue;
                            }
                        }
                    }
                }
                FloodRouteArgs                 = new sFloodRouteArgs();
                FloodRouteArgs.CurrentPath     = StartPath;
                FloodRouteArgs.FinishNodes     = Destinations;
                FloodRouteArgs.FinishNodeCount = DestinationCount;
                FloodRouteArgs.FinishIsParent  = FinishIsParent;
                FloodRouteArgs.Visit           = Visit;
                FloodRouteArgs.NodeValues      = NodeValues;
                FloodRouteArgs.SourceNodes     = Nodes_Nodes;
                FloodRouteArgs.MinClearance    = MinClearance;
                for (A = 0; A <= DestinationCount - 1; A++)
                {
                    BestPaths[A]  = null;
                    BestValues[A] = float.MaxValue;
                }
                for (A = 0; A <= StartNodeCount - 1; A++)
                {
                    if (StartCanReach[A])
                    {
                        StartPath.NodeCount      = 1;
                        StartPath.Nodes[0]       = LayerStartNodes[LayerNum, A];
                        StartPath.Value          = 0.0F;
                        FloodRouteArgs.BestPaths = new Path[DestinationCount];
                        FloodRoute(ref FloodRouteArgs);
                        for (PathNum = 0; PathNum <= DestinationCount - 1; PathNum++)
                        {
                            if (FloodRouteArgs.BestPaths[PathNum] != null)
                            {
                                if (FloodRouteArgs.BestPaths[PathNum].Value < BestValues[PathNum])
                                {
                                    BestValues[PathNum] = FloodRouteArgs.BestPaths[PathNum].Value;
                                    BestPaths[PathNum]  = FloodRouteArgs.BestPaths[PathNum];
                                }
                            }
                        }
                    }
                }
                Paths[LayerNum].Paths     = new Path[DestinationCount];
                Paths[LayerNum].PathCount = 0;
                for (PathNum = 0; PathNum <= DestinationCount - 1; PathNum++)
                {
                    if (BestPaths[PathNum] != null)
                    {
                        Paths[LayerNum].Paths[Paths[LayerNum].PathCount] = BestPaths[PathNum];
                        Paths[LayerNum].PathCount++;
                    }
                }
                Array.Resize(ref Paths[LayerNum].Paths, Paths[LayerNum].PathCount);
                if (Paths[LayerNum].PathCount == 0)
                {
                    return(null);
                }
            } while (true);
            return(Paths);
        }
Ejemplo n.º 6
0
        public void FloodRoute(ref sFloodRouteArgs Args)
        {
            var   CurrentNode     = default(PathfinderNode);
            var   ConnectedNode   = default(PathfinderNode);
            var   A               = 0;
            var   SourceNodeCount = 0;
            var   SourceNodeNum   = 0;
            var   tmpConnection   = default(PathfinderConnection);
            float ResultValue     = 0;
            var   BestPath        = default(Path);
            var   StartNode       = default(PathfinderNode);
            var   B               = 0;
            float BestDist        = 0;
            float Dist            = 0;
            var   BestNode        = default(PathfinderNode);
            var   C               = 0;

            StartNode = Args.CurrentPath.Nodes[0];

            Args.SourceNodes[0] = StartNode;
            SourceNodeCount     = 1;
            Args.NodeValues[StartNode.Layer_NodeNum] = 0.0F;

            SourceNodeNum = 0;
            while (SourceNodeNum < SourceNodeCount)
            {
                CurrentNode = Args.SourceNodes[SourceNodeNum];
                for (A = 0; A <= CurrentNode.ConnectionCount - 1; A++)
                {
                    tmpConnection = CurrentNode.Connections[A];
                    ConnectedNode = tmpConnection.GetOtherNode(CurrentNode);
                    if (ConnectedNode.ParentNode != null)
                    {
                        if (Args.Visit[ConnectedNode.ParentNode.Layer_NodeNum])
                        {
                            if (ConnectedNode.Clearance >= Args.MinClearance)
                            {
                                ResultValue = Args.NodeValues[CurrentNode.Layer_NodeNum] + tmpConnection.Value;
                                if (ResultValue < Args.NodeValues[ConnectedNode.Layer_NodeNum])
                                {
                                    Args.NodeValues[ConnectedNode.Layer_NodeNum] = ResultValue;
                                    Args.SourceNodes[SourceNodeCount]            = ConnectedNode;
                                    SourceNodeCount++;
                                }
                            }
                        }
                    }
                }
                SourceNodeNum++;
            }

            for (A = 0; A <= Args.FinishNodeCount - 1; A++)
            {
                if (Args.FinishIsParent)
                {
                    BestNode = null;
                    BestDist = float.MaxValue;
                    for (C = 0; C <= Args.FinishNodes[A].NodeCount - 1; C++)
                    {
                        CurrentNode = Args.FinishNodes[A].Nodes[C];
                        Dist        = Args.NodeValues[CurrentNode.Layer_NodeNum];
                        if (Dist < BestDist)
                        {
                            BestDist = Dist;
                            BestNode = CurrentNode;
                        }
                    }
                    CurrentNode = BestNode;
                }
                else
                {
                    CurrentNode = Args.FinishNodes[A];
                }
                if (CurrentNode == null)
                {
                    //no path
                    return;
                }
                SourceNodeCount = 0;
                BestDist        = Args.NodeValues[CurrentNode.Layer_NodeNum];
                if (BestDist == float.MaxValue)
                {
                    //no path
                    return;
                }
                do
                {
                    Args.SourceNodes[SourceNodeCount] = CurrentNode;
                    SourceNodeCount++;
                    if (CurrentNode == StartNode)
                    {
                        break;
                    }
                    BestNode = null;
                    for (B = 0; B <= CurrentNode.ConnectionCount - 1; B++)
                    {
                        tmpConnection = CurrentNode.Connections[B];
                        ConnectedNode = tmpConnection.GetOtherNode(CurrentNode);
                        if (ConnectedNode.ParentNode != null)
                        {
                            if (Args.Visit[ConnectedNode.ParentNode.Layer_NodeNum])
                            {
                                Dist = Args.NodeValues[ConnectedNode.Layer_NodeNum];
                                if (Dist < BestDist)
                                {
                                    BestDist = Dist;
                                    BestNode = ConnectedNode;
                                }
                            }
                        }
                    }
                    if (BestNode == null)
                    {
                        Args.BestPaths[A] = null;
                        return;
                    }
                    CurrentNode = BestNode;
                } while (true);

                BestPath           = new Path();
                Args.BestPaths[A]  = BestPath;
                BestPath.Value     = Args.NodeValues[Args.FinishNodes[A].Layer_NodeNum];
                BestPath.NodeCount = SourceNodeCount;
                BestPath.Nodes     = new PathfinderNode[BestPath.NodeCount];
                for (B = 0; B <= BestPath.NodeCount - 1; B++)
                {
                    BestPath.Nodes[B] = Args.SourceNodes[SourceNodeCount - B - 1];
                }
            }
        }