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;
        }
Пример #2
0
        public static Plant TryReproduceFrom(IntVec3 source, ThingDef plantDef, SeedTargFindMode mode, Map map)
        {
            IntVec3 dest;

            if (!GenPlantReproduction.TryFindReproductionDestination(source, plantDef, mode, map, out dest))
            {
                return(null);
            }
            return(GenPlantReproduction.TryReproduceInto(dest, plantDef, map));
        }
Пример #3
0
        public override void Generate(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 && c.Roofed(map) && map.fertilityGrid.FertilityAt(c) > 0f)
                {
                    if (Rand.Chance(0.18f))
                    {
                        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;
                            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;
        }