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 bool CanExitMapAndJoinOrCreateCaravanNow(Pawn pawn)
 {
     if (!pawn.Spawned)
     {
         return(false);
     }
     if (!pawn.Map.exitMapGrid.MapUsesExitGrid)
     {
         return(false);
     }
     return(pawn.IsColonist || CaravanExitMapUtility.FindCaravanToJoinFor(pawn) != null);
 }
예제 #3
0
        public static void ExitMapAndJoinOrCreateCaravan(Pawn pawn, Rot4 exitDir)
        {
            Caravan caravan = CaravanExitMapUtility.FindCaravanToJoinFor(pawn);

            if (caravan != null)
            {
                CaravanExitMapUtility.AddCaravanExitTaleIfShould(pawn);
                pawn.DeSpawn(DestroyMode.Vanish);
                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);
            }
        }
예제 #4
0
        public static bool AnyoneTryingToJoinCaravan(Caravan c)
        {
            List <Map> maps = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                Map map = maps[i];
                if (!map.IsPlayerHome && Find.WorldGrid.IsNeighborOrSame(c.Tile, map.Tile))
                {
                    List <Pawn> allPawnsSpawned = map.mapPawns.AllPawnsSpawned;
                    for (int j = 0; j < allPawnsSpawned.Count; j++)
                    {
                        if (!allPawnsSpawned[j].IsColonistPlayerControlled && !allPawnsSpawned[j].Downed && CaravanExitMapUtility.FindCaravanToJoinFor(allPawnsSpawned[j]) == c)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }