Beispiel #1
0
 private static bool TryFindBestBillIngredientsInSet_AllowMix(List <Thing> availableThings, Building_CokeFurnace bill, List <ThingCount> chosen)
 {
     chosen.Clear();
     for (int i = 0; i < bill.SelectedRecipe.ingredients.Count; i++)
     {
         IngredientCount ingredientCount = bill.SelectedRecipe.ingredients[i];
         float           num             = ingredientCount.GetBaseCount();
         for (int j = 0; j < availableThings.Count; j++)
         {
             Thing thing = availableThings[j];
             if (ingredientCount.filter.Allows(thing) && ingredientCount.IsFixedIngredient)
             {
                 float num2 = bill.SelectedRecipe.IngredientValueGetter.ValuePerUnitOf(thing.def);
                 int   num3 = Mathf.Min(Mathf.CeilToInt(num / num2), thing.stackCount);
                 ThingCountUtility.AddToList(chosen, thing, num3);
                 num -= (float)num3 * num2;
                 if (num <= 0.0001f)
                 {
                     break;
                 }
             }
         }
         if (num > 0.0001f)
         {
             return(false);
         }
     }
     return(true);
 }
        private static ERecipeType GetType(ThingDef td, IngredientCount ing, Bill_Production bill)
        {
            if (ing.IsFixedIngredient)
            {
                if (!bill.recipe.fixedIngredientFilter.Allows(td))
                {
                    return(ERecipeType.FixedNotSelectable);
                }

                if (bill.ingredientFilter.Allows(td))
                {
                    return(ERecipeType.FixedSelectableAllowed);
                }

                return(ERecipeType.Unknown);
            }

            if (bill.recipe.fixedIngredientFilter.Allows(td))
            {
                return(bill.ingredientFilter.Allows(td)
                    ? ERecipeType.SelectableAllowed
                    : ERecipeType.SelectableNotAllowed);
            }

            return(ERecipeType.Unknown);
        }
        public static bool Prefix(List <Thing> availableThings, Bill bill, List <ThingCount> chosen, ref bool __result)
        {
            Pawn trainee = WorkGiver_DoBill_TryFindBestBillIngredients.Trainee;

            if (trainee != null)
            {
                chosen.Clear();
                availableThings.Sort((Thing t, Thing t2) => bill.recipe.IngredientValueGetter.ValuePerUnitOf(t2.def).CompareTo(bill.recipe.IngredientValueGetter.ValuePerUnitOf(t.def)));
                for (int i = 0; i < bill.recipe.ingredients.Count; i++)
                {
                    IngredientCount ingredientCount = bill.recipe.ingredients[i];
                    for (int j = 0; j < availableThings.Count; j++)
                    {
                        Thing thing = availableThings[j];
                        if (ingredientCount.filter.Allows(thing) && (ingredientCount.IsFixedIngredient || bill.ingredientFilter.Allows(thing)))
                        {
                            ThingCountUtility.AddToList(chosen, thing, 1);
                        }
                    }
                }
                __result = true;
                return(false);
            }
            return(true);
        }
Beispiel #4
0
        public override void CkeckResolve(Thing thing, int amount, float nutriment)
        {
            IngestibleInfo ingestibleInfo = null;

            if (FoodUtility.IsHumanlikeMeatOrHumanlikeCorpse(thing))
            {
                ingestibleInfo = ThingsWanted[0];
            }
            else if (ThingsWanted[0].inIngredient)
            {
                CompIngredients compIngredients = thing.TryGetComp <CompIngredients>();
                if (compIngredients != null && !compIngredients.ingredients.NullOrEmpty())
                {
                    amount    = 0;
                    nutriment = 0;
                    for (int i = 0; i < compIngredients.ingredients.Count; i++)
                    {
                        if (FoodUtility.IsHumanlikeMeat(compIngredients.ingredients[i]))
                        {
                            RecipeDef recipe = DefDatabase <RecipeDef> .AllDefsListForReading.Find(rec => rec.ProducedThingDef == thing.def);

                            IngredientCount ingredient = recipe?.ingredients?.Find(ing => ing.filter.Allows(compIngredients.ingredients[i])) ?? null;
                            if (ingredient != null)
                            {
                                amount        += ingredient.CountRequiredOfFor(ThingsWanted[0].ingestible, recipe);
                                nutriment     += ingredient.GetBaseCount();
                                ingestibleInfo = ThingsWanted[0];
                            }
                        }
                    }
                }
            }
            DoUpdate(ingestibleInfo, amount, nutriment);
        }
Beispiel #5
0
 private static void MakeIngredientsListInProcessingOrder(List <IngredientCount> ingredientsOrdered, Bill bill)
 {
     ingredientsOrdered.Clear();
     if (bill.recipe.productHasIngredientStuff)
     {
         ingredientsOrdered.Add(bill.recipe.ingredients[0]);
     }
     for (int i = 0; i < bill.recipe.ingredients.Count; i++)
     {
         if (!bill.recipe.productHasIngredientStuff || i != 0)
         {
             IngredientCount ingredientCount = bill.recipe.ingredients[i];
             if (ingredientCount.IsFixedIngredient)
             {
                 ingredientsOrdered.Add(ingredientCount);
             }
         }
     }
     for (int j = 0; j < bill.recipe.ingredients.Count; j++)
     {
         IngredientCount item = bill.recipe.ingredients[j];
         if (!ingredientsOrdered.Contains(item))
         {
             ingredientsOrdered.Add(item);
         }
     }
 }
 private static IEnumerable <RecipeDef> DrugAdministerDefs()
 {
     foreach (ThingDef item in DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.IsDrug))
     {
         RecipeDef recipeDef = new RecipeDef();
         recipeDef.defName                    = "Administer_" + item.defName;
         recipeDef.label                      = "RecipeAdminister".Translate(item.label);
         recipeDef.jobString                  = "RecipeAdministerJobString".Translate(item.label);
         recipeDef.workerClass                = typeof(Recipe_AdministerIngestible);
         recipeDef.targetsBodyPart            = false;
         recipeDef.anesthetize                = false;
         recipeDef.surgerySuccessChanceFactor = 99999f;
         recipeDef.modContentPack             = item.modContentPack;
         recipeDef.workAmount                 = item.ingestible.baseIngestTicks;
         IngredientCount ingredientCount = new IngredientCount();
         ingredientCount.SetBaseCount(1f);
         ingredientCount.filter.SetAllow(item, allow: true);
         recipeDef.ingredients.Add(ingredientCount);
         recipeDef.fixedIngredientFilter.SetAllow(item, allow: true);
         recipeDef.recipeUsers = new List <ThingDef>();
         foreach (ThingDef item2 in DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.category == ThingCategory.Pawn && d.race.IsFlesh))
         {
             recipeDef.recipeUsers.Add(item2);
         }
         yield return(recipeDef);
     }
 }
Beispiel #7
0
 private static void MakeIngredientsListInProcessingOrder(
     List <IngredientCount> ingredientsOrdered,
     Bill bill)
 {
     ingredientsOrdered.Clear();
     if (bill.recipe.productHasIngredientStuff)
     {
         ingredientsOrdered.Add(bill.recipe.ingredients[0]);
     }
     for (int index = 0; index < bill.recipe.ingredients.Count; ++index)
     {
         if (!bill.recipe.productHasIngredientStuff || index != 0)
         {
             IngredientCount ingredient = bill.recipe.ingredients[index];
             if (ingredient.IsFixedIngredient)
             {
                 ingredientsOrdered.Add(ingredient);
             }
         }
     }
     for (int index = 0; index < bill.recipe.ingredients.Count; ++index)
     {
         IngredientCount ingredient = bill.recipe.ingredients[index];
         if (!ingredientsOrdered.Contains(ingredient))
         {
             ingredientsOrdered.Add(ingredient);
         }
     }
 }
 public static bool TryFindBestRecipeIngredientsInSet_AllowMix(this RecipeDef recipeDef, List <Thing> availableThings, List <ThingCount> chosen)
 {
     chosen.Clear();
     for (int ingredientIndex = 0; ingredientIndex < recipeDef.ingredients.Count; ++ingredientIndex)
     {
         IngredientCount ingredientCount = recipeDef.ingredients[ingredientIndex];
         float           baseCount       = ingredientCount.GetBaseCount();
         for (int thingIndex = 0; thingIndex < availableThings.Count; ++thingIndex)
         {
             Thing thing = availableThings[thingIndex];
             if (ingredientCount.filter.Allows(thing))
             {
                 float ingredientValue = recipeDef.IngredientValueGetter.ValuePerUnitOf(thing.def);
                 int   countToAdd      = Mathf.Min(Mathf.CeilToInt(baseCount / ingredientValue), thing.stackCount);
                 ThingCountUtility.AddToList(chosen, thing, countToAdd);
                 baseCount -= (float)countToAdd * ingredientValue;
                 if ((double)baseCount <= 9.99999974737875E-05)
                 {
                     break;
                 }
             }
         }
         if ((double)baseCount > 9.99999974737875E-05)
         {
             return(false);
         }
     }
     return(true);
 }
 private static IEnumerable <RecipeDef> DrugAdministerDefs()
 {
     foreach (ThingDef def in from d in DefDatabase <ThingDef> .AllDefs
              where d.IsDrug
              select d)
     {
         RecipeDef r = new RecipeDef();
         r.defName = "Administer_" + def.defName;
         r.label   = "RecipeAdminister".Translate(new object[]
         {
             def.label
         });
         r.jobString = "RecipeAdministerJobString".Translate(new object[]
         {
             def.label
         });
         r.workerClass                = typeof(Recipe_AdministerIngestible);
         r.targetsBodyPart            = false;
         r.anesthetize                = false;
         r.surgerySuccessChanceFactor = 99999f;
         r.workAmount = (float)def.ingestible.baseIngestTicks;
         IngredientCount ic = new IngredientCount();
         ic.SetBaseCount(1f);
         ic.filter.SetAllow(def, true);
         r.ingredients.Add(ic);
         r.fixedIngredientFilter.SetAllow(def, true);
         r.recipeUsers = new List <ThingDef>();
         foreach (ThingDef current in DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.category == ThingCategory.Pawn && d.race.IsFlesh))
         {
             r.recipeUsers.Add(current);
         }
         yield return(r);
     }
 }
 public bool TryDropThings(IngredientCount ic, out List <Thing> dropped)
 {
     dropped = null;
     foreach (LinkedList <Thing> l in this.storedThings.Values)
     {
         if (l.Count > 0)
         {
             if (ic.filter.Allows(l.First.Value.def))
             {
                 foreach (Thing t in l)
                 {
                     if (ic.filter.Allows(t))
                     {
                         this.DropThing(t, null);
                         if (dropped == null)
                         {
                             dropped = new List <Thing>();
                         }
                         dropped.Add(t);
                     }
                 }
             }
         }
     }
     return(dropped?.Count > 0);
 }
Beispiel #11
0
 private static bool TryFindBestBillIngredientsInSet_AllowMix(List <Thing> availableThings, Bill bill, List <ThingAmount> chosen)
 {
     chosen.Clear();
     for (int i = 0; i < bill.recipe.ingredients.Count; i++)
     {
         IngredientCount ingredientCount = bill.recipe.ingredients[i];
         float           num             = ingredientCount.GetBaseCount();
         for (int j = 0; j < availableThings.Count; j++)
         {
             Thing thing = availableThings[j];
             if (ingredientCount.filter.Allows(thing) && (ingredientCount.IsFixedIngredient || bill.ingredientFilter.Allows(thing)))
             {
                 float num2 = bill.recipe.IngredientValueGetter.ValuePerUnitOf(thing.def);
                 int   num3 = Mathf.Min(Mathf.CeilToInt(num / num2), thing.stackCount);
                 ThingAmount.AddToList(chosen, thing, num3);
                 num -= (float)num3 * num2;
                 if (num <= 9.9999997473787516E-05)
                 {
                     break;
                 }
             }
         }
         if (num > 9.9999997473787516E-05)
         {
             return(false);
         }
     }
     return(true);
 }
        private static RecipeDef CreateToEnergyRecipeDef(string defName, string label, string jobString, float workAmount, int count, HashSet <ThingDef> toEnergyDefs)
        {
            var r = CreateRecipeDef(defName, label, jobString, workAmount);

            var c = new IngredientCount();

            r.ingredients.Add(c);
            c.SetBaseCount(count);
            c.filter = new ThingFilter();
            toEnergyDefs.ForEach(d =>
            {
                if (d.defName != "NR_MaterialEnergy_Energy")
                {
                    r.fixedIngredientFilter.SetAllow(d, true);
                    c.filter.SetAllow(d, true);
                }
            });
            c.filter.RecalculateDisplayRootCategory();
            r.defaultIngredientFilter = new ThingFilter();
            r.defaultIngredientFilter.SetDisallowAll(null);
            r.fixedIngredientFilter.RecalculateDisplayRootCategory();
            r.ResolveReferences();
            r.products.Add(new ThingDefCount(energyThingDef, count));
            r.allowMixingIngredients = true;

            return(r);
        }
Beispiel #13
0
 internal static bool TryFindBestMixInSet_AllowMix(List <Thing> availableThings, Bill bill, List <ThingCount> chosen)
 {
     chosen.Clear();
     for (var i = 0; i < bill.recipe.ingredients.Count; i++)
     {
         IngredientCount ingredientCount = bill.recipe.ingredients[i];
         var             num             = ingredientCount.GetBaseCount();
         for (var j = 0; j < availableThings.Count; j++)
         {
             Thing thing = availableThings[j];
             if (ingredientCount.filter.Allows(thing) && (ingredientCount.IsFixedIngredient || bill.ingredientFilter.Allows(thing)))
             {
                 var num2 = bill.recipe.IngredientValueGetter.ValuePerUnitOf(thing.def);
                 var num3 = Mathf.Min(Mathf.CeilToInt(num / num2), thing.stackCount);
                 ThingCountUtility.AddToList(chosen, thing, num3);
                 num -= (float)num3 * num2;
                 if (num <= 0.0001f)
                 {
                     break;
                 }
             }
         }
         if (num > 0.0001f)
         {
             return(false);
         }
     }
     return(true);
 }
        private static RecipeDef CreateMaterializeRecipeDef(string defName, string label, string jobString, float workAmount, int energyCount, ThingDef product, int productCount, ThingDef stuff)
        {
            var r = CreateRecipeDef(defName, label, jobString, workAmount);

            var c = new IngredientCount();

            r.ingredients.Add(c);
            c.SetBaseCount(energyCount);
            c.filter = new ThingFilter();
            r.defaultIngredientFilter = new ThingFilter();

            if (stuff != null)
            {
                var st = new IngredientCount();
                r.ingredients.Add(st);
                st.filter.SetAllow(stuff, true);
                // とりえあずstuff は 10個でいい.
                st.SetBaseCount(10);
            }

            c.filter.SetAllow(energyThingDef, true);
            r.defaultIngredientFilter.SetAllow(energyThingDef, true);
            c.filter.RecalculateDisplayRootCategory();

            r.fixedIngredientFilter.RecalculateDisplayRootCategory();
            r.ResolveReferences();
            r.products.Add(new ThingDefCount(product, productCount));

            return(r);
        }
Beispiel #15
0
 private static bool TryFindBestBillIngredientsInSet_AllowMix(
     List <Thing> availableThings,
     Bill bill,
     List <ThingCount> chosen)
 {
     chosen.Clear();
     availableThings.Sort((t, t2) => bill.recipe.IngredientValueGetter.ValuePerUnitOf(t2.def).CompareTo(bill.recipe.IngredientValueGetter.ValuePerUnitOf(t.def)));
     for (int index1 = 0; index1 < bill.recipe.ingredients.Count; ++index1)
     {
         IngredientCount ingredient = bill.recipe.ingredients[index1];
         float           baseCount  = ingredient.GetBaseCount();
         for (int index2 = 0; index2 < availableThings.Count; ++index2)
         {
             Thing availableThing = availableThings[index2];
             if (ingredient.filter.Allows(availableThing) && (ingredient.IsFixedIngredient || bill.ingredientFilter.Allows(availableThing)))
             {
                 float num        = bill.recipe.IngredientValueGetter.ValuePerUnitOf(availableThing.def);
                 int   countToAdd = Mathf.Min(Mathf.CeilToInt(baseCount / num), availableThing.stackCount);
                 ThingCountUtility.AddToList(chosen, availableThing, countToAdd);
                 baseCount -= countToAdd * num;
                 if (baseCount <= 9.99999974737875E-05)
                 {
                     break;
                 }
             }
         }
         if (baseCount > 9.99999974737875E-05)
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #16
0
        private static IEnumerable <RecipeDef> DefsFromRecipeMakers()
        {
            using (IEnumerator <ThingDef> enumerator = (from d in DefDatabase <ThingDef> .AllDefs
                                                        where d.recipeMaker != null
                                                        select d).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    ThingDef def             = enumerator.Current;
                    RecipeMakerProperties rm = def.recipeMaker;
                    RecipeDef             r  = new RecipeDef
                    {
                        defName        = "Make_" + def.defName,
                        label          = "RecipeMake".Translate(def.label),
                        jobString      = "RecipeMakeJobString".Translate(def.label),
                        modContentPack = def.modContentPack,
                        workAmount     = (float)rm.workAmount,
                        workSpeedStat  = rm.workSpeedStat,
                        efficiencyStat = rm.efficiencyStat
                    };
                    if (def.MadeFromStuff)
                    {
                        IngredientCount ingredientCount = new IngredientCount();
                        ingredientCount.SetBaseCount((float)def.costStuffCount);
                        ingredientCount.filter.SetAllowAllWhoCanMake(def);
                        r.ingredients.Add(ingredientCount);
                        r.fixedIngredientFilter.SetAllowAllWhoCanMake(def);
                        r.productHasIngredientStuff = true;
                    }
                    if (def.costList != null)
                    {
                        foreach (ThingDefCountClass cost in def.costList)
                        {
                            IngredientCount ingredientCount2 = new IngredientCount();
                            ingredientCount2.SetBaseCount((float)cost.count);
                            ingredientCount2.filter.SetAllow(cost.thingDef, allow: true);
                            r.ingredients.Add(ingredientCount2);
                        }
                    }
                    r.defaultIngredientFilter = rm.defaultIngredientFilter;
                    r.products.Add(new ThingDefCountClass(def, rm.productCount));
                    r.targetCountAdjustment   = rm.targetCountAdjustment;
                    r.skillRequirements       = rm.skillRequirements.ListFullCopyOrNull();
                    r.workSkill               = rm.workSkill;
                    r.workSkillLearnFactor    = rm.workSkillLearnPerTick;
                    r.unfinishedThingDef      = rm.unfinishedThingDef;
                    r.recipeUsers             = rm.recipeUsers.ListFullCopyOrNull();
                    r.effectWorking           = rm.effectWorking;
                    r.soundWorking            = rm.soundWorking;
                    r.researchPrerequisite    = rm.researchPrerequisite;
                    r.factionPrerequisiteTags = rm.factionPrerequisiteTags;
                    yield return(r);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield break;
IL_03ca:
            /*Error near IL_03cb: Unexpected return in MoveNext()*/;
        }
        public static string GetMaxAllowedCount(RecipeDef r, IngredientCount ing, bool isNutrition)
        {
            float countMax = 0f, countMaxNutrition = 0f;

            var bill = CurrentBill;

            if (bill == null)
            {
                return("");
            }

            foreach (var td in ing.filter.AllowedThingDefs)
            {
                var ingType = GetType(td, ing, bill);
                if (ingType != ERecipeType.Unknown && ingType != ERecipeType.SelectableNotAllowed)
                {
                    var count = ThingCountOnMap(td);

                    if (td.smallVolume)
                    {
                        count *= 10f;
                    }

                    if (count > countMax)
                    {
                        countMax = count;

                        if (isNutrition)
                        {
                            countMaxNutrition = count * NutritionValuePerUnitOf(td);
                        }
                    }


                    //Log.Message(String.Format("thing: {0}({1}), is_fixed: {2}, in_rff: {3}, in_bff: {4}, in_bif: {5}",
                    //    td.LabelCap,
                    //    count,
                    //    ing.IsFixedIngredient,
                    //    r.fixedIngredientFilter.Allows(td),
                    //    bill.recipe.fixedIngredientFilter.Allows(td),
                    //    bill.ingredientFilter.Allows(td)));
                }
            }

            string result;

            if (isNutrition)
            {
                result = !Settings.UseDashes || countMaxNutrition >= ing.GetBaseCount()
                    ? $" ({countMaxNutrition} / {countMax})"
                    : " (-)";
            }
            else
            {
                result = !Settings.UseDashes || countMax >= ing.GetBaseCount() ? $" ({countMax})" : " (-)";
            }

            return(result);
        }
Beispiel #18
0
        private static bool Prefix(ref string __result, RecipeDef r, IngredientCount ing)
        {
            __result = "BillRequiresNutrition"
                       .Translate(ing.GetBaseCount() + BillRequirementsMod.GetMaxAllowedCount(r, ing, true))
                       + " (" + ing.filter.Summary + ")";

            return(false);
        }
Beispiel #19
0
 private static IEnumerable <RecipeDef> DefsFromRecipeMakers()
 {
     foreach (ThingDef def in from d in DefDatabase <ThingDef> .AllDefs
              where d.recipeMaker != null
              select d)
     {
         RecipeMakerProperties rm = def.recipeMaker;
         RecipeDef             r  = new RecipeDef();
         r.defName = "Make_" + def.defName;
         r.label   = "RecipeMake".Translate(new object[]
         {
             def.label
         });
         r.jobString = "RecipeMakeJobString".Translate(new object[]
         {
             def.label
         });
         r.modContentPack = def.modContentPack;
         r.workAmount     = (float)rm.workAmount;
         r.workSpeedStat  = rm.workSpeedStat;
         r.efficiencyStat = rm.efficiencyStat;
         if (def.MadeFromStuff)
         {
             IngredientCount ingredientCount = new IngredientCount();
             ingredientCount.SetBaseCount((float)def.costStuffCount);
             ingredientCount.filter.SetAllowAllWhoCanMake(def);
             r.ingredients.Add(ingredientCount);
             r.fixedIngredientFilter.SetAllowAllWhoCanMake(def);
             r.productHasIngredientStuff = true;
         }
         if (def.costList != null)
         {
             foreach (ThingDefCountClass thingDefCountClass in def.costList)
             {
                 IngredientCount ingredientCount2 = new IngredientCount();
                 ingredientCount2.SetBaseCount((float)thingDefCountClass.count);
                 ingredientCount2.filter.SetAllow(thingDefCountClass.thingDef, true);
                 r.ingredients.Add(ingredientCount2);
             }
         }
         r.defaultIngredientFilter = rm.defaultIngredientFilter;
         r.products.Add(new ThingDefCountClass(def, rm.productCount));
         r.targetCountAdjustment   = rm.targetCountAdjustment;
         r.skillRequirements       = rm.skillRequirements.ListFullCopyOrNull <SkillRequirement>();
         r.workSkill               = rm.workSkill;
         r.workSkillLearnFactor    = rm.workSkillLearnPerTick;
         r.unfinishedThingDef      = rm.unfinishedThingDef;
         r.recipeUsers             = rm.recipeUsers.ListFullCopyOrNull <ThingDef>();
         r.effectWorking           = rm.effectWorking;
         r.soundWorking            = rm.soundWorking;
         r.researchPrerequisite    = rm.researchPrerequisite;
         r.factionPrerequisiteTags = rm.factionPrerequisiteTags;
         yield return(r);
     }
     yield break;
 }
        private static bool TryFindBestBillIngredientsInSet_NoMix(List <Thing> availableThings, Bill bill, List <ThingCount> chosen)
        {
            RecipeDef recipe = bill.recipe;

            chosen.Clear();
            WorkGiver_DoBill.availableCounts.Clear();
            WorkGiver_DoBill.availableCounts.GenerateFrom(availableThings);
            for (int i = 0; i < WorkGiver_DoBill.ingredientsOrdered.Count; i++)
            {
                IngredientCount ingredientCount = recipe.ingredients[i];
                bool            flag            = false;
                for (int j = 0; j < WorkGiver_DoBill.availableCounts.Count; j++)
                {
                    float num = (float)ingredientCount.CountRequiredOfFor(WorkGiver_DoBill.availableCounts.GetDef(j), bill.recipe);
                    if (num <= WorkGiver_DoBill.availableCounts.GetCount(j))
                    {
                        if (ingredientCount.filter.Allows(WorkGiver_DoBill.availableCounts.GetDef(j)))
                        {
                            if (ingredientCount.IsFixedIngredient || bill.ingredientFilter.Allows(WorkGiver_DoBill.availableCounts.GetDef(j)))
                            {
                                for (int k = 0; k < availableThings.Count; k++)
                                {
                                    if (availableThings[k].def == WorkGiver_DoBill.availableCounts.GetDef(j))
                                    {
                                        int num2 = availableThings[k].stackCount - ThingCountUtility.CountOf(chosen, availableThings[k]);
                                        if (num2 > 0)
                                        {
                                            int num3 = Mathf.Min(Mathf.FloorToInt(num), num2);
                                            ThingCountUtility.AddToList(chosen, availableThings[k], num3);
                                            num -= (float)num3;
                                            if (num < 0.001f)
                                            {
                                                flag = true;
                                                float num4 = WorkGiver_DoBill.availableCounts.GetCount(j);
                                                num4 -= (float)ingredientCount.CountRequiredOfFor(WorkGiver_DoBill.availableCounts.GetDef(j), bill.recipe);
                                                WorkGiver_DoBill.availableCounts.SetCount(j, num4);
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (flag)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!flag)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #21
0
        } //end FindClosestIngForBill

        public static Thing FindClosestIngToBillGiver(Bill theBill, IngredientCount curIng)
        {
            IBillGiver   billGiver            = theBill.billStack.billGiver;
            IThingHolder holder               = billGiver as IThingHolder;
            Thing        building             = billGiver as Thing;
            ThingOwner   vatStoredIngredients = holder?.GetDirectlyHeldThings();

            if (billGiver == null || building == null || billGiver == null || vatStoredIngredients == null)
            {
                return(null);
            }

            int storedCount           = vatStoredIngredients.FirstOrDefault(thing => thing.def == curIng.FixedIngredient)?.stackCount ?? 0;
            int countNeededFromRecipe = (int)(curIng.CountRequiredOfFor(curIng.FixedIngredient, theBill.recipe) *
                                              QEESettings.instance.organTotalResourcesFloat);

            int countNeededForCrafting = countNeededFromRecipe - storedCount;

            countNeededForCrafting = countNeededForCrafting < 0 ? 0 : countNeededForCrafting;

            //only check the map for Things if the vat still needs some of this ingredient
            if (countNeededForCrafting > 0)
            {
                //find the closest accessible Thing of that ThingDef on the map
                ThingRequest tRequest = ThingRequest.ForDef(curIng.FixedIngredient);

                IEnumerable <Thing> searchSet = billGiver.Map.listerThings.ThingsMatching(tRequest);
                Thing result = GenClosest.ClosestThing_Global(building.Position, searchSet,
                                                              validator :
                                                              delegate(Thing testThing)
                {
                    if (testThing.def.defName != curIng.FixedIngredient.defName)
                    {
                        return(false);
                    }

                    if (testThing.IsForbidden(building.Faction))
                    {
                        return(false);
                    }

                    return(true);
                });

                //return the Thing, if we found one
                if (result != null)
                {
                    //QEEMod.TryLog("Ingredient found: " + curIng.FixedIngredient.label + " | stackCount: " + result.stackCount + " | recipe: "
                    //    + countNeededFromRecipe);
                    return(result);
                }
            }

            return(null);
        } //end function FindClosestIngToBillGiver
        public IngredientCountWidget(IngredientCount ingredientCount)
        {
            this.uniqueId = uniqueCount;
            ++uniqueCount;

            this.IngredientCount = ingredientCount;

            this.filter = new ThingFilterWidget("Ingredient Filter", this.IngredientCount.filter);

            this.count = new FloatInputWidget <IngredientCount>(
                this.IngredientCount, "Ingredient Count", (ic) => IngredientCountStats.GetIngredientCount(ic), (ic, f) => IngredientCountStats.SetIngredientCount(ic, f));
        }
Beispiel #23
0
 public bool IsFixedOrAllowedIngredient(Thing thing)
 {
     for (int i = 0; i < recipe.ingredients.Count; i++)
     {
         IngredientCount ingredientCount = recipe.ingredients[i];
         if (ingredientCount.IsFixedIngredient && ingredientCount.filter.Allows(thing))
         {
             return(true);
         }
     }
     return(recipe.fixedIngredientFilter.Allows(thing) && ingredientFilter.Allows(thing));
 }
        public override string BillRequirementsDescription(RecipeDef r, IngredientCount ing)
        {
            foreach (ThingDef def in ing.filter.AllowedThingDefs)
            {
                if (def.IsNutritionGivingIngestible)
                {
                    return("BillRequiresNutrition".Translate((ing.GetBaseCount()), "") + " (" + ing.filter.Summary + ")");
                }
            }

            return("BillRequires".Translate((ing.GetBaseCount()), ing.filter.Summary));
        }
Beispiel #25
0
        private static RecipeDef MkNewRecipe(RecipeDef rd, int factor)
        {
            if (rd.ingredients.Count == 0 || rd.products.Count != 1)
            {
                return(null);
            }

            var r = new RecipeDef
            {
                defName                   = rd.defName + $"_{factor}x",
                label                     = rd.label + $" x{factor}",
                description               = rd.description + $" (x{factor})",
                jobString                 = rd.jobString,
                modContentPack            = rd.modContentPack,
                workSpeedStat             = rd.workSpeedStat,
                efficiencyStat            = rd.efficiencyStat,
                fixedIngredientFilter     = rd.fixedIngredientFilter,
                productHasIngredientStuff = rd.productHasIngredientStuff,
                workSkill                 = rd.workSkill,
                workSkillLearnFactor      = rd.workSkillLearnFactor,
                skillRequirements         = rd.skillRequirements.ListFullCopyOrNull(),
                recipeUsers               = rd.recipeUsers.ListFullCopyOrNull(),
                unfinishedThingDef        = null, //rd.unfinishedThingDef,
                effectWorking             = rd.effectWorking,
                soundWorking              = rd.soundWorking,
                allowMixingIngredients    = rd.allowMixingIngredients,
                defaultIngredientFilter   = rd.defaultIngredientFilter,
                researchPrerequisite      = rd.researchPrerequisite,
                factionPrerequisiteTags   = rd.factionPrerequisiteTags
            };

            r.products.Add(new ThingDefCountClass(rd.products[0].thingDef, rd.products[0].count * factor));
            var new_ingredients = new List <IngredientCount>();

            foreach (var oic in rd.ingredients)
            {
                var nic = new IngredientCount();
                nic.SetBaseCount(oic.GetBaseCount() * factor);
                nic.filter = oic.filter;
                new_ingredients.Add(nic);
            }

            r.ingredients = new_ingredients;
            r.workAmount  = rd.WorkAmountTotal(null) * factor;

            var IVGClass = (Type)Traverse.Create(rd).Field("ingredientValueGetterClass").GetValue();

            Traverse.Create(r).Field("ingredientValueGetterClass").SetValue(IVGClass);

            //if (rd.unfinishedThingDef != null)
            //    Log.Message(rd.label + " uses unfinishedThingDef " + rd.unfinishedThingDef.label+"  an it is removed");
            return(r);
        }
Beispiel #26
0
 public bool IsFixedOrAllowedIngredient(ThingDef def)
 {
     for (int i = 0; i < this.recipe.ingredients.Count; i++)
     {
         IngredientCount ingredientCount = this.recipe.ingredients[i];
         if (ingredientCount.IsFixedIngredient && ingredientCount.filter.Allows(def))
         {
             return(true);
         }
     }
     return(this.recipe.fixedIngredientFilter.Allows(def) && this.ingredientFilter.Allows(def));
 }
Beispiel #27
0
        private static bool TryFindBestBillIngredientsInSet_NoMix(List <Thing> availableThings, Building_CokeFurnace bill, List <ThingCount> chosen)
        {
            RecipeDef recipe = bill.SelectedRecipe;

            chosen.Clear();
            availableCounts.Clear();
            availableCounts.GenerateFrom(availableThings);
            for (int i = 0; i < ingredientsOrdered.Count; i++)
            {
                IngredientCount ingredientCount = recipe.ingredients[i];
                bool            flag            = false;
                for (int j = 0; j < availableCounts.Count; j++)
                {
                    float num = ingredientCount.CountRequiredOfFor(availableCounts.GetDef(j), bill.SelectedRecipe);
                    if (num > availableCounts.GetCount(j) || !ingredientCount.filter.Allows(availableCounts.GetDef(j)) || !ingredientCount.IsFixedIngredient)
                    {
                        continue;
                    }
                    for (int k = 0; k < availableThings.Count; k++)
                    {
                        if (availableThings[k].def != availableCounts.GetDef(j))
                        {
                            continue;
                        }
                        int num2 = availableThings[k].stackCount - ThingCountUtility.CountOf(chosen, availableThings[k]);
                        if (num2 > 0)
                        {
                            int num3 = Mathf.Min(Mathf.FloorToInt(num), num2);
                            ThingCountUtility.AddToList(chosen, availableThings[k], num3);

                            num -= (float)num3;
                            if (num < 0.001f)
                            {
                                flag = true;
                                float count = availableCounts.GetCount(j);
                                count -= (float)ingredientCount.CountRequiredOfFor(availableCounts.GetDef(j), bill.SelectedRecipe);
                                availableCounts.SetCount(j, count);
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
                if (!flag)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #28
0
        internal static bool TryFindBestMixInSet_NoMix(List <Thing> availableThings, Bill bill, List <ThingCount> chosen, List <IngredientCount> ingredientsOrdered)
        {
            var       availableCounts = new BMixDefCountList();
            RecipeDef recipe          = bill.recipe;

            chosen.Clear();
            availableCounts.Clear();
            availableCounts.GenerateFrom(availableThings);
            for (var i = 0; i < ingredientsOrdered.Count; i++)
            {
                IngredientCount ingredientCount = recipe.ingredients[i];
                var             flag            = false;
                for (var j = 0; j < availableCounts.Count; j++)
                {
                    float num = ingredientCount.CountRequiredOfFor(availableCounts.GetDef(j), bill.recipe);
                    if (num > availableCounts.GetCount(j) || !ingredientCount.filter.Allows(availableCounts.GetDef(j)) || (!ingredientCount.IsFixedIngredient && !bill.ingredientFilter.Allows(availableCounts.GetDef(j))))
                    {
                        continue;
                    }
                    for (var k = 0; k < availableThings.Count; k++)
                    {
                        if (availableThings[k].def != availableCounts.GetDef(j))
                        {
                            continue;
                        }
                        var num2 = availableThings[k].stackCount - ThingCountUtility.CountOf(chosen, availableThings[k]);
                        if (num2 > 0)
                        {
                            var num3 = Mathf.Min(Mathf.FloorToInt(num), num2);
                            ThingCountUtility.AddToList(chosen, availableThings[k], num3);
                            num -= (float)num3;
                            if (num < 0.001f)
                            {
                                flag = true;
                                var count = availableCounts.GetCount(j);
                                count -= (float)ingredientCount.CountRequiredOfFor(availableCounts.GetDef(j), bill.recipe);
                                availableCounts.SetCount(j, count);
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
                if (!flag)
                {
                    return(false);
                }
            }
            return(true);
        }
        // Will return null if recipe requires no components
        private RecipeDef TryMakeRecipeVariantWithSteel(RecipeDef recipeOriginal)
        {
            var recipeCopy = (RecipeDef)objectCloneMethod.Invoke(recipeOriginal, null);

            recipeCopy.shortHash = 0;
            InjectedDefHasher.GiveShortHasToDef(recipeCopy, typeof(RecipeDef));
            recipeCopy.defName += RemoteExplosivesUtility.InjectedRecipeNameSuffix;

            var newFixedFilter = new ThingFilter();

            foreach (var allowedThingDef in recipeOriginal.fixedIngredientFilter.AllowedThingDefs)
            {
                if (allowedThingDef == ThingDefOf.Component)
                {
                    continue;
                }
                newFixedFilter.SetAllow(allowedThingDef, true);
            }
            newFixedFilter.SetAllow(ThingDefOf.Steel, true);
            recipeCopy.fixedIngredientFilter   = newFixedFilter;
            recipeCopy.defaultIngredientFilter = null;

            float numComponentsRequired = 0;
            var   newIngredientList     = new List <IngredientCount>(recipeOriginal.ingredients);

            foreach (var ingredientCount in newIngredientList)
            {
                if (ingredientCount.filter.Allows(ThingDefOf.Component))
                {
                    numComponentsRequired = ingredientCount.GetBaseCount();
                    newIngredientList.Remove(ingredientCount);
                    break;
                }
            }
            if (numComponentsRequired == 0)
            {
                return(null);
            }

            var steelFilter = new ThingFilter();

            steelFilter.SetAllow(ThingDefOf.Steel, true);
            var steelIngredient = new IngredientCount {
                filter = steelFilter
            };

            steelIngredient.SetBaseCount(ComponentValueInSteel * numComponentsRequired);
            newIngredientList.Add(steelIngredient);
            recipeCopy.ingredients = newIngredientList;
            recipeCopy.ResolveReferences();
            return(recipeCopy);
        }
        public void AddItemToFurnace(Thing item)
        {
            if (ContainedResources.ContainsKey(item.def))
            {
                IngredientCount ingr = SelectedRecipe.ingredients.Where(x => x.FixedIngredient == item.def).FirstOrDefault();

                int remaining = (int)(ingr.GetBaseCount() * Multiplier) - ContainedResources[item.def];
                int toSplit   = Mathf.Min(item.stackCount, remaining);
                item.SplitOff(toSplit).Destroy();

                ContainedResources[item.def] += toSplit;
            }
        }
Beispiel #31
0
        public void SetupThingWithCompsSpawnVehicleDef()
        {
            foreach (ThingDef thingDef in DefDatabase<ThingDef>.AllDefs.Where(x => x.thingClass == System.Type.GetType("Vehicle")))
            {
                if (DefDatabase<ThingDef>.GetNamedSilentFail("Spawn" + thingDef.defName) != null)
                    continue;

                ThingWithCompsSpawnVehicleDef thingWithCompsSpawnVehicle = new ThingWithCompsSpawnVehicleDef();
                thingWithCompsSpawnVehicle.DefaultDef();

                thingWithCompsSpawnVehicle.defName = "Spawn" + thingDef.defName;
                if (DefDatabase<PawnKindDef>.GetNamed(thingDef.defName) != null)
                    thingWithCompsSpawnVehicle.spawnPawnDef = DefDatabase<PawnKindDef>.GetNamed(thingDef.defName);
                else
                    Log.Error(thingDef.defName + " doesn't have PawnKindDef");
                thingWithCompsSpawnVehicle.label = thingDef.label;
                thingWithCompsSpawnVehicle.description = thingDef.description;
                thingWithCompsSpawnVehicle.costStuffCount = thingDef.costStuffCount;
                if (thingDef.statBases.Find(x => x.stat == StatDefOf.WorkToMake) != null)
                    thingWithCompsSpawnVehicle.recipeMaker.workAmount = (int)thingDef.statBases.Find(x => x.stat == StatDefOf.WorkToMake).value;
                else
                {
                    Log.Error(thingDef.defName + " doesn't have WorkToMake value. Set 1000 default value");
                    thingWithCompsSpawnVehicle.recipeMaker.workAmount = 1000;
                }

                thingWithCompsSpawnVehicle.PostLoad();
                DefDatabase<ThingWithCompsSpawnVehicleDef>.Add(thingWithCompsSpawnVehicle);

                RecipeDef recipeDef = FullCopyRecipeDef(DefDatabase<RecipeDef>.GetNamed("Make_SpawnVehicleAbstract"));

                recipeDef.defName = "Make_" + "Spawn" + thingDef.defName;
                    string key1 = "RecipeMake";
                    object[] objArray1 = new object[1];
                    int index1 = 0;
                    string str1 = thingDef.label;
                    objArray1[index1] = (object) str1;
                    string str2 = Translator.Translate(key1, objArray1);
                recipeDef.label = str2;
                    string key2 = "RecipeMakeJobString";
                    object[] objArray2 = new object[1];
                    int index2 = 0;
                    string str3 = thingDef.label;
                    objArray2[index2] = (object) str3;
                    string str4 = Translator.Translate(key2, objArray2);
                recipeDef.jobString = str4;
                if (thingDef.MadeFromStuff)
                {
                    IngredientCount ingredientCount = new IngredientCount();
                    ingredientCount.SetBaseCount((float)thingDef.costStuffCount);
                    ingredientCount.filter.SetAllowAllWhoCanMake(thingDef);
                    recipeDef.ingredients.Add(ingredientCount);
                    recipeDef.fixedIngredientFilter.SetAllowAllWhoCanMake(thingDef);
                    recipeDef.productHasIngredientStuff = true;
                }
                recipeDef.products = new List<ThingCount>();
                recipeDef.products.Add(new ThingCount(thingDef, 1));
                ThingDef unfinishedVehicle = FullCopyUnfinishedThingDef(DefDatabase<ThingDef>.GetNamed("UnfinishedAbstract"));
                unfinishedVehicle.defName = "Unfinished" + thingDef.defName;
                unfinishedVehicle.graphicData.texPath = thingDef.graphicData.texPath;
                unfinishedVehicle.graphicData.graphicClass = thingDef.graphicData.graphicClass;
                unfinishedVehicle.graphicData.drawSize = thingDef.graphicData.drawSize;
                unfinishedVehicle.PostLoad();
                DefDatabase<ThingDef>.Add(unfinishedVehicle);
                recipeDef.unfinishedThingDef = unfinishedVehicle;

                recipeDef.PostLoad();
                DefDatabase<RecipeDef>.Add(recipeDef);
            }
        }
 private void MergeIngredientIntoFilter( ThingFilter filter, IngredientCount ingredient )
 {
     //Log.Message( string.Format( "{0}.CompHopperUser.MergeIngredientIntoFilter( ThingFilter, IngredientCount )", this.parent.ThingID ) );
     if( ingredient.filter != null )
     {
         if( !ingredient.filter.Categories().NullOrEmpty() )
         {
             foreach( var category in ingredient.filter.Categories() )
             {
                 var categoryDef = DefDatabase<ThingCategoryDef>.GetNamed( category, true );
                 filter.SetAllow( categoryDef, true );
             }
         }
         if( !ingredient.filter.ThingDefs().NullOrEmpty() )
         {
             foreach( var thingDef in ingredient.filter.ThingDefs() )
             {
                 filter.SetAllow( thingDef, true );
             }
         }
     }
 }
 private void MergeIngredientIntoHopperSettings( IngredientCount ingredient, RecipeDef recipe )
 {
     //Log.Message( string.Format( "{0}.CompHopperUser.MergeIngredientIntoHopperSettings( IngredientCount, {1} )", this.parent.ThingID, recipe == null ? "null" : recipe.defName ) );
     if( ingredient.filter != null )
     {
         if( !ingredient.filter.Categories().NullOrEmpty() )
         {
             foreach( var category in ingredient.filter.Categories() )
             {
                 var categoryDef = DefDatabase<ThingCategoryDef>.GetNamed( category, true );
                 HopperSettingsAmount.AddToList( hopperSettings, categoryDef, ingredient.GetBaseCount(), recipe );
             }
         }
         if( !ingredient.filter.ThingDefs().NullOrEmpty() )
         {
             foreach( var thingDef in ingredient.filter.ThingDefs() )
             {
                 HopperSettingsAmount.AddToList( hopperSettings, thingDef, ingredient.GetBaseCount(), recipe );
             }
         }
     }
 }
            public RecipeDef targetRecipe; // the parent recipe itself.

            #endregion Fields

            #region Constructors

            public IngredientSelector( Manager manager, IngredientCount ingredient, int count, RecipeDef targetRecipe )
            {
                // set up vars
                this.ingredient = ingredient;
                this.targetRecipe = targetRecipe;
                this.manager = manager;
                targetCount = (int) Math.Sqrt( count ) * (int) ingredient.GetBaseCount();
                allowedThingDefs = ingredient.filter.AllowedThingDefs.ToList();

                // if there's only one allowed we don't need to manually choose.
                if ( allowedThingDefs.Count == 1 )
                {
                    recipeSelector = new RecipeSelector( manager, allowedThingDefs.First(), targetCount );
                }
            }