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 support for intensity to vitamin deficiencies [WIP] #16402

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 25 additions & 15 deletions data/json/effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -1518,45 +1518,55 @@
{
"type": "effect_type",
"id": "brittlebone",
"name": [ "Brittle bones" ],
"desc": [ "A lack of calcium in your diet has made your bones brittle." ],
"apply_message": "Your bones have become brittle.",
"max_intensity": 2,
"name": [ "Hypocalcaemia", "Brittle bones" ],
"desc": [ "A lack of calcium in your diet will make your bones progressively weaker." ],
"apply_message": "Your bones are becoming more brittle.",
"decay_messages": [ [ "Your calcium deficiency is starting to resolve.", "good" ] ],
"remove_message": "Your bones regain their usual strength.",
"rating": "bad"
},
{
"type": "effect_type",
"id": "anemia",
"name": [ "Anemia" ],
"desc": [ "A lack of iron in your diet has made you anemic." ],
"apply_message": "You feel tired and listless.",
"max_intensity": 2,
"name": [ "Iron deficiency", "Anemia" ],
"desc": [ "A lack of iron in your diet will result in progressively worsening anemia." ],
"apply_message": "You beging feeling increasingly tired and listless.",
"decay_messages": [ [ "Your iron deficiency is starting to resolve.", "good" ] ],
"remove_message": "You no longer feel anemic.",
"rating": "bad"
},
{
"type": "effect_type",
"id": "nightblind",
"name": [ "Night blindness" ],
"desc": [ "A lack of vitamin A in your diet has affected your vision." ],
"apply_message": "You struggle to make out the finer details.",
"max_intensity": 2,
"name": [ "Poor vision", "Night blindness" ],
"desc": [ "A lack of vitamin A in your diet will progressively worsen your vision." ],
"apply_message": "You beging struggling to make out the finer details.",
"decay_messages": [ [ "Your vitamin A deficiency is starting to resolve.", "good" ] ],
"remove_message": "Your normal visual accuity returns.",
"rating": "bad"
},
{
"type": "effect_type",
"id": "slowheal",
"name": [ "Slow healing" ],
"desc": [ "A lack of vitamin B12 in your diet has affected your ability to heal." ],
"apply_message": "Simple wounds concern you more than usual.",
"max_intensity": 2,
"name": [ "B12 deficiency", "Slow healing" ],
"desc": [ "A lack of vitamin B12 in your diet will affect your ability to heal." ],
"apply_message": "Simple wounds are starting to concern you more than usual.",
"decay_messages": [ [ "Your vitamin B12 deficiency is starting to resolve.", "good" ] ],
"remove_message": "Your wounds now heal normally.",
"rating": "bad"
},
{
"type": "effect_type",
"id": "scurvy",
"name": [ "Scurvy" ],
"desc": [ "A lack of vitamin C in your diet has resulted in you developing scurvy." ],
"apply_message": "You have contracted scurvy.",
"max_intensity": 2,
"name": [ "Early scurvy", "Scurvy" ],
"desc": [ "A lack of vitamin C in your diet will result in progressively worse symptoms of scurvy." ],
"apply_message": "You start to develop symptoms of scurvy.",
"decay_messages": [ [ "Your vitamin C deficiency is starting to resolve.", "good" ] ],
"remove_message": "Your scurvy has resolved.",
"rating": "bad"
},
Expand Down
29 changes: 22 additions & 7 deletions data/json/vitamin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,53 @@
"type": "vitamin",
"name": "Calcium",
"min": -600,
"deficiency": [ [ "brittlebone", -300 ] ]
"deficiency": [
[ -250, "brittlebone", 1 ],
[ -300, "brittlebone", 2 ]
]
},
{
"id": "iron",
"type": "vitamin",
"name": "Iron",
"min": -600,
"max": 200,
"deficiency": [ [ "anemia", -300 ] ],
"excess": [ [ "hypervitaminosis", 100 ] ]
"deficiency": [
[ -250, "anemia", 1 ],
[ -300, "anemia", 2 ]
],
"excess": [ [ 100, "hypervitaminosis", 1 ] ]
},
{
"id": "vitA",
"type": "vitamin",
"name": "Vitamin A",
"min": -200,
"max": 200,
"deficiency": [ [ "nightblind", -100 ] ],
"excess": [ [ "hypervitaminosis", 100 ] ]
"deficiency": [
[ -100, "nightblind", 1 ],
[ -150, "nightblind", 2 ]
],
"excess": [ [ 100, "hypervitaminosis", 1 ] ]
},
{
"id": "vitB",
"type": "vitamin",
"name": "Vitamin B12",
"min": -200,
"deficiency": [ [ "slowheal", -100 ] ]
"deficiency": [
[ -100, "slowheal", 1 ],
[ -150, "slowheal", 2 ]
]
},
{
"id": "vitC",
"type": "vitamin",
"name": "Vitamin C",
"min": -200,
"deficiency": [ [ "scurvy", -100 ] ]
"deficiency": [
[ -100, "scurvy", 1 ],
[ -150, "scurvy", 2 ]
]
}
]
5 changes: 3 additions & 2 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ int player::vitamin_mod( const vitamin_id &vit, int qty, bool capped )
}

auto eff = v.effect( it->second );
if( !eff.is_null() ) {
if( !eff.first.is_null() ) {
// consumption rate may vary so extend effect until next check due for this vitamin
add_effect( eff, ( std::abs( vitamin_rate( vit ) ) * MINUTES( 1 ) ) - get_effect_dur( eff ) + 1 );
add_effect( eff.first, ( std::abs( vitamin_rate( vit ) ) * MINUTES( 1 ) ) - get_effect_dur( eff.first ) + 1,
num_bp, false, eff.second );
}

return it->second;
Expand Down
25 changes: 17 additions & 8 deletions src/vitamin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ const vitamin &string_id<vitamin>::obj() const
return found->second;
}

const efftype_id &vitamin::effect( int level ) const
const std::pair<efftype_id, int> &vitamin::effect( int level ) const
{
for( const auto &e : deficiency_ ) {
if( level <= e.second ) {
return e.first;
if( level <= e.first ) {
return e.second;
}
}
for( const auto &e : excess_ ) {
if( level >= e.second ) {
return e.first;
if( level >= e.first ) {
return e.second;
}
}
static efftype_id null_effect = NULL_ID;
static std::pair<efftype_id, int> null_effect = { NULL_ID, 1 };
return null_effect;
}

Expand All @@ -54,16 +54,25 @@ void vitamin::load_vitamin( JsonObject &jo )
jo.throw_error( "vitamin consumption rate cannot be negative", "rate" );
}

using disease = std::pair<int, std::pair<efftype_id, int>>;

auto def = jo.get_array( "deficiency" );
while( def.has_more() ) {
auto e = def.next_array();
vit.deficiency_.emplace_back( efftype_id( e.get_string( 0 ) ), e.get_int( 1 ) );
vit.deficiency_.emplace_back( e.get_int( 0 ),
std::make_pair( efftype_id( e.get_string( 1 ) ), e.get_int( 2 ) ) );
}
std::sort( vit.deficiency_.begin(), vit.deficiency_.end(),
[]( const disease& lhs, const disease& rhs ) { return lhs.first < rhs.first; } );

auto exc = jo.get_array( "excess" );
while( exc.has_more() ) {
auto e = exc.next_array();
vit.excess_.emplace_back( efftype_id( e.get_string( 0 ) ), e.get_int( 1 ) );
vit.excess_.emplace_back( e.get_int( 0 ),
std::make_pair( efftype_id( e.get_string( 1 ) ), e.get_int( 2 ) ) );
}
std::sort( vit.excess_.rbegin(), vit.excess_.rend(),
[]( const disease& lhs, const disease& rhs ) { return lhs.first < rhs.first; } );

if( vitamins_all.find( vit.id_ ) != vitamins_all.end() ) {
jo.throw_error( "parsed vitamin overwrites existing definition", "id" );
Expand Down
8 changes: 4 additions & 4 deletions src/vitamin.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class vitamin
return rate_;
}

/** Get applicable status effect (if any) at @ref level */
const efftype_id &effect( int level ) const;
/** Get applicable status effect and intensity (if any) at @ref level */
const std::pair<efftype_id, int> &effect( int level ) const;

/** Load vitamin from JSON definition */
static void load_vitamin( JsonObject &jo );
Expand All @@ -61,8 +61,8 @@ class vitamin
int min_;
int max_;
int rate_;
std::vector<std::pair<efftype_id, int>> deficiency_;
std::vector<std::pair<efftype_id, int>> excess_;
std::vector<std::pair<int, std::pair<efftype_id, int>>> deficiency_;
std::vector<std::pair<int, std::pair<efftype_id, int>>> excess_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look very alike in every aspect. Could they be replaced with a single vector having values below/above zero to represent deficiency/excess respectively (as it is now)? This would prevent duplication.

};

#endif