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
        private void TrySpawnPlantFromMapEdge()
        {
            ThingDef plantDef = default(ThingDef);
            IntVec3  source   = default(IntVec3);

            if (this.map.Biome.AllWildPlants.TryRandomElementByWeight <ThingDef>((Func <ThingDef, float>)((ThingDef def) => this.map.Biome.CommonalityOfPlant(def)), out plantDef) && RCellFinder.TryFindRandomCellToPlantInFromOffMap(plantDef, this.map, out source))
            {
                GenPlantReproduction.TryReproduceFrom(source, plantDef, SeedTargFindMode.MapEdge, this.map);
            }
        }
예제 #4
0
        private void TrySpawnPlantFromMapEdge()
        {
            ThingDef plantDef;

            if (!this.map.Biome.AllWildPlants.TryRandomElementByWeight((ThingDef def) => this.map.Biome.CommonalityOfPlant(def), out plantDef))
            {
                return;
            }
            IntVec3 source;

            if (RCellFinder.TryFindRandomCellToPlantInFromOffMap(plantDef, this.map, out source))
            {
                GenPlantReproduction.TryReproduceFrom(source, plantDef, SeedTargFindMode.MapEdge, this.map);
            }
        }
예제 #5
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;
        }
예제 #6
0
 private void TrySpawnCavePlant()
 {
     WildSpawner.undergroundCells.Clear();
     CellRect.CellRectIterator iterator = CellRect.WholeMap(this.map).GetIterator();
     while (!iterator.Done())
     {
         IntVec3 current = iterator.Current;
         if (GenPlantReproduction.GoodRoofForCavePlantReproduction(current, this.map))
         {
             if (current.GetFirstItem(this.map) == null && current.GetFirstPawn(this.map) == null && current.GetFirstBuilding(this.map) == null)
             {
                 bool flag = false;
                 for (int i = 0; i < WildSpawner.cavePlants.Count; i++)
                 {
                     if (WildSpawner.cavePlants[i].CanEverPlantAt(current, this.map))
                     {
                         flag = true;
                         break;
                     }
                 }
                 if (flag)
                 {
                     WildSpawner.undergroundCells.Add(current);
                 }
             }
         }
         iterator.MoveNext();
     }
     if (WildSpawner.undergroundCells.Any <IntVec3>())
     {
         IntVec3  cell     = WildSpawner.undergroundCells.RandomElement <IntVec3>();
         ThingDef plantDef = (from x in WildSpawner.cavePlants
                              where x.CanEverPlantAt(cell, this.map)
                              select x).RandomElement <ThingDef>();
         GenPlantReproduction.TryReproduceFrom(cell, plantDef, SeedTargFindMode.Cave, this.map);
     }
 }
예제 #7
0
        public override void TickLong()
        {
            this.CheckTemperatureMakeLeafless();
            if (!base.Destroyed)
            {
                if (GenPlant.GrowthSeasonNow(base.Position, base.Map))
                {
                    float num  = this.growthInt;
                    bool  flag = this.LifeStage == PlantLifeStage.Mature;
                    this.growthInt += (float)(this.GrowthPerTick * 2000.0);
                    if (this.growthInt > 1.0)
                    {
                        this.growthInt = 1f;
                    }
                    if (!flag && this.LifeStage == PlantLifeStage.Mature)
                    {
                        goto IL_0099;
                    }
                    if ((int)(num * 10.0) != (int)(this.growthInt * 10.0))
                    {
                        goto IL_0099;
                    }
                    goto IL_00bb;
                }
                goto IL_0103;
            }
            return;

IL_0103:
            if (!this.HasEnoughLightToGrow)
            {
                this.unlitTicks += 2000;
            }
            else
            {
                this.unlitTicks = 0;
            }
            this.ageInt += 2000;
            if (this.Dying)
            {
                Map  map                        = base.Map;
                bool isCrop                     = this.IsCrop;
                bool harvestableNow             = this.HarvestableNow;
                bool dyingBecauseExposedToLight = this.DyingBecauseExposedToLight;
                int  amount                     = Mathf.CeilToInt((float)(this.CurrentDyingDamagePerTick * 2000.0));
                base.TakeDamage(new DamageInfo(DamageDefOf.Rotting, amount, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                if (base.Destroyed)
                {
                    if (isCrop && base.def.plant.Harvestable && MessagesRepeatAvoider.MessageShowAllowed("MessagePlantDiedOfRot-" + base.def.defName, 240f))
                    {
                        string key = (!harvestableNow) ? ((!dyingBecauseExposedToLight) ? "MessagePlantDiedOfRot" : "MessagePlantDiedOfRot_ExposedToLight") : "MessagePlantDiedOfRot_LeftUnharvested";
                        Messages.Message(key.Translate(this.Label).CapitalizeFirst(), new TargetInfo(base.Position, map, false), MessageTypeDefOf.NegativeEvent);
                    }
                    return;
                }
            }
            this.cachedLabelMouseover = null;
            return;

IL_00bb:
            if (this.CanReproduceNow && Rand.MTBEventOccurs(base.def.plant.reproduceMtbDays, 60000f, 2000f))
            {
                GenPlantReproduction.TryReproduceFrom(base.Position, base.def, SeedTargFindMode.Reproduce, base.Map);
            }
            goto IL_0103;
IL_0099:
            if (this.CurrentlyCultivated())
            {
                base.Map.mapDrawer.MapMeshDirty(base.Position, MapMeshFlag.Things);
            }
            goto IL_00bb;
        }
예제 #8
0
        public static bool TryFindReproductionDestination(IntVec3 source, ThingDef plantDef, SeedTargFindMode mode, Map map, out IntVec3 foundCell)
        {
            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)
            {
                foundCell = IntVec3.Invalid;
                return(false);
            }
            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(false);
                }
                float num10 = num5 * num7;
                bool  flag3 = (float)num2 < num10 * 0.5f;
                if (flag && !flag3)
                {
                    foundCell = IntVec3.Invalid;
                    return(false);
                }
            }
            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);

            return(CellFinder.TryFindRandomCellNear(source, map, Mathf.CeilToInt(radius), validator, out foundCell));
        }