示例#1
0
        public static Thing ClosestThingReachable(IntVec3 root, Map map, ThingRequest thingReq, PathEndMode peMode, TraverseParms traverseParams, float maxDistance = 9999f, Predicate <Thing> validator = null, IEnumerable <Thing> customGlobalSearchSet = null, int searchRegionsMin = 0, int searchRegionsMax = -1, bool forceGlobalSearch = false, RegionType traversableRegionTypes = RegionType.Set_Passable, bool ignoreEntirelyForbiddenRegions = false)
        {
            if (searchRegionsMax > 0 && customGlobalSearchSet != null && !forceGlobalSearch)
            {
                Log.ErrorOnce("searchRegionsMax > 0 && customGlobalSearchSet != null && !forceGlobalSearch. customGlobalSearchSet will never be used.", 634984);
            }
            if (GenClosest.EarlyOutSearch(root, map, thingReq, customGlobalSearchSet))
            {
                return(null);
            }
            Thing thing = null;

            if (!thingReq.IsUndefined)
            {
                int maxRegions = (searchRegionsMax <= 0) ? 30 : searchRegionsMax;
                thing = GenClosest.RegionwiseBFSWorker(root, map, thingReq, peMode, traverseParams, validator, null, searchRegionsMin, maxRegions, maxDistance, traversableRegionTypes, ignoreEntirelyForbiddenRegions);
            }
            if (thing == null && (searchRegionsMax < 0 || forceGlobalSearch))
            {
                if (traversableRegionTypes != RegionType.Set_Passable)
                {
                    Log.ErrorOnce("ClosestThingReachable had to do a global search, but traversableRegionTypes is not set to passable only. It's not supported, because Reachability is based on passable regions only.", 14384767);
                }
                Predicate <Thing>   validator2 = (Thing t) => map.reachability.CanReach(root, t, peMode, traverseParams) && (validator == null || validator(t));
                IEnumerable <Thing> searchSet  = customGlobalSearchSet ?? map.listerThings.ThingsMatching(thingReq);
                thing = GenClosest.ClosestThing_Global(root, searchSet, maxDistance, validator2, null);
            }
            return(thing);
        }
示例#2
0
        private static void SpawnPawn()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef item in DefDatabase <PawnKindDef> .AllDefs.OrderBy((PawnKindDef kd) => kd.defName))
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Tool, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    Pawn newPawn    = PawnGenerator.GeneratePawn(localKindDef, faction);
                    GenSpawn.Spawn(newPawn, UI.MouseCell(), Find.CurrentMap);
                    if (faction != null && faction != Faction.OfPlayer)
                    {
                        Lord lord = null;
                        if (newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn))
                        {
                            lord = ((Pawn)GenClosest.ClosestThing_Global(newPawn.Position, newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null)).GetLord();
                        }
                        if (lord == null)
                        {
                            LordJob_DefendPoint lordJob = new LordJob_DefendPoint(newPawn.Position);
                            lord = LordMaker.MakeNewLord(faction, lordJob, Find.CurrentMap);
                        }
                        lord.AddPawn(newPawn);
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
示例#3
0
        public static Thing ClosestThingReachable(IntVec3 root, Map map, ThingRequest thingReq, PathEndMode peMode, TraverseParms traverseParams, float maxDistance = 9999f, Predicate <Thing> validator = null, IEnumerable <Thing> customGlobalSearchSet = null, int searchRegionsMin = 0, int searchRegionsMax = -1, bool forceGlobalSearch = false, RegionType traversableRegionTypes = RegionType.Set_Passable, bool ignoreEntirelyForbiddenRegions = false)
        {
            bool flag = searchRegionsMax < 0 || forceGlobalSearch;

            if (!flag && customGlobalSearchSet != null)
            {
                Log.ErrorOnce("searchRegionsMax >= 0 && customGlobalSearchSet != null && !forceGlobalSearch. customGlobalSearchSet will never be used.", 634984, false);
            }
            Thing result;

            if (!flag && !thingReq.IsUndefined && !thingReq.CanBeFoundInRegion)
            {
                Log.ErrorOnce("ClosestThingReachable with thing request group " + thingReq.group + " and global search not allowed. This will never find anything because this group is never stored in regions. Either allow global search or don't call this method at all.", 518498981, false);
                result = null;
            }
            else if (GenClosest.EarlyOutSearch(root, map, thingReq, customGlobalSearchSet, validator))
            {
                result = null;
            }
            else
            {
                Thing thing = null;
                bool  flag2 = false;
                if (!thingReq.IsUndefined && thingReq.CanBeFoundInRegion)
                {
                    int num = (searchRegionsMax <= 0) ? 30 : searchRegionsMax;
                    int num2;
                    thing = GenClosest.RegionwiseBFSWorker(root, map, thingReq, peMode, traverseParams, validator, null, searchRegionsMin, num, maxDistance, out num2, traversableRegionTypes, ignoreEntirelyForbiddenRegions);
                    flag2 = (thing == null && num2 < num);
                }
                if (thing == null && flag && !flag2)
                {
                    if (traversableRegionTypes != RegionType.Set_Passable)
                    {
                        Log.ErrorOnce("ClosestThingReachable had to do a global search, but traversableRegionTypes is not set to passable only. It's not supported, because Reachability is based on passable regions only.", 14384767, false);
                    }
                    Predicate <Thing>   validator2 = (Thing t) => map.reachability.CanReach(root, t, peMode, traverseParams) && (validator == null || validator(t));
                    IEnumerable <Thing> searchSet  = customGlobalSearchSet ?? map.listerThings.ThingsMatching(thingReq);
                    thing = GenClosest.ClosestThing_Global(root, searchSet, maxDistance, validator2, null);
                }
                result = thing;
            }
            return(result);
        }