internal void Arrive(IntVec3 targetCell, ShipArrivalAction arrivalAction, PawnsArrivalModeDef mapArrivalMode) { if (this.IsPlayerControlled && arrivalAction != ShipArrivalAction.BombingRun) { Messages.Message("MessageShipsArrived".Translate(), this, MessageTypeDefOf.NeutralEvent); } if (arrivalAction == ShipArrivalAction.EnterMapAssault || arrivalAction == ShipArrivalAction.EnterMapFriendly) { MapParent parent = Find.WorldObjects.MapParentAt(this.Tile); if (parent != null) { Map map = parent.Map; if (map == null) { LongEventHandler.QueueLongEvent(delegate { MapGeneratorDef def = WorldShipUtility.GetMapGeneratorDefForObject(parent); map = MapGenerator.GenerateMap(Find.World.info.initialMapSize, parent, MapGeneratorDefOf.Base_Faction); targetCell = IntVec3.Zero; }, "GeneratingMap", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap)); } LongEventHandler.QueueLongEvent(delegate { WorldShipUtility.EnterMapWithShip(this, map, targetCell, arrivalAction, mapArrivalMode); }, "SpawningColonists", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap)); } } else if (arrivalAction == ShipArrivalAction.BombingRun) { if (BombingUtility.TryBombWorldTarget(this.Tile, this)) { } } }
public static Command ShipTouchdownCommand(WorldShip worldShip, bool settlePermanent = false) { string comtitle = settlePermanent ? "CommandSettle".Translate() : "CommandShipTouchdown".Translate(); string comdesc = settlePermanent ? "CommandSettleDesc".Translate() : "CommandShipTouchdownDesc".Translate(); Command_Settle command_Settle = new Command_Settle(); command_Settle.defaultLabel = comtitle; command_Settle.defaultDesc = comdesc; command_Settle.icon = settlePermanent ? SettleUtility.SettleCommandTex : DropShipUtility.TouchDownCommandTex; command_Settle.action = delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); WorldShipUtility.Settle(worldShip, settlePermanent); }; bool flag = false; List <WorldObject> allWorldObjects = Find.WorldObjects.AllWorldObjects; for (int i = 0; i < allWorldObjects.Count; i++) { WorldObject worldObject = allWorldObjects[i]; if ((worldObject.Tile == worldShip.Tile && worldObject != worldShip && settlePermanent)) { flag = true; break; } } if (flag) { command_Settle.Disable("CommandSettleFailOtherWorldObjectsHere".Translate()); } else if (settlePermanent && SettleUtility.PlayerSettlementsCountLimitReached) { if (Prefs.MaxNumberOfPlayerSettlements > 1) { command_Settle.Disable("CommandSettleFailReachedMaximumNumberOfBases".Translate()); } else { command_Settle.Disable("CommandSettleFailAlreadyHaveBase".Translate()); } } return(command_Settle); }
public static void EnterMapWithShip(WorldShip worldShip, Map map, IntVec3 targetCell, ShipArrivalAction arrivalAction, PawnsArrivalModeDef pawnsArrivalMode) { WorldShipUtility.Enter(worldShip, map, targetCell, arrivalAction, pawnsArrivalMode); }
public static void Settle(WorldShip worldShip, bool settlePermanent = false) { Faction faction = worldShip.Faction; PawnsArrivalModeDef arrivalMode = PawnsArrivalModeDefOf.CenterDrop; if (faction != Faction.OfPlayer) { Log.Error("Cannot settle with non-player faction."); return; } MapParent newWorldObject; Map mapToDropIn = null; if (settlePermanent) { newWorldObject = SettleUtility.AddNewHome(worldShip.Tile, faction); } else { newWorldObject = Find.WorldObjects.MapParentAt(worldShip.Tile); if (newWorldObject == null) { newWorldObject = (ShipDropSite)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.ShipDropSite); newWorldObject.SetFaction(faction); newWorldObject.Tile = worldShip.Tile; Find.WorldObjects.Add(newWorldObject); } } LongEventHandler.QueueLongEvent(delegate { IntVec3 vec3; if (settlePermanent) { vec3 = Find.World.info.initialMapSize; mapToDropIn = MapGenerator.GenerateMap(vec3, newWorldObject, MapGeneratorDefOf.Base_Player, null, null); } else if (newWorldObject != null) { if (newWorldObject.HasMap) { arrivalMode = PawnsArrivalModeDefOf.EdgeDrop; mapToDropIn = newWorldObject.Map; } else { Site site = newWorldObject as Site; mapToDropIn = GetOrGenerateMapUtility.GetOrGenerateMap(worldShip.Tile, site == null ? Find.World.info.initialMapSize : SiteCoreWorker.MapSize, newWorldObject.def); arrivalMode = PawnsArrivalModeDefOf.EdgeDrop; } } else { vec3 = new IntVec3(100, 1, 100); mapToDropIn = MapGenerator.GenerateMap(vec3, newWorldObject, MapGeneratorDefOf.Base_Player, null, null); } if (mapToDropIn == null) { Log.Error("Failed to generate Map for Ship Dropdown"); return; } Current.Game.CurrentMap = mapToDropIn; }, "GeneratingMap", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap)); LongEventHandler.QueueLongEvent(delegate { Map map = newWorldObject.Map; WorldShipUtility.EnterMapWithShip(worldShip, map, IntVec3.Zero, ShipArrivalAction.EnterMapFriendly, arrivalMode); Find.CameraDriver.JumpToCurrentMapLoc(map.Center); Find.MainTabsRoot.EscapeCurrentTab(false); }, "SpawningColonists", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap)); }
public override IEnumerable <Gizmo> GetGizmos() { for (int i = 0; i < this.AllComps.Count; i++) { foreach (Gizmo gizmo in this.AllComps[i].GetGizmos()) { yield return(gizmo); } } if (this.IsPlayerControlled) { if (Find.WorldSelector.SingleSelectedObject == this) { yield return(WorldShipUtility.ShipTouchdownCommand(this, true)); yield return(WorldShipUtility.ShipTouchdownCommand(this, false)); Command_Action command_Action = new Command_Action(); command_Action.defaultLabel = "CommandLaunchShip".Translate(); command_Action.defaultDesc = "CommandLaunchShipDesc".Translate(); command_Action.icon = DropShipUtility.LaunchSingleCommandTex; command_Action.action = delegate { SoundDef.Named("ShipTakeoff_SuborbitalLaunch").PlayOneShotOnCamera(); this.IsTargeting = true; this.WorldShipData.FirstOrDefault().Ship.StartChoosingDestination(false); }; yield return(command_Action); } SettlementBase Settlement = (Settlement)Find.WorldObjects.SettlementAt(this.Tile); if (Settlement != null && Settlement.CanTradeNow) { yield return(WorldShipUtility.TradeCommand(this)); } if (this.pather.Moving) { yield return(new Command_Action { hotKey = KeyBindingDefOf.Misc1, action = delegate { if (!this.pather.Moving) { return; } this.pather.ToggleCircling(); }, defaultDesc = "CommandWorldShipHoldDesc".Translate(2f.ToString("0.#"), 0.3f.ToStringPercent()), icon = TexCommand.PauseCaravan, defaultLabel = "CommandWorldShipHold".Translate() }); yield return(new Command_Action { hotKey = KeyBindingDefOf.Misc1, action = delegate { if (!this.pather.Moving) { return; } this.pather.Halt(); }, defaultDesc = "CommandWorldShipHaltDesc".Translate(2f.ToString("0.#"), 0.3f.ToStringPercent()), icon = TexCommand.PauseCaravan, defaultLabel = "CommandWorldShipHalt".Translate() }); } } }