/// <summary> /// Try to spawn another plant in this cluster. /// </summary> 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, cluster.Map); newPlant.cluster = cluster; cluster.NotifyPlantAdded(); if (cluster.plantDef.isSymbiosisPlant) { // Destroy source symbiosis plant. Thing sourceSymbiosisPlant = spawnCell.GetFirstThing(cluster.Map, cluster.plantDef.symbiosisPlantDefSource); if (sourceSymbiosisPlant != null) { sourceSymbiosisPlant.Destroy(); } } return(newPlant); } else { return(null); } }
/// <summary> /// Try to spawn another cave plant in the cluster or to spawn a new cluster. /// </summary> public static ClusterPlant TryToReproduce(ClusterPlant plant) { if (plant.cluster == null) { Log.Warning("CaveworldFlora:TryToReproduce: cluster is null at " + plant.Position); } // Test if it is growing on a fungiponics basin. if (plant.isOnCavePlantGrower) { return(null); } if (plant.cluster.actualSize < plant.cluster.desiredSize) { // Cluster is not mature, grow the cluster. return(TryGrowCluster(plant.cluster)); } else { // Cluster is mature: try to spawn a new cluster and/or a symbiosis cluster. if (plant.clusterPlantProps.isSymbiosisPlant == false) { return(TrySpawnNewClusterAwayFrom(plant.cluster)); } if (plant.clusterPlantProps.symbiosisPlantDefEvolution != null) { TryToSpawnNewSymbiosisCluster(plant.cluster); } } return(null); }
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); } }
public static void GrowCluster(ClusterPlant plant, bool clusterIsMature) { Cluster cluster = plant.cluster; int seedPlantsNumber = 0; if (clusterIsMature) { seedPlantsNumber = cluster.desiredSize - 1; // The first plant is already spawned. } else { seedPlantsNumber = (int)((float)cluster.desiredSize * Rand.Range(0.25f, 0.75f)); } if (seedPlantsNumber == 0) { return; } for (int seedPlantIndex = 0; seedPlantIndex < seedPlantsNumber; seedPlantIndex++) { ClusterPlant seedPlant = GenClusterPlantReproduction.TryToReproduce(plant); if (seedPlant != null) { seedPlant.Growth = Rand.Range(plantMinGrowth, plantMaxGrowth); } } if (clusterIsMature && cluster.plantDef.symbiosisPlantDefEvolution != null) { ClusterPlant symbiosisPlant = GenClusterPlantReproduction.TryToSpawnNewSymbiosisCluster(cluster); if (symbiosisPlant != null) { symbiosisPlant.Growth = Rand.Range(plantMinGrowth, plantMaxGrowth); GrowCluster(symbiosisPlant, clusterIsMature); } } }
/// <summary> /// Try to spawn another cave plant in the cluster or to spawn a new cluster. /// </summary> public static ClusterPlant TryToReproduce(ClusterPlant plant) { // Test if it is growing on a fungiponics basin. if (plant.isOnCavePlantGrower) { return null; } if (plant.cluster.actualSize < plant.cluster.desiredSize) { // Cluster is not mature, grow the cluster. return TryGrowCluster(plant.cluster); } else { // Cluster is mature: try to spawn a new cluster and/or a symbiosis cluster. if (plant.clusterPlantProps.isSymbiosisPlant == false) { return TrySpawnNewClusterAwayFrom(plant.cluster); } if (plant.clusterPlantProps.symbiosisPlantDefEvolution != null) { TryToSpawnNewSymbiosisCluster(plant.cluster); } } return null; }
// New cluster initialization. public static ClusterPlant SpawnNewClusterAt(Map map, IntVec3 spawnCell, ThingDef_ClusterPlant plantDef, int desiredSize) { ClusterPlant newPlant = ThingMaker.MakeThing(plantDef) as ClusterPlant; GenSpawn.Spawn(newPlant, spawnCell, map); Cluster newCluster = ThingMaker.MakeThing(Util_CaveworldFlora.ClusterDef) as Cluster; newCluster.Initialize(plantDef, desiredSize); GenSpawn.Spawn(newCluster, spawnCell, map); newPlant.cluster = newCluster; return(newPlant); }
/// <summary> /// Check if a new fungiponics basin can be built at this location. /// - the fungiponics basin must be roofed. /// - must not be too near from another fungiponics basin. /// </summary> public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot) { foreach (IntVec3 cell in GenAdj.CellsOccupiedBy(loc, rot, checkingDef.Size)) { if (ClusterPlant.IsNaturalRoughRockAt(cell) == false) { return(new AcceptanceReport("Fungiponics basin must be built on rough rock.")); } if (Find.RoofGrid.Roofed(loc) == false) { return(new AcceptanceReport("Fungiponics basin must be roofed.")); } } List <Thing> fungiponicsBasinsList = new List <Thing>(); IEnumerable <Thing> list = Find.ListerThings.ThingsOfDef(ThingDef.Named("FungiponicsBasin")); foreach (Thing basin in list) { fungiponicsBasinsList.Add(basin); } list = Find.ListerThings.ThingsOfDef(ThingDef.Named("FungiponicsBasin").blueprintDef); foreach (Thing basin in list) { fungiponicsBasinsList.Add(basin); } list = Find.ListerThings.ThingsOfDef(ThingDef.Named("FungiponicsBasin").frameDef); foreach (Thing basin in list) { fungiponicsBasinsList.Add(basin); } foreach (Thing basin in fungiponicsBasinsList) { if (basin.Position.InHorDistOf(loc, minDistanceBetweenFungiponicsBasins)) { return(new AcceptanceReport("An other fungiponics basin is too close.")); } } return(true); }
/// <summary> /// Check if a new fungiponics basin can be built at this location. /// - the fungiponics basin must be roofed. /// - must not be too near from another fungiponics basin. /// </summary> public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Thing thingToIgnore = null) { foreach (IntVec3 cell in GenAdj.CellsOccupiedBy(loc, rot, checkingDef.Size)) { if (ClusterPlant.IsNaturalRoughRockAt(base.Map, cell) == false) { return(new AcceptanceReport("CaveworldFlora.MustOnRoughRock".Translate())); } if (base.Map.roofGrid.Roofed(loc) == false) { return(new AcceptanceReport("CaveworldFlora.MustBeRoofed".Translate())); } } List <Thing> fungiponicsBasinsList = new List <Thing>(); IEnumerable <Thing> list = base.Map.listerThings.ThingsOfDef(ThingDef.Named("FungiponicsBasin")); foreach (Thing basin in list) { fungiponicsBasinsList.Add(basin); } list = base.Map.listerThings.ThingsOfDef(ThingDef.Named("FungiponicsBasin").blueprintDef); foreach (Thing basin in list) { fungiponicsBasinsList.Add(basin); } list = base.Map.listerThings.ThingsOfDef(ThingDef.Named("FungiponicsBasin").frameDef); foreach (Thing basin in list) { fungiponicsBasinsList.Add(basin); } foreach (Thing basin in fungiponicsBasinsList) { if (basin.Position.InHorDistOf(loc, minDistanceBetweenFungiponicsBasins)) { return(new AcceptanceReport("CaveworldFlora.TooClose".Translate())); } } return(true); }
public static ClusterPlant TryToSpawnNewSymbiosisCluster(Cluster cluster) { // Check there is not already a symbiosis cluster. if (cluster.symbiosisCluster == null) { foreach (IntVec3 cell in GenRadial.RadialCellsAround(cluster.Position, cluster.plantDef.clusterSpawnRadius, false).InRandomOrder()) { if (cell.InBounds() == false) { continue; } ClusterPlant plant = cell.GetFirstThing(cluster.plantDef) as ClusterPlant; if (plant != null) { plant.Destroy(); ClusterPlant symbiosisPlant = Cluster.SpawnNewClusterAt(cell, cluster.plantDef.symbiosisPlantDefEvolution, cluster.plantDef.symbiosisPlantDefEvolution.clusterSizeRange.RandomInRange); cluster.NotifySymbiosisClusterAdded(symbiosisPlant.cluster); return(symbiosisPlant); } } } return(null); }
/// <summary> /// Check if position is valid to grow a plant. Does not check cluster exclusivity! /// </summary> public static bool IsValidPositionToGrowPlant(ThingDef_ClusterPlant plantDef, Map map, IntVec3 position, bool checkTemperature = true) { if (position.InBounds(map) == false) { return(false); } if (plantDef.isSymbiosisPlant) { // For symbiosis plant, only check there is a source symbiosis plant. if (position.GetFirstThing(map, plantDef.symbiosisPlantDefSource) != null) { return(true); } else { return(false); } } // Check there is no building or cover. if ((position.GetEdifice(map) != null) || (position.GetCover(map) != null)) { return(false); } // Check terrain condition. if (ClusterPlant.CanTerrainSupportPlantAt(plantDef, map, position) == false) { return(false); } // Check temperature conditions. if (ClusterPlant.IsTemperatureConditionOkAt(plantDef, map, position) == false) { return(false); } // Check light conditions. if (ClusterPlant.IsLightConditionOkAt(plantDef, map, position) == false) { return(false); } // Check there is no other plant. if (map.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 = map.thingGrid.ThingsListAt(position); for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++) { Thing thing = thingList[thingIndex]; 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, map) == false) { return(false); } return(true); }