protected bool parent; //or child public override bool FilterApplies(Thing t) { if (parent) { IThingHolder parent = t.ParentHolder; while (parent.IsValidHolder()) { if (parent is Thing parentThing && base.FilterApplies(parentThing)) { return(true); } parent = parent.ParentHolder; } return(false); } else { return(ContentsUtility.AllKnownThings(t as IThingHolder).Any(child => base.FilterApplies(child))); } }
public List <Thing> Get(Map map) { IEnumerable <Thing> allThings = Enumerable.Empty <Thing>(); switch (baseType) { case BaseListType.Selectable: allThings = map.listerThings.AllThings.Where(t => t.def.selectable); break; case BaseListType.All: allThings = ContentsUtility.AllKnownThings(map); break; case BaseListType.Buildings: allThings = map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial); break; case BaseListType.Natural: allThings = map.listerThings.AllThings.Where(t => t.def.filthLeaving == ThingDefOf.Filth_RubbleRock); break; case BaseListType.Plants: allThings = map.listerThings.ThingsInGroup(ThingRequestGroup.Plant); break; case BaseListType.Inventory: List <IThingHolder> holders = new List <IThingHolder>(); map.GetChildHolders(holders); List <Thing> list = new List <Thing>(); foreach (IThingHolder holder in holders.Where(ContentsUtility.CanPeekInventory)) { list.AddRange(ContentsUtility.AllKnownThings(holder)); } allThings = list; break; case BaseListType.Items: allThings = map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableAlways); break; case BaseListType.Everyone: allThings = map.mapPawns.AllPawnsSpawned.Cast <Thing>(); break; case BaseListType.Colonists: allThings = map.mapPawns.FreeColonistsSpawned.Cast <Thing>(); break; case BaseListType.Animals: allThings = map.mapPawns.AllPawnsSpawned.Where(p => !p.RaceProps.Humanlike).Cast <Thing>(); break; //Devmode options: case BaseListType.Haulables: allThings = map.listerHaulables.ThingsPotentiallyNeedingHauling(); break; case BaseListType.Mergables: allThings = map.listerMergeables.ThingsPotentiallyNeedingMerging(); break; case BaseListType.FilthInHomeArea: allThings = map.listerFilthInHomeArea.FilthInHomeArea; break; } //Filters allThings = allThings.Where(t => !(t.ParentHolder is Corpse) && !(t.ParentHolder is MinifiedThing)); if (!DebugSettings.godMode) { allThings = allThings.Where(t => ValidDef(t.def)); allThings = allThings.Where(t => !t.PositionHeld.Fogged(map)); } foreach (ListFilter filter in filters) { allThings = filter.Apply(allThings); } //Sort return(allThings.OrderBy(t => t.def.shortHash).ThenBy(t => t.Stuff?.shortHash ?? 0).ThenBy(t => t.Position.x + t.Position.z * 1000).ToList()); }