示例#1
0
        public static int RandomBestExitTileFrom(Map map)
        {
            Tile       tileInfo = map.TileInfo;
            List <int> options  = CaravanExitMapUtility.AvailableExitTilesAt(map);

            if (!options.Any <int>())
            {
                return(-1);
            }
            List <Tile.RoadLink> roads = tileInfo.Roads;

            if (roads == null)
            {
                return(options.RandomElement <int>());
            }
            int bestRoadIndex = -1;

            for (int i = 0; i < roads.Count; i++)
            {
                if (options.Contains(roads[i].neighbor))
                {
                    if (bestRoadIndex == -1 || roads[i].road.priority > roads[bestRoadIndex].road.priority)
                    {
                        bestRoadIndex = i;
                    }
                }
            }
            if (bestRoadIndex == -1)
            {
                return(options.RandomElement <int>());
            }
            return((from rl in roads
                    where options.Contains(rl.neighbor) && rl.road == roads[bestRoadIndex].road
                    select rl).RandomElement <Tile.RoadLink>().neighbor);
        }
示例#2
0
        public static int BestExitTileToGoTo(int destinationTile, Map from)
        {
            int num = -1;

            using (WorldPath worldPath = Find.WorldPathFinder.FindPath(from.Tile, destinationTile, null, null))
            {
                if (worldPath.Found && worldPath.NodesLeftCount >= 2)
                {
                    num = worldPath.NodesReversed[worldPath.NodesReversed.Count - 2];
                }
            }
            if (num == -1)
            {
                return(CaravanExitMapUtility.RandomBestExitTileFrom(from));
            }
            float      num2 = 0f;
            int        num3 = -1;
            List <int> list = CaravanExitMapUtility.AvailableExitTilesAt(from);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i] == num)
                {
                    return(list[i]);
                }
                float num4 = (Find.WorldGrid.GetTileCenter(list[i]) - Find.WorldGrid.GetTileCenter(num)).MagnitudeHorizontalSquared();
                if (num3 == -1 || num4 < num2)
                {
                    num3 = list[i];
                    num2 = num4;
                }
            }
            return(num3);
        }
示例#3
0
 public static void ForceReform(MapParent mapParent)
 {
     if (Dialog_FormCaravan.AllSendablePawns(mapParent.Map, reform: true).Any((Pawn x) => x.IsColonist))
     {
         Messages.Message("MessageYouHaveToReformCaravanNow".Translate(), new GlobalTargetInfo(mapParent.Tile), MessageTypeDefOf.NeutralEvent);
         Current.Game.CurrentMap = mapParent.Map;
         Dialog_FormCaravan window = new Dialog_FormCaravan(mapParent.Map, reform: true, delegate
         {
             if (mapParent.HasMap)
             {
                 mapParent.Destroy();
             }
         }, mapAboutToBeRemoved: true);
         Find.WindowStack.Add(window);
         return;
     }
     tmpPawns.Clear();
     tmpPawns.AddRange(mapParent.Map.mapPawns.AllPawns.Where((Pawn x) => x.Faction == Faction.OfPlayer || x.HostFaction == Faction.OfPlayer));
     if (tmpPawns.Any((Pawn x) => CaravanUtility.IsOwner(x, Faction.OfPlayer)))
     {
         CaravanExitMapUtility.ExitMapAndCreateCaravan(tmpPawns, Faction.OfPlayer, mapParent.Tile, mapParent.Tile, -1);
     }
     tmpPawns.Clear();
     mapParent.Destroy();
 }
 public static void ForceReform(MapParent mapParent)
 {
     if (Dialog_FormCaravan.AllSendablePawns(mapParent.Map, true).Any((Pawn x) => x.IsColonist))
     {
         Messages.Message("MessageYouHaveToReformCaravanNow".Translate(), new GlobalTargetInfo(mapParent.Tile), MessageTypeDefOf.NeutralEvent, true);
         Current.Game.CurrentMap = mapParent.Map;
         Dialog_FormCaravan window = new Dialog_FormCaravan(mapParent.Map, true, delegate()
         {
             if (mapParent.HasMap)
             {
                 Find.WorldObjects.Remove(mapParent);
             }
         }, 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 x) => CaravanUtility.IsOwner(x, Faction.OfPlayer)))
         {
             CaravanExitMapUtility.ExitMapAndCreateCaravan(TimedForcedExit.tmpPawns, Faction.OfPlayer, mapParent.Tile, mapParent.Tile, -1, true);
         }
         TimedForcedExit.tmpPawns.Clear();
         Find.WorldObjects.Remove(mapParent);
     }
 }
        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.");
            }
        }
示例#6
0
        private static int FindRandomStartingTileBasedOnExitDir(int tileID, Direction8Way exitDir)
        {
            CaravanExitMapUtility.tileCandidates.Clear();
            World     world = Find.World;
            WorldGrid grid  = world.grid;

            grid.GetTileNeighbors(tileID, CaravanExitMapUtility.tmpNeighbors);
            for (int i = 0; i < CaravanExitMapUtility.tmpNeighbors.Count; i++)
            {
                int num = CaravanExitMapUtility.tmpNeighbors[i];
                if (CaravanExitMapUtility.IsGoodCaravanStartingTile(num))
                {
                    if (grid.GetDirection8WayFromTo(tileID, num) == exitDir)
                    {
                        CaravanExitMapUtility.tileCandidates.Add(num);
                    }
                }
            }
            int result;

            if (CaravanExitMapUtility.tileCandidates.TryRandomElement(out result))
            {
                return(result);
            }
            if (CaravanExitMapUtility.tmpNeighbors.Where(new Func <int, bool>(CaravanExitMapUtility.IsGoodCaravanStartingTile)).TryRandomElement(out result))
            {
                return(result);
            }
            return(tileID);
        }
        public override void CompTick()
        {
            MapParent mapParent = base.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())
                            {
                                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(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;
                }
            }
        }
        public static int RandomBestExitTileFrom(Map map)
        {
            Tile       tile    = map.TileInfo;
            List <int> options = CaravanExitMapUtility.AvailableExitTilesAt(map);

            if (!options.Any())
            {
                return(-1);
            }
            if (tile.roads == null)
            {
                return(options.RandomElement());
            }
            int bestRoadIndex = -1;

            for (int i = 0; i < tile.roads.Count; i++)
            {
                List <int>    list     = options;
                Tile.RoadLink roadLink = tile.roads[i];
                if (list.Contains(roadLink.neighbor))
                {
                    if (bestRoadIndex == -1)
                    {
                        goto IL_00e9;
                    }
                    Tile.RoadLink roadLink2 = tile.roads[i];
                    int           priority  = roadLink2.road.priority;
                    Tile.RoadLink roadLink3 = tile.roads[bestRoadIndex];
                    if (priority > roadLink3.road.priority)
                    {
                        goto IL_00e9;
                    }
                }
                continue;
IL_00e9:
                bestRoadIndex = i;
            }
            if (bestRoadIndex == -1)
            {
                return(options.RandomElement());
            }
            Tile.RoadLink roadLink4 = tile.roads.Where(delegate(Tile.RoadLink rl)
            {
                int result;
                if (options.Contains(rl.neighbor))
                {
                    RoadDef road            = rl.road;
                    Tile.RoadLink roadLink5 = tile.roads[bestRoadIndex];
                    result = ((road == roadLink5.road) ? 1 : 0);
                }
                else
                {
                    result = 0;
                }
                return((byte)result != 0);
            }).RandomElement();
            return(roadLink4.neighbor);
        }
示例#9
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            MapParent mapParent = (MapParent)parent;

            if (!mapParent.HasMap)
            {
                yield break;
            }
            if (!Reform)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandFormCaravan".Translate();
                command_Action.defaultDesc  = "CommandFormCaravanDesc".Translate();
                command_Action.icon         = FormCaravanCommand;
                command_Action.hotKey       = KeyBindingDefOf.Misc2;
                command_Action.tutorTag     = "FormCaravan";
                command_Action.action       = delegate
                {
                    Find.WindowStack.Add(new Dialog_FormCaravan(mapParent.Map));
                };
                yield return(command_Action);
            }
            else if (mapParent.Map.mapPawns.FreeColonistsSpawnedCount != 0)
            {
                Command_Action command_Action2 = new Command_Action();
                command_Action2.defaultLabel = "CommandReformCaravan".Translate();
                command_Action2.defaultDesc  = "CommandReformCaravanDesc".Translate();
                command_Action2.icon         = FormCaravanCommand;
                command_Action2.hotKey       = KeyBindingDefOf.Misc2;
                command_Action2.tutorTag     = "ReformCaravan";
                command_Action2.action       = delegate
                {
                    Find.WindowStack.Add(new Dialog_FormCaravan(mapParent.Map, reform: true));
                };
                if (GenHostility.AnyHostileActiveThreatToPlayer(mapParent.Map, countDormantPawnsAsHostile: true))
                {
                    command_Action2.Disable("CommandReformCaravanFailHostilePawns".Translate());
                }
                yield return(command_Action2);
            }
            if (!Prefs.DevMode)
            {
                yield break;
            }
            Command_Action command_Action3 = new Command_Action();

            command_Action3.defaultLabel = "Dev: Show available exits";
            command_Action3.action       = delegate
            {
                foreach (int item in CaravanExitMapUtility.AvailableExitTilesAt(mapParent.Map))
                {
                    Find.WorldDebugDrawer.FlashTile(item, 0f, null, 10);
                }
            };
            yield return(command_Action3);
        }
示例#10
0
        private static int FindRandomStartingTileBasedOnExitDir(int tileID, Rot4 exitDir)
        {
            CaravanExitMapUtility.tileCandidates.Clear();
            World     world = Find.World;
            WorldGrid grid  = world.grid;

            grid.GetTileNeighbors(tileID, CaravanExitMapUtility.tmpNeighbors);
            for (int i = 0; i < CaravanExitMapUtility.tmpNeighbors.Count; i++)
            {
                int num = CaravanExitMapUtility.tmpNeighbors[i];
                if (CaravanExitMapUtility.IsGoodCaravanStartingTile(num))
                {
                    if (!exitDir.IsValid || !(grid.GetRotFromTo(tileID, num) != exitDir))
                    {
                        CaravanExitMapUtility.tileCandidates.Add(num);
                    }
                }
            }
            int num2;
            int result;

            if (CaravanExitMapUtility.tileCandidates.TryRandomElement(out num2))
            {
                result = num2;
            }
            else if (CaravanExitMapUtility.tmpNeighbors.Where(delegate(int x)
            {
                bool result2;
                if (!CaravanExitMapUtility.IsGoodCaravanStartingTile(x))
                {
                    result2 = false;
                }
                else
                {
                    Rot4 rotFromTo = grid.GetRotFromTo(tileID, x);
                    result2 = (((exitDir == Rot4.North || exitDir == Rot4.South) && (rotFromTo == Rot4.East || rotFromTo == Rot4.West)) || ((exitDir == Rot4.East || exitDir == Rot4.West) && (rotFromTo == Rot4.North || rotFromTo == Rot4.South)));
                }
                return(result2);
            }).TryRandomElement(out num2))
            {
                result = num2;
            }
            else if ((from x in CaravanExitMapUtility.tmpNeighbors
                      where CaravanExitMapUtility.IsGoodCaravanStartingTile(x)
                      select x).TryRandomElement(out num2))
            {
                result = num2;
            }
            else
            {
                result = tileID;
            }
            return(result);
        }
 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);
 }
示例#12
0
 private void AutoOrderToTile(Caravan c, int tile)
 {
     if (tile >= 0)
     {
         if (c.autoJoinable && CaravanExitMapUtility.IsTheOnlyJoinableCaravanForAnyPrisonerOrAnimal(c))
         {
             CaravanExitMapUtility.OpenTheOnlyJoinableCaravanForPrisonerOrAnimalDialog(c, delegate
             {
                 this.AutoOrderToTileNow(c, tile);
             });
         }
         else
         {
             this.AutoOrderToTileNow(c, tile);
         }
     }
 }
示例#13
0
 private void AutoOrderToTile(Caravan c, int tile)
 {
     if (tile >= 0)
     {
         if (c.autoJoinable && CaravanExitMapUtility.AnyoneTryingToJoinCaravan(c))
         {
             CaravanExitMapUtility.OpenSomeoneTryingToJoinCaravanDialog(c, delegate
             {
                 AutoOrderToTileNow(c, tile);
             });
         }
         else
         {
             AutoOrderToTileNow(c, tile);
         }
     }
 }
示例#14
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);
            }
        }
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        private static int FindRandomStartingTileBasedOnExitDir(int tileID, Direction8Way exitDir)
        {
            CaravanExitMapUtility.tileCandidates.Clear();
            World     world = Find.World;
            WorldGrid grid  = world.grid;

            grid.GetTileNeighbors(tileID, CaravanExitMapUtility.tmpNeighbors);
            for (int i = 0; i < CaravanExitMapUtility.tmpNeighbors.Count; i++)
            {
                int num = CaravanExitMapUtility.tmpNeighbors[i];
                if (CaravanExitMapUtility.IsGoodCaravanStartingTile(num))
                {
                    if (grid.GetDirection8WayFromTo(tileID, num) == exitDir)
                    {
                        CaravanExitMapUtility.tileCandidates.Add(num);
                    }
                }
            }
            int num2;
            int result;

            if (CaravanExitMapUtility.tileCandidates.TryRandomElement(out num2))
            {
                result = num2;
            }
            else if ((from x in CaravanExitMapUtility.tmpNeighbors
                      where CaravanExitMapUtility.IsGoodCaravanStartingTile(x)
                      select x).TryRandomElement(out num2))
            {
                result = num2;
            }
            else
            {
                result = tileID;
            }
            return(result);
        }
示例#18
0
        public static List <int> AvailableExitTilesAt(Map map)
        {
            CaravanExitMapUtility.retTiles.Clear();
            int       currentTileID = map.Tile;
            World     world         = Find.World;
            WorldGrid grid          = world.grid;

            grid.GetTileNeighbors(currentTileID, CaravanExitMapUtility.tmpNeighbors);
            for (int i = 0; i < CaravanExitMapUtility.tmpNeighbors.Count; i++)
            {
                int num = CaravanExitMapUtility.tmpNeighbors[i];
                if (CaravanExitMapUtility.IsGoodCaravanStartingTile(num))
                {
                    Rot4    rotFromTo = grid.GetRotFromTo(currentTileID, num);
                    IntVec3 intVec;
                    if (CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Walkable(map) && !x.Fogged(map), map, rotFromTo, CellFinder.EdgeRoadChance_Ignore, out intVec))
                    {
                        CaravanExitMapUtility.retTiles.Add(num);
                    }
                }
            }
            CaravanExitMapUtility.retTiles.SortBy((int x) => grid.GetHeadingFromTo(currentTileID, x));
            return(CaravanExitMapUtility.retTiles);
        }
示例#19
0
 public static void FormAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile, int destinationTile)
 {
     CaravanExitMapUtility.ExitMapAndCreateCaravan(pawns, faction, exitFromTile, directionTile, destinationTile, true);
 }
示例#20
0
 private static bool <FindRandomStartingTileBasedOnExitDir> m__3(int x)
 {
     return(CaravanExitMapUtility.IsGoodCaravanStartingTile(x));
 }
示例#21
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);
        }
示例#22
0
        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);
        }
示例#23
0
        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);
        }