private void GenerateRoad(ResolveParams rp, Map map)
        {
            CGO.currentGenStepMoreInfo = "Placing terrain";
            int x = rp.rect.Corners.ElementAt(2).x,
                y = rp.rect.Corners.ElementAt(2).z;

            for (int i = 0; i < CGO.grid.Length; i++)
            {
                for (int j = 0; j < CGO.grid[i].Length; j++)
                {
                    IntVec3 cell = new IntVec3(x + i, 0, y - j);
                    if (cell.InBounds(map))
                    {
                        switch (CGO.grid[i][j].Type)
                        {
                        case CellType.ROAD:
                            SpawnConduit(cell, BaseGen.globalSettings.map);
                            GenUtils.GenerateTerrainAt(map, cell, CGO.settlementLayoutDef.roadDef);
                            break;

                        case CellType.MAINROAD:
                            SpawnConduit(cell, BaseGen.globalSettings.map);
                            GenUtils.GenerateTerrainAt(map, cell, CGO.preRoadTypes?.Count > 0 ? CGO.preRoadTypes.RandomElement() : CGO.settlementLayoutDef.mainRoadDef);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            BaseGen.symbolStack.Push("kcsg_addfields", rp, null);
        }
Esempio n. 2
0
        private static void QuickspawnStructure()
        {
            if (DefDatabase <StructureLayoutDef> .AllDefs.Count() > 0)
            {
                List <DebugMenuOption> list = new List <DebugMenuOption>();
                foreach (StructureLayoutDef localDef2 in DefDatabase <StructureLayoutDef> .AllDefs)
                {
                    StructureLayoutDef localDef = localDef2;
                    list.Add(new DebugMenuOption(localDef.defName, DebugMenuOptionMode.Tool, delegate()
                    {
                        if (UI.MouseCell().InBounds(Find.CurrentMap))
                        {
                            RectUtils.HeightWidthFromLayout(localDef, out int h, out int w);
                            CellRect cellRect = CellRect.CenteredOn(UI.MouseCell(), w, h);

                            foreach (List <string> item in localDef.layouts)
                            {
                                GenUtils.GenerateRoomFromLayout(item, cellRect, Find.CurrentMap, localDef);
                            }
                        }
                    }));
                }
                Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
            }
        }
        public override void Resolve(ResolveParams rp)
        {
            CGO.currentGenStep = "Generating single structure";

            Map map = BaseGen.globalSettings.map;
            StructureLayoutDef rld = CGO.structureLayoutDef;

            foreach (List <string> item in rld.layouts)
            {
                GenUtils.GenerateRoomFromLayout(item, rp.rect, map, rld);
            }

            GenUtils.EnsureBatteriesConnectedAndMakeSense(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, KThingDefOf.KCSG_PowerConduit);
            GenUtils.EnsurePowerUsersConnected(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, KThingDefOf.KCSG_PowerConduit);
            GenUtils.EnsureGeneratorsConnectedAndMakeSense(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, KThingDefOf.KCSG_PowerConduit);
        }
        public override void Resolve(ResolveParams rp)
        {
            CGO.currentGenStep = "Generating settlement";

            Map map = BaseGen.globalSettings.map;

            rp.faction = rp.faction ?? Find.FactionManager.RandomEnemyFaction(false, false, true, TechLevel.Undefined);

            if (CGO.useStructureLayout)
            {
                this.HandleRuin(rp);
                this.AddHostilePawnGroup(rp.faction, map, rp);

                BaseGen.symbolStack.Push("kcsg_roomsgenfromstructure", rp, null);

                if (CGO.factionSettlement.preGenClear)
                {
                    GenUtils.PreClean(map, rp.rect, CGO.structureLayoutDef.roofGrid, CGO.factionSettlement.fullClear);
                }
            }
            else
            {
                this.HandleRuin(rp);
                this.AddHostilePawnGroup(rp.faction, map, rp);

                if (CGO.settlementLayoutDef.vanillaLikeDefense)
                {
                    int           dWidth = (Rand.Bool ? 2 : 4);
                    ResolveParams rp3    = rp;
                    rp3.rect                      = new CellRect(rp.rect.minX - dWidth, rp.rect.minZ - dWidth, rp.rect.Width + (dWidth * 2), rp.rect.Height + (dWidth * 2));
                    rp3.faction                   = rp.faction;
                    rp3.edgeDefenseWidth          = dWidth;
                    rp3.edgeThingMustReachMapEdge = new bool?(rp.edgeThingMustReachMapEdge ?? true);
                    BaseGen.symbolStack.Push("edgeDefense", rp3, null);
                }

                this.GenerateRooms(CGO.settlementLayoutDef, map, rp);

                if (CGO.factionSettlement.preGenClear)
                {
                    GenUtils.PreClean(map, rp.rect, CGO.factionSettlement.fullClear);
                }
            }
        }
Esempio n. 5
0
        public override void Generate(Map map, GenStepParams parms)
        {
            StructureLayoutDef structureLayoutDef = structureLayoutDefs.RandomElement();

            RectUtils.HeightWidthFromLayout(structureLayoutDef, out int h, out int w);
            CellRect cellRect = CellRect.CenteredOn(map.Center, w, h);

            GenUtils.PreClean(map, cellRect, structureLayoutDef.roofGrid, fullClear);

            foreach (List <string> item in structureLayoutDef.layouts)
            {
                GenUtils.GenerateRoomFromLayout(item, cellRect, map, structureLayoutDef);
            }

            if (shouldRuin)
            {
                CGO.factionSettlement = new CustomGenOption
                {
                    filthTypes    = filthTypes,
                    scatterThings = scatterThings,
                    scatterChance = scatterChance
                };

                ResolveParams rp = new ResolveParams
                {
                    faction = map.ParentFaction,
                    rect    = cellRect
                };
                foreach (string resolver in ruinSymbolResolvers)
                {
                    if (!(ruinSymbolResolvers.Contains("kcsg_randomroofremoval") && resolver == "kcsg_scatterstuffaround"))
                    {
                        BaseGen.symbolStack.Push(resolver, rp, null);
                    }
                }
            }

            // Flood refog
            if (map.mapPawns.FreeColonistsSpawned.Count > 0)
            {
                FloodFillerFog.DebugRefogMap(map);
            }
        }
        public override void Resolve(ResolveParams rp)
        {
            CGO.currentGenStep = "Generating structures";

            foreach (KeyValuePair <CustomVector, StructureLayoutDef> keyValue in CGO.vectStruct)
            {
                CGO.currentGenStepMoreInfo = "Generating " + keyValue.Value.defName;

                RectUtils.HeightWidthFromLayout(keyValue.Value, out int height, out int width);
                IntVec3 limitMin = new IntVec3
                {
                    x = CGO.offset.x + (int)keyValue.Key.X,
                    z = CGO.offset.z - (int)keyValue.Key.Y - height + 1
                };
                CellRect rect = new CellRect(limitMin.x, limitMin.z, width, height);

                foreach (List <string> item in keyValue.Value.layouts)
                {
                    GenUtils.GenerateRoomFromLayout(item, rect, BaseGen.globalSettings.map, keyValue.Value);
                }

                if (keyValue.Value.isStorage)
                {
                    ResolveParams rstock = rp;
                    rstock.rect = new CellRect(limitMin.x, limitMin.z, width, height);
                    BaseGen.symbolStack.Push("kcsg_storagezone", rstock, null);
                }
            }

            if (CGO.settlementLayoutDef.addLandingPad && ModLister.RoyaltyInstalled)
            {
                if (rp.rect.TryFindRandomInnerRect(new IntVec2(9, 9), out CellRect rect, null))
                {
                    CGO.currentGenStepMoreInfo = "Generating landing pad";
                    ResolveParams resolveParams = rp;
                    resolveParams.rect = rect;
                    BaseGen.symbolStack.Push("landingPad", resolveParams, null);
                    BaseGen.globalSettings.basePart_landingPadsResolved++;
                }
            }

            BaseGen.symbolStack.Push("kcsg_gridsecondpass", rp, null);
        }
        public override void PostMapGenerate(Map map)
        {
            if (Find.TickManager.TicksGame > 5f || chooseFrom.Count <= 0 || PrepareCarefully_Util.pcScenariosSave.Count <= 0)
            {
                return;
            }

            StructureLayoutDef structureLayoutDef;

            if (ModLister.GetActiveModWithIdentifier("EdB.PrepareCarefully") != null)
            {
                structureLayoutDef = PrepareCarefully_Util.pcScenariosSave.First().Key;
                nearMapCenter      = PrepareCarefully_Util.pcScenariosSave.First().Value;
            }
            else
            {
                structureLayoutDef = chooseFrom.RandomElement();
            }

            RectUtils.HeightWidthFromLayout(structureLayoutDef, out int h, out int w);
            CellRect cellRect = this.CreateCellRect(map, h, w);

            if (preGenClear)
            {
                GenUtils.PreClean(map, cellRect, structureLayoutDef.roofGrid, fullClear);
            }

            foreach (List <string> item in structureLayoutDef.layouts)
            {
                GenUtils.GenerateRoomFromLayout(item, cellRect, map, structureLayoutDef, spawnConduits);
            }

            if (spawnTheStartingPawn && Find.GameInitData != null)
            {
                List <List <Thing> > thingsGroups = new List <List <Thing> >();
                foreach (Pawn startingAndOptionalPawn in Find.GameInitData.startingAndOptionalPawns)
                {
                    thingsGroups.Add(new List <Thing>()
                    {
                        startingAndOptionalPawn
                    });
                }

                List <Thing> thingList = new List <Thing>();
                foreach (ScenPart allPart in Find.Scenario.AllParts)
                {
                    thingList.AddRange(allPart.PlayerStartingThings());
                }

                int index = 0;
                foreach (Thing thing in thingList)
                {
                    if (thing.def.CanHaveFaction)
                    {
                        thing.SetFactionDirect(Faction.OfPlayer);
                    }

                    thingsGroups[index].Add(thing);
                    ++index;
                    if (index >= thingsGroups.Count)
                    {
                        index = 0;
                    }
                }

                IntVec3 center = map.Center;
                Pos     offset = structureLayoutDef.spawnAtPos.RandomElement();
                center.x += offset.x;
                center.y += offset.y;
                KLog.Message($"Spawning pawns and stuff at {center}");
                this.DropThingGroupsAt(center, map, thingsGroups, instaDrop: (Find.GameInitData.QuickStarted || this.method != PlayerPawnsArriveMethod.DropPods), leaveSlag: true, allowFogged: false);
            }

            if (map.mapPawns.FreeColonistsSpawned.Count > 0)
            {
                FloodFillerFog.DebugRefogMap(map);
            }
        }