CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.31k stars 4.14k forks source link

Vitamin RDA % is computed slightly incorrectly #74840

Open nornagon opened 3 months ago

nornagon commented 3 months ago

Describe the bug

For example, a hamburger is set in its JSON to have "vitamins": [ [ "calcium", 57 ], ... ], which appears to be intended to correspond to 57% of RDA. However, in-game it is shown as 56%. This seems to also affect the computed vitamin mass, which is listed as 563 µg instead of 570 µg which would be 57% of the 1000 mg RDA.

Attach save file

N/A

Steps to reproduce

  1. Open spawn item menu and find the hamburger

Expected behavior

Calcium RDA% should be 57% at 570 µg.

Screenshots

Screenshot 2024-06-29 at 19 57 06

Versions and configuration

Additional context

I believe this is due to an incorrect interpretation of the vitamin's weight_per_unit.

vitamin::RDA_to_default computes:

( 24_hours / rate_ ) * ( static_cast<float>( percent ) / 100.0f )

which, for [ "calcium", 57 ], gives 24 h / 15 m * ( 57 / 100 ) = 54.72

This is rounded to an int, giving 54.

then Character::vitamin_RDA reverses this lossily:

const double multiplier = vitamin_rate( vitamin ) / 1_days * 100;
return std::lround( amount * multiplier );

giving 15 m / 24 h 100 54 = 56.25, floored to 56%.

For vitamins given as integers in the JSON, they are round-tripped through this lossy conversion from %RDA to units and back, resulting in a value in-game which doesn't always match what's in the JSON.

Karol1223 commented 3 months ago

I believe this bug predates the current RDA weight support, unless this is somehow something different entirely. I think even back in 2022 we had reports of vitamins ingame being 1-unit smaller than JSON dictated.

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not bump or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.