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);
                }
            }
        }
Exemple #2
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 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);
            }
        }