Пример #1
0
        public static TaleData_Thing GenerateRandom()
        {
            ThingDef thingDef = DefDatabase <ThingDef> .AllDefs.Where(delegate(ThingDef d)
            {
                bool arg_36_0;
                if (d.comps != null)
                {
                    arg_36_0 = d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt));
                }
                else
                {
                    arg_36_0 = false;
                }
                return(arg_36_0);
            }).RandomElement <ThingDef>();

            ThingDef             thingDef2   = GenStuff.RandomStuffFor(thingDef);
            Thing                thing       = ThingMaker.MakeThing(thingDef, thingDef2);
            ArtGenerationContext source      = (Rand.Value >= 0.5f) ? ArtGenerationContext.Outsider : ArtGenerationContext.Colony;
            CompQuality          compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality != null && compQuality.Quality < thing.TryGetComp <CompArt>().Props.minQualityForArtistic)
            {
                compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source);
            }
            thing.TryGetComp <CompArt>().InitializeArt(source);
            return(TaleData_Thing.GenerateFrom(thing));
        }
Пример #2
0
        public static ThingDef RandomStuffInexpensiveFor(ThingDef thingDef, TechLevel maxTechLevel)
        {
            ThingDef result;

            if (!thingDef.MadeFromStuff)
            {
                result = null;
            }
            else
            {
                IEnumerable <ThingDef> enumerable = GenStuff.AllowedStuffsFor(thingDef, maxTechLevel);
                float cheapestPrice = -1f;
                foreach (ThingDef thingDef2 in enumerable)
                {
                    float num = thingDef2.BaseMarketValue / thingDef2.VolumePerUnit;
                    if (cheapestPrice == -1f || num < cheapestPrice)
                    {
                        cheapestPrice = num;
                    }
                }
                enumerable = from x in enumerable
                             where x.BaseMarketValue / x.VolumePerUnit <= cheapestPrice * 4f
                             select x;
                ThingDef thingDef3;
                if (enumerable.TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out thingDef3))
                {
                    result = thingDef3;
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
Пример #3
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 TryGetRandomThingWhichCanWeighNoMoreThan(IEnumerable <ThingDef> candidates, TechLevel stuffTechLevel, float maxMass, QualityGenerator?qualityGenerator, out ThingStuffPair thingStuffPair)
        {
            if (!candidates.Where((ThingDef x) => PossibleToWeighNoMoreThan(x, maxMass, GenStuff.AllowedStuffsFor(x, stuffTechLevel))).TryRandomElement(out var thingDef))
            {
                thingStuffPair = default(ThingStuffPair);
                return(false);
            }
            ThingDef result;

            if (thingDef.MadeFromStuff)
            {
                if (!(from x in GenStuff.AllowedStuffsFor(thingDef, stuffTechLevel)
                      where thingDef.GetStatValueAbstract(StatDefOf.Mass, x) <= maxMass && !IsDerpAndDisallowed(thingDef, x, qualityGenerator)
                      select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out result))
                {
                    thingStuffPair = default(ThingStuffPair);
                    return(false);
                }
            }
            else
            {
                result = null;
            }
            thingStuffPair = new ThingStuffPair(thingDef, result);
            return(true);
        }
Пример #5
0
        public static ThingDef DefaultStuffFor(ThingDef td)
        {
            if (!td.MadeFromStuff)
            {
                return(null);
            }
            if (ThingDefOf.WoodLog.stuffProps.CanMake(td))
            {
                return(ThingDefOf.WoodLog);
            }
            if (ThingDefOf.Steel.stuffProps.CanMake(td))
            {
                return(ThingDefOf.Steel);
            }
            if (ThingDefOf.Cloth.stuffProps.CanMake(td))
            {
                return(ThingDefOf.Cloth);
            }
            ThingDef leatherDef = ThingDefOf.Cow.race.leatherDef;

            if (leatherDef.stuffProps.CanMake(td))
            {
                return(leatherDef);
            }
            if (ThingDefOf.BlocksGranite.stuffProps.CanMake(td))
            {
                return(ThingDefOf.BlocksGranite);
            }
            if (ThingDefOf.Plasteel.stuffProps.CanMake(td))
            {
                return(ThingDefOf.Plasteel);
            }
            return(GenStuff.RandomStuffFor(td));
        }
Пример #6
0
 public static ThingDef RandomStuffFor(ThingDef td)
 {
     if (!td.MadeFromStuff)
     {
         return(null);
     }
     return(GenStuff.AllowedStuffsFor(td).RandomElement());
 }
Пример #7
0
 public static ThingDef RandomStuffFor(ThingDef td)
 {
     if (!td.MadeFromStuff)
     {
         return(null);
     }
     return(GenStuff.AllowedStuffsFor(td, TechLevel.Undefined).RandomElement <ThingDef>());
 }
Пример #8
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 List <ThingDefCountClass> value))
            {
                value = new List <ThingDefCountClass>();
                int num = 0;
                if (entDef.MadeFromStuff)
                {
                    if (errorOnNullStuff && stuff == null)
                    {
                        Log.Error("Cannot get AdjustedCostList for " + entDef + " with null Stuff.");
                        ThingDef thingDef = GenStuff.DefaultStuffFor(entDef);
                        return((thingDef == null) ? null : 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("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);
        }
Пример #9
0
        public void ResetStuffToDefault()
        {
            ThingDef thingDef = this.entDef as ThingDef;

            if (thingDef != null && thingDef.MadeFromStuff)
            {
                this.stuffDef = GenStuff.DefaultStuffFor(thingDef);
            }
        }
Пример #10
0
        public static bool TryRandomStuffByCommonalityFor(ThingDef td, out ThingDef stuff, TechLevel maxTechLevel = TechLevel.Undefined)
        {
            if (!td.MadeFromStuff)
            {
                stuff = null;
                return(true);
            }
            IEnumerable <ThingDef> source = GenStuff.AllowedStuffsFor(td, maxTechLevel);

            return(source.TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff));
        }
Пример #11
0
        public static bool TryRandomStuffFor(ThingDef td, out ThingDef stuff, TechLevel maxTechLevel = TechLevel.Undefined)
        {
            if (!td.MadeFromStuff)
            {
                stuff = null;
                return(true);
            }
            IEnumerable <ThingDef> source = GenStuff.AllowedStuffsFor(td, maxTechLevel);

            return(source.TryRandomElement(out stuff));
        }
Пример #12
0
        private static void AddBuildingsToSketch(Sketch sketch, IntVec2 size, List <ThingDef> buildings)
        {
            List <CellRect> edgeWallRects = new List <CellRect>
            {
                new CellRect(0, 0, size.x, 1),
                new CellRect(0, 0, 1, size.z),
                new CellRect(size.x - 1, 0, 1, size.z),
                new CellRect(0, size.z - 1, size.x, 1)
            };

            foreach (ThingDef item in buildings.OrderBy((ThingDef x) => x.building.IsTurret && !x.building.IsMortar))
            {
                bool flag = item.building.IsTurret && !item.building.IsMortar;
                if (!TryFindRandomPlaceFor(item, sketch, size, out var pos, lowerLeftQuarterOnly: false, flag, flag, !flag, edgeWallRects) && !TryFindRandomPlaceFor(item, sketch, size + new IntVec2(6, 6), out pos, lowerLeftQuarterOnly: false, flag, flag, !flag, edgeWallRects))
                {
                    continue;
                }
                sketch.AddThing(item, pos, Rot4.North, GenStuff.RandomStuffByCommonalityFor(item));
                if (item != ThingDefOf.Turret_AutoMiniTurret)
                {
                    continue;
                }
                if (pos.x < size.x / 2)
                {
                    if (pos.z < size.z / 2)
                    {
                        sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x - 1, 0, pos.z), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                        sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x - 1, 0, pos.z - 1), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                        sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x, 0, pos.z - 1), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                    }
                    else
                    {
                        sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x - 1, 0, pos.z), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                        sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x - 1, 0, pos.z + 1), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                        sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x, 0, pos.z + 1), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                    }
                }
                else if (pos.z < size.z / 2)
                {
                    sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x + 1, 0, pos.z), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                    sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x + 1, 0, pos.z - 1), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                    sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x, 0, pos.z - 1), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                }
                else
                {
                    sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x + 1, 0, pos.z), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                    sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x + 1, 0, pos.z + 1), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                    sketch.AddThing(ThingDefOf.Barricade, new IntVec3(pos.x, 0, pos.z + 1), Rot4.North, ThingDefOf.Steel, 1, null, null, wipeIfCollides: false);
                }
            }
        }
Пример #13
0
        public static ThingDef RandomStuffFor(ThingDef td)
        {
            ThingDef result;

            if (!td.MadeFromStuff)
            {
                result = null;
            }
            else
            {
                result = GenStuff.AllowedStuffsFor(td, TechLevel.Undefined).RandomElement <ThingDef>();
            }
            return(result);
        }
Пример #14
0
        public static ThingDef RandomStuffByCommonalityFor(ThingDef td, TechLevel maxTechLevel = TechLevel.Undefined)
        {
            if (!td.MadeFromStuff)
            {
                return(null);
            }
            ThingDef result;

            if (!GenStuff.TryRandomStuffByCommonalityFor(td, out result, maxTechLevel))
            {
                result = GenStuff.DefaultStuffFor(td);
            }
            return(result);
        }
 private static void CalculateAllowedThingStuffPairs(IEnumerable <ThingDef> allowed, TechLevel techLevel, QualityGenerator qualityGenerator)
 {
     allowedThingStuffPairs.Clear();
     foreach (ThingDef td in allowed)
     {
         for (int i = 0; i < 5; i++)
         {
             if (GenStuff.TryRandomStuffFor(td, out ThingDef stuff, techLevel, (ThingDef x) => !ThingSetMakerUtility.IsDerpAndDisallowed(td, x, qualityGenerator)))
             {
                 QualityCategory quality = td.HasComp(typeof(CompQuality)) ? QualityUtility.GenerateQuality(qualityGenerator) : QualityCategory.Normal;
                 allowedThingStuffPairs.Add(new ThingStuffPairWithQuality(td, stuff, quality));
             }
         }
     }
 }
 private static void CalculateAllowedThingStuffPairs(IEnumerable <ThingDef> allowed, TechLevel techLevel, QualityGenerator qualityGenerator)
 {
     allowedThingStuffPairs.Clear();
     foreach (ThingDef item in allowed)
     {
         for (int i = 0; i < 5; i++)
         {
             if (GenStuff.TryRandomStuffFor(item, out ThingDef stuff, techLevel))
             {
                 QualityCategory quality = (!item.HasComp(typeof(CompQuality))) ? QualityCategory.Normal : QualityUtility.GenerateQuality(qualityGenerator);
                 allowedThingStuffPairs.Add(new ThingStuffPairWithQuality(item, stuff, quality));
             }
         }
     }
 }
Пример #17
0
        public Thing Instantiate()
        {
            Thing thing = ThingMaker.MakeThing(def, stuff ?? GenStuff.DefaultStuffFor(def));

            thing.stackCount = stackCount;
            if (quality.HasValue)
            {
                thing.TryGetComp <CompQuality>()?.SetQuality(quality.Value, ArtGenerationContext.Outsider);
            }
            if (hitPoints.HasValue)
            {
                thing.HitPoints = hitPoints.Value;
            }
            return(thing);
        }
Пример #18
0
 public override void Randomize()
 {
     this.thingDef = this.PossibleThingDefs().RandomElement <ThingDef>();
     this.stuff    = GenStuff.RandomStuffFor(this.thingDef);
     if (this.thingDef.statBases.StatListContains(StatDefOf.MarketValue))
     {
         float num = (float)Rand.Range(200, 2000);
         float statValueAbstract = this.thingDef.GetStatValueAbstract(StatDefOf.MarketValue, this.stuff);
         this.count = Mathf.CeilToInt(num / statValueAbstract);
     }
     else
     {
         this.count = Rand.RangeInclusive(1, 100);
     }
 }
Пример #19
0
 private static void CalculateAllowedThingStuffPairs(IEnumerable <ThingDef> allowed, TechLevel techLevel, QualityGenerator qualityGenerator)
 {
     ThingSetMakerByTotalStatUtility.allowedThingStuffPairs.Clear();
     foreach (ThingDef thingDef in allowed)
     {
         for (int i = 0; i < 5; i++)
         {
             ThingDef stuff;
             if (GenStuff.TryRandomStuffFor(thingDef, out stuff, techLevel))
             {
                 QualityCategory quality = (!thingDef.HasComp(typeof(CompQuality))) ? QualityCategory.Normal : QualityUtility.GenerateQuality(qualityGenerator);
                 ThingSetMakerByTotalStatUtility.allowedThingStuffPairs.Add(new ThingStuffPairWithQuality(thingDef, stuff, quality));
             }
         }
     }
 }
Пример #20
0
        public static TaleData_Thing GenerateRandom()
        {
            ThingDef obj = DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.comps != null && d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt))).RandomElement();

            ThingDef             thingDef    = GenStuff.RandomStuffFor(obj);
            Thing                thing       = ThingMaker.MakeThing(obj, thingDef);
            ArtGenerationContext source      = (Rand.Value < 0.5f) ? ArtGenerationContext.Colony : ArtGenerationContext.Outsider;
            CompQuality          compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality != null && (int)compQuality.Quality < (int)thing.TryGetComp <CompArt>().Props.minQualityForArtistic)
            {
                compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source);
            }
            thing.TryGetComp <CompArt>().InitializeArt(source);
            return(GenerateFrom(thing));
        }
Пример #21
0
        public static bool TryRandomStuffFor(ThingDef td, out ThingDef stuff, TechLevel maxTechLevel = TechLevel.Undefined)
        {
            bool result;

            if (!td.MadeFromStuff)
            {
                stuff  = null;
                result = true;
            }
            else
            {
                IEnumerable <ThingDef> source = GenStuff.AllowedStuffsFor(td, maxTechLevel);
                result = source.TryRandomElement(out stuff);
            }
            return(result);
        }
        public static TaleData_Thing GenerateRandom()
        {
            ThingDef thingDef = (from d in DefDatabase <ThingDef> .AllDefs
                                 where d.comps != null && d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt))
                                 select d).RandomElement();
            ThingDef             thingDef2   = GenStuff.RandomStuffFor(thingDef);
            Thing                thing       = ThingMaker.MakeThing(thingDef, thingDef2);
            ArtGenerationContext source      = (ArtGenerationContext)((Rand.Value < 0.5) ? 1 : 0);
            CompQuality          compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality != null && (int)compQuality.Quality < (int)thing.TryGetComp <CompArt>().Props.minQualityForArtistic)
            {
                compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source);
            }
            thing.TryGetComp <CompArt>().InitializeArt(source);
            return(TaleData_Thing.GenerateFrom(thing));
        }
Пример #23
0
        public static bool TryRandomStuffByCommonalityFor(ThingDef td, out ThingDef stuff, TechLevel maxTechLevel = TechLevel.Undefined)
        {
            if (!td.MadeFromStuff)
            {
                stuff = null;
                return(true);
            }
            IEnumerable <ThingDef> source = GenStuff.AllowedStuffsFor(td);

            if (maxTechLevel != 0)
            {
                source = from x in source
                         where (int)x.techLevel <= (int)maxTechLevel
                         select x;
            }
            return(source.TryRandomElementByWeight <ThingDef>((Func <ThingDef, float>)((ThingDef x) => x.stuffProps.commonality), out stuff));
        }
        public static float GetMinMarketValue(ThingDef thingDef, TechLevel stuffTechLevel)
        {
            float num = float.MaxValue;

            if (thingDef.MadeFromStuff)
            {
                foreach (ThingDef item in GenStuff.AllowedStuffsFor(thingDef, stuffTechLevel))
                {
                    if (item.stuffProps.commonality > 0f)
                    {
                        num = Mathf.Min(num, StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(thingDef, item, QualityCategory.Awful)));
                    }
                }
                return(num);
            }
            return(Mathf.Min(num, StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(thingDef, null, QualityCategory.Awful))));
        }
        public static float GetMinMass(ThingDef thingDef, TechLevel stuffTechLevel)
        {
            float num = float.MaxValue;

            if (thingDef.MadeFromStuff)
            {
                foreach (ThingDef item in GenStuff.AllowedStuffsFor(thingDef, stuffTechLevel))
                {
                    if (item.stuffProps.commonality > 0f)
                    {
                        num = Mathf.Min(num, thingDef.GetStatValueAbstract(StatDefOf.Mass, item));
                    }
                }
                return(num);
            }
            return(Mathf.Min(num, thingDef.GetStatValueAbstract(StatDefOf.Mass)));
        }
Пример #26
0
        public override void DoEditInterface(Listing_ScenEdit listing)
        {
            Rect scenPartRect = listing.GetScenPartRect(this, ScenPart.RowHeight * 3f);
            Rect rect         = new Rect(scenPartRect.x, scenPartRect.y, scenPartRect.width, scenPartRect.height / 3f);
            Rect rect2        = new Rect(scenPartRect.x, scenPartRect.y + scenPartRect.height / 3f, scenPartRect.width, scenPartRect.height / 3f);
            Rect rect3        = new Rect(scenPartRect.x, scenPartRect.y + scenPartRect.height * 2f / 3f, scenPartRect.width, scenPartRect.height / 3f);

            if (Widgets.ButtonText(rect, this.thingDef.LabelCap, true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (ThingDef localTd2 in from t in this.PossibleThingDefs()
                         orderby t.label
                         select t)
                {
                    ThingDef localTd = localTd2;
                    list.Add(new FloatMenuOption(localTd.LabelCap, delegate()
                    {
                        this.thingDef = localTd;
                        this.stuff    = GenStuff.DefaultStuffFor(localTd);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list));
            }
            if (this.thingDef.MadeFromStuff)
            {
                if (Widgets.ButtonText(rect2, this.stuff.LabelCap, true, false, true))
                {
                    List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                    foreach (ThingDef localSd2 in from t in GenStuff.AllowedStuffsFor(this.thingDef, TechLevel.Undefined)
                             orderby t.label
                             select t)
                    {
                        ThingDef localSd = localSd2;
                        list2.Add(new FloatMenuOption(localSd.LabelCap, delegate()
                        {
                            this.stuff = localSd;
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    Find.WindowStack.Add(new FloatMenu(list2));
                }
            }
            Widgets.TextFieldNumeric <int>(rect3, ref this.count, ref this.countBuf, 1f, 1E+09f);
        }
Пример #27
0
        public static ThingDef RandomStuffByCommonalityFor(ThingDef td, TechLevel maxTechLevel = TechLevel.Undefined)
        {
            ThingDef result;

            if (!td.MadeFromStuff)
            {
                result = null;
            }
            else
            {
                ThingDef thingDef;
                if (!GenStuff.TryRandomStuffByCommonalityFor(td, out thingDef, maxTechLevel))
                {
                    thingDef = GenStuff.DefaultStuffFor(td);
                }
                result = thingDef;
            }
            return(result);
        }
Пример #28
0
        public IEnumerable <ThingDef> AllowedStuffs()
        {
            tmpStuffCategories.Clear();
            bool flag = true;
            List <SketchThing> things = sketch.Things;

            for (int i = 0; i < things.Count; i++)
            {
                if (!things[i].def.MadeFromStuff || things[i].stuff != null)
                {
                    continue;
                }
                if (flag)
                {
                    flag = false;
                    tmpStuffCategories.AddRange(things[i].def.stuffCategories);
                    continue;
                }
                bool flag2 = false;
                for (int j = 0; j < things[i].def.stuffCategories.Count; j++)
                {
                    if (tmpStuffCategories.Contains(things[i].def.stuffCategories[j]))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    continue;
                }
                for (int num = tmpStuffCategories.Count - 1; num >= 0; num--)
                {
                    if (!things[i].def.stuffCategories.Contains(tmpStuffCategories[num]))
                    {
                        tmpStuffCategories.RemoveAt(num);
                    }
                }
            }
            return(GenStuff.AllowedStuffs(tmpStuffCategories));
        }
Пример #29
0
        public override void DoEditInterface(Listing_ScenEdit listing)
        {
            Rect scenPartRect = listing.GetScenPartRect(this, ScenPart.RowHeight * 3f);
            Rect rect         = new Rect(scenPartRect.x, scenPartRect.y, scenPartRect.width, scenPartRect.height / 3f);
            Rect rect2        = new Rect(scenPartRect.x, scenPartRect.y + scenPartRect.height / 3f, scenPartRect.width, scenPartRect.height / 3f);
            Rect rect3        = new Rect(scenPartRect.x, scenPartRect.y + scenPartRect.height * 2f / 3f, scenPartRect.width, scenPartRect.height / 3f);

            if (Widgets.ButtonText(rect, thingDef.LabelCap))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (ThingDef item in from t in PossibleThingDefs()
                         orderby t.label
                         select t)
                {
                    ThingDef localTd = item;
                    list.Add(new FloatMenuOption(localTd.LabelCap, delegate
                    {
                        thingDef = localTd;
                        stuff    = GenStuff.DefaultStuffFor(localTd);
                    }));
                }
                Find.WindowStack.Add(new FloatMenu(list));
            }
            if (thingDef.MadeFromStuff && Widgets.ButtonText(rect2, stuff.LabelCap))
            {
                List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                foreach (ThingDef item2 in from t in GenStuff.AllowedStuffsFor(thingDef)
                         orderby t.label
                         select t)
                {
                    ThingDef localSd = item2;
                    list2.Add(new FloatMenuOption(localSd.LabelCap, delegate
                    {
                        stuff = localSd;
                    }));
                }
                Find.WindowStack.Add(new FloatMenu(list2));
            }
            Widgets.TextFieldNumeric(rect3, ref count, ref countBuf, 1f);
        }
Пример #30
0
        public static Thing TryMakeForStockSingle(ThingDef thingDef, int stackCount)
        {
            if (stackCount <= 0)
            {
                return(null);
            }
            if (thingDef.tradeability != Tradeability.Stockable)
            {
                Log.Error("Tried to make non-Stockable thing for trader stock: " + thingDef);
                return(null);
            }
            ThingDef stuff = null;

            if (thingDef.MadeFromStuff)
            {
                stuff = GenStuff.RandomStuffByCommonalityFor(thingDef, TechLevel.Undefined);
            }
            Thing thing = ThingMaker.MakeThing(thingDef, stuff);

            thing.stackCount = stackCount;
            return(thing);
        }