Beispiel #1
0
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (Autotests_ColonyMaker.usedCells == null)
            {
                Autotests_ColonyMaker.usedCells = new BoolGrid(Autotests_ColonyMaker.Map);
            }
            else
            {
                Autotests_ColonyMaker.usedCells.ClearAndResizeTo(Autotests_ColonyMaker.Map);
            }
            Autotests_ColonyMaker.overRect = new CellRect(Autotests_ColonyMaker.Map.Center.x - 50, Autotests_ColonyMaker.Map.Center.z - 50, 100, 100);
            Autotests_ColonyMaker.DeleteAllSpawnedPawns();
            GenDebug.ClearArea(Autotests_ColonyMaker.overRect, Find.VisibleMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef current in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal
                         select k)
                {
                    CellRect cellRect;
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 3, out cellRect))
                    {
                        return;
                    }
                    cellRect = cellRect.ContractedBy(1);
                    foreach (IntVec3 current2 in cellRect)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(current2, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(current, null), cellRect.Cells.ElementAt(0), Autotests_ColonyMaker.Map);
                    IntVec3 intVec = cellRect.Cells.ElementAt(1);
                    Pawn    p      = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(current, null), intVec, Autotests_ColonyMaker.Map);
                    HealthUtility.DamageUntilDead(p);
                    Corpse       thing        = (Corpse)intVec.GetThingList(Find.VisibleMap).First((Thing t) => t is Corpse);
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (current.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(current.RaceProps.leatherDef, cellRect.Cells.ElementAt(2), Autotests_ColonyMaker.Map);
                    }
                    if (current.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(current.RaceProps.meatDef, cellRect.Cells.ElementAt(3), Autotests_ColonyMaker.Map);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ConduitGrid))
            {
                Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit);
                for (int i = Autotests_ColonyMaker.overRect.minX; i < Autotests_ColonyMaker.overRect.maxX; i++)
                {
                    for (int j = Autotests_ColonyMaker.overRect.minZ; j < Autotests_ColonyMaker.overRect.maxZ; j += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(i, 0, j));
                    }
                }
                for (int k2 = Autotests_ColonyMaker.overRect.minZ; k2 < Autotests_ColonyMaker.overRect.maxZ; k2++)
                {
                    for (int l = Autotests_ColonyMaker.overRect.minX; l < Autotests_ColonyMaker.overRect.maxX; l += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(l, 0, k2));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>
                {
                    ThingDefOf.SolarGenerator,
                    ThingDefOf.WindTurbine
                };
                for (int m = 0; m < 8; m++)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(list[m % list.Count]) == null)
                    {
                        Log.Message("Could not make solar generator.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Batteries))
            {
                for (int n = 0; n < 6; n++)
                {
                    Thing thing2 = Autotests_ColonyMaker.TryMakeBuilding(ThingDefOf.Battery);
                    if (thing2 == null)
                    {
                        Log.Message("Could not make battery.");
                        break;
                    }
                    ((Building_Battery)thing2).GetComp <CompPowerBattery>().AddEnergy(999999f);
                }
            }
            if (flags.Contains(ColonyMakerFlag.WorkTables))
            {
                IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs
                                                    where typeof(Building_WorkTable).IsAssignableFrom(def.thingClass)
                                                    select def;
                foreach (ThingDef current3 in enumerable)
                {
                    Thing thing3 = Autotests_ColonyMaker.TryMakeBuilding(current3);
                    if (thing3 == null)
                    {
                        Log.Message("Could not make worktable: " + current3.defName);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing3 as Building_WorkTable;
                    if (building_WorkTable != null)
                    {
                        foreach (RecipeDef current4 in building_WorkTable.def.AllRecipes)
                        {
                            building_WorkTable.billStack.AddBill(current4.MakeNewBill());
                        }
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.AllBuildings))
            {
                IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs
                                                     where def.category == ThingCategory.Building && def.designationCategory != null
                                                     select def;
                foreach (ThingDef current5 in enumerable2)
                {
                    if (current5 != ThingDefOf.PowerConduit)
                    {
                        if (Autotests_ColonyMaker.TryMakeBuilding(current5) == null)
                        {
                            Log.Message("Could not make building: " + current5.defName);
                            break;
                        }
                    }
                }
            }
            CellRect rect;

            if (!Autotests_ColonyMaker.TryGetFreeRect(33, 33, out rect))
            {
                Log.Error("Could not get wallable rect");
            }
            rect = rect.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs
                                            where DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item
                                            select def).ToList <ThingDef>();
                Autotests_ColonyMaker.FillWithItems(rect, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list2 = new List <ThingDef>();
                list2.Add(ThingDefOf.RawPotatoes);
                Autotests_ColonyMaker.FillWithItems(rect, list2);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 current6 in rect)
                {
                    GenSpawn.Spawn(ThingDefOf.FilthDirt, current6, Autotests_ColonyMaker.Map);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ItemsWall))
            {
                CellRect         cellRect2         = rect.ExpandedBy(1);
                Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall);
                designator_Build2.SetStuffDef(ThingDefOf.WoodLog);
                foreach (IntVec3 current7 in cellRect2.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(current7);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsMany))
            {
                Autotests_ColonyMaker.MakeColonists(15, Autotests_ColonyMaker.overRect.CenterCell);
            }
            else if (flags.Contains(ColonyMakerFlag.ColonistOne))
            {
                Autotests_ColonyMaker.MakeColonists(1, Autotests_ColonyMaker.overRect.CenterCell);
            }
            if (flags.Contains(ColonyMakerFlag.Fire))
            {
                CellRect cellRect3;
                if (!Autotests_ColonyMaker.TryGetFreeRect(30, 30, out cellRect3))
                {
                    Log.Error("Could not get free rect for fire.");
                }
                ThingDef plantTreeOak = ThingDefOf.PlantTreeOak;
                foreach (IntVec3 current8 in cellRect3)
                {
                    GenSpawn.Spawn(plantTreeOak, current8, Autotests_ColonyMaker.Map);
                }
                foreach (IntVec3 current9 in cellRect3)
                {
                    if (current9.x % 7 == 0 && current9.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(current9, Find.VisibleMap, 3.9f, DamageDefOf.Flame, null, -1, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsHungry))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsTired))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsInjured))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    DamageDef def = (from d in DefDatabase <DamageDef> .AllDefs
                                     where d.externalViolence
                                     select d).RandomElement <DamageDef>();
                    col.TakeDamage(new DamageInfo(def, 10, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef current10 in from d in DefDatabase <HediffDef> .AllDefs
                         where d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode)))
                         select d)
                {
                    Pawn     pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                    CellRect cellRect4;
                    Autotests_ColonyMaker.TryGetFreeRect(1, 1, out cellRect4);
                    GenSpawn.Spawn(pawn, cellRect4.CenterCell, Autotests_ColonyMaker.Map);
                    pawn.health.AddHediff(current10, null, null);
                }
            }
            if (flags.Contains(ColonyMakerFlag.Beds))
            {
                IEnumerable <ThingDef> source = from def in DefDatabase <ThingDef> .AllDefs
                                                where def.thingClass == typeof(Building_Bed)
                                                select def;
                int freeColonistsCount = Autotests_ColonyMaker.Map.mapPawns.FreeColonistsCount;
                for (int num = 0; num < freeColonistsCount; num++)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(source.RandomElement <ThingDef>()) == null)
                    {
                        Log.Message("Could not make beds.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Stockpiles))
            {
                Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources();
                foreach (StoragePriority priority in Enum.GetValues(typeof(StoragePriority)))
                {
                    CellRect cellRect5;
                    Autotests_ColonyMaker.TryGetFreeRect(7, 7, out cellRect5);
                    cellRect5 = cellRect5.ContractedBy(1);
                    designator_ZoneAddStockpile_Resources.DesignateMultiCell(cellRect5.Cells);
                    Zone_Stockpile zone_Stockpile = (Zone_Stockpile)Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect5.CenterCell);
                    zone_Stockpile.settings.Priority = priority;
                }
            }
            if (flags.Contains(ColonyMakerFlag.GrowingZones))
            {
                Zone_Growing dummyZone = new Zone_Growing(Autotests_ColonyMaker.Map.zoneManager);
                foreach (ThingDef current11 in from d in DefDatabase <ThingDef> .AllDefs
                         where d.plant != null && GenPlant.CanSowOnGrower(d, dummyZone)
                         select d)
                {
                    CellRect cellRect6;
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 6, out cellRect6))
                    {
                        Log.Error("Could not get growing zone rect.");
                    }
                    cellRect6 = cellRect6.ContractedBy(1);
                    foreach (IntVec3 current12 in cellRect6)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(current12, TerrainDefOf.Soil);
                    }
                    Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing();
                    designator_ZoneAdd_Growing.DesignateMultiCell(cellRect6.Cells);
                    Zone_Growing zone_Growing = (Zone_Growing)Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect6.CenterCell);
                    zone_Growing.SetPlantDefToGrow(current11);
                }
                dummyZone.Delete();
            }
            Autotests_ColonyMaker.ClearAllHomeArea();
            Autotests_ColonyMaker.FillWithHomeArea(Autotests_ColonyMaker.overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
        private static void CacheAccessibleThings(int nearTile)
        {
            if (nearTile == cachedAccessibleThingsForTile && RealTime.frameCount == cachedAccessibleThingsForFrame)
            {
                return;
            }
            cachedAccessibleThings.Clear();
            cachedPossiblyAccessibleThings.Clear();
            cachedMakeableItemDefs.Clear();
            WorldGrid  worldGrid = Find.WorldGrid;
            List <Map> maps      = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                if (!(worldGrid.ApproxDistanceInTiles(nearTile, maps[i].Tile) > 5f))
                {
                    ThingOwnerUtility.GetAllThingsRecursively(maps[i], tmpThings, allowUnreal: false);
                    cachedAccessibleThings.AddRange(tmpThings);
                }
            }
            List <Caravan> caravans = Find.WorldObjects.Caravans;

            for (int j = 0; j < caravans.Count; j++)
            {
                if (caravans[j].IsPlayerControlled && !(worldGrid.ApproxDistanceInTiles(nearTile, caravans[j].Tile) > 5f))
                {
                    ThingOwnerUtility.GetAllThingsRecursively(caravans[j], tmpThings, allowUnreal: false);
                    cachedAccessibleThings.AddRange(tmpThings);
                }
            }
            for (int k = 0; k < cachedAccessibleThings.Count; k++)
            {
                Thing thing = cachedAccessibleThings[k];
                cachedPossiblyAccessibleThings.Add(new ThingDefCount(thing.def, thing.stackCount));
                if (GenLeaving.CanBuildingLeaveResources(thing, DestroyMode.Deconstruct))
                {
                    List <ThingDefCountClass> list = thing.CostListAdjusted();
                    for (int l = 0; l < list.Count; l++)
                    {
                        int num = Mathf.RoundToInt((float)list[l].count * thing.def.resourcesFractionWhenDeconstructed);
                        if (num > 0)
                        {
                            cachedPossiblyAccessibleThings.Add(new ThingDefCount(list[l].thingDef, num));
                            cachedMakeableItemDefs.Add(list[l].thingDef);
                        }
                    }
                }
                Plant plant = thing as Plant;
                if (plant != null && (plant.HarvestableNow || plant.HarvestableSoon))
                {
                    int num2 = Mathf.RoundToInt(plant.def.plant.harvestYield * Find.Storyteller.difficultyValues.cropYieldFactor);
                    if (num2 > 0)
                    {
                        cachedPossiblyAccessibleThings.Add(new ThingDefCount(plant.def.plant.harvestedThingDef, num2));
                        cachedMakeableItemDefs.Add(plant.def.plant.harvestedThingDef);
                    }
                }
                if (!thing.def.butcherProducts.NullOrEmpty())
                {
                    for (int m = 0; m < thing.def.butcherProducts.Count; m++)
                    {
                        cachedPossiblyAccessibleThings.Add(thing.def.butcherProducts[m]);
                        cachedMakeableItemDefs.Add(thing.def.butcherProducts[m].thingDef);
                    }
                }
                Pawn pawn = thing as Pawn;
                if (pawn != null)
                {
                    if (pawn.RaceProps.meatDef != null)
                    {
                        int num3 = Mathf.RoundToInt(pawn.GetStatValue(StatDefOf.MeatAmount));
                        if (num3 > 0)
                        {
                            cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.meatDef, num3));
                            cachedMakeableItemDefs.Add(pawn.RaceProps.meatDef);
                        }
                    }
                    if (pawn.RaceProps.leatherDef != null)
                    {
                        int num4 = GenMath.RoundRandom(pawn.GetStatValue(StatDefOf.LeatherAmount));
                        if (num4 > 0)
                        {
                            cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.leatherDef, num4));
                            cachedMakeableItemDefs.Add(pawn.RaceProps.leatherDef);
                        }
                    }
                    if (!pawn.RaceProps.Humanlike)
                    {
                        PawnKindLifeStage curKindLifeStage = pawn.ageTracker.CurKindLifeStage;
                        if (curKindLifeStage.butcherBodyPart != null)
                        {
                            cachedPossiblyAccessibleThings.Add(new ThingDefCount(curKindLifeStage.butcherBodyPart.thing, 1));
                            cachedMakeableItemDefs.Add(curKindLifeStage.butcherBodyPart.thing);
                        }
                    }
                }
                if (thing.def.smeltable)
                {
                    List <ThingDefCountClass> list2 = thing.CostListAdjusted();
                    for (int n = 0; n < list2.Count; n++)
                    {
                        if (!list2[n].thingDef.intricate)
                        {
                            int num5 = Mathf.RoundToInt((float)list2[n].count * 0.25f);
                            if (num5 > 0)
                            {
                                cachedPossiblyAccessibleThings.Add(new ThingDefCount(list2[n].thingDef, num5));
                                cachedMakeableItemDefs.Add(list2[n].thingDef);
                            }
                        }
                    }
                }
                if (thing.def.smeltable && !thing.def.smeltProducts.NullOrEmpty())
                {
                    for (int num6 = 0; num6 < thing.def.smeltProducts.Count; num6++)
                    {
                        cachedPossiblyAccessibleThings.Add(thing.def.smeltProducts[num6]);
                        cachedMakeableItemDefs.Add(thing.def.smeltProducts[num6].thingDef);
                    }
                }
            }
            int num7 = 0;

            for (int num8 = 0; num8 < cachedAccessibleThings.Count; num8++)
            {
                Pawn pawn2 = cachedAccessibleThings[num8] as Pawn;
                if (pawn2 != null && pawn2.IsFreeColonist && !pawn2.Dead && !pawn2.Downed && pawn2.workSettings.WorkIsActive(WorkTypeDefOf.Crafting))
                {
                    num7++;
                }
            }
            if (num7 > 0)
            {
                tmpWorkTables.Clear();
                for (int num9 = 0; num9 < cachedAccessibleThings.Count; num9++)
                {
                    Building_WorkTable building_WorkTable = cachedAccessibleThings[num9] as Building_WorkTable;
                    if (building_WorkTable == null || !building_WorkTable.Spawned || !tmpWorkTables.Add(building_WorkTable.def))
                    {
                        continue;
                    }
                    List <RecipeDef> allRecipes = building_WorkTable.def.AllRecipes;
                    for (int num10 = 0; num10 < allRecipes.Count; num10++)
                    {
                        if (!allRecipes[num10].AvailableNow || !allRecipes[num10].AvailableOnNow(building_WorkTable) || !allRecipes[num10].products.Any() || allRecipes[num10].PotentiallyMissingIngredients(null, building_WorkTable.Map).Any())
                        {
                            continue;
                        }
                        ThingDef stuffDef = (allRecipes[num10].products[0].thingDef.MadeFromStuff ? GenStuff.DefaultStuffFor(allRecipes[num10].products[0].thingDef) : null);
                        float    num11    = allRecipes[num10].WorkAmountTotal(stuffDef);
                        if (num11 <= 0f)
                        {
                            continue;
                        }
                        int num12 = Mathf.FloorToInt((float)(num7 * 60000 * 5) * 0.09f / num11);
                        if (num12 > 0)
                        {
                            for (int num13 = 0; num13 < allRecipes[num10].products.Count; num13++)
                            {
                                cachedPossiblyAccessibleThings.Add(new ThingDefCount(allRecipes[num10].products[num13].thingDef, allRecipes[num10].products[num13].count * num12));
                                cachedMakeableItemDefs.Add(allRecipes[num10].products[num13].thingDef);
                            }
                        }
                    }
                }
            }
            cachedAccessibleThingsForTile  = nearTile;
            cachedAccessibleThingsForFrame = RealTime.frameCount;
        }
Beispiel #3
0
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (usedCells == null)
            {
                usedCells = new BoolGrid(Map);
            }
            else
            {
                usedCells.ClearAndResizeTo(Map);
            }
            IntVec3 center  = Map.Center;
            int     minX    = center.x - 50;
            IntVec3 center2 = Map.Center;

            overRect = new CellRect(minX, center2.z - 50, 100, 100);
            DeleteAllSpawnedPawns();
            GenDebug.ClearArea(overRect, Find.CurrentMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef item in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal
                         select k)
                {
                    if (!TryGetFreeRect(6, 3, out CellRect result))
                    {
                        return;
                    }
                    result = result.ContractedBy(1);
                    foreach (IntVec3 item2 in result)
                    {
                        Map.terrainGrid.SetTerrain(item2, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), result.Cells.ElementAt(0), Map);
                    IntVec3 intVec = result.Cells.ElementAt(1);
                    Pawn    p      = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), intVec, Map);
                    HealthUtility.DamageUntilDead(p);
                    Corpse       thing        = (Corpse)intVec.GetThingList(Find.CurrentMap).First((Thing t) => t is Corpse);
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (item.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(item.RaceProps.leatherDef, result.Cells.ElementAt(2), Map);
                    }
                    if (item.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(item.RaceProps.meatDef, result.Cells.ElementAt(3), Map);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ConduitGrid))
            {
                Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit);
                for (int i = overRect.minX; i < overRect.maxX; i++)
                {
                    for (int j = overRect.minZ; j < overRect.maxZ; j += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(i, 0, j));
                    }
                }
                for (int l = overRect.minZ; l < overRect.maxZ; l++)
                {
                    for (int m = overRect.minX; m < overRect.maxX; m += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(m, 0, l));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>();
                list.Add(ThingDefOf.SolarGenerator);
                list.Add(ThingDefOf.WindTurbine);
                List <ThingDef> list2 = list;
                for (int n = 0; n < 8; n++)
                {
                    if (TryMakeBuilding(list2[n % list2.Count]) == null)
                    {
                        Log.Message("Could not make solar generator.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Batteries))
            {
                for (int num = 0; num < 6; num++)
                {
                    Thing thing2 = TryMakeBuilding(ThingDefOf.Battery);
                    if (thing2 == null)
                    {
                        Log.Message("Could not make battery.");
                        break;
                    }
                    ((Building_Battery)thing2).GetComp <CompPowerBattery>().AddEnergy(999999f);
                }
            }
            if (flags.Contains(ColonyMakerFlag.WorkTables))
            {
                IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs
                                                    where typeof(Building_WorkTable).IsAssignableFrom(def.thingClass)
                                                    select def;
                foreach (ThingDef item3 in enumerable)
                {
                    Thing thing3 = TryMakeBuilding(item3);
                    if (thing3 == null)
                    {
                        Log.Message("Could not make worktable: " + item3.defName);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing3 as Building_WorkTable;
                    if (building_WorkTable != null)
                    {
                        foreach (RecipeDef allRecipe in building_WorkTable.def.AllRecipes)
                        {
                            building_WorkTable.billStack.AddBill(allRecipe.MakeNewBill());
                        }
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.AllBuildings))
            {
                IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs
                                                     where def.category == ThingCategory.Building && def.BuildableByPlayer
                                                     select def;
                foreach (ThingDef item4 in enumerable2)
                {
                    if (item4 != ThingDefOf.PowerConduit)
                    {
                        Thing thing4 = TryMakeBuilding(item4);
                        if (thing4 == null)
                        {
                            Log.Message("Could not make building: " + item4.defName);
                            break;
                        }
                    }
                }
            }
            if (!TryGetFreeRect(33, 33, out CellRect result2))
            {
                Log.Error("Could not get wallable rect");
            }
            result2 = result2.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs
                                            where DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item
                                            select def).ToList();
                FillWithItems(result2, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list3 = new List <ThingDef>();
                list3.Add(ThingDefOf.RawPotatoes);
                FillWithItems(result2, list3);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 item5 in result2)
                {
                    GenSpawn.Spawn(ThingDefOf.Filth_Dirt, item5, Map);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ItemsWall))
            {
                CellRect         cellRect          = result2.ExpandedBy(1);
                Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall);
                designator_Build2.SetStuffDef(ThingDefOf.WoodLog);
                foreach (IntVec3 edgeCell in cellRect.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(edgeCell);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsMany))
            {
                MakeColonists(15, overRect.CenterCell);
            }
            else if (flags.Contains(ColonyMakerFlag.ColonistOne))
            {
                MakeColonists(1, overRect.CenterCell);
            }
            if (flags.Contains(ColonyMakerFlag.Fire))
            {
                if (!TryGetFreeRect(30, 30, out CellRect result3))
                {
                    Log.Error("Could not get free rect for fire.");
                }
                ThingDef plant_TreeOak = ThingDefOf.Plant_TreeOak;
                foreach (IntVec3 item6 in result3)
                {
                    GenSpawn.Spawn(plant_TreeOak, item6, Map);
                }
                foreach (IntVec3 item7 in result3)
                {
                    IntVec3 current9 = item7;
                    if (current9.x % 7 == 0 && current9.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(current9, Find.CurrentMap, 3.9f, DamageDefOf.Flame, null);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsHungry))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsTired))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsInjured))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    DamageDef def2 = (from d in DefDatabase <DamageDef> .AllDefs
                                      where d.ExternalViolenceFor(null)
                                      select d).RandomElement();
                    col.TakeDamage(new DamageInfo(def2, 10f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef item8 in from d in DefDatabase <HediffDef> .AllDefs
                         where d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode)))
                         select d)
                {
                    Pawn pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                    TryGetFreeRect(1, 1, out CellRect result4);
                    GenSpawn.Spawn(pawn, result4.CenterCell, Map);
                    pawn.health.AddHediff(item8);
                }
            }
            if (flags.Contains(ColonyMakerFlag.Beds))
            {
                IEnumerable <ThingDef> source = from def in DefDatabase <ThingDef> .AllDefs
                                                where def.thingClass == typeof(Building_Bed)
                                                select def;
                int freeColonistsCount = Map.mapPawns.FreeColonistsCount;
                for (int num2 = 0; num2 < freeColonistsCount; num2++)
                {
                    if (TryMakeBuilding(source.RandomElement()) == null)
                    {
                        Log.Message("Could not make beds.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Stockpiles))
            {
                Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources();
                IEnumerator enumerator11 = Enum.GetValues(typeof(StoragePriority)).GetEnumerator();
                try
                {
                    while (enumerator11.MoveNext())
                    {
                        StoragePriority priority = (StoragePriority)enumerator11.Current;
                        TryGetFreeRect(7, 7, out CellRect result5);
                        result5 = result5.ContractedBy(1);
                        designator_ZoneAddStockpile_Resources.DesignateMultiCell(result5.Cells);
                        Zone_Stockpile zone_Stockpile = (Zone_Stockpile)Map.zoneManager.ZoneAt(result5.CenterCell);
                        zone_Stockpile.settings.Priority = priority;
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator11 as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.GrowingZones))
            {
                Zone_Growing dummyZone = new Zone_Growing(Map.zoneManager);
                Map.zoneManager.RegisterZone(dummyZone);
                foreach (ThingDef item9 in from d in DefDatabase <ThingDef> .AllDefs
                         where d.plant != null && PlantUtility.CanSowOnGrower(d, dummyZone)
                         select d)
                {
                    if (!TryGetFreeRect(6, 6, out CellRect result6))
                    {
                        Log.Error("Could not get growing zone rect.");
                    }
                    result6 = result6.ContractedBy(1);
                    foreach (IntVec3 item10 in result6)
                    {
                        Map.terrainGrid.SetTerrain(item10, TerrainDefOf.Soil);
                    }
                    Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing();
                    designator_ZoneAdd_Growing.DesignateMultiCell(result6.Cells);
                    (Map.zoneManager.ZoneAt(result6.CenterCell) as Zone_Growing)?.SetPlantDefToGrow(item9);
                }
                dummyZone.Delete();
            }
            ClearAllHomeArea();
            FillWithHomeArea(overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
 private static void CacheAccessibleThings(int nearTile)
 {
     if (nearTile != PlayerItemAccessibilityUtility.cachedAccessibleThingsForTile || RealTime.frameCount != PlayerItemAccessibilityUtility.cachedAccessibleThingsForFrame)
     {
         PlayerItemAccessibilityUtility.cachedAccessibleThings.Clear();
         PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Clear();
         WorldGrid  worldGrid = Find.WorldGrid;
         List <Map> maps      = Find.Maps;
         for (int i = 0; i < maps.Count; i++)
         {
             float num = worldGrid.ApproxDistanceInTiles(nearTile, maps[i].Tile);
             if (num <= 5f)
             {
                 ThingOwnerUtility.GetAllThingsRecursively(maps[i], PlayerItemAccessibilityUtility.tmpThings, false, null);
                 PlayerItemAccessibilityUtility.cachedAccessibleThings.AddRange(PlayerItemAccessibilityUtility.tmpThings);
             }
         }
         List <Caravan> caravans = Find.WorldObjects.Caravans;
         for (int j = 0; j < caravans.Count; j++)
         {
             if (caravans[j].IsPlayerControlled)
             {
                 float num2 = worldGrid.ApproxDistanceInTiles(nearTile, caravans[j].Tile);
                 if (num2 <= 5f)
                 {
                     ThingOwnerUtility.GetAllThingsRecursively(caravans[j], PlayerItemAccessibilityUtility.tmpThings, false, null);
                     PlayerItemAccessibilityUtility.cachedAccessibleThings.AddRange(PlayerItemAccessibilityUtility.tmpThings);
                 }
             }
         }
         for (int k = 0; k < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; k++)
         {
             Thing thing = PlayerItemAccessibilityUtility.cachedAccessibleThings[k];
             PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(thing.def, thing.stackCount));
             if (GenLeaving.CanBuildingLeaveResources(thing, DestroyMode.Deconstruct))
             {
                 List <ThingDefCountClass> list = thing.CostListAdjusted();
                 for (int l = 0; l < list.Count; l++)
                 {
                     int num3 = Mathf.RoundToInt((float)list[l].count * thing.def.resourcesFractionWhenDeconstructed);
                     if (num3 > 0)
                     {
                         PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(list[l].thingDef, num3));
                     }
                 }
             }
             Plant plant = thing as Plant;
             if (plant != null)
             {
                 if (plant.HarvestableNow || plant.HarvestableSoon)
                 {
                     int num4 = Mathf.RoundToInt(plant.def.plant.harvestYield * Find.Storyteller.difficulty.cropYieldFactor);
                     if (num4 > 0)
                     {
                         PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(plant.def.plant.harvestedThingDef, num4));
                     }
                 }
             }
             if (!thing.def.butcherProducts.NullOrEmpty <ThingDefCountClass>())
             {
                 for (int m = 0; m < thing.def.butcherProducts.Count; m++)
                 {
                     PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(thing.def.butcherProducts[m]);
                 }
             }
             Pawn pawn = thing as Pawn;
             if (pawn != null)
             {
                 if (pawn.RaceProps.meatDef != null)
                 {
                     int num5 = Mathf.RoundToInt(pawn.GetStatValue(StatDefOf.MeatAmount, true));
                     if (num5 > 0)
                     {
                         PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.meatDef, num5));
                     }
                 }
                 if (pawn.RaceProps.leatherDef != null)
                 {
                     int num6 = GenMath.RoundRandom(pawn.GetStatValue(StatDefOf.LeatherAmount, true));
                     if (num6 > 0)
                     {
                         PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.leatherDef, num6));
                     }
                 }
                 if (!pawn.RaceProps.Humanlike)
                 {
                     PawnKindLifeStage curKindLifeStage = pawn.ageTracker.CurKindLifeStage;
                     if (curKindLifeStage.butcherBodyPart != null)
                     {
                         PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(curKindLifeStage.butcherBodyPart.thing, 1));
                     }
                 }
             }
             if (thing.def.smeltable)
             {
                 List <ThingDefCountClass> list2 = thing.CostListAdjusted();
                 for (int n = 0; n < list2.Count; n++)
                 {
                     if (!list2[n].thingDef.intricate)
                     {
                         int num7 = Mathf.RoundToInt((float)list2[n].count * 0.25f);
                         if (num7 > 0)
                         {
                             PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(list2[n].thingDef, num7));
                         }
                     }
                 }
             }
             if (thing.def.smeltable && !thing.def.smeltProducts.NullOrEmpty <ThingDefCountClass>())
             {
                 for (int num8 = 0; num8 < thing.def.smeltProducts.Count; num8++)
                 {
                     PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(thing.def.smeltProducts[num8]);
                 }
             }
         }
         int num9 = 0;
         for (int num10 = 0; num10 < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; num10++)
         {
             Pawn pawn2 = PlayerItemAccessibilityUtility.cachedAccessibleThings[num10] as Pawn;
             if (pawn2 != null && pawn2.IsFreeColonist && !pawn2.Dead && !pawn2.Downed && pawn2.workSettings.WorkIsActive(WorkTypeDefOf.Crafting))
             {
                 num9++;
             }
         }
         if (num9 > 0)
         {
             PlayerItemAccessibilityUtility.tmpWorkTables.Clear();
             for (int num11 = 0; num11 < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; num11++)
             {
                 Building_WorkTable building_WorkTable = PlayerItemAccessibilityUtility.cachedAccessibleThings[num11] as Building_WorkTable;
                 if (building_WorkTable != null && building_WorkTable.Spawned && PlayerItemAccessibilityUtility.tmpWorkTables.Add(building_WorkTable.def))
                 {
                     List <RecipeDef> allRecipes = building_WorkTable.def.AllRecipes;
                     for (int num12 = 0; num12 < allRecipes.Count; num12++)
                     {
                         if (allRecipes[num12].AvailableNow)
                         {
                             if (allRecipes[num12].products.Any <ThingDefCountClass>())
                             {
                                 if (!allRecipes[num12].PotentiallyMissingIngredients(null, building_WorkTable.Map).Any <ThingDef>())
                                 {
                                     ThingDef stuffDef = (!allRecipes[num12].products[0].thingDef.MadeFromStuff) ? null : GenStuff.DefaultStuffFor(allRecipes[num12].products[0].thingDef);
                                     float    num13    = allRecipes[num12].WorkAmountTotal(stuffDef);
                                     if (num13 > 0f)
                                     {
                                         int num14 = Mathf.FloorToInt((float)(num9 * 60000 * 5) * 0.09f / num13);
                                         if (num14 > 0)
                                         {
                                             for (int num15 = 0; num15 < allRecipes[num12].products.Count; num15++)
                                             {
                                                 PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(allRecipes[num12].products[num15].thingDef, allRecipes[num12].products[num15].count * num14));
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         PlayerItemAccessibilityUtility.cachedAccessibleThingsForTile  = nearTile;
         PlayerItemAccessibilityUtility.cachedAccessibleThingsForFrame = RealTime.frameCount;
     }
 }