diff --git a/data/json/effects.json b/data/json/effects.json index d0aa1987f58c2..802c0c170a49d 100644 --- a/data/json/effects.json +++ b/data/json/effects.json @@ -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" }, diff --git a/data/json/vitamin.json b/data/json/vitamin.json index 57b4406c78130..4292260adc586 100644 --- a/data/json/vitamin.json +++ b/data/json/vitamin.json @@ -4,7 +4,10 @@ "type": "vitamin", "name": "Calcium", "min": -600, - "deficiency": [ [ "brittlebone", -300 ] ] + "deficiency": [ + [ -250, "brittlebone", 1 ], + [ -300, "brittlebone", 2 ] + ] }, { "id": "iron", @@ -12,8 +15,11 @@ "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", @@ -21,21 +27,30 @@ "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 ] + ] } ] diff --git a/src/consumption.cpp b/src/consumption.cpp index ac8c3e886919c..81bb853143bb8 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -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; diff --git a/src/vitamin.cpp b/src/vitamin.cpp index 5ba3f855cdeb1..a251e636a717d 100644 --- a/src/vitamin.cpp +++ b/src/vitamin.cpp @@ -24,19 +24,19 @@ const vitamin &string_id::obj() const return found->second; } -const efftype_id &vitamin::effect( int level ) const +const std::pair &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 null_effect = { NULL_ID, 1 }; return null_effect; } @@ -54,16 +54,25 @@ void vitamin::load_vitamin( JsonObject &jo ) jo.throw_error( "vitamin consumption rate cannot be negative", "rate" ); } + using disease = std::pair>; + 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" ); diff --git a/src/vitamin.h b/src/vitamin.h index b837192bfa938..736afa877eeaf 100644 --- a/src/vitamin.h +++ b/src/vitamin.h @@ -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 &effect( int level ) const; /** Load vitamin from JSON definition */ static void load_vitamin( JsonObject &jo ); @@ -61,8 +61,8 @@ class vitamin int min_; int max_; int rate_; - std::vector> deficiency_; - std::vector> excess_; + std::vector>> deficiency_; + std::vector>> excess_; }; #endif