public override void MapComponentTick() { if (speciality == null) { return; } IntVec3 place; if (speciality.AnimalSpeciality != null && Find.TickManager.TicksGame % 1210 == 0 && Rand.Value < 0.0268888883f * map.wildSpawner.DesiredAnimalDensity(map) * (1 + pawnExtraSpawn) && RCellFinder.TryFindRandomPawnEntryCell(out place, this.map, CellFinder.EdgeRoadChance_Animal, null)) { spawnAnimalsAt(place); } ThingDef plantDef = speciality.PlantSpeciality; if (plantDef != null) { float num = map.gameConditionManager.AggregatePlantDensityFactor(); if (num > 0.0001f) { int num2 = map.Size.x * 2 + map.Size.z * 2; float num3 = 650f / ((float)num2 / 100f); int num4 = (int)(num3 / num); if (num4 <= 0 || Find.TickManager.TicksGame % num4 == 0) { if (RCellFinder.TryFindRandomCellToPlantInFromOffMap(plantDef, map, out place)) { GenPlantReproduction.TryReproduceFrom(place, plantDef, SeedTargFindMode.MapEdge, map); } } } } }
private void spawnPlant(IntVec3 place, MapGenFloatGrid caves, float desiredTotalDensity, ThingDef plantDef) { if (place.GetEdifice(map) == null && place.GetCover(map) == null && caves[place] <= 0f) { float num2 = map.fertilityGrid.FertilityAt(place); float num3 = num2 * desiredTotalDensity; if (Rand.Value < num3) { for (int j = 0; j < plantDef.plant.wildClusterSizeRange.RandomInRange; j++) { IntVec3 c2; if (j == 0) { c2 = place; } else if (!GenPlantReproduction.TryFindReproductionDestination(place, plantDef, SeedTargFindMode.MapGenCluster, map, out c2)) { break; } Plant plant = (Plant)ThingMaker.MakeThing(plantDef, null); plant.Growth = Rand.Range(0.07f, 1f); if (plant.def.plant.LimitedLifespan) { plant.Age = Rand.Range(0, Mathf.Max(plant.def.plant.LifespanTicks - 50, 0)); } GenSpawn.Spawn(plant, c2, map); } } } }
public static bool GenerateCavePlant_PreFix(Map map) { map.regionAndRoomUpdater.Enabled = false; MapGenFloatGrid caves = MapGenerator.Caves; List <ThingDef> source = (from x in DefDatabase <ThingDef> .AllDefsListForReading where x.category == ThingCategory.Plant && x.plant.cavePlant select x).ToList <ThingDef>(); foreach (IntVec3 c in map.AllCells.InRandomOrder(null)) { if (c.GetEdifice(map) == null && c.GetCover(map) == null && (caves[c] > 0f || map.Biome.defName == "RWBCavern") && c.Roofed(map) && map.fertilityGrid.FertilityAt(c) > 0f) { IEnumerable <ThingDef> source2 = from def in source where def.CanEverPlantAt(c, map) select def; if (source2.Any <ThingDef>()) { ThingDef thingDef = source2.RandomElement <ThingDef>(); int randomInRange = thingDef.plant.wildClusterSizeRange.RandomInRange; float chance; if (Math.Abs(map.Biome.CommonalityOfPlant(thingDef)) > Double.Epsilon) { chance = map.Biome.CommonalityOfPlant(thingDef); } else { chance = 0.18f; } if (Rand.Chance(chance)) { for (int i = 0; i < randomInRange; i++) { IntVec3 c2; if (i == 0) { c2 = c; } else if (!GenPlantReproduction.TryFindReproductionDestination(c, thingDef, SeedTargFindMode.MapGenCluster, map, out c2)) { break; } Plant plant = (Plant)ThingMaker.MakeThing(thingDef, null); plant.Growth = Rand.Range(0.07f, 1f); if (plant.def.plant.LimitedLifespan) { plant.Age = Rand.Range(0, Mathf.Max(plant.def.plant.LifespanTicks - 50, 0)); } GenSpawn.Spawn(plant, c2, map); } } } } } map.regionAndRoomUpdater.Enabled = true; return(false); }
private static void WildSpawner_TrySpawnPlantFromMapEdge_PostFix(WildSpawner __instance) { //every 2 in game seconds at speed 1 if ((Find.TickManager.TicksGame % 120) == 0) { float SpawnedMaturity = 0.05f; int SpawnRate = 1; //are we in the caverns Map map = (Map)typeof(WildSpawner).GetField("map", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance); if (map.Biome.defName == "RWBCavern") { //at normal spawnrate of 1 ThingDef plantDef; if (SpawnRate == 1) { if (!map.Biome.AllWildPlants.TryRandomElementByWeight((ThingDef def) => map.Biome.CommonalityOfPlant(def), out plantDef)) { return; } // Checks wether the plantdef has a fertility value(Added for TiberiumRim users since Tiberium has 0% fertility) if (plantDef.plant == null || plantDef.plant.fertilityMin <= 0f) { Log.Message("[Biomes!] if you see this message, contact the modmakers because of a mod conflict"); return; } IntVec3 source; int FailSafe = 0; do { //loop that runs 5 times to look for a plantable tile source = CellFinder.RandomCell(map); if (FailSafe >= 4) { return; // Exit because no free spot found. } FailSafe++; }while (!plantDef.CanEverPlantAt(source, map)); //plants GenPlantReproduction.TryReproduceInto(source, plantDef, map); if (source.GetPlant(map).def == plantDef) { source.GetPlant(map).Growth = SpawnedMaturity; } } } } }
public override void TickLong() { this.CheckTemperatureMakeLeafless(); if (!GenPlant.GrowthSeasonNow(this.Position, Find.VisibleMap)) { return; } if (!this.HasEnoughLightToGrow) { this.unlitTicks += 2000; } else { this.unlitTicks = 0; } bool flag = this.LifeStage == PlantLifeStage.Mature; this.growth += this.GrowthPerTick * 2000f; if (!flag && this.LifeStage == PlantLifeStage.Mature) { this.NewlyMatured(); } if (this.def.plant.LimitedLifespan) { this.age += 2000; if (this.get_Rotting()) { int num = Mathf.CeilToInt(10f); this.TakeDamage(new DamageInfo(DamageDefOf.Rotting, num, (Thing)null, new BodyPartDamageInfo?(), (ThingDef)null)); } } if (this.Destroyed || !this.def.plant.shootsSeeds || ((double)this.growth < 0.600000023841858 || !Rand.MTBEventOccurs(this.def.plant.seedEmitMTBDays, 30000f, 2000f)) || (!GenPlant.SnowAllowsPlanting(this.Position) || GridsUtility.Roofed(this.Position))) { return; } GenPlantReproduction.TrySpawnSeed(this.Position, this.def, SeedTargFindMode.MapGenCluster, (Thing)this); }
public static void TryFindReproductionDestination_PostFix(IntVec3 source, ThingDef plantDef, SeedTargFindMode mode, Map map, ref IntVec3 foundCell, ref bool __result) { if (plantDef.plant.cavePlant) { float radius = -1f; if (mode == SeedTargFindMode.Reproduce) { radius = plantDef.plant.reproduceRadius; } else if (mode == SeedTargFindMode.MapGenCluster) { radius = plantDef.plant.WildClusterRadiusActual; } else if (mode == SeedTargFindMode.MapEdge) { radius = 40f; } else if (mode == SeedTargFindMode.Cave) { radius = plantDef.plant.WildClusterRadiusActual; } int num = 0; int num2 = 0; float num3 = 0f; CellRect cellRect = CellRect.CenteredOn(source, Mathf.RoundToInt(radius)); cellRect.ClipInsideMap(map); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { IntVec3 c2 = new IntVec3(j, 0, i); Plant plant = c2.GetPlant(map); if (plant != null && (mode != SeedTargFindMode.Cave || plant.def.plant.cavePlant)) { num++; if (plant.def == plantDef) { num2++; } } num3 += c2.GetTerrain(map).fertility; } } float num4 = (mode != SeedTargFindMode.Cave) ? map.Biome.plantDensity : 0.5f; float num5 = num3 * num4; bool flag = (float)num > num5; bool flag2 = (float)num > num5 * 1.25f; if (flag2 && map.Biome.defName != "RWBCavern") { foundCell = IntVec3.Invalid; return; } if (mode != SeedTargFindMode.MapGenCluster && mode != SeedTargFindMode.Cave) { BiomeDef curBiome = map.Biome; float num6 = curBiome.AllWildPlants.Sum((ThingDef pd) => curBiome.CommonalityOfPlant(pd)); float num7 = curBiome.CommonalityOfPlant(plantDef) / num6; float num8 = curBiome.CommonalityOfPlant(plantDef) * plantDef.plant.wildCommonalityMaxFraction / num6; float num9 = num5 * num8; if ((float)num2 > num9) { foundCell = IntVec3.Invalid; return; } float num10 = num5 * num7; bool flag3 = (float)num2 < num10 * 0.5f; if (flag && !flag3) { foundCell = IntVec3.Invalid; return; } } Predicate <IntVec3> validator = (IntVec3 c) => plantDef.CanEverPlantAt(c, map) && (!plantDef.plant.cavePlant || GenPlantReproduction.GoodRoofForCavePlantReproduction(c, map)) && GenPlant.SnowAllowsPlanting(c, map) && source.InHorDistOf(c, radius) && GenSight.LineOfSight(source, c, map, true, null, 0, 0); __result = CellFinder.TryFindRandomCellNear(source, map, Mathf.CeilToInt(radius), validator, out foundCell); return; } }
public override void TickLong() { CheckTemperatureMakeLeafless(); if (Destroyed) { return; } if (GrowthSeasonNow(Position, Map)) { if (!HasEnoughLightToGrow) { unlitTicks += 2000; } else { unlitTicks = 0; } float num = growthInt; bool flag = LifeStage == PlantLifeStage.Mature; growthInt += GrowthPerTick * 2000f; if (growthInt > 1f) { growthInt = 1f; } if (((!flag && LifeStage == PlantLifeStage.Mature) || (int)(num * 10f) != (int)(growthInt * 10f)) && CurrentlyCultivated()) { Map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Things); } if (def.plant.LimitedLifespan) { ageInt += 2000; if (Dying) { Map map = Map; bool isCrop = IsCrop; int amount = Mathf.CeilToInt(10f); TakeDamage(new DamageInfo(DamageDefOf.Rotting, amount, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown)); if (Destroyed) { if (isCrop && def.plant.Harvestable && MessagesRepeatAvoider.MessageShowAllowed("MessagePlantDiedOfRot-" + def.defName, 240f)) { Messages.Message("MessagePlantDiedOfRot".Translate(new object[] { Label }).CapitalizeFirst(), new TargetInfo(Position, map, false), MessageTypeDefOf.NegativeEvent); } return; } } } if (def.plant.reproduces && growthInt >= 0.6f && Rand.MTBEventOccurs(def.plant.reproduceMtbDays, 60000f, 2000f)) { if (!GenPlant.SnowAllowsPlanting(Position, Map)) { return; } GenPlantReproduction.TryReproduceFrom(Position, def, SeedTargFindMode.Reproduce, Map); } } hardyCachedLabelMouseover = null; }