Cooks use more ingredients than necessary depending on scan order

Started by Ospish, November 20, 2017, 01:40:00 PM

Previous topic - Next topic

Ospish

Hi to all.
I'm using the last RimWorld build v0.18.1722 and I'm not exactly sure if it's been posted already, but I saw a bug with cooking nutrition mathematics, which consists of pawns making inappropriate decisions while cooking simple meal with items counting 0.25 nutrition, like egg. Specifically, when I sent the pawn to cook, it first tried to cook 1 egg with 9 meat chunks. I saw it, and suspecting that as an inappropriate behaviour due to miscalculation, I gave him a second "Cook" command, executing which the pawn landed the corrrect 1 egg and 5 chunks.
Is that a bug? If so, please take a look.
P.S. I thank the RimWorld creators sincerely for their wonderful work.

asanbr


Razuhl

Its not a math problem. The algorithm works like this:
Find ingredients that are applicable to the recipe.
Order them by distance(closest first).
Select from the beginning until you have enough.

So after selecting 9 chunks it was missing 0.05 nutrition. The next best ingredient was an egg. The overflow is lost.

The method WorkGiver_DoBill.TryFindBestBillIngredientsInSet_AllowMix can easily be fixed by doing a pass over the "List<Thing_Amount> chosen" variable if the aggregated ingredient count is too far negative. The list must be ordered by the recipes IngredientValueGetter.ValuePerUnitOf, putting the biggest ingredients first and then dropping ingredients from beginning to end that do not tilt the ingredient count into the positive.

Ospish

#3
Well explained, thanks! I guess I made a mistake in topic name. Such game behavior doesn't look like logical though...

Razuhl

It certainly isn't what a player would expect based on what the game teaches. You might wan't to look at: https://ludeon.com/forums/index.php?topic=38051.0

Tynan

It's a tiny issue, but one with a clear solution, I think. As Raz said:

0 Make ingredients list as now
1 Sort ingredients big-to-small by nutrition
2 Drop ingredients from the end of the list as long as doing so doesn't reduce total nutrition under the requirement
Tynan Sylvester - @TynanSylvester - Tynan's Blog

Kenneth