From de0f5940aa3755359ad770a39ef04712be95703d Mon Sep 17 00:00:00 2001 From: ZeroInternalReflection <89038572+ZeroInternalReflection@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:35:09 -0500 Subject: [PATCH] Move the ratio of tablets:water to json --- data/json/items/chemicals_and_resources.json | 4 +++- src/iuse.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/data/json/items/chemicals_and_resources.json b/data/json/items/chemicals_and_resources.json index 895309d9c65d4..148103eea5fc5 100644 --- a/data/json/items/chemicals_and_resources.json +++ b/data/json/items/chemicals_and_resources.json @@ -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", diff --git a/src/iuse.cpp b/src/iuse.cpp index d46cabda3b0a6..8fe991099aa6a 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -2532,8 +2532,14 @@ std::optional 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 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( 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 liquids = water->items_with( []( const item & it ) { return it.typeId() == itype_water;