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); } }
public static Command TradeCommand(LandedShip caravan) { //Pawn bestNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan); //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 = CaravanVisitUtility.SettlementVisitedNow(caravan); // if (Settlement != null && Settlement.CanTradeNow) // { // caravan.UnloadCargoForTrading(); // //Find.WindowStack.Add(new Dialog_TradeFromShips(caravan, bestNegotiator, Settlement)); // Find.WindowStack.Add(new Dialog_TradeFromShips(this, 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; return(null); }
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); }
public static bool AllInventoryItemsPrefix(ref Caravan caravan, ref List <Thing> __result) { __result = new List <Thing>(); List <Pawn> pawnsListForReading = caravan.PawnsListForReading; for (int i = 0; i < pawnsListForReading.Count; i++) { Pawn pawn = pawnsListForReading[i]; for (int j = 0; j < pawn.inventory.innerContainer.Count; j++) { Thing item = pawn.inventory.innerContainer[j]; __result.Add(item); } } LandedShip landedShip = caravan as LandedShip; Predicate <Thing> cargoValidator = delegate(Thing t) { Pawn pawn = t as Pawn; if (pawn != null) { if (pawn.IsColonist || pawn.records.GetAsInt(RecordDefOf.TimeAsColonistOrColonyAnimal) > 0) { return(false); } } return(true); }; if (landedShip != null) { __result.AddRange(landedShip.AllLandedShipCargo.Where(x => cargoValidator(x))); } return(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); }
public static Command TradeCommand(LandedShip caravan) { Pawn bestNegotiator = CaravanVisitUtility.BestNegotiator(caravan); 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 { FactionBase factionBase = CaravanVisitUtility.FactionBaseVisitedNow(caravan); if (factionBase != null && factionBase.CanTradeNow) { caravan.UnloadCargoForTrading(); Find.WindowStack.Add(new Dialog_TradeFromShips(caravan, bestNegotiator, factionBase)); string empty = string.Empty; string empty2 = string.Empty; PawnRelationUtility.Notify_PawnsSeenByPlayer(factionBase.Goods.OfType <Pawn>(), ref empty, ref empty2, "LetterRelatedPawnsTradingWithFactionBase".Translate(), false); if (!empty2.NullOrEmpty()) { Find.LetterStack.ReceiveLetter(empty, empty2, LetterType.Good, factionBase, null); } } }; if (bestNegotiator == null) { command_Action.Disable("CommandTradeFailNoNegotiator".Translate()); } return(command_Action); }
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); } }
public static bool AutoOrderToTileNowPrefix(Caravan c, int tile) { LandedShip ship = c as LandedShip; if (ship != null) { return(false); } return(true); }
public static void AddAllLandedPawnsToWorld(LandedShip landedShip) { for (int i = 0; i < landedShip.PawnsListForReading.Count; i++) { Pawn pawn = landedShip.PawnsListForReading[i]; if (!Find.WorldPawns.Contains(pawn)) { Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); } } }
public static void RemoveLandedShipPawns(LandedShip landedShip) { for (int i = 0; i < landedShip.PawnsListForReading.Count; i++) { Pawn pawn = landedShip.PawnsListForReading[i]; if (Find.WorldPawns.Contains(pawn)) { Find.WorldPawns.RemovePawn(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(LandedShip caravan, Map map) { List <ShipBase> ships = caravan.ships; IntVec3 randomEdgeCell = CellFinder.RandomEdgeCell(map); IntVec3 randomSpawnEdgeCell = new IntVec3(); DropShipUtility.TryFindShipDropLocationNear(randomEdgeCell, 100, map, out randomSpawnEdgeCell, new IntVec2(4, 4)); DropShipUtility.DropShipGroups(randomSpawnEdgeCell, map, ships, TravelingShipArrivalAction.EnterMapFriendly); if (caravan.Spawned) { Find.WorldObjects.Remove(caravan); } }
public static void ReimbarkPawnsFromLandedShip(LandedShip landedShip) { foreach (KeyValuePair <ShipBase, List <string> > entry in landedShip.shipsPassengerList) { List <Pawn> caravanPassengers = new List <Pawn>(); caravanPassengers.AddRange(landedShip.PawnsListForReading); for (int i = 0; i < caravanPassengers.Count; i++) { if (entry.Value.Contains(caravanPassengers[i].ThingID)) { landedShip.pawns.TryTransferToContainer(caravanPassengers[i], entry.Key.GetDirectlyHeldThings(), true); } } } }
public static void ReimbarkPawnsFromLandedShip(LandedShip landedShip) { foreach (KeyValuePair <ShipBase, List <string> > entry in landedShip.shipsPassengerList) { List <Pawn> caravanPassengers = new List <Pawn>(); caravanPassengers.AddRange(landedShip.PawnsListForReading); for (int i = 0; i < caravanPassengers.Count; i++) { if (entry.Value.Contains(caravanPassengers[i].ThingID)) { entry.Key.TryAcceptThing(caravanPassengers[i]); } } } }
public static void DistributePawnsOnShips(LandedShip landedObject) { List <ShipBase> ships = landedObject.ships; while (landedObject.PawnsListForReading.Count > 0) { for (int i = 0; i < landedObject.PawnsListForReading.Count; i++) { ships.RandomElement().TryAcceptThing(landedObject.PawnsListForReading[i]); landedObject.RemovePawn(landedObject.PawnsListForReading[i]); } } while (landedObject.Goods.Count() > 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)); }
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); }
public static bool TryAddToLandedFleet(TravelingShips incomingShips, int tile) { if (tile >= 0) { LandedShip landedFleet = Find.World.worldObjects.AllWorldObjects.FirstOrDefault(x => x.Tile == tile && x.def == ShipNamespaceDefOfs.LandedShip) as LandedShip; if (landedFleet != null) { for (int i = 0; i < incomingShips.ships.Count; i++) { ShipBase ship = incomingShips.ships[i]; if (landedFleet.ships[0].fleetID == ship.fleetID) { landedFleet.ships.Add(ship); incomingShips.ships.Remove(ship); } } } } return(false); }
public static void SetupShipTrading(LandedShip landedShip) { List <Pawn> allPawns = new List <Pawn>(); foreach (ShipBase current in landedShip.ships) { allPawns = DropShipUtility.AllPawnsInShip(current); for (int k = 0; k < allPawns.Count; k++) { ThingContainer innerContainer2 = current.GetInnerContainer(); for (int l = 0; l < innerContainer2.Count; l++) { if (!(innerContainer2[l] is Pawn)) { Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(innerContainer2[l], allPawns, null, null); pawn2.inventory.innerContainer.TryAdd(innerContainer2[l], true); } } } } }
public static void EnterMapWithShip(LandedShip caravan, Map map) { TravelingShipsUtility.ReimbarkPawnsFromLandedShip(caravan); TravelingShipsUtility.Enter(caravan, map); }
public Dialog_TradeFromShips(LandedShip landedShip, Pawn playerNegotiator, ITrader trader) : base(playerNegotiator, trader) { this.landedShip = landedShip; }
public static LandedShip MakeLandedShip(TravelingShips incomingShips, Faction faction, int startingTile, bool addToWorldPawnsIfNotAlready) { // TravelingShipsUtility.MakepawnInfos(incomingShips.ships[0].GetDirectlyHeldThings()); if (startingTile < 0 && addToWorldPawnsIfNotAlready) { Log.Warning("Tried to create a caravan but chose not to spawn a caravan but pass pawns to world. This can cause bugs because pawns can be discarded."); } TravelingShipsUtility.tmpPawns.Clear(); TravelingShipsUtility.tmpPawns.AddRange(incomingShips.Pawns); LandedShip caravan = (LandedShip)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.LandedShip); if (startingTile >= 0) { caravan.Tile = startingTile; } caravan.SetFaction(faction); if (startingTile >= 0) { Find.WorldObjects.Add(caravan); } foreach (ShipBase current in incomingShips.ships) { // current.shouldDeepSave = false; List <Thing> passengers = current.GetDirectlyHeldThings().ToList(); List <string> passengerIDs = new List <string>(); for (int i = 0; i < passengers.Count; i++) { Pawn pawn = passengers[i] as Pawn; if (pawn != null) { if (pawn.Dead) { Log.Warning("Tried to form a caravan with a dead pawn " + pawn); } else { passengerIDs.Add(pawn.ThingID); //pawn.holdingOwner = null; current.GetDirectlyHeldThings().Remove(pawn); caravan.AddPawn(pawn, addToWorldPawnsIfNotAlready); if (addToWorldPawnsIfNotAlready && !pawn.IsWorldPawn()) { if (pawn.Spawned) { pawn.DeSpawn(); } Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); } } } } caravan.shipsPassengerList.Add(current, passengerIDs); } string name; if (incomingShips.ships[0].fleetID != -1 && DropShipUtility.currentShipTracker.PlayerFleetManager.ContainsKey(incomingShips.ships[0].fleetID)) { name = DropShipUtility.currentShipTracker.PlayerFleetManager[incomingShips.ships[0].fleetID]; } else { name = incomingShips.ships[0].ShipNick; } caravan.Name = name; caravan.ships.AddRange(incomingShips.ships); foreach (ShipBase ship in caravan.ships) { //DropShipUtility.PassWorldPawnsForLandedShip(ship); } return(caravan); }
public static LandedShip MakeLandedShip(TravelingShips incomingShips, Faction faction, int startingTile, bool addToWorldPawnsIfNotAlready) { // Log.Message("Making LandedShip"); // TravelingShipsUtility.MakepawnInfos(incomingShips.ships[0].GetInnerContainer()); if (startingTile < 0 && addToWorldPawnsIfNotAlready) { Log.Warning("Tried to create a caravan but chose not to spawn a caravan but pass pawns to world. This can cause bugs because pawns can be discarded."); } TravelingShipsUtility.tmpPawns.Clear(); TravelingShipsUtility.tmpPawns.AddRange(incomingShips.Pawns); LandedShip caravan = (LandedShip)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.LandedShip); if (startingTile >= 0) { caravan.Tile = startingTile; } caravan.SetFaction(faction); if (startingTile >= 0) { Find.WorldObjects.Add(caravan); } for (int i = 0; i < TravelingShipsUtility.tmpPawns.Count; i++) { Pawn pawn = TravelingShipsUtility.tmpPawns[i]; if (pawn.Dead) { Log.Warning("Tried to form a caravan with a dead pawn " + pawn); } else { caravan.AddPawn(pawn, addToWorldPawnsIfNotAlready); if (addToWorldPawnsIfNotAlready && !pawn.IsWorldPawn()) { if (pawn.Spawned) { pawn.DeSpawn(); } Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); } } } string name; if (incomingShips.ships[0].fleetID != -1 && DropShipUtility.currentShipTracker.PlayerFleetManager.ContainsKey(incomingShips.ships[0].fleetID)) { name = DropShipUtility.currentShipTracker.PlayerFleetManager[incomingShips.ships[0].fleetID]; } else { name = incomingShips.ships[0].ShipNick; } caravan.Name = name; caravan.ships.AddRange(incomingShips.ships); foreach (ShipBase ship in caravan.ships) { DropShipUtility.PassWorldPawnsForLandedShip(ship); } return(caravan); }