Don't truncate allergy vitamins out of existence #78792
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
None
Purpose of change
#77825 (comment)
Describe the solution
Basically camps were doing
1 * some_double_less_than_one
and always receiving0
, because we truncated to integer. The truncation was intended, but this scenario was not anticipated when I wrote the operator, because we didn't have allergies as vitamins.So now the
*=
operator (double overload) always keeps at least 1 of existing vitamins, instead of fully truncating. For results greater than 1 (e.g. 1.1, or 62.7, or other numbers) it still truncates normally. The only reason for this is make sure we don't truncate allergies out of existence.This may slightly skew the resulting math, but only to a negligible degree.
This does not support being called on negative vitamin values, which are technically possible (via stored character values). The operator is only currently called for faction camps distributing food items, where I added it.
Because the math produced would be VERY, VERY wrong if negative values are used, I added an assertion that the stored value is not negative. The game will crash, loudly and pointedly, which should be sufficient to warn any C++ contributor who might use it in the future without considering this.
Describe alternatives you've considered
Require some minimum amount of allergy vitamin to avoid this pitfall, but that just papers over the problem. Besides we'll get more good PRs like #75918 (by @PatrikLundell ) who run into our bad math. Asking everyone to dodge around our bad math is not a solution.
Only keep 1 if the vitamin type is actually an allergy? We don't have such a clearly defined
vit_type
at the moment...Testing
Math checks out, I've gone over it several times.
I did not compile this branch.
Additional context