Example #1
0
 public void Randomize()
 {
     LoggerTool.Post("Generate a randomize island for preview");
     generator.useRandomSeed = true;
     UpdateInputValue();
     generator.GenerateIsland();
 }
Example #2
0
 public void GenerateWithSeed()
 {
     LoggerTool.Post("Generate a seeded island for preview");
     generator.useRandomSeed = false;
     generator.seed          = seedInput.text;
     UpdateInputValue();
     generator.GenerateIsland();
 }
 void OnValuesUpdated()
 {
     if (!Application.isPlaying)
     {
         LoggerTool.Post("Generate island from Editor");
         GenerateIsland();
     }
 }
Example #4
0
        protected void packOneBundlePack()
        {
            string        resPath        = "";
            List <string> assetNamesList = new List <string>();
            List <Object> objList        = new List <Object>();

            UnityEngine.Object go;

            List <string> pathList  = new List <string>();
            List <string> filesList = ExportUtil.GetAll(ExportUtil.getDataPath(m_packParam.m_inPath));
            string        ext       = "";
            string        nameNoExt = "";

#if UNITY_4_6
            string tmpStr = "";
#endif
            AssetBundleParam bundleParam = new AssetBundleParam();

            foreach (string filePath in filesList)
            {
                objList.Clear();
                assetNamesList.Clear();
                ext       = ExportUtil.getFileExt(filePath);
                nameNoExt = ExportUtil.getFileNameNoExt(filePath);
                if (ExportUtil.isArrContainElem(ext, m_packParam.m_extArr))
                {
                    resPath = ExportUtil.convFullPath2AssetsPath(filePath);
                    assetNamesList.Add(resPath);
                    go = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(ExportUtil.convExt2ResStr(ext)));
                    if (go)
                    {
                        objList.Add(go);

#if UNITY_5
                        bundleParam.m_buildList = new AssetBundleBuild[1];
                        bundleParam.m_buildList[0].assetBundleName    = nameNoExt;
                        bundleParam.m_buildList[0].assetBundleVariant = ExportUtil.UNITY3D;
                        bundleParam.m_buildList[0].assetNames         = assetNamesList.ToArray();
                        pathList.Clear();
                        pathList.Add(m_packParam.m_outPath);
                        bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
#elif UNITY_4_6 || UNITY_4_5
                        bundleParam.m_assets = objList.ToArray();
                        pathList.Clear();
                        pathList.Add(m_packParam.m_outPath);
                        tmpStr = string.Format("{0}{1}", nameNoExt, ExportUtil.DOTUNITY3D);
                        pathList.Add(tmpStr);
                        bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
#endif
                        ExportUtil.BuildAssetBundle(bundleParam);
                    }
                    else
                    {
                        LoggerTool.error(string.Format("AssetDatabase.LoadAssetAtPath 不能加载资源 {0}", filePath));
                    }
                }
            }
        }
    void InitializeDatabase()
    {
        NameGenerator nameGen = GetComponent <NameGenerator> ();

        if (!JsonFile.FilesExistIn("NameGenerator"))
        {
            LoggerTool.Post("Initializing Database");
            nameGen.BuildDatabase();
        }
    }
Example #6
0
    // Called by LandMap.GetZones (), returns number of subregions
    public int ClusterLocationsAccordKMeans(MapPoint[,] points, TerrainVerticesDatabase vertDatabase)
    {
        // K-means cluster algorithm to separate locations in the regions

        int regionId = 0;

        for (int isleId = 0; isleId < regions.Count; isleId++)
        {
            MapRegion region = regions[isleId];

            double[][] tileLocations = new double[region.turf.Count][];

            for (int i = 0; i < tileLocations.Length; i++)
            {
                tileLocations[i] = new double[3];

                TerrainVertData vertData = vertDatabase.GetVertDataFromRegionTile(region.turf[i], isleId);
                //LoggerTool.Post ("Requesting " + region.turf[i].ToString ());
                if (vertData != null)
                {
                    tileLocations[i][0] = region.turf[i].x;
                    tileLocations[i][1] = vertData.inlandPosition;
                    tileLocations[i][2] = region.turf[i].y;
                }
                else
                {
                    LoggerTool.Post("Null from VertDB for " + region.turf[i].ToString());
                    tileLocations[i][0] = 0;
                    tileLocations[i][1] = 0;
                    tileLocations[i][2] = 0;
                }
            }

            int k = InitializeNumOfK(tileLocations.Length);
            Debug.Log(k + " centroid(s)");

            KMeans kmeans = new KMeans(k);
            KMeansClusterCollection clusters = kmeans.Learn(tileLocations);

            int[] labels = clusters.Decide(tileLocations);

            Debug.Log("Number of labels (clusters) = " + labels.Length);
            for (int i = 0; i < labels.Length; i++)
            {
                points[(int)tileLocations[i][0], (int)tileLocations[i][2]].areaValue = regionId + labels[i];
            }

            regionId += k;
        }

        return(regionId);
    }
Example #7
0
    public static void Delete(string fileName, string folder)
    {
        string path = Application.persistentDataPath + "/" + folder + "/" + fileName;

        if (File.Exists(path))
        {
            File.Delete(path);
        }
        else
        {
            Debug.LogWarning(fileName + " not found in the " + folder + " folder!");
            LoggerTool.Post(fileName + " not found in the " + folder + " folder!", false);
        }
    }
 void Awake()
 {
     if (Instance == null)
     {
         Instance = (T)this;
         SingletonAwake();
     }
     else
     {
         Debug.LogWarning("Duplicate singleton " + GetType(), this);
         LoggerTool.Post("Duplicate singleton " + GetType(), false);
         Destroy(gameObject);
     }
 }
Example #9
0
        protected void packOneBundlePack(PackParam param)
        {
            string        resPath        = "";
            List <Object> objList        = new List <Object>();
            List <string> assetNamesList = new List <string>();

            UnityEngine.Object go;

            List <string> pathList = new List <string>();

            foreach (PackItem packItem in m_packList)
            {
                pathList.Clear();
                pathList.Add(param.m_inPath);
                pathList.Add(packItem.m_path);

                resPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray()));
                assetNamesList.Add(resPath);
                go = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(packItem.m_resType));
                if (go)
                {
                    objList.Add(go);
                }
                else
                {
                    LoggerTool.error(string.Format("AssetDatabase.LoadAssetAtPath 不能加载资源 {0}", resPath));
                }
            }

            AssetBundleParam bundleParam = new AssetBundleParam();

#if UNITY_5
            bundleParam.m_buildList = new AssetBundleBuild[1];
            bundleParam.m_buildList[0].assetBundleName    = m_name;
            bundleParam.m_buildList[0].assetBundleVariant = UtilApi.UNITY3D;
            bundleParam.m_buildList[0].assetNames         = assetNamesList.ToArray();
            pathList.Clear();
            pathList.Add(param.m_outPath);
            bundleParam.m_pathName = ExportUtil.getStreamingDataPath(UtilPath.combine(pathList.ToArray()));
#elif UNITY_4_6 || UNITY_4_5
            bundleParam.m_assets = objList.ToArray();
            pathList.Clear();
            pathList.Add(param.m_outPath);
            pathList.Add(m_name);
            bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray()));
#endif

            ExportUtil.BuildAssetBundle(bundleParam);
        }
Example #10
0
    public void SetVerticesBottomPoint(List <Vector3> vertices, Vector3 origin)
    {
        for (int i = 0; i < vertices.Count; i++)
        {
            Vector2 key = (vertices[i] + origin).ToVec2FromXZ();

            if (!verticesDictionary.ContainsKey(key))
            {
                LoggerTool.Post(key.ToString() + " is not found while setting bottom point!");
                continue;
            }

            verticesDictionary[key].bottomPoint = vertices[i].y;
        }
    }
    void Update()
    {
        if (!readyPlaying && generator.IsDone())
        {
            LoggerTool.Post("Generated with " + clock.Elapsed() + " seconds.");
            readyPlaying = true;

            if (overviewCam)
            {
                overviewCam.SetActive(false);
            }

            curtain.FadeToColour(Color.clear);
        }
    }
Example #12
0
    public void BuildDatabase()
    {
        Prefix currentPrefix = new Prefix(2);

        for (int i = 0; i <= sample.Length; i++)
        {
            char   next          = i < sample.Length ? CheckCharOf(sample[i]) : '*';
            Suffix currentSuffix = new Suffix(next);
            AddToDatabase(currentPrefix, currentSuffix);
            currentPrefix.Add(next);
        }

        SaveDatabase();
        LoggerTool.Post("Finished building database!");
    }
Example #13
0
    public static void Load <T> (string fileName, string folder, ref T saveData)
    {
        string path = Application.persistentDataPath + "/" + folder + "/" + fileName;

        if (File.Exists(path))
        {
            string jsonData = File.ReadAllText(path);
            saveData = JsonUtility.FromJson <T> (jsonData);
        }
        else
        {
            Debug.LogWarning(fileName + " not found in the " + folder + " folder!");
            LoggerTool.Post(fileName + " not found in the " + folder + " folder!", false);
        }
    }
Example #14
0
    // Called by LandMap.GetZones (), returns number of subregions
    public int ClusterLocationsDBSCAN(float epsilon, int minPts, MapPoint[,] points, TerrainVerticesDatabase vertDatabase)
    {
        // DBSCAN cluster algorithm to separate locations in the regions

        int regionId = 0;

        for (int isleId = 0; isleId < regions.Count; isleId++)
        {
            MapRegion region = regions[isleId];

            List <TilePoint> tileLocations = new List <TilePoint> ();

            for (int i = 0; i < region.turf.Count; i++)
            {
                TerrainVertData vertData = vertDatabase.GetVertDataFromRegionTile(region.turf[i], isleId);
                if (vertData != null)
                {
                    tileLocations.Add(new TilePoint(region.turf[i].x, vertData.inlandPosition, region.turf[i].y));
                }
                else
                {
                    LoggerTool.Post("Null from VertDB for " + region.turf[i].ToString());
                }
            }

            HashSet <TilePoint[]> clusters;

            var dbscan = new DbscanImplementation.DbscanAlgorithm <TilePoint> ((t1, t2) => TilePoint.Dist(t1, t2));
            dbscan.ComputeClusterDbscan(allPoints: tileLocations.ToArray(), epsilon: epsilon, minPts: minPts, clusters: out clusters);

            int k = clusters.Count;
            Debug.Log("Number of clusters = " + k);

            int clstCount = 0;
            foreach (var tiles in clusters)
            {
                for (int i = 0; i < tiles.Length; i++)
                {
                    points[(int)tiles[i].X, (int)tiles[i].Z].areaValue = regionId + clstCount;
                }
                clstCount++;
            }

            regionId += k;
        }

        return(regionId);
    }
Example #15
0
    public static string[] GetAllFilesIn(string folder)
    {
        string folderPath = Application.persistentDataPath + "/" + folder;

        if (!Directory.Exists(folderPath))
        {
            Debug.LogWarning(folder + " folder not found!");
            LoggerTool.Post(folder + " folder not found!", false);
            return(null);
        }

        string[] files = Directory.GetFiles(folderPath, "*.json");
        for (int i = 0; i < files.Length; i++)
        {
            files[i] = Path.GetFileName(files[i]);
        }

        return(files);
    }
    void Start()
    {
        if (inputManagerDatabase == null)
        {
            inputManagerDatabase = (InputManager)Resources.Load("InputManager");
        }
        if (inventory == null)
        {
            inventory = GameObject.FindGameObjectWithTag("MainInventory");
            if (inventory)
            {
                inventory.SetActive(false);
            }
            else
            {
                LoggerTool.Post(gameObject.name + ": MainInventory not found");
            }
        }

        stats = GetComponent <PlayerStats> ();

        if (craftSystem != null)
        {
            cS = craftSystem.GetComponent <CraftSystem> ();
        }

        if (GameObject.FindGameObjectWithTag("Tooltip") != null)
        {
            toolTip = GameObject.FindGameObjectWithTag("Tooltip").GetComponent <Tooltip> ();
        }
        if (inventory != null)
        {
            mainInventory = inventory.GetComponent <Inventory> ();
        }
        if (characterSystem != null)
        {
            characterSystemInventory = characterSystem.GetComponent <Inventory> ();
        }
        if (craftSystem != null)
        {
            craftSystemInventory = craftSystem.GetComponent <Inventory> ();
        }
    }
    public override void OnInspectorGUI()
    {
        IslandGenerator islandGen = target as IslandGenerator;

        if (DrawDefaultInspector())
        {
            if (islandGen.autoUpdate)
            {
                LoggerTool.Post("Generate island from Editor");
                islandGen.GenerateIsland(false);
            }
        }

        GUILayout.Space(10);
        if (GUILayout.Button("Generate"))
        {
            LoggerTool.Post("Generate island from Editor");
            islandGen.GenerateIsland(false);
        }
    }
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            LoggerTool.Post("Start generating island from a click");
            bool prevRandSet = islandGenerator.useRandomSeed;
            islandGenerator.useRandomSeed = useRandomSeed;
            startedRecording = true;
            clock.Start();
            islandGenerator.GenerateIsland();
            islandGenerator.useRandomSeed = prevRandSet;
        }

        if (startedRecording && islandGenerator.IsDone())
        {
            startedRecording = false;
            LoggerTool.Post("Generated with " + clock.Elapsed() + " seconds.");
            LoggerTool.Post(" ----------------------- ");
        }
    }
    IEnumerator LoadGameLevelWithProgress(string levelName)
    {
        yield return(new WaitForSecondsRealtime(0.5f));

        loadingOperation = SceneManager.LoadSceneAsync(levelName);
        loadingOperation.allowSceneActivation = false;

        while (!loadingOperation.isDone)
        {
            LoggerTool.Post("Loading progress " + (loadingOperation.progress * 100) + "%");

            if (loadingOperation.progress >= 0.9f)
            {
                loadingOperation.allowSceneActivation = true;
                LoggerTool.Post("Loaded level [" + levelName + "] with " + clock.Elapsed() + " seconds.");
            }

            yield return(null);
        }
    }
Example #20
0
    public List <MapRegion> GetZones(int zoneNum)
    {
        // Initialize list to prepare zones
        List <List <Coord> > zoneTiles = new List <List <Coord> > ();

        for (int i = 0; i <= zoneNum; i++)
        {
            zoneTiles.Add(new List <Coord> ());
        }

        LoggerTool.Post("ZoneNum: " + zoneNum);

        // Fill the lists
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < length; y++)
            {
                if (spots[x, y].filled)
                {
                    spots[x, y].areaValue = (spots[x, y].areaValue != -1) ? spots[x, y].areaValue : (zoneNum - 1);
                    zoneTiles[spots[x, y].areaValue].Add(new Coord(x, y));
                }
            }
        }

        List <MapRegion> zones = new List <MapRegion> ();

        for (int i = 0; i < zoneNum; i++)
        {
            if (zoneTiles[i].Count > 0)
            {
                zones.Add(new MapRegion(zoneTiles[i], width, length));
            }
            else
            {
                LoggerTool.Post("Zone " + (i + 1) + " is empty, skip creating zone region.");
            }
        }

        return(zones);
    }
Example #21
0
    public void BuildDatabase()
    {
        PrefixWord currentPrefix = new PrefixWord(2);

        char[]   delimiterChars = { ' ', '\t', '\n', '\r' };
        string[] words          = sample.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);

        //string pattern = @"\s?";
        //string[] words = Regex.Split (sample, pattern);

        for (int i = 0; i <= words.Length; i++)
        {
            string     next          = i < words.Length ? words[i] : "*";
            SuffixWord currentSuffix = new SuffixWord(next);
            AddToDatabase(currentPrefix, currentSuffix);
            currentPrefix.Add(next);
        }

        SaveDatabase();
        LoggerTool.Post("Finished building story database!");
    }
 void Start()
 {
     LoggerTool.Post("GameController: Started game.");
 }
 //Animation Events
 void Hit()
 {
     LoggerTool.Post("PlayerControllerExtension: Hit! (Animation event)", true, false);
 }
    int DoClustering(List <MapRegion> regions, MapPoint[,] spots, TerrainVerticesDatabase vertDatabase, CAMethod clusteringAlgo, int seed)
    {
        Cluster cl = new Cluster(regions, islandData.tileSize, seed);
        int     numOfCluster;

        switch (clusteringAlgo)
        {
        default:
        case CAMethod.KMeans3D:
            LoggerTool.Post("Using K-Means inclusive heights.");
            numOfCluster = cl.ClusterLocationsKMeans(spots, vertDatabase);
            break;

        case CAMethod.KMeans3DAccord:
            LoggerTool.Post("Using K-Means inclusive heights with Accord library.");
            numOfCluster = cl.ClusterLocationsAccordKMeans(spots, vertDatabase);
            break;

        case CAMethod.KMeans2D:
            LoggerTool.Post("Using K-Means straightforward.");
            numOfCluster = cl.ClusterLocationsKMeans(spots);
            break;

        case CAMethod.KMeans2DAccord:
            LoggerTool.Post("Using K-Means straightforward with Accord library.");
            numOfCluster = cl.ClusterLocationsAccordKMeans(spots);
            break;

        case CAMethod.Dbscan2D:
            LoggerTool.Post("Using DBSCAN straightforward.");
            numOfCluster = cl.ClusterLocationsDBSCAN(6, 20, spots);
            break;

        case CAMethod.Dbscan3D:
            LoggerTool.Post("Using DBSCAN inclusive heights.");
            numOfCluster = cl.ClusterLocationsDBSCAN(6, 20, spots, vertDatabase);
            break;

        case CAMethod.KMedoidsPam2D:
            LoggerTool.Post("Using K-Medoids (PAM) straightforward.");
            numOfCluster = cl.ClusterLocationsKMedoidsPAM(spots);
            break;

        case CAMethod.KMedoidsPam2DAccord:
            LoggerTool.Post("Using K-Medoids (PAM) straightforward with Accord library.");
            numOfCluster = cl.ClusterLocationsAccordKMedoidsPAM(spots);
            break;

        case CAMethod.KMedoidsVoronoi2D:
            LoggerTool.Post("Using K-Medoids (voronoi iteration) straightforward.");
            numOfCluster = cl.ClusterLocationsKMedoidsVoronoi(spots);
            break;

        case CAMethod.KMedoidsVoronoi2DAccord:
            LoggerTool.Post("Using K-Medoids (voronoi iteration) straightforward with Accord library.");
            numOfCluster = cl.ClusterLocationsAccordKMedoidsVoronoi(spots);
            break;

        case CAMethod.KMedoidsPam3DAccord:
            LoggerTool.Post("Using K-Medoid inclusive heights (PAM) with Accord library.");
            numOfCluster = cl.ClusterLocationsAccordKMedoidsPAM(spots, vertDatabase);
            break;

        case CAMethod.KMedoidsVoronoi3DAccord:
            LoggerTool.Post("Using K-Medoid inclusive heights (voronoi iteration) with Accord library.");
            numOfCluster = cl.ClusterLocationsAccordKMedoidsVoronoi(spots, vertDatabase);
            break;
        }

        return(numOfCluster);
    }
Example #25
0
    // Called by LandMap.GetZones (), returns number of subregions
    public int ClusterLocationsKMeans(MapPoint[,] points, TerrainVerticesDatabase vertDatabase)
    {
        // K-means cluster algorithm to separate locations in the regions

        int regionId = 0;

        for (int isleId = 0; isleId < regions.Count; isleId++)
        {
            MapRegion region = regions[isleId];

            Vector3[] tileLocations = new Vector3[region.turf.Count];
            for (int i = 0; i < tileLocations.Length; i++)
            {
                TerrainVertData vertData = vertDatabase.GetVertDataFromRegionTile(region.turf[i], isleId);
                if (vertData != null)
                {
                    tileLocations[i] = new Vector3(region.turf[i].x, vertData.surfaceElevatedCurve, region.turf[i].y);
                }
                else
                {
                    LoggerTool.Post("Null from VertDB for " + region.turf[i].ToString());
                }
            }

            int k = InitializeNumOfK(tileLocations.Length);
            Debug.Log(k + " centroid(s)");

            Vector3[] centroids = new Vector3[k];
            for (int i = 0; i < k; i++)
            {
                // Assign centroid to first k data points
                centroids[i] = tileLocations[i * (tileLocations.Length / k)];
                //centroids[i] = tileLocations[i];
            }

            // Loop until converged
            int changes = -1;
            int iter    = 0;
            while (changes != 0 /* && iter < 1*/)
            {
                changes = 0;

                for (int tIndex = 0; tIndex < tileLocations.Length; tIndex++)
                {
                    Coord tile = region.turf[tIndex];

                    int   initialArea        = points[tile.x, tile.y].areaValue;
                    float distanceToCentroid = float.MaxValue;

                    for (int i = 0; i < k; i++)
                    {
                        //float currDistToCentroid = centroids[i].ManhattanDist (tileLocations[tIndex]);
                        //float currDistToCentroid = Vector3.Distance (centroids[i], tileLocations[tIndex]);
                        float currDistToCentroid = Vector2.Distance(centroids[i].ToVec2FromXZ(), tileLocations[tIndex].ToVec2FromXZ());
                        if (currDistToCentroid < distanceToCentroid)
                        {
                            distanceToCentroid = currDistToCentroid;
                            points[tile.x, tile.y].areaValue = regionId + i;
                        }
                    }

                    if (initialArea != points[tile.x, tile.y].areaValue)
                    {
                        changes++;
                    }
                }

                int[]     frequency           = new int[k];
                Vector3[] cumulativeCentroids = new Vector3[k];
                for (int i = 0; i < k; i++)
                {
                    frequency[i]           = 0;
                    cumulativeCentroids[i] = Vector3.zero;
                }

                for (int i = 0; i < tileLocations.Length; i++)
                {
                    Coord tile = region.turf[i];
                    cumulativeCentroids[Mathf.Max(0, points[tile.x, tile.y].areaValue - regionId)] += tileLocations[i];
                    frequency[Mathf.Max(0, points[tile.x, tile.y].areaValue - regionId)]++;
                }

                for (int i = 0; i < k; i++)
                {
                    if (frequency[i] != 0)
                    {
                        centroids[i] = cumulativeCentroids[i] / frequency[i];
                    }
                    else
                    {
                        centroids[i] = tileLocations[Random.Range(0, tileLocations.Length)];
                    }
                }

                iter++;
            }

            for (int i = 0; i < k; i++)
            {
                Debug.Log("Centroid " + (regionId + i) + " at " + centroids[i].ToString());
            }

            LoggerTool.Post("No of iteration: " + iter);
            regionId += k;
        }

        return(regionId);
    }
 void Land()
 {
     LoggerTool.Post("PlayerControllerExtension: Land! (Animation event)", true, false);
 }
 void Jump()
 {
     LoggerTool.Post("PlayerControllerExtension: Jump! (Animation event)", true, false);
 }
Example #28
0
    // Called by LandMap.GetZones (), returns number of subregions
    public int ClusterLocationsDBSCAN(float epsilon, int minPts, MapPoint[,] points)
    {
        // DBSCAN cluster algorithm to separate locations in the regions

        Dictionary <Coord, ClusterPoint> clusteredPts = new Dictionary <Coord, ClusterPoint> ();

        foreach (MapRegion region in regions)
        {
            foreach (Coord tile in region.turf)
            {
                if (!clusteredPts.ContainsKey(tile))
                {
                    clusteredPts.Add(tile, new ClusterPoint());
                }
                else
                {
                    LoggerTool.Post("DBSCAN: Duplicate of tile found! (" + tile.x + "," + tile.y + ")");
                }
            }
        }

        int regionId = 0;

        foreach (MapRegion region in regions)
        {
            foreach (Coord tile in region.turf)
            {
                ClusterPoint cPt;
                if (clusteredPts[tile].done)
                {
                    continue;
                }

                List <Coord> n = RangeQueries(region.turf, tile, epsilon);
                if (n.Count + 1 < minPts)
                {
                    cPt = clusteredPts[tile];
                    cPt.regionNumber = -1;
                    points[tile.x, tile.y].areaValue = -1;
                    cPt.done           = true;
                    clusteredPts[tile] = cPt;
                    LoggerTool.Post("Outlier", true, false);
                    continue;
                }
                else
                {
                    LoggerTool.Post("Zone " + regionId);
                    cPt = clusteredPts[tile];
                    cPt.regionNumber = regionId;
                    points[tile.x, tile.y].areaValue = regionId;
                    cPt.done           = true;
                    clusteredPts[tile] = cPt;
                }

                for (int i = 0; i < n.Count; i++)
                {
                    Coord q = n[i];
                    if (clusteredPts[q].regionNumber == -1)
                    {
                        cPt = clusteredPts[q];
                        cPt.regionNumber           = regionId;
                        points[q.x, q.y].areaValue = regionId;
                        cPt.done        = true;
                        clusteredPts[q] = cPt;
                    }

                    if (clusteredPts[q].done)
                    {
                        continue;
                    }

                    cPt = clusteredPts[q];
                    cPt.regionNumber           = regionId;
                    points[q.x, q.y].areaValue = regionId;
                    cPt.done        = true;
                    clusteredPts[q] = cPt;

                    List <Coord> nb = RangeQueries(region.turf, q, epsilon);
                    if (nb.Count >= minPts)
                    {
                        n.AddRange(nb);
                    }
                }

                regionId++;
            }
        }

        return(regionId + 1);
    }
 public virtual void Interact()
 {
     // This method is meant to be overwritten
     LoggerTool.Post("Interacting with " + transform.name, true, false);
 }
    IEnumerator GenerateInProgress()
    {
        finished = false;

        if (useRandomSeed)
        {
            seed = DateTime.Now.ToString();
        }

        Random.State oldState = Random.state;
        int          seedHash = seed.GetHashCode();

        Random.InitState(seedHash);

        yield return(new WaitForEndOfFrame());

        for (int i = 0; i < randCol.Length; i++)
        {
            randCol[i] = Random.ColorHSV(0, 1, 0, 1, 0.5f, 1);
        }

        yield return(new WaitForEndOfFrame());

        map = new LandMap(islandData.maxWidth, islandData.maxHeight);

        // Fill the map randomly with 0s and 1s based on percentage fill
        map.RandomFillMap(islandData.randomFillPercent);

        // Mold to the base shape
        if (islandData.baseShape)
        {
            map.makeBaseShape(islandData.baseShape);
        }

        // Smooth the map 5 times
        map.SmoothMap(5);

        yield return(new WaitForEndOfFrame());

        meshGen = GetComponent <IslandMeshGenerator> ();
        vertDatabase.Clear();
        vertDatabase.tileSize = islandData.tileSize;

        // Find separated regions to form an island
        List <MapRegion> regions = map.GetRegions();

        yield return(new WaitForEndOfFrame());

        // Create separate islands
        SeparateIslands(regions);

        yield return(new WaitForEndOfFrame());

        clk.Start();
        vertDatabase.SetCoordDB();
        LoggerTool.Post("Indexing takes " + clk.Elapsed() + " seconds.");

        yield return(new WaitForEndOfFrame());

        if (shouldElevate)
        {
            int highestPeak = 0;
            foreach (IsleInfo island in islands)
            {
                int peak = island.surfaceMeshDetail.localPeak;
                highestPeak = peak > highestPeak ? peak : highestPeak;
            }
            foreach (IsleInfo island in islands)
            {
                island.surfaceMeshDetail.NormalizeGradientMap(highestPeak);
            }

            vertDatabase.SetVerticesInlandPos(islands, islandData.mountainCurve);

            ElevationGenerator elevGen = GetComponent <ElevationGenerator> ();
            elevGen.elevateSurface(islands, islandData.altitude, islandData.mountainCurve, surfaceNoiseData, seedHash, 0, vertDatabase);    // elevate hills on the surface
            elevGen.elevateSurface(islands, -islandData.stalactite, islandData.bellyCurve, undersideNoiseData, seedHash, 2, vertDatabase);  // extend stakes at surface below
        }

        yield return(new WaitForEndOfFrame());

        clk.Start();
        int zoneNum = DoClustering(regions, map.spots, vertDatabase, clusterAnalysis, seedHash);

        LoggerTool.Post("Clustering takes " + clk.Elapsed() + " seconds.");

        yield return(new WaitForEndOfFrame());

        // Find strategic locations in each region
        List <MapRegion> zones = map.GetZones(zoneNum);

        SpliceTerritory(zones);

        yield return(new WaitForEndOfFrame());

        SetColliders();

        yield return(new WaitForEndOfFrame());

        PlacementGenerator placement = GetComponent <PlacementGenerator> ();

        if (placement && decorateTerrain)
        {
            placement.GenerateTrees(islands);
            placement.GenerateSectorsContent(sectors, vertDatabase);
        }
        else if (placement)
        {
            //placement.GeneratePlacements (islands);
            placement.GenerateSectorsContent(sectors, vertDatabase);
        }

        yield return(new WaitForEndOfFrame());

        if (flatShading)
        {
            foreach (IsleInfo island in islands)
            {
                for (int surfaceIndex = 0; surfaceIndex < 3; surfaceIndex++)
                {
                    MeshFilter mf           = island.GetSurfaceMesh(surfaceIndex);
                    float      oldVertCount = mf.sharedMesh.vertexCount;
                    mf.sharedMesh = FlatShade.DuplicateSharedVertex(mf.sharedMesh);
                    float newVertCount = mf.sharedMesh.vertexCount;
                    //Debug.Log (mf.transform.parent.name + "." + mf.transform.name + " new vertices are at " + (newVertCount / oldVertCount * 100) + "% with " + newVertCount + " verts.");
                }
            }
        }

        Random.state = oldState;

        finished = true;
        yield return(null);
    }