private bool TrySplitCaravan() { List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(this.transferables); if (!this.CheckForErrors(pawnsFromTransferables)) { return(false); } for (int i = 0; i < pawnsFromTransferables.Count; i++) { CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawnsFromTransferables[i], this.caravan.PawnsListForReading, pawnsFromTransferables); } for (int j = 0; j < pawnsFromTransferables.Count; j++) { this.caravan.RemovePawn(pawnsFromTransferables[j]); } Caravan newCaravan = CaravanMaker.MakeCaravan(pawnsFromTransferables, this.caravan.Faction, this.caravan.Tile, true); this.transferables.RemoveAll((TransferableOneWay x) => x.AnyThing is Pawn); for (int k = 0; k < this.transferables.Count; k++) { TransferableUtility.TransferNoSplit(this.transferables[k].things, this.transferables[k].CountToTransfer, delegate(Thing thing, int numToTake) { Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(this.caravan, thing); if (ownerOf == null) { Log.Error("Error while splitting a caravan: Thing " + thing + " has no owner. Where did it come from then?", false); return; } CaravanInventoryUtility.MoveInventoryToSomeoneElse(ownerOf, thing, newCaravan.PawnsListForReading, null, numToTake); }, true, true); } return(true); }
private void SpawnCaravanAtDestinationTile() { TravelingTransportPods.tmpPawns.Clear(); for (int i = 0; i < this.pods.Count; i++) { ThingOwner innerContainer = this.pods[i].innerContainer; for (int j = innerContainer.Count - 1; j >= 0; j--) { Pawn pawn = innerContainer[j] as Pawn; if (pawn != null) { TravelingTransportPods.tmpPawns.Add(pawn); innerContainer.Remove(pawn); } } } int startingTile; if (!GenWorldClosest.TryFindClosestPassableTile(this.destinationTile, out startingTile)) { startingTile = this.destinationTile; } Caravan o = CaravanMaker.MakeCaravan(TravelingTransportPods.tmpPawns, base.Faction, startingTile, true); for (int k = 0; k < this.pods.Count; k++) { TravelingTransportPods.tmpContainedThings.Clear(); TravelingTransportPods.tmpContainedThings.AddRange(this.pods[k].innerContainer); for (int l = 0; l < TravelingTransportPods.tmpContainedThings.Count; l++) { this.pods[k].innerContainer.Remove(TravelingTransportPods.tmpContainedThings[l]); Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(TravelingTransportPods.tmpContainedThings[l], TravelingTransportPods.tmpPawns, null, null); bool flag = false; if (pawn2 != null) { flag = pawn2.inventory.innerContainer.TryAdd(TravelingTransportPods.tmpContainedThings[l], true); } if (!flag) { TravelingTransportPods.tmpContainedThings[l].Destroy(DestroyMode.Vanish); } } } this.RemoveAllPods(); Find.WorldObjects.Remove(this); TravelingTransportPods.tmpPawns.Clear(); TravelingTransportPods.tmpContainedThings.Clear(); Messages.Message("MessageTransportPodsArrived".Translate(), o, MessageTypeDefOf.TaskCompletion); }
public static Caravan ExitMapAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int startingTile) { if (!GenWorldClosest.TryFindClosestPassableTile(startingTile, out startingTile)) { Log.Error("Could not find any passable tile for a new caravan."); return(null); } CaravanExitMapUtility.tmpPawns.Clear(); CaravanExitMapUtility.tmpPawns.AddRange(pawns); Map map = null; int num = 0; while (num < CaravanExitMapUtility.tmpPawns.Count) { map = CaravanExitMapUtility.tmpPawns[num].MapHeld; if (map == null) { num++; continue; } break; } Caravan caravan = CaravanMaker.MakeCaravan(CaravanExitMapUtility.tmpPawns, faction, startingTile, false); for (int i = 0; i < CaravanExitMapUtility.tmpPawns.Count; i++) { CaravanExitMapUtility.tmpPawns[i].ExitMap(false); } List <Pawn> pawnsListForReading = caravan.PawnsListForReading; for (int j = 0; j < pawnsListForReading.Count; j++) { if (!pawnsListForReading[j].IsWorldPawn()) { Find.WorldPawns.PassToWorld(pawnsListForReading[j], PawnDiscardDecideMode.Decide); } } if (map != null) { map.info.parent.Notify_CaravanFormed(caravan); } return(caravan); }
public override void Arrived(List <ActiveDropPodInfo> pods, int tile) { TransportPodsArrivalAction_FormCaravan.tmpPawns.Clear(); for (int i = 0; i < pods.Count; i++) { ThingOwner innerContainer = pods[i].innerContainer; for (int j = innerContainer.Count - 1; j >= 0; j--) { Pawn pawn = innerContainer[j] as Pawn; if (pawn != null) { TransportPodsArrivalAction_FormCaravan.tmpPawns.Add(pawn); innerContainer.Remove(pawn); } } } int startingTile; if (!GenWorldClosest.TryFindClosestPassableTile(tile, out startingTile)) { startingTile = tile; } Caravan caravan = CaravanMaker.MakeCaravan(TransportPodsArrivalAction_FormCaravan.tmpPawns, Faction.OfPlayer, startingTile, true); for (int k = 0; k < pods.Count; k++) { TransportPodsArrivalAction_FormCaravan.tmpContainedThings.Clear(); TransportPodsArrivalAction_FormCaravan.tmpContainedThings.AddRange(pods[k].innerContainer); for (int l = 0; l < TransportPodsArrivalAction_FormCaravan.tmpContainedThings.Count; l++) { pods[k].innerContainer.Remove(TransportPodsArrivalAction_FormCaravan.tmpContainedThings[l]); CaravanInventoryUtility.GiveThing(caravan, TransportPodsArrivalAction_FormCaravan.tmpContainedThings[l]); } } TransportPodsArrivalAction_FormCaravan.tmpPawns.Clear(); TransportPodsArrivalAction_FormCaravan.tmpContainedThings.Clear(); Messages.Message("MessageTransportPodsArrived".Translate(), caravan, MessageTypeDefOf.TaskCompletion, true); }
public override void Arrived(List <ActiveDropPodInfo> pods, int tile) { tmpPawns.Clear(); for (int i = 0; i < pods.Count; i++) { ThingOwner innerContainer = pods[i].innerContainer; for (int num = innerContainer.Count - 1; num >= 0; num--) { Pawn pawn = innerContainer[num] as Pawn; if (pawn != null) { tmpPawns.Add(pawn); innerContainer.Remove(pawn); } } } if (!GenWorldClosest.TryFindClosestPassableTile(tile, out var foundTile)) { foundTile = tile; } Caravan caravan = CaravanMaker.MakeCaravan(tmpPawns, Faction.OfPlayer, foundTile, addToWorldPawnsIfNotAlready: true); for (int j = 0; j < pods.Count; j++) { tmpContainedThings.Clear(); tmpContainedThings.AddRange(pods[j].innerContainer); for (int k = 0; k < tmpContainedThings.Count; k++) { pods[j].innerContainer.Remove(tmpContainedThings[k]); CaravanInventoryUtility.GiveThing(caravan, tmpContainedThings[k]); } } tmpPawns.Clear(); tmpContainedThings.Clear(); Messages.Message(arrivalMessageKey.Translate(), caravan, MessageTypeDefOf.TaskCompletion); }
public static Caravan ExitMapAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile, int destinationTile, bool sendMessage = true) { Caravan result; if (!GenWorldClosest.TryFindClosestPassableTile(exitFromTile, out exitFromTile)) { Log.Error("Could not find any passable tile for a new caravan.", false); result = null; } else { if (Find.World.Impassable(directionTile)) { directionTile = exitFromTile; } CaravanExitMapUtility.tmpPawns.Clear(); CaravanExitMapUtility.tmpPawns.AddRange(pawns); Map map = null; for (int i = 0; i < CaravanExitMapUtility.tmpPawns.Count; i++) { CaravanExitMapUtility.AddCaravanExitTaleIfShould(CaravanExitMapUtility.tmpPawns[i]); map = CaravanExitMapUtility.tmpPawns[i].MapHeld; if (map != null) { break; } } Caravan caravan = CaravanMaker.MakeCaravan(CaravanExitMapUtility.tmpPawns, faction, exitFromTile, false); Rot4 exitDir = (map == null) ? Rot4.Invalid : Find.WorldGrid.GetRotFromTo(exitFromTile, directionTile); for (int j = 0; j < CaravanExitMapUtility.tmpPawns.Count; j++) { CaravanExitMapUtility.tmpPawns[j].ExitMap(false, exitDir); } List <Pawn> pawnsListForReading = caravan.PawnsListForReading; for (int k = 0; k < pawnsListForReading.Count; k++) { if (!pawnsListForReading[k].IsWorldPawn()) { Find.WorldPawns.PassToWorld(pawnsListForReading[k], PawnDiscardDecideMode.Decide); } } if (map != null) { map.Parent.Notify_CaravanFormed(caravan); map.retainedCaravanData.Notify_CaravanFormed(caravan); } if (!caravan.pather.Moving && caravan.Tile != directionTile) { caravan.pather.StartPath(directionTile, null, true, true); caravan.pather.nextTileCostLeft /= 2f; caravan.tweener.ResetTweenedPosToRoot(); } if (destinationTile != -1) { List <FloatMenuOption> list = FloatMenuMakerWorld.ChoicesAtFor(destinationTile, caravan); if (list.Any((FloatMenuOption x) => !x.Disabled)) { FloatMenuOption floatMenuOption = list.First((FloatMenuOption x) => !x.Disabled); floatMenuOption.action(); } else { caravan.pather.StartPath(destinationTile, null, true, true); } } if (sendMessage) { string text = "MessageFormedCaravan".Translate(new object[] { caravan.Name }).CapitalizeFirst(); if (caravan.pather.Moving && caravan.pather.ArrivalAction != null) { string text2 = text; text = string.Concat(new string[] { text2, " ", "MessageFormedCaravan_Orders".Translate(), ": ", caravan.pather.ArrivalAction.Label, "." }); } Messages.Message(text, caravan, MessageTypeDefOf.TaskCompletion, true); } result = caravan; } return(result); }
public static Caravan ExitMapAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile, int destinationTile, bool sendMessage = true) { if (!GenWorldClosest.TryFindClosestPassableTile(exitFromTile, out exitFromTile)) { Log.Error("Could not find any passable tile for a new caravan."); return(null); } if (Find.World.Impassable(directionTile)) { directionTile = exitFromTile; } tmpPawns.Clear(); tmpPawns.AddRange(pawns); Map map = null; for (int i = 0; i < tmpPawns.Count; i++) { AddCaravanExitTaleIfShould(tmpPawns[i]); map = tmpPawns[i].MapHeld; if (map != null) { break; } } Caravan caravan = CaravanMaker.MakeCaravan(tmpPawns, faction, exitFromTile, addToWorldPawnsIfNotAlready: false); Rot4 exitDir = (map != null) ? Find.WorldGrid.GetRotFromTo(exitFromTile, directionTile) : Rot4.Invalid; for (int j = 0; j < tmpPawns.Count; j++) { tmpPawns[j].ExitMap(allowedToJoinOrCreateCaravan: false, exitDir); } List <Pawn> pawnsListForReading = caravan.PawnsListForReading; for (int k = 0; k < pawnsListForReading.Count; k++) { if (!pawnsListForReading[k].IsWorldPawn()) { Find.WorldPawns.PassToWorld(pawnsListForReading[k]); } } if (map != null) { map.Parent.Notify_CaravanFormed(caravan); map.retainedCaravanData.Notify_CaravanFormed(caravan); } if (!caravan.pather.Moving && caravan.Tile != directionTile) { caravan.pather.StartPath(directionTile, null, repathImmediately: true); caravan.pather.nextTileCostLeft /= 2f; caravan.tweener.ResetTweenedPosToRoot(); } if (destinationTile != -1) { List <FloatMenuOption> list = FloatMenuMakerWorld.ChoicesAtFor(destinationTile, caravan); if (list.Any((FloatMenuOption x) => !x.Disabled)) { list.First((FloatMenuOption x) => !x.Disabled).action(); } else { caravan.pather.StartPath(destinationTile, null, repathImmediately: true); } } if (sendMessage) { TaggedString taggedString = "MessageFormedCaravan".Translate(caravan.Name).CapitalizeFirst(); if (caravan.pather.Moving && caravan.pather.ArrivalAction != null) { taggedString += " " + "MessageFormedCaravan_Orders".Translate() + ": " + caravan.pather.ArrivalAction.Label + "."; } Messages.Message(taggedString, caravan, MessageTypeDefOf.TaskCompletion); } return(caravan); }