public void QueueAsLongEvent(Map map, IntVec3 min, IntVec3 max, string textKey, bool async, Action <Exception> handler) { LongEventHandler.QueueLongEvent(() => { ShipInteriorMod.Log(textKey.Translate() + "..."); UnsafeExecute(map, min, max); }, textKey, async, handler); }
public MapScanner Unfog(int minOffset = 0, int maxOffset = 0) { return(ForPoints((point, map) => { try { map.fogGrid.Unfog(point); } catch (Exception e) { ShipInteriorMod.Log("Whoops, couldn't unfog: " + e.Message); } }, minOffset, maxOffset)); }
public override void PostMapGenerate(Map map) { if (Find.GameInitData == null) { return; } string str1 = Path.Combine(Path.Combine(GenFilePaths.SaveDataFolderPath, "Ships"), shipFactionName + ".rwship"); string actualFactionName = shipFactionName; bool isVersion2 = false; if (File.Exists(str1 + "2")) //woo 2.0 { str1 += "2"; isVersion2 = true; } Scribe.loader.InitLoading(str1); FactionDef factionDef = Faction.OfPlayer.def; ShipDefinition ship = null; ShipInteriorMod.Log("Loading base managers..."); Scribe_Deep.Look(ref Current.Game.uniqueIDsManager, false, "uniqueIDsManager", new object[0]); Scribe_Deep.Look(ref Current.Game.tickManager, false, "tickManager", new object[0]); Scribe_Deep.Look(ref Current.Game.drugPolicyDatabase, false, "drugPolicyDatabase", new object[0]); Scribe_Deep.Look(ref Current.Game.outfitDatabase, false, "outfitDatabase", new object[0]); //spawn a temp pawn. Pawn tmpPawn = StartingPawnUtility.NewGeneratedStartingPawn(); //Advancing time ShipInteriorMod.Log("Advancing time..."); Current.Game.tickManager.DebugSetTicksGame(Current.Game.tickManager.TicksAbs + 3600000 * Rand.RangeInclusive(Mod.minTravelTime.Value, Mod.maxTravelTime.Value)); if (isVersion2) { Scribe_Values.Look(ref actualFactionName, "playerFactionName"); Scribe_Deep.Look(ref ship, "shipDefinition"); } else { ship = new ShipDefinition(); //load the data the more cludgey way. ship.ExposeData(); } highCorner = ship.Max; lowCorner = ship.Min; IntVec3 spot = MapGenerator.PlayerStartSpot; int width = highCorner.x - lowCorner.x; int height = highCorner.z - lowCorner.z; //try to position us over the start location spot.x -= width / 2; spot.z -= height / 2; //now offset the corners and the parts to the spot. int offsetx = spot.x - lowCorner.x; int offsety = spot.z - lowCorner.z; lowCorner.x += offsetx; lowCorner.z += offsety; highCorner.x += offsetx; highCorner.z += offsety; tmpPawn.Position = lowCorner - new IntVec3(3, 0, 3); tmpPawn.SpawnSetup(map, false); ShipInteriorMod.Log("Low Corner: " + lowCorner.x + ", " + lowCorner.y + ", " + lowCorner.z); ShipInteriorMod.Log("High Corner: " + highCorner.x + ", " + highCorner.y + ", " + highCorner.z); ShipInteriorMod.Log("Map Size: " + map.Size.x + ", " + map.Size.y + ", " + map.Size.z); ship.AdaptToNewGame(map, offsetx, offsety, "Landing", true, Handler); new MapScanner() .DestroyThings(-2, 2) .ForPoints((point, m) => m.roofGrid.SetRoof(point, null), -2, 2) .ForPoints((point, m) => m.terrainGrid.SetTerrain(point, TerrainDefOf.Gravel)) .Unfog(-3, 3) .QueueAsLongEvent(map, lowCorner, highCorner, "Landing_Clean", true, Handler); ship.SpawnInNewGame(map, "Landing", true, Handler); LongEventHandler.QueueLongEvent(() => { ShipInteriorMod.Log("Loading managers..."); Scribe_Deep.Look(ref Current.Game.researchManager, false, "researchManager", new object[0]); Scribe_Deep.Look(ref Current.Game.taleManager, false, "taleManager", new object[0]); Scribe_Deep.Look(ref Current.Game.playLog, false, "playLog", new object[0]); Scribe.loader.FinalizeLoading(); tmpPawn.DeSpawn(); Faction.OfPlayer.Name = actualFactionName; ShipInteriorMod.Log("Done."); }, "Landing_Managers", true, Handler); }
private void TryOrbit() { //move ship there Map newMap = null; Map oldMap = parent.Map; ShipInteriorMod.Log("Adding world object..."); Planet.MapParent obj = Planet.WorldObjectMaker.MakeWorldObject(GenDefDatabase.GetDef(typeof(WorldObjectDef), "OrbitShip") as WorldObjectDef) as Planet.MapParent; obj.Tile = oldMap.Tile; Find.World.worldObjects.Add(obj); //create world map pawn for ship LongEventHandler.QueueLongEvent(() => { ShipInteriorMod.Log("Generating map..."); //generate orbit map var generatorDef = GenDefDatabase.GetDef(typeof(MapGeneratorDef), "Orbit") as MapGeneratorDef; ShipInteriorMod.noSpaceWeather = true; newMap = MapGenerator.GenerateMap(oldMap.Size, obj, generatorDef, obj.ExtraGenStepDefs, null); ShipInteriorMod.noSpaceWeather = false; }, "Orbit_Generate", doAsynchronously: true, exceptionHandler: GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap); oldMap .GetSpaceAtmosphereMapComponent() .DefinitionAt(parent.Position) .Move(oldMap, () => newMap, "Orbit", true, Handler, (AirShipWorldObject)obj) .Then(() => { HashSet <RoomGroup> processedGroups = new HashSet <RoomGroup>(); foreach (var room in newMap.regionGrid.allRooms) { var group = room.Group; if (!processedGroups.Contains(group)) { processedGroups.Add(group); group.Temperature = 21f; // initialize life support } } }, "Orbit_Temperature", Handler) .Then(() => { //generate some meteors ShipInteriorMod.Log("Generating meteors..."); int numMeteors = Rand.Range(ShipInteriorMod.instance.meteorMinCount.Value, ShipInteriorMod.instance.meteorMaxCount.Value); for (int i = 0; i < numMeteors; i++) { if (!TryFindCell(out IntVec3 cell, newMap)) { ShipInteriorMod.Log("Nowhere for meteor!?!"); continue; } ShipInteriorMod.Log("Found cell for meteor!"); List <Thing> list = new List <Thing>(); for (int m = 0; m < ShipInteriorMod.instance.meteorSizeMultiplier.Value; m++) { list.AddRange(ThingSetMakerDefOf.Meteorite.root.Generate()); } ShipInteriorMod.Log("Meteor has " + list.Count + " chunks!"); for (int num = list.Count - 1; num >= 0; num--) { ShipInteriorMod.Log("Placing chunk!"); GenPlace.TryPlaceThing(list[num], cell, newMap, ThingPlaceMode.Near, (Thing thing, int count) => { PawnUtility.RecoverFromUnwalkablePositionOrKill(thing.Position, thing.Map); }); } } }, "Orbit_Meteors", Handler) .Then(() => { Current.Game.CurrentMap = newMap; }, "Orbit_Swap", Handler) .Then(() => { foreach (var cell in Find.CurrentMap.areaManager.Home.ActiveCells.ToList()) { if (!Find.CurrentMap.thingGrid.ThingsAt(cell).Any(x => (x.def.building?.shipPart).GetValueOrDefault(false))) { Find.CurrentMap.areaManager.Home[cell] = false; } } foreach (var pawn in Find.CurrentMap.mapPawns.AllPawns.Where(p => p.Faction == Faction.OfPlayer)) { pawn.playerSettings.AreaRestriction = Find.CurrentMap.areaManager.Home; } }, "Orbit_Swap", Handler); //do cool graphic? }