Exemplo n.º 1
0
        public static Thing ClosestThing_Regionwise_ReachablePrioritized(IntVec3 root, Map map, ThingRequest thingReq, PathEndMode peMode, TraverseParms traverseParams, float maxDistance = 9999f, Predicate <Thing> validator = null, Func <Thing, float> priorityGetter = null, int minRegions = 24, int maxRegions = 30)
        {
            Thing result;

            if (!thingReq.IsUndefined && !thingReq.CanBeFoundInRegion)
            {
                Log.ErrorOnce("ClosestThing_Regionwise_ReachablePrioritized with thing request group " + thingReq.group + ". This will never find anything because this group is never stored in regions. Most likely a global search should have been used.", 738476712, false);
                result = null;
            }
            else if (GenClosest.EarlyOutSearch(root, map, thingReq, null, validator))
            {
                result = null;
            }
            else
            {
                if (maxRegions < minRegions)
                {
                    Log.ErrorOnce("maxRegions < minRegions", 754343, false);
                }
                Thing thing = null;
                if (!thingReq.IsUndefined)
                {
                    int num;
                    thing = GenClosest.RegionwiseBFSWorker(root, map, thingReq, peMode, traverseParams, validator, priorityGetter, minRegions, maxRegions, maxDistance, out num, RegionType.Set_Passable, false);
                }
                result = thing;
            }
            return(result);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public static Thing ClosestThing_Regionwise_ReachablePrioritized(IntVec3 root, Map map, ThingRequest thingReq, PathEndMode peMode, TraverseParms traverseParams, float maxDistance = 9999f, Predicate <Thing> validator = null, Func <Thing, float> priorityGetter = null, int minRegions = 24, int maxRegions = 30)
        {
            if (GenClosest.EarlyOutSearch(root, map, thingReq, null))
            {
                return(null);
            }
            if (maxRegions < minRegions)
            {
                Log.ErrorOnce("maxRegions < minRegions", 754343);
            }
            Thing result = null;

            if (!thingReq.IsUndefined)
            {
                result = GenClosest.RegionwiseBFSWorker(root, map, thingReq, peMode, traverseParams, validator, priorityGetter, minRegions, maxRegions, maxDistance, RegionType.Set_Passable, false);
            }
            return(result);
        }
Exemplo n.º 4
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);
        }