Exemple #1
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);
        }
Exemple #2
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);
        }
        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 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);
        }
Exemple #5
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);
        }