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

Add NO_DISPLAY vitamin flag, show non-nutritional vitamins as 'Other contents' in food information menu #35942

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/json/vitamin.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"min": 0,
"max": 40,
"rate": "4 h",
"flags": [ "NO_DISPLAY" ],
"disease_excess": [ [ 10, 19 ], [ 20, 29 ], [ 30, 40 ] ]
}
]
12 changes: 11 additions & 1 deletion doc/VITAMIN.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## vitamin
# vitamin

## definition

```JSON
{
Expand All @@ -11,6 +13,7 @@
"min": -12000,
"max": 3600,
"rate": "15 m",
"flags": [ "FOO" ],
"disease": [ [ -4800, -5600 ], [ -5601, -6400 ], [ -6401, -12000 ] ],
"disease_excess": [ [ 10, 19 ], [ 20, 29 ], [ 30, 40 ] ]
},
Expand Down Expand Up @@ -55,6 +58,9 @@ The highest amount of this vitamin that the avatar can have.
### `rate`
How long it takes to lose one unit of this vitamin.

### `flags`
An array of string flags, see the flags section below for valid ones

### `disease`
What the thresholds of deficiency of this vitamin are.
Each pair in the list determines the start and end points of that tier of deficiency.
Expand All @@ -64,3 +70,7 @@ Each tier of deficiency corresponds to the intensity level of the effect defined
What the thresholds of excess of this vitamin are.
Each pair in the list determines the start and end points of that tier of excess.
Each tier of excess corresponds to the intensity level of the effect defined in `excess`.

## flags

- ```NO_DISPLAY``` - This vitamin will not be shown when examining a food
21 changes: 20 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,16 +1359,35 @@ void item::food_info( const item *food_item, std::vector<iteminfo> &info,
nutr.vitamins.end(),
[]( const std::pair<vitamin_id, int> &v ) {
// only display vitamins that we actually require
return ( g->u.vitamin_rate( v.first ) > 0_turns && v.second != 0 ) ?
return ( g->u.vitamin_rate( v.first ) > 0_turns && v.second != 0 &&
v.first->type() == vitamin_type::VITAMIN && !v.first->has_flag( "NO_DISPLAY" ) ) ?
string_format( "%s (%i%%)", v.first.obj().name(),
static_cast<int>( v.second * g->u.vitamin_rate( v.first ) /
1_days * 100 ) ) :
std::string();
} );

const std::string effect_vits = enumerate_as_string(
nutr.vitamins.begin(),
nutr.vitamins.end(),
[]( const std::pair<vitamin_id, int> &v ) {
// only display vitamins that we actually require
return ( g->u.vitamin_rate( v.first ) > 0_turns && v.second != 0 &&
v.first->type() != vitamin_type::VITAMIN && !v.first->has_flag( "NO_DISPLAY" ) ) ?
string_format( "%s (%i%%)", v.first.obj().name(),
static_cast<int>( v.second * g->u.vitamin_rate( v.first ) /
1_days * 100 ) ) :
std::string();
} );

if( !required_vits.empty() && parts->test( iteminfo_parts::FOOD_VITAMINS ) ) {
info.emplace_back( "FOOD", _( "Vitamins (RDA): " ), required_vits );
}

if( !effect_vits.empty() && parts->test( iteminfo_parts::FOOD_VIT_EFFECTS ) ) {
info.emplace_back( "FOOD", _( "Other contents: " ), effect_vits );
}

if( g->u.allergy_type( *food_item ) != morale_type( "morale_null" ) ) {
info.emplace_back( "DESCRIPTION",
_( "* This food will cause an <bad>allergic reaction</bad>." ) );
Expand Down
1 change: 1 addition & 0 deletions src/iteminfo_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum class iteminfo_parts : size_t {
FOOD_PORTIONS,
FOOD_SMELL,
FOOD_VITAMINS,
FOOD_VIT_EFFECTS,
FOOD_CANNIBALISM,
FOOD_TAINT,
FOOD_POISON,
Expand Down
4 changes: 4 additions & 0 deletions src/vitamin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ void vitamin::load_vitamin( const JsonObject &jo )
vit.disease_excess_.emplace_back( e.get_int( 0 ), e.get_int( 1 ) );
}

for( std::string e : jo.get_array( "flags" ) ) {
vit.flags_.insert( e );
}

if( vitamins_all.find( vit.id_ ) != vitamins_all.end() ) {
jo.throw_error( "parsed vitamin overwrites existing definition", "id" );
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/vitamin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <map>
#include <utility>
#include <vector>
#include <set>
#include <string>

#include "calendar.h"
Expand Down Expand Up @@ -48,6 +49,10 @@ class vitamin
return name_.translated();
}

bool has_flag( const std::string &flag ) const {
return flags_.count( flag ) > 0;
}

/** Disease effect with increasing intensity proportional to vitamin deficiency */
const efftype_id &deficiency() const {
return deficiency_;
Expand Down Expand Up @@ -102,6 +107,7 @@ class vitamin
time_duration rate_;
std::vector<std::pair<int, int>> disease_;
std::vector<std::pair<int, int>> disease_excess_;
std::set<std::string> flags_;
};

#endif