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);
 }
Beispiel #2
0
        private Job TryStartNewDoBillJob(Pawn pawn, Bill bill, IBillGiver giver)
        {
            Job job = WorkGiverUtility.HaulStuffOffBillGiverJob(pawn, giver, null);

            if (job != null)
            {
                return(job);
            }
            Job job2 = new Job(JobDefOf.DoBill, (Thing)giver);

            job2.targetQueueB = new List <LocalTargetInfo>(this.chosenIngThings.Count);
            job2.countQueue   = new List <int>(this.chosenIngThings.Count);
            for (int i = 0; i < this.chosenIngThings.Count; i++)
            {
                List <LocalTargetInfo> targetQueueB = job2.targetQueueB;
                ThingAmount            thingAmount  = this.chosenIngThings[i];
                targetQueueB.Add(thingAmount.thing);
                List <int>  countQueue   = job2.countQueue;
                ThingAmount thingAmount2 = this.chosenIngThings[i];
                countQueue.Add(thingAmount2.count);
            }
            job2.haulMode = HaulMode.ToCellNonStorage;
            job2.bill     = bill;
            return(job2);
        }
        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);
        }
Beispiel #4
0
 public static void AddToList(List <ThingAmount> list, Thing thing, int countToAdd)
 {
     for (int i = 0; i < list.Count; i++)
     {
         if (list[i].thing == thing)
         {
             list[i] = new ThingAmount(list[i].thing, list[i].count + countToAdd);
             return;
         }
     }
     list.Add(new ThingAmount(thing, countToAdd));
 }
 public static int CountUsed(List <ThingAmount> list, Thing thing)
 {
     for (int i = 0; i < list.Count; i++)
     {
         ThingAmount thingAmount = list[i];
         if (thingAmount.thing == thing)
         {
             ThingAmount thingAmount2 = list[i];
             return(thingAmount2.count);
         }
     }
     return(0);
 }
 public static void AddToList(List <ThingAmount> list, Thing thing, int countToAdd)
 {
     for (int i = 0; i < list.Count; i++)
     {
         ThingAmount thingAmount = list[i];
         if (thingAmount.thing == thing)
         {
             int         index        = i;
             ThingAmount thingAmount2 = list[i];
             Thing       obj          = thingAmount2.thing;
             ThingAmount thingAmount3 = list[i];
             list[index] = new ThingAmount(obj, thingAmount3.count + countToAdd);
             return;
         }
     }
     list.Add(new ThingAmount(thing, countToAdd));
 }