Exemplo n.º 1
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))
             {
                 if (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 <= 0.0001f)
                     {
                         break;
                     }
                 }
             }
         }
         if (num > 0.0001f)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 2
0
        private static bool TryFindBestBillIngredientsInSet_NoMix(List <Thing> availableThings, Bill bill, List <ThingAmount> 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 - ThingAmount.CountUsed(chosen, availableThings[k]);
                                        if (num2 > 0)
                                        {
                                            int num3 = Mathf.Min(Mathf.FloorToInt(num), num2);
                                            ThingAmount.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);
        }