Skip to content

Commit

Permalink
Add consumption_eocs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramza13 committed Jul 30, 2021
1 parent aafbb03 commit 8f36b1a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" );
}
Expand Down
3 changes: 3 additions & 0 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<effect_on_condition_id> consumption_eocs;

/**List of diseases carried by this comestible and their associated probability*/
std::map<diseasetype_id, int> contamination;

Expand Down

0 comments on commit 8f36b1a

Please sign in to comment.