예제 #1
0
        public bool CheckSpawnWildPlantAt(IntVec3 c, float plantDensity, float wholeMapNumDesiredPlants, bool setRandomGrowth = false)
        {
            if (plantDensity <= 0f || c.GetPlant(this.map) != null || c.GetCover(this.map) != null || c.GetEdifice(this.map) != null || this.map.fertilityGrid.FertilityAt(c) <= 0f || !PlantUtility.SnowAllowsPlanting(c, this.map))
            {
                return(false);
            }
            bool cavePlants = this.GoodRoofForCavePlant(c);

            if (this.SaturatedAt(c, plantDensity, cavePlants, wholeMapNumDesiredPlants))
            {
                return(false);
            }
            this.CalculatePlantsWhichCanGrowAt(c, WildPlantSpawner.tmpPossiblePlants, cavePlants, plantDensity);
            if (!WildPlantSpawner.tmpPossiblePlants.Any <ThingDef>())
            {
                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;

            if (!WildPlantSpawner.tmpPossiblePlantsWithWeight.TryRandomElementByWeight((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, this.map, WipeMode.Vanish);
            return(true);
        }