示例#1
0
        public static TerrainDef BeachTerrainAt(IntVec3 loc, BiomeDef biome)
        {
            TerrainDef result;

            if (BeachMaker.beachNoise == null)
            {
                result = null;
            }
            else
            {
                float value = BeachMaker.beachNoise.GetValue(loc);
                if (value < 0.1f)
                {
                    result = TerrainDefOf.WaterOceanDeep;
                }
                else if (value < 0.45f)
                {
                    result = TerrainDefOf.WaterOceanShallow;
                }
                else if (value < 1f)
                {
                    result = ((biome != BiomeDefOf.SeaIce) ? TerrainDefOf.Sand : TerrainDefOf.Ice);
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
        public static TerrainDef BeachTerrainAt(IntVec3 loc, BiomeDef biome)
        {
            if (beachNoise == null)
            {
                return(null);
            }
            float value = beachNoise.GetValue(loc);

            if (value < 0.1f)
            {
                return(TerrainDefOf.WaterOceanDeep);
            }
            if (value < 0.45f)
            {
                return(TerrainDefOf.WaterOceanShallow);
            }
            if (value < 1f)
            {
                if (biome != BiomeDefOf.SeaIce)
                {
                    return(TerrainDefOf.Sand);
                }
                return(TerrainDefOf.Ice);
            }
            return(null);
        }
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            _003CMakeIntervalIncidents_003Ec__Iterator0 _003CMakeIntervalIncidents_003Ec__Iterator = (_003CMakeIntervalIncidents_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/;

            if (DebugSettings.enableRandomDiseases && target.Tile != -1)
            {
                BiomeDef biome = Find.WorldGrid[target.Tile].biome;
                float    mtb2  = biome.diseaseMtbDays;
                mtb2 *= Find.Storyteller.difficulty.diseaseIntervalFactor;
                if (!Rand.MTBEventOccurs(mtb2, 60000f, 1000f))
                {
                    yield break;
                }
                IncidentDef inc;
                if (!(from d in DefDatabase <IncidentDef> .AllDefs
                      where d.Worker.CanFireNow(target) && d.category == IncidentCategory.Disease
                      select d).TryRandomElementByWeight <IncidentDef>((Func <IncidentDef, float>)((IncidentDef d) => biome.CommonalityOfDisease(d)), out inc))
                {
                    yield break;
                }
                yield return(new FiringIncident(inc, this, this.GenerateParms(inc.category, target)));

                /*Error: Unable to find new state assignment for yield return*/;
            }
        }
示例#4
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (!(target is World))
            {
                List <IncidentDef> allIncidents = DefDatabase <IncidentDef> .AllDefsListForReading;
                int           i = 0;
                IncidentDef   inc;
                IncidentParms parms;
                while (true)
                {
                    if (i >= allIncidents.Count)
                    {
                        yield break;
                    }
                    inc = allIncidents[i];
                    if (inc.category == Props.category)
                    {
                        _003CMakeIntervalIncidents_003Ec__Iterator0 _003CMakeIntervalIncidents_003Ec__Iterator = (_003CMakeIntervalIncidents_003Ec__Iterator0) /*Error near IL_0095: stateMachine*/;
                        BiomeDef biome = Find.WorldGrid[target.Tile].biome;
                        if (inc.mtbDaysByBiome != null)
                        {
                            MTBByBiome entry = inc.mtbDaysByBiome.Find((MTBByBiome x) => x.biome == biome);
                            if (entry != null)
                            {
                                float mtb = entry.mtbDays;
                                if (Props.applyCaravanVisibility)
                                {
                                    Caravan caravan = target as Caravan;
                                    if (caravan != null)
                                    {
                                        mtb /= caravan.Visibility;
                                    }
                                    else
                                    {
                                        Map map = target as Map;
                                        if (map != null && map.Parent.def.isTempIncidentMapOwner)
                                        {
                                            IEnumerable <Pawn> pawns = map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer).Concat(map.mapPawns.PrisonersOfColonySpawned);
                                            mtb /= CaravanVisibilityCalculator.Visibility(pawns, caravanMovingNow: false);
                                        }
                                    }
                                }
                                if (Rand.MTBEventOccurs(mtb, 60000f, 1000f))
                                {
                                    parms = GenerateParms(inc.category, target);
                                    if (inc.Worker.CanFireNow(parms))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    i++;
                }
                yield return(new FiringIncident(inc, this, parms));

                /*Error: Unable to find new state assignment for yield return*/;
            }
        }
示例#5
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (!(target is World))
            {
                List <IncidentDef> allIncidents = DefDatabase <IncidentDef> .AllDefsListForReading;
                int         i = 0;
                IncidentDef inc;
                while (true)
                {
                    if (i < allIncidents.Count)
                    {
                        inc = allIncidents[i];
                        if (inc.category == this.Props.category)
                        {
                            _003CMakeIntervalIncidents_003Ec__Iterator0 _003CMakeIntervalIncidents_003Ec__Iterator = (_003CMakeIntervalIncidents_003Ec__Iterator0) /*Error near IL_0095: stateMachine*/;
                            BiomeDef biome = Find.WorldGrid[target.Tile].biome;
                            if (inc.mtbDaysByBiome != null)
                            {
                                MTBByBiome entry = inc.mtbDaysByBiome.Find((MTBByBiome x) => x.biome == biome);
                                if (entry != null)
                                {
                                    float mtb = entry.mtbDays;
                                    if (this.Props.applyCaravanStealthFactor)
                                    {
                                        Caravan caravan = target as Caravan;
                                        if (caravan != null)
                                        {
                                            mtb *= CaravanIncidentUtility.CalculateCaravanStealthFactor(caravan.PawnsListForReading.Count);
                                        }
                                        else
                                        {
                                            Map map = target as Map;
                                            if (map != null && map.info.parent.def.isTempIncidentMapOwner)
                                            {
                                                int pawnCount = map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer).Count + map.mapPawns.PrisonersOfColonySpawnedCount;
                                                mtb *= CaravanIncidentUtility.CalculateCaravanStealthFactor(pawnCount);
                                            }
                                        }
                                    }
                                    if (Rand.MTBEventOccurs(mtb, 60000f, 1000f) && inc.Worker.CanFireNow(target))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        i++;
                        continue;
                    }
                    yield break;
                }
                yield return(new FiringIncident(inc, this, this.GenerateParms(inc.category, target)));

                /*Error: Unable to find new state assignment for yield return*/;
            }
        }
 public bool CanFireNow(IncidentParms parms, bool forced = false)
 {
     if (!parms.forced)
     {
         if (!def.TargetAllowed(parms.target))
         {
             return(false);
         }
         if (GenDate.DaysPassed < def.earliestDay)
         {
             return(false);
         }
         if (!Find.Storyteller.difficultyValues.AllowedBy(def.disabledWhen) || (def.category == IncidentCategoryDefOf.ThreatBig && !Find.Storyteller.difficultyValues.allowBigThreats))
         {
             return(false);
         }
         if (parms.points >= 0f && parms.points < def.minThreatPoints)
         {
             return(false);
         }
         if (def.allowedBiomes != null)
         {
             BiomeDef biome = Find.WorldGrid[parms.target.Tile].biome;
             if (!def.allowedBiomes.Contains(biome))
             {
                 return(false);
             }
         }
         Scenario scenario = Find.Scenario;
         for (int i = 0; i < scenario.parts.Count; i++)
         {
             ScenPart_DisableIncident scenPart_DisableIncident = scenario.parts[i] as ScenPart_DisableIncident;
             if (scenPart_DisableIncident != null && scenPart_DisableIncident.Incident == def)
             {
                 return(false);
             }
         }
         if (def.minPopulation > 0 && PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists.Count() < def.minPopulation)
         {
             return(false);
         }
         if (FiredTooRecently(parms.target))
         {
             return(false);
         }
         if (def.minGreatestPopulation > 0 && Find.StoryWatcher.statsRecord.greatestPopulation < def.minGreatestPopulation)
         {
             return(false);
         }
     }
     if (!CanFireNowSub(parms))
     {
         return(false);
     }
     return(true);
 }
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (target is World)
            {
                yield break;
            }
            List <IncidentDef> allIncidents = DefDatabase <IncidentDef> .AllDefsListForReading;
            int i = 0;

            while (i < allIncidents.Count)
            {
                IncidentDef inc = allIncidents[i];
                if (inc.category == this.Props.category)
                {
                    BiomeDef biome = Find.WorldGrid[target.Tile].biome;
                    if (inc.mtbDaysByBiome != null)
                    {
                        MTBByBiome entry = inc.mtbDaysByBiome.Find((MTBByBiome x) => x.biome == biome);
                        if (entry != null)
                        {
                            float mtb = entry.mtbDays;
                            if (this.Props.applyCaravanVisibility)
                            {
                                Caravan caravan = target as Caravan;
                                if (caravan != null)
                                {
                                    mtb /= caravan.Visibility;
                                }
                                else
                                {
                                    Map map = target as Map;
                                    if (map != null && map.Parent.def.isTempIncidentMapOwner)
                                    {
                                        IEnumerable <Pawn> pawns = map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer).Concat(map.mapPawns.PrisonersOfColonySpawned);
                                        mtb /= CaravanVisibilityCalculator.Visibility(pawns, false, null);
                                    }
                                }
                            }
                            if (Rand.MTBEventOccurs(mtb, 60000f, 1000f))
                            {
                                IncidentParms parms = this.GenerateParms(inc.category, target);
                                if (inc.Worker.CanFireNow(parms))
                                {
                                    yield return(new FiringIncident(inc, this, parms));
                                }
                            }
                        }
                    }
                }
IL_24E:
                i++;
                continue;
                goto IL_24E;
            }
            yield break;
        }
示例#8
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (target is World)
            {
                yield break;
            }
            List <IncidentDef> allIncidents = DefDatabase <IncidentDef> .AllDefsListForReading;

            for (int i = 0; i < allIncidents.Count; i++)
            {
                IncidentDef incidentDef = allIncidents[i];
                if (incidentDef.category != Props.category)
                {
                    continue;
                }
                BiomeDef biome = Find.WorldGrid[target.Tile].biome;
                if (incidentDef.mtbDaysByBiome == null)
                {
                    continue;
                }
                MTBByBiome mTBByBiome = incidentDef.mtbDaysByBiome.Find((MTBByBiome x) => x.biome == biome);
                if (mTBByBiome == null)
                {
                    continue;
                }
                float num = mTBByBiome.mtbDays;
                if (Props.applyCaravanVisibility)
                {
                    Caravan caravan = target as Caravan;
                    if (caravan != null)
                    {
                        num /= caravan.Visibility;
                    }
                    else
                    {
                        Map map = target as Map;
                        if (map != null && map.Parent.def.isTempIncidentMapOwner)
                        {
                            IEnumerable <Pawn> pawns = map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer).Concat(map.mapPawns.PrisonersOfColonySpawned);
                            num /= CaravanVisibilityCalculator.Visibility(pawns, caravanMovingNow: false);
                        }
                    }
                }
                if (Rand.MTBEventOccurs(num, 60000f, 1000f))
                {
                    IncidentParms parms = GenerateParms(incidentDef.category, target);
                    if (incidentDef.Worker.CanFireNow(parms))
                    {
                        yield return(new FiringIncident(incidentDef, this, parms));
                    }
                }
            }
        }
        private float CurrentWeatherCommonality(WeatherDef weather)
        {
            float result;

            if (this.map.weatherManager.curWeather != null && !this.map.weatherManager.curWeather.repeatable && weather == this.map.weatherManager.curWeather)
            {
                result = 0f;
            }
            else if (!weather.temperatureRange.Includes(this.map.mapTemperature.OutdoorTemp))
            {
                result = 0f;
            }
            else if (weather.favorability < Favorability.Neutral && GenDate.DaysPassed < 8)
            {
                result = 0f;
            }
            else if (weather.rainRate > 0.1f && Find.TickManager.TicksGame < this.ticksWhenRainAllowedAgain)
            {
                result = 0f;
            }
            else
            {
                if (weather.rainRate > 0.1f)
                {
                    if (this.map.gameConditionManager.ActiveConditions.Any((GameCondition x) => x.def.preventRain))
                    {
                        return(0f);
                    }
                }
                BiomeDef biome = this.map.Biome;
                for (int i = 0; i < biome.baseWeatherCommonalities.Count; i++)
                {
                    WeatherCommonalityRecord weatherCommonalityRecord = biome.baseWeatherCommonalities[i];
                    if (weatherCommonalityRecord.weather == weather)
                    {
                        float num = weatherCommonalityRecord.commonality;
                        if (this.map.fireWatcher.LargeFireDangerPresent && weather.rainRate > 0.1f)
                        {
                            num *= 15f;
                        }
                        if (weatherCommonalityRecord.weather.commonalityRainfallFactor != null)
                        {
                            num *= weatherCommonalityRecord.weather.commonalityRainfallFactor.Evaluate(this.map.TileInfo.rainfall);
                        }
                        return(num);
                    }
                }
                result = 0f;
            }
            return(result);
        }
示例#10
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            _003CMakeIntervalIncidents_003Ec__Iterator0 _003CMakeIntervalIncidents_003Ec__Iterator = (_003CMakeIntervalIncidents_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/;

            if (DebugSettings.enableRandomDiseases && target.Tile != -1)
            {
                BiomeDef biome = Find.WorldGrid[target.Tile].biome;
                float    mtb2  = biome.diseaseMtbDays;
                mtb2 *= Find.Storyteller.difficulty.diseaseIntervalFactor;
                if (Rand.MTBEventOccurs(mtb2, 60000f, 1000f) && UsableIncidentsInCategory(Props.category, target).TryRandomElementByWeight((IncidentDef d) => biome.CommonalityOfDisease(d), out IncidentDef inc))
                {
                    yield return(new FiringIncident(inc, this, GenerateParms(inc.category, target)));

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
        }
 public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
 {
     if (DebugSettings.enableRandomDiseases)
     {
         if (target.Tile != -1)
         {
             BiomeDef biome = Find.WorldGrid[target.Tile].biome;
             float    mtb   = biome.diseaseMtbDays;
             mtb *= Find.Storyteller.difficulty.diseaseIntervalFactor;
             IncidentDef inc;
             if (Rand.MTBEventOccurs(mtb, 60000f, 1000f) && base.UsableIncidentsInCategory(this.Props.category, target).TryRandomElementByWeight((IncidentDef d) => biome.CommonalityOfDisease(d), out inc))
             {
                 yield return(new FiringIncident(inc, this, this.GenerateParms(inc.category, target)));
             }
         }
     }
 }
 public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
 {
     if (DebugSettings.enableRandomDiseases)
     {
         if (target.Tile != -1)
         {
             BiomeDef biome = Find.WorldGrid[target.Tile].biome;
             float    mtb   = biome.diseaseMtbDays;
             mtb *= Find.Storyteller.difficulty.diseaseIntervalFactor;
             IncidentDef inc;
             if (Rand.MTBEventOccurs(mtb, 60000f, 1000f) && (from d in DefDatabase <IncidentDef> .AllDefs
                                                             where d.Worker.CanFireNow(target) && d.category == IncidentCategory.Disease
                                                             select d).TryRandomElementByWeight((IncidentDef d) => biome.CommonalityOfDisease(d), out inc))
             {
                 yield return(new FiringIncident(inc, this, this.GenerateParms(inc.category, target)));
             }
         }
     }
 }
示例#13
0
        private static Dictionary <ThingDef, float> CalculateDesiredPlantProportions(BiomeDef biome)
        {
            Dictionary <ThingDef, float> dictionary = new Dictionary <ThingDef, float>();
            float num = 0f;

            foreach (ThingDef allDef in DefDatabase <ThingDef> .AllDefs)
            {
                if (allDef.plant != null)
                {
                    float num2 = biome.CommonalityOfPlant(allDef);
                    dictionary.Add(allDef, num2);
                    num += num2;
                }
            }
            foreach (ThingDef allWildPlant in biome.AllWildPlants)
            {
                dictionary[allWildPlant] /= num;
            }
            return(dictionary);
        }
示例#14
0
        private static Dictionary <ThingDef, float> CalculateDesiredPlantProportions(BiomeDef biome)
        {
            Dictionary <ThingDef, float> dictionary = new Dictionary <ThingDef, float>();
            float num = 0f;

            foreach (ThingDef thingDef in DefDatabase <ThingDef> .AllDefs)
            {
                if (thingDef.plant != null)
                {
                    float num2 = biome.CommonalityOfPlant(thingDef);
                    dictionary.Add(thingDef, num2);
                    num += num2;
                }
            }
            foreach (ThingDef thingDef2 in biome.AllWildPlants)
            {
                Dictionary <ThingDef, float> dictionary2;
                ThingDef key;
                (dictionary2 = dictionary)[key = thingDef2] = dictionary2[key] / num;
            }
            return(dictionary);
        }
示例#15
0
        public static TerrainDef BeachTerrainAt(IntVec3 loc, BiomeDef biome)
        {
            if (BeachMaker.beachNoise == null)
            {
                return(null);
            }
            float value = BeachMaker.beachNoise.GetValue(loc);

            if (value < 0.10000000149011612)
            {
                return(TerrainDefOf.WaterOceanDeep);
            }
            if (value < 0.44999998807907104)
            {
                return(TerrainDefOf.WaterOceanShallow);
            }
            if (value < 1.0)
            {
                return((biome != BiomeDefOf.SeaIce) ? TerrainDefOf.Sand : TerrainDefOf.Ice);
            }
            return(null);
        }
示例#16
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (!DebugSettings.enableRandomDiseases || target is World || Find.Storyteller.difficultyValues.diseaseIntervalFactor >= 100f)
            {
                yield break;
            }
            BiomeDef biome          = Find.WorldGrid[target.Tile].biome;
            float    diseaseMtbDays = biome.diseaseMtbDays;

            diseaseMtbDays *= Find.Storyteller.difficultyValues.diseaseIntervalFactor;
            if (target is Caravan)
            {
                diseaseMtbDays *= CaravanDiseaseMTBFactor;
            }
            if (Rand.MTBEventOccurs(diseaseMtbDays, 60000f, 1000f))
            {
                IncidentParms parms = GenerateParms(Props.category, target);
                if (UsableIncidentsInCategory(Props.category, parms).TryRandomElementByWeight((IncidentDef d) => biome.CommonalityOfDisease(d), out var result))
                {
                    yield return(new FiringIncident(result, this, parms));
                }
            }
        }
示例#17
0
 public bool CanFireNow(IncidentParms parms, bool forced = false)
 {
     if (!parms.forced)
     {
         if (!this.def.TargetAllowed(parms.target))
         {
             return(false);
         }
         if (GenDate.DaysPassed < this.def.earliestDay)
         {
             return(false);
         }
         if (Find.Storyteller.difficulty.difficulty < this.def.minDifficulty)
         {
             return(false);
         }
         if (this.def.allowedBiomes != null)
         {
             BiomeDef biome = Find.WorldGrid[parms.target.Tile].biome;
             if (!this.def.allowedBiomes.Contains(biome))
             {
                 return(false);
             }
         }
         Scenario scenario = Find.Scenario;
         for (int i = 0; i < scenario.parts.Count; i++)
         {
             ScenPart_DisableIncident scenPart_DisableIncident = scenario.parts[i] as ScenPart_DisableIncident;
             if (scenPart_DisableIncident != null && scenPart_DisableIncident.Incident == this.def)
             {
                 return(false);
             }
         }
         if (this.def.minPopulation > 0 && PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists.Count <Pawn>() < this.def.minPopulation)
         {
             return(false);
         }
         Dictionary <IncidentDef, int> lastFireTicks = parms.target.StoryState.lastFireTicks;
         int ticksGame = Find.TickManager.TicksGame;
         int num;
         if (lastFireTicks.TryGetValue(this.def, out num))
         {
             float num2 = (float)(ticksGame - num) / 60000f;
             if (num2 < this.def.minRefireDays)
             {
                 return(false);
             }
         }
         List <IncidentDef> refireCheckIncidents = this.def.RefireCheckIncidents;
         if (refireCheckIncidents != null)
         {
             for (int j = 0; j < refireCheckIncidents.Count; j++)
             {
                 if (lastFireTicks.TryGetValue(refireCheckIncidents[j], out num))
                 {
                     float num3 = (float)(ticksGame - num) / 60000f;
                     if (num3 < this.def.minRefireDays)
                     {
                         return(false);
                     }
                 }
             }
         }
         if (this.def.minGreatestPopulation > 0 && Find.StoryWatcher.statsRecord.greatestPopulation < this.def.minGreatestPopulation)
         {
             return(false);
         }
     }
     return(this.CanFireNowSub(parms));
 }
        public bool CanFireNow(IIncidentTarget target)
        {
            if (!this.def.TargetAllowed(target))
            {
                return(false);
            }
            if (GenDate.DaysPassed < this.def.earliestDay)
            {
                return(false);
            }
            if (this.def.minPopulation > 0 && PawnsFinder.AllMapsCaravansAndTravelingTransportPods_FreeColonists.Count() < this.def.minPopulation)
            {
                return(false);
            }
            if (Find.Storyteller.difficulty.difficulty < this.def.minDifficulty)
            {
                return(false);
            }
            if (this.def.allowedBiomes != null)
            {
                BiomeDef biome = Find.WorldGrid[target.Tile].biome;
                if (!this.def.allowedBiomes.Contains(biome))
                {
                    return(false);
                }
            }
            for (int i = 0; i < Find.Scenario.parts.Count; i++)
            {
                ScenPart_DisableIncident scenPart_DisableIncident = Find.Scenario.parts[i] as ScenPart_DisableIncident;
                if (scenPart_DisableIncident != null && scenPart_DisableIncident.Incident == this.def)
                {
                    return(false);
                }
            }
            Dictionary <IncidentDef, int> lastFireTicks = target.StoryState.lastFireTicks;
            int ticksGame = Find.TickManager.TicksGame;
            int num       = default(int);

            if (lastFireTicks.TryGetValue(this.def, out num))
            {
                float num2 = (float)((float)(ticksGame - num) / 60000.0);
                if (num2 < this.def.minRefireDays)
                {
                    return(false);
                }
            }
            List <IncidentDef> refireCheckIncidents = this.def.RefireCheckIncidents;

            if (refireCheckIncidents != null)
            {
                for (int j = 0; j < refireCheckIncidents.Count; j++)
                {
                    if (lastFireTicks.TryGetValue(refireCheckIncidents[j], out num))
                    {
                        float num3 = (float)((float)(ticksGame - num) / 60000.0);
                        if (num3 < this.def.minRefireDays)
                        {
                            return(false);
                        }
                    }
                }
            }
            if (!this.CanFireNowSub(target))
            {
                return(false);
            }
            return(true);
        }
        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));
        }