GenClusterPlantReproduction class.
Exemple #1
0
        /// <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, Map map, out IntVec3 spawnCell)
        {
            spawnCell = IntVec3.Invalid;

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

            bool validCellIsFound = CellFinderLoose.TryGetRandomCellWith(validator, map, 1000, out spawnCell);

            if (validCellIsFound == false)
            {
                // Just for robustness, TryGetRandomCellWith set result to IntVec3.Invalid if no valid cell is found.
                spawnCell = IntVec3.Invalid;
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Tries to spawn a new cluster at a random position on the map. The exclusivity radius still applies.
        /// </summary>
        public void TrySpawnNewClusterAtRandomPosition()
        {
            ThingDef_ClusterPlant cavePlantDef = cavePlantDefs.RandomElementByWeight((ThingDef_ClusterPlant plantDef) => plantDef.plant.wildCommonalityMaxFraction / plantDef.clusterSizeRange.Average);

            int     newDesiredClusterSize = cavePlantDef.clusterSizeRange.RandomInRange;
            IntVec3 spawnCell             = IntVec3.Invalid;

            GenClusterPlantReproduction.TryGetRandomClusterSpawnCell(cavePlantDef, newDesiredClusterSize, true, this.map, out spawnCell);
            if (spawnCell.IsValid)
            {
                Cluster.SpawnNewClusterAt(this.map, spawnCell, cavePlantDef, newDesiredClusterSize);
            }
        }
Exemple #4
0
        /// <summary>
        /// Tries to spawn a new cluster at a random position on the map. The exclusivity radius still applies.
        /// </summary>
        public void TrySpawnNewClusterAtRandomPosition()
        {
            //Log.Message("TrySpawnNewClusterAtRandomPosition");
            for (int defindex = 0; defindex < cavePlantDefs.Count; defindex++)
            {
                //Log.Message("cavePlantDefs: " + cavePlantDefs[defindex].ToString());
            }
            ThingDef_ClusterPlant cavePlantDef = cavePlantDefs.RandomElementByWeight((ThingDef_ClusterPlant plantDef) => plantDef.plant.wildCommonalityMaxFraction / plantDef.clusterSizeRange.Average);
            //Log.Message("selected cavePlantDef = " + cavePlantDef.ToString());

            int     newDesiredClusterSize = cavePlantDef.clusterSizeRange.RandomInRange;
            IntVec3 spawnCell             = IntVec3.Invalid;

            GenClusterPlantReproduction.TryGetRandomClusterSpawnCell(cavePlantDef, newDesiredClusterSize, true, out spawnCell);
            if (spawnCell.IsValid)
            {
                Cluster.SpawnNewClusterAt(spawnCell, cavePlantDef, newDesiredClusterSize);
            }
        }
Exemple #5
0
        // ===================== Main Work Function =====================
        /// <summary>
        /// Main function:
        /// - update the glower if necessary.
        /// - verify the cave plant is in good conditions to growth.
        /// - when the cave plant is too old, damage it over time.
        /// - when the cave plant is mature, try to reproduce.
        /// </summary>
        public override void TickLong()
        {
            if (this.isGrowingNow)
            {
                bool plantWasAlreadyMature = (this.LifeStage == PlantLifeStage.Mature);
                this.growthInt += this.GrowthPerTick * GenTicks.TickLongInterval;
                if (!plantWasAlreadyMature &&
                    (this.LifeStage == PlantLifeStage.Mature))
                {
                    // Plant just became mature.
                    this.Map.mapDrawer.MapMeshDirty(this.Position, MapMeshFlag.Things);
                }
            }

            // Verify the plant is not in cryostasis.
            if (this.isInCryostasis == false)
            {
                if (this.LifeStage == PlantLifeStage.Mature)
                {
                    this.ageInt += GenTicks.TickLongInterval;
                }
                if (this.Dying)
                {
                    int amount = Mathf.CeilToInt(1.25f);
                    base.TakeDamage(new DamageInfo(DamageDefOf.Rotting, amount, -1, null, null, null));
                }
                if (!base.Destroyed &&
                    (this.growthInt > minGrowthToReproduce) &&
                    !this.Dying &&
                    Rand.MTBEventOccurs(this.def.plant.reproduceMtbDays, GenDate.TicksPerDay, GenTicks.TickLongInterval))
                {
                    GenClusterPlantReproduction.TryToReproduce(this);
                }
            }

            // Update glower.
            if (!base.Destroyed)
            {
                UpdateGlowerAccordingToGrowth();
            }

            this.cachedLabelMouseover = null;
        }
Exemple #6
0
        // ===================== Main Work Function =====================
        /// <summary>
        /// Main function:
        /// - update the glower if necessary.
        /// - verify the cave plant is in good conditions to growth.
        /// - when the cave plant is too old, damage it over time.
        /// - when the cave plant is mature, try to reproduce.
        /// </summary>
        public override void TickLong()
        {
            /*Log.Message("TickLong");
             * Log.Message("isGrowingNow = " + this.isGrowingNow);
             * Log.Message("isInCryostasis = " + this.isInCryostasis);*/
            if (this.isGrowingNow)
            {
                bool plantWasAlreadyMature = (this.LifeStage == PlantLifeStage.Mature);

                /*Log.Message("plantWasAlreadyMature = " + plantWasAlreadyMature);
                 * Log.Message("growthInt before = " + this.growthInt);
                 * Log.Message("GrowthPerTick = " + this.GrowthPerTick);*/
                this.growthInt += this.GrowthPerTick * GenTicks.TickLongInterval;
                if (DebugSettings.fastEcology)
                {
                    // TODO: fastEcology debug.
                    this.growthInt += 0.1f;
                }
                if (!plantWasAlreadyMature &&
                    (this.LifeStage == PlantLifeStage.Mature))
                {
                    // Plant just became mature.
                    Find.MapDrawer.MapMeshDirty(this.Position, MapMeshFlag.Things);
                }
            }

            // Verify the plant is not in cryostasis.
            if (this.isInCryostasis == false)
            {
                if (this.LifeStage == PlantLifeStage.Mature)
                {
                    this.ageInt += GenTicks.TickLongInterval;
                }
                if (this.Dying)
                {
                    int amount = Mathf.CeilToInt(1.25f);
                    base.TakeDamage(new DamageInfo(DamageDefOf.Rotting, amount, null, null, null));
                }
                if (!base.Destroyed &&
                    (this.growthInt > minGrowthToReproduce) &&
                    Rand.MTBEventOccurs(this.def.plant.seedEmitMTBDays, GenDate.TicksPerDay, GenTicks.TickLongInterval))
                {
                    GenClusterPlantReproduction.TryToReproduce(this);
                }

                if (DebugSettings.fastEcology &&
                    !base.Destroyed &&
                    (this.growthInt > minGrowthToReproduce))
                {
                    // TODO: fastEcology debug.
                    GenClusterPlantReproduction.TryToReproduce(this);
                }
            }

            // Update glower.
            if (!base.Destroyed)
            {
                UpdateGlowerAccordingToGrowth();
            }

            this.cachedLabelMouseover = null;
        }