From 2628ca17f99fb9631db146da67d1ba62186457bd Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Tue, 3 Dec 2019 19:23:41 +0100 Subject: [PATCH 01/13] disease_type infrastructure --- src/disease.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/disease.h | 23 +++++++++++++++++++++++ src/init.cpp | 3 +++ src/type_id.h | 3 +++ 4 files changed, 77 insertions(+) create mode 100644 src/disease.cpp create mode 100644 src/disease.h diff --git a/src/disease.cpp b/src/disease.cpp new file mode 100644 index 0000000000000..fb58f34330f18 --- /dev/null +++ b/src/disease.cpp @@ -0,0 +1,48 @@ +#include "disease.h" + +#include "assign.h" +#include "generic_factory.h" + +namespace +{ +generic_factory disease_factory( "disease_type" ); +} // namespace + +template<> +const disease_type &string_id::obj() const +{ + return disease_factory.obj( *this ); +} + +template<> +bool string_id::is_valid() const +{ + return disease_factory.is_valid( *this ); +} + +void disease_type::load_disease_type( JsonObject &jo, const std::string &src ) +{ + disease_factory.load( jo, src ); +} + +void disease_type::load( JsonObject &jo, const std::string & ) +{ + assign( jo, "id", id ); + assign( jo, "symptoms", symptoms ); +} + +const std::vector &disease_type::get_all() +{ + return disease_factory.get_all(); +} + +void disease_type::check_disease_consistency() +{ + for( const disease_type &dis : get_all() ) { + const efftype_id symp = dis.symptoms; + if( !symp.is_valid() ) { + debugmsg( "disease_type %s has invalid efftype_id %s in symptoms", dis.id.c_str(), symp.c_str() ); + } + } +} + diff --git a/src/disease.h b/src/disease.h new file mode 100644 index 0000000000000..b1dd18043c696 --- /dev/null +++ b/src/disease.h @@ -0,0 +1,23 @@ +#pragma once +#ifndef DISEASE_H +#define DISEASE_H + +#include "effect.h" +#include "type_id.h" +#include "json.h" + +class disease_type +{ + public: + static void load_disease_type( JsonObject &jo, const std::string &src ); + void load( JsonObject &jo, const std::string & ); + static const std::vector &get_all(); + static void check_disease_consistency(); + bool was_loaded; + + diseasetype_id id; + efftype_id symptoms; + +}; +#endif + diff --git a/src/init.cpp b/src/init.cpp index fb4592ad3f5d5..b065bb9feb222 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -21,6 +21,7 @@ #include "creature.h" #include "debug.h" #include "dialogue.h" +#include "disease.h" #include "effect.h" #include "emit.h" #include "event_statistics.h" @@ -215,6 +216,7 @@ void DynamicDataLoader::initialize() add( "enchantment", &enchantment::load_enchantment ); add( "hit_range", &Creature::load_hit_range ); add( "scent_type", &scent_type::load_scent_type ); + add( "disease_type", &disease_type::load_disease_type ); // json/colors.json would be listed here, but it's loaded before the others (see init_colors()) // Non Static Function Access @@ -685,6 +687,7 @@ void DynamicDataLoader::check_consistency( loading_ui &ui ) { _( "Transformations" ), &event_transformation::check_consistency }, { _( "Statistics" ), &event_statistic::check_consistency }, { _( "Scent types" ), &scent_type::check_scent_consistency }, + { _( "Disease types" ), &disease_type::check_disease_consistency }, { _( "Scores" ), &score::check_consistency } } }; diff --git a/src/type_id.h b/src/type_id.h index 09deb42cf8013..be8e5029b8741 100644 --- a/src/type_id.h +++ b/src/type_id.h @@ -23,6 +23,9 @@ using efftype_id = string_id; class scent_type; using scenttype_id = string_id; +class disease_type; +using diseasetype_id = string_id; + class emit; using emit_id = string_id; From 50f96931534c958f14f4df517f50828520d3544c Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Tue, 3 Dec 2019 22:32:17 +0100 Subject: [PATCH 02/13] more infrastructure --- src/disease.cpp | 22 ++++++++++++++++++---- src/disease.h | 9 ++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/disease.cpp b/src/disease.cpp index fb58f34330f18..6188f86a8fe72 100644 --- a/src/disease.cpp +++ b/src/disease.cpp @@ -27,8 +27,20 @@ void disease_type::load_disease_type( JsonObject &jo, const std::string &src ) void disease_type::load( JsonObject &jo, const std::string & ) { + disease_type new_disease; + assign( jo, "id", id ); - assign( jo, "symptoms", symptoms ); + assign( jo, "min_duration", min_duration ); + assign( jo, "max_duration", max_duration ); + assign( jo, "min_intensity", min_intensity ); + assign( jo, "max_intensity", max_intensity ); + assign( jo, "health_threshold", health_threshold ); + + JsonArray jsr = jo.get_array( "symptoms" ); + while( jsr.has_more() ) { + new_disease.symptoms.emplace( jsr.next_string() ); + } + } const std::vector &disease_type::get_all() @@ -39,9 +51,11 @@ const std::vector &disease_type::get_all() void disease_type::check_disease_consistency() { for( const disease_type &dis : get_all() ) { - const efftype_id symp = dis.symptoms; - if( !symp.is_valid() ) { - debugmsg( "disease_type %s has invalid efftype_id %s in symptoms", dis.id.c_str(), symp.c_str() ); + const std::set &symps = dis.symptoms; + for( const efftype_id symp : symps ) { + if( !symp.is_valid() ) { + debugmsg( "disease_type %s has invalid efftype_id %s in symptoms", dis.id.c_str(), symp.c_str() ); + } } } } diff --git a/src/disease.h b/src/disease.h index b1dd18043c696..8bd5e380daa85 100644 --- a/src/disease.h +++ b/src/disease.h @@ -16,7 +16,14 @@ class disease_type bool was_loaded; diseasetype_id id; - efftype_id symptoms; + time_duration min_duration; + time_duration max_duration; + int min_intensity; + int max_intensity; + /**If not empty this sets the health threshold above which you're immune to the disease*/ + cata::optional health_threshold; + /**effects applied by this disease*/ + std::set symptoms; }; #endif From 725d63489c7b56f56a4c7f5d8c8944c5078a3122 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Tue, 3 Dec 2019 23:22:10 +0100 Subject: [PATCH 03/13] affected_bodyparts --- src/disease.cpp | 13 ++++++------- src/disease.h | 15 +++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/disease.cpp b/src/disease.cpp index 6188f86a8fe72..46bfe589cc1f3 100644 --- a/src/disease.cpp +++ b/src/disease.cpp @@ -35,10 +35,11 @@ void disease_type::load( JsonObject &jo, const std::string & ) assign( jo, "min_intensity", min_intensity ); assign( jo, "max_intensity", max_intensity ); assign( jo, "health_threshold", health_threshold ); + assign( jo, "symptoms", symptoms ); - JsonArray jsr = jo.get_array( "symptoms" ); + JsonArray jsr = jo.get_array( "affected_bodyparts" ); while( jsr.has_more() ) { - new_disease.symptoms.emplace( jsr.next_string() ); + new_disease.affected_bodyparts.emplace( get_body_part_token( jsr.next_string() ) ); } } @@ -51,11 +52,9 @@ const std::vector &disease_type::get_all() void disease_type::check_disease_consistency() { for( const disease_type &dis : get_all() ) { - const std::set &symps = dis.symptoms; - for( const efftype_id symp : symps ) { - if( !symp.is_valid() ) { - debugmsg( "disease_type %s has invalid efftype_id %s in symptoms", dis.id.c_str(), symp.c_str() ); - } + const efftype_id &symp = dis.symptoms; + if( !symp.is_valid() ) { + debugmsg( "disease_type %s has invalid efftype_id %s in symptoms", dis.id.c_str(), symp.c_str() ); } } } diff --git a/src/disease.h b/src/disease.h index 8bd5e380daa85..ca749d9b4774a 100644 --- a/src/disease.h +++ b/src/disease.h @@ -2,6 +2,7 @@ #ifndef DISEASE_H #define DISEASE_H +#include "bodypart.h" #include "effect.h" #include "type_id.h" #include "json.h" @@ -16,14 +17,16 @@ class disease_type bool was_loaded; diseasetype_id id; - time_duration min_duration; - time_duration max_duration; - int min_intensity; - int max_intensity; + time_duration min_duration = 1_turns; + time_duration max_duration = 1_turns; + int min_intensity = 1; + int max_intensity = 1; + /**Affected body parts*/ + std::set affected_bodyparts; /**If not empty this sets the health threshold above which you're immune to the disease*/ cata::optional health_threshold; - /**effects applied by this disease*/ - std::set symptoms; + /**effect applied by this disease*/ + efftype_id symptoms; }; #endif From b77c5024f3cd5f3925bb2403aa4e3194deb3cdcf Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Tue, 3 Dec 2019 23:22:32 +0100 Subject: [PATCH 04/13] expose_to_disease() --- src/character.cpp | 19 +++++++++++++++++++ src/character.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/src/character.cpp b/src/character.cpp index 06eadef24d4c1..aae90cf4fce7f 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -1017,6 +1017,25 @@ void Character::add_effect( const efftype_id &eff_id, const time_duration dur, b Creature::add_effect( eff_id, dur, bp, permanent, intensity, force, deferred ); } +void Character::expose_to_disease( const diseasetype_id dis_type ) +{ + const cata::optional &healt_thresh = dis_type->health_threshold; + if( healt_thresh && healt_thresh.value() < get_healthy() ) { + return; + } + const std::set &bps = dis_type->affected_bodyparts; + if( !bps.empty() ) { + for( const body_part &bp : bps ) { + add_effect( dis_type->symptoms, rng( dis_type->min_duration, dis_type->max_duration ), bp, false, + rng( dis_type->min_intensity, dis_type->max_intensity ) ); + } + } else { + add_effect( dis_type->symptoms, rng( dis_type->min_duration, dis_type->max_duration ), num_bp, + false, + rng( dis_type->min_intensity, dis_type->max_intensity ) ); + } +} + void Character::process_turn() { for( auto &i : *my_bionics ) { diff --git a/src/character.h b/src/character.h index 5bc38b28ddddd..0ed7dcf2f87d7 100644 --- a/src/character.h +++ b/src/character.h @@ -21,6 +21,7 @@ #include "character_id.h" #include "character_martial_arts.h" #include "creature.h" +#include "disease.h" #include "game_constants.h" #include "inventory.h" #include "pimpl.h" @@ -442,6 +443,9 @@ class Character : public Creature, public visitable void add_effect( const efftype_id &eff_id, time_duration dur, body_part bp = num_bp, bool permanent = false, int intensity = 0, bool force = false, bool deferred = false ) override; + + /**Determine if character is susceptible to dis_type and if so apply the symptoms*/ + void expose_to_disease( const diseasetype_id dis_type ); /** * Handles end-of-turn processing. */ From f4d0a741f8b2f4bd86fae8e9134bbefbd01b52fe Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Tue, 3 Dec 2019 23:31:01 +0100 Subject: [PATCH 05/13] foodborne diseases --- src/consumption.cpp | 6 ++++++ src/itype.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/consumption.cpp b/src/consumption.cpp index 17299487e695b..ea35d01a7fce8 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -949,6 +949,12 @@ bool player::eat( item &food, bool force ) } } + for( const auto &elem : food.get_comestible()->contamination ) { + if( rng( 1, 100 ) <= elem.second ) { + expose_to_disease( elem.first ); + } + } + if( will_vomit ) { vomit(); } diff --git a/src/itype.h b/src/itype.h index 2cd3bbc2371d6..c035b5ccc74d6 100644 --- a/src/itype.h +++ b/src/itype.h @@ -149,6 +149,9 @@ struct islot_comestible { /** chance (odds) of becoming parasitised when eating (zero if never occurs) */ int parasites = 0; + /**List of diseases carried by this comestible and their associated probability*/ + std::map contamination; + /** freezing point in degrees Fahrenheit, below this temperature item can freeze */ int freeze_point = temperatures::freezing; From 6d5d778b917bc8a7eeb7b8c473f5f89135ac391d Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Mon, 23 Mar 2020 23:03:18 +0100 Subject: [PATCH 06/13] get it to compile --- src/consumption.cpp | 2 +- src/disease.cpp | 4 ++-- src/disease.h | 4 ++-- src/item_factory.cpp | 11 ++++++++++- src/itype.h | 5 +---- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/consumption.cpp b/src/consumption.cpp index f1c0f4370b470..d7a7af3fbd6d2 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1001,7 +1001,7 @@ bool player::eat( item &food, bool force ) } } - for( const auto &elem : food.get_comestible()->contamination ) { + for( const auto &elem : food.get_comestible()->foodborne_diseases ) { if( rng( 1, 100 ) <= elem.second ) { expose_to_disease( elem.first ); } diff --git a/src/disease.cpp b/src/disease.cpp index 46bfe589cc1f3..e728bd8fa7ed1 100644 --- a/src/disease.cpp +++ b/src/disease.cpp @@ -20,12 +20,12 @@ bool string_id::is_valid() const return disease_factory.is_valid( *this ); } -void disease_type::load_disease_type( JsonObject &jo, const std::string &src ) +void disease_type::load_disease_type( const JsonObject &jo, const std::string &src ) { disease_factory.load( jo, src ); } -void disease_type::load( JsonObject &jo, const std::string & ) +void disease_type::load( const JsonObject &jo, const std::string & ) { disease_type new_disease; diff --git a/src/disease.h b/src/disease.h index ca749d9b4774a..aa8b474182b1b 100644 --- a/src/disease.h +++ b/src/disease.h @@ -10,8 +10,8 @@ class disease_type { public: - static void load_disease_type( JsonObject &jo, const std::string &src ); - void load( JsonObject &jo, const std::string & ); + static void load_disease_type( const JsonObject &jo, const std::string &src ); + void load( const JsonObject &jo, const std::string & ); static const std::vector &get_all(); static void check_disease_consistency(); bool was_loaded; diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 8e6e30e0b467d..11f55ba00de32 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -514,6 +514,12 @@ void Item_factory::finalize_post( itype &obj ) } } + for( const std::pair elem : obj.comestible->foodborne_diseases ) { + if( !elem.first.is_valid() ) { + debugmsg( "foodborne_diseases in %s contains invalid diseasetype_id.", obj.id ); + } + } + for( std::string &line : obj.ascii_picture ) { if( utf8_width( remove_color_tags( line ) ) > ascii_art_width ) { line = trim_by_length( line, ascii_art_width ); @@ -1835,12 +1841,15 @@ void Item_factory::load( islot_comestible &slot, const JsonObject &jo, const std assign( jo, "stim", slot.stim, strict ); assign( jo, "healthy", slot.healthy, strict ); assign( jo, "parasites", slot.parasites, strict, 0 ); - assign( jo, "contamination", slot.contamination, strict, 0, 100 ); assign( jo, "freezing_point", slot.freeze_point, strict ); assign( jo, "spoils_in", slot.spoils, strict, 1_hours ); assign( jo, "cooks_like", slot.cooks_like, strict ); assign( jo, "smoking_result", slot.smoking_result, strict ); + for( JsonArray ja : jo.get_array( "foodborne diseases" ) ) { + slot.foodborne_diseases.emplace( diseasetype_id( ja.get_string( 0 ) ), ja.get_int( 1 ) ); + } + bool is_junkfood = false; if( jo.has_member( "primary_material" ) ) { std::string mat = jo.get_string( "primary_material" ); diff --git a/src/itype.h b/src/itype.h index 9483dbf4da6f8..dd98516ab9a99 100644 --- a/src/itype.h +++ b/src/itype.h @@ -152,14 +152,11 @@ struct islot_comestible { /** chance (odds) of becoming parasitised when eating (zero if never occurs) */ int parasites = 0; - /** probability [0, 100] to get food poisoning from this comestible */ - int contamination = 0; - /** freezing point in degrees Fahrenheit, below this temperature item can freeze */ int freeze_point = temperatures::freezing; /**List of diseases carried by this comestible and their associated probability*/ - std::map contamination; + std::map foodborne_diseases; //** specific heats in J/(g K) and latent heat in J/g */ float specific_heat_liquid = 4.186; From 864d773e828c5e0f6aec221ddf9808595b900091 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Mon, 23 Mar 2020 23:03:49 +0100 Subject: [PATCH 07/13] doc first part --- doc/JSON_INFO.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 9546097953799..2f3e3077d183f 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -19,6 +19,7 @@ Use the `Home` key to return to the top. * [`data/json/` JSONs](#datajson-jsons) + [Bionics](#bionics) + [Dreams](#dreams) + + [Disease](#disease_type) + [Item Groups](#item-groups) + [Item Category](#item-category) + [Materials](#materials) @@ -188,6 +189,7 @@ Here's a quick summary of what each of the JSON files contain, broken down by fo | default_blacklist.json | a standard blacklist of joke monsters | doll_speech.json | talk doll speech messages | dreams.json | dream text and linked mutation categories +| disease.json | desease definitions | effects.json | common effects and their effects | emit.json | smoke and gas emissions | flags.json | common flags and their descriptions @@ -457,6 +459,26 @@ When adding a new bionic, if it's not included with another one, you must also a } ``` +### Disease + +| Identifier | Description +|--- |--- +| id | Unique ID. Must be one continuous word, use underscores if necessary. +| min_duration | The minimum duration the disease can last. Uses strings "x m", "x s","x d". +| max_duration | The maximum duration the disease can last. +| min_intensity | The minimum intensity of the effect applied by the disease +| max_intensity | The maximum intensity of the effect. +| health_threshold | The amount of health above which one is immune to the disease. +| symptopms | The effect applied by the disease. +| affected_bodyparts | The list of bodyparts on which the effect is applied. + + +```json +{ + +} +``` + ### Item Groups Item groups have been expanded, look at [the detailed docs](ITEM_SPAWN.md) to their new description. From 35bff8716286eb68afe33838cf376dab3c2164ec Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Tue, 24 Mar 2020 12:04:13 +0100 Subject: [PATCH 08/13] fixes --- src/consumption.cpp | 2 +- src/item_factory.cpp | 14 ++++++++------ src/itype.h | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/consumption.cpp b/src/consumption.cpp index d7a7af3fbd6d2..6dda6118a1054 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1001,7 +1001,7 @@ bool player::eat( item &food, bool force ) } } - for( const auto &elem : food.get_comestible()->foodborne_diseases ) { + for( const std::pair &elem : food.get_comestible()->contamination ) { if( rng( 1, 100 ) <= elem.second ) { expose_to_disease( elem.first ); } diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 11f55ba00de32..8067e00ff62fd 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -514,12 +514,14 @@ void Item_factory::finalize_post( itype &obj ) } } - for( const std::pair elem : obj.comestible->foodborne_diseases ) { - if( !elem.first.is_valid() ) { - debugmsg( "foodborne_diseases in %s contains invalid diseasetype_id.", obj.id ); + if( obj.comestible ) { + for( const std::pair elem : obj.comestible->contamination ) { + const diseasetype_id dtype = elem.first; + if( !dtype.is_valid() ) { + debugmsg( "contamination in %s contains invalid diseasetype_id %s.", obj.id, dtype.c_str() ); + } } } - for( std::string &line : obj.ascii_picture ) { if( utf8_width( remove_color_tags( line ) ) > ascii_art_width ) { line = trim_by_length( line, ascii_art_width ); @@ -1846,8 +1848,8 @@ void Item_factory::load( islot_comestible &slot, const JsonObject &jo, const std assign( jo, "cooks_like", slot.cooks_like, strict ); assign( jo, "smoking_result", slot.smoking_result, strict ); - for( JsonArray ja : jo.get_array( "foodborne diseases" ) ) { - slot.foodborne_diseases.emplace( diseasetype_id( ja.get_string( 0 ) ), ja.get_int( 1 ) ); + for( JsonArray ja : jo.get_array( "contamination" ) ) { + slot.contamination.emplace( diseasetype_id( ja.get_string( 0 ) ), ja.get_int( 1 ) ); } bool is_junkfood = false; diff --git a/src/itype.h b/src/itype.h index dd98516ab9a99..c041ccbfb994e 100644 --- a/src/itype.h +++ b/src/itype.h @@ -156,7 +156,7 @@ struct islot_comestible { int freeze_point = temperatures::freezing; /**List of diseases carried by this comestible and their associated probability*/ - std::map foodborne_diseases; + std::map contamination; //** specific heats in J/(g K) and latent heat in J/g */ float specific_heat_liquid = 4.186; From 0f65153fee62328abad2236243615335a1df675d Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Tue, 24 Mar 2020 12:04:35 +0100 Subject: [PATCH 09/13] doc and json --- data/json/disease.json | 12 ++++++++++++ data/json/items/comestibles/dairy.json | 2 +- doc/JSON_INFO.md | 22 +++++++++++++++------- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 data/json/disease.json diff --git a/data/json/disease.json b/data/json/disease.json new file mode 100644 index 0000000000000..d7434b8ae333a --- /dev/null +++ b/data/json/disease.json @@ -0,0 +1,12 @@ +[ + { + "type": "disease_type", + "id": "bad_food", + "min_duration": "6 m", + "max_duration": "1 h", + "min_intensity": 1, + "max_intensity": 1, + "health_threshold": 100, + "symptoms": "foodpoison" + } +] diff --git a/data/json/items/comestibles/dairy.json b/data/json/items/comestibles/dairy.json index 071a84e080f3a..df6a93afcf9b4 100644 --- a/data/json/items/comestibles/dairy.json +++ b/data/json/items/comestibles/dairy.json @@ -6,7 +6,7 @@ "copy-from": "milk", "spoils_in": "12 hours", "price": 19, - "contamination": 5, + "contamination": [ [ "bad_food", 5 ] ], "description": "This is raw, unhomogenized and unpasteurized milk from a cow. It couldn't be any fresher unless you drank it straight from the cow, which might upset it. Depending on your dietary sensibilities, you might want to pasteurize or even boil this before drinking." }, { diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 2f3e3077d183f..c9a9a5cea9d91 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -468,15 +468,23 @@ When adding a new bionic, if it's not included with another one, you must also a | max_duration | The maximum duration the disease can last. | min_intensity | The minimum intensity of the effect applied by the disease | max_intensity | The maximum intensity of the effect. -| health_threshold | The amount of health above which one is immune to the disease. -| symptopms | The effect applied by the disease. -| affected_bodyparts | The list of bodyparts on which the effect is applied. +| health_threshold | The amount of health above which one is immune to the disease. Must be between -200 and 200. (optional ) +| symptoms | The effect applied by the disease. +| affected_bodyparts | The list of bodyparts on which the effect is applied. (optional, default to num_bp) ```json -{ - -} + { + "type": "disease_type", + "id": "bad_food", + "min_duration": "6 m", + "max_duration": "1 h", + "min_intensity": 1, + "max_intensity": 1, + "affected_bodyparts": [ "TORSO" ], + "health_threshold": 100, + "symptoms": "foodpoison" + } ``` ### Item Groups @@ -1614,7 +1622,7 @@ CBMs can be defined like this: "freezing_point": 32, // (Optional) Temperature in F at which item freezes, default is water (32F/0C) "cooks_like": "meat_cooked" // (Optional) If the item is used in a recipe, replaces it with its cooks_like "parasites": 10, // (Optional) Probability of becoming parasitised when eating -"contamination": 5, // (Optional) Probability to get food poisoning from this comestible. Values must be in the [0, 100] range. +"contamination": [ [ "bad_food", 5 ] ], // (Optional) List of diseases carried by this comestible and their associated probability. Values must be in the [0, 100] range. ``` ### Containers From b981fc6e088ef16ddb788941d91b8653cbc49f2f Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Tue, 24 Mar 2020 12:07:59 +0100 Subject: [PATCH 10/13] fix merge error --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index 5e1940d62db2e..455631b5a5667 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -696,6 +696,7 @@ void DynamicDataLoader::check_consistency( loading_ui &ui ) { _( "Transformations" ), &event_transformation::check_consistency }, { _( "Statistics" ), &event_statistic::check_consistency }, { _( "Scent types" ), &scent_type::check_scent_consistency }, + { _( "Scores" ), &score::check_consistency }, { _( "Disease types" ), &disease_type::check_disease_consistency }, { _( "Factions" ), &faction_template::check_consistency }, } From cf5fbb43255d3d9b7cb49049fe1446aaa9d73177 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Wed, 25 Mar 2020 10:57:55 +0100 Subject: [PATCH 11/13] array to object --- data/json/items/comestibles/dairy.json | 2 +- doc/JSON_INFO.md | 2 +- src/item_factory.cpp | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/data/json/items/comestibles/dairy.json b/data/json/items/comestibles/dairy.json index df6a93afcf9b4..b530eedd864ff 100644 --- a/data/json/items/comestibles/dairy.json +++ b/data/json/items/comestibles/dairy.json @@ -6,7 +6,7 @@ "copy-from": "milk", "spoils_in": "12 hours", "price": 19, - "contamination": [ [ "bad_food", 5 ] ], + "contamination": [ { "disease": "bad_food", "probability": 5 } ], "description": "This is raw, unhomogenized and unpasteurized milk from a cow. It couldn't be any fresher unless you drank it straight from the cow, which might upset it. Depending on your dietary sensibilities, you might want to pasteurize or even boil this before drinking." }, { diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index c9a9a5cea9d91..124abe5f359d5 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -1622,7 +1622,7 @@ CBMs can be defined like this: "freezing_point": 32, // (Optional) Temperature in F at which item freezes, default is water (32F/0C) "cooks_like": "meat_cooked" // (Optional) If the item is used in a recipe, replaces it with its cooks_like "parasites": 10, // (Optional) Probability of becoming parasitised when eating -"contamination": [ [ "bad_food", 5 ] ], // (Optional) List of diseases carried by this comestible and their associated probability. Values must be in the [0, 100] range. +"contamination": [ { "disease": "bad_food", "probability": 5 } ], // (Optional) List of diseases carried by this comestible and their associated probability. Values must be in the [0, 100] range. ``` ### Containers diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 8067e00ff62fd..0cc6bb896773b 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -1848,8 +1848,9 @@ void Item_factory::load( islot_comestible &slot, const JsonObject &jo, const std assign( jo, "cooks_like", slot.cooks_like, strict ); assign( jo, "smoking_result", slot.smoking_result, strict ); - for( JsonArray ja : jo.get_array( "contamination" ) ) { - slot.contamination.emplace( diseasetype_id( ja.get_string( 0 ) ), ja.get_int( 1 ) ); + for( const JsonObject &jsobj : jo.get_array( "contamination" ) ) { + slot.contamination.emplace( diseasetype_id( jsobj.get_string( "disease" ) ), + jsobj.get_int( "probability" ) ); } bool is_junkfood = false; From 54ffcf40db631009a74095085e22d3769a40d62d Mon Sep 17 00:00:00 2001 From: Fris0uman <41293484+Fris0uman@users.noreply.github.com> Date: Wed, 25 Mar 2020 18:37:00 +0100 Subject: [PATCH 12/13] Update doc/JSON_INFO.md Co-Authored-By: Anton Burmistrov --- doc/JSON_INFO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 124abe5f359d5..ff4a08dd4b4fc 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -189,7 +189,7 @@ Here's a quick summary of what each of the JSON files contain, broken down by fo | default_blacklist.json | a standard blacklist of joke monsters | doll_speech.json | talk doll speech messages | dreams.json | dream text and linked mutation categories -| disease.json | desease definitions +| disease.json | disease definitions | effects.json | common effects and their effects | emit.json | smoke and gas emissions | flags.json | common flags and their descriptions From b73b2e0ab767f7f9d89d7da522259159fb189624 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Fri, 3 Apr 2020 11:52:53 +0200 Subject: [PATCH 13/13] include fix --- src/character.cpp | 1 + src/character.h | 1 - src/consumption.cpp | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/character.cpp b/src/character.cpp index 494ef71fbe6e5..b18cca5b6b169 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -16,6 +16,7 @@ #include "construction.h" #include "coordinate_conversions.h" #include "debug.h" +#include "disease.h" #include "effect.h" #include "event_bus.h" #include "field.h" diff --git a/src/character.h b/src/character.h index 736ca468702a3..49f21047172fb 100644 --- a/src/character.h +++ b/src/character.h @@ -21,7 +21,6 @@ #include "character_id.h" #include "character_martial_arts.h" #include "creature.h" -#include "disease.h" #include "game_constants.h" #include "inventory.h" #include "pimpl.h" diff --git a/src/consumption.cpp b/src/consumption.cpp index bbb168f9725d7..f314af0a4a4ff 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -13,6 +13,7 @@ #include "calendar.h" #include "cata_utility.h" #include "debug.h" +#include "disease.h" #include "game.h" #include "itype.h" #include "map.h"