示例#1
0
        private static ThingsTracker GetCachedTracker(Map map, bool fallbackMode = false)
        {
            int index = map.Index;

            if (index >= 0 && index < comps.Length)
            {
                ThingsTracker tracker = comps[index];
                if (maps[index] != map)
                {
                    maps[index]  = map;
                    comps[index] = tracker = map.GetComponent <ThingsTracker>();
                }
                return(tracker);
            }
            else if (fallbackMode)
            {
                throw new Exception($"GetTracker has failed twice for index {index}");
            }
            Map[]           tempMaps  = new Map[Math.Max(maps.Length * 2, index + 1)];
            ThingsTracker[] tempComps = new ThingsTracker[Math.Max(comps.Length * 2, index + 1)];
            Array.Copy(maps, 0, tempMaps, 0, maps.Length);
            maps = tempMaps;
            Array.Copy(comps, 0, tempComps, 0, comps.Length);
            comps = tempComps;
            return(GetCachedTracker(map, fallbackMode: true));
        }
示例#2
0
        public static IEnumerable <Pawn> PawnsInRange(this IntVec3 cell, Map map, float range, PathEndMode pathEndMode = PathEndMode.None, TraverseMode traverseMode = TraverseMode.ByPawn, Danger danger = Danger.Unspecified)
        {
            ThingsTracker tracker = map.GetThingTracker();

            return(ThingsReachableFrom(map, tracker.ThingsInRangeOf(TrackedThingsRequestCategory.Pawns, cell, range), cell, pathEndMode, traverseMode, danger).Select(t => t as Pawn));
        }
示例#3
0
        public static IEnumerable <Thing> ThingsByDefInRange(this IntVec3 cell, Map map, ThingDef thingDef, float range, PathEndMode pathEndMode = PathEndMode.None, TraverseMode traverseMode = TraverseMode.ByPawn, Danger danger = Danger.Unspecified)
        {
            ThingsTracker tracker = map.GetThingTracker();

            return(ThingsReachableFrom(map, tracker.ThingsInRangeOf(thingDef, cell, range), cell, pathEndMode, traverseMode, danger));
        }
示例#4
0
        public static IEnumerable <Thing> SimilarInRange(this Thing thing, float range, PathEndMode pathEndMode = PathEndMode.None, TraverseMode traverseMode = TraverseMode.ByPawn, Danger danger = Danger.Unspecified)
        {
            ThingsTracker tracker = thing.Map.GetThingTracker();

            return(ThingsReachableFrom(thing.Map, tracker.SimilarInRangeOf(thing, range), thing, pathEndMode, traverseMode, danger));
        }
示例#5
0
        public static IEnumerable <Apparel> ApparelInRange(this IntVec3 cell, Map map, float range)
        {
            ThingsTracker tracker = map.GetThingTracker();

            return(tracker.ThingsInRangeOf(TrackedThingsRequestCategory.Apparel, cell, range).Select(t => t as Apparel));
        }
示例#6
0
        public static IEnumerable <ThingWithComps> MedicineInRange(this IntVec3 cell, Map map, float range)
        {
            ThingsTracker tracker = map.GetThingTracker();

            return(tracker.ThingsInRangeOf(TrackedThingsRequestCategory.Medicine, cell, range).Select(t => t as ThingWithComps));
        }
示例#7
0
        public static IEnumerable <Pawn> HostilesInRange(this IntVec3 cell, Map map, Faction faction, float range)
        {
            ThingsTracker tracker = map.GetThingTracker();

            return(tracker.ThingsInRangeOf(TrackedThingsRequestCategory.Pawns, cell, range).Where(t => t.Faction?.HostileTo(faction) ?? false).Select(t => t as Pawn));
        }
示例#8
0
        public static IEnumerable <Pawn> PawnsInRange(this IntVec3 cell, Map map, float range)
        {
            ThingsTracker tracker = map.GetThingTracker();

            return(tracker.ThingsInRangeOf(TrackedThingsRequestCategory.Pawns, cell, range).Select(t => t as Pawn));
        }
示例#9
0
        public static IEnumerable <Thing> ThingsByDefInRange(this IntVec3 cell, Map map, ThingDef thingDef, float range)
        {
            ThingsTracker tracker = map.GetThingTracker();

            return(tracker.ThingsInRangeOf(thingDef, cell, range));
        }
示例#10
0
        public static IEnumerable <Thing> SimilarInRange(this Thing thing, float range)
        {
            ThingsTracker tracker = thing.Map.GetThingTracker();

            return(tracker.SimilarInRangeOf(thing, range));
        }
示例#11
0
 public static ThingsTracker GetThingTracker(this Map map)
 {
     return(ThingsTracker.GetTracker(map));
 }