Exemplo n.º 1
0
        public static Thing TryMakeForStockSingle(ThingDef thingDef, int stackCount)
        {
            Thing result;

            if (stackCount <= 0)
            {
                result = null;
            }
            else if (!thingDef.tradeability.TraderCanSell())
            {
                Log.Error("Tried to make non-trader-sellable thing for trader stock: " + thingDef, false);
                result = null;
            }
            else
            {
                ThingDef stuff = null;
                if (thingDef.MadeFromStuff)
                {
                    if (!(from x in GenStuff.AllowedStuffsFor(thingDef, TechLevel.Undefined)
                          where !PawnWeaponGenerator.IsDerpWeapon(thingDef, x)
                          select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff))
                    {
                        stuff = GenStuff.RandomStuffByCommonalityFor(thingDef, TechLevel.Undefined);
                    }
                }
                Thing thing = ThingMaker.MakeThing(thingDef, stuff);
                thing.stackCount = stackCount;
                result           = thing;
            }
            return(result);
        }
 public static bool IsDerpAndDisallowed(ThingDef thing, ThingDef stuff, QualityGenerator?qualityGenerator)
 {
     if (qualityGenerator == QualityGenerator.Gift || qualityGenerator == QualityGenerator.Reward || qualityGenerator == QualityGenerator.Super)
     {
         if (!PawnWeaponGenerator.IsDerpWeapon(thing, stuff))
         {
             return(PawnApparelGenerator.IsDerpApparel(thing, stuff));
         }
         return(true);
     }
     return(false);
 }
        public static float CheapestNonDerpPriceFor(ThingDef weaponDef)
        {
            float num = 9999999f;

            for (int i = 0; i < PawnWeaponGenerator.allWeaponPairs.Count; i++)
            {
                ThingStuffPair thingStuffPair = PawnWeaponGenerator.allWeaponPairs[i];
                if (thingStuffPair.thing == weaponDef && !PawnWeaponGenerator.IsDerpWeapon(thingStuffPair.thing, thingStuffPair.stuff) && thingStuffPair.Price < num)
                {
                    num = thingStuffPair.Price;
                }
            }
            return(num);
        }
Exemplo n.º 4
0
        public static Thing TryMakeForStockSingle(ThingDef thingDef, int stackCount)
        {
            if (stackCount <= 0)
            {
                return(null);
            }
            if (!thingDef.tradeability.TraderCanSell())
            {
                Log.Error("Tried to make non-trader-sellable thing for trader stock: " + thingDef);
                return(null);
            }
            ThingDef result = null;

            if (thingDef.MadeFromStuff && !(from x in GenStuff.AllowedStuffsFor(thingDef)
                                            where !PawnWeaponGenerator.IsDerpWeapon(thingDef, x)
                                            select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out result))
            {
                result = GenStuff.RandomStuffByCommonalityFor(thingDef);
            }
            Thing thing = ThingMaker.MakeThing(thingDef, result);

            thing.stackCount = stackCount;
            return(thing);
        }
Exemplo n.º 5
0
        public static List <ThingStuffPairWithQuality> GenerateDefsWithPossibleTotalValue(IntRange countRange, float totalValue, IEnumerable <ThingDef> allowed, TechLevel techLevel, QualityGenerator qualityGenerator, Func <ThingStuffPairWithQuality, float> getMinValue, Func <ThingStuffPairWithQuality, float> getMaxValue, Func <ThingDef, float> weightSelector = null, int tries = 100, float maxMass = 3.40282347E+38f)
        {
            List <ThingStuffPairWithQuality> chosen = new List <ThingStuffPairWithQuality>();

            if (countRange.max <= 0)
            {
                return(chosen);
            }
            if (countRange.min < 1)
            {
                countRange.min = 1;
            }
            ThingSetMakerByTotalStatUtility.CalculateAllowedThingStuffPairs(allowed, techLevel, qualityGenerator);
            float trashThreshold = ThingSetMakerByTotalStatUtility.GetTrashThreshold(countRange, totalValue, getMaxValue);

            ThingSetMakerByTotalStatUtility.allowedThingStuffPairs.RemoveAll((ThingStuffPairWithQuality x) => getMaxValue(x) < trashThreshold);
            if (!ThingSetMakerByTotalStatUtility.allowedThingStuffPairs.Any <ThingStuffPairWithQuality>())
            {
                return(chosen);
            }
            float minCandidateValueEver = float.MaxValue;
            float maxCandidateValueEver = float.MinValue;
            float minMassEver           = float.MaxValue;

            foreach (ThingStuffPairWithQuality thingStuffPairWithQuality in ThingSetMakerByTotalStatUtility.allowedThingStuffPairs)
            {
                minCandidateValueEver = Mathf.Min(minCandidateValueEver, getMinValue(thingStuffPairWithQuality));
                maxCandidateValueEver = Mathf.Max(maxCandidateValueEver, getMaxValue(thingStuffPairWithQuality));
                if (thingStuffPairWithQuality.thing.category != ThingCategory.Pawn)
                {
                    minMassEver = Mathf.Min(minMassEver, ThingSetMakerByTotalStatUtility.GetNonTrashMass(thingStuffPairWithQuality, trashThreshold, getMinValue));
                }
            }
            minCandidateValueEver = Mathf.Max(minCandidateValueEver, trashThreshold);
            float totalMinValueSoFar = 0f;
            float totalMaxValueSoFar = 0f;
            float minMassSoFar       = 0f;
            int   num = 0;

            for (;;)
            {
                num++;
                if (num > 10000)
                {
                    break;
                }
                IEnumerable <ThingStuffPairWithQuality> enumerable = ThingSetMakerByTotalStatUtility.allowedThingStuffPairs.Where(delegate(ThingStuffPairWithQuality x)
                {
                    if (maxMass != 3.40282347E+38f && x.thing.category != ThingCategory.Pawn)
                    {
                        float nonTrashMass = ThingSetMakerByTotalStatUtility.GetNonTrashMass(x, trashThreshold, getMinValue);
                        if (minMassSoFar + nonTrashMass > maxMass)
                        {
                            return(false);
                        }
                        if (chosen.Count < countRange.min && minMassSoFar + minMassEver * (float)(countRange.min - chosen.Count - 1) + nonTrashMass > maxMass)
                        {
                            return(false);
                        }
                    }
                    return(totalMinValueSoFar + Mathf.Max(getMinValue(x), trashThreshold) <= totalValue && (chosen.Count >= countRange.min || totalMinValueSoFar + minCandidateValueEver * (float)(countRange.min - chosen.Count - 1) + Mathf.Max(getMinValue(x), trashThreshold) <= totalValue));
                });
                if (countRange.max != 2147483647 && totalMaxValueSoFar < totalValue * 0.5f)
                {
                    IEnumerable <ThingStuffPairWithQuality> enumerable2 = enumerable;
                    enumerable = from x in enumerable
                                 where totalMaxValueSoFar + maxCandidateValueEver * (float)(countRange.max - chosen.Count - 1) + getMaxValue(x) >= totalValue * 0.5f
                                 select x;
                    if (!enumerable.Any <ThingStuffPairWithQuality>())
                    {
                        enumerable = enumerable2;
                    }
                }
                float maxCandidateMinValue = float.MinValue;
                foreach (ThingStuffPairWithQuality arg in enumerable)
                {
                    maxCandidateMinValue = Mathf.Max(maxCandidateMinValue, Mathf.Max(getMinValue(arg), trashThreshold));
                }
                ThingStuffPairWithQuality thingStuffPairWithQuality2;
                if (!enumerable.TryRandomElementByWeight(delegate(ThingStuffPairWithQuality x)
                {
                    float a = 1f;
                    if (countRange.max != 2147483647 && chosen.Count < countRange.max && totalValue >= totalMaxValueSoFar)
                    {
                        int num2 = countRange.max - chosen.Count;
                        float b = (totalValue - totalMaxValueSoFar) / (float)num2;
                        a = Mathf.InverseLerp(0f, b, getMaxValue(x));
                    }
                    float b2 = 1f;
                    if (chosen.Count < countRange.min && totalValue >= totalMinValueSoFar)
                    {
                        int num3 = countRange.min - chosen.Count;
                        float num4 = (totalValue - totalMinValueSoFar) / (float)num3;
                        float num5 = Mathf.Max(getMinValue(x), trashThreshold);
                        if (num5 > num4)
                        {
                            b2 = num4 / num5;
                        }
                    }
                    float num6 = Mathf.Max(Mathf.Min(a, b2), 1E-05f);
                    if (weightSelector != null)
                    {
                        num6 *= weightSelector(x.thing);
                    }
                    if (totalValue > totalMaxValueSoFar)
                    {
                        int num7 = Mathf.Max(countRange.min - chosen.Count, 1);
                        float num8 = Mathf.InverseLerp(0f, maxCandidateMinValue * 0.85f, ThingSetMakerByTotalStatUtility.GetMaxValueWithMaxMass(x, minMassSoFar, maxMass, getMinValue, getMaxValue) * (float)num7);
                        num6 *= num8 * num8;
                    }
                    if (PawnWeaponGenerator.IsDerpWeapon(x.thing, x.stuff))
                    {
                        num6 *= 0.1f;
                    }
                    if (techLevel != TechLevel.Undefined)
                    {
                        TechLevel techLevel2 = x.thing.techLevel;
                        if (techLevel2 < techLevel && techLevel2 <= TechLevel.Neolithic && (x.thing.IsApparel || x.thing.IsWeapon))
                        {
                            num6 *= 0.1f;
                        }
                    }
                    return(num6);
                }, out thingStuffPairWithQuality2))
                {
                    goto Block_10;
                }
                chosen.Add(thingStuffPairWithQuality2);
                totalMinValueSoFar += Mathf.Max(getMinValue(thingStuffPairWithQuality2), trashThreshold);
                totalMaxValueSoFar += getMaxValue(thingStuffPairWithQuality2);
                if (thingStuffPairWithQuality2.thing.category != ThingCategory.Pawn)
                {
                    minMassSoFar += ThingSetMakerByTotalStatUtility.GetNonTrashMass(thingStuffPairWithQuality2, trashThreshold, getMinValue);
                }
                if (chosen.Count >= countRange.max)
                {
                    goto Block_12;
                }
                if (chosen.Count >= countRange.min && totalMaxValueSoFar >= totalValue * 0.9f)
                {
                    goto Block_14;
                }
            }
            Log.Error("Too many iterations.", false);
Block_10:
Block_12:
Block_14:
            return(chosen);
        }
 internal static void MakeTableWeaponPairs()
 {
     DebugTables.MakeTablesDialog(from p in PawnWeaponGenerator.allWeaponPairs
                                  orderby p.thing.defName descending
                                  select p, new TableDataGetter <ThingStuffPair>("thing", (ThingStuffPair p) => p.thing.defName), new TableDataGetter <ThingStuffPair>("stuff", (ThingStuffPair p) => (p.stuff == null) ? string.Empty : p.stuff.defName), new TableDataGetter <ThingStuffPair>("price", (ThingStuffPair p) => p.Price.ToString()), new TableDataGetter <ThingStuffPair>("commonality", (ThingStuffPair p) => p.Commonality.ToString("F5")), new TableDataGetter <ThingStuffPair>("commMult", (ThingStuffPair p) => p.commonalityMultiplier.ToString("F5")), new TableDataGetter <ThingStuffPair>("def-commonality", (ThingStuffPair p) => p.thing.generateCommonality.ToString("F2")), new TableDataGetter <ThingStuffPair>("derp", (ThingStuffPair p) => (!PawnWeaponGenerator.IsDerpWeapon(p.thing, p.stuff)) ? string.Empty : "D"));
 }
        public static List <ThingStuffPairWithQuality> GenerateDefsWithPossibleTotalValue_NewTmp3(IntRange countRange, float totalValue, IEnumerable <ThingDef> allowed, TechLevel techLevel, QualityGenerator qualityGenerator, Func <ThingStuffPairWithQuality, float> getMinValue, Func <ThingStuffPairWithQuality, float> getMaxValue, Func <ThingStuffPairWithQuality, float> getSingleThingValue, Func <ThingDef, float> weightSelector = null, int tries = 100, float maxMass = float.MaxValue, bool allowNonStackableDuplicates = true, float minSingleItemValue = 0f)
        {
            List <ThingStuffPairWithQuality> chosen = new List <ThingStuffPairWithQuality>();

            if (countRange.max <= 0)
            {
                return(chosen);
            }
            if (countRange.min < 1)
            {
                countRange.min = 1;
            }
            CalculateAllowedThingStuffPairs(allowed, techLevel, qualityGenerator);
            float trashThreshold = Mathf.Max(GetTrashThreshold(countRange, totalValue, getMaxValue), minSingleItemValue);

            allowedThingStuffPairs.RemoveAll((ThingStuffPairWithQuality x) => getMaxValue(x) < trashThreshold);
            if (!allowedThingStuffPairs.Any())
            {
                return(chosen);
            }
            float minCandidateValueEver = float.MaxValue;
            float maxCandidateValueEver = float.MinValue;
            float minMassEver           = float.MaxValue;

            foreach (ThingStuffPairWithQuality allowedThingStuffPair in allowedThingStuffPairs)
            {
                minCandidateValueEver = Mathf.Min(minCandidateValueEver, getMinValue(allowedThingStuffPair));
                maxCandidateValueEver = Mathf.Max(maxCandidateValueEver, getMaxValue(allowedThingStuffPair));
                if (allowedThingStuffPair.thing.category != ThingCategory.Pawn)
                {
                    minMassEver = Mathf.Min(minMassEver, GetNonTrashMass(allowedThingStuffPair, trashThreshold, getMinValue));
                }
            }
            minCandidateValueEver = Mathf.Max(minCandidateValueEver, trashThreshold);
            float totalMinValueSoFar = 0f;
            float totalMaxValueSoFar = 0f;
            float minMassSoFar       = 0f;
            int   num = 0;

            do
            {
                num++;
                if (num > 10000)
                {
                    Log.Error("Too many iterations.");
                    break;
                }
                IEnumerable <ThingStuffPairWithQuality> enumerable = allowedThingStuffPairs.Where(delegate(ThingStuffPairWithQuality x)
                {
                    if (!allowNonStackableDuplicates && x.thing.stackLimit == 1 && chosen.Any((ThingStuffPairWithQuality c) => c.thing == x.thing))
                    {
                        return(false);
                    }
                    if (maxMass != float.MaxValue && x.thing.category != ThingCategory.Pawn)
                    {
                        float nonTrashMass = GetNonTrashMass(x, trashThreshold, getMinValue);
                        if (minMassSoFar + nonTrashMass > maxMass)
                        {
                            return(false);
                        }
                        if (chosen.Count < countRange.min && minMassSoFar + minMassEver * (float)(countRange.min - chosen.Count - 1) + nonTrashMass > maxMass)
                        {
                            return(false);
                        }
                    }
                    if (totalMinValueSoFar + Mathf.Max(getMinValue(x), trashThreshold) > totalValue)
                    {
                        return(false);
                    }
                    return((chosen.Count >= countRange.min || !(totalMinValueSoFar + minCandidateValueEver * (float)(countRange.min - chosen.Count - 1) + Mathf.Max(getMinValue(x), trashThreshold) > totalValue)) ? true : false);
                });
                if (countRange.max != int.MaxValue && totalMaxValueSoFar < totalValue * 0.5f)
                {
                    IEnumerable <ThingStuffPairWithQuality> enumerable2 = enumerable;
                    enumerable = enumerable.Where((ThingStuffPairWithQuality x) => totalMaxValueSoFar + maxCandidateValueEver * (float)(countRange.max - chosen.Count - 1) + getMaxValue(x) >= totalValue * 0.5f);
                    if (!enumerable.Any())
                    {
                        enumerable = enumerable2;
                    }
                }
                float maxCandidateMinValue = float.MinValue;
                foreach (ThingStuffPairWithQuality item in enumerable)
                {
                    maxCandidateMinValue = Mathf.Max(maxCandidateMinValue, Mathf.Max(getMinValue(item), trashThreshold));
                }
                if (!enumerable.TryRandomElementByWeight(delegate(ThingStuffPairWithQuality x)
                {
                    float a = 1f;
                    if (countRange.max != int.MaxValue && chosen.Count < countRange.max && totalValue >= totalMaxValueSoFar)
                    {
                        int num2 = countRange.max - chosen.Count;
                        float b = (totalValue - totalMaxValueSoFar) / (float)num2;
                        a = Mathf.InverseLerp(0f, b, getMaxValue(x));
                    }
                    float b2 = 1f;
                    if (chosen.Count < countRange.min && totalValue >= totalMinValueSoFar)
                    {
                        int num3 = countRange.min - chosen.Count;
                        float num4 = (totalValue - totalMinValueSoFar) / (float)num3;
                        float num5 = Mathf.Max(getMinValue(x), trashThreshold);
                        if (num5 > num4)
                        {
                            b2 = num4 / num5;
                        }
                    }
                    float num6 = Mathf.Max(Mathf.Min(a, b2), 1E-05f);
                    if (weightSelector != null)
                    {
                        num6 *= weightSelector(x.thing);
                    }
                    if (totalValue > totalMaxValueSoFar)
                    {
                        int num7 = Mathf.Max(countRange.min - chosen.Count, 1);
                        float num8 = Mathf.InverseLerp(0f, maxCandidateMinValue * 0.85f, GetMaxValueWithMaxMass(x, minMassSoFar, maxMass, getMinValue, getMaxValue) * (float)num7);
                        num6 *= num8 * num8;
                    }
                    if (PawnWeaponGenerator.IsDerpWeapon(x.thing, x.stuff))
                    {
                        num6 *= 0.1f;
                    }
                    if (techLevel != 0)
                    {
                        TechLevel techLevel2 = x.thing.techLevel;
                        if ((int)techLevel2 < (int)techLevel && (int)techLevel2 <= 2 && (x.thing.IsApparel || x.thing.IsWeapon))
                        {
                            num6 *= 0.1f;
                        }
                    }
                    return(num6);
                }, out ThingStuffPairWithQuality result))
                {
                    break;
                }
                chosen.Add(result);
                totalMinValueSoFar += Mathf.Max(getMinValue(result), trashThreshold);
                totalMaxValueSoFar += getMaxValue(result);
                if (result.thing.category != ThingCategory.Pawn)
                {
                    minMassSoFar += GetNonTrashMass(result, trashThreshold, getMinValue);
                }
            }while (chosen.Count < countRange.max && (chosen.Count < countRange.min || !(totalMaxValueSoFar >= totalValue * 0.9f)));
            return(chosen);
        }
Exemplo n.º 8
0
        public static List <ThingStuffPairWithQuality> GenerateDefsWithPossibleTotalValue_NewTmp3(IntRange countRange, float totalValue, IEnumerable <ThingDef> allowed, TechLevel techLevel, QualityGenerator qualityGenerator, Func <ThingStuffPairWithQuality, float> getMinValue, Func <ThingStuffPairWithQuality, float> getMaxValue, Func <ThingStuffPairWithQuality, float> getSingleThingValue, Func <ThingDef, float> weightSelector = null, int tries = 100, float maxMass = float.MaxValue, bool allowNonStackableDuplicates = true, float minSingleItemValue = 0f)
        {
            minValuesTmp.Clear();
            maxValuesTmp.Clear();
            List <ThingStuffPairWithQuality> chosen = new List <ThingStuffPairWithQuality>();

            if (countRange.max <= 0)
            {
                return(chosen);
            }
            if (countRange.min < 1)
            {
                countRange.min = 1;
            }
            CalculateAllowedThingStuffPairs(allowed, techLevel, qualityGenerator);
            float trashThreshold = Mathf.Max(GetTrashThreshold(countRange, totalValue, MaxValue), minSingleItemValue);

            allowedThingStuffPairs.RemoveAll((ThingStuffPairWithQuality x) => MaxValue(x) < trashThreshold);
            if (!allowedThingStuffPairs.Any())
            {
                return(chosen);
            }
            float a    = float.MaxValue;
            float num  = float.MinValue;
            float num2 = float.MaxValue;

            foreach (ThingStuffPairWithQuality allowedThingStuffPair in allowedThingStuffPairs)
            {
                a   = Mathf.Min(a, MinValue(allowedThingStuffPair));
                num = Mathf.Max(num, MaxValue(allowedThingStuffPair));
                if (allowedThingStuffPair.thing.category != ThingCategory.Pawn)
                {
                    num2 = Mathf.Min(num2, GetNonTrashMass(allowedThingStuffPair, trashThreshold, MinValue));
                }
            }
            a = Mathf.Max(a, trashThreshold);
            float totalMinValueSoFar = 0f;
            float totalMaxValueSoFar = 0f;
            float minMassSoFar       = 0f;
            int   num3 = 0;

            do
            {
                num3++;
                if (num3 > 10000)
                {
                    Log.Error("Too many iterations.");
                    break;
                }
                candidatesTmp.Clear();
                for (int i = 0; i < allowedThingStuffPairs.Count; i++)
                {
                    ThingStuffPairWithQuality candidate = allowedThingStuffPairs[i];
                    if (!allowNonStackableDuplicates && candidate.thing.stackLimit == 1 && chosen.Any((ThingStuffPairWithQuality c) => c.thing == candidate.thing))
                    {
                        continue;
                    }
                    if (maxMass != float.MaxValue && candidate.thing.category != ThingCategory.Pawn)
                    {
                        float nonTrashMass = GetNonTrashMass(candidate, trashThreshold, MinValue);
                        if (minMassSoFar + nonTrashMass > maxMass || (chosen.Count < countRange.min && minMassSoFar + num2 * (float)(countRange.min - chosen.Count - 1) + nonTrashMass > maxMass))
                        {
                            continue;
                        }
                    }
                    if (!(totalMinValueSoFar + Mathf.Max(MinValue(candidate), trashThreshold) > totalValue) && (chosen.Count >= countRange.min || !(totalMinValueSoFar + a * (float)(countRange.min - chosen.Count - 1) + Mathf.Max(MinValue(candidate), trashThreshold) > totalValue)))
                    {
                        candidatesTmp.Add(candidate);
                    }
                }
                if (countRange.max != int.MaxValue && totalMaxValueSoFar < totalValue * 0.5f)
                {
                    candidatesTmpNew.Clear();
                    for (int j = 0; j < candidatesTmp.Count; j++)
                    {
                        ThingStuffPairWithQuality thingStuffPairWithQuality = candidatesTmp[j];
                        if (totalMaxValueSoFar + num * (float)(countRange.max - chosen.Count - 1) + MaxValue(thingStuffPairWithQuality) >= totalValue * 0.5f)
                        {
                            candidatesTmpNew.Add(thingStuffPairWithQuality);
                        }
                    }
                    if (candidatesTmpNew.Any())
                    {
                        candidatesTmp.Clear();
                        candidatesTmp.AddRange(candidatesTmpNew);
                    }
                }
                float maxCandidateMinValue = float.MinValue;
                for (int k = 0; k < candidatesTmp.Count; k++)
                {
                    ThingStuffPairWithQuality t2 = candidatesTmp[k];
                    maxCandidateMinValue = Mathf.Max(maxCandidateMinValue, Mathf.Max(MinValue(t2), trashThreshold));
                }
                if (!candidatesTmp.TryRandomElementByWeight(delegate(ThingStuffPairWithQuality x)
                {
                    float a2 = 1f;
                    if (countRange.max != int.MaxValue && chosen.Count < countRange.max && totalValue >= totalMaxValueSoFar)
                    {
                        int num4 = countRange.max - chosen.Count;
                        float b = (totalValue - totalMaxValueSoFar) / (float)num4;
                        a2 = Mathf.InverseLerp(0f, b, MaxValue(x));
                    }
                    float b2 = 1f;
                    if (chosen.Count < countRange.min && totalValue >= totalMinValueSoFar)
                    {
                        int num5 = countRange.min - chosen.Count;
                        float num6 = (totalValue - totalMinValueSoFar) / (float)num5;
                        float num7 = Mathf.Max(MinValue(x), trashThreshold);
                        if (num7 > num6)
                        {
                            b2 = num6 / num7;
                        }
                    }
                    float num8 = Mathf.Max(Mathf.Min(a2, b2), 1E-05f);
                    if (weightSelector != null)
                    {
                        num8 *= weightSelector(x.thing);
                    }
                    if (totalValue > totalMaxValueSoFar)
                    {
                        int num9 = Mathf.Max(countRange.min - chosen.Count, 1);
                        float num10 = Mathf.InverseLerp(0f, maxCandidateMinValue * 0.85f, GetMaxValueWithMaxMass(x, minMassSoFar, maxMass, MinValue, MaxValue) * (float)num9);
                        num8 *= num10 * num10;
                    }
                    if (PawnWeaponGenerator.IsDerpWeapon(x.thing, x.stuff))
                    {
                        num8 *= 0.1f;
                    }
                    if (techLevel != 0)
                    {
                        TechLevel techLevel2 = x.thing.techLevel;
                        if ((int)techLevel2 < (int)techLevel && (int)techLevel2 <= 2 && (x.thing.IsApparel || x.thing.IsWeapon))
                        {
                            num8 *= 0.1f;
                        }
                    }
                    return(num8);
                }, out var result))
                {
                    break;
                }
                chosen.Add(result);
                totalMinValueSoFar += Mathf.Max(MinValue(result), trashThreshold);
                totalMaxValueSoFar += MaxValue(result);
                if (result.thing.category != ThingCategory.Pawn)
                {
                    minMassSoFar += GetNonTrashMass(result, trashThreshold, MinValue);
                }
            }while (chosen.Count < countRange.max && (chosen.Count < countRange.min || !(totalMaxValueSoFar >= totalValue * 0.9f)));
            return(chosen);

            float MaxValue(ThingStuffPairWithQuality t)
            {
                if (!maxValuesTmp.TryGetValue(t, out var value2))
                {
                    value2          = getMaxValue(t);
                    maxValuesTmp[t] = value2;
                }
                return(value2);
            }

            float MinValue(ThingStuffPairWithQuality t)
            {
                if (!minValuesTmp.TryGetValue(t, out var value))
                {
                    value           = getMinValue(t);
                    minValuesTmp[t] = value;
                }
                return(value);
            }
        }
Exemplo n.º 9
0
        internal static void MakeTableWeaponPairs()
        {
            IEnumerable <ThingStuffPair> arg_153_0 = from p in PawnWeaponGenerator.allWeaponPairs
                                                     orderby p.thing.defName descending
                                                     select p;

            TableDataGetter <ThingStuffPair>[] expr_2D = new TableDataGetter <ThingStuffPair> [7];
            expr_2D[0] = new TableDataGetter <ThingStuffPair>("thing", (ThingStuffPair p) => p.thing.defName);
            expr_2D[1] = new TableDataGetter <ThingStuffPair>("stuff", (ThingStuffPair p) => (p.stuff == null) ? string.Empty : p.stuff.defName);
            expr_2D[2] = new TableDataGetter <ThingStuffPair>("price", (ThingStuffPair p) => p.Price.ToString());
            expr_2D[3] = new TableDataGetter <ThingStuffPair>("commonality", (ThingStuffPair p) => p.Commonality.ToString("F5"));
            expr_2D[4] = new TableDataGetter <ThingStuffPair>("commMult", (ThingStuffPair p) => p.commonalityMultiplier.ToString("F5"));
            expr_2D[5] = new TableDataGetter <ThingStuffPair>("def-commonality", (ThingStuffPair p) => p.thing.generateCommonality.ToString("F2"));
            expr_2D[6] = new TableDataGetter <ThingStuffPair>("derp", (ThingStuffPair p) => (!PawnWeaponGenerator.IsDerpWeapon(p.thing, p.stuff)) ? string.Empty : "D");
            DebugTables.MakeTablesDialog <ThingStuffPair>(arg_153_0, expr_2D);
        }
 private static string <WeaponPairs> m__A(ThingStuffPair p)
 {
     return((!PawnWeaponGenerator.IsDerpWeapon(p.thing, p.stuff)) ? string.Empty : "D");
 }
        private static void WeaponPairs()
        {
            IEnumerable <ThingStuffPair> dataSources = from p in PawnWeaponGenerator.allWeaponPairs
                                                       orderby p.thing.defName descending
                                                       select p;

            TableDataGetter <ThingStuffPair>[] array = new TableDataGetter <ThingStuffPair> [7];
            array[0] = new TableDataGetter <ThingStuffPair>("thing", (ThingStuffPair p) => p.thing.defName);
            array[1] = new TableDataGetter <ThingStuffPair>("stuff", (ThingStuffPair p) => (p.stuff == null) ? string.Empty : p.stuff.defName);
            array[2] = new TableDataGetter <ThingStuffPair>("price", (ThingStuffPair p) => p.Price.ToString());
            array[3] = new TableDataGetter <ThingStuffPair>("commonality", (ThingStuffPair p) => p.Commonality.ToString("F5"));
            array[4] = new TableDataGetter <ThingStuffPair>("commMult", (ThingStuffPair p) => p.commonalityMultiplier.ToString("F5"));
            array[5] = new TableDataGetter <ThingStuffPair>("generateCommonality", (ThingStuffPair p) => p.thing.generateCommonality.ToString("F2"));
            array[6] = new TableDataGetter <ThingStuffPair>("derp", (ThingStuffPair p) => (!PawnWeaponGenerator.IsDerpWeapon(p.thing, p.stuff)) ? string.Empty : "D");
            DebugTables.MakeTablesDialog <ThingStuffPair>(dataSources, array);
        }