ThingDef_ClusterPlant class.
Inheritance: ThingDef
        /// <summary>
        /// Try to get a valid cell to spawn a new cluster anywhere on the map.
        /// </summary>
        public static void TryGetRandomClusterSpawnCell(ThingDef_ClusterPlant plantDef, int newDesiredClusterSize, bool checkTemperature, out IntVec3 spawnCell)
        {
            spawnCell = IntVec3.Invalid;

            Predicate<IntVec3> validator = delegate(IntVec3 cell)
            {
                // Check a plant can be spawned here.
                if (GenClusterPlantReproduction.IsValidPositionToGrowPlant(plantDef, cell) == false)
                {
                    return false;
                }
                // Check there is no third cluster nearby.
                if (GenClusterPlantReproduction.IsClusterAreaClear(plantDef, newDesiredClusterSize, cell) == false)
                {
                    return false;
                }
                return true;
            };

            bool validCellIsFound = CellFinderLoose.TryGetRandomCellWith(validator, 1000, out spawnCell);
            if (validCellIsFound == false)
            {
                // Just for robustness, TryGetRandomCellWith set result to IntVec3.Invalid if no valid cell is found.
                spawnCell = IntVec3.Invalid;
            }
        }
Beispiel #2
0
 // New cluster initialization.
 public static ClusterPlant SpawnNewClusterAt(IntVec3 spawnCell, ThingDef_ClusterPlant plantDef, int desiredSize)
 {
     ClusterPlant newPlant = ThingMaker.MakeThing(plantDef) as ClusterPlant;
     GenSpawn.Spawn(newPlant, spawnCell);
     Cluster newCluster = ThingMaker.MakeThing(Util_CaveworldFlora.ClusterDef) as Cluster;
     newCluster.Initialize(plantDef, desiredSize);
     GenSpawn.Spawn(newCluster, spawnCell);
     newPlant.cluster = newCluster;
     return newPlant;
 }
        public static bool CanTerrainSupportPlantAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
        {
            bool isValidSpot = true;

            if (plantDef.growOnlyOnRoughRock)
            {
                isValidSpot &= IsNaturalRoughRockAt(position);
            }
            else
            {
                isValidSpot &= IsFertilityConditionOkAt(plantDef, position);
            }
            if (plantDef.growOnlyUndeRoof)
            {
                isValidSpot &= Find.RoofGrid.Roofed(position);
            }
            if (plantDef.growOnlyNearNaturalRock)
            {
                isValidSpot &= IsNearNaturalRockBlock(position);
            }
            return isValidSpot;
        }
 public static bool IsTemperatureConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
 {
     float temperature = position.GetTemperature();
     return ((temperature >= plantDef.minGrowTemperature)
         && (temperature <= plantDef.maxGrowTemperature));
 }
 public static bool IsLightConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
 {
     float light = Find.GlowGrid.GameGlowAt(position);
     if ((light >= plantDef.minLight)
         && (light <= plantDef.maxLight))
     {
         return true;
     }
     return false;
 }
 // ===================== Static exported functions =====================
 public static bool IsFertilityConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
 {
     float fertility = Find.FertilityGrid.FertilityAt(position);
     return ((fertility >= plantDef.minFertility)
         && (fertility <= plantDef.maxFertility));
 }
        /// <summary>
        /// Check if position is valid to grow a plant. Does not check cluster exclusivity!
        /// </summary>
        public static bool IsValidPositionToGrowPlant(ThingDef_ClusterPlant plantDef, IntVec3 position, bool checkTemperature = true)
        {
            if (position.InBounds() == false)
            {
                return false;
            }
            if (plantDef.isSymbiosisPlant)
            {
                // For symbiosis plant, only check there is a source symbiosis plant.
                if (position.GetFirstThing(plantDef.symbiosisPlantDefSource) != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            // Check there is no building or cover.
            if ((position.GetEdifice() != null)
                || (position.GetCover() != null))
            {
                return false;
            }
            // Check terrain condition.
            if (ClusterPlant.CanTerrainSupportPlantAt(plantDef, position) == false)
            {
                return false;
            }
            // Check temperature conditions.
            if (ClusterPlant.IsTemperatureConditionOkAt(plantDef, position) == false)
            {
                return false;
            }
            // Check light conditions.
            if (ClusterPlant.IsLightConditionOkAt(plantDef, position) == false)
            {
                return false;
            }
            // Check there is no other plant.
            if (Find.ThingGrid.ThingAt(position, ThingCategory.Plant) != null)
            {
                return false;
            }
            // Check the cell is not blocked by a plant, an item, a pawn, a rock...
	        List<Thing> thingList = Find.ThingGrid.ThingsListAt(position);
	        for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
	        {
                Thing thing = thingList[thingIndex];
                //Log.Message("checking thing + " + thing.ToString() + " at " + position.ToString());
		        if (thing.def.BlockPlanting)
		        {
			        return false;
		        }
		        if (plantDef.passability == Traversability.Impassable
                    && (thing.def.category == ThingCategory.Pawn
                        || thing.def.category == ThingCategory.Item
                        || thing.def.category == ThingCategory.Building
                        || thing.def.category == ThingCategory.Plant))
		        {
			        return false;
		        }
	        }
            // Check snow level.
            if (GenPlant.SnowAllowsPlanting(position) == false)
            {
                return false;
            }
            return true;
        }
 /// <summary>
 /// Check if there is another cluster too close.
 /// </summary>
 public static bool IsClusterAreaClear(ThingDef_ClusterPlant plantDef, int newDesiredClusterSize, IntVec3 position)
 {
     float newClusterExclusivityRadius = Cluster.GetExclusivityRadius(plantDef, newDesiredClusterSize);
     foreach (Thing thing in Find.ListerThings.ThingsOfDef(Util_CaveworldFlora.ClusterDef))
     {
         Cluster cluster = thing as Cluster;
         if (cluster.plantDef != plantDef)
         {
             continue;
         }
         if (cluster.Position.InHorDistOf(position, cluster.exclusivityRadius + newClusterExclusivityRadius))
         {
             return false;
         }
     }
     return true;
 }
Beispiel #9
0
        public override void ExposeData()
        {
            base.ExposeData();
            string plantDefAsString = "";
            if (Scribe.mode == LoadSaveMode.Saving)
            {
                plantDefAsString = this.plantDef.defName;
                Scribe_Values.LookValue<string>(ref plantDefAsString, "plantDefAsString");
            }
            else if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                Scribe_Values.LookValue<string>(ref plantDefAsString, "plantDefAsString");
                this.plantDef = ThingDef.Named(plantDefAsString) as ThingDef_ClusterPlant;
            }
            Scribe_Values.LookValue<int>(ref this.actualSize, "actualSize");
            Scribe_Values.LookValue<int>(ref this.desiredSize, "desiredSize");

            Scribe_References.LookReference<Cluster>(ref this.symbiosisCluster, "symbiosisCluster");
        }
Beispiel #10
0
 public static float GetMaxExclusivityRadius(ThingDef_ClusterPlant plantDef)
 {
     return (plantDef.clusterExclusivityRadiusOffset + ((float)plantDef.clusterSizeRange.max) * plantDef.clusterExclusivityRadiusFactor);
 }
Beispiel #11
0
 public static float GetExclusivityRadius(ThingDef_ClusterPlant plantDef, int clusterSize)
 {
     return (plantDef.clusterExclusivityRadiusOffset + (float)clusterSize * plantDef.clusterExclusivityRadiusFactor);
 }
Beispiel #12
0
 public void Initialize(ThingDef_ClusterPlant plantDef, int desiredSize)
 {
     this.plantDef = plantDef;
     this.actualSize = 1;
     this.desiredSize = desiredSize;
 }