public override void Generate(Map map) { map.regionAndRoomUpdater.Enabled = false; List <ThingDef> list = map.Biome.AllWildPlants.ToList(); for (int i = 0; i < list.Count; i++) { GenStep_Plants.numExtant.Add(list[i], 0); } GenStep_Plants.desiredProportions = GenPlant.CalculateDesiredPlantProportions(map.Biome); MapGenFloatGrid caves = MapGenerator.Caves; float num = map.Biome.plantDensity * map.gameConditionManager.AggregatePlantDensityFactor(); foreach (IntVec3 item in map.AllCells.InRandomOrder(null)) { if (item.GetEdifice(map) == null && item.GetCover(map) == null && !(caves[item] > 0.0)) { float num2 = map.fertilityGrid.FertilityAt(item); float num3 = num2 * num; if (!(Rand.Value >= num3)) { IEnumerable <ThingDef> source = from def in list where def.CanEverPlantAt(item, map) select def; if (source.Any()) { ThingDef thingDef = source.RandomElementByWeight((ThingDef x) => GenStep_Plants.PlantChoiceWeight(x, map)); int randomInRange = thingDef.plant.wildClusterSizeRange.RandomInRange; for (int j = 0; j < randomInRange; j++) { IntVec3 loc = default(IntVec3); if (j == 0) { loc = item; } else if (!GenPlantReproduction.TryFindReproductionDestination(item, thingDef, SeedTargFindMode.MapGenCluster, map, out loc)) { 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, loc, map); GenStep_Plants.RecordAdded(thingDef); } } } } } GenStep_Plants.numExtant.Clear(); GenStep_Plants.desiredProportions.Clear(); GenStep_Plants.totalExtant = 0; map.regionAndRoomUpdater.Enabled = true; }
public static void LogPlantProportions() { Dictionary <ThingDef, float> dictionary = new Dictionary <ThingDef, float>(); foreach (ThingDef key in Find.CurrentMap.Biome.AllWildPlants) { dictionary.Add(key, 0f); } float num = 0f; foreach (IntVec3 c in Find.CurrentMap.AllCells) { Plant plant = c.GetPlant(Find.CurrentMap); if (plant != null && dictionary.ContainsKey(plant.def)) { Dictionary <ThingDef, float> dictionary2; ThingDef def; (dictionary2 = dictionary)[def = plant.def] = dictionary2[def] + 1f; num += 1f; } } foreach (ThingDef thingDef in Find.CurrentMap.Biome.AllWildPlants) { Dictionary <ThingDef, float> dictionary2; ThingDef key2; (dictionary2 = dictionary)[key2 = thingDef] = dictionary2[key2] / num; } Dictionary <ThingDef, float> dictionary3 = GenPlant.CalculateDesiredPlantProportions(Find.CurrentMap.Biome); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("PLANT EXPECTED FOUND"); foreach (ThingDef thingDef2 in Find.CurrentMap.Biome.AllWildPlants) { stringBuilder.AppendLine(string.Concat(new string[] { thingDef2.LabelCap, " ", dictionary3[thingDef2].ToStringPercent(), " ", dictionary[thingDef2].ToStringPercent() })); } Log.Message(stringBuilder.ToString(), false); }
public static void LogPlantProportions() { Dictionary <ThingDef, float> dictionary = new Dictionary <ThingDef, float>(); foreach (ThingDef allWildPlant in Find.VisibleMap.Biome.AllWildPlants) { dictionary.Add(allWildPlant, 0f); } float num = 0f; foreach (IntVec3 allCell in Find.VisibleMap.AllCells) { Plant plant = allCell.GetPlant(Find.VisibleMap); if (plant != null && dictionary.ContainsKey(plant.def)) { Dictionary <ThingDef, float> dictionary2; ThingDef def; (dictionary2 = dictionary)[def = plant.def] = (float)(dictionary2[def] + 1.0); num = (float)(num + 1.0); } } foreach (ThingDef allWildPlant2 in Find.VisibleMap.Biome.AllWildPlants) { Dictionary <ThingDef, float> dictionary2; ThingDef key; (dictionary2 = dictionary)[key = allWildPlant2] = dictionary2[key] / num; } Dictionary <ThingDef, float> dictionary3 = GenPlant.CalculateDesiredPlantProportions(Find.VisibleMap.Biome); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("PLANT EXPECTED FOUND"); foreach (ThingDef allWildPlant3 in Find.VisibleMap.Biome.AllWildPlants) { stringBuilder.AppendLine(allWildPlant3.LabelCap + " " + dictionary3[allWildPlant3].ToStringPercent() + " " + dictionary[allWildPlant3].ToStringPercent()); } Log.Message(stringBuilder.ToString()); }