예제 #1
0
 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);
        }