public static void ExitMapAndJoinOrCreateCaravan(Pawn pawn) { CaravanExitMapUtility.GenerateCaravanExitTale(pawn); Caravan caravan = CaravanExitMapUtility.FindCaravanToJoinFor(pawn); if (caravan != null) { pawn.DeSpawn(); caravan.AddPawn(pawn, true); pawn.ExitMap(false); } else if (pawn.IsColonist) { List <int> list = CaravanExitMapUtility.AvailableExitTilesAt(pawn.Map); Caravan caravan2 = CaravanExitMapUtility.ExitMapAndCreateCaravan(Gen.YieldSingle(pawn), pawn.Faction, pawn.Map.Tile, (!list.Any()) ? pawn.Map.Tile : list.RandomElement()); caravan2.autoJoinable = true; if (pawn.Faction == Faction.OfPlayer) { Messages.Message("MessagePawnLeftMapAndCreatedCaravan".Translate(pawn.LabelShort).CapitalizeFirst(), caravan2, MessageTypeDefOf.TaskCompletion); } } else { Log.Error("Pawn " + pawn + " didn't find any caravan to join, and he can't create one."); } }
public static Caravan MakeCaravan(IEnumerable <Pawn> pawns, Faction faction, int startingTile, bool addToWorldPawnsIfNotAlready) { 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."); } CaravanMaker.tmpPawns.Clear(); CaravanMaker.tmpPawns.AddRange(pawns); Caravan caravan = (Caravan)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Caravan); if (startingTile >= 0) { caravan.Tile = startingTile; } caravan.SetFaction(faction); caravan.Name = CaravanNameGenerator.GenerateCaravanName(caravan); if (startingTile >= 0) { Find.WorldObjects.Add(caravan); } for (int i = 0; i < CaravanMaker.tmpPawns.Count; i++) { Pawn pawn = CaravanMaker.tmpPawns[i]; CaravanExitMapUtility.GenerateCaravanExitTale(pawn); if (pawn.Dead) { Log.Warning("Tried to form a caravan with a dead pawn " + pawn); } else { caravan.AddPawn(pawn, addToWorldPawnsIfNotAlready); if (addToWorldPawnsIfNotAlready && !pawn.IsWorldPawn()) { Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); } } } return(caravan); }