public static void ExitMapAndJoinOrCreateCaravan(Pawn pawn, Rot4 exitDir) { Caravan caravan = CaravanExitMapUtility.FindCaravanToJoinFor(pawn); if (caravan != null) { CaravanExitMapUtility.AddCaravanExitTaleIfShould(pawn); caravan.AddPawn(pawn, true); pawn.ExitMap(false, exitDir); } else if (pawn.IsColonist) { Map map = pawn.Map; int directionTile = CaravanExitMapUtility.FindRandomStartingTileBasedOnExitDir(map.Tile, exitDir); Caravan caravan2 = CaravanExitMapUtility.ExitMapAndCreateCaravan(Gen.YieldSingle <Pawn>(pawn), pawn.Faction, map.Tile, directionTile, -1, false); caravan2.autoJoinable = true; bool flag = false; List <Pawn> allPawnsSpawned = map.mapPawns.AllPawnsSpawned; for (int i = 0; i < allPawnsSpawned.Count; i++) { if (CaravanExitMapUtility.FindCaravanToJoinFor(allPawnsSpawned[i]) != null && !allPawnsSpawned[i].Downed && !allPawnsSpawned[i].Drafted) { if (allPawnsSpawned[i].RaceProps.Animal) { flag = true; } RestUtility.WakeUp(allPawnsSpawned[i]); allPawnsSpawned[i].jobs.CheckForJobOverride(); } } string text = "MessagePawnLeftMapAndCreatedCaravan".Translate(new object[] { pawn.LabelShort }).CapitalizeFirst(); if (flag) { text = text + " " + "MessagePawnLeftMapAndCreatedCaravan_AnimalsWantToJoin".Translate(); } Messages.Message(text, caravan2, MessageTypeDefOf.TaskCompletion, true); } else { Log.Error("Pawn " + pawn + " didn't find any caravan to join, and he can't create one.", false); } }
public static Caravan ExitMapAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile) { if (Find.World.Impassable(directionTile)) { directionTile = exitFromTile; } if (Find.World.Impassable(exitFromTile)) { exitFromTile = directionTile; } Caravan caravan = CaravanExitMapUtility.ExitMapAndCreateCaravan(pawns, faction, exitFromTile); if (caravan.Tile != directionTile) { caravan.pather.StartPath(directionTile, null, true); caravan.pather.nextTileCostLeft /= 2f; caravan.tweener.ResetToPosition(); } return(caravan); }
public static void FormAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile, int destinationTile) { CaravanExitMapUtility.ExitMapAndCreateCaravan(pawns, faction, exitFromTile, directionTile, destinationTile, true); }
public static Caravan ExitMapAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, Direction8Way dir, int destinationTile, bool sendMessage = true) { int directionTile = CaravanExitMapUtility.FindRandomStartingTileBasedOnExitDir(exitFromTile, dir); return(CaravanExitMapUtility.ExitMapAndCreateCaravan(pawns, faction, exitFromTile, directionTile, destinationTile, sendMessage)); }
public static void FormAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile) { Caravan o = CaravanExitMapUtility.ExitMapAndCreateCaravan(pawns, faction, exitFromTile, directionTile); Find.LetterStack.ReceiveLetter("LetterLabelFormedCaravan".Translate(), "LetterFormedCaravan".Translate(), LetterDefOf.NeutralEvent, o, null); }
public override void CompTick() { MapParent mapParent = this.parent as MapParent; if (this.ForceExitAndRemoveMapCountdownActive) { if (mapParent.HasMap) { this.ticksLeftToForceExitAndRemoveMap--; if (this.ticksLeftToForceExitAndRemoveMap == 0) { if (Dialog_FormCaravan.AllSendablePawns(mapParent.Map, true).Any((Pawn x) => x.IsColonist)) { Messages.Message("MessageYouHaveToReformCaravanNow".Translate(), new GlobalTargetInfo(mapParent.Tile), MessageTypeDefOf.NeutralEvent); Current.Game.VisibleMap = mapParent.Map; Dialog_FormCaravan window = new Dialog_FormCaravan(mapParent.Map, true, delegate { if (mapParent.HasMap) { this.ShowWorldViewIfVisibleMapAboutToBeRemoved(mapParent.Map); Find.WorldObjects.Remove(mapParent); } }, false, true); Find.WindowStack.Add(window); } else { TimedForcedExit.tmpPawns.Clear(); TimedForcedExit.tmpPawns.AddRange(from x in mapParent.Map.mapPawns.AllPawns where x.Faction == Faction.OfPlayer || x.HostFaction == Faction.OfPlayer select x); if (TimedForcedExit.tmpPawns.Any <Pawn>()) { if (TimedForcedExit.tmpPawns.Any((Pawn x) => CaravanUtility.IsOwner(x, Faction.OfPlayer))) { Caravan o = CaravanExitMapUtility.ExitMapAndCreateCaravan(TimedForcedExit.tmpPawns, Faction.OfPlayer, mapParent.Tile); Messages.Message("MessageAutomaticallyReformedCaravan".Translate(), o, MessageTypeDefOf.NeutralEvent); } else { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < TimedForcedExit.tmpPawns.Count; i++) { stringBuilder.AppendLine(" " + TimedForcedExit.tmpPawns[i].LabelCap); } Find.LetterStack.ReceiveLetter("LetterLabelPawnsLostDueToMapCountdown".Translate(), "LetterPawnsLostDueToMapCountdown".Translate(new object[] { stringBuilder.ToString().TrimEndNewlines() }), LetterDefOf.NegativeEvent, new GlobalTargetInfo(mapParent.Tile), null); } TimedForcedExit.tmpPawns.Clear(); } this.ShowWorldViewIfVisibleMapAboutToBeRemoved(mapParent.Map); Find.WorldObjects.Remove(mapParent); } } } else { this.ticksLeftToForceExitAndRemoveMap = -1; } } }