Exemplo n.º 1
0
        public override void ProcessInput(Event ev)
        {
            if (!base.CheckCanInteract())
            {
                return;
            }
            if (Designator_ExportToXmlFromArea.selectedArea != null)
            {
                base.ProcessInput(ev);
            }

            Designator_ExportToXmlFromArea.MakeAllowedAreaListFloatMenu(delegate(Area a)
            {
                Log.Clear();

                KCSG_Utilities.EdgeFromArea(a.ActiveCells.ToList(), out int height, out int width);
                List <IntVec3> cellExport = KCSG_Utilities.AreaToSquare(a, height, width);

                List <string> justCreated = new List <string>();
                Dictionary <IntVec3, List <Thing> > pairsCellThingList = new Dictionary <IntVec3, List <Thing> >();

                KCSG_Utilities.FillCellThingsList(cellExport, base.Map, pairsCellThingList);

                KCSG_Utilities.CreateSymbolIfNeeded(cellExport, base.Map, justCreated, pairsCellThingList, a);

                KCSG_Utilities.CreateStructureDef(cellExport, base.Map, KCSG_Utilities.FillpairsSymbolLabel(), pairsCellThingList, a);

                Log.TryOpenLogWindow();
            }, false, true, base.Map);
        }
        public override void Resolve(ResolveParams rp)
        {
            Map map = BaseGen.globalSettings.map;

            StructureLayoutDef rld = DefDatabase <StructureLayoutDef> .GetNamed(FactionSettlement.temp);

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

            ThingDef conduit;

            if (LoadedModManager.RunningMods.ToList().FindAll(m => m.Name == "Subsurface Conduit").Count > 0)
            {
                conduit = DefDatabase <ThingDef> .AllDefsListForReading.FindAll(d => d.defName == "MUR_SubsurfaceConduit").First();
            }
            else
            {
                conduit = ThingDefOf.PowerConduit;
            }

            KCSG_Utilities.EnsureBatteriesConnectedAndMakeSense(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, conduit);
            KCSG_Utilities.EnsurePowerUsersConnected(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, conduit);
            KCSG_Utilities.EnsureGeneratorsConnectedAndMakeSense(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, conduit);
        }
        public override void PostMapGenerate(Map map)
        {
            if (Find.TickManager.TicksGame > 5f)
            {
                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();
            }

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

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

            FloodFillerFog.DebugRefogMap(map);
        }
Exemplo n.º 4
0
        public override void PostMapGenerate(Map map)
        {
            if (Find.TickManager.TicksGame > 5f)
            {
                return;
            }

            StructureLayoutDef structureLayoutDef = chooseFrom.RandomElement();

            if (VFECore.VFEGlobal.settings.enableLog)
            {
                Log.Message("ScenPart_AddStartingStructure - Structure choosen: " + structureLayoutDef.defName);
            }

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

            int count = 0;

            foreach (List <string> item in structureLayoutDef.layouts)
            {
                KCSG_Utilities.GenerateRoomFromLayout(item, cellRect, map, structureLayoutDef);
                if (VFECore.VFEGlobal.settings.enableLog)
                {
                    Log.Message("ScenPart_AddStartingStructure - Layout " + count++.ToString() + " generation - PASS");
                }
            }

            if (this.unfogBuilding)
            {
                this.UnfogBuildingsInRect(map, cellRect);
            }
        }
 private static void QuickTestStructureSize()
 {
     foreach (StructureLayoutDef sld in DefDatabase <StructureLayoutDef> .AllDefsListForReading)
     {
         int h, w;
         KCSG_Utilities.HeightWidthFromLayout(sld, out h, out w);
         Log.Message("Layout " + sld.defName + " Height: " + h + " Width: " + w);
     }
 }
 public Dialog_ExportWindow(Map map, List <IntVec3> cells)
 {
     this.map   = map;
     this.cells = cells;
     KCSG_Utilities.FillCellThingsList(cells, this.map, this.pairsCellThingList);
     // Window settings
     this.forcePause              = true;
     this.doCloseX                = false;
     this.doCloseButton           = false;
     this.closeOnClickedOutside   = false;
     this.absorbInputAroundWindow = true;
 }
Exemplo n.º 7
0
        public override void Resolve(ResolveParams rp)
        {
            Map map = BaseGen.globalSettings.map;
            SettlementLayoutDef lDef      = FactionSettlement.temp;
            List <CellRect>     gridRects = FactionSettlement.tempRectList;

            if (VFECore.VFEGlobal.settings.enableLog)
            {
                Log.Message("KCSG_RoomGen generating " + lDef.defName.ToString());
            }

            int count = 0;

            foreach (string str in lDef.roomLayout)
            {
                if (str != ".")
                {
                    StructureLayoutDef rld = DefDatabase <StructureLayoutDef> .GetNamed(str);

                    KCSG_Utilities.FillCellThingsList(gridRects[count].Cells.ToList(), map, pairsCellThingList);

                    foreach (List <String> item in rld.layouts)
                    {
                        KCSG_Utilities.GenerateRoomFromLayout(item, gridRects[count], map, rld);
                    }

                    if (rld.isStockpile)
                    {
                        KCSG_Utilities.FillStockpileRoom(rld, gridRects[count], map);
                    }
                }
                count++;
            }

            ThingDef conduit;

            if (LoadedModManager.RunningMods.ToList().FindAll(m => m.Name == "Subsurface Conduit").Count > 0)
            {
                conduit = DefDatabase <ThingDef> .AllDefsListForReading.FindAll(d => d.defName == "MUR_SubsurfaceConduit").First();
            }
            else
            {
                conduit = ThingDefOf.PowerConduit;
            }

            KCSG_Utilities.EnsureBatteriesConnectedAndMakeSense(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, conduit);
            KCSG_Utilities.EnsurePowerUsersConnected(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, conduit);
            KCSG_Utilities.EnsureGeneratorsConnectedAndMakeSense(map, tmpThings, tmpPowerNetPredicateResults, tmpCells, conduit);
        }
 private void CreateLayoutSymbols()
 {
     this.symbols.Clear();
     // Base
     this.symbols    = KCSG_Utilities.CreateSymbolIfNeeded(this.cells, this.map, symbolPrefix, pairsCellThingList);
     this.structureL = KCSG_Utilities.CreateStructureDef(this.cells, this.map, symbolPrefix, KCSG_Utilities.FillpairsSymbolLabel(), pairsCellThingList);
     // Defname change
     structureL.SetElementValue("defName", defname);
     // Royalty change
     if (this.needRoyalty)
     {
         if (structureL.Element("requireRoyalty") == null)
         {
             structureL.Add(new XElement("requireRoyalty", true));
         }
     }
     else
     {
         if (structureL.Element("requireRoyalty") != null)
         {
             structureL.Element("requireRoyalty").Remove();
         }
     }
     // isStorage change
     if (this.isStorage)
     {
         if (structureL.Element("isStorage") == null)
         {
             structureL.Add(new XElement("isStorage", true));
         }
     }
     else
     {
         if (structureL.Element("isStorage") != null)
         {
             structureL.Element("isStorage").Remove();
         }
     }
     // Tags changes
     if (tags.Count > 0)
     {
         XElement temp1 = new XElement("tags");
         foreach (var item in this.tags)
         {
             temp1.Add(new XElement("li", item));
         }
         structureL.Add(temp1);
     }
 }
Exemplo n.º 9
0
        public override void DesignateMultiCell(IEnumerable <IntVec3> cells)
        {
            Log.Clear();

            List <string> justCreated = new List <string>();
            Dictionary <IntVec3, List <Thing> > pairsCellThingList = new Dictionary <IntVec3, List <Thing> >();

            KCSG_Utilities.FillCellThingsList(cells.ToList(), base.Map, pairsCellThingList);

            KCSG_Utilities.CreateSymbolIfNeeded(cells.ToList(), base.Map, justCreated, pairsCellThingList);

            KCSG_Utilities.CreateStructureDef(cells.ToList(), base.Map, KCSG_Utilities.FillpairsSymbolLabel(), pairsCellThingList);

            Log.TryOpenLogWindow();
        }
Exemplo n.º 10
0
        public override void Generate(Map map, GenStepParams parms)
        {
            StructureLayoutDef structureLayoutDef = structureLayoutDefs.RandomElement();

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

            int count = 1;

            foreach (List <String> item in structureLayoutDef.layouts)
            {
                KCSG_Utilities.GenerateRoomFromLayout(item, cellRect, map, structureLayoutDef);
                if (VFECore.VFEGlobal.settings.enableLog)
                {
                    Log.Message("Layout " + count.ToString() + " generation - PASS");
                }
                count++;
            }
        }
Exemplo n.º 11
0
        public override void ProcessInput(Event ev)
        {
            if (!base.CheckCanInteract())
            {
                return;
            }
            if (Designator_ExportToXmlFromArea.selectedArea != null)
            {
                base.ProcessInput(ev);
            }

            Designator_ExportToXmlFromArea.MakeAllowedAreaListFloatMenu(delegate(Area a)
            {
                KCSG_Utilities.EdgeFromArea(a.ActiveCells.ToList(), out int height, out int width);
                List <IntVec3> cellExport = KCSG_Utilities.AreaToSquare(a, height, width);

                Dialog_ExportWindow exportWindow = new Dialog_ExportWindow(base.Map, cellExport);
                Find.WindowStack.Add(exportWindow);
            }, false, true, base.Map);
        }
Exemplo n.º 12
0
        public override void Generate(Map map, GenStepParams parms)
        {
            StructureLayoutDef structureLayoutDef = structureLayoutDefs.RandomElement();

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

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

            // Flood refog
            this.SetAllFogged(map);
            foreach (IntVec3 loc in map.AllCells)
            {
                map.mapDrawer.MapMeshDirty(loc, MapMeshFlag.FogOfWar);
            }

            // Remove power cable not connected to a powered grid
            map.listerBuildings.allBuildingsNonColonist.RemoveAll(b => b.TryGetComp <CompPowerTransmitter>() is CompPowerTransmitter cp && cp != null && cp.Props.transmitsPower == true && !cp.PowerNet.HasActivePowerSource);
        }
Exemplo n.º 13
0
        private static void QuickspawnStructure()
        {
            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))
                    {
                        KCSG_Utilities.HeightWidthFromLayout(localDef, out int h, out int w);
                        CellRect cellRect = CellRect.CenteredOn(UI.MouseCell(), w, h);

                        foreach (List <string> item in localDef.layouts)
                        {
                            KCSG_Utilities.GenerateRoomFromLayout(item, cellRect, Find.CurrentMap, localDef);
                        }
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
        public static void Generate(Map map, IntVec3 c, FactionSettlement sf, string symbolResolver = "kcsg_settlement")
        {
            FactionSettlement.tempUseStructureLayout = sf.useStructureLayout;

            string sld;

            if (!sf.useStructureLayout)
            {
                sld = sf.chooseFromSettlements.RandomElement().defName;
            }
            else
            {
                if (ModLister.RoyaltyInstalled)
                {
                    sld = sf.chooseFromlayouts.RandomElement().defName;
                }
                else
                {
                    sld = sf.chooseFromlayouts.ToList().FindAll(sfl => !sfl.requireRoyalty).RandomElement().defName;
                }
            }

            FactionSettlement.temp = sld;

            // Get faction
            Faction faction;

            if (map.ParentFaction == null || map.ParentFaction == Faction.OfPlayer)
            {
                faction = Find.FactionManager.RandomEnemyFaction(false, false, true, TechLevel.Undefined);
            }
            else
            {
                faction = map.ParentFaction;
            }

            // Get settlement size
            int width;
            int height;

            if (sf.useStructureLayout)
            {
                KCSG_Utilities.HeightWidthFromLayout(DefDatabase <StructureLayoutDef> .GetNamed(sld), out height, out width);
            }
            else
            {
                SettlementLayoutDef temp = DefDatabase <SettlementLayoutDef> .GetNamed(sld);

                height = temp.settlementSize.x;
                width  = temp.settlementSize.z;
            }

            CellRect rect = new CellRect(c.x - width / 2, c.z - height / 2, width, height);

            rect.ClipInsideMap(map);

            ResolveParams rp = default(ResolveParams);

            rp.faction = faction;
            rp.rect    = rect;

            BaseGen.globalSettings.map = map;
            BaseGen.symbolStack.Push(symbolResolver, rp, null);
            BaseGen.Generate();
        }
Exemplo n.º 15
0
        public override void Resolve(ResolveParams rp)
        {
            Map                 map     = BaseGen.globalSettings.map;
            Faction             faction = rp.faction ?? Find.FactionManager.RandomEnemyFaction(false, false, true, TechLevel.Undefined);
            SettlementLayoutDef lDef    = FactionSettlement.temp;

            List <CellRect> gridRects = KCSG_Utilities.GetRects(rp.rect, lDef, map, out rp.rect);

            FactionSettlement.tempRectList = gridRects;

            if (VFECore.VFEGlobal.settings.enableLog)
            {
                Log.Message("Hostile pawns generation - PASS");
            }

            // Add pawn to the base
            Lord          singlePawnLord = rp.singlePawnLord ?? LordMaker.MakeNewLord(faction, new LordJob_DefendBase(faction, rp.rect.CenterCell), map, null);
            TraverseParms traverseParms  = TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false);
            ResolveParams resolveParams  = rp;

            resolveParams.rect             = rp.rect;
            resolveParams.faction          = faction;
            resolveParams.singlePawnLord   = singlePawnLord;
            resolveParams.pawnGroupKindDef = (rp.pawnGroupKindDef ?? PawnGroupKindDefOf.Settlement);
            resolveParams.singlePawnSpawnCellExtraPredicate = (rp.singlePawnSpawnCellExtraPredicate ?? ((IntVec3 x) => map.reachability.CanReachMapEdge(x, traverseParms)));
            if (resolveParams.pawnGroupMakerParams == null && faction.def.pawnGroupMakers.Any(pgm => pgm.kindDef == PawnGroupKindDefOf.Settlement))
            {
                resolveParams.pawnGroupMakerParams             = new PawnGroupMakerParms();
                resolveParams.pawnGroupMakerParams.tile        = map.Tile;
                resolveParams.pawnGroupMakerParams.faction     = faction;
                resolveParams.pawnGroupMakerParams.points      = (rp.settlementPawnGroupPoints ?? SymbolResolver_Settlement.DefaultPawnsPoints.RandomInRange);
                resolveParams.pawnGroupMakerParams.inhabitants = true;
                resolveParams.pawnGroupMakerParams.seed        = rp.settlementPawnGroupSeed;
            }
            if (faction.def.pawnGroupMakers.Any(pgm => pgm.kindDef == PawnGroupKindDefOf.Settlement))
            {
                BaseGen.symbolStack.Push("pawnGroup", resolveParams, null);
            }

            // Add defense
            if (lDef.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                   = faction;
                rp3.edgeDefenseWidth          = dWidth;
                rp3.edgeThingMustReachMapEdge = new bool?(rp.edgeThingMustReachMapEdge ?? true);
                BaseGen.symbolStack.Push("edgeDefense", rp3, null);
            }

            if (VFECore.VFEGlobal.settings.enableLog)
            {
                Log.Message("Structures generation - PASS");
            }

            // Create the rooms
            ResolveParams rp2 = rp;

            rp2.faction = faction;
            BaseGen.symbolStack.Push("kcsg_roomsgen", rp2, null);

            // Add path

            if (VFECore.VFEGlobal.settings.enableLog)
            {
                Log.Message("Adding paths - PASS");
            }

            if (lDef.path)
            {
                ResolveParams rp1 = rp;
                rp1.floorDef = lDef.pathType ?? TerrainDefOf.Gravel;
                rp1.allowBridgeOnAnyImpassableTerrain = true;
                BaseGen.symbolStack.Push("floor", rp1, null);
            }

            // Destroy all things before spawning the base

            if (VFECore.VFEGlobal.settings.enableLog)
            {
                Log.Message("Clearing ground - PASS");
            }

            if (lDef.clearEverything)
            {
                foreach (IntVec3 c in rp.rect)
                {
                    c.GetThingList(map).ToList().ForEach((t) => t.DeSpawn()); // Remove all things
                    map.roofGrid.SetRoof(c, null);                            // Remove roof
                }
                map.roofGrid.RoofGridUpdate();                                // Update roof grid
            }
            else
            {
                foreach (IntVec3 c in rp.rect)
                {
                    c.GetThingList(map).ToList().FindAll(t1 => t1.def.category == ThingCategory.Filth || t1.def.category == ThingCategory.Item).ForEach((t) => t.DeSpawn());
                }
            }
        }