private static List <CustomVector> GetDoorsInLayout(StructureLayoutDef building) { List <CustomVector> doors = new List <CustomVector>(); foreach (List <string> layout in building.layouts) { List <string> rLayout = layout.ListFullCopy(); rLayout.Reverse(); for (int row = 0; row < rLayout.Count; row++) { string[] array = rLayout[row].Split(','); for (int col = 0; col < array.Length; col++) { if (array[col] != ".") { SymbolDef tempS = DefDatabase <SymbolDef> .GetNamedSilentFail(array[col]); if (tempS != null && tempS.thingDef != null && tempS.thingDef.altitudeLayer == AltitudeLayer.DoorMoveable) { doors.Add(new CustomVector(col, row)); } } } } } return(doors); }
private static SymbolDef CreateSymbolDef(ThingDef thing) { SymbolDef symbolDef = new SymbolDef { defName = $"{thing.defName}", thingDef = thing, }; sCreated++; return(symbolDef); }
private static SymbolDef CreateSymbolDef(PawnKindDef pawnKindDef) { SymbolDef symbolDef = new SymbolDef { defName = $"{pawnKindDef.defName}", pawnKindDefNS = pawnKindDef, }; sCreated++; return(symbolDef); }
private static SymbolDef CreateSymbolDef(ThingDef thing, Rot4 rot) { SymbolDef symbolDef = new SymbolDef { defName = $"{thing.defName}_{rot.ToStringHuman()}", thingDef = thing, rotation = rot, }; sCreated++; return(symbolDef); }
private static SymbolDef CreateSymbolDef(ThingDef thing, ThingDef stuff) { SymbolDef symbolDef = new SymbolDef { defName = $"{thing.defName}_{stuff.defName}", thingDef = thing, stuffDef = stuff, }; sCreated++; return(symbolDef); }
private static SymbolDef CreateSymbolDef(TerrainDef terrain) { SymbolDef symbolDef = new SymbolDef { defName = $"{terrain.defName}", isTerrain = true, terrainDef = terrain, }; sCreated++; return(symbolDef); }
private static void AddDef(SymbolDef def) { if (DefDatabase <SymbolDef> .DefCount < 65535) { if (DefDatabase <SymbolDef> .GetNamedSilentFail(def.defName) == null) { DefDatabase <SymbolDef> .Add(def); } } else if (VFECore.VFEGlobal.settings.enableVerboseLogging) { Log.Error($"[KCSG] Error creating symbol: {def.defName} from {def.thingDef.modContentPack?.PackageId}. Suppressing further errors"); defCreated = true; } }
public static void GenerateRoomFromLayout(List <string> layoutList, CellRect roomRect, Map map, StructureLayoutDef rld, bool generateConduit = true) { bool parentFaction = map.ParentFaction != null; if (rld.roofGrid != null) { GenerateRoofGrid(rld.roofGrid, roomRect, map); } List <string> allSymbList = new List <string>(); foreach (string str in layoutList) { allSymbList.AddRange(str.Split(',')); } int l = 0; foreach (IntVec3 cell in roomRect) { if (l < allSymbList.Count && allSymbList[l] != ".") { SymbolDef temp = DefDatabase <SymbolDef> .GetNamedSilentFail(allSymbList[l]); Thing thing; if (temp != null) { if (temp.isTerrain && temp.terrainDef != null) { GenerateTerrainAt(map, cell, temp.terrainDef); } else if (temp.pawnKindDefNS != null && CGO.factionSettlement?.shouldRuin == false) { if (temp.lordJob != null) { Lord lord = CreateNewLord(temp.lordJob, map, cell); for (int i = 0; i < temp.numberToSpawn; i++) { Pawn pawn = temp.spawnPartOfFaction ? PawnGenerator.GeneratePawn(temp.pawnKindDefNS, map.ParentFaction) : PawnGenerator.GeneratePawn(temp.pawnKindDefNS); if (pawn != null) { if (temp.isSlave && parentFaction) { pawn.guest.SetGuestStatus(map.ParentFaction, GuestStatus.Prisoner); } GenSpawn.Spawn(pawn, cell, map, WipeMode.FullRefund); lord.AddPawn(pawn); } } } else { for (int i = 0; i < temp.numberToSpawn; i++) { Pawn pawn = temp.spawnPartOfFaction ? PawnGenerator.GeneratePawn(temp.pawnKindDefNS, map.ParentFaction) : PawnGenerator.GeneratePawn(temp.pawnKindDefNS); if (pawn != null) { if (temp.isSlave && parentFaction) { pawn.guest.SetGuestStatus(map.ParentFaction, GuestStatus.Prisoner); } GenSpawn.Spawn(pawn, cell, map, WipeMode.FullRefund); } } } } else if (temp.thingDef?.category == ThingCategory.Item && cell.Walkable(map)) { thing = ThingMaker.MakeThing(temp.thingDef, temp.stuffDef ?? (temp.thingDef.stuffCategories?.Count > 0 ? GenStuff.RandomStuffFor(temp.thingDef) : null)); thing.stackCount = Mathf.Clamp(Rand.RangeInclusive(1, temp.thingDef.stackLimit), 1, 75); CompQuality quality = thing.TryGetComp <CompQuality>(); quality?.SetQuality(QualityUtility.GenerateQualityBaseGen(), ArtGenerationContext.Outsider); GenSpawn.Spawn(thing, cell, map, WipeMode.FullRefund); thing.SetForbidden(true, false); } else if (temp.thingDef != null) { thing = ThingMaker.MakeThing(temp.thingDef, temp.thingDef.CostStuffCount > 0 ? (temp.stuffDef ?? temp.thingDef.defaultStuff ?? ThingDefOf.WoodLog) : null); CompRefuelable refuelable = thing.TryGetComp <CompRefuelable>(); refuelable?.Refuel(refuelable.Props.fuelCapacity); CompPowerBattery battery = thing.TryGetComp <CompPowerBattery>(); battery?.AddEnergy(battery.Props.storedEnergyMax); if (thing is Building_CryptosleepCasket cryptosleepCasket && Rand.Value < temp.chanceToContainPawn) { Pawn pawn = GeneratePawnForContainer(temp, map); if (!cryptosleepCasket.TryAcceptThing(pawn)) { pawn.Destroy(); } } else if (thing is Building_CorpseCasket corpseCasket && Rand.Value < temp.chanceToContainPawn) { Pawn pawn = GeneratePawnForContainer(temp, map); if (!corpseCasket.TryAcceptThing(pawn)) { pawn.Destroy(); } } else if (thing is Building_Crate crate) { List <Thing> thingList = new List <Thing>(); if (map.ParentFaction == Faction.OfPlayer && temp.thingSetMakerDefForPlayer != null) { thingList = temp.thingSetMakerDefForPlayer.root.Generate(new ThingSetMakerParams()); } else if (temp.thingSetMakerDef != null) { thingList = temp.thingSetMakerDef.root.Generate(new ThingSetMakerParams()); } foreach (Thing t in thingList) { t.stackCount = Math.Min((int)(t.stackCount * temp.crateStackMultiplier), t.def.stackLimit); } thingList.ForEach(t => { if (!crate.TryAcceptThing(t, false)) { t.Destroy(); } }); } if (thing.def.category == ThingCategory.Pawn && CGO.factionSettlement?.shouldRuin == true) { l++; continue; } else if (cell.GetFirstMineable(map) is Mineable m && thing.def.designationCategory == DesignationCategoryDefOf.Security) { l++; continue; } else if (thing.def.category == ThingCategory.Plant && cell.GetTerrain(map).fertility > 0.5 && cell.Walkable(map)) // If it's a plant { Plant plant = thing as Plant; plant.Growth = temp.plantGrowth; // apply the growth GenSpawn.Spawn(plant, cell, map, WipeMode.VanishOrMoveAside); } else if (thing.def.category == ThingCategory.Building) { if (!cell.GetTerrain(map).affordances.Contains(TerrainAffordanceDefOf.Heavy)) { if (thing.def.building.isNaturalRock) { TerrainDef t = DefDatabase <TerrainDef> .GetNamedSilentFail($"{thing.def.defName}_Rough"); map.terrainGrid.SetTerrain(cell, t ?? TerrainDefOf.Soil); foreach (IntVec3 intVec3 in CellRect.CenteredOn(cell, 1)) { if (!intVec3.GetTerrain(map).BuildableByPlayer) { map.terrainGrid.SetTerrain(intVec3, t ?? TerrainDefOf.Soil); } } } else { map.terrainGrid.SetTerrain(cell, TerrainDefOf.Bridge); } } if (thing.def.rotatable) { GenSpawn.Spawn(thing, cell, map, new Rot4(temp.rotation.AsInt), WipeMode.VanishOrMoveAside); } else { GenSpawn.Spawn(thing, cell, map, WipeMode.VanishOrMoveAside); } if (parentFaction) { thing.SetFactionDirect(map.ParentFaction); } } if (generateConduit && rld.spawnConduits && !thing.def.mineable && (thing.def.passability == Traversability.Impassable || thing.def.IsDoor) && map.ParentFaction?.def.techLevel >= TechLevel.Industrial) // Add power cable under all impassable { Thing c = ThingMaker.MakeThing(ThingDefOf.PowerConduit); if (parentFaction) { c.SetFactionDirect(map.ParentFaction); } GenSpawn.Spawn(c, cell, map, WipeMode.FullRefund); } // Handle mortar and mortar pawns if (thing?.def?.building?.buildingTags?.Count > 0) { if (thing.def.building.IsMortar && thing.def.category == ThingCategory.Building && thing.def.building.buildingTags.Contains("Artillery_MannedMortar") && thing.def.HasComp(typeof(CompMannable)) && parentFaction) { // Spawn pawn Lord singlePawnLord = LordMaker.MakeNewLord(map.ParentFaction, new LordJob_ManTurrets(), map, null); PawnGenerationRequest value = new PawnGenerationRequest(map.ParentFaction.RandomPawnKind(), map.ParentFaction, PawnGenerationContext.NonPlayer, map.Tile, mustBeCapableOfViolence: true, inhabitant: true); ResolveParams rpPawn = new ResolveParams { faction = map.ParentFaction, singlePawnGenerationRequest = new PawnGenerationRequest?(value), rect = CellRect.SingleCell(thing.InteractionCell), singlePawnLord = singlePawnLord }; BaseGen.symbolStack.Push("pawn", rpPawn); // Spawn shells ThingDef shellDef = TurretGunUtility.TryFindRandomShellDef(thing.def, false, true, map.ParentFaction.def.techLevel, false, 250f); if (shellDef != null) { ResolveParams rpShell = new ResolveParams { faction = map.ParentFaction, singleThingDef = shellDef, singleThingStackCount = Rand.RangeInclusive(8, Math.Min(12, shellDef.stackLimit)) }; BaseGen.symbolStack.Push("thing", rpShell); } } } }
public override List <Pawn> SpawnThreats(IncidentParms parms) { RectUtils.HeightWidthFromLayout(CGO.fallingStructureChoosen, out int h, out int w); CellRect cellRect = CellRect.CenteredOn(parms.spawnCenter, w, h); List <string> allSymbList = new List <string>(); Map map = (Map)parms.target; foreach (string str in CGO.fallingStructureChoosen.layouts[0]) { List <string> symbSplitFromLine = str.Split(',').ToList(); symbSplitFromLine.ForEach((s) => allSymbList.Add(s)); } List <TTIR> fallers = new List <TTIR>(); Dictionary <ActiveDropPodInfo, IntVec3> pods = new Dictionary <ActiveDropPodInfo, IntVec3>(); int l = 0; foreach (IntVec3 cell in cellRect.Cells) { if (l < allSymbList.Count && allSymbList[l] != ".") { SymbolDef temp = DefDatabase <SymbolDef> .GetNamed(allSymbList[l], false); Thing thing; if (temp.thingDef != null && !CGO.fallingStructure.thingsToSpawnInDropPod.Contains(temp.thingDef)) { TTIR ttir = new TTIR(); thing = ThingMaker.MakeThing(temp.thingDef, temp.stuffDef); thing.SetFactionDirect(parms.faction); if (!CGO.fallingStructure.spawnDormantWhenPossible && thing.TryGetComp <CompCanBeDormant>() is CompCanBeDormant ccbd && ccbd != null) { ccbd.wakeUpOnTick = Find.TickManager.TicksGame + 150; } if (thing.def.rotatable && thing.def.category == ThingCategory.Building) { ttir.rot = new Rot4(temp.rotation.AsInt); } ThingDef faller = new ThingDef { thingClass = CGO.fallingStructure.skyfaller, category = ThingCategory.Ethereal, useHitPoints = false, drawOffscreen = true, tickerType = TickerType.Normal, altitudeLayer = AltitudeLayer.Skyfaller, drawerType = DrawerType.RealtimeOnly, defName = temp.thingDef.defName, label = temp.thingDef.label + " (incoming)", size = new IntVec2(thing.def.size.x, thing.def.size.z) }; faller.skyfaller = new SkyfallerProperties() { shadowSize = new UnityEngine.Vector2(thing.def.size.x + 1, thing.def.size.z + 1), ticksToImpactRange = new IntRange(150, 150), movementType = SkyfallerMovementType.Decelerate }; ttir.faller = faller; ttir.toSpawn = thing; ttir.cell = cell; fallers.Add(ttir); } else if (temp.thingDef != null) { thing = ThingMaker.MakeThing(temp.thingDef, temp.stuffDef); thing.SetFactionDirect(parms.faction); ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo(); activeDropPodInfo.innerContainer.TryAdd(thing); activeDropPodInfo.openDelay = 40; activeDropPodInfo.leaveSlag = false; pods.Add(activeDropPodInfo, cell); } } l++; } // ARRIVAL fallers.ForEach(ttir => this.SpawnSkyfaller(ttir.faller, ttir.toSpawn, ttir.cell, map, ttir.rot)); for (int i = 0; i < pods.Count; i++) { DropPodUtility.MakeDropPodAt(pods.ElementAt(i).Value, map, pods.ElementAt(i).Key); } IncidentParms parms1 = parms; RCellFinder.TryFindRandomCellNearWith(parms.spawnCenter, i => i.Walkable(map), map, out parms1.spawnCenter, 33, 40); base.SpawnThreats(parms1); CGO.ClearFalling(); return(null); }