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);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
     }
 }
Esempio n. 4
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;
        }