Exemple #1
0
        public static Command TradeCommand(WorldShip worldShip)
        {
            Pawn           bestNegotiator = BestNegotiator(worldShip);
            Command_Action command_Action = new Command_Action();

            command_Action.defaultLabel = "CommandTrade".Translate();
            command_Action.defaultDesc  = "CommandTradeDesc".Translate();
            command_Action.icon         = DropShipUtility.TradeCommandTex;
            command_Action.action       = delegate
            {
                SettlementBase Settlement = (SettlementBase)Find.WorldObjects.SettlementBaseAt(worldShip.Tile);
                if (Settlement != null && Settlement.CanTradeNow)
                {
                    //caravan.UnloadCargoForTrading();
                    //Find.WindowStack.Add(new Dialog_TradeFromShips(caravan, bestNegotiator, Settlement));
                    Find.WindowStack.Add(new Dialog_TradeFromShips(worldShip, bestNegotiator, Settlement));
                    string empty  = string.Empty;
                    string empty2 = string.Empty;
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(Settlement.Goods.OfType <Pawn>(), ref empty, ref empty2, "LetterRelatedPawnsTradingWithSettlement".Translate(), false);
                    if (!empty2.NullOrEmpty())
                    {
                        Find.LetterStack.ReceiveLetter(empty, empty2, LetterDefOf.PositiveEvent, Settlement, null);
                    }
                }
            };
            if (bestNegotiator == null)
            {
                command_Action.Disable("CommandTradeFailNoNegotiator".Translate());
            }
            return(command_Action);
        }
Exemple #2
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.parentShipCached = null;
            //this.shouldDeepSave = true;
            this.DeepsaveTurrets = false;
            if (shouldSpawnTurrets)
            {
                foreach (KeyValuePair <ShipWeaponSlot, Building_ShipTurret> current in this.installedTurrets)
                {
                    if (current.Value != null && !current.Value.Spawned)
                    {
                        IntVec3 drawLoc = this.Position + DropShipUtility.AdjustedIntVecForShip(this, current.Key.turretPosOffset);
                        GenSpawn.Spawn(current.Value, drawLoc, this.Map);
                    }
                }
            }
            this.shouldSpawnTurrets = false;
            if (shipState == ShipState.Incoming)
            {
                SoundDef.Named("ShipTakeoff_SuborbitalLaunch").PlayOneShotOnCamera();
            }

            if (this.ShouldSpawnFueled)
            {
                this.refuelableComp.Refuel(800);
                this.ShouldSpawnFueled = false;
            }
            DropShipUtility.InitializeDropShipSpawn(this);
            this.FirstSpawned = false;
        }
        public static bool AllInventoryItemsPrefix(ref SettlementBase_TraderTracker __instance, ref IEnumerable <Thing> __result, Pawn playerNegotiator)
        {
            WorldShip worldShip = playerNegotiator.GetWorldShip();

            if (worldShip != null)
            {
                Predicate <Thing> cargoValidator = delegate(Thing t)
                {
                    Pawn pawn = t as Pawn;
                    if (pawn != null)
                    {
                        if (pawn.IsColonist || (pawn.records.GetAsInt(RecordDefOf.TimeAsColonistOrColonyAnimal) > 0 && pawn.records.GetAsInt(RecordDefOf.TimeAsPrisoner) == 0))
                        {
                            return(false);
                        }
                    }
                    return(true);
                };
                List <Thing> newResult = new List <Thing>();
                foreach (var data in worldShip.WorldShipData)
                {
                    foreach (Thing t in data.Ship.GetDirectlyHeldThings().Where(x => cargoValidator(x)))
                    {
                        newResult.Add(t);
                    }
                }
                __result = newResult;
                return(false);
            }
            return(true);
        }
Exemple #4
0
 private static void NotifySettlementBombed(Faction targetFaction, WorldShip worldShip)
 {
     Messages.Message("MessageBombedSettlement".Translate(), worldShip, MessageTypeDefOf.ThreatSmall);
     foreach (var faction in Find.FactionManager.AllFactionsVisible)
     {
         if (faction.RelationKindWith(targetFaction) != FactionRelationKind.Hostile)
         {
             faction.RelationWith(worldShip.Faction).goodwill -= 5;
         }
     }
 }
Exemple #5
0
        private static void Enter(WorldShip worldShip, Map map, IntVec3 targetCell, ShipArrivalAction arrivalAction, PawnsArrivalModeDef pawnsArrivalMode)
        {
            List <ShipBase> ships = worldShip.WorldShipData.Select(x => x.Ship).ToList();
            IntVec3         cell  = GetCellForArrivalMode(worldShip.WorldShipData[0].Ship, targetCell, map, pawnsArrivalMode);

            DropShipUtility.DropShipGroups(cell, map, ships, arrivalAction, worldShip.WorldShipData.Count == 1);
            if (worldShip.Spawned)
            {
                Find.WorldObjects.Remove(worldShip);
            }
        }
        public static bool GiveSoldThingToPlayerPrefix(ref SettlementBase_TraderTracker __instance, Thing toGive, int countToGive, Pawn playerNegotiator)
        {
            WorldShip worldShip = playerNegotiator.GetWorldShip();

            if (worldShip != null)
            {
                Thing thing = toGive.SplitOff(countToGive);
                thing.PreTraded(TradeAction.PlayerBuys, playerNegotiator, __instance.settlement);
                worldShip.trader.GiveSoldThingToPlayer(toGive, countToGive, playerNegotiator);

                return(false);
            }
            return(true);
        }
        public static void CheckGameOverPostfix()
        {
            //Log.Error("5");
            List <WorldShip> travelingShips = Find.WorldObjects.AllWorldObjects.FindAll(x => x is WorldShip).Cast <WorldShip>().ToList();

            for (int i = 0; i < travelingShips.Count; i++)
            {
                WorldShip ship = travelingShips[i];
                if (ship.WorldShipData.Any(x => x.Passengers.Any(y => y.IsColonist)))
                {
                    Find.GameEnder.gameEnding = false;
                }
            }
        }
Exemple #8
0
        private static Pawn BestNegotiator(WorldShip worldShip)
        {
            IEnumerable <Pawn> pawns = worldShip.WorldShipData.SelectMany(d => d.Passengers);
            Pawn negotiator          = null;
            int  maxSocialSkill      = 0;
            int  currentSocialSkill;

            foreach (Pawn pawn in pawns)
            {
                currentSocialSkill = pawn.skills.GetSkill(SkillDefOf.Social).Level;
                if (currentSocialSkill > maxSocialSkill)
                {
                    maxSocialSkill = currentSocialSkill;
                    negotiator     = pawn;
                }
            }
            return(negotiator);
        }
        public static bool GiveSoldThingToTraderPrefix(ref Settlement_TraderTracker __instance, Thing toGive, int countToGive, Pawn playerNegotiator)
        {
            WorldShip worldShip = playerNegotiator.GetWorldShip();

            if (worldShip != null)
            {
                Thing thing = toGive.SplitOff(countToGive);
                var   init  = __instance.StockListForReading.Count;
                thing.PreTraded(TradeAction.PlayerSells, playerNegotiator, __instance.settlement);
                if (!__instance.GetDirectlyHeldThings().TryAdd(thing, false))
                {
                    thing.Destroy(DestroyMode.Vanish);
                }

                return(false);
            }

            return(true);
        }
Exemple #10
0
        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);
        }
        private void ShipsLeaving()
        {
            WorldShip worldShip = (WorldShip)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.WorldShip);

            worldShip.SetFaction(this.containingShip.Faction);
            worldShip.Tile = this.Map.Tile;
            worldShip.AddShip(this.containingShip, true);
            Find.World.worldObjects.Add(worldShip);
            Predicate <Thing> predicate = delegate(Thing t)
            {
                if (t != this)
                {
                    if (t is ShipBase_Traveling)
                    {
                        ShipBase_Traveling ship = (ShipBase_Traveling)t;
                        if (ship.containingShip.shipState == ShipState.Outgoing)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            };
            List <Thing> tmpleavingShips = base.Map.listerThings.AllThings.FindAll(x => predicate(x));

            for (int i = 0; i < tmpleavingShips.Count; i++)
            {
                ShipBase_Traveling dropPodLeaving = tmpleavingShips[i] as ShipBase_Traveling;
                if (dropPodLeaving != null && dropPodLeaving.fleetID == this.fleetID)
                {
                    dropPodLeaving.alreadyLeft = true;
                    worldShip.AddShip(dropPodLeaving.containingShip, true);
                    dropPodLeaving.Destroy(DestroyMode.Vanish);
                }
            }

            worldShip.Launch(this.destinationTile, this.destinationCell, arrivalAction, pawnArriveMode);
            this.DeSpawn();
        }
Exemple #12
0
        public static bool TryBombWorldTarget(int targetTile, WorldShip worldShip)
        {
            MapParent parent = Find.WorldObjects.WorldObjectAt <MapParent>(targetTile);

            if (parent != null)
            {
                if (parent.HasMap)
                {
                    return(BombingUtility.BombingRunOnMapCenter(parent.Map));
                }
                else
                {
                    Find.World.worldObjects.Remove(parent);
                }

                foreach (var data in worldShip.WorldShipData)
                {
                    ShipBase ship = data.Ship;
                    ship.loadedBombs.ForEach(c => c.Discard(true));
                }
            }
            return(false);
        }
Exemple #13
0
 public WorldShipPather(WorldShip worldShip)
 {
     this._worldShip = worldShip;
 }
Exemple #14
0
 public Dialog_TradeFromShips(WorldShip landedShip, Pawn playerNegotiator, ITrader trader) : base(playerNegotiator, trader)
 {
     this.worldShip = landedShip;
 }
Exemple #15
0
        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));
        }
Exemple #16
0
 public WorldShipTrader(WorldShip worldShip)
 {
     this._worldShip = worldShip;
 }
 public static void EnterMapWithShip(WorldShip worldShip, Map map, IntVec3 targetCell, ShipArrivalAction arrivalAction, PawnsArrivalModeDef pawnsArrivalMode)
 {
     TravelingShipsUtility.Enter(worldShip, map, targetCell, arrivalAction, pawnsArrivalMode);
 }