public override void Resolve(ResolveParams rp)
        {
            var count = rp.hivesCount ?? 1;

            for (var i = 0; i < count; i++)
            {
                var kind    = Rand.Value > 0.3f ? DwarfDefOf.LotRD_DwarfVillager : DwarfDefOf.LotRD_DwarfGuardMountain;
                var faction = rp.faction;
                var request = new PawnGenerationRequest(kind, faction,
                                                        PawnGenerationContext.NonPlayer, BaseGen.globalSettings?.map?.Tile ?? Find.CurrentMap.Tile, false,
                                                        false, false, false, true, true, 1f, false, true, false,
                                                        false);
                var pawn = PawnGenerator.GeneratePawn(request);

                //CellFinder.TryFindBestPawnStandCell(pawn, out spawnLoc);
                var map = BaseGen.globalSettings?.map ?? Find.CurrentMap;
                CellFinderLoose.TryGetRandomCellWith(
                    x => x.IsValid && rp.rect.Contains(x) && x.GetEdifice(map) == null && x.GetFirstItem(map) == null,
                    map, 250, out var spawnLoc);
                GenSpawn.Spawn(pawn, spawnLoc, map);
                pawn.Kill(null);
                if (pawn.Corpse is not {
                } c || c.TryGetComp <CompRottable>() is not {
                } comp)
                {
                    continue;
                }

                c.Age += GenDate.TicksPerSeason * Rand.Range(8, 100);
                Log.Message("Rotted corpse");
                comp.RotProgress += 9999999;
            }
        }
Exemple #2
0
        /// <summary>
        /// Try to get a valid cell to spawn a new cluster anywhere on the map.
        /// </summary>
        public static void TryGetRandomClusterSpawnCell(ThingDef_ClusterPlant plantDef, int newDesiredClusterSize, bool checkTemperature, Map map, out IntVec3 spawnCell)
        {
            spawnCell = IntVec3.Invalid;

            Predicate <IntVec3> validator = delegate(IntVec3 cell)
            {
                // Check a plant can be spawned here.
                if (GenClusterPlantReproduction.IsValidPositionToGrowPlant(plantDef, map, cell, checkTemperature) == false)
                {
                    return(false);
                }
                // Check there is no third cluster nearby.
                if (GenClusterPlantReproduction.IsClusterAreaClear(plantDef, newDesiredClusterSize, map, cell) == false)
                {
                    return(false);
                }
                return(true);
            };

            bool validCellIsFound = CellFinderLoose.TryGetRandomCellWith(validator, map, 1000, out spawnCell);

            if (validCellIsFound == false)
            {
                // Just for robustness, TryGetRandomCellWith set result to IntVec3.Invalid if no valid cell is found.
                spawnCell = IntVec3.Invalid;
            }
        }
Exemple #3
0
        public override void Generate(Map map, GenStepParams parms)
        {
            float num = Mathf.Min(18000f, Mathf.Max(new float[]
            {
                Mathf.Exp(Rand.Gaussian(8f, 0.65f))
            }));
            ThingSetMakerParams value = default(ThingSetMakerParams);

            value.techLevel = TechLevel.Spacer;
            int count = Rand.RangeInclusive(2, 10);

            value.countRange            = new IntRange?(new IntRange(count, count));
            value.totalMarketValueRange = new FloatRange?(new FloatRange(num, num));
            value.validator             = ((ThingDef t) => t.defName != "Silver");
            if (num > 10000f)
            {
                value.countRange = new IntRange?(new IntRange(1, 1));
            }
            List <Thing> list = ThingSetMakerDefOf.Reward_ItemsStandard.root.Generate(value);

            foreach (Thing thing in list)
            {
                if (thing.stackCount > thing.def.stackLimit)
                {
                    thing.stackCount = thing.def.stackLimit;
                }
                IntVec3 intVec;
                if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => x.Standable(map) && x.Fogged(map) && GridsUtility.GetRoom(x, map, RegionType.Set_Passable).CellCount >= 2, map, 1000, out intVec))
                {
                    // TODO: check if it works
                    GenSpawn.Spawn(thing, intVec, map, Rot4.Random, WipeMode.Vanish, false);
                }
            }
        }
Exemple #4
0
 private void CollapseRandomRoof()
 {
     foreach (Map map in AffectedMaps)
     {
         IntVec3 intVec;
         if (CellFinderLoose.TryGetRandomCellWith((IntVec3 c) => c.Standable(map) && map.roofGrid.Roofed(c), map, 500, out intVec))
         {
             map.roofCollapseBuffer.MarkToCollapse(intVec);
             IntVec3[] array = new IntVec3[]
             {
                 intVec + IntVec3.West,
                 intVec + IntVec3.East,
                 intVec + IntVec3.South,
                 intVec + IntVec3.North
             };
             foreach (IntVec3 c2 in array)
             {
                 if (c2.Standable(map) && map.roofGrid.Roofed(c2))
                 {
                     map.roofCollapseBuffer.MarkToCollapse(c2);
                 }
             }
         }
     }
 }
        public override void Generate(Map map, GenStepParams parms)
        {
            float       num  = this.pointsRange.RandomInRange;
            List <Pawn> list = new List <Pawn>();

            for (int i = 0; i < 50; i++)
            {
                PawnKindDef pawnKindDef;
                if (!ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(this.pointsRange.RandomInRange, map.Tile, out pawnKindDef))
                {
                    return;
                }
                list.Add(PawnGenerator.GeneratePawn(pawnKindDef, null));
                num -= pawnKindDef.combatPower;
                if (num <= 0f)
                {
                    break;
                }
            }
            for (int j = 0; j < list.Count; j++)
            {
                IntVec3 intVec;
                if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => x.Standable(map) && x.Fogged(map) && GridsUtility.GetRoom(x, map, RegionType.Set_Passable).CellCount >= 4, map, 1000, out intVec))
                {
                    IntVec3 intVec2 = CellFinder.RandomSpawnCellForPawnNear(intVec, map, 10);
                    GenSpawn.Spawn(list[j], intVec2, map, Rot4.Random, WipeMode.Vanish, false);
                    list[j].mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent, null, false, false, null);
                }
            }
        }
        public static IntVec3 RandomRaidDest(IntVec3 raidSpawnLoc, Map map)
        {
            List <ThingDef> allBedDefBestToWorst = RestUtility.AllBedDefBestToWorst;
            List <Building> list = new List <Building>(map.mapPawns.FreeColonistsAndPrisonersSpawnedCount);

            for (int i = 0; i < allBedDefBestToWorst.Count; i++)
            {
                foreach (Building building in map.listerBuildings.AllBuildingsColonistOfDef(allBedDefBestToWorst[i]))
                {
                    if (((Building_Bed)building).owners.Any <Pawn>() && map.reachability.CanReach(raidSpawnLoc, building, PathEndMode.OnCell, TraverseMode.PassAllDestroyableThings, Danger.Deadly))
                    {
                        list.Add(building);
                    }
                }
            }
            Building building2;
            IntVec3  result;

            if (list.TryRandomElement(out building2))
            {
                result = building2.Position;
            }
            else
            {
                IEnumerable <Building> source = from b in map.listerBuildings.allBuildingsColonist
                                                where !b.def.building.ai_combatDangerous && !b.def.building.isInert
                                                select b;
                if (source.Any <Building>())
                {
                    for (int j = 0; j < 500; j++)
                    {
                        Building t      = source.RandomElement <Building>();
                        IntVec3  intVec = t.RandomAdjacentCell8Way();
                        if (intVec.Walkable(map) && map.reachability.CanReach(raidSpawnLoc, intVec, PathEndMode.OnCell, TraverseMode.PassAllDestroyableThings, Danger.Deadly))
                        {
                            return(intVec);
                        }
                    }
                }
                Pawn    pawn;
                IntVec3 intVec2;
                if ((from x in map.mapPawns.FreeColonistsSpawned
                     where map.reachability.CanReach(raidSpawnLoc, x, PathEndMode.OnCell, TraverseMode.PassAllDestroyableThings, Danger.Deadly)
                     select x).TryRandomElement(out pawn))
                {
                    result = pawn.Position;
                }
                else if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => map.reachability.CanReach(raidSpawnLoc, x, PathEndMode.OnCell, TraverseMode.PassAllDestroyableThings, Danger.Deadly), map, 1000, out intVec2))
                {
                    result = intVec2;
                }
                else
                {
                    result = map.Center;
                }
            }
            return(result);
        }
        public static IntVec3 RandomAnimalSpawnCell_MapGen(Map map)
        {
            int numStand = 0;
            int numRoom  = 0;
            int numTouch = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    numStand++;
                    return(false);
                }
                if (c.GetTerrain(map).avoidWander)
                {
                    return(false);
                }
                Room room = c.GetRoom(map, RegionType.Set_Passable);
                if (room == null)
                {
                    numRoom++;
                    return(false);
                }
                if (!room.TouchesMapEdge)
                {
                    numTouch++;
                    return(false);
                }
                return(true);
            };
            IntVec3 intVec;

            if (!CellFinderLoose.TryGetRandomCellWith(validator, map, 1000, out intVec))
            {
                intVec = CellFinder.RandomCell(map);
                Log.Warning(string.Concat(new object[]
                {
                    "RandomAnimalSpawnCell_MapGen failed: numStand=",
                    numStand,
                    ", numRoom=",
                    numRoom,
                    ", numTouch=",
                    numTouch,
                    ". PlayerStartSpot=",
                    MapGenerator.PlayerStartSpot,
                    ". Returning ",
                    intVec
                }), false);
            }
            return(intVec);
        }
Exemple #8
0
        private IntVec3 GetRandomDropSpot()
        {
            Map map = mapParent.Map;

            if (useTradeDropSpot)
            {
                return(DropCellFinder.TradeDropSpot(map));
            }
            if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => x.Standable(map) && !x.Roofed(map) && !x.Fogged(map) && map.reachability.CanReachColony(x), map, 1000, out var result))
            {
                return(result);
            }
            return(DropCellFinder.RandomDropSpot(map));
        }
Exemple #9
0
        public static IntVec3 RandomRaidDest(IntVec3 raidSpawnLoc, Map map)
        {
            List <ThingDef> allBedDefBestToWorst = RestUtility.AllBedDefBestToWorst;
            List <Building> list = new List <Building>(map.mapPawns.FreeColonistsAndPrisonersSpawnedCount);

            for (int i = 0; i < allBedDefBestToWorst.Count; i++)
            {
                foreach (Building item in map.listerBuildings.AllBuildingsColonistOfDef(allBedDefBestToWorst[i]))
                {
                    if (((Building_Bed)item).OwnersForReading.Any() && map.reachability.CanReach(raidSpawnLoc, item, PathEndMode.OnCell, TraverseMode.PassAllDestroyableThings, Danger.Deadly))
                    {
                        list.Add(item);
                    }
                }
            }
            if (list.TryRandomElement(out Building result))
            {
                return(result.Position);
            }
            IEnumerable <Building> source = map.listerBuildings.allBuildingsColonist.Where((Building b) => !b.def.building.ai_combatDangerous && !b.def.building.isInert && !b.def.building.ai_neverTrashThis);

            if (source.Any())
            {
                for (int j = 0; j < 500; j++)
                {
                    IntVec3 intVec = source.RandomElement().RandomAdjacentCell8Way();
                    if (intVec.Walkable(map) && map.reachability.CanReach(raidSpawnLoc, intVec, PathEndMode.OnCell, TraverseMode.PassAllDestroyableThings, Danger.Deadly))
                    {
                        return(intVec);
                    }
                }
            }
            if (map.mapPawns.FreeColonistsSpawned.Where((Pawn x) => map.reachability.CanReach(raidSpawnLoc, x, PathEndMode.OnCell, TraverseMode.PassAllDestroyableThings, Danger.Deadly)).TryRandomElement(out Pawn result2))
            {
                return(result2.Position);
            }
            if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => map.reachability.CanReach(raidSpawnLoc, x, PathEndMode.OnCell, TraverseMode.PassAllDestroyableThings, Danger.Deadly), map, 1000, out IntVec3 result3))
            {
                return(result3);
            }
            return(map.Center);
        }
Exemple #10
0
        // The delegated method makes transpiling this a PITA... so we're just going to overwrite it and ignore avoidWander.
        static bool Prefix(ref IntVec3 __result, Map map)
        {
            int numStand = 0;
            int numRoom  = 0;
            int numTouch = 0;

            if (!CellFinderLoose.TryGetRandomCellWith(delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    numStand++;
                    return(false);
                }

                /*if (c.GetTerrain(map).avoidWander)
                 * {
                 *  return false;
                 * }*/
                Room room = c.GetRoom(map);
                if (room == null)
                {
                    numRoom++;
                    return(false);
                }
                if (!room.TouchesMapEdge)
                {
                    numTouch++;
                    return(false);
                }
                return(true);
            }, map, 1000, out IntVec3 result))
            {
                result = CellFinder.RandomCell(map);
                Log.Warning("RandomAnimalSpawnCell_MapGen failed: numStand=" + numStand + ", numRoom=" + numRoom + ", numTouch=" + numTouch + ". PlayerStartSpot=" + MapGenerator.PlayerStartSpot + ". Returning " + result);
            }
            __result = result;
            return(false);
        }
        public void DoEffect(Map map)
        {
            List <Pawn> allPawnsSpawned = map.mapPawns.AllPawnsSpawned;

            for (int i = 0; i < allPawnsSpawned.Count; i++)
            {
                Pawn pawn = allPawnsSpawned[i];
                if (CanDamage(pawn, map))
                {
                    FireUtility.TryAttachFire(pawn, 0.4f);
                }
            }

            int count = Rand.Range(4, 7);

            for (int i = 0; i < count; i++)
            {
                if (CellFinderLoose.TryGetRandomCellWith(x => !x.Roofed(map), map, 5000, out IntVec3 result))
                {
                    FireUtility.TryStartFireIn(result, map, 0.7f);
                }
            }
        }
Exemple #12
0
        public static IntVec3 RandomAnimalSpawnCell_MapGen(Map map)
        {
            int numStand = 0;
            int numRoom  = 0;
            int numTouch = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    numStand++;
                    return(false);
                }
                if (c.GetTerrain(map).avoidWander)
                {
                    return(false);
                }
                Room room = c.GetRoom(map);
                if (room == null)
                {
                    numRoom++;
                    return(false);
                }
                if (!room.TouchesMapEdge)
                {
                    numTouch++;
                    return(false);
                }
                return(true);
            };

            if (!CellFinderLoose.TryGetRandomCellWith(validator, map, 1000, out IntVec3 result))
            {
                result = CellFinder.RandomCell(map);
                Log.Warning("RandomAnimalSpawnCell_MapGen failed: numStand=" + numStand + ", numRoom=" + numRoom + ", numTouch=" + numTouch + ". PlayerStartSpot=" + MapGenerator.PlayerStartSpot + ". Returning " + result);
            }
            return(result);
        }
        public override void Generate(Map map)
        {
            System.Random random = new System.Random();
            float         num    = Mathf.Min(10000f, (float)GenMath.RoundRandom(random.Next(10000, 12000)));
            ItemCollectionGenerator_Arcane itemCollectionGenerator_Arcane = new ItemCollectionGenerator_Arcane();
            ItemCollectionGeneratorParams  itemCollectionGeneratorParams  = default(ItemCollectionGeneratorParams);

            itemCollectionGeneratorParams.techLevel        = (TechLevel)5;
            itemCollectionGeneratorParams.totalMarketValue = num;
            itemCollectionGeneratorParams.count            = Rand.RangeInclusive(10, 20);
            if (num > 12000f)
            {
                itemCollectionGeneratorParams.count = 1;
            }
            itemCollectionGeneratorParams.validator = ((ThingDef t) => t.defName != "Silver");
            List <Thing> list = new List <Thing>();
            Thing        item = new Thing();

            //random = new System.Random();
            //int rnd = GenMath.RoundRandom(random.Next(0, 10));
            //if (rnd < 2)
            //{
            //    item.def = TorannMagicDefOf.BookOfInnerFire;
            //}
            //else if (rnd >= 2 && rnd < 4)
            //{
            //    item.def = TorannMagicDefOf.BookOfHeartOfFrost;
            //}
            //else if (rnd >= 4 && rnd < 6)
            //{
            //    item.def = TorannMagicDefOf.BookOfStormBorn;
            //}
            //else if (rnd >= 6 && rnd < 8)
            //{
            //    item.def = TorannMagicDefOf.BookOfArcanist;
            //}
            //else
            //{
            //    item.def = TorannMagicDefOf.BookOfValiant;
            //}
            //item.stackCount = 1;

            //list.Add(item);
            foreach (Thing current in list)
            {
                if (current.stackCount > current.def.stackLimit)
                {
                    current.stackCount = current.def.stackLimit;
                }
                IntVec3 intVec;
                if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => GenGrid.Standable(x, map) && GridsUtility.Fogged(x, map) && GridsUtility.GetRoom(x, map, (RegionType)6).CellCount >= 2, map, 1000, out intVec))
                {
                    GenSpawn.Spawn(current, intVec, map, Rot4.Random, false);
                }
            }


            list = itemCollectionGenerator_Arcane.Generate(itemCollectionGeneratorParams);
            foreach (Thing current in list)
            {
                if (current.stackCount > current.def.stackLimit)
                {
                    current.stackCount = current.def.stackLimit;
                }
                IntVec3 intVec;
                if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => GenGrid.Standable(x, map) && GridsUtility.Fogged(x, map) && GridsUtility.GetRoom(x, map, (RegionType)6).CellCount >= 2, map, 1000, out intVec))
                {
                    GenSpawn.Spawn(current, intVec, map, Rot4.North, false);
                }
            }
        }
Exemple #14
0
        public static bool TryFindRandomSpotJustOutsideColony(IntVec3 root, Map map, Pawn searcher, out IntVec3 result, Predicate <IntVec3> extraValidator = null)
        {
            bool desperate                = false;
            int  minColonyBuildingsLOS    = 0;
            int  walkRadius               = 0;
            int  walkRadiusMaxImpassable  = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    return(false);
                }
                Room room = c.GetRoom(map);
                if (!room.PsychologicallyOutdoors || !room.TouchesMapEdge)
                {
                    return(false);
                }
                if (room == null || room.CellCount < 60)
                {
                    return(false);
                }
                if (root.IsValid)
                {
                    TraverseParms traverseParams = (searcher != null) ? TraverseParms.For(searcher) : ((TraverseParms)TraverseMode.PassDoors);
                    if (!map.reachability.CanReach(root, c, PathEndMode.Touch, traverseParams))
                    {
                        return(false);
                    }
                }
                if (!desperate && !map.reachability.CanReachColony(c))
                {
                    return(false);
                }
                if (extraValidator != null && !extraValidator(c))
                {
                    return(false);
                }
                int num = 0;
                foreach (IntVec3 item in CellRect.CenteredOn(c, walkRadius))
                {
                    Room room2 = item.GetRoom(map);
                    if (room2 != room)
                    {
                        num++;
                        if (!desperate && room2 != null && room2.IsDoorway)
                        {
                            return(false);
                        }
                    }
                    if (num > walkRadiusMaxImpassable)
                    {
                        return(false);
                    }
                }
                if (minColonyBuildingsLOS > 0)
                {
                    int colonyBuildingsLOSFound = 0;
                    tmpBuildings.Clear();
                    RegionTraverser.BreadthFirstTraverse(c, map, (Region from, Region to) => true, delegate(Region reg)
                    {
                        Faction ofPlayer  = Faction.OfPlayer;
                        List <Thing> list = reg.ListerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial);
                        for (int l = 0; l < list.Count; l++)
                        {
                            Thing thing = list[l];
                            if (thing.Faction == ofPlayer && thing.Position.InHorDistOf(c, 16f) && GenSight.LineOfSight(thing.Position, c, map, skipFirstCell: true) && !tmpBuildings.Contains(thing))
                            {
                                tmpBuildings.Add(thing);
                                colonyBuildingsLOSFound++;
                                if (colonyBuildingsLOSFound >= minColonyBuildingsLOS)
                                {
                                    return(true);
                                }
                            }
                        }
                        return(false);
                    }, 12);
                    tmpBuildings.Clear();
                    if (colonyBuildingsLOSFound < minColonyBuildingsLOS)
                    {
                        return(false);
                    }
                }
                return(true);
            };
            IEnumerable <Building> source = map.listerBuildings.allBuildingsColonist.Where((Building b) => b.def.building.ai_chillDestination);

            for (int i = 0; i < 120; i++)
            {
                Building result2 = null;
                if (!source.TryRandomElement(out result2))
                {
                    break;
                }
                desperate  = (i > 60);
                walkRadius = 6 - i / 20;
                walkRadiusMaxImpassable = 6 - i / 20;
                minColonyBuildingsLOS   = 5 - i / 30;
                if (CellFinder.TryFindRandomCellNear(result2.Position, map, 10, validator, out result, 50))
                {
                    return(true);
                }
            }
            List <Building> allBuildingsColonist = map.listerBuildings.allBuildingsColonist;

            for (int j = 0; j < 120; j++)
            {
                Building result3 = null;
                if (!allBuildingsColonist.TryRandomElement(out result3))
                {
                    break;
                }
                desperate  = (j > 60);
                walkRadius = 6 - j / 20;
                walkRadiusMaxImpassable = 6 - j / 20;
                minColonyBuildingsLOS   = 4 - j / 30;
                if (CellFinder.TryFindRandomCellNear(result3.Position, map, 15, validator, out result, 50))
                {
                    return(true);
                }
            }
            for (int k = 0; k < 50; k++)
            {
                Pawn result4 = null;
                if (!map.mapPawns.FreeColonistsAndPrisonersSpawned.TryRandomElement(out result4))
                {
                    break;
                }
                desperate  = (k > 25);
                walkRadius = 3;
                walkRadiusMaxImpassable = 6;
                minColonyBuildingsLOS   = 0;
                if (CellFinder.TryFindRandomCellNear(result4.Position, map, 15, validator, out result, 50))
                {
                    return(true);
                }
            }
            desperate  = true;
            walkRadius = 3;
            walkRadiusMaxImpassable = 6;
            minColonyBuildingsLOS   = 0;
            if (CellFinderLoose.TryGetRandomCellWith(validator, map, 1000, out result))
            {
                return(true);
            }
            return(false);
        }
        public static bool TryFindRandomSpotJustOutsideColony(IntVec3 root, Map map, Pawn searcher, out IntVec3 result, Predicate <IntVec3> extraValidator = null)
        {
            bool desperate                = false;
            int  minColonyBuildingsLOS    = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    return(false);
                }
                Room room = c.GetRoom(map, RegionType.Set_Passable);
                if (room.PsychologicallyOutdoors && room.TouchesMapEdge)
                {
                    if (room != null && room.CellCount >= 25)
                    {
                        if (!desperate && !map.reachability.CanReachColony(c))
                        {
                            return(false);
                        }
                        if (extraValidator != null && !extraValidator(c))
                        {
                            return(false);
                        }
                        if (minColonyBuildingsLOS > 0)
                        {
                            int colonyBuildingsLOSFound = 0;
                            RCellFinder.tmpBuildings.Clear();
                            RegionTraverser.BreadthFirstTraverse(c, map, (Region from, Region to) => true, delegate(Region reg)
                            {
                                Faction ofPlayer  = Faction.OfPlayer;
                                List <Thing> list = reg.ListerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial);
                                for (int i = 0; i < list.Count; i++)
                                {
                                    Thing thing = list[i];
                                    if (thing.Faction == ofPlayer && thing.Position.InHorDistOf(c, 16f) && GenSight.LineOfSight(thing.Position, c, map, true, null, 0, 0) && !RCellFinder.tmpBuildings.Contains(thing))
                                    {
                                        RCellFinder.tmpBuildings.Add(thing);
                                        colonyBuildingsLOSFound++;
                                        if (colonyBuildingsLOSFound >= minColonyBuildingsLOS)
                                        {
                                            return(true);
                                        }
                                    }
                                }
                                return(false);
                            }, 12, RegionType.Set_Passable);
                            RCellFinder.tmpBuildings.Clear();
                            if (colonyBuildingsLOSFound < minColonyBuildingsLOS)
                            {
                                return(false);
                            }
                        }
                        if (root.IsValid)
                        {
                            TraverseParms traverseParams = (searcher == null) ? ((TraverseParms)TraverseMode.PassDoors) : TraverseParms.For(searcher, Danger.Deadly, TraverseMode.ByPawn, false);
                            if (!map.reachability.CanReach(root, c, PathEndMode.Touch, traverseParams))
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    return(false);
                }
                return(false);
            };
            int num = 0;

            while (num < 100)
            {
                Building building = null;
                if ((from b in map.listerBuildings.allBuildingsColonist
                     where b.def.designationCategory != DesignationCategoryDefOf.Structure && b.def.building.ai_chillDestination
                     select b).TryRandomElement <Building>(out building))
                {
                    if (num < 10)
                    {
                        minColonyBuildingsLOS = 4;
                    }
                    else if (num < 25)
                    {
                        minColonyBuildingsLOS = 3;
                    }
                    else if (num < 40)
                    {
                        minColonyBuildingsLOS = 2;
                    }
                    else
                    {
                        minColonyBuildingsLOS = 1;
                    }
                    int squareRadius = 10 + num / 5;
                    desperate = (num > 60);
                    if (CellFinder.TryFindRandomCellNear(building.Position, map, squareRadius, validator, out result))
                    {
                        return(true);
                    }
                    num++;
                    continue;
                }
                break;
            }
            int num2 = 0;

            while (num2 < 50)
            {
                Building building2 = null;
                if (((IEnumerable <Building>)map.listerBuildings.allBuildingsColonist).TryRandomElement <Building>(out building2))
                {
                    if (num2 < 10)
                    {
                        minColonyBuildingsLOS = 3;
                    }
                    else if (num2 < 20)
                    {
                        minColonyBuildingsLOS = 2;
                    }
                    else if (num2 < 30)
                    {
                        minColonyBuildingsLOS = 1;
                    }
                    else
                    {
                        minColonyBuildingsLOS = 0;
                    }
                    desperate = (num2 > 20);
                    if (CellFinder.TryFindRandomCellNear(building2.Position, map, 14, validator, out result))
                    {
                        return(true);
                    }
                    num2++;
                    continue;
                }
                break;
            }
            int num3 = 0;

            while (num3 < 100)
            {
                Pawn pawn = null;
                if (map.mapPawns.FreeColonistsAndPrisonersSpawned.TryRandomElement <Pawn>(out pawn))
                {
                    minColonyBuildingsLOS = 0;
                    desperate             = (num3 > 50);
                    if (CellFinder.TryFindRandomCellNear(pawn.Position, map, 14, validator, out result))
                    {
                        return(true);
                    }
                    num3++;
                    continue;
                }
                break;
            }
            desperate             = true;
            minColonyBuildingsLOS = 0;
            if (CellFinderLoose.TryGetRandomCellWith(validator, map, 1000, out result))
            {
                return(true);
            }
            return(false);
        }