CaveworldFlora.GenClusterPlantReproduction.TryGrowCluster C# (CSharp) Method

TryGrowCluster() public static method

Try to spawn another plant in this cluster.
public static TryGrowCluster ( Cluster cluster ) : ClusterPlant
cluster Cluster
return ClusterPlant
        public static ClusterPlant TryGrowCluster(Cluster cluster)
        {
            IntVec3 spawnCell = IntVec3.Invalid;
            TryGetRandomSpawnCellNearCluster(cluster, out spawnCell);
            if (spawnCell.IsValid)
            {
                ClusterPlant newPlant = ThingMaker.MakeThing(cluster.plantDef) as ClusterPlant;
                GenSpawn.Spawn(newPlant, spawnCell);
                newPlant.cluster = cluster;
                cluster.NotifyPlantAdded();
                if (cluster.plantDef.isSymbiosisPlant)
                {
                    // Destroy source symbiosis plant.
                    Thing sourceSymbiosisPlant = spawnCell.GetFirstThing(cluster.plantDef.symbiosisPlantDefSource);
                    if (sourceSymbiosisPlant != null)
                    {
                        sourceSymbiosisPlant.Destroy();
                    }
                }
                return newPlant;
            }
            else
            {
                return null;
            }
        }

Usage Example

Beispiel #1
0
        public override void TickLong()
        {
            // Grow cluster and spawn symbiosis cluster.
            if ((Find.TickManager.TicksGame > this.nextGrownTick) &&
                ClusterPlant.IsTemperatureConditionOkAt(this.plantDef, this.Map, this.Position) &&
                ClusterPlant.IsLightConditionOkAt(this.plantDef, this.Map, this.Position))
            {
                this.nextGrownTick = Find.TickManager.TicksGame + (int)(this.plantDef.plant.reproduceMtbDays * GenDate.TicksPerDay);

                // Grow cluster.
                GenClusterPlantReproduction.TryGrowCluster(this);

                // Spawn symbiosis cluster.
                if ((this.actualSize == this.desiredSize) &&
                    (this.plantDef.symbiosisPlantDefEvolution != null))
                {
                    GenClusterPlantReproduction.TrySpawnNewSymbiosisCluster(this);
                }
            }

            // Spawn new cluster.
            if ((this.actualSize == this.desiredSize) &&
                (Find.TickManager.TicksGame > this.nextReproductionTick) &&
                ClusterPlant.IsTemperatureConditionOkAt(this.plantDef, this.Map, this.Position) &&
                ClusterPlant.IsLightConditionOkAt(this.plantDef, this.Map, this.Position))
            {
                GenClusterPlantReproduction.TrySpawnNewClusterAwayFrom(this);
                this.nextReproductionTick = Find.TickManager.TicksGame + (int)(this.plantDef.plant.reproduceMtbDays * 10f * GenDate.TicksPerDay);
            }
        }