Example #1
0
        public static List <ThingCountClass> CostListAdjusted(this BuildableDef entDef, ThingDef stuff, bool errorOnNullStuff = true)
        {
            CostListPair           key  = new CostListPair(entDef, stuff);
            List <ThingCountClass> list = default(List <ThingCountClass>);

            if (!CostListCalculator.cachedCosts.TryGetValue(key, out list))
            {
                list = new List <ThingCountClass>();
                int num = 0;
                if (entDef.MadeFromStuff)
                {
                    if (errorOnNullStuff && stuff == null)
                    {
                        Log.Error("Cannot get AdjustedCostList for " + entDef + " with null Stuff.");
                        return(null);
                    }
                    if (stuff != null)
                    {
                        num = Mathf.RoundToInt((float)entDef.costStuffCount / stuff.VolumePerUnit);
                        if (num < 1)
                        {
                            num = 1;
                        }
                    }
                    else
                    {
                        num = entDef.costStuffCount;
                    }
                }
                else if (stuff != null)
                {
                    Log.Error("Got AdjustedCostList for " + entDef + " with stuff " + stuff + " but is not MadeFromStuff.");
                }
                bool flag = false;
                if (entDef.costList != null)
                {
                    for (int i = 0; i < entDef.costList.Count; i++)
                    {
                        ThingCountClass thingCountClass = entDef.costList[i];
                        if (thingCountClass.thingDef == stuff)
                        {
                            list.Add(new ThingCountClass(thingCountClass.thingDef, thingCountClass.count + num));
                            flag = true;
                        }
                        else
                        {
                            list.Add(thingCountClass);
                        }
                    }
                }
                if (!flag && num > 0)
                {
                    list.Add(new ThingCountClass(stuff, num));
                }
                CostListCalculator.cachedCosts.Add(key, list);
            }
            return(list);
        }
Example #2
0
        public static List <ThingDefCountClass> CostListAdjusted(this BuildableDef entDef, ThingDef stuff, bool errorOnNullStuff = true)
        {
            CostListPair key = new CostListPair(entDef, stuff);

            if (!cachedCosts.TryGetValue(key, out var value))
            {
                value = new List <ThingDefCountClass>();
                int num = 0;
                if (entDef.MadeFromStuff)
                {
                    if (errorOnNullStuff && stuff == null)
                    {
                        Log.Error(string.Concat("Cannot get AdjustedCostList for ", entDef, " with null Stuff."));
                        if (GenStuff.DefaultStuffFor(entDef) == null)
                        {
                            return(null);
                        }
                        return(entDef.CostListAdjusted(GenStuff.DefaultStuffFor(entDef)));
                    }
                    if (stuff != null)
                    {
                        num = Mathf.RoundToInt((float)entDef.costStuffCount / stuff.VolumePerUnit);
                        if (num < 1)
                        {
                            num = 1;
                        }
                    }
                    else
                    {
                        num = entDef.costStuffCount;
                    }
                }
                else if (stuff != null)
                {
                    Log.Error(string.Concat("Got AdjustedCostList for ", entDef, " with stuff ", stuff, " but is not MadeFromStuff."));
                }
                bool flag = false;
                if (entDef.costList != null)
                {
                    for (int i = 0; i < entDef.costList.Count; i++)
                    {
                        ThingDefCountClass thingDefCountClass = entDef.costList[i];
                        if (thingDefCountClass.thingDef == stuff)
                        {
                            value.Add(new ThingDefCountClass(thingDefCountClass.thingDef, thingDefCountClass.count + num));
                            flag = true;
                        }
                        else
                        {
                            value.Add(thingDefCountClass);
                        }
                    }
                }
                if (!flag && num > 0)
                {
                    value.Add(new ThingDefCountClass(stuff, num));
                }
                cachedCosts.Add(key, value);
            }
            return(value);
        }