コード例 #1
0
        public bool TryGetFilteredApparel(Bill bill, ThingFilter filter, out List <Apparel> gotten, bool getOne = false, bool isForMending = false)
        {
            gotten = null;
            foreach (KeyValuePair <ThingDef, LinkedList <Apparel> > kv in this.StoredApparel.StoredApparelLookup)
            {
                if (bill.IsFixedOrAllowedIngredient(kv.Key) && filter.Allows(kv.Key))
                {
                    foreach (Apparel t in kv.Value)
                    {
                        if (bill.IsFixedOrAllowedIngredient(t) && filter.Allows(t))
                        {
                            if (isForMending && t.HitPoints == t.MaxHitPoints)
                            {
                                continue;
                            }

                            if (gotten == null)
                            {
                                gotten = new List <Apparel>();
                            }
                            gotten.Add(t);

                            if (getOne)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(gotten != null);
        }
        public bool TryGetFirstFilteredItemForMending(Bill bill, ThingFilter filter, bool remove, out Thing gotten)
        {
            gotten = null;
            foreach (LinkedList <Thing> l in this.storedThings.Values)
            {
                if (l != null && l.Count > 0)
                {
                    for (LinkedListNode <Thing> n = l.First; n.Next != null; n = n.Next)
                    {
                        Thing t = n.Value;
                        if (!bill.IsFixedOrAllowedIngredient(t.def) || !filter.Allows(t.def))
                        {
                            break;
                        }

                        if (bill.IsFixedOrAllowedIngredient(t) && filter.Allows(t))
                        {
                            if (t.HitPoints == t.MaxHitPoints)
                            {
                                continue;
                            }

                            l.Remove(n);
                            BuildingUtil.DropSingleThing(t, this, this.Map, out gotten);
                            return(true);
                        }
                    }
                }
            }
            return(gotten != null);
        }
コード例 #3
0
 public bool IsOnMenu(ThingDef def)
 {
     if (menuFilter == null)
     {
         InitMenuFilter(menuGlobalFilter);
     }
     return(menuFilter.Allows(def));
 }
コード例 #4
0
 public bool IsFixedOrAllowedIngredient(Thing thing)
 {
     for (int i = 0; i < recipe.ingredients.Count; i++)
     {
         IngredientCount ingredientCount = recipe.ingredients[i];
         if (ingredientCount.IsFixedIngredient && ingredientCount.filter.Allows(thing))
         {
             return(true);
         }
     }
     return(recipe.fixedIngredientFilter.Allows(thing) && ingredientFilter.Allows(thing));
 }
コード例 #5
0
 private void GetFilteredWeaponsFromStorage(Bill bill, ThingFilter filter, List <ThingWithComps> gotten, KeyValuePair <ThingDef, LinkedList <ThingWithComps> > kv)
 {
     if (filter.Allows(kv.Key))
     {
         foreach (ThingWithComps weapon in kv.Value)
         {
             if (bill.IsFixedOrAllowedIngredient(weapon) && filter.Allows(weapon))
             {
                 gotten.Add(weapon);
             }
         }
     }
 }
コード例 #6
0
        public bool ThingMatches(Thing thing)
        {
            if (HasThing)
            {
                return(this.thing == thing);
            }
            if (HasThingFilter)
            {
                return(thingFilter.Allows(thing));
            }

            return(false);
        }
コード例 #7
0
        public static bool PlayerOrItemStashHas(ThingFilter thingFilter)
        {
            ThingRequest bestThingRequest = thingFilter.BestThingRequest;
            List <Map>   maps             = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                List <Thing> list = maps[i].listerThings.ThingsMatching(bestThingRequest);
                for (int j = 0; j < list.Count; j++)
                {
                    if (thingFilter.Allows(list[j]))
                    {
                        return(true);
                    }
                }
            }
            List <Caravan> caravans = Find.WorldObjects.Caravans;

            for (int k = 0; k < caravans.Count; k++)
            {
                if (caravans[k].IsPlayerControlled)
                {
                    List <Thing> list2 = CaravanInventoryUtility.AllInventoryItems(caravans[k]);
                    for (int l = 0; l < list2.Count; l++)
                    {
                        if (thingFilter.Allows(list2[l]))
                        {
                            return(true);
                        }
                    }
                }
            }
            List <Site> sites = Find.WorldObjects.Sites;

            for (int m = 0; m < sites.Count; m++)
            {
                ItemStashContentsComp component = sites[m].GetComponent <ItemStashContentsComp>();
                if (component != null)
                {
                    ThingOwner contents = component.contents;
                    for (int n = 0; n < contents.Count; n++)
                    {
                        if (thingFilter.Allows(contents[n]))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #8
0
        public ZoneContainer(Zone_Stockpile stockpile) : base(new Version(1, 0))
        {
            ThingFilter filter = stockpile.settings.filter;

            Stockpile  = stockpile;
            Color      = stockpile.color;
            Priority   = stockpile.settings.Priority;
            Reflection = new ThingFilterReflection(filter);

            // Allowed things
            var allowed = from thing in Reflection.AllStorableThingDefs
                          where filter.Allows(thing)
                          select thing;

            AllowedThings = new List <ThingDef>(allowed);


            // Can configure HP
            if (filter.allowedHitPointsConfigurable)
            {
                AllowedHitPoints = filter.AllowedHitPointsPercents;
            }


            // Can configure Qualities
            if (filter.allowedQualitiesConfigurable)
            {
                AllowedQualities = filter.AllowedQualityLevels;
            }


            // Disallowed Specials
            DisallowedSpecialThings = Reflection.DisallowedSpecialFilters;
        }
コード例 #9
0
 public bool AllowedToAccept(Thing t)
 {
     if (!filter.Allows(t))
     {
         return(false);
     }
     if (owner != null)
     {
         StorageSettings parentStoreSettings = owner.GetParentStoreSettings();
         if (parentStoreSettings != null && !parentStoreSettings.AllowedToAccept(t))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #10
0
        /// <summary>
        /// Extra predicate used when searching for possible ingredients.
        /// </summary>
        /// <returns>New predicate</returns>
        public Predicate <Thing> ExtraPredicate()
        {
            if (nutrition)
            {
                if (thingFilter == null)
                {
                    return(thing => (!thing.def?.ingestible.IsMeal ?? false) && thing.def.IsNutritionGivingIngestible);
                }
                else
                {
                    return delegate(Thing thing)
                           {
                               if (thingFilter.Allows(thing) && thing.def.IsNutritionGivingIngestible)
                               {
                                   Corpse corpse = thing as Corpse;
                                   if (corpse != null && corpse.IsDessicated())
                                   {
                                       return false;
                                   }
                                   return true;
                               }

                               return false;
                           }
                };
                //return thing => thingFilter.Allows(thing) && thing.def.IsNutritionGivingIngestible
            }

            return(thing => true);
        }
コード例 #11
0
        public bool DoesThingMatchFilter(ThingFilter ingredientFilter, Thing thing)
        {
            if (_extendedBillData.UseInputFilter &&
                thing.Stuff != null &&
                ingredientFilter != null)
            {
                if (!ingredientFilter.Allows(thing.Stuff))
                {
                    return(false);
                }
            }

            var filter = _extendedBillData.OutputFilter;

            if (_isQualityFilterNeeded)
            {
                QualityCategory quality;
                if (filter.allowedQualitiesConfigurable && thing.TryGetQuality(out quality))
                {
                    if (!filter.AllowedQualityLevels.Includes(quality))
                    {
                        return(false);
                    }
                }
            }

            if (!_isHitpointsFilterNeeded)
            {
                return(true);
            }

            var thingHitPointsPercent = (float)thing.HitPoints / thing.MaxHitPoints;

            return(filter.AllowedHitPointsPercents.IncludesEpsilon(thingHitPointsPercent));
        }
コード例 #12
0
        private bool DoFiltersMatch(ThingFilter first, ThingFilter second)
        {
            if (first == null && second == null)
            {
                return(true);
            }

            if (first == null || second == null)
            {
                return(false);
            }

            // Only matching on allowed things for performance. May need to match
            // other fields in the future;
            if (first.AllowedDefCount != second.AllowedDefCount)
            {
                return(false);
            }

            foreach (var thingDef in first.AllowedThingDefs)
            {
                if (first.Allows(thingDef) != second.Allows(thingDef))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #13
0
 public bool TryGetFilteredThings(Bill bill, ThingFilter filter, out List <Thing> gotten)
 {
     gotten = null;
     foreach (LinkedList <Thing> l in this.storedThings.Values)
     {
         if (l.Count > 0)
         {
             if (bill.IsFixedOrAllowedIngredient(l.First.Value.def))
             {
                 foreach (Thing t in l)
                 {
                     if (filter.Allows(t))
                     {
                         if (gotten == null)
                         {
                             gotten = new List <Thing>();
                         }
                         gotten.Add(t);
                     }
                 }
             }
         }
     }
     return(gotten != null);
 }
コード例 #14
0
 public static void Postfix(ThingDef td, ThingFilter ___parentFilter, ref bool __result)
 {
     if (HarmonyPatches.VisibleBooksCategory)
     {
         __result = td.IsWithinCategory(TechDefOf.Knowledge) && ___parentFilter.Allows(td);
     }
 }
コード例 #15
0
        public static void Add(this ThingFilter filter, ThingFilter other)
        {
            foreach (ThingDef def in other.AllowedThingDefs)
            {
                filter.SetAllow(def, true);
            }

            List <SpecialThingFilterDef> disallowedSpecialFilters = (List <SpecialThingFilterDef>)specials.GetValue(other);

            foreach (SpecialThingFilterDef specDef in disallowedSpecialFilters)
            {
                if (other.Allows(specDef))
                {
                    filter.SetAllow(specDef, true);
                }
            }

            QualityRange q  = filter.AllowedQualityLevels;
            QualityRange qO = other.AllowedQualityLevels;

            q.max = q.max > qO.max ? q.max : qO.max;
            q.min = q.min < qO.min ? q.min : qO.min;
            filter.AllowedQualityLevels = q;

            FloatRange hp  = filter.AllowedHitPointsPercents;
            FloatRange hpO = other.AllowedHitPointsPercents;

            hp.max = Math.Max(hp.max, hpO.max);
            hp.min = Math.Min(hp.min, hpO.min);
            filter.AllowedHitPointsPercents = hp;
        }
コード例 #16
0
        public static ThingDef TryFindRandomShellDef(ThingDef turret, bool allowEMP = true, bool mustHarmHealth = true, TechLevel techLevel = TechLevel.Undefined, bool allowAntigrainWarhead = false, float maxMarketValue = -1f)
        {
            ThingDef result;

            if (!TurretGunUtility.NeedsShells(turret))
            {
                result = null;
            }
            else
            {
                ThingFilter fixedFilter = turret.building.turretGunDef.building.fixedStorageSettings.filter;
                ThingDef    thingDef;
                if ((from x in DefDatabase <ThingDef> .AllDefsListForReading
                     where fixedFilter.Allows(x) && (allowEMP || x.projectileWhenLoaded.projectile.damageDef != DamageDefOf.EMP) && (!mustHarmHealth || x.projectileWhenLoaded.projectile.damageDef.harmsHealth) && (techLevel == TechLevel.Undefined || x.techLevel <= techLevel) && (allowAntigrainWarhead || x != ThingDefOf.Shell_AntigrainWarhead) && (maxMarketValue < 0f || x.BaseMarketValue <= maxMarketValue)
                     select x).TryRandomElement(out thingDef))
                {
                    result = thingDef;
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
コード例 #17
0
        private bool Allows(Thing t, ThingDef expectedDef, QualityRange qualityRange, FloatRange hpRange, ThingFilter filter)
        {
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Warning("StoredApparel.Allows Begin [" + t.Label + "]");
#endif
            if (t.def != expectedDef)
            {
#if DEBUG || DEBUG_DO_UNTIL_X
                Log.Warning("StoredApparel.Allows End Def Does Not Match [False]");
#endif
                return(false);
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Message("    def uses HP: " + expectedDef.useHitPoints + " filter: " + hpRange.min + " " + hpRange.max);
#endif
            if (expectedDef.useHitPoints &&
                hpRange != null &&
                hpRange.min != 0f && hpRange.max != 100f)
            {
                float num = (float)t.HitPoints / (float)t.MaxHitPoints;
                num = GenMath.RoundedHundredth(num);
                if (!hpRange.IncludesEpsilon(Mathf.Clamp01(num)))
                {
#if DEBUG || DEBUG_DO_UNTIL_X
                    Log.Warning("StoredApparel.Allows End Hit Points [False - HP]");
#endif
                    return(false);
                }
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Message("    def follows quality: " + t.def.FollowQualityThingFilter() + " filter quality levels: " + qualityRange.min + " " + qualityRange.max);
#endif
            if (qualityRange != null && qualityRange != QualityRange.All && t.def.FollowQualityThingFilter())
            {
                QualityCategory p;
                if (!t.TryGetQuality(out p))
                {
                    p = QualityCategory.Normal;
                }
                if (!qualityRange.Includes(p))
                {
#if DEBUG || DEBUG_DO_UNTIL_X
                    Log.Warning("StoredApparel.Allows End Quality [False - Quality]");
#endif
                    return(false);
                }
            }

            if (filter != null && !filter.Allows(t.Stuff))
            {
#if DEBUG || DEBUG_DO_UNTIL_X
                Log.Warning("StoredApparel.Allows End Quality [False - filters.Allows]");
#endif
                return(false);
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Warning("    StoredApparel.Allows End [True]");
#endif
            return(true);
        }
コード例 #18
0
        // Token: 0x06000011 RID: 17 RVA: 0x000022E8 File Offset: 0x000004E8
        public Predicate <Thing> ExtraPredicate()
        {
            if (!nutrition)
            {
                return(_ => true);
            }

            if (thingFilter == null)
            {
                return(delegate(Thing thing)
                {
                    var def = thing.def;
                    return def != null && !def.ingestible.IsMeal && thing.def.IsNutritionGivingIngestible;
                });
            }

            return(delegate(Thing thing)
            {
                if (thingFilter.Allows(thing) && thing.def.IsNutritionGivingIngestible)
                {
                    return !(thing is Corpse corpse) || !corpse.IsDessicated();
                }

                return false;
            });
        }
コード例 #19
0
        public bool Allows(Thing thing)
        {
            TechLevel thingTech = thing.def.techLevel;

            return(thingTech >= techLevel.min &&
                   thingTech <= techLevel.max &&
                   match.Allows(thing));
        }
コード例 #20
0
 public bool CanUseStuffForApparel(ThingDef stuffDef)
 {
     if (apparelStuffFilter == null)
     {
         return(true);
     }
     return(apparelStuffFilter.Allows(stuffDef));
 }
        //private bool InViewArea => true;

        #region Drawers
        private void DoSpecialFilter(SpecialThingFilterDef sfDef, int nestLevel)
        {
            if (!sfDef.configurable)
            {
                return;
            }
            if (InViewArea)
            {
                LabelLeft("*" + sfDef.LabelCap, sfDef.description, nestLevel);
                var flag  = filter.Allows(sfDef);
                var flag2 = flag;
                Widgets.Checkbox(new Vector2(LabelWidth, curY), ref flag, lineHeight, false, true);
                if (flag != flag2)
                {
                    filter.SetAllow(sfDef, flag);
                }
            }
            EndLine();
        }
コード例 #22
0
        public bool TryGetFilteredApparel(Bill bill, ThingFilter filter, out List <Apparel> gotten, bool getOne = false, bool isForMending = false)
        {
            gotten = null;
            foreach (KeyValuePair <ThingDef, LinkedList <Apparel> > kv in this.StoredApparel.StoredApparelLookup)
            {
                if (bill.IsFixedOrAllowedIngredient(kv.Key) && filter.Allows(kv.Key))
                {
                    var n = kv.Value.First;
                    while (n != null)
                    {
                        var     next = n.Next;
                        Apparel t    = n.Value;
                        if (t == null || t.Destroyed || t.HitPoints == 0)
                        {
                            kv.Value.Remove(n);
                        }
                        else if (bill.IsFixedOrAllowedIngredient(t) && filter.Allows(t))
                        {
                            if (isForMending && t.HitPoints == t.MaxHitPoints)
                            {
                                continue;
                            }

                            if (gotten == null)
                            {
                                gotten = new List <Apparel>();
                            }
                            gotten.Add(t);

                            if (getOne)
                            {
                                return(true);
                            }
                        }
                        n = next;
                    }
                }
            }
            return(gotten != null);
        }
コード例 #23
0
        private static Thing FindBestFuel(Pawn pawn, ThingFilter filter)
        {
            Predicate <Thing> validator = delegate(Thing x)
            {
                if (x.IsForbidden(pawn) || !pawn.CanReserve(x))
                {
                    return(false);
                }
                return(filter.Allows(x) ? true : false);
            };

            return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, filter.BestThingRequest, PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, validator));
        }
コード例 #24
0
        private static FloatRange CalculateStatRange(StatDef stat)
        {
            var statRange     = FloatRange.Zero;
            var apparelFilter = new ThingFilter();

            apparelFilter.SetAllow(ThingCategoryDefOf.Apparel, true);
            var apparels = ThingCategoryNodeDatabase.RootNode.catDef.DescendantThingDefs
                           .Where(t => apparelFilter.Allows(t) && !apparelFilter.IsAlwaysDisallowedDueToSpecialFilters(t)).ToList()
                           .Where(a => a.statBases != null && a.StatBaseDefined(stat) ||
                                  a.equippedStatOffsets != null && a.equippedStatOffsets.Any(o => o.stat == stat)).ToList();

            if (apparels.Any())
            {
                foreach (var apparel in apparels)
                {
                    var   statBase        = apparel.statBases?.Find(sm => sm.stat == stat);
                    var   baseStatValue   = statBase?.value ?? stat.defaultBaseValue;
                    float statOffsetValue = 0;
                    var   statOffset      = apparel.equippedStatOffsets?.Find(sm => sm.stat == stat);
                    if (statOffset != null)
                    {
                        statOffsetValue = statOffset.value;
                    }
                    var totalStatValue = baseStatValue + statOffsetValue - stat.defaultBaseValue;
                    if (Math.Abs(statRange.min) < 0.0001 && Math.Abs(statRange.max) < 0.0001)
                    {
                        statRange.min = totalStatValue;
                        statRange.max = totalStatValue;
                    }
                    else
                    {
                        if (statRange.min > totalStatValue)
                        {
                            statRange.min = totalStatValue;
                        }
                        if (statRange.max < totalStatValue)
                        {
                            statRange.max = totalStatValue;
                        }
                    }
                }
            }
            else
            {
                statRange.min = stat.defaultBaseValue;
                statRange.max = stat.defaultBaseValue;
            }
            StatRanges.Add(stat, statRange);
            return(statRange);
        }
コード例 #25
0
        public static ThingDef TryFindRandomShellDef(ThingDef turret, bool allowEMP = true, bool mustHarmHealth = true, TechLevel techLevel = TechLevel.Undefined, bool allowAntigrainWarhead = false, float maxMarketValue = -1f)
        {
            if (!NeedsShells(turret))
            {
                return(null);
            }
            ThingFilter fixedFilter = turret.building.turretGunDef.building.fixedStorageSettings.filter;

            if (DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef x) => fixedFilter.Allows(x) && (allowEMP || x.projectileWhenLoaded.projectile.damageDef != DamageDefOf.EMP) && (!mustHarmHealth || x.projectileWhenLoaded.projectile.damageDef.harmsHealth) && (techLevel == TechLevel.Undefined || (int)x.techLevel <= (int)techLevel) && (allowAntigrainWarhead || x != ThingDefOf.Shell_AntigrainWarhead) && (maxMarketValue < 0f || x.BaseMarketValue <= maxMarketValue)).TryRandomElement(out ThingDef result))
            {
                return(result);
            }
            return(null);
        }
コード例 #26
0
        internal bool TryRemoveBestApparel(ThingDef def, ThingFilter filter, out Apparel apparel)
        {
#if DEBUG
            Log.Message(Environment.NewLine + "Start StoredApparel.TryRemoveBestApperal Def: " + def.label);
#endif
            LinkedList <Apparel> l;
            if (this.StoredApparelLookup.TryGetValue(def, out l))
            {
#if DEBUG
                Log.Warning("Apparel List found Count: " + l.Count);
#endif
                LinkedListNode <Apparel> n = l.First;
                while (n != null)
                {
#if DEBUG
                    Log.Warning("Apparel " + n.Value.Label);
#endif
                    try
                    {
                        var next = n.Next;
                        if (filter.Allows(n.Value))
                        {
                            l.Remove(n);
                            apparel = n.Value;
#if DEBUG
                            Log.Warning("Start StoredApparel.TryRemoveBestApperal Return: True Apparel:" + apparel.LabelShort + Environment.NewLine);
#endif
                            return(true);
                        }
#if DEBUG
                        else
                        {
                            Log.Warning("Filter rejected");
                        }
#endif
                        n = next;
                    }
                    catch
                    {
                        Log.Error("catch");
                    }
                }
            }
            apparel = null;
#if DEBUG
            Log.Message("End StoredApparel.TryRemoveBestApperal Return: False" + Environment.NewLine);
#endif
            return(false);
        }
コード例 #27
0
        private static void WriteFiltersToFile(ThingFilter filter, StreamWriter sw)
        {
            ThingFilterReflection tfr = new ThingFilterReflection(filter);
            StringBuilder         sb  = new StringBuilder();

            foreach (ThingDef thing in tfr.AllStorableThingDefs)
            {
                if (filter.Allows(thing))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("/");
                    }
                    sb.Append(thing.defName);
                }
            }
            WriteField(sw, "allowedDefs", sb.ToString());
            sb = null;

            if (filter.allowedHitPointsConfigurable)
            {
                sb = new StringBuilder(filter.AllowedHitPointsPercents.min.ToString("N4"));
                sb.Append(":");
                sb.Append(filter.AllowedHitPointsPercents.max.ToString("N4"));
                WriteField(sw, "allowedHitPointsPercents", sb.ToString());
                sb = null;
            }

            if (filter.allowedQualitiesConfigurable)
            {
                sb = new StringBuilder(filter.AllowedQualityLevels.min.ToString());
                sb.Append(":");
                sb.Append(filter.AllowedQualityLevels.max.ToString());
                WriteField(sw, "allowedQualities", sb.ToString());
                sb = null;
            }

            sb = new StringBuilder();
            foreach (SpecialThingFilterDef def in tfr.DisallowedSpecialFilters)
            {
                if (sb.Length > 0)
                {
                    sb.Append("/");
                }
                sb.Append(def.defName);
            }
            WriteField(sw, "disallowedSpecialFilters", sb.ToString());
            sb = null;
        }
        private bool Visible(ThingDef td)
        {
            if (td.menuHidden)
            {
                return(false);
            }
            if (forceHiddenDefs != null && forceHiddenDefs.Contains(td))
            {
                return(false);
            }
            if (parentFilter != null)
            {
                if (!parentFilter.Allows(td))
                {
                    return(false);
                }
                if (parentFilter.IsAlwaysDisallowedDueToSpecialFilters(td))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #29
0
 public bool TryRemove(ThingFilter filter, out List <Thing> removed)
 {
     foreach (LinkedList <Thing> l in this.storedThings.Values)
     {
         if (l.Count > 0 &&
             filter.Allows(l.First.Value.def))
         {
             Thing t     = l.First.Value;
             int   count = Math.Min(t.stackCount, t.def.stackLimit);
             return(this.TryRemove(t, count, out removed));
         }
     }
     removed = null;
     return(false);
 }
コード例 #30
0
        private static List <Thing> FindAllFuel(Pawn pawn, Thing refuelable)
        {
            int               quantity  = refuelable.TryGetComp <CompRefuelable>().GetFuelCountToFullyRefuel();
            ThingFilter       filter    = refuelable.TryGetComp <CompRefuelable>().Props.fuelFilter;
            Predicate <Thing> validator = delegate(Thing x)
            {
                if (x.IsForbidden(pawn) || !pawn.CanReserve(x))
                {
                    return(false);
                }
                if (!filter.Allows(x))
                {
                    return(false);
                }
                return(true);
            };
            IntVec3              position       = refuelable.Position;
            Region               region         = position.GetRegion(pawn.Map);
            TraverseParms        traverseParams = TraverseParms.For(pawn);
            RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParams, isDestination: false);
            List <Thing>         chosenThings   = new List <Thing>();
            int             accumulatedQuantity = 0;
            RegionProcessor regionProcessor     = delegate(Region r)
            {
                List <Thing> list = r.ListerThings.ThingsMatching(ThingRequest.ForGroup(ThingRequestGroup.HaulableEver));
                for (int i = 0; i < list.Count; i++)
                {
                    Thing thing = list[i];
                    if (validator(thing) && !chosenThings.Contains(thing) && ReachabilityWithinRegion.ThingFromRegionListerReachable(thing, r, PathEndMode.ClosestTouch, pawn))
                    {
                        chosenThings.Add(thing);
                        accumulatedQuantity += thing.stackCount;
                        if (accumulatedQuantity >= quantity)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            };

            RegionTraverser.BreadthFirstTraverse(region, entryCondition, regionProcessor, 99999);
            if (accumulatedQuantity >= quantity)
            {
                return(chosenThings);
            }
            return(null);
        }
コード例 #31
0
 public static bool Matches( this ThingFilter a, ThingFilter b )
 {
     foreach( var thingDefA in a.AllowedThingDefs )
     {
         if( !b.Allows( thingDefA ) )
         {
             return false;
         }
     }
     foreach( var thingDefB in b.AllowedThingDefs )
     {
         if( !a.Allows( thingDefB ) )
         {
             return false;
         }
     }
     return true;
 }
コード例 #32
0
        public List<Thing> GetAllResources( ThingFilter acceptableResources )
        {
            var things = parent.Position.GetThingList().Where( t => (
                ( acceptableResources.Allows( t.def ) )
            ) ).ToList();
            if( things.NullOrEmpty() )
            {
                return null;
            }

            things.Sort( ( Thing x, Thing y ) => ( x.stackCount > y.stackCount ) ? -1 : 1 );

            // Return sorted by quantity list of things
            return things;
        }