Example #1
0
        public ThingsTrackingModel[] GetModelsFor(ThingDef def)
        {
            var result = trackers[def.index];

            if (result[0] != null)
            {
                return(result);
            }
            result[0] = new ThingsTrackingModel(def, map, this);
            return(result);
        }
Example #2
0
        public ThingsTracker(Map map) : base(map)
        {
            pawnsTracker    = new ThingsTrackingModel(null, map, this);
            weaponsTracker  = new ThingsTrackingModel(null, map, this);
            ammoTracker     = new ThingsTrackingModel(null, map, this);
            apparelTracker  = new ThingsTrackingModel(null, map, this);
            medicineTracker = new ThingsTrackingModel(null, map, this);
            flaresTracker   = new ThingsTrackingModel(null, map, this);

            trackers = new ThingsTrackingModel[DefDatabase <ThingDef> .AllDefs.Max((def) => def.index) + 1][];
            for (int i = 0; i < trackers.Length; i++)
            {
                trackers[i] = new ThingsTrackingModel[2];
            }

            foreach (var def in DefDatabase <ThingDef> .AllDefs.Where(d => d.race != null || d.category == ThingCategory.Pawn))
            {
                trackers[def.index][1] = pawnsTracker;
            }
            foreach (var def in DefDatabase <ThingDef> .AllDefs.Where(d => d.IsWeapon))
            {
                trackers[def.index][1] = weaponsTracker;
            }
            foreach (var def in DefDatabase <ThingDef> .AllDefs.Where(d => d.IsApparel))
            {
                trackers[def.index][1] = apparelTracker;
            }
            foreach (var def in DefDatabase <ThingDef> .AllDefs.Where(d => d.thingClass == typeof(Flare)))
            {
                trackers[def.index][1] = flaresTracker;
            }
            foreach (var def in DefDatabase <ThingDef> .AllDefs.Where(d => d.IsMedicine))
            {
                trackers[def.index][1] = medicineTracker;
            }
            foreach (var def in DefDatabase <AmmoDef> .AllDefs)
            {
                trackers[def.index][1] = ammoTracker;
            }

            if (validDefs != null)
            {
                return;
            }

            validDefs = new bool[ushort.MaxValue];
            foreach (var def in DefDatabase <ThingDef> .AllDefs)
            {
                if (def.thingClass == typeof(Flare))
                {
                    validDefs[def.index] = true;
                }
                else if (def.category == ThingCategory.Mote)
                {
                    validDefs[def.index] = false;
                }
                else if (def.category == ThingCategory.Filth)
                {
                    validDefs[def.index] = false;
                }
                else if (def.category == ThingCategory.Building)
                {
                    validDefs[def.index] = false;
                }
                else if (def.category == ThingCategory.Gas)
                {
                    validDefs[def.index] = false;
                }
                else if (def.category == ThingCategory.Plant)
                {
                    validDefs[def.index] = false;
                }
                else
                {
                    validDefs[def.index] = true;
                }
            }
            foreach (var def in DefDatabase <FleckDef> .AllDefs)
            {
                validDefs[def.index] = false;
            }
        }
Example #3
0
        public IEnumerable <Thing> ThingsInRangeOf(TrackedThingsRequestCategory category, IntVec3 cell, float range)
        {
            ThingsTrackingModel tracker = GetModelFor(category);

            return(tracker.ThingsInRangeOf(cell, range));
        }