コード例 #1
0
        public void PaintVegetation(MapRegion region, IRegionBiomeTemplate template)
        {
            var treeType = template.AreTreesJungle ? CellVegetation.Jungle : CellVegetation.Forest;

            var openCells = new List <IHexCell>();

            foreach (var cell in region.LandCells)
            {
                if (ShouldBeMarsh(cell, template))
                {
                    ModLogic.ChangeVegetationOfCell(cell, CellVegetation.Marsh);
                }
                else if (ModLogic.CanChangeVegetationOfCell(cell, treeType))
                {
                    openCells.Add(cell);
                }
            }

            int treeCount = Mathf.RoundToInt(template.TreePercentage * openCells.Count * 0.01f);

            var treeSeeds = CellRandomSampler.SampleElementsFromSet(
                openCells, UnityEngine.Random.Range(template.MinTreeClumps, template.MaxTreeClumps),
                GetTreeSeedWeightFunction(treeType, template)
                );

            var treeCells = new List <IHexCell>();

            var treeCrawlers = treeSeeds.Select(
                seed => GridTraversalLogic.GetCrawlingEnumerator(
                    seed, openCells, treeCells, GetTreeCrawlingCostFunction(treeType, template)
                    )
                ).ToList();

            for (int i = 0; i < treeCount; i++)
            {
                if (treeCrawlers.Count == 0)
                {
                    Debug.LogWarning("Failed to paint correct number of trees into region");
                    break;
                }

                var crawler = treeCrawlers.Random();

                if (crawler.MoveNext())
                {
                    treeCells.Add(crawler.Current);
                    openCells.Remove(crawler.Current);
                }
                else
                {
                    treeCrawlers.Remove(crawler);
                    i--;
                }
            }

            foreach (var treeCell in treeCells)
            {
                ModLogic.ChangeVegetationOfCell(treeCell, treeType);
            }
        }
コード例 #2
0
 private bool IncreaseScoreFilter(IHexCell cell)
 {
     if (ModLogic.CanChangeVegetationOfCell(cell, CellVegetation.Jungle))
     {
         return(Grid.GetNeighbors(cell).Count(neighbor => neighbor.Vegetation == CellVegetation.Jungle) >= 3);
     }
     else
     {
         return(false);
     }
 }
コード例 #3
0
 protected override void EditCell(IHexCell cell)
 {
     if (IsPainting && CellModificationLogic.CanChangeVegetationOfCell(cell, ActiveVegetation))
     {
         CellModificationLogic.ChangeVegetationOfCell(cell, ActiveVegetation);
     }
 }