Пример #1
0
        /// <summary>
        /// Check if cell is valid to spawn a new cave plant.
        /// </summary>
        private static bool IsCellValidToSPawnANewCavePlant(IntVec3 cell)
        {
            bool cellIsValid = false;

            cellIsValid = Find.RoofGrid.Roofed(cell) &&
                          ((Find.ThingGrid.ThingsListAt(cell).Count == 0) ||
                           ((Find.ThingGrid.ThingAt(cell, ThingDef.Named("RockRubble")) != null) &&
                            (Find.ThingGrid.ThingAt(cell, ThingCategory.Plant) == null))) &&
                          CavePlant.IsLightConditionOk(cell) &&
                          CavePlant.IsNearNaturalRockBlock(cell) &&
                          CavePlant.IsTerrainConditionOk(cell) &&
                          CavePlant.IsTemperatureConditionOk(cell);

            return(cellIsValid);
        }
Пример #2
0
        /// <summary>
        /// Tries to spawn a new cluster at a random position on the map. The exclusivity radius still applies.
        /// </summary>
        public bool TrySpawnNewClusterAtRandomPosition()
        {
            ThingDef cavePlantDef   = GetRandomCavePlantDef();
            int      newClusterSize = Rand.RangeInclusive(cavePlantDef.plant.wildClusterSizeRange.min, cavePlantDef.plant.wildClusterSizeRange.max);
            float    newClusterExclusivityRadius = CavePlant.GetClusterExclusivityRadius(cavePlantDef, newClusterSize);
            int      checkedCellsNumber          = 0;

            for (checkedCellsNumber = 0; checkedCellsNumber < 1000; checkedCellsNumber++)
            {
                IntVec3 newClusterCell = new IntVec3(Rand.Range(0, Find.Map.Size.x), 0, Rand.Range(0, Find.Map.Size.z));
                if (Find.RoofGrid.Roofed(newClusterCell) &&
                    ((Find.ThingGrid.ThingsListAt(newClusterCell).Count == 0) ||
                     ((Find.ThingGrid.ThingAt(newClusterCell, ThingDef.Named("RockRubble")) != null) &&
                      (Find.ThingGrid.ThingAt(newClusterCell, ThingCategory.Plant) == null))) &&
                    CavePlant.IsLightConditionOk(newClusterCell) &&
                    CavePlant.IsNearNaturalRockBlock(newClusterCell) &&
                    CavePlant.IsTerrainConditionOk(newClusterCell) &&
                    CavePlant.IsTemperatureConditionOk(newClusterCell))
                {
                    float cavePlantSearchRadius = CavePlant.GetMaxClusterExclusivityRadius(cavePlantDef) * 2f;
                    IEnumerable <IntVec3> cellsAroundNewCluster = GenRadial.RadialCellsAround(newClusterCell, cavePlantSearchRadius, false);
                    bool anotherClusterIsTooClose = false;
                    foreach (IntVec3 cell in cellsAroundNewCluster)
                    {
                        Thing potentialDistantCavePlant = Find.ThingGrid.ThingAt(cell, cavePlantDef);
                        if (potentialDistantCavePlant != null)
                        {
                            CavePlant distantCavePlant = potentialDistantCavePlant as CavePlant;
                            if (distantCavePlant.Position.InHorDistOf(cell, newClusterExclusivityRadius + distantCavePlant.GetClusterExclusivityRadius()))
                            {
                                anotherClusterIsTooClose = true;
                                break;
                            }
                        }
                    }
                    if (anotherClusterIsTooClose == false)
                    {
                        GenSpawn.Spawn(cavePlantDef, newClusterCell);
                        return(true);
                    }
                }
            }
            return(false);
        }