Skip to content

Commit

Permalink
Add enchantments to bionics
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman committed Apr 14, 2020
1 parent a015c70 commit a2c0eb8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,8 @@ void load_bionic( const JsonObject &jsobj )

new_bionic.weight_capacity_modifier = jsobj.get_float( "weight_capacity_modifier", 1.0 );

assign( jsobj, "enchantments", new_bionic.enchantments );

assign( jsobj, "weight_capacity_bonus", new_bionic.weight_capacity_bonus, false, 0_gram );
assign( jsobj, "exothermic_power_gen", new_bionic.exothermic_power_gen );
assign( jsobj, "power_gen_emission", new_bionic.power_gen_emission );
Expand Down Expand Up @@ -2638,6 +2640,11 @@ void check_bionics()
bio.first.c_str(), mid.c_str() );
}
}
for( const enchantment_id &eid : bio.first->enchantments ) {
if( !eid.is_valid() ) {
debugmsg( "Bionic %s uses undefined enchantment %s", bio.first.c_str(), eid.c_str() );
}
}
for( const bionic_id &bid : bio.second.included_bionics ) {
if( !bid.is_valid() ) {
debugmsg( "Bionic %s includes undefined bionic %s",
Expand Down
3 changes: 3 additions & 0 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ struct bionic_data {
/**Amount of cut protection offered by this bionic*/
std::map<body_part, size_t> cut_protec;

/** bionic enchantments */
std::vector<enchantment_id> enchantments;

/**
* Body part slots used to install this bionic, mapped to the amount of space required.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@ void Character::process_turn()
}
}

enchantment_cache.activate_passive( *this );

Creature::process_turn();
}

Expand Down Expand Up @@ -7945,6 +7947,20 @@ void Character::recalculate_enchantment_cache()
}
}
}

for( const bionic &bio : *my_bionics ) {
const bionic_id &bid = bio.id;
if( bid->toggled && !bio.powered ) {
continue;
}

for( const enchantment_id &ench_id : bid->enchantments ) {
const enchantment &ench = ench_id.obj();
if( ench.is_active( *this ) ) {
enchantment_cache.force_add( ench );
}
}
}
}

double Character::calculate_by_enchantment( double modify, enchantment::mod value,
Expand Down
7 changes: 7 additions & 0 deletions src/magic_enchantment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ void enchantment::load( const JsonObject &jo, const std::string & )
active_conditions.second = io::string_to_enum<condition>( jo.get_string( "condition",
"ALWAYS" ) );

for( JsonObject jsobj : jo.get_array( "ench_effects" ) ) {
ench_effects.emplace( jsobj.get_string( "effect" ), jsobj.get_int( "intensity" ) );
}

if( jo.has_array( "values" ) ) {
for( const JsonObject value_obj : jo.get_array( "values" ) ) {
const enchantment::mod value = io::string_to_enum<mod>( value_obj.get_string( "value" ) );
Expand Down Expand Up @@ -399,6 +403,9 @@ void enchantment::activate_passive( Character &guy ) const
if( emitter ) {
g->m.emit_field( guy.pos(), *emitter );
}
for( const std::pair<efftype_id, int> eff : ench_effects ) {
guy.add_effect( eff.first, 1_seconds, num_bp, false, eff.second );
}
for( const std::pair<const time_duration, std::vector<fake_spell>> &activation :
intermittent_activation ) {
// a random approximation!
Expand Down
1 change: 1 addition & 0 deletions src/magic_enchantment.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class enchantment
void cast_hit_me( Character &caster, const Creature *target ) const;
private:
cata::optional<emit_id> emitter;
std::map<efftype_id, int> ench_effects;
// values that add to the base value
std::map<mod, int> values_add;
// values that get multiplied to the base value
Expand Down

0 comments on commit a2c0eb8

Please sign in to comment.