From 6feb61ad05c6796c15c9c7f4b2802d2fdb653419 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Thu, 30 Jan 2020 16:51:05 +0100 Subject: [PATCH 1/2] Jsonize CBM bash and cut protection --- data/json/bionics.json | 34 ++++++++++++++++++ src/bionics.cpp | 9 +++++ src/bionics.h | 6 ++++ src/character.cpp | 79 +++++++++++++----------------------------- 4 files changed, 74 insertions(+), 54 deletions(-) diff --git a/data/json/bionics.json b/data/json/bionics.json index ed4b9a8c05beb..a778f404f7a9d 100644 --- a/data/json/bionics.json +++ b/data/json/bionics.json @@ -43,6 +43,8 @@ "name": "Alloy Plating - Arms", "description": "The flesh on your arms has been surgically replaced by alloy plating. Provides passive protection and can be used in conjunction with bionic martial arts.", "occupied_bodyparts": [ [ "ARM_L", 4 ], [ "ARM_R", 4 ] ], + "bash_protec": [ [ "ARM_L", 3 ], [ "ARM_R", 3 ] ], + "cut_protec": [ [ "ARM_L", 3 ], [ "ARM_R", 3 ] ], "flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ] }, { @@ -52,6 +54,8 @@ "description": "Your eye sockets have been surgically sealed with highly protective mirrored lenses and your tear ducts have been re-routed to your mouth. When you cry, you must spit out or swallow your tears.", "occupied_bodyparts": [ [ "EYES", 1 ] ], "env_protec": [ [ "EYES", 7 ] ], + "bash_protec": [ [ "EYES", 3 ] ], + "cut_protec": [ [ "EYES", 3 ] ], "flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ] }, { @@ -60,6 +64,8 @@ "name": "Alloy Plating - Head", "description": "The flesh on your head has been surgically replaced by alloy plating, protecting both your head and jaw regions.", "occupied_bodyparts": [ [ "HEAD", 5 ], [ "MOUTH", 1 ] ], + "bash_protec": [ [ "HEAD", 3 ] ], + "cut_protec": [ [ "HEAD", 3 ] ], "flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ] }, { @@ -68,6 +74,8 @@ "name": "Alloy Plating - Legs", "description": "The flesh on your legs has been surgically replaced by alloy plating. Provides passive protection and can be used in conjunction with bionic martial arts.", "occupied_bodyparts": [ [ "LEG_L", 6 ], [ "LEG_R", 6 ] ], + "bash_protec": [ [ "LEG_L", 3 ], [ "LEG_R", 3 ] ], + "cut_protec": [ [ "LEG_L", 3 ], [ "LEG_R", 3 ] ], "flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ] }, { @@ -76,6 +84,8 @@ "name": "Alloy Plating - Torso", "description": "The flesh on your torso has been surgically replaced by alloy plating, protecting it from physical trauma.", "occupied_bodyparts": [ [ "TORSO", 10 ] ], + "bash_protec": [ [ "TORSO", 3 ] ], + "cut_protec": [ [ "TORSO", 3 ] ], "flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ] }, { @@ -163,6 +173,30 @@ [ "FOOT_L", 1 ], [ "FOOT_R", 1 ] ], + "bash_protec": [ + [ "TORSO", 2 ], + [ "HEAD", 2 ], + [ "ARM_L", 2 ], + [ "ARM_R", 2 ], + [ "HAND_L", 2 ], + [ "HAND_R", 2 ], + [ "LEG_L", 2 ], + [ "LEG_R", 2 ], + [ "FOOT_L", 2 ], + [ "FOOT_R", 2 ] + ], + "cut_protec": [ + [ "TORSO", 4 ], + [ "HEAD", 4 ], + [ "ARM_L", 4 ], + [ "ARM_R", 4 ], + [ "HAND_L", 4 ], + [ "HAND_R", 4 ], + [ "LEG_L", 4 ], + [ "LEG_R", 4 ], + [ "FOOT_L", 4 ], + [ "FOOT_R", 4 ] + ], "flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ] }, { diff --git a/src/bionics.cpp b/src/bionics.cpp index 58db0ada33c11..7bbd3fcf59223 100644 --- a/src/bionics.cpp +++ b/src/bionics.cpp @@ -2392,6 +2392,15 @@ void load_bionic( const JsonObject &jsobj ) ja.get_int( 1 ) ); } + for( JsonArray ja : jsobj.get_array( "bash_protec" ) ) { + new_bionic.bash_protec.emplace( get_body_part_token( ja.get_string( 0 ) ), + ja.get_int( 1 ) ); + } + for( JsonArray ja : jsobj.get_array( "cut_protec" ) ) { + new_bionic.cut_protec.emplace( get_body_part_token( ja.get_string( 0 ) ), + ja.get_int( 1 ) ); + } + new_bionic.activated = new_bionic.toggled || new_bionic.power_activate > 0_kJ || new_bionic.charge_time > 0; diff --git a/src/bionics.h b/src/bionics.h index 22d0cd1c47772..c1da377933a68 100644 --- a/src/bionics.h +++ b/src/bionics.h @@ -101,6 +101,12 @@ struct bionic_data { emit_id power_gen_emission = emit_id::NULL_ID(); /**Amount of environemental protection offered by this bionic*/ std::map env_protec; + + /**Amount of bash protection offered by this bionic*/ + std::map bash_protec; + /**Amount of cut protection offered by this bionic*/ + std::map cut_protec; + /** * Body part slots used to install this bionic, mapped to the amount of space required. */ diff --git a/src/character.cpp b/src/character.cpp index fdd4dc70270c5..454dbfffca474 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -6301,23 +6301,11 @@ int Character::get_armor_bash_base( body_part bp ) const ret += i.bash_resist(); } } - if( has_bionic( bio_carbon ) ) { - ret += 2; - } - if( bp == bp_head && has_bionic( bio_armor_head ) ) { - ret += 3; - } - if( ( bp == bp_arm_l || bp == bp_arm_r ) && has_bionic( bio_armor_arms ) ) { - ret += 3; - } - if( bp == bp_torso && has_bionic( bio_armor_torso ) ) { - ret += 3; - } - if( ( bp == bp_leg_l || bp == bp_leg_r ) && has_bionic( bio_armor_legs ) ) { - ret += 3; - } - if( bp == bp_eyes && has_bionic( bio_armor_eyes ) ) { - ret += 3; + for( const bionic_id &bid : get_bionics() ) { + const auto bash_prot = bid->bash_protec.find( bp ); + if( bash_prot != bid->bash_protec.end() ) { + ret += bash_prot->second; + } } ret += mutation_armor( bp, DT_BASH ); @@ -6332,19 +6320,11 @@ int Character::get_armor_cut_base( body_part bp ) const ret += i.cut_resist(); } } - if( has_bionic( bio_carbon ) ) { - ret += 4; - } - if( bp == bp_head && has_bionic( bio_armor_head ) ) { - ret += 3; - } else if( ( bp == bp_arm_l || bp == bp_arm_r ) && has_bionic( bio_armor_arms ) ) { - ret += 3; - } else if( bp == bp_torso && has_bionic( bio_armor_torso ) ) { - ret += 3; - } else if( ( bp == bp_leg_l || bp == bp_leg_r ) && has_bionic( bio_armor_legs ) ) { - ret += 3; - } else if( bp == bp_eyes && has_bionic( bio_armor_eyes ) ) { - ret += 3; + for( const bionic_id &bid : get_bionics() ) { + const auto cut_prot = bid->cut_protec.find( bp ); + if( cut_prot != bid->cut_protec.end() ) { + ret += cut_prot->second; + } } ret += mutation_armor( bp, DT_CUT ); @@ -7458,31 +7438,22 @@ bool Character::armor_absorb( damage_unit &du, item &armor ) float Character::bionic_armor_bonus( body_part bp, damage_type dt ) const { float result = 0.0f; - // We only check the passive bionics - if( has_bionic( bio_carbon ) ) { - if( dt == DT_BASH ) { - result += 2; - } else if( dt == DT_CUT || dt == DT_STAB ) { - result += 4; - } - } - // All the other bionic armors reduce bash/cut/stab by 3 - // Map body parts to a set of bionics that protect it - // TODO: JSONize passive bionic armor instead of hardcoding it - static const std::map< body_part, bionic_id > armor_bionics = { - { bp_head, { bio_armor_head } }, - { bp_arm_l, { bio_armor_arms } }, - { bp_arm_r, { bio_armor_arms } }, - { bp_torso, { bio_armor_torso } }, - { bp_leg_l, { bio_armor_legs } }, - { bp_leg_r, { bio_armor_legs } }, - { bp_eyes, { bio_armor_eyes } } - }; - auto iter = armor_bionics.find( bp ); - if( iter != armor_bionics.end() && has_bionic( iter->second ) && - ( dt == DT_BASH || dt == DT_CUT || dt == DT_STAB ) ) { - result += 3; + if( dt == DT_CUT || dt == DT_STAB ) { + for( const bionic_id &bid : get_bionics() ) { + const auto cut_prot = bid->cut_protec.find( bp ); + if( cut_prot != bid->cut_protec.end() ) { + result += cut_prot->second; + } + } + } else if( dt == DT_BASH ) { + for( const bionic_id &bid : get_bionics() ) { + const auto bash_prot = bid->bash_protec.find( bp ); + if( bash_prot != bid->bash_protec.end() ) { + result += bash_prot->second; + } + } } + return result; } From 08c0cb51dd02b1a02d1e6d17734f71f27d3a365a Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Thu, 30 Jan 2020 16:58:59 +0100 Subject: [PATCH 2/2] Display protection in item description --- src/item.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index a18936fc0cf66..5ed41661ba9fa 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -3039,7 +3039,26 @@ void item::final_info( std::vector &info, const iteminfo_query *parts, info.push_back( iteminfo( "DESCRIPTION", _( "Environmental Protection: " ), iteminfo::no_newline ) ); - for( const auto &element : bid->env_protec ) { + for( const std::pair< body_part, size_t > &element : bid->env_protec ) { + info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first, 1 ), + " ", iteminfo::no_newline, element.second ) ); + } + } + + if( !bid->bash_protec.empty() ) { + info.push_back( iteminfo( "DESCRIPTION", + _( "Bash Protection: " ), + iteminfo::no_newline ) ); + for( const std::pair< body_part, size_t > &element : bid->bash_protec ) { + info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first, 1 ), + " ", iteminfo::no_newline, element.second ) ); + } + } + if( !bid->cut_protec.empty() ) { + info.push_back( iteminfo( "DESCRIPTION", + _( "Cut Protection: " ), + iteminfo::no_newline ) ); + for( const std::pair< body_part, size_t > &element : bid->cut_protec ) { info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first, 1 ), " ", iteminfo::no_newline, element.second ) ); }