Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-counting byproducts in batch food crafting #38127

Merged
merged 1 commit into from
Feb 18, 2020

Conversation

jkraybill
Copy link
Contributor

@jkraybill jkraybill commented Feb 18, 2020

Summary

SUMMARY: Bugfixes "Fix multi-counting byproducts in batch food crafting"

Purpose of change

Fixes #38071.

That bug was caused by byproducts of food crafting recipes getting progressively multi-counted when batch-crafting food that had variable calories and byproducts. This could lead to situations where you were crafting canned juice with negative calories.

As far as I can tell, this bug is currently confined to canned juice recipes but is theoretically possible in any food recipe with variable calories and byproducts, where the output is charge-based (e.g. a liquid in a can).

Describe the solution

There was a loop in complete_craft that was adding byproducts to the "used" list for every outputted item. So item 1 would have correct calorie counts, but every subsequent item had calories lower than it should by the previous total of the byproduct calories.

I fixed this by cloning the "used" list every time byproducts are calculated, so the byproducts did not accumulate.

Describe alternatives you've considered

There may be some more efficient way to achieve what I did without having to copy the used list every time.

Testing

Tested before and after crafting fruit juice, and calculated the caloric content expected. The result matched expected. Here's a screenshot from crafting 4 pear juice:

sc001342

Additional context

As with previous C++ commits from me, I'm extremely rusty in C++, so if someone has a better way to do this please let me know.

I was a little fearful at first that doing this may have unexpected consequences, like somewhere in the code that somehow expected the byproduct list to grow as items were produced, but after reviewing I don't believe that is the case. However it's possible I've missed some obscure annals of the code base.

@jkraybill
Copy link
Contributor Author

That test failure is a weapons failure... could it possibly have been caused by my commit?

@ifreund ifreund added <Bugfix> This is a fix for a bug (or closes open issue) Crafting / Construction / Recipes Includes: Uncrafting / Disassembling labels Feb 18, 2020
@ifreund
Copy link
Contributor

ifreund commented Feb 18, 2020

Don't think so, i just restarted the build. Code looks good to me, thanks for fixing this.

@ifreund ifreund added the [C++] Changes (can be) made in C++. Previously named `Code` label Feb 18, 2020
@KorGgenT KorGgenT merged commit 20342e9 into CleverRaven:master Feb 18, 2020
@jkraybill jkraybill deleted the 38071 branch March 1, 2020 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Crafting / Construction / Recipes Includes: Uncrafting / Disassembling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crafting canned juice yield's product with varying caloric and nutritional values.
3 participants