Ejemplo n.º 1
0
        /// <summary>
        /// Uses A* algorithm to find a path from disconnected clusters to main cluster and
        /// convert nodes on that path to floors.
        /// </summary>
        public void ConnectClusters()
        {
            int mainClusterIndex = CalculateMainCluster();

            NodeCluster mainCluster = Clusters [mainClusterIndex];

            for (int clusterIndex = 0; clusterIndex < Clusters.Count; clusterIndex++)
            {
                if (clusterIndex != mainClusterIndex)
                {
                    NodeCluster origCluster = Clusters [clusterIndex];

                    Node origCell = origCluster.Nodes [(int)((origCluster.Nodes.Count - 1) * Random.value)];

                    Node destCell = mainCluster.Nodes [(int)((mainCluster.Nodes.Count - 1) * Random.value)];

                    List <Node> path = pathManager.GetShortestPath(origCell, destCell, 1f, true);


                    if (path == null || path.Count == 0)
                    {
                        if (Utilities.instance.IsDebug)
                        {
                            Debug.Log(SCRIPT_NAME + ": no path found");
                        }
                    }
                    else
                    {
                        ConstructPath(path, NodeType.Floor);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Iterats through each cluster and returns the index of the cluster with the largest size.
        /// </summary>
        /// <returns>The main cluster index.</returns>
        public int CalculateMainCluster()
        {
            int mainClusterIndex = -1;
            int maxClusterSize   = 0;

            for (int i = 0; i < Clusters.Count; i++)
            {
                NodeCluster cluster = Clusters [i];

                int cellCount = cluster.Nodes.Count;

                if (cellCount > maxClusterSize)
                {
                    maxClusterSize   = cellCount;
                    mainClusterIndex = i;
                }
            }

            return(mainClusterIndex);
        }