Exemple #1
0
        public void CheckIntegrity()
        {
            //make sure im still a good parent

            if (NodeCount >= 2)
            {
                var Visited = new sVisited();
                Visited.Visited = new bool[NodeCount];
                var A = 0;
                FloodCheckInternal(Nodes[0], ref Visited);
                for (A = 0; A <= NodeCount - 1; A++)
                {
                    if (!Visited.Visited[A])
                    {
                        goto DisbandAndFind;
                    }
                }
            }

            if (NodeCount == 1 & ConnectionCount == 0)
            {
                goto DisbandAndFind;
            }
            if (NodeCount > 1)
            {
                SpanCalc();
            }
            else if (NodeCount == 0)
            {
                if (ParentNode != null)
                {
                    var tmpNode = ParentNode;
                    tmpNode.Node_Remove(ParentNode_NodeNum);
                    tmpNode.CheckIntegrity();
                }
                if (Layer.Network_LayerNum > 0)
                {
                    Deallocate();
                }
            }

            return;

DisbandAndFind:
            var B = 0;
            var Children = new PathfinderNode[NodeCount];

            for (B = 0; B <= NodeCount - 1; B++)
            {
                Children[B] = Nodes[B];
            }
            var ChildCount = NodeCount;

            Disband();

            for (B = 0; B <= ChildCount - 1; B++)
            {
                Children[B].Layer.Network.FindParentNode_Add(Children[B]);
            }
        }
Exemple #2
0
 public PathfinderNode GetOtherNode(PathfinderNode Self)
 {
     if (NodeA == Self)
     {
         return(NodeB);
     }
     return(NodeA);
 }
 public void Node_Add(PathfinderNode NewNode)
 {
     if (Nodes.GetUpperBound(0) < NodeCount)
     {
         Array.Resize(ref Nodes, (NodeCount + 1) * 2);
     }
     Nodes[NodeCount] = NewNode;
     Nodes[NodeCount].Layer_NodeNum = NodeCount;
     NodeCount++;
 }
Exemple #4
0
        public PathfinderConnection(PathfinderConnection SourceConnection)
        {
            NodeA = SourceConnection.NodeA.ParentNode;
            NodeB = SourceConnection.NodeB.ParentNode;
            NodeA.Connection_Add(this, ref NodeA_ConnectionNum);
            NodeB.Connection_Add(this, ref NodeB_ConnectionNum);

            NodeA.Layer.Connection_Add(this);
            ValueCalc();
        }
Exemple #5
0
        private void RemoveFromNodes()
        {
            NodeA.Connection_Remove(NodeA_ConnectionNum);
            NodeA = null;
            NodeA_ConnectionNum = -1;

            NodeB.Connection_Remove(NodeB_ConnectionNum);
            NodeB = null;
            NodeB_ConnectionNum = -1;
        }
Exemple #6
0
        public void ForceDeallocate()
        {
            var A = 0;

            for (A = 0; A <= ConnectionCount - 1; A++)
            {
                Connections[A].ForceDeallocate();
            }
            Connections = null;
            Nodes       = null;
            ParentNode  = null;
            Layer       = null;
        }
Exemple #7
0
        public PathfinderConnection FindConnection(PathfinderNode NodeToFind)
        {
            var A             = 0;
            var tmpConnection = default(PathfinderConnection);

            for (A = 0; A <= ConnectionCount - 1; A++)
            {
                tmpConnection = Connections[A];
                if (tmpConnection.GetOtherNode(this) == NodeToFind)
                {
                    return(tmpConnection);
                }
            }
            return(null);
        }
        public void ChangedNode_Add(PathfinderNode NewChangedNode)
        {
            if (NewChangedNode.Layer_ChangedNodeNum >= 0)
            {
                return;
            }

            if (ChangedNodes.GetUpperBound(0) < ChangedNodeCount)
            {
                Array.Resize(ref ChangedNodes, ChangedNodeCount * 2 + 1 + 1);
            }
            ChangedNodes[ChangedNodeCount] = NewChangedNode;
            ChangedNodes[ChangedNodeCount].Layer_ChangedNodeNum = ChangedNodeCount;
            ChangedNodeCount++;
        }
Exemple #9
0
        public void FindParentNode_Add(PathfinderNode NewFindParentNode)
        {
            if (NewFindParentNode.Network_FindParentNum >= 0)
            {
                return;
            }

            if (FindParentNodes.GetUpperBound(0) < FindParentNodeCount)
            {
                Array.Resize(ref FindParentNodes, (FindParentNodeCount + 1) * 2);
            }
            FindParentNodes[FindParentNodeCount] = NewFindParentNode;
            FindParentNodes[FindParentNodeCount].Network_FindParentNum = FindParentNodeCount;
            FindParentNodeCount++;
        }
Exemple #10
0
        public PathfinderConnection GetOrCreateConnection(PathfinderNode OtherNode, float Value)
        {
            var tmpConnection = default(PathfinderConnection);

            if (OtherNode.Layer != Layer)
            {
                return(null);
            }

            tmpConnection = FindConnection(OtherNode);
            if (tmpConnection == null)
            {
                return(new PathfinderConnection(this, OtherNode, Value));
            }
            return(tmpConnection);
        }
Exemple #11
0
        public void Node_Add(PathfinderNode NodeToAdd)
        {
            if (Layer == null)
            {
                Debugger.Break();
                return;
            }

            if (NodeToAdd.Layer.Network_LayerNum != Layer.Network_LayerNum - 1)
            {
                Debugger.Break();
                return;
            }

            if (NodeToAdd.ParentNode != null)
            {
                Debugger.Break();
                return;
            }

            if (Layer_ChangedNodeNum < 0)
            {
                Layer.ChangedNode_Add(this);
            }

            NodeToAdd.ParentNode         = this;
            NodeToAdd.ParentNode_NodeNum = NodeCount;

            Nodes[NodeCount] = NodeToAdd;
            NodeCount++;

            if (NodeToAdd.ConnectionCount == 0)
            {
                Debugger.Break();
            }

            if (NodeToAdd.Clearance > Clearance)
            {
                ClearanceSet(Clearance);
            }
            else
            {
                ClearanceCalc();
            }
        }
Exemple #12
0
        public void FloodCheckInternal(PathfinderNode CurrentNode, ref sVisited Visited)
        {
            var A             = 0;
            var tmpNode       = default(PathfinderNode);
            var tmpConnection = default(PathfinderConnection);

            Visited.Visited[CurrentNode.ParentNode_NodeNum] = true;

            for (A = 0; A <= CurrentNode.ConnectionCount - 1; A++)
            {
                tmpConnection = CurrentNode.Connections[A];
                tmpNode       = tmpConnection.GetOtherNode(CurrentNode);
                if (tmpNode.ParentNode == this)
                {
                    if (!Visited.Visited[tmpNode.ParentNode_NodeNum])
                    {
                        FloodCheckInternal(tmpNode, ref Visited);
                    }
                }
            }
        }
Exemple #13
0
        public PathfinderConnection(PathfinderNode NewNodeA, PathfinderNode NewNodeB, float NewValue)
        {
            if (NewNodeA.Layer.Network_LayerNum > 0 | NewNodeB.Layer.Network_LayerNum > 0 | NewValue <= 0.0F)
            {
                Debugger.Break();
                return;
            }

            Value = NewValue;

            LinkCount = 1;

            NodeA = NewNodeA;
            NodeB = NewNodeB;
            NodeA.Connection_Add(this, ref NodeA_ConnectionNum);
            NodeB.Connection_Add(this, ref NodeB_ConnectionNum);

            NodeA.Layer.Connection_Add(this);

            RaiseDependant();
        }
Exemple #14
0
        public bool NodeCanReachNode(PathfinderNode StartNode, PathfinderNode FinishNode)
        {
            var StartParent  = StartNode;
            var FinishParent = FinishNode;

            do
            {
                if (StartParent == FinishParent)
                {
                    return(true);
                }
                StartParent = StartParent.ParentNode;
                if (StartParent == null)
                {
                    return(false);
                }
                FinishParent = FinishParent.ParentNode;
                if (FinishParent == null)
                {
                    return(false);
                }
            } while (true);
        }
Exemple #15
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);
        }
Exemple #16
0
        public void Split()
        {
            if (NodeCount != 4)
            {
                Debugger.Break();
            }

            float                Value          = 0;
            float                BestValue      = 0;
            PathfinderNode       BestNodeA      = null;
            PathfinderNode       BestNodeB      = null;
            PathfinderNode       BestNodeC      = null;
            PathfinderNode       BestNodeD      = null;
            var                  A              = 0;
            var                  B              = 0;
            var                  tmpNodeA       = default(PathfinderNode);
            var                  tmpNodeB       = default(PathfinderNode);
            var                  tmpNodeC       = default(PathfinderNode);
            var                  tmpNodeD       = default(PathfinderNode);
            PathfinderConnection tmpConnectionA = null;
            PathfinderConnection tmpConnectionB = null;
            var                  C              = 0;
            var                  D              = 0;

            var Children = new PathfinderNode[NodeCount];

            for (A = 0; A <= NodeCount - 1; A++)
            {
                Children[A] = Nodes[A];
            }
            var ChildCount = NodeCount;
            var ThisLayer  = Layer;

            Disband();

            BestValue = float.MaxValue;
            for (A = 0; A <= ChildCount - 1; A++)
            {
                tmpNodeA = Children[A];
                for (B = A + 1; B <= ChildCount - 1; B++)
                {
                    tmpNodeB = Children[B];
                    for (C = 0; C <= ChildCount - 1; C++)
                    {
                        if (Children[C] != tmpNodeA && Children[C] != tmpNodeB)
                        {
                            break;
                        }
                    }
                    tmpNodeC = Children[C];
                    for (D = C + 1; D <= ChildCount - 1; D++)
                    {
                        if (Children[D] != tmpNodeA && Children[D] != tmpNodeB)
                        {
                            break;
                        }
                    }
                    tmpNodeD = Children[D];
                    for (C = 0; C <= tmpNodeA.ConnectionCount - 1; C++)
                    {
                        tmpConnectionA = tmpNodeA.Connections[C];
                        if (tmpConnectionA.GetOtherNode(tmpNodeA) == tmpNodeB)
                        {
                            break;
                        }
                    }
                    for (D = 0; D <= tmpNodeC.ConnectionCount - 1; D++)
                    {
                        tmpConnectionB = tmpNodeC.Connections[D];
                        if (tmpConnectionB.GetOtherNode(tmpNodeC) == tmpNodeD)
                        {
                            break;
                        }
                    }
                    if (C < tmpNodeA.ConnectionCount & D < tmpNodeC.ConnectionCount)
                    {
                        Value = tmpConnectionA.Value + tmpConnectionB.Value;
                        if (Value < BestValue)
                        {
                            BestValue = Value;
                            BestNodeA = tmpNodeA;
                            BestNodeB = tmpNodeB;
                            BestNodeC = tmpNodeC;
                            BestNodeD = tmpNodeD;
                        }
                    }
                }
            }

            if (BestNodeA != null)
            {
                if (ParentNode != null)
                {
                    tmpNodeA = ParentNode;
                    tmpNodeA.Node_Remove(ParentNode_NodeNum);
                }
                else
                {
                    tmpNodeA = null;
                }
                if (tmpNodeA != null)
                {
                    tmpNodeA.CheckIntegrity();
                }

                var NewNodeA = new PathfinderNode(ThisLayer);
                var NewNodeB = new PathfinderNode(ThisLayer);

                NewNodeA.Node_Add(BestNodeA);
                NewNodeA.Node_Add(BestNodeB);

                NewNodeA.SpanCalc();
                BestNodeA.RaiseConnections();
                BestNodeB.RaiseConnections();

                NewNodeA.Layer.Network.FindParentNode_Add(NewNodeA);

                NewNodeB.Node_Add(BestNodeC);
                NewNodeB.Node_Add(BestNodeD);

                NewNodeB.SpanCalc();
                BestNodeC.RaiseConnections();
                BestNodeD.RaiseConnections();

                NewNodeB.Layer.Network.FindParentNode_Add(NewNodeB);
            }
            else
            {
                Debugger.Break();
            }
        }
Exemple #17
0
        public void FindParent()
        {
            var            tmpNodeA      = default(PathfinderNode);
            float          BestScore     = 0;
            PathfinderNode BestNode      = null;
            float          Score         = 0;
            var            A             = 0;
            var            MakeNew       = default(bool);
            var            B             = 0;
            var            Count         = 0;
            var            C             = 0;
            var            Allow         = default(bool);
            var            tmpConnection = default(PathfinderConnection);
            var            DestNode      = default(PathfinderNode);

            if (NodeCount == 0 & Layer.Network_LayerNum > 0)
            {
                Debugger.Break();
                return;
            }

            if (ParentNode != null)
            {
                Debugger.Break();
                return;
            }

            BestScore = float.MaxValue;
            for (A = 0; A <= ConnectionCount - 1; A++)
            {
                tmpConnection = Connections[A];
                DestNode      = tmpConnection.GetOtherNode(this);
                tmpNodeA      = DestNode.ParentNode;
                if (tmpNodeA == null)
                {
                    tmpNodeA = tmpConnection.GetOtherNode(this);
                    Score    = tmpConnection.Value * (0.98F + App.Random.Next() * 0.04F);
                    if (Score < BestScore)
                    {
                        BestScore = Score;
                        BestNode  = tmpNodeA;
                        MakeNew   = true;
                    }
                }
                else
                {
                    //dont allow this to join to another when the other has 3 nodes and they only have one connection
                    if (tmpNodeA.NodeCount == 3)
                    {
                        Count = 0;
                        Allow = false;
                        for (B = 0; B <= tmpNodeA.NodeCount - 1; B++)
                        {
                            for (C = 0; C <= tmpNodeA.Nodes[B].ConnectionCount - 1; C++)
                            {
                                if (tmpNodeA.Nodes[B].Connections[C].GetOtherNode(tmpNodeA.Nodes[B]) == this)
                                {
                                    Count++;
                                    if (Count >= 2)
                                    {
                                        Allow = true;
                                        goto CountFinished;
                                    }
                                    break;
                                }
                            }
                        }
CountFinished:
                        1.GetHashCode(); //TODO: cleanup this loop
                    }
                    else
                    {
                        Allow = true;
                    }
                    if (Allow)
                    {
                        Score = (DestNode.SiblingSpan + tmpConnection.Value) * (0.98F + App.Random.Next() * 0.04F);
                        if (Score < BestScore)
                        {
                            BestScore = Score;
                            BestNode  = tmpNodeA;
                            MakeNew   = false;
                        }
                    }
                }
            }
            if (BestNode != null)
            {
                if (MakeNew)
                {
                    var tmpLayer = default(PathfinderLayer);
                    if (Layer.ParentLayer == null)
                    {
                        tmpLayer = new PathfinderLayer(Layer.Network);
                    }
                    else
                    {
                        tmpLayer = Layer.ParentLayer;
                    }
                    var NewNode = new PathfinderNode(tmpLayer);
                    NewNode.Node_Add(this);
                    NewNode.Node_Add(BestNode);
                    NewNode.SpanCalc();
                    RaiseConnections();
                    BestNode.RaiseConnections();
                    NewNode.Layer.Network.FindParentNode_Add(NewNode);
                }
                else
                {
                    if (BestNode != null)
                    {
                        BestNode.Node_Add(this);
                        if (BestNode.NodeCount >= 4)
                        {
                            BestNode.Split();
                        }
                        else
                        {
                            BestNode.SpanCalc();
                            RaiseConnections();
                            if (BestNode.ParentNode == null)
                            {
                                BestNode.Layer.Network.FindParentNode_Add(BestNode);
                            }
                        }
                    }
                }
            }
            else if (ConnectionCount > 0)
            {
                //it is part of a network but there is no suitable parent to join, so make a new isolated parent
                var tmpLayer = default(PathfinderLayer);
                if (Layer.ParentLayer == null)
                {
                    tmpLayer = new PathfinderLayer(Layer.Network);
                }
                else
                {
                    tmpLayer = Layer.ParentLayer;
                }
                var NewNode = new PathfinderNode(tmpLayer);
                NewNode.Node_Add(this);
                NewNode.SpanCalc();
                RaiseConnections();
                NewNode.Layer.Network.FindParentNode_Add(NewNode);
            }
        }
Exemple #18
0
        public void FindCalc()
        {
            PathfinderNode[] ShuffledNodes = null;
            var ShuffledNodeCount          = 0;

            int[] Positions     = null;
            var   PositionCount = 0;
            var   RandNum       = 0;
            var   A             = 0;

            while (FindParentNodeCount > 0)
            {
                Positions         = new int[FindParentNodeCount];
                ShuffledNodeCount = FindParentNodeCount;
                ShuffledNodes     = new PathfinderNode[ShuffledNodeCount];

                for (A = 0; A <= FindParentNodeCount - 1; A++)
                {
                    Positions[PositionCount] = PositionCount;
                    PositionCount++;
                }
                for (A = 0; A <= FindParentNodeCount - 1; A++)
                {
                    RandNum = App.Random.Next() * PositionCount;
                    ShuffledNodes[Positions[RandNum]] = FindParentNodes[A];
                    PositionCount--;
                    if (RandNum < PositionCount)
                    {
                        Positions[RandNum] = Positions[PositionCount];
                    }
                }

                for (A = 0; A <= ShuffledNodeCount - 1; A++)
                {
                    if (ShuffledNodes[A].Network_FindParentNum >= 0)
                    {
                        if (ShuffledNodes[A].ParentNode == null)
                        {
                            ShuffledNodes[A].FindParent();
                        }
                        FindParentNode_Remove(ShuffledNodes[A].Network_FindParentNum);
                    }
                }
            }

            //remove empty layers
            var LayerNum = NodeLayerCount - 1;

            do
            {
                if (NodeLayers[LayerNum].NodeCount > 0)
                {
                    break;
                }
                NodeLayers[LayerNum].Network_LayerNum = -1;
                if (LayerNum == 0)
                {
                    break;
                }
                NodeLayers[LayerNum - 1].ParentLayer = null;
                LayerNum--;
            } while (true);
            if (LayerNum < NodeLayerCount - 1)
            {
                Array.Resize(ref NodeLayers, LayerNum + 1);
                NodeLayerCount = LayerNum + 1;
            }
        }
Exemple #19
0
 public void ForceDeallocate()
 {
     DependantConnection = null;
     NodeA = null;
     NodeB = null;
 }
Exemple #20
0
        public Path[] GetAllPaths(PathfinderNode[] StartNodes, PathfinderNode FinishNode, int MinClearance)
        {
            var StartNodeCount   = StartNodes.GetUpperBound(0) + 1;
            var LayerStartNodes  = new PathfinderNode[32, StartNodeCount];
            var LayerFinishNodes = new PathfinderNode[32];
            var LayerNum         = 0;
            var FloodRouteDArgs  = new sFloodRouteAllArgs();
            var FinalLayer       = 0;
            var StartCanReach    = new bool[StartNodeCount];
            var tmpNodeA         = default(PathfinderNode);
            var CanReachCount    = 0;
            var FirstLayer       = 0;
            var SubPaths         = new Path[32];
            var Nodes_Nodes      = NetworkLargeArrays.Nodes_Nodes;
            var Visit            = NetworkLargeArrays.Nodes_Booleans;
            var NodeValues       = NetworkLargeArrays.Nodes_ValuesA;
            var NodeValuesB      = NetworkLargeArrays.Nodes_ValuesB;
            var A = 0;
            var B = 0;
            var C = 0;
            var D = 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;
            SubPaths[LayerNum]           = new Path();
            SubPaths[LayerNum].Nodes     = new[] { LayerFinishNodes[LayerNum] };
            SubPaths[LayerNum].NodeCount = 1;
            var LastLayer = 0;

            do
            {
                LastLayer = LayerNum;
                LayerNum--;
                if (LayerNum < FinalLayer)
                {
                    break;
                }
                for (A = 0; A <= SubPaths[LastLayer].NodeCount - 1; A++)
                {
                    tmpNodeA = SubPaths[LastLayer].Nodes[A];
                    for (B = 0; B <= tmpNodeA.ConnectionCount - 1; B++)
                    {
                        C        = tmpNodeA.Connections[B].GetOtherNode(tmpNodeA).Layer_NodeNum;
                        Visit[C] = false;
                    }
                }
                for (A = 0; A <= SubPaths[LastLayer].NodeCount - 1; A++)
                {
                    tmpNodeA = SubPaths[LastLayer].Nodes[A];
                    C        = tmpNodeA.Layer_NodeNum;
                    Visit[C] = true;
                    for (D = 0; D <= tmpNodeA.NodeCount - 1; D++)
                    {
                        C              = tmpNodeA.Nodes[D].Layer_NodeNum;
                        NodeValues[C]  = float.MaxValue;
                        NodeValuesB[C] = float.MaxValue;
                    }
                }
                FloodRouteDArgs               = new sFloodRouteAllArgs();
                FloodRouteDArgs.FinishNode    = LayerFinishNodes[LayerNum];
                FloodRouteDArgs.Visit         = Visit;
                FloodRouteDArgs.NodeValuesA   = NodeValues;
                FloodRouteDArgs.SourceNodes   = Nodes_Nodes;
                FloodRouteDArgs.NodeValuesB   = NodeValuesB;
                FloodRouteDArgs.MinClearance  = MinClearance;
                FloodRouteDArgs.BestTolerance = (float)(Math.Pow(1.1D, LayerNum));
                FloodRouteDArgs.StartNodes    = new PathfinderNode[StartNodeCount];
                for (A = 0; A <= StartNodeCount - 1; A++)
                {
                    if (StartCanReach[A])
                    {
                        FloodRouteDArgs.StartNodes[FloodRouteDArgs.StartNodeCount] = LayerStartNodes[LayerNum, A];
                        FloodRouteDArgs.StartNodeCount++;
                    }
                }
                Array.Resize(ref FloodRouteDArgs.StartNodes, FloodRouteDArgs.StartNodeCount);
                FloodRouteAll(ref FloodRouteDArgs);
                SubPaths[LayerNum]       = new Path();
                SubPaths[LayerNum].Nodes = new PathfinderNode[FloodRouteDArgs.BestNodeCount];
                for (A = 0; A <= FloodRouteDArgs.BestNodeCount - 1; A++)
                {
                    SubPaths[LayerNum].Nodes[A] = FloodRouteDArgs.SourceNodes[A];
                }
                SubPaths[LayerNum].NodeCount = FloodRouteDArgs.BestNodeCount;
                if (FloodRouteDArgs.BestNodeCount == 0)
                {
                    Debugger.Break();
                    return(SubPaths);
                }
            } while (true);
            return(SubPaths);
        }