From 3b13bea381766336732cc5d12ed9289fea1cc84c Mon Sep 17 00:00:00 2001 From: Ramza13 <52087122+Ramza13@users.noreply.github.com> Date: Thu, 15 Jul 2021 00:18:18 -0400 Subject: [PATCH] Add consumption_eocs --- doc/JSON_INFO.md | 1 + src/consumption.cpp | 27 +++++++++++++++++++++++++++ src/item_factory.cpp | 5 +++++ src/itype.h | 3 +++ 4 files changed, 36 insertions(+) diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 95c109355bee7..f920ebc168d1d 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -2640,6 +2640,7 @@ CBMs can be defined like this: "fatigue_mod": 3, // How much fatigue this comestible removes. (Negative values add fatigue) "radiation": 8, // How much radiation you get from this comestible. "comestible_type" : "MED", // Comestible type, used for inventory sorting +"consumption_effect_on_conditions" : [ "EOC_1" ], // Effect on conditions to run after consuming. Inline or string id supported "quench" : 0, // Thirst quenched "healthy" : -2, // Health effects (used for sickness chances) "addiction_potential" : 80, // Ability to cause addictions diff --git a/src/consumption.cpp b/src/consumption.cpp index 6b57307c4ed0d..6bbadf7f4b4ec 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1478,6 +1478,19 @@ bool Character::consume_effects( item &food ) if( has_effect( effect_tapeworm ) ) { ingested.nutr /= 2; } + dialogue d; + standard_npc default_npc( "Default" ); + if( avatar *u = as_avatar() ) { + d.alpha = get_talker_for( u ); + } else if( npc *n = as_npc() ) { + d.alpha = get_talker_for( n ); + } + item_location loc( *( as_character() ), &food ); + d.beta = get_talker_for( loc ); + + for( const effect_on_condition_id &eoc : comest.consumption_eocs ) { + eoc->activate( d ); + } // GET IN MAH BELLY! stomach.ingest( ingested ); @@ -1730,6 +1743,20 @@ static bool consume_med( item &target, player &you ) // Take by mouth you.consume_effects( target ); } + dialogue d; + standard_npc default_npc( "Default" ); + if( avatar *u = you.as_avatar() ) { + d.alpha = get_talker_for( u ); + } else if( npc *n = you.as_npc() ) { + d.alpha = get_talker_for( n ); + } + item_location loc( *( you.as_character() ), &target ); + d.beta = get_talker_for( loc ); + + const auto &comest = *target.get_comestible(); + for( const effect_on_condition_id &eoc : comest.consumption_eocs ) { + eoc->activate( d ); + } target.mod_charges( -amount_used ); return true; diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 0424dfc71a165..95d50dc7e8859 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -24,6 +24,7 @@ #include "color.h" #include "damage.h" #include "debug.h" +#include "effect_on_condition.h" #include "enum_conversions.h" #include "enums.h" #include "explosion.h" @@ -2225,6 +2226,10 @@ void Item_factory::load( islot_comestible &slot, const JsonObject &jo, const std 1000; } + for( JsonValue jv : jo.get_array( "consumption_effect_on_conditions" ) ) { + slot.consumption_eocs.push_back( effect_on_conditions::load_inline_eoc( jv, "" ) ); + } + if( jo.has_member( "nutrition" ) && got_calories ) { jo.throw_error( "cannot specify both nutrition and calories", "nutrition" ); } diff --git a/src/itype.h b/src/itype.h index 398122e6a25e3..2f17703b65d2f 100644 --- a/src/itype.h +++ b/src/itype.h @@ -164,6 +164,9 @@ struct islot_comestible { /** freezing point in degrees celsius, below this temperature item can freeze */ float freeze_point = 0; + /**effect on conditions to apply on consumption*/ + std::vector consumption_eocs; + /**List of diseases carried by this comestible and their associated probability*/ std::map contamination;