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); }
public void ResetStuffToDefault() { ThingDef thingDef = this.entDef as ThingDef; if (thingDef != null && thingDef.MadeFromStuff) { this.stuffDef = GenStuff.DefaultStuffFor(thingDef); } }
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); }
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); }
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); }
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); }
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); }
public override bool HandlesThingDef(ThingDef td) { if (td == ThingDefOf.Apparel_ShieldBelt) { return(true); } if (td == ThingDefOf.Apparel_SmokepopBelt) { return(true); } ThingDef stuff = GenStuff.DefaultStuffFor(td); if (base.HandlesThingDef(td) && td.IsApparel) { if (!(td.GetStatValueAbstract(StatDefOf.ArmorRating_Blunt, stuff) > 0.15f)) { return(td.GetStatValueAbstract(StatDefOf.ArmorRating_Sharp, stuff) > 0.15f); } return(true); } return(false); }
private static void CacheAccessibleThings(int nearTile) { if (nearTile == cachedAccessibleThingsForTile && RealTime.frameCount == cachedAccessibleThingsForFrame) { return; } cachedAccessibleThings.Clear(); cachedPossiblyAccessibleThings.Clear(); cachedMakeableItemDefs.Clear(); WorldGrid worldGrid = Find.WorldGrid; List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { if (!(worldGrid.ApproxDistanceInTiles(nearTile, maps[i].Tile) > 5f)) { ThingOwnerUtility.GetAllThingsRecursively(maps[i], tmpThings, allowUnreal: false); cachedAccessibleThings.AddRange(tmpThings); } } List <Caravan> caravans = Find.WorldObjects.Caravans; for (int j = 0; j < caravans.Count; j++) { if (caravans[j].IsPlayerControlled && !(worldGrid.ApproxDistanceInTiles(nearTile, caravans[j].Tile) > 5f)) { ThingOwnerUtility.GetAllThingsRecursively(caravans[j], tmpThings, allowUnreal: false); cachedAccessibleThings.AddRange(tmpThings); } } for (int k = 0; k < cachedAccessibleThings.Count; k++) { Thing thing = cachedAccessibleThings[k]; cachedPossiblyAccessibleThings.Add(new ThingDefCount(thing.def, thing.stackCount)); if (GenLeaving.CanBuildingLeaveResources(thing, DestroyMode.Deconstruct)) { List <ThingDefCountClass> list = thing.CostListAdjusted(); for (int l = 0; l < list.Count; l++) { int num = Mathf.RoundToInt((float)list[l].count * thing.def.resourcesFractionWhenDeconstructed); if (num > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(list[l].thingDef, num)); cachedMakeableItemDefs.Add(list[l].thingDef); } } } Plant plant = thing as Plant; if (plant != null && (plant.HarvestableNow || plant.HarvestableSoon)) { int num2 = Mathf.RoundToInt(plant.def.plant.harvestYield * Find.Storyteller.difficultyValues.cropYieldFactor); if (num2 > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(plant.def.plant.harvestedThingDef, num2)); cachedMakeableItemDefs.Add(plant.def.plant.harvestedThingDef); } } if (!thing.def.butcherProducts.NullOrEmpty()) { for (int m = 0; m < thing.def.butcherProducts.Count; m++) { cachedPossiblyAccessibleThings.Add(thing.def.butcherProducts[m]); cachedMakeableItemDefs.Add(thing.def.butcherProducts[m].thingDef); } } Pawn pawn = thing as Pawn; if (pawn != null) { if (pawn.RaceProps.meatDef != null) { int num3 = Mathf.RoundToInt(pawn.GetStatValue(StatDefOf.MeatAmount)); if (num3 > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.meatDef, num3)); cachedMakeableItemDefs.Add(pawn.RaceProps.meatDef); } } if (pawn.RaceProps.leatherDef != null) { int num4 = GenMath.RoundRandom(pawn.GetStatValue(StatDefOf.LeatherAmount)); if (num4 > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.leatherDef, num4)); cachedMakeableItemDefs.Add(pawn.RaceProps.leatherDef); } } if (!pawn.RaceProps.Humanlike) { PawnKindLifeStage curKindLifeStage = pawn.ageTracker.CurKindLifeStage; if (curKindLifeStage.butcherBodyPart != null) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(curKindLifeStage.butcherBodyPart.thing, 1)); cachedMakeableItemDefs.Add(curKindLifeStage.butcherBodyPart.thing); } } } if (thing.def.smeltable) { List <ThingDefCountClass> list2 = thing.CostListAdjusted(); for (int n = 0; n < list2.Count; n++) { if (!list2[n].thingDef.intricate) { int num5 = Mathf.RoundToInt((float)list2[n].count * 0.25f); if (num5 > 0) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(list2[n].thingDef, num5)); cachedMakeableItemDefs.Add(list2[n].thingDef); } } } } if (thing.def.smeltable && !thing.def.smeltProducts.NullOrEmpty()) { for (int num6 = 0; num6 < thing.def.smeltProducts.Count; num6++) { cachedPossiblyAccessibleThings.Add(thing.def.smeltProducts[num6]); cachedMakeableItemDefs.Add(thing.def.smeltProducts[num6].thingDef); } } } int num7 = 0; for (int num8 = 0; num8 < cachedAccessibleThings.Count; num8++) { Pawn pawn2 = cachedAccessibleThings[num8] as Pawn; if (pawn2 != null && pawn2.IsFreeColonist && !pawn2.Dead && !pawn2.Downed && pawn2.workSettings.WorkIsActive(WorkTypeDefOf.Crafting)) { num7++; } } if (num7 > 0) { tmpWorkTables.Clear(); for (int num9 = 0; num9 < cachedAccessibleThings.Count; num9++) { Building_WorkTable building_WorkTable = cachedAccessibleThings[num9] as Building_WorkTable; if (building_WorkTable == null || !building_WorkTable.Spawned || !tmpWorkTables.Add(building_WorkTable.def)) { continue; } List <RecipeDef> allRecipes = building_WorkTable.def.AllRecipes; for (int num10 = 0; num10 < allRecipes.Count; num10++) { if (!allRecipes[num10].AvailableNow || !allRecipes[num10].AvailableOnNow(building_WorkTable) || !allRecipes[num10].products.Any() || allRecipes[num10].PotentiallyMissingIngredients(null, building_WorkTable.Map).Any()) { continue; } ThingDef stuffDef = (allRecipes[num10].products[0].thingDef.MadeFromStuff ? GenStuff.DefaultStuffFor(allRecipes[num10].products[0].thingDef) : null); float num11 = allRecipes[num10].WorkAmountTotal(stuffDef); if (num11 <= 0f) { continue; } int num12 = Mathf.FloorToInt((float)(num7 * 60000 * 5) * 0.09f / num11); if (num12 > 0) { for (int num13 = 0; num13 < allRecipes[num10].products.Count; num13++) { cachedPossiblyAccessibleThings.Add(new ThingDefCount(allRecipes[num10].products[num13].thingDef, allRecipes[num10].products[num13].count * num12)); cachedMakeableItemDefs.Add(allRecipes[num10].products[num13].thingDef); } } } } } cachedAccessibleThingsForTile = nearTile; cachedAccessibleThingsForFrame = RealTime.frameCount; }
public override void DoWindowContents(Rect inRect) { Text.Font = GameFont.Medium; Rect rect = new Rect(0f, 0f, 400f, 50f); Widgets.Label(rect, this.bill.LabelCap); float width = (float)((int)((inRect.width - 34f) / 3f)); Rect rect2 = new Rect(0f, 80f, width, inRect.height - 80f); Rect rect3 = new Rect(rect2.xMax + 17f, 50f, width, inRect.height - 50f - this.CloseButSize.y); Rect rect4 = new Rect(rect3.xMax + 17f, 50f, 0f, inRect.height - 50f - this.CloseButSize.y); rect4.xMax = inRect.xMax; Text.Font = GameFont.Small; Listing_Standard listing_Standard = new Listing_Standard(); listing_Standard.Begin(rect3); Listing_Standard listing_Standard2 = listing_Standard.BeginSection((float)Dialog_BillConfig.RepeatModeSubdialogHeight); if (listing_Standard2.ButtonText(this.bill.repeatMode.LabelCap, null)) { BillRepeatModeUtility.MakeConfigFloatMenu(this.bill); } listing_Standard2.Gap(12f); if (this.bill.repeatMode == BillRepeatModeDefOf.RepeatCount) { listing_Standard2.Label("RepeatCount".Translate(new object[] { this.bill.repeatCount }), -1f, null); listing_Standard2.IntEntry(ref this.bill.repeatCount, ref this.repeatCountEditBuffer, 1); } else if (this.bill.repeatMode == BillRepeatModeDefOf.TargetCount) { string text = "CurrentlyHave".Translate() + ": "; text += this.bill.recipe.WorkerCounter.CountProducts(this.bill); text += " / "; text += ((this.bill.targetCount >= 999999) ? "Infinite".Translate().ToLower() : this.bill.targetCount.ToString()); string text2 = this.bill.recipe.WorkerCounter.ProductsDescription(this.bill); if (!text2.NullOrEmpty()) { string text3 = text; text = string.Concat(new string[] { text3, "\n", "CountingProducts".Translate(), ": ", text2 }); } listing_Standard2.Label(text, -1f, null); int targetCount = this.bill.targetCount; listing_Standard2.IntEntry(ref this.bill.targetCount, ref this.targetCountEditBuffer, this.bill.recipe.targetCountAdjustment); this.bill.unpauseWhenYouHave = Mathf.Max(0, this.bill.unpauseWhenYouHave + (this.bill.targetCount - targetCount)); ThingDef producedThingDef = this.bill.recipe.ProducedThingDef; if (producedThingDef != null) { if (producedThingDef.IsWeapon || producedThingDef.IsApparel) { listing_Standard2.CheckboxLabeled("IncludeEquipped".Translate(), ref this.bill.includeEquipped, null); } if (producedThingDef.IsApparel && producedThingDef.apparel.careIfWornByCorpse) { listing_Standard2.CheckboxLabeled("IncludeTainted".Translate(), ref this.bill.includeTainted, null); } Widgets.Dropdown <Bill_Production, Zone_Stockpile>(listing_Standard2.GetRect(30f), this.bill, (Bill_Production b) => b.includeFromZone, (Bill_Production b) => this.GenerateStockpileInclusion(), (this.bill.includeFromZone != null) ? "IncludeSpecific".Translate(new object[] { this.bill.includeFromZone.label }) : "IncludeFromAll".Translate(), null, null, null, null, false); Widgets.FloatRange(listing_Standard2.GetRect(28f), 10, ref this.bill.hpRange, 0f, 1f, "HitPoints", ToStringStyle.PercentZero); if (producedThingDef.HasComp(typeof(CompQuality))) { Widgets.QualityRange(listing_Standard2.GetRect(28f), 2, ref this.bill.qualityRange); } if (producedThingDef.MadeFromStuff) { listing_Standard2.CheckboxLabeled("LimitToAllowedStuff".Translate(), ref this.bill.limitToAllowedStuff, null); } } } if (this.bill.repeatMode == BillRepeatModeDefOf.TargetCount) { listing_Standard2.Gap(12f); listing_Standard2.Gap(12f); listing_Standard2.CheckboxLabeled("PauseWhenSatisfied".Translate(), ref this.bill.pauseWhenSatisfied, null); if (this.bill.pauseWhenSatisfied) { listing_Standard2.Label("UnpauseWhenYouHave".Translate() + ": " + this.bill.unpauseWhenYouHave.ToString("F0"), -1f, null); listing_Standard2.IntEntry(ref this.bill.unpauseWhenYouHave, ref this.unpauseCountEditBuffer, this.bill.recipe.targetCountAdjustment); if (this.bill.unpauseWhenYouHave >= this.bill.targetCount) { this.bill.unpauseWhenYouHave = this.bill.targetCount - 1; this.unpauseCountEditBuffer = this.bill.unpauseWhenYouHave.ToStringCached(); } } } listing_Standard.EndSection(listing_Standard2); listing_Standard.Gap(12f); Listing_Standard listing_Standard3 = listing_Standard.BeginSection((float)Dialog_BillConfig.StoreModeSubdialogHeight); string text4 = string.Format(this.bill.GetStoreMode().LabelCap, (this.bill.GetStoreZone() == null) ? "" : this.bill.GetStoreZone().SlotYielderLabel()); if (this.bill.GetStoreZone() != null && !this.bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(this.bill, this.bill.GetStoreZone())) { text4 += string.Format(" ({0})", "IncompatibleLower".Translate()); Text.Font = GameFont.Tiny; } if (listing_Standard3.ButtonText(text4, null)) { Text.Font = GameFont.Small; List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (BillStoreModeDef billStoreModeDef in from bsm in DefDatabase <BillStoreModeDef> .AllDefs orderby bsm.listOrder select bsm) { if (billStoreModeDef == BillStoreModeDefOf.SpecificStockpile) { List <SlotGroup> allGroupsListInPriorityOrder = this.bill.billStack.billGiver.Map.haulDestinationManager.AllGroupsListInPriorityOrder; int count = allGroupsListInPriorityOrder.Count; for (int i = 0; i < count; i++) { SlotGroup group = allGroupsListInPriorityOrder[i]; Zone_Stockpile zone_Stockpile = group.parent as Zone_Stockpile; if (zone_Stockpile != null) { if (!this.bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(this.bill, zone_Stockpile)) { list.Add(new FloatMenuOption(string.Format("{0} ({1})", string.Format(billStoreModeDef.LabelCap, group.parent.SlotYielderLabel()), "IncompatibleLower".Translate()), null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { list.Add(new FloatMenuOption(string.Format(billStoreModeDef.LabelCap, group.parent.SlotYielderLabel()), delegate() { this.bill.SetStoreMode(BillStoreModeDefOf.SpecificStockpile, (Zone_Stockpile)group.parent); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } } } } else { BillStoreModeDef smLocal = billStoreModeDef; list.Add(new FloatMenuOption(smLocal.LabelCap, delegate() { this.bill.SetStoreMode(smLocal, null); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } } Find.WindowStack.Add(new FloatMenu(list)); } Text.Font = GameFont.Small; listing_Standard.EndSection(listing_Standard3); listing_Standard.Gap(12f); Listing_Standard listing_Standard4 = listing_Standard.BeginSection((float)Dialog_BillConfig.WorkerSelectionSubdialogHeight); Widgets.Dropdown <Bill_Production, Pawn>(listing_Standard4.GetRect(30f), this.bill, (Bill_Production b) => b.pawnRestriction, (Bill_Production b) => this.GeneratePawnRestrictionOptions(), (this.bill.pawnRestriction != null) ? this.bill.pawnRestriction.LabelShortCap : "AnyWorker".Translate(), null, null, null, null, false); if (this.bill.pawnRestriction == null && this.bill.recipe.workSkill != null) { listing_Standard4.Label("AllowedSkillRange".Translate(new object[] { this.bill.recipe.workSkill.label }), -1f, null); listing_Standard4.IntRange(ref this.bill.allowedSkillRange, 0, 20); } listing_Standard.EndSection(listing_Standard4); listing_Standard.End(); Rect rect5 = rect4; rect5.yMin = rect5.yMax - (float)Dialog_BillConfig.IngredientRadiusSubdialogHeight; rect4.yMax = rect5.yMin - 17f; bool flag = this.bill.GetStoreZone() == null || this.bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(this.bill, this.bill.GetStoreZone()); ThingFilterUI.DoThingFilterConfigWindow(rect4, ref this.thingFilterScrollPosition, this.bill.ingredientFilter, this.bill.recipe.fixedIngredientFilter, 4, null, this.bill.recipe.forceHiddenSpecialFilters, this.bill.recipe.GetPremultipliedSmallIngredients(), this.bill.Map); bool flag2 = this.bill.GetStoreZone() == null || this.bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(this.bill, this.bill.GetStoreZone()); if (flag && !flag2) { Messages.Message("MessageBillValidationStoreZoneInsufficient".Translate(new object[] { this.bill.LabelCap, this.bill.billStack.billGiver.LabelShort.CapitalizeFirst(), this.bill.GetStoreZone().label }), this.bill.billStack.billGiver as Thing, MessageTypeDefOf.RejectInput, false); } Listing_Standard listing_Standard5 = new Listing_Standard(); listing_Standard5.Begin(rect5); listing_Standard5.Label("IngredientSearchRadius".Translate() + ": " + ((this.bill.ingredientSearchRadius != 999f) ? this.bill.ingredientSearchRadius.ToString("F0") : "Unlimited".Translate()), -1f, null); this.bill.ingredientSearchRadius = listing_Standard5.Slider(this.bill.ingredientSearchRadius, 3f, 100f); if (this.bill.ingredientSearchRadius >= 100f) { this.bill.ingredientSearchRadius = 999f; } listing_Standard5.End(); Listing_Standard listing_Standard6 = new Listing_Standard(); listing_Standard6.Begin(rect2); if (this.bill.suspended) { if (listing_Standard6.ButtonText("Suspended".Translate(), null)) { this.bill.suspended = false; SoundDefOf.Click.PlayOneShotOnCamera(null); } } else if (listing_Standard6.ButtonText("NotSuspended".Translate(), null)) { this.bill.suspended = true; SoundDefOf.Click.PlayOneShotOnCamera(null); } StringBuilder stringBuilder = new StringBuilder(); if (this.bill.recipe.description != null) { stringBuilder.AppendLine(this.bill.recipe.description); stringBuilder.AppendLine(); } stringBuilder.AppendLine("WorkAmount".Translate() + ": " + this.bill.recipe.WorkAmountTotal(null).ToStringWorkAmount()); for (int j = 0; j < this.bill.recipe.ingredients.Count; j++) { IngredientCount ingredientCount = this.bill.recipe.ingredients[j]; if (!ingredientCount.filter.Summary.NullOrEmpty()) { stringBuilder.AppendLine(this.bill.recipe.IngredientValueGetter.BillRequirementsDescription(this.bill.recipe, ingredientCount)); } } stringBuilder.AppendLine(); string text5 = this.bill.recipe.IngredientValueGetter.ExtraDescriptionLine(this.bill.recipe); if (text5 != null) { stringBuilder.AppendLine(text5); stringBuilder.AppendLine(); } if (!this.bill.recipe.skillRequirements.NullOrEmpty <SkillRequirement>()) { stringBuilder.AppendLine("MinimumSkills".Translate()); stringBuilder.AppendLine(this.bill.recipe.MinSkillString); } Text.Font = GameFont.Small; string text6 = stringBuilder.ToString(); if (Text.CalcHeight(text6, rect2.width) > rect2.height) { Text.Font = GameFont.Tiny; } listing_Standard6.Label(text6, -1f, null); Text.Font = GameFont.Small; listing_Standard6.End(); if (this.bill.recipe.products.Count == 1) { ThingDef thingDef = this.bill.recipe.products[0].thingDef; Widgets.InfoCardButton(rect2.x, rect4.y, thingDef, GenStuff.DefaultStuffFor(thingDef)); } }
public override bool Spawn(IntVec3 at, Map map, Faction faction, Sketch.SpawnMode spawnMode = Sketch.SpawnMode.Normal, bool wipeIfCollides = false, List <Thing> spawnedThings = null, bool dormant = false) { if (IsSpawningBlocked(at, map, null, wipeIfCollides)) { return(false); } switch (spawnMode) { case Sketch.SpawnMode.Blueprint: GenConstruct.PlaceBlueprintForBuild(def, at, map, rot, faction, stuff ?? GenStuff.DefaultStuffFor(def)); break; case Sketch.SpawnMode.Normal: { Thing thing2 = Instantiate(); spawnedThings?.Add(thing2); if (faction != null) { thing2.SetFactionDirect(faction); } SetDormant(thing2, dormant); GenSpawn.Spawn(thing2, at, map, rot, WipeMode.VanishOrMoveAside); break; } case Sketch.SpawnMode.TransportPod: { Thing thing = Instantiate(); thing.Position = at; thing.Rotation = rot; spawnedThings?.Add(thing); if (faction != null) { thing.SetFactionDirect(faction); } SetDormant(thing, dormant); ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo(); activeDropPodInfo.innerContainer.TryAdd(thing, 1); activeDropPodInfo.openDelay = 60; activeDropPodInfo.leaveSlag = false; activeDropPodInfo.despawnPodBeforeSpawningThing = true; activeDropPodInfo.spawnWipeMode = (wipeIfCollides ? new WipeMode?(WipeMode.VanishOrMoveAside) : null); activeDropPodInfo.moveItemsAsideBeforeSpawning = true; activeDropPodInfo.setRotation = rot; DropPodUtility.MakeDropPodAt(at, map, activeDropPodInfo); break; } default: throw new NotImplementedException("Spawn mode " + spawnMode + " not implemented!"); } return(true); }
public override bool CanBuildOnTerrain(IntVec3 at, Map map) { return(GenConstruct.CanBuildOnTerrain(def, at, map, rot, null, stuff ?? GenStuff.DefaultStuffFor(def))); }
public override bool IsSpawningBlocked(IntVec3 at, Map map, Thing thingToIgnore = null, bool wipeIfCollides = false) { if (IsSpawningBlockedPermanently(at, map, thingToIgnore, wipeIfCollides)) { return(true); } if (!at.InBounds(map)) { return(true); } if (!GenConstruct.CanPlaceBlueprintAt(def, at, rot, map, wipeIfCollides, thingToIgnore, null, stuff ?? GenStuff.DefaultStuffFor(def)).Accepted) { return(true); } return(false); }
private static void CacheAccessibleThings(int nearTile) { if (nearTile != PlayerItemAccessibilityUtility.cachedAccessibleThingsForTile || RealTime.frameCount != PlayerItemAccessibilityUtility.cachedAccessibleThingsForFrame) { PlayerItemAccessibilityUtility.cachedAccessibleThings.Clear(); PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Clear(); WorldGrid worldGrid = Find.WorldGrid; List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { float num = worldGrid.ApproxDistanceInTiles(nearTile, maps[i].Tile); if (num <= 5f) { ThingOwnerUtility.GetAllThingsRecursively(maps[i], PlayerItemAccessibilityUtility.tmpThings, false, null); PlayerItemAccessibilityUtility.cachedAccessibleThings.AddRange(PlayerItemAccessibilityUtility.tmpThings); } } List <Caravan> caravans = Find.WorldObjects.Caravans; for (int j = 0; j < caravans.Count; j++) { if (caravans[j].IsPlayerControlled) { float num2 = worldGrid.ApproxDistanceInTiles(nearTile, caravans[j].Tile); if (num2 <= 5f) { ThingOwnerUtility.GetAllThingsRecursively(caravans[j], PlayerItemAccessibilityUtility.tmpThings, false, null); PlayerItemAccessibilityUtility.cachedAccessibleThings.AddRange(PlayerItemAccessibilityUtility.tmpThings); } } } for (int k = 0; k < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; k++) { Thing thing = PlayerItemAccessibilityUtility.cachedAccessibleThings[k]; PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(thing.def, thing.stackCount)); if (GenLeaving.CanBuildingLeaveResources(thing, DestroyMode.Deconstruct)) { List <ThingDefCountClass> list = thing.CostListAdjusted(); for (int l = 0; l < list.Count; l++) { int num3 = Mathf.RoundToInt((float)list[l].count * thing.def.resourcesFractionWhenDeconstructed); if (num3 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(list[l].thingDef, num3)); } } } Plant plant = thing as Plant; if (plant != null) { if (plant.HarvestableNow || plant.HarvestableSoon) { int num4 = Mathf.RoundToInt(plant.def.plant.harvestYield * Find.Storyteller.difficulty.cropYieldFactor); if (num4 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(plant.def.plant.harvestedThingDef, num4)); } } } if (!thing.def.butcherProducts.NullOrEmpty <ThingDefCountClass>()) { for (int m = 0; m < thing.def.butcherProducts.Count; m++) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(thing.def.butcherProducts[m]); } } Pawn pawn = thing as Pawn; if (pawn != null) { if (pawn.RaceProps.meatDef != null) { int num5 = Mathf.RoundToInt(pawn.GetStatValue(StatDefOf.MeatAmount, true)); if (num5 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.meatDef, num5)); } } if (pawn.RaceProps.leatherDef != null) { int num6 = GenMath.RoundRandom(pawn.GetStatValue(StatDefOf.LeatherAmount, true)); if (num6 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(pawn.RaceProps.leatherDef, num6)); } } if (!pawn.RaceProps.Humanlike) { PawnKindLifeStage curKindLifeStage = pawn.ageTracker.CurKindLifeStage; if (curKindLifeStage.butcherBodyPart != null) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(curKindLifeStage.butcherBodyPart.thing, 1)); } } } if (thing.def.smeltable) { List <ThingDefCountClass> list2 = thing.CostListAdjusted(); for (int n = 0; n < list2.Count; n++) { if (!list2[n].thingDef.intricate) { int num7 = Mathf.RoundToInt((float)list2[n].count * 0.25f); if (num7 > 0) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(list2[n].thingDef, num7)); } } } } if (thing.def.smeltable && !thing.def.smeltProducts.NullOrEmpty <ThingDefCountClass>()) { for (int num8 = 0; num8 < thing.def.smeltProducts.Count; num8++) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(thing.def.smeltProducts[num8]); } } } int num9 = 0; for (int num10 = 0; num10 < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; num10++) { Pawn pawn2 = PlayerItemAccessibilityUtility.cachedAccessibleThings[num10] as Pawn; if (pawn2 != null && pawn2.IsFreeColonist && !pawn2.Dead && !pawn2.Downed && pawn2.workSettings.WorkIsActive(WorkTypeDefOf.Crafting)) { num9++; } } if (num9 > 0) { PlayerItemAccessibilityUtility.tmpWorkTables.Clear(); for (int num11 = 0; num11 < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; num11++) { Building_WorkTable building_WorkTable = PlayerItemAccessibilityUtility.cachedAccessibleThings[num11] as Building_WorkTable; if (building_WorkTable != null && building_WorkTable.Spawned && PlayerItemAccessibilityUtility.tmpWorkTables.Add(building_WorkTable.def)) { List <RecipeDef> allRecipes = building_WorkTable.def.AllRecipes; for (int num12 = 0; num12 < allRecipes.Count; num12++) { if (allRecipes[num12].AvailableNow) { if (allRecipes[num12].products.Any <ThingDefCountClass>()) { if (!allRecipes[num12].PotentiallyMissingIngredients(null, building_WorkTable.Map).Any <ThingDef>()) { ThingDef stuffDef = (!allRecipes[num12].products[0].thingDef.MadeFromStuff) ? null : GenStuff.DefaultStuffFor(allRecipes[num12].products[0].thingDef); float num13 = allRecipes[num12].WorkAmountTotal(stuffDef); if (num13 > 0f) { int num14 = Mathf.FloorToInt((float)(num9 * 60000 * 5) * 0.09f / num13); if (num14 > 0) { for (int num15 = 0; num15 < allRecipes[num12].products.Count; num15++) { PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Add(new ThingDefCount(allRecipes[num12].products[num15].thingDef, allRecipes[num12].products[num15].count * num14)); } } } } } } } } } } PlayerItemAccessibilityUtility.cachedAccessibleThingsForTile = nearTile; PlayerItemAccessibilityUtility.cachedAccessibleThingsForFrame = RealTime.frameCount; } }
public override void DoWindowContents(Rect inRect) { Text.Font = GameFont.Medium; Widgets.Label(new Rect(0f, 0f, 400f, 50f), bill.LabelCap); float width = (int)((inRect.width - 34f) / 3f); Rect rect = new Rect(0f, 80f, width, inRect.height - 80f); Rect rect2 = new Rect(rect.xMax + 17f, 50f, width, inRect.height - 50f - CloseButSize.y); Rect rect3 = new Rect(rect2.xMax + 17f, 50f, 0f, inRect.height - 50f - CloseButSize.y); rect3.xMax = inRect.xMax; Text.Font = GameFont.Small; Listing_Standard listing_Standard = new Listing_Standard(); listing_Standard.Begin(rect2); Listing_Standard listing_Standard2 = listing_Standard.BeginSection(RepeatModeSubdialogHeight); if (listing_Standard2.ButtonText(bill.repeatMode.LabelCap)) { BillRepeatModeUtility.MakeConfigFloatMenu(bill); } listing_Standard2.Gap(); if (bill.repeatMode == BillRepeatModeDefOf.RepeatCount) { listing_Standard2.Label("RepeatCount".Translate(bill.repeatCount)); listing_Standard2.IntEntry(ref bill.repeatCount, ref repeatCountEditBuffer); } else if (bill.repeatMode == BillRepeatModeDefOf.TargetCount) { string arg = "CurrentlyHave".Translate() + ": "; arg += bill.recipe.WorkerCounter.CountProducts(bill); arg += " / "; arg += ((bill.targetCount < 999999) ? bill.targetCount.ToString() : "Infinite".Translate().ToLower().ToString()); string str = bill.recipe.WorkerCounter.ProductsDescription(bill); if (!str.NullOrEmpty()) { arg += "\n" + "CountingProducts".Translate() + ": " + str.CapitalizeFirst(); } listing_Standard2.Label(arg); int targetCount = bill.targetCount; listing_Standard2.IntEntry(ref bill.targetCount, ref targetCountEditBuffer, bill.recipe.targetCountAdjustment); bill.unpauseWhenYouHave = Mathf.Max(0, bill.unpauseWhenYouHave + (bill.targetCount - targetCount)); ThingDef producedThingDef = bill.recipe.ProducedThingDef; if (producedThingDef != null) { if (producedThingDef.IsWeapon || producedThingDef.IsApparel) { listing_Standard2.CheckboxLabeled("IncludeEquipped".Translate(), ref bill.includeEquipped); } if (producedThingDef.IsApparel && producedThingDef.apparel.careIfWornByCorpse) { listing_Standard2.CheckboxLabeled("IncludeTainted".Translate(), ref bill.includeTainted); } Widgets.Dropdown(listing_Standard2.GetRect(30f), bill, (Bill_Production b) => b.includeFromZone, (Bill_Production b) => GenerateStockpileInclusion(), (bill.includeFromZone == null) ? "IncludeFromAll".Translate() : "IncludeSpecific".Translate(bill.includeFromZone.label)); if (bill.recipe.products.Any((ThingDefCountClass prod) => prod.thingDef.useHitPoints)) { Widgets.FloatRange(listing_Standard2.GetRect(28f), 975643279, ref bill.hpRange, 0f, 1f, "HitPoints", ToStringStyle.PercentZero); bill.hpRange.min = Mathf.Round(bill.hpRange.min * 100f) / 100f; bill.hpRange.max = Mathf.Round(bill.hpRange.max * 100f) / 100f; } if (producedThingDef.HasComp(typeof(CompQuality))) { Widgets.QualityRange(listing_Standard2.GetRect(28f), 1098906561, ref bill.qualityRange); } if (producedThingDef.MadeFromStuff) { listing_Standard2.CheckboxLabeled("LimitToAllowedStuff".Translate(), ref bill.limitToAllowedStuff); } } } if (bill.repeatMode == BillRepeatModeDefOf.TargetCount) { listing_Standard2.CheckboxLabeled("PauseWhenSatisfied".Translate(), ref bill.pauseWhenSatisfied); if (bill.pauseWhenSatisfied) { listing_Standard2.Label("UnpauseWhenYouHave".Translate() + ": " + bill.unpauseWhenYouHave.ToString("F0")); listing_Standard2.IntEntry(ref bill.unpauseWhenYouHave, ref unpauseCountEditBuffer, bill.recipe.targetCountAdjustment); if (bill.unpauseWhenYouHave >= bill.targetCount) { bill.unpauseWhenYouHave = bill.targetCount - 1; unpauseCountEditBuffer = bill.unpauseWhenYouHave.ToStringCached(); } } } listing_Standard.EndSection(listing_Standard2); listing_Standard.Gap(); Listing_Standard listing_Standard3 = listing_Standard.BeginSection(StoreModeSubdialogHeight); string text = string.Format(bill.GetStoreMode().LabelCap, (bill.GetStoreZone() != null) ? bill.GetStoreZone().SlotYielderLabel() : ""); if (bill.GetStoreZone() != null && !bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(bill, bill.GetStoreZone())) { text += string.Format(" ({0})", "IncompatibleLower".Translate()); Text.Font = GameFont.Tiny; } if (listing_Standard3.ButtonText(text)) { Text.Font = GameFont.Small; List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (BillStoreModeDef item in DefDatabase <BillStoreModeDef> .AllDefs.OrderBy((BillStoreModeDef bsm) => bsm.listOrder)) { if (item == BillStoreModeDefOf.SpecificStockpile) { List <SlotGroup> allGroupsListInPriorityOrder = bill.billStack.billGiver.Map.haulDestinationManager.AllGroupsListInPriorityOrder; int count = allGroupsListInPriorityOrder.Count; for (int i = 0; i < count; i++) { SlotGroup group = allGroupsListInPriorityOrder[i]; Zone_Stockpile zone_Stockpile = group.parent as Zone_Stockpile; if (zone_Stockpile != null) { if (!bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(bill, zone_Stockpile)) { list.Add(new FloatMenuOption(string.Format("{0} ({1})", string.Format(item.LabelCap, group.parent.SlotYielderLabel()), "IncompatibleLower".Translate()), null)); } else { list.Add(new FloatMenuOption(string.Format(item.LabelCap, group.parent.SlotYielderLabel()), delegate { bill.SetStoreMode(BillStoreModeDefOf.SpecificStockpile, (Zone_Stockpile)group.parent); })); } } } } else { BillStoreModeDef smLocal = item; list.Add(new FloatMenuOption(smLocal.LabelCap, delegate { bill.SetStoreMode(smLocal); })); } } Find.WindowStack.Add(new FloatMenu(list)); } Text.Font = GameFont.Small; listing_Standard.EndSection(listing_Standard3); listing_Standard.Gap(); Listing_Standard listing_Standard4 = listing_Standard.BeginSection(WorkerSelectionSubdialogHeight); Widgets.Dropdown(listing_Standard4.GetRect(30f), bill, (Bill_Production b) => b.pawnRestriction, (Bill_Production b) => GeneratePawnRestrictionOptions(), (bill.pawnRestriction == null) ? "AnyWorker".TranslateSimple() : bill.pawnRestriction.LabelShortCap); if (bill.pawnRestriction == null && bill.recipe.workSkill != null) { listing_Standard4.Label("AllowedSkillRange".Translate(bill.recipe.workSkill.label)); listing_Standard4.IntRange(ref bill.allowedSkillRange, 0, 20); } listing_Standard.EndSection(listing_Standard4); listing_Standard.End(); Rect rect4 = rect3; bool flag = true; for (int j = 0; j < bill.recipe.ingredients.Count; j++) { if (!bill.recipe.ingredients[j].IsFixedIngredient) { flag = false; break; } } if (!flag) { rect4.yMin = rect4.yMax - (float)IngredientRadiusSubdialogHeight; rect3.yMax = rect4.yMin - 17f; bool num = bill.GetStoreZone() == null || bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(bill, bill.GetStoreZone()); ThingFilterUI.DoThingFilterConfigWindow(rect3, ref thingFilterScrollPosition, bill.ingredientFilter, bill.recipe.fixedIngredientFilter, 4, null, bill.recipe.forceHiddenSpecialFilters, forceHideHitPointsConfig: false, bill.recipe.GetPremultipliedSmallIngredients(), bill.Map); bool flag2 = bill.GetStoreZone() == null || bill.recipe.WorkerCounter.CanPossiblyStoreInStockpile(bill, bill.GetStoreZone()); if (num && !flag2) { Messages.Message("MessageBillValidationStoreZoneInsufficient".Translate(bill.LabelCap, bill.billStack.billGiver.LabelShort.CapitalizeFirst(), bill.GetStoreZone().label), bill.billStack.billGiver as Thing, MessageTypeDefOf.RejectInput, historical: false); } } else { rect4.yMin = 50f; } Listing_Standard listing_Standard5 = new Listing_Standard(); listing_Standard5.Begin(rect4); string str2 = "IngredientSearchRadius".Translate().Truncate(rect4.width * 0.6f); string str3 = (bill.ingredientSearchRadius == 999f) ? "Unlimited".TranslateSimple().Truncate(rect4.width * 0.3f) : bill.ingredientSearchRadius.ToString("F0"); listing_Standard5.Label(str2 + ": " + str3); bill.ingredientSearchRadius = listing_Standard5.Slider((bill.ingredientSearchRadius > 100f) ? 100f : bill.ingredientSearchRadius, 3f, 100f); if (bill.ingredientSearchRadius >= 100f) { bill.ingredientSearchRadius = 999f; } listing_Standard5.End(); Listing_Standard listing_Standard6 = new Listing_Standard(); listing_Standard6.Begin(rect); if (bill.suspended) { if (listing_Standard6.ButtonText("Suspended".Translate())) { bill.suspended = false; SoundDefOf.Click.PlayOneShotOnCamera(); } } else if (listing_Standard6.ButtonText("NotSuspended".Translate())) { bill.suspended = true; SoundDefOf.Click.PlayOneShotOnCamera(); } StringBuilder stringBuilder = new StringBuilder(); if (bill.recipe.description != null) { stringBuilder.AppendLine(bill.recipe.description); stringBuilder.AppendLine(); } stringBuilder.AppendLine("WorkAmount".Translate() + ": " + bill.recipe.WorkAmountTotal(null).ToStringWorkAmount()); for (int k = 0; k < bill.recipe.ingredients.Count; k++) { IngredientCount ingredientCount = bill.recipe.ingredients[k]; if (!ingredientCount.filter.Summary.NullOrEmpty()) { stringBuilder.AppendLine(bill.recipe.IngredientValueGetter.BillRequirementsDescription(bill.recipe, ingredientCount)); } } stringBuilder.AppendLine(); string text2 = bill.recipe.IngredientValueGetter.ExtraDescriptionLine(bill.recipe); if (text2 != null) { stringBuilder.AppendLine(text2); stringBuilder.AppendLine(); } if (!bill.recipe.skillRequirements.NullOrEmpty()) { stringBuilder.AppendLine("MinimumSkills".Translate()); stringBuilder.AppendLine(bill.recipe.MinSkillString); } Text.Font = GameFont.Small; string text3 = stringBuilder.ToString(); if (Text.CalcHeight(text3, rect.width) > rect.height) { Text.Font = GameFont.Tiny; } listing_Standard6.Label(text3); Text.Font = GameFont.Small; listing_Standard6.End(); if (bill.recipe.products.Count == 1) { ThingDef thingDef = bill.recipe.products[0].thingDef; Widgets.InfoCardButton(rect.x, rect3.y, thingDef, GenStuff.DefaultStuffFor(thingDef)); } }
internal void <> m__0() { this.$this.thingDef = this.localTd; this.$this.stuff = GenStuff.DefaultStuffFor(this.localTd); }