public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); var ZTracker = ZUtils.ZTracker; if (ZTracker.totalStairsDown == null) { ZTracker.totalStairsDown = new HashSet <Building_Stairs>(); } ZTracker.totalStairsDown.Add(this); if (!ZTracker.stairsDown.ContainsKey(this.Map)) { ZTracker.stairsDown[this.Map] = new List <Building_Stairs>(); } if (!ZTracker.stairsDown[this.Map].Contains(this)) { ZTracker.stairsDown[this.Map].Add(this); } ZLogger.Message("Spawning " + this); if (!respawningAfterLoad) { if (this.Position.GetTerrain(this.Map) == ZLevelsDefOf.ZL_OutsideTerrain) { this.Map.terrainGrid.SetTerrain(this.Position, ZLevelsDefOf.ZL_OutsideTerrainTwo); } Map mapBelow = ZTracker.GetLowerLevel(this.Map.Tile, this.Map); if (mapBelow != null && mapBelow != this.Map && this.def.defName == "FC_StairsDown") { for (int i = mapBelow.thingGrid.ThingsListAt(this.Position).Count - 1; i >= 0; i--) { Thing thing = mapBelow.thingGrid.ThingsListAt(this.Position)[i]; if (thing is Mineable) { if (thing.Spawned) { thing.DeSpawn(DestroyMode.WillReplace); } } } if (!this.Position.GetThingList(mapBelow).Any(x => x.def == ZLevelsDefOf.ZL_StairsUp)) { var stairsToSpawn = ThingMaker.MakeThing(ZLevelsDefOf.ZL_StairsUp, this.Stuff); mapBelow.terrainGrid.SetTerrain(this.Position, ZLevelsDefOf.ZL_OutsideTerrainTwo); GenPlace.TryPlaceThing(stairsToSpawn, this.Position, mapBelow, ThingPlaceMode.Direct); stairsToSpawn.SetFaction(this.Faction); } FloodFillerFog.FloodUnfog(this.Position, mapBelow); mapBelow.fogGrid.FloodUnfogAdjacent(this.Position); } else if (mapBelow == this.Map) { Log.Error("There was a mismatch of ZLevels indices. This is a serious error, report it to the mod developers"); foreach (var map2 in ZTracker.GetAllMaps(this.Map.Tile)) { ZLogger.Message("Index: " + ZTracker.GetMapInfo(map2)); } } } }
// Token: 0x06000033 RID: 51 RVA: 0x00005990 File Offset: 0x00003B90 private new void ActivatedBy(Pawn p) { Find.SignalManager.SendSignal(new Signal(signalTag, p.Named("SUBJECT"))); FloodFillerFog.FloodUnfog(p.Position, p.Map); p.Position.GetRoom(p.Map).Notify_RoomShapeChanged(); if (!destroyIfUnfogged && !Destroyed) { Destroy(); } }
static bool Prefix(Map map, ref IntVec3 __result) { if (map.Parent is Citadel) { __result = NarrowUtil.FindStartSpot(map); FloodFillerFog.FloodUnfog(__result, map); return(false); } return(true); }
public override void Generate(Map map, GenStepParams parms) { DeepProfiler.Start("GenerateInitialFogGrid"); map.fogGrid.SetAllFogged(); FloodFillerFog.FloodUnfog(MapGenerator.PlayerStartSpot, map); List <IntVec3> rootsToUnfog = MapGenerator.rootsToUnfog; for (int i = 0; i < rootsToUnfog.Count; i++) { FloodFillerFog.FloodUnfog(rootsToUnfog[i], map); } DeepProfiler.End(); }
public static void UnfogFromRandomEdge(Map map) { MapGenUtility.FogAll(map); MapGenerator.rootsToUnfog.Clear(); foreach (Pawn current in map.mapPawns.FreeColonists) { MapGenerator.rootsToUnfog.Add(current.Position); } MapGenerator.rootsToUnfog.Add(CellFinderLoose.RandomCellWith((IntVec3 loc) => GenGrid.Standable(loc, map) && (loc.x <4 || loc.z <4 || loc.x> map.Size.x - 5 || loc.z> map.Size.z - 5), map, 1000)); foreach (IntVec3 current2 in MapGenerator.rootsToUnfog) { FloodFillerFog.FloodUnfog(current2, map); } }
private void ActivatedBy(Pawn p, Map map) { if (signalTag != null && signalTag != "") { Find.SignalManager.SendSignal(new Signal(signalTag, p)); } FloodFillerFog.FloodUnfog(p.Position, map); p.Position.GetRoom(map).Notify_RoomShapeOrContainedBedsChanged(); if (!destroyIfUnfogged && !base.Destroyed) { Destroy(DestroyMode.Vanish); } }
private void FloodUnfogAdjacent(IntVec3 c, Map map) { map.fogGrid.Unfog(c); bool flag = false; FloodUnfogResult floodUnfogResult = default(FloodUnfogResult); for (int i = 0; i < 4; i++) { IntVec3 intVec = c + GenAdj.CardinalDirections[i]; if (intVec.InBounds(map) && intVec.Fogged(map)) { Building edifice = intVec.GetEdifice(map); if (edifice == null || !edifice.def.MakeFog) { flag = true; floodUnfogResult = FloodFillerFog.FloodUnfog(intVec, map); } else { map.fogGrid.Unfog(intVec); } } } for (int j = 0; j < 8; j++) { IntVec3 c2 = c + GenAdj.AdjacentCells[j]; if (c2.InBounds(map)) { Building edifice2 = c2.GetEdifice(map); if (edifice2 != null && edifice2.def.MakeFog) { map.fogGrid.Unfog(c2); } } } if (flag) { if (floodUnfogResult.mechanoidFound) { Find.LetterStack.ReceiveLetter("LetterLabelAreaRevealed".Translate(), "AreaRevealedWithMechanoids".Translate(), LetterDefOf.ThreatBig, new TargetInfo(c, map, false), null, null, null, null); return; } if (!floodUnfogResult.allOnScreen || floodUnfogResult.cellsUnfogged >= 600) { Find.LetterStack.ReceiveLetter("LetterLabelAreaRevealed".Translate(), "AreaRevealed".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(c, map, false), null, null, null, null); } } }
protected override IEnumerable <Toil> MakeNewToils() { Building_Farcaster building_Farcaster = null; this.FailOnDespawnedOrNull(TargetIndex.A); yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.InteractionCell).FailOn(delegate(Toil to) { building_Farcaster = (Building_Farcaster)to.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing; return false; })); Toil enterFarcaster = new Toil(); enterFarcaster.initAction = delegate { pawn.DeSpawn(); GenSpawn.Spawn(pawn, building_Farcaster.locationFarcast, building_Farcaster.mapParent.Map); FloodFillerFog.FloodUnfog(building_Farcaster.locationFarcast, building_Farcaster.mapParent.Map); }; yield return(enterFarcaster); }
static bool Prefix(ref FogGrid __instance, ref Map ___map, IntVec3 c) { if (!(___map.Parent is City)) { return(true); } __instance.Unfog(c); FloodUnfogResult floodUnfogResult = default(FloodUnfogResult); for (int i = 0; i < 4; i++) { IntVec3 intVec = c + GenAdj.CardinalDirections[i]; if (intVec.InBounds(___map) && intVec.Fogged(___map)) { Building edifice = intVec.GetEdifice(___map); if (edifice == null || !edifice.def.MakeFog) { floodUnfogResult = FloodFillerFog.FloodUnfog(intVec, ___map); } else { __instance.Unfog(intVec); } } } for (int j = 0; j < 8; j++) { IntVec3 c2 = c + GenAdj.AdjacentCells[j]; if (c2.InBounds(___map)) { Building edifice2 = c2.GetEdifice(___map); if (edifice2 != null && edifice2.def.MakeFog) { __instance.Unfog(c2); } } } return(false); }
static bool Prefix(ref FogGrid __instance, ref Map ___map, IntVec3 c) { if (___map.Parent is City) { var map = ___map; __instance.Unfog(c); for (var index = 0; index < 4; ++index) { var intVec3 = c + GenAdj.CardinalDirections[index]; if (intVec3.InBounds(map) && intVec3.Fogged(map)) { var edifice = intVec3.GetEdifice(map); if (edifice == null || !edifice.def.MakeFog) { FloodFillerFog.FloodUnfog(intVec3, map); } else { __instance.Unfog(intVec3); } } } for (var index = 0; index < 8; ++index) { var c1 = c + GenAdj.AdjacentCells[index]; if (c1.InBounds(map)) { var edifice = c1.GetEdifice(map); if (edifice != null && edifice.def.MakeFog) { __instance.Unfog(c1); } } } return(false); } return(true); }
public static void RefogMap(Map map) { CellIndices cellIndices = map.cellIndices; if (map.fogGrid == null) { map.fogGrid.fogGrid = new bool[cellIndices.NumGridCells]; } foreach (IntVec3 allCell in map.AllCells) { map.fogGrid.fogGrid[cellIndices.CellToIndex(allCell)] = true; } if (Current.ProgramState == ProgramState.Playing) { map.roofGrid.Drawer.SetDirty(); } foreach (IntVec3 allCell in map.AllCells) { map.mapDrawer.MapMeshDirty(allCell, MapMeshFlag.FogOfWar); } CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => !x.Roofed(map) && x.Walkable(map), map, 0f, out IntVec3 result);; FloodFillerFog.FloodUnfog(result, map); }
// Token: 0x0600000D RID: 13 RVA: 0x0000250C File Offset: 0x0000070C private void DrillToOldLayer() { UndergroundManager undergroundManager = Map.components.Find((MapComponent item) => item is UndergroundManager) as UndergroundManager; UndergroundMapParent undergroundMapParent = undergroundManager.layersState[targetedLevel]; connectedMapParent = undergroundMapParent; connectedMap = undergroundMapParent.Map; CellRect cellRect = this.OccupiedRect(); IntVec3 intVec = new IntVec3(cellRect.minX + 1, 0, cellRect.minZ + 1); connectedLift = GenSpawn.Spawn(ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("undergroundlift", true), Stuff), intVec, connectedMap, WipeMode.Vanish); connectedLift.SetFaction(Faction.OfPlayer, null); FloodFillerFog.FloodUnfog(intVec, connectedMap); bool flag = connectedLift is Building_SpawnedLift; if (flag) { ((Building_SpawnedLift)connectedLift).depth = connectedMapParent.depth; } else { Log.Warning("Spawned lift isn't deeprim's lift. Someone's editing this mod! And doing it badly!!! Very badly.", false); } }
public static CellRect CreateStartingArea(Faction pawnFaction, Map map, IntVec3 pawnPosition, CellRect rect) { RESettings.DM("Create Starting Area"); RESettings.DM("Generate Bedrooms"); RESettings.DM("Variable Test:"); RESettings.DM($"{rect.CenterCell.ToString()}"); RESettings.DM($"{map.ToString()}"); RESettings.DM($"{pawnFaction.ToString()}"); //Bedrooms CreateWallsAt(rect.CenterCell.x + -11, rect.CenterCell.z + 5, 16, false, map, ThingDefOf.Plasteel, pawnFaction, true, 13); SpawnBuildingAt(ThingDefOf.StandingLamp, rect.CenterCell.x - 10, rect.CenterCell.z + 6, map, pawnFaction, Rot4.North); SpawnBuildingAt(ThingDefOf.StandingLamp, rect.CenterCell.x + 4, rect.CenterCell.z + 6, map, pawnFaction, Rot4.North); RESettings.DM("Generate Beds"); //Beds for (int i = 0; i < 9; i++) { if (i % 2 != 0) { continue; } SpawnBuildingAt(ThingDefOf.Bed, rect.CenterCell.x - 9 + i, rect.CenterCell.z + 9, map, pawnFaction, Rot4.South, ThingDefOf.Steel); } RESettings.DM("Generate Fab Room"); //Fabrication room CreateWallsAt(rect.CenterCell.x + 5, rect.CenterCell.z + 10, 16, true, map, ThingDefOf.Plasteel, pawnFaction, true, 14); SpawnBuildingAt(ThingDef.Named("FabricationBench"), rect.CenterCell.x + 8, rect.CenterCell.z + 6, map, pawnFaction, Rot4.West, out Thing fabBench); SpawnBuildingAt(ThingDefOf.StandingLamp, rect.CenterCell.x + 6, rect.CenterCell.z + 0, map, pawnFaction, Rot4.South); GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("Stool"), ThingDefOf.Steel), fabBench.InteractionCell, map, fabBench.Rotation.Opposite); RESettings.DM("Generate Research Room"); //Research Room CreateWallsAt(rect.CenterCell.x - 5, rect.CenterCell.z - 6, 16, false, map, ThingDefOf.Plasteel, pawnFaction, true, 1); SpawnBuildingAt(ThingDef.Named("HiTechResearchBench"), rect.CenterCell.x + 5, rect.CenterCell.z - 9, map, pawnFaction, Rot4.South, out Thing resBench, ThingDefOf.Plasteel); GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("Stool"), ThingDefOf.Steel), resBench.InteractionCell, map, resBench.Rotation.Opposite); RESettings.DM("Generate Dining Room"); //Dining room CreateWallsAt(rect.CenterCell.x - 6, rect.CenterCell.z + 4, 16, true, map, ThingDefOf.Plasteel, pawnFaction, true, 1); SpawnBuildingAt(ThingDefOf.Table2x2c, rect.CenterCell.x - 10, rect.CenterCell.z - 3, map, pawnFaction, Rot4.North, out Thing spawnedTable, ThingDef.Named("BlocksMarble")); RESettings.DM("Generate Tables and Stools"); ////Spawn a table and stools CellRect tableRect = spawnedTable.OccupiedRect().ExpandedBy(1); bool randomFlag = false; foreach (IntVec3 stoolSpot in tableRect.EdgeCells.InRandomOrder()) { Thing spawnedStool = null; if (!tableRect.IsCorner(stoolSpot) && stoolSpot.Standable(map) && stoolSpot.GetEdifice(map) == null && (!randomFlag || !Rand.Bool) ) { Thing stool = ThingMaker.MakeThing(ThingDef.Named("Stool"), ThingDefOf.Steel); GenPlace.TryPlaceThing(stool, stoolSpot, map, ThingPlaceMode.Direct, out spawnedStool); if (spawnedStool != null) { spawnedStool.Rotation = (stoolSpot.x == tableRect.minX) ? Rot4.East : ((stoolSpot.x == tableRect.maxX) ? Rot4.West : ((stoolSpot.z != tableRect.minZ) ? Rot4.South : Rot4.North)); } } } RESettings.DM("Generate Crematorium"); //For erasing some zombies ^^ SpawnBuildingAt(ThingDef.Named("ElectricCrematorium"), rect.CenterCell.x - 8, rect.CenterCell.z - 8, map, pawnFaction, Rot4.East, ThingDefOf.Plasteel); RESettings.DM("Generate Geothermal Generator"); //Geothermal Generator SpawnBuildingAt(ThingDefOf.GeothermalGenerator, rect.CenterCell.x - 1, rect.CenterCell.z - 1, map, pawnFaction, Rot4.North); RESettings.DM("Spawn Steel"); //Steel, for making power cables var steelLoc = CellFinder.FindNoWipeSpawnLocNear(rect.RandomCell, map, ThingDefOf.Steel, Rot4.South); for (int i = 0; i < 3; i++) { Thing steelPiece = ThingMaker.MakeThing(ThingDefOf.Steel, null); steelPiece.stackCount = Rand.Range(15, 50); GenPlace.TryPlaceThing(steelPiece, steelLoc, map, ThingPlaceMode.Near); } RESettings.DM("Spawn Empty Syringes"); //Empty syringes var syringesLoc = CellFinder.FindNoWipeSpawnLocNear(rect.RandomCell, map, ThingDefOf.Steel, Rot4.South); Thing syringePiece = ThingMaker.MakeThing(ThingDef.Named("RE_Syringe"), null); syringePiece.stackCount = Rand.Range(4, 6); GenPlace.TryPlaceThing(syringePiece, syringesLoc, map, ThingPlaceMode.Near); RESettings.DM("Spawn Food"); //Food var foodStartPoint = CellFinder.FindNoWipeSpawnLocNear(rect.RandomCell, map, ThingDefOf.MealSurvivalPack, Rot4.South); for (int i = 0; i < 2; i++) { Thing foodToEat = ThingMaker.MakeThing(ThingDefOf.MealSurvivalPack); if (GenPlace.TryPlaceThing(foodToEat, foodStartPoint, map, ThingPlaceMode.Near, out Thing foodSpawned)) { foodSpawned.stackCount = 10; } } RESettings.DM("Spawn Herbs"); //Some green herbs var greenHerbStartPoint = CellFinder.FindNoWipeSpawnLocNear(rect.RandomCell, map, ThingDefOf.MealSurvivalPack, Rot4.South); for (int i = 0; i < 3; i++) { Plant herb = (Plant)ThingMaker.MakeThing(ThingDef.Named("RE_Plant_ResidentEvilHerbGreen")); if (GenPlace.TryPlaceThing(herb, greenHerbStartPoint, map, ThingPlaceMode.Near, out Thing herbSpawned)) { var plantHerb = (Plant)herbSpawned; plantHerb.Growth = 1.0f; } } RESettings.DM("Spawn Other Herbs"); //Some other herbs. var otherHerbStartPoint = CellFinder.FindNoWipeSpawnLocNear(rect.RandomCell, map, ThingDefOf.MealSurvivalPack, Rot4.South); for (int i = 0; i < 2; i++) { Plant herb = (Plant)ThingMaker.MakeThing(Rand.Value > 0.5f ? ThingDef.Named("RE_Plant_ResidentEvilHerbBlue") : ThingDef.Named("RE_Plant_ResidentEvilHerbRed")); if (GenPlace.TryPlaceThing(herb, otherHerbStartPoint, map, ThingPlaceMode.Near, out Thing herbSpawned)) { var plantHerb = (Plant)herbSpawned; plantHerb.Growth = 1.0f; } } HarmonyPatches.calcWealthFloors = false; RESettings.DM("Refog"); //Refog Traverse.Create(map.fogGrid).Method("SetAllFogged", new object[] { }).GetValue(); RESettings.DM("Place pawns in area"); //Bring in the boys foreach (var pawn in Find.GameInitData.startingAndOptionalPawns) { if (pawn.Spawned) { IntVec3 loc = CellFinder.RandomSpawnCellForPawnNear(rect.CenterCell, map); //CellFinder.TryFindBestPawnStandCell(pawn, out loc); pawn.DeSpawn(); var flag = false; for (int i = 0; i < GenRadial.RadialPattern.Length; i++) { IntVec3 intVec = loc + GenRadial.RadialPattern[i]; if (!PawnCanOccupy(intVec, map, pawn)) { continue; } flag = true; pawn.Position = intVec; GenSpawn.Spawn(pawn, intVec, map); break; } if (!flag) { GenSpawn.Spawn(pawn, loc, map); } //GenPlace.TryPlaceThing(pawn, map.Center, map, ThingPlaceMode.Near); pawn.playerSettings.hostilityResponse = HostilityResponseMode.Attack; FloodFillerFog.FloodUnfog(pawn.Position, map); } } return(rect); }
public override void PostGameStart() { if (SoS2Reflection.inaccessible) { return; } if (WorldSwitchUtility.SelectiveWorldGenFlag) { return; } ShipCombatManager.CanSalvageEnemyShip = false; ShipCombatManager.ShouldSalvageEnemyShip = false; ShipCombatManager.InCombat = false; ShipCombatManager.InEncounter = false; List <Pawn> startingPawns = Find.CurrentMap.mapPawns.PawnsInFaction(Faction.OfPlayer); int newTile = -1; for (int i = 0; i < 420; i++) { if (!Find.World.worldObjects.AnyMapParentAt(i)) { newTile = i; break; } } Map spaceMap = GetOrGenerateMapUtility.GetOrGenerateMap(newTile, DefDatabase <WorldObjectDef> .GetNamed("ShipOrbiting")); ((WorldObjectOrbitingShip)spaceMap.Parent).radius = 150; ((WorldObjectOrbitingShip)spaceMap.Parent).theta = 2.75f; //Building core = null; Current.ProgramState = ProgramState.MapInitializing; SoS2Reflection.GenerateShip(DefDatabase <EnemyShipDef> .GetNamed("CentaursScenarioRetroCruise"), spaceMap, null, Faction.OfPlayer, null, out _); Current.ProgramState = ProgramState.Playing; IntVec2 secs = (IntVec2)typeof(MapDrawer).GetProperty("SectionCount", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(spaceMap.mapDrawer); Section[,] secArray = new Section[secs.x, secs.z]; typeof(MapDrawer).GetField("sections", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(spaceMap.mapDrawer, secArray); for (int i = 0; i < secs.x; i++) { for (int j = 0; j < secs.z; j++) { if (secArray[i, j] == null) { secArray[i, j] = new Section(new IntVec3(i, 0, j), spaceMap); } } } List <IntVec3> cryptoPos = GetAllCryptoCells(spaceMap); foreach (Pawn p in startingPawns) { if (p.InContainerEnclosed) { p.ParentHolder.GetDirectlyHeldThings().Remove(p); } else { p.DeSpawn(); p.SpawnSetup(spaceMap, true); } } List <List <Thing> > list = new List <List <Thing> >(); foreach (Pawn startingAndOptionalPawn in Find.GameInitData.startingAndOptionalPawns) { List <Thing> list2 = new List <Thing> { startingAndOptionalPawn }; list.Add(list2); } List <Thing> list3 = new List <Thing>(); foreach (ScenPart allPart in Find.Scenario.AllParts) { list3.AddRange(allPart.PlayerStartingThings()); } int num = 0; foreach (Thing item in list3) { if (!(item is Pawn)) { if (item.def.CanHaveFaction) { item.SetFactionDirect(Faction.OfPlayer); } list[num].Add(item); num++; if (num >= list.Count) { num = 0; } } } foreach (List <Thing> thingies in list) { IntVec3 casketPos = cryptoPos.RandomElement(); cryptoPos.Remove(casketPos); if (cryptoPos.Count() == 0) { cryptoPos = GetAllCryptoCells(spaceMap); //Out of caskets, time to start double-dipping } foreach (Thing thingy in thingies) { thingy.SetForbidden(true, false); GenPlace.TryPlaceThing(thingy, casketPos, spaceMap, ThingPlaceMode.Near); } FloodFillerFog.FloodUnfog(casketPos, spaceMap); } Find.CurrentMap.Parent.Destroy(); CameraJumper.TryJump(spaceMap.Center, spaceMap); spaceMap.weatherManager.curWeather = WeatherDef.Named("OuterSpaceWeather"); spaceMap.weatherManager.lastWeather = WeatherDef.Named("OuterSpaceWeather"); H_Vacuum_PathFinder.ResetMap(spaceMap); Find.MapUI.Notify_SwitchedMap(); CentaurAlphaShipPostProcess(spaceMap); }
public static HashSet <IntVec3> DoSettlementGeneration(Map map, string path, LocationDef locationDef, Faction faction, bool disableFog) { Log.Message("DoSettlementGeneration: GetOrGenerateMapPatch.locationData: " + GetOrGenerateMapPatch.locationData?.locationDef); Log.Message("DoSettlementGeneration: path: " + path); Log.Message("DoSettlementGeneration: locationDef: " + locationDef); GetOrGenerateMapPatch.locationData = null; GetOrGenerateMapPatch.caravanArrival = false; var mapComp = map.GetComponent <MapComponentGeneration>(); try { if (locationDef != null && locationDef.destroyEverythingOnTheMapBeforeGeneration) { var thingsToDespawn = map.listerThings.AllThings; if (thingsToDespawn != null && thingsToDespawn.Count > 0) { for (int i = thingsToDespawn.Count - 1; i >= 0; i--) { try { if (thingsToDespawn[i].Spawned) { thingsToDespawn[i].DeSpawn(DestroyMode.WillReplace); } } catch (Exception ex) { Log.Error("4 Cant despawn: " + thingsToDespawn[i] + " - " + thingsToDespawn[i].Position + "error: " + ex); } } } } if (locationDef != null && locationDef.factionDefForNPCsAndTurrets != null) { faction = Find.FactionManager.FirstFactionOfDef(locationDef.factionDefForNPCsAndTurrets); } else if (faction == Faction.OfPlayer || faction == null) { faction = Faction.OfAncients; } List <Thing> thingsToDestroy = new List <Thing>(); HashSet <IntVec3> tilesToProcess = new HashSet <IntVec3>(); int radiusToClear = 0; // //foreach (var building in map.listerThings.AllThings // .Where(x => x is Building && x.Faction == faction && !(x is Mineable))) //{ // foreach (var pos in GenRadial.RadialCellsAround(building.Position, radiusToClear, true)) // { // if (GenGrid.InBounds(pos, map)) // { // tilesToProcess.Add(pos); // } // } // thingsToDestroy.Add(building); //} List <Corpse> corpses = new List <Corpse>(); List <Pawn> pawnCorpses = new List <Pawn>(); List <Pawn> pawns = new List <Pawn>(); List <Building> buildings = new List <Building>(); List <Thing> things = new List <Thing>(); List <Filth> filths = new List <Filth>(); List <Plant> plants = new List <Plant>(); Dictionary <IntVec3, TerrainDef> terrains = new Dictionary <IntVec3, TerrainDef>(); Dictionary <IntVec3, RoofDef> roofs = new Dictionary <IntVec3, RoofDef>(); HashSet <IntVec3> tilesToSpawnPawnsOnThem = new HashSet <IntVec3>(); Scribe.loader.InitLoading(path); Scribe_Collections.Look <Pawn>(ref pawnCorpses, "PawnCorpses", LookMode.Deep, new object[0]); Scribe_Collections.Look <Corpse>(ref corpses, "Corpses", LookMode.Deep, new object[0]); Scribe_Collections.Look <Pawn>(ref pawns, "Pawns", LookMode.Deep, new object[0]); Scribe_Collections.Look <Building>(ref buildings, "Buildings", LookMode.Deep, new object[0]); Scribe_Collections.Look <Filth>(ref filths, "Filths", LookMode.Deep, new object[0]); Scribe_Collections.Look <Thing>(ref things, "Things", LookMode.Deep, new object[0]); Scribe_Collections.Look <Plant>(ref plants, "Plants", LookMode.Deep, new object[0]); Scribe_Collections.Look <IntVec3, TerrainDef>(ref terrains, "Terrains", LookMode.Value, LookMode.Def, ref terrainKeys, ref terrainValues); Scribe_Collections.Look <IntVec3, RoofDef>(ref roofs, "Roofs", LookMode.Value, LookMode.Def, ref roofsKeys, ref roofsValues); Scribe_Collections.Look <IntVec3>(ref tilesToSpawnPawnsOnThem, "tilesToSpawnPawnsOnThem", LookMode.Value); Scribe.loader.FinalizeLoading(); if (corpses is null) { corpses = new List <Corpse>(); } else { corpses.RemoveAll(x => x is null); } if (pawnCorpses is null) { pawnCorpses = new List <Pawn>(); } else { pawnCorpses.RemoveAll(x => x is null); } if (pawns is null) { pawns = new List <Pawn>(); } else { pawns.RemoveAll(x => x is null); } if (buildings is null) { buildings = new List <Building>(); } else { buildings.RemoveAll(x => x is null); } if (things is null) { things = new List <Thing>(); } else { things.RemoveAll(x => x is null); } if (filths is null) { filths = new List <Filth>(); } else { filths.RemoveAll(x => x is null); } if (plants is null) { plants = new List <Plant>(); } else { plants.RemoveAll(x => x is null); } var cells = new List <IntVec3>(tilesToSpawnPawnsOnThem); cells.AddRange(buildings.Select(x => x.Position).ToList()); var centerCell = GetCellCenterFor(cells); var offset = map.Center - centerCell; if (corpses != null && corpses.Count > 0) { foreach (var corpse in corpses) { try { var position = GetOffsetPosition(locationDef, corpse.Position, offset); if (GenGrid.InBounds(position, map)) { GenSpawn.Spawn(corpse, position, map, WipeMode.Vanish); } } catch (Exception ex) { Log.Error("1 Error in map generating, cant spawn " + corpse + " - " + ex); } } } if (pawns != null && pawns.Count > 0) { foreach (var pawn in pawns) { try { var position = GetOffsetPosition(locationDef, pawn.Position, offset); if (GenGrid.InBounds(position, map)) { pawn.pather = new Pawn_PathFollower(pawn); GenSpawn.Spawn(pawn, position, map, WipeMode.Vanish); if (pawn.Faction != faction) { pawn.SetFaction(faction); } } } catch (Exception ex) { Log.Error("2 Error in map generating, cant spawn " + pawn + " - " + ex); } } } if (tilesToSpawnPawnsOnThem != null && tilesToSpawnPawnsOnThem.Count > 0) { foreach (var tile in tilesToSpawnPawnsOnThem) { var position = GetOffsetPosition(locationDef, tile, offset); try { if (GenGrid.InBounds(position, map)) { var things2 = map.thingGrid.ThingsListAt(position); foreach (var thing in things2) { if (thing is Building || (thing is Plant plant && plant.def != ThingDefOf.Plant_Grass) || IsChunk(thing)) { thingsToDestroy.Add(thing); } } } } catch (Exception ex) { Log.Error("3 Error in map generating, cant spawn " + position + " - " + ex); } } } if (buildings != null && buildings.Count > 0) { foreach (var building in buildings) { var position = GetOffsetPosition(locationDef, building.Position, offset); foreach (var pos in GenRadial.RadialCellsAround(position, radiusToClear, true)) { if (GenGrid.InBounds(pos, map)) { tilesToProcess.Add(pos); } } } if (tilesToProcess != null && tilesToProcess.Count > 0) { foreach (var pos in tilesToProcess) { if (pos.InBounds(map)) { var things2 = map.thingGrid.ThingsListAt(pos); foreach (var thing in things2) { if (thing is Building || (thing is Plant plant && plant.def != ThingDefOf.Plant_Grass) || IsChunk(thing)) { thingsToDestroy.Add(thing); } } var terrain = pos.GetTerrain(map); if (terrain != null) { if (terrain.IsWater) { map.terrainGrid.SetTerrain(pos, TerrainDefOf.Soil); } if (map.terrainGrid.CanRemoveTopLayerAt(pos)) { map.terrainGrid.RemoveTopLayer(pos, false); } } var roof = pos.GetRoof(map); if (roof != null && (!map.roofGrid.RoofAt(pos).isNatural || map.roofGrid.RoofAt(pos) == RoofDefOf.RoofRockThin)) { map.roofGrid.SetRoof(pos, null); } } } } if (thingsToDestroy != null && thingsToDestroy.Count > 0) { for (int i = thingsToDestroy.Count - 1; i >= 0; i--) { try { if (thingsToDestroy[i].Spawned) { thingsToDestroy[i].DeSpawn(DestroyMode.WillReplace); } } catch (Exception ex) { Log.Error("4 Cant despawn: " + thingsToDestroy[i] + " - " + thingsToDestroy[i].Position + "error: " + ex); } } } foreach (var building in buildings) { var position = GetOffsetPosition(locationDef, building.Position, offset); try { if (GenGrid.InBounds(position, map)) { GenSpawn.Spawn(building, position, map, building.Rotation, WipeMode.Vanish); if (building.def.CanHaveFaction && building.Faction != faction) { building.SetFaction(faction); } } } catch (Exception ex) { Log.Error("5 Error in map generating, cant spawn " + building + " - " + position + " - " + ex); } } } if (filths != null && filths.Count > 0) { foreach (var filth in filths) { try { var position = GetOffsetPosition(locationDef, filth.Position, offset); if (position.InBounds(map)) { GenSpawn.Spawn(filth, position, map, WipeMode.Vanish); } } catch (Exception ex) { Log.Error("6.5 Error in map generating, cant spawn " + filth + " - " + ex); } } } if (plants != null && plants.Count > 0) { foreach (var plant in plants) { try { var position = GetOffsetPosition(locationDef, plant.Position, offset); if (position.InBounds(map) && map.fertilityGrid.FertilityAt(position) >= plant.def.plant.fertilityMin) { GenSpawn.Spawn(plant, position, map, WipeMode.Vanish); } } catch (Exception ex) { Log.Error("6 Error in map generating, cant spawn " + plant + " - " + ex); } } } var containers = map.listerThings.AllThings.Where(x => x is Building_Storage).ToList(); if (things != null && things.Count > 0) { foreach (var thing in things) { try { var position = GetOffsetPosition(locationDef, thing.Position, offset); if (position.InBounds(map)) { GenSpawn.Spawn(thing, position, map, WipeMode.Vanish); if (locationDef != null && locationDef.moveThingsToShelves) { TryDistributeTo(thing, map, containers, faction != Faction.OfPlayer); } } } catch (Exception ex) { Log.Error("7 Error in map generating, cant spawn " + thing + " - " + ex); } } } if (locationDef != null && locationDef.moveThingsToShelves) { foreach (var item in map.listerThings.AllThings) { if (item.IsForbidden(Faction.OfPlayer)) { TryDistributeTo(item, map, containers, faction != Faction.OfPlayer); } } } if (terrains != null && terrains.Count > 0) { foreach (var terrain in terrains) { try { var position = GetOffsetPosition(locationDef, terrain.Key, offset); if (GenGrid.InBounds(position, map)) { map.terrainGrid.SetTerrain(position, terrain.Value); } } catch (Exception ex) { Log.Error("8 Error in map generating, cant spawn " + terrain.Key + " - " + ex); } } } if (roofs != null && roofs.Count > 0) { foreach (var roof in roofs) { try { var position = GetOffsetPosition(locationDef, roof.Key, offset); if (GenGrid.InBounds(position, map)) { map.roofGrid.SetRoof(position, roof.Value); } } catch (Exception ex) { Log.Error("9 Error in map generating, cant spawn " + roof.Key + " - " + ex); } } } if (locationDef != null && (locationDef.percentOfDamagedWalls.HasValue || locationDef.percentOfDestroyedWalls.HasValue) || locationDef.percentOfDamagedFurnitures.HasValue) { var walls = map.listerThings.AllThings.Where(x => x.def.IsEdifice() && x.def.defName.ToLower().Contains("wall")).ToList(); if (locationDef.percentOfDestroyedWalls.HasValue) { var percent = locationDef.percentOfDestroyedWalls.Value.RandomInRange * 100f; var countToTake = (int)((percent * walls.Count()) / 100f); var wallsToDestroy = walls.InRandomOrder().Take(countToTake).ToList(); for (int num = wallsToDestroy.Count - 1; num >= 0; num--) { walls.Remove(wallsToDestroy[num]); wallsToDestroy[num].DeSpawn(); } } if (locationDef.percentOfDamagedWalls.HasValue) { var percent = locationDef.percentOfDamagedWalls.Value.RandomInRange * 100f; var countToTake = (int)((percent * walls.Count()) / 100f); var wallsToDamage = walls.InRandomOrder().Take(countToTake).ToList(); for (int num = wallsToDamage.Count - 1; num >= 0; num--) { var damagePercent = Rand.Range(0.3f, 0.6f); var hitpointsToTake = (int)(wallsToDamage[num].MaxHitPoints * damagePercent); wallsToDamage[num].HitPoints = hitpointsToTake; } } if (locationDef.percentOfDamagedFurnitures.HasValue) { var furnitures = map.listerThings.AllThings.Where(x => !walls.Contains(x) && x.def.IsBuildingArtificial).ToList(); var percent = locationDef.percentOfDamagedFurnitures.Value.RandomInRange * 100f; var countToTake = (int)((percent * furnitures.Count()) / 100f); var furnituresToDamage = furnitures.InRandomOrder().Take(countToTake).ToList(); for (int num = furnituresToDamage.Count - 1; num >= 0; num--) { var damagePercent = Rand.Range(0.3f, 0.6f); var hitpointsToTake = (int)(furnituresToDamage[num].MaxHitPoints * damagePercent); furnituresToDamage[num].HitPoints = hitpointsToTake; } } } if (faction.def.HasModExtension <SettlementOptionModExtension>()) { var options = faction.def.GetModExtension <SettlementOptionModExtension>(); if (options.removeVanillaGeneratedPawns) { for (int i = map.mapPawns.PawnsInFaction(faction).Count - 1; i >= 0; i--) { map.mapPawns.PawnsInFaction(faction)[i].DeSpawn(DestroyMode.Vanish); } } if (options.pawnsToGenerate != null && options.pawnsToGenerate.Count > 0 && tilesToSpawnPawnsOnThem != null && tilesToSpawnPawnsOnThem.Count > 0) { foreach (var pawn in options.pawnsToGenerate) { foreach (var i in Enumerable.Range(1, (int)pawn.selectionWeight)) { var settler = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawn.kind, faction)); try { var pos = tilesToSpawnPawnsOnThem.Where(x => map.thingGrid.ThingsListAt(x) .Where(y => y is Building).Count() == 0).RandomElement(); GenSpawn.Spawn(settler, pos, map); } catch (Exception ex) { Log.Error("10 Error in map generating, cant spawn " + settler + " - " + ex); } } } } } foreach (var pawn in map.mapPawns.PawnsInFaction(faction)) { var lord = pawn.GetLord(); if (lord != null) { map.lordManager.RemoveLord(lord); } var lordJob = new LordJob_DefendBase(); if (tilesToSpawnPawnsOnThem != null && tilesToSpawnPawnsOnThem.Count > 0) { lordJob = new LordJob_DefendBase(faction, tilesToSpawnPawnsOnThem.RandomElement()); } else { lordJob = new LordJob_DefendBase(faction, pawn.Position); } LordMaker.MakeNewLord(faction, lordJob, map, null).AddPawn(pawn); } if (disableFog != true) { try { FloodFillerFog.DebugRefogMap(map); } catch { foreach (var cell in map.AllCells) { if (!tilesToProcess.Contains(cell) && !(cell.GetFirstBuilding(map) is Mineable)) { var item = cell.GetFirstItem(map); if (item != null) { var room = item.GetRoom(); if (room != null) { if (room.PsychologicallyOutdoors) { FloodFillerFog.FloodUnfog(cell, map); } } } } } } mapComp.reFog = true; } mapComp.doGeneration = false; mapComp.path = null; GetOrGenerateMapPatch.caravanArrival = false; return(tilesToSpawnPawnsOnThem.Select(x => GetOffsetPosition(locationDef, x, offset)).ToHashSet()); } catch (Exception ex) { Log.Error("Error in DoSettlementGeneration: " + ex); } mapComp.doGeneration = false; mapComp.path = null; return(null); }