Skip to content

Commit

Permalink
Move the ratio of tablets:water to json
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroInternalReflection committed Mar 1, 2024
1 parent 05949eb commit de0f594
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion data/json/items/chemicals_and_resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,9 @@
"price": "9 cent",
"price_postapoc": "20 cent",
"volume": "2 ml",
"flags": [ "NO_INGEST" ]
"flags": [ "NO_INGEST" ],
"//6": "The ratio of how much water can be purified per tablet (maximum). Should match the water_purifying recipe",
"variables": { "water_per_tablet": "4" }
},
{
"type": "GENERIC",
Expand Down
10 changes: 8 additions & 2 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2532,8 +2532,14 @@ std::optional<int> iuse::water_purifier( Character *p, item *it, const tripoint
// Part of iuse::water_tablets, but with the user interaction split out so it can be unit tested
std::optional<int> iuse::purify_water( Character *p, item *purifier, item_location &water )
{
// TODO: Find a way to move this to json:
const int max_water_per_tablet = 4;
const double default_ratio = 4; // Existing pur_tablets will not have the var
const int max_water_per_tablet = static_cast<int>( purifier->get_var( "water_per_tablet",
default_ratio ) );
if( max_water_per_tablet < 1 ) {
debugmsg( "ERROR: %s set to purify only %i water each. Nothing was purified.",
purifier->typeId().str(), max_water_per_tablet );
return std::nullopt;
}

const std::vector<item *> liquids = water->items_with( []( const item & it ) {
return it.typeId() == itype_water;
Expand Down

0 comments on commit de0f594

Please sign in to comment.