Example #1
0
 public void TryLaunch(RimWorld.Planet.GlobalTargetInfo target, PawnsArriveMode arriveMode, TravelingShipArrivalAction arrivalAction, bool launchedAsSingleShip = false)
 {
     this.timeToLiftoff = 0;
     if (this.parentLandedShip == null)
     {
         this.shipState = ShipState.Outgoing;
         ShipBase_Traveling travelingShip = new ShipBase_Traveling(this, target, arriveMode, arrivalAction);
         GenSpawn.Spawn(travelingShip, this.Position, this.Map);
         this.DeSpawn();
         if (this.LaunchAsFleet)
         {
             foreach (ShipBase current in DropShipUtility.currentShipTracker.ShipsInFleet(this.fleetID))
             {
                 if (current != this)
                 {
                     current.shipState = ShipState.Outgoing;
                     ShipBase_Traveling travelingShip2 = new ShipBase_Traveling(current, target, arriveMode, arrivalAction);
                     GenSpawn.Spawn(travelingShip2, current.Position, current.Map);
                     current.DeSpawn();
                 }
             }
         }
     }
     else
     {
         //      Find.WorldSelector.Select(parentLandedShip);
         TravelingShipsUtility.LaunchLandedFleet(this.parentLandedShip, target.Tile, target.Cell, arriveMode, arrivalAction);
         this.landedShipCached = null;
         //Find.MainTabsRoot.SetCurrentTab(MainButtonDefOf.World, false);
     }
 }
        private void SpawnCaravanAtDestinationTile()
        {
            TravelingShipsUtility.tmpPawns.Clear();
            for (int i = 0; i < this.ships.Count; i++)
            {
                ThingOwner innerContainer = this.ships[i].GetDirectlyHeldThings();
                //    Log.Message("SpawningCaravan");
                //    TravelingShipsUtility.MakepawnInfos(innerContainer);
                for (int j = 0; j < innerContainer.Count; j++)
                {
                    Pawn pawn = innerContainer[j] as Pawn;
                    if (pawn != null)
                    {
                        TravelingShipsUtility.tmpPawns.Add(pawn);
                    }
                }
            }
            int startingTile;

            if (!GenWorldClosest.TryFindClosestPassableTile(this.destinationTile, out startingTile))
            {
                startingTile = this.destinationTile;
            }

            LandedShip landedShip = TravelingShipsUtility.MakeLandedShip(this, this.Faction, startingTile, true);

            this.RemoveAllShip();
            Find.WorldObjects.Remove(this);

            Messages.Message("MessageShipsArrived".Translate(), landedShip, MessageTypeDefOf.NeutralEvent);
        }
Example #3
0
        public static void EnterMapWithShip(LandedShip caravan, Map map, CaravanEnterMode enterMode)
        {
            IntVec3 enterCell = TravelingShipsUtility.CenterCell(map);
            Func <ShipBase, IntVec3> spawnCellGetter = (ShipBase p) => CellFinder.RandomSpawnCellForPawnNear(enterCell, map);

            TravelingShipsUtility.Enter(caravan, map, spawnCellGetter);
        }
Example #4
0
        public static void LaunchLandedFleet(LandedShip landedShip, int destinationTile, IntVec3 destinationCell, PawnsArriveMode pawnArriveMode, TravelingShipArrivalAction arrivalAction)
        {
            if (destinationTile < 0)
            {
                Log.Error("Tried launching landed ship, but its destination tile is " + destinationTile);
                return;
            }

            TravelingShips travelingShips = (TravelingShips)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.TravelingSuborbitalShip);

            travelingShips.Tile = landedShip.Tile;
            travelingShips.SetFaction(landedShip.Faction);
            travelingShips.destinationTile = destinationTile;
            travelingShips.destinationCell = destinationCell;
            //        travelingShips.destinationCell = this.destinationCell;
            travelingShips.arriveMode    = pawnArriveMode;
            travelingShips.arrivalAction = arrivalAction;
            Find.WorldObjects.Add(travelingShips);
            foreach (ShipBase current in landedShip.ships)
            {
                travelingShips.AddShip(current, true);
                //            current.SavePotentialWorldPawns();
                DropShipUtility.ReimbarkWorldPawnsForLandedShip(current);
            }
            travelingShips.SetFaction(landedShip.Faction);
            TravelingShipsUtility.AddAllLandedPawnsToWorld(landedShip);
            if (Find.World.worldObjects.Contains(landedShip))
            {
                Find.World.worldObjects.Remove(landedShip);
            }
        }
Example #5
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            if (this.IsPlayerControlled)
            {
                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.ships[0].StartChoosingDestination(this.ships[0], false);
                };
                yield return(command_Action);

                if (Find.WorldSelector.SingleSelectedObject == this)
                {
                    yield return(TravelingShipsUtility.ShipTouchdownCommand(this, true));

                    yield return(TravelingShipsUtility.ShipTouchdownCommand(this, false));
                }
                FactionBase factionBase = CaravanVisitUtility.FactionBaseVisitedNow(this);
                if (factionBase != null && factionBase.CanTradeNow)
                {
                    yield return(TravelingShipsUtility.TradeCommand(this));
                }
                if (CaravanJourneyDestinationUtility.AnyJurneyDestinationAt(base.Tile))
                {
                    yield return(CaravanJourneyDestinationUtility.TakeOffCommand(base.Tile));
                }
            }
        }
Example #6
0
 public static void MakepawnInfos(ThingContainer container)
 {
     foreach (Thing t in container)
     {
         Pawn pawn = t as Pawn;
         if (pawn != null)
         {
             Log.Message(TravelingShipsUtility.PawnInfoString(pawn));
         }
     }
 }
        public static void Enter(LandedShip caravan, Map map, Func <ShipBase, IntVec3> spawnCellGetter)
        {
            List <ShipBase> ships = caravan.ships;

            DropShipUtility.DropShipGroups(TravelingShipsUtility.CenterCell(map), map, ships, ShipArrivalAction.EnterMapFriendly);
            //caravan.RemoveAllPawns();
            if (caravan.Spawned)
            {
                Find.WorldObjects.Remove(caravan);
            }
        }
        public static void Enter(List <ShipBase> ships, Map map, bool centerDrop = true)
        {
            IntVec3 loc;

            if (centerDrop)
            {
                loc = TravelingShipsUtility.CenterCell(map);
            }
            else
            {
                loc = DropCellFinder.FindRaidDropCenterDistant(map);
            }
            DropShipUtility.DropShipGroups(loc, map, ships, ShipArrivalAction.EnterMapFriendly);
        }
Example #9
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            if (this.IsPlayerControlled)
            {
                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.ships[0].StartChoosingDestination(this.ships[0], false);
                };
                yield return(command_Action);

                if (Find.WorldSelector.SingleSelectedObject == this)
                {
                    yield return(TravelingShipsUtility.ShipTouchdownCommand(this, true));

                    yield return(TravelingShipsUtility.ShipTouchdownCommand(this, false));
                }
                Settlement factionBase = CaravanVisitUtility.SettlementVisitedNow(this);
                if (factionBase != null && factionBase.CanTradeNow)
                {
                    yield return(TravelingShipsUtility.TradeCommand(this));
                }
                if (CaravanJourneyDestinationUtility.AnyJurneyDestinationAt(base.Tile))
                {
                    yield return(CaravanJourneyDestinationUtility.TakeOffCommand(base.Tile));
                }

                if (!this.ships.Any(x => x.ParkingMap == null))
                {
                    Command_Action command_Action4 = new Command_Action();
                    command_Action4.defaultLabel = "CommandTravelParkingPosition".Translate();
                    command_Action4.defaultDesc  = "CommandTravelParkingPositionDesc".Translate();
                    command_Action4.icon         = DropShipUtility.ReturnParkingFleet;
                    command_Action4.action       = delegate
                    {
                        foreach (ShipBase ship in this.ships)
                        {
                            ship.TryLaunch(new GlobalTargetInfo(ship.ParkingPosition, ship.ParkingMap), PawnsArriveMode.CenterDrop, TravelingShipArrivalAction.EnterMapFriendly, false);
                        }
                    };
                    yield return(command_Action4);
                }
            }
        }
Example #10
0
        public static void Settle(LandedShip landedShip, bool settlePermanent = false)
        {
            Faction faction = landedShip.Faction;

            if (faction != Faction.OfPlayer)
            {
                Log.Error("Cannot settle with non-player faction.");
                return;
            }
            MapParent newWorldObject;

            if (settlePermanent)
            {
                newWorldObject = SettleUtility.AddNewHome(landedShip.Tile, faction);
            }
            else
            {
                newWorldObject = (ShipDropSite)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.ShipDropSite);
                newWorldObject.SetFaction(faction);
                newWorldObject.Tile = landedShip.Tile;
                Find.WorldObjects.Add(newWorldObject);
            }
            LongEventHandler.QueueLongEvent(delegate
            {
                IntVec3 vec3;
                if (settlePermanent)
                {
                    vec3 = Find.World.info.initialMapSize;
                }
                else
                {
                    vec3 = new IntVec3(100, 1, 100);
                }
                Map visibleMap          = MapGenerator.GenerateMap(vec3, landedShip.Tile, newWorldObject, null, null);
                Current.Game.VisibleMap = visibleMap;
            }, "GeneratingMap", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap));
            LongEventHandler.QueueLongEvent(delegate
            {
                Map map   = newWorldObject.Map;
                Pawn pawn = landedShip.PawnsListForReading[0];
                Predicate <IntVec3> extraCellValidator = (IntVec3 x) => x.GetRegion(map).CellCount >= 600;
                TravelingShipsUtility.EnterMapWithShip(landedShip, map, CaravanEnterMode.Center);
                Find.CameraDriver.JumpTo(map.Center);
                Find.MainTabsRoot.EscapeCurrentTab(false);
            }, "SpawningColonists", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap));
        }
Example #11
0
        public static void Enter(List <ShipBase> ships, Map map, bool centerDrop = true)
        {
            foreach (ShipBase ship in ships)
            {
                DropShipUtility.ReimbarkWorldPawnsForLandedShip(ship);
            }
            IntVec3 loc;

            if (centerDrop)
            {
                loc = TravelingShipsUtility.CenterCell(map);
            }
            else
            {
                loc = DropCellFinder.FindRaidDropCenterDistant(map);
            }
            DropShipUtility.DropShipGroups(loc, map, ships, TravelingShipArrivalAction.EnterMapFriendly);
        }
Example #12
0
        public static Command ShipTouchdownCommand(LandedShip landedShip, 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.TickHigh.PlayOneShotOnCamera();
                TravelingShipsUtility.Settle(landedShip, 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 == landedShip.Tile && worldObject != landedShip)
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                command_Settle.Disable("CommandSettleFailOtherWorldObjectsHere".Translate());
            }
            else if (settlePermanent && SettleUtility.PlayerHomesCountLimitReached)
            {
                if (Prefs.MaxNumberOfPlayerHomes > 1)
                {
                    command_Settle.Disable("CommandSettleFailReachedMaximumNumberOfBases".Translate());
                }
                else
                {
                    command_Settle.Disable("CommandSettleFailAlreadyHaveBase".Translate());
                }
            }
            return(command_Settle);
        }
        private void Arrived()
        {
            if (this.arrived)
            {
                return;
            }

            this.arrived = true;
            if (TravelingShipsUtility.TryAddToLandedFleet(this, this.destinationTile))
            {
                return;
            }
            if (this.arrivalAction == ShipArrivalAction.BombingRun)
            {
                MapParent parent = Find.World.worldObjects.MapParentAt(this.destinationTile);
                if (parent != null)
                {
                    Messages.Message("MessageBombedSettlement".Translate(new object[] { parent.ToString(), parent.Faction.Name }), parent, MessageTypeDefOf.NeutralEvent);
                    Find.World.worldObjects.Remove(parent);
                }
                this.SwitchOriginToDest();

                //TravelingShips travelingShips = (TravelingShips)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.TravelingSuborbitalShip);
                //travelingShips.ships.AddRange(this.ships);
                //travelingShips.Tile = this.destinationTile;
                //travelingShips.SetFaction(Faction.OfPlayer);
                //travelingShips.destinationTile = this.initialTile;
                //travelingShips.destinationCell = this.launchCell;
                //travelingShips.arriveMode = this.arriveMode;
                //travelingShips.arrivalAction = TravelingShipArrivalAction.EnterMapFriendly;
                //Find.WorldObjects.Add(travelingShips);
                //Find.WorldObjects.Remove(this);
            }
            else if (arrivalAction == ShipArrivalAction.Despawn)
            {
                this.Destroy();
            }
            else
            {
                Map map = Current.Game.FindMap(this.destinationTile);
                if (map != null)
                {
                    this.SpawnShipsInMap(map, null);
                }
                else if (!this.LandedShipHasCaravanOwner)
                {
                    for (int i = 0; i < this.ships.Count; i++)
                    {
                        this.ships[i].GetDirectlyHeldThings().ClearAndDestroyContentsOrPassToWorld(DestroyMode.Vanish);
                    }
                    this.RemoveAllShip();
                    Find.WorldObjects.Remove(this);
                    Messages.Message("MessageTransportPodsArrivedAndLost".Translate(), new GlobalTargetInfo(this.destinationTile), MessageTypeDefOf.NegativeEvent);
                }
                else
                {
                    Settlement Settlement = Find.WorldObjects.Settlements.Find((Settlement x) => x.Tile == this.destinationTile);

                    if (Settlement != null && Settlement.Faction != Faction.OfPlayer && this.arrivalAction != ShipArrivalAction.StayOnWorldMap)
                    {
                        LongEventHandler.QueueLongEvent(delegate
                        {
                            Map map2 = GetOrGenerateMapUtility.GetOrGenerateMap(Settlement.Tile, Find.World.info.initialMapSize, null);;

                            string extraMessagePart = null;
                            if (this.arrivalAction == ShipArrivalAction.EnterMapAssault && !Settlement.Faction.HostileTo(Faction.OfPlayer))
                            {
                                Settlement.Faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile);
                                extraMessagePart = "MessageTransportPodsArrived_BecameHostile".Translate(new object[]
                                {
                                    Settlement.Faction.Name
                                }).CapitalizeFirst();
                            }
                            Find.TickManager.CurTimeSpeed = TimeSpeed.Paused;
                            Current.Game.CurrentMap       = map2;
                            Find.CameraDriver.JumpToCurrentMapLoc(map2.Center);
                            this.SpawnShipsInMap(map2, extraMessagePart);
                        }, "GeneratingMapForNewEncounter", false, null);
                    }
                    else
                    {
                        this.SpawnCaravanAtDestinationTile();
                    }
                }
            }
        }
 public static void EnterMapWithShip(WorldShip worldShip, Map map, IntVec3 targetCell, ShipArrivalAction arrivalAction, PawnsArrivalModeDef pawnsArrivalMode)
 {
     TravelingShipsUtility.Enter(worldShip, map, targetCell, arrivalAction, pawnsArrivalMode);
 }
Example #15
0
        private void Arrived()
        {
            if (this.arrived)
            {
                return;
            }

            this.arrived = true;
            if (TravelingShipsUtility.TryAddToLandedFleet(this, this.destinationTile))
            {
                return;
            }
            if (this.arrivalAction == TravelingShipArrivalAction.BombingRun)
            {
                TravelingShips travelingShips = (TravelingShips)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.TravelingSuborbitalShip);
                travelingShips.Tile = this.destinationTile;
                travelingShips.SetFaction(Faction.OfPlayer);
                travelingShips.destinationTile = this.initialTile;
                travelingShips.destinationCell = this.launchCell;
                travelingShips.arriveMode      = this.arriveMode;
                travelingShips.arrivalAction   = TravelingShipArrivalAction.EnterMapFriendly;
                Find.WorldObjects.Add(travelingShips);
                Find.WorldObjects.Remove(this);
            }
            else
            {
                Map map = Current.Game.FindMap(this.destinationTile);
                if (map != null)
                {
                    this.SpawnShipsInMap(map, null);
                }
                else if (!this.LandedShipHasCaravanOwner)
                {
                    for (int i = 0; i < this.ships.Count; i++)
                    {
                        this.ships[i].GetInnerContainer().ClearAndDestroyContentsOrPassToWorld(DestroyMode.Vanish);
                    }
                    this.RemoveAllPods();
                    Find.WorldObjects.Remove(this);
                    Messages.Message("MessageTransportPodsArrivedAndLost".Translate(), new GlobalTargetInfo(this.destinationTile), MessageSound.Negative);
                }
                else
                {
                    FactionBase factionBase = Find.WorldObjects.FactionBases.Find((FactionBase x) => x.Tile == this.destinationTile);

                    if (factionBase != null && factionBase.Faction != Faction.OfPlayer && this.arrivalAction != TravelingShipArrivalAction.StayOnWorldMap)
                    {
                        LongEventHandler.QueueLongEvent(delegate
                        {
                            Map map2 = AttackCaravanArrivalActionUtility.GenerateFactionBaseMap(factionBase);

                            string extraMessagePart = null;
                            if (this.arrivalAction == TravelingShipArrivalAction.EnterMapAssault && !factionBase.Faction.HostileTo(Faction.OfPlayer))
                            {
                                factionBase.Faction.SetHostileTo(Faction.OfPlayer, true);
                                extraMessagePart = "MessageTransportPodsArrived_BecameHostile".Translate(new object[]
                                {
                                    factionBase.Faction.Name
                                }).CapitalizeFirst();
                            }
                            Find.TickManager.CurTimeSpeed = TimeSpeed.Paused;
                            Current.Game.VisibleMap       = map2;
                            Find.CameraDriver.JumpTo(map2.Center);
                            this.SpawnShipsInMap(map2, extraMessagePart);
                        }, "GeneratingMapForNewEncounter", false, null);
                    }
                    else
                    {
                        this.SpawnCaravanAtDestinationTile();
                    }
                }
            }
        }
Example #16
0
 public static void EnterMapWithShip(LandedShip caravan, Map map)
 {
     TravelingShipsUtility.ReimbarkPawnsFromLandedShip(caravan);
     TravelingShipsUtility.Enter(caravan, map);
 }