Ejemplo n.º 1
0
        public static void Prefix(BiomeDef __instance)
        {
            BiomeSeasonalSettings biomeSettings = __instance.GetModExtension <BiomeSeasonalSettings>();

            if (biomeSettings != null && biomeSettings.diseaseCacheUpdated == false)
            {
                // Log.Warning("updating cachedDiseaseCommonalities");
                Traverse.Create(__instance).Field("cachedDiseaseCommonalities").SetValue(null);
                biomeSettings.diseaseCacheUpdated = true;
            }
        }
Ejemplo n.º 2
0
        protected override bool CanFireNowSub(IncidentParms parms)
        {
            IIncidentTarget target = parms.target;
            Map             map    = (Map)target;
            PawnKindDef     pawnKindDef;
            IntVec3         intVec;
            IntVec3         intVec2;

            if (map.Biome.HasModExtension <BiomeSeasonalSettings>())
            {
                mod = map.Biome.GetModExtension <BiomeSeasonalSettings>();
                if (mod.specialHerds == null)
                {
                    return(false);
                }
                return(this.TryFindAnimalKind(map.Tile, out pawnKindDef) && this.TryFindStartAndEndCells(map, out intVec, out intVec2));
            }
            return(false);
        }
Ejemplo n.º 3
0
        public override void FinalizeInit()
        {
            /*
             * List<ThingDef> plants = map.Biome.AllWildPlants;
             * foreach(ThingDef plant in plants ){
             *      Log.Warning("Wild plant: " + plant.defName);
             * }
             */

            base.FinalizeInit();
            this.biomeSettings = map.Biome.GetModExtension <BiomeSeasonalSettings>();
            this.updateBiomeSettings(true);

            this.rebuildCellLists();
            // this.map.GetComponent<FrostGrid>().Regenerate();
            if (TKKN_Holder.modsPatched.ToArray().Count() > 0)
            {
                Log.Message("TKKN NPS: Loaded patches for: " + string.Join(", ", TKKN_Holder.modsPatched.ToArray()));
            }
        }
Ejemplo n.º 4
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!base.settingsCheck())
            {
                return(false);
            }

            Map     map    = (Map)parms.target;
            IntVec3 intVec = CellFinder.RandomNotEdgeCell(15, map);

            //can the biome support it?
            bool canBloomHere = true;
            BiomeSeasonalSettings biomeSettings = map.Biome.GetModExtension <BiomeSeasonalSettings>();

            if (biomeSettings == null)
            {
                return(false);
            }
            List <ThingDef> bloomPlants = biomeSettings.bloomPlants.ToList <ThingDef>();

            if (bloomPlants.Count == 0)
            {
                return(false);
            }

            if (!canBloomHere)
            {
                return(false);
            }



            Find.LetterStack.ReceiveLetter(this.def.letterLabel.Translate(), this.def.letterText.Translate(), this.def.letterDef);


            return(true);
        }
        public static void Postfix(WildPlantSpawner __instance, IntVec3 c, float plantDensity, float wholeMapNumDesiredPlants, bool setRandomGrowth, ref bool __result)
        {
            if (__result == false)
            {
                Map map = Traverse.Create(__instance).Field("map").GetValue <Map>();

                if (!(plantDensity <= 0.0) && c.GetPlant(map) == null && c.GetCover(map) == null && c.GetEdifice(map) == null && PlantUtility.SnowAllowsPlanting(c, map))
                {
                    //check if we're on water or salt.
                    TerrainDef            terrain  = c.GetTerrain(map);
                    BiomeSeasonalSettings biomeSet = map.Biome.GetModExtension <BiomeSeasonalSettings>();
                    if (biomeSet.specialPlants != null)
                    {
                        //spawn any special plants
                        WildPlantSpawner.tmpPossiblePlants

                        this.CalculatePlantsWhichCanGrowAt(c, WildPlantSpawner.tmpPossiblePlants, cavePlants, plantDensity);

                        if (!WildPlantSpawner.tmpPossiblePlants.Any())
                        {
                            return(false);
                        }
                        this.CalculateDistancesToNearbyClusters(c);
                        WildPlantSpawner.tmpPossiblePlantsWithWeight.Clear();
                        for (int i = 0; i < WildPlantSpawner.tmpPossiblePlants.Count; i++)
                        {
                            float value = this.PlantChoiceWeight(WildPlantSpawner.tmpPossiblePlants[i], c, WildPlantSpawner.distanceSqToNearbyClusters, wholeMapNumDesiredPlants, plantDensity);
                            WildPlantSpawner.tmpPossiblePlantsWithWeight.Add(new KeyValuePair <ThingDef, float>(WildPlantSpawner.tmpPossiblePlants[i], value));
                        }
                        KeyValuePair <ThingDef, float> keyValuePair = default(KeyValuePair <ThingDef, float>);
                        if (!((IEnumerable <KeyValuePair <ThingDef, float> >)WildPlantSpawner.tmpPossiblePlantsWithWeight).TryRandomElementByWeight <KeyValuePair <ThingDef, float> >((Func <KeyValuePair <ThingDef, float>, float>)((KeyValuePair <ThingDef, float> x) => x.Value), out keyValuePair))
                        {
                            return(false);
                        }
                        Plant plant = (Plant)ThingMaker.MakeThing(keyValuePair.Key, null);
                        if (setRandomGrowth)
                        {
                            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, c, map, WipeMode.Vanish);
                        return(true);
                    }

                    PlantDef = c.GetPlant(map);
                    if (__result == true && plantDef != null && c != null && map != null)
                    {
                        BiomeDef biome = map.Biome;
                        BiomeSeasonalSettings biomeSettings = biome.GetModExtension <BiomeSeasonalSettings>();
                        if (biomeSettings != null)
                        {
                            if (!biomeSettings.canPutOnTerrain(c, plantDef, map))
                            {
                                __result = false;
                            }
                        }
                    }
                }
            }
        }
        public void DoCellSteadyEffects(IntVec3 c)
        {
            //must be outdoors.
            Map map = base.SingleMap;
            BiomeSeasonalSettings biomeSettings = base.SingleMap.Biome.GetModExtension <BiomeSeasonalSettings>();
            List <ThingDef>       bloomPlants   = biomeSettings.bloomPlants.ToList <ThingDef>();

            if (bloomPlants.Count == 0)
            {
                return;
            }

            Room room = c.GetRoom(base.SingleMap, RegionType.Set_All);

            if (room != null)
            {
                return;
            }


            TerrainDef terrain = c.GetTerrain(base.SingleMap);

            if (terrain.fertility == 0)
            {
                return;
            }

            if (!c.Roofed(base.SingleMap) && c.GetEdifice(base.SingleMap) == null && c.GetCover(base.SingleMap) == null)
            {
                List <Thing> thingList = c.GetThingList(base.SingleMap);
                bool         planted   = false;
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    if (thing is Plant)
                    {
                        if (Rand.Value < 0.0065f)
                        {
                            Plant plant = (Plant)ThingMaker.MakeThing(thing.def, null);
                            if (plant.def.plant.LimitedLifespan && plant.def.statBases.GetStatOffsetFromList(StatDefOf.Beauty) > 3 && plant.def.ingestible.foodType != FoodTypeFlags.Tree)
                            {
                                plant.Growth = 1;
                            }
                            planted = true;
                        }
                    }
                }
                if (planted)
                {
                    return;
                }
            }
            else
            {
                return;
            }

            if (Rand.Value < 0.65f * base.SingleMap.fertilityGrid.FertilityAt(c) * this.howManyBlooms)
            {
                IEnumerable <ThingDef> source = from def in bloomPlants
                                                where def.CanEverPlantAt(c, base.SingleMap)
                                                select def;
                if (source.Any <ThingDef>())
                {
                    ThingDef thingDef = source.RandomElement();
                    Plant    plant    = (Plant)ThingMaker.MakeThing(thingDef, null);
                    plant.Growth = 1;
                    GenSpawn.Spawn(plant, c, base.SingleMap);
                }
            }
        }