Skip to content

Commit

Permalink
Merge pull request #37558 from Fris0uman/bio_prot
Browse files Browse the repository at this point in the history
Jsonize bash and cut protection from bionics
  • Loading branch information
kevingranade authored Jan 31, 2020
2 parents ffc3ce3 + 08c0cb5 commit 7a0ad59
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 55 deletions.
34 changes: 34 additions & 0 deletions data/json/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
},
{
Expand All @@ -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" ]
},
{
Expand All @@ -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" ]
},
{
Expand All @@ -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" ]
},
{
Expand All @@ -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" ]
},
{
Expand Down Expand Up @@ -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" ]
},
{
Expand Down
9 changes: 9 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<body_part, size_t> env_protec;

/**Amount of bash protection offered by this bionic*/
std::map<body_part, size_t> bash_protec;
/**Amount of cut protection offered by this bionic*/
std::map<body_part, size_t> cut_protec;

/**
* Body part slots used to install this bionic, mapped to the amount of space required.
*/
Expand Down
79 changes: 25 additions & 54 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
}

Expand Down
21 changes: 20 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3039,7 +3039,26 @@ void item::final_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
info.push_back( iteminfo( "DESCRIPTION",
_( "<bold>Environmental Protection:</bold> " ),
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 ),
" <num> ", iteminfo::no_newline, element.second ) );
}
}

if( !bid->bash_protec.empty() ) {
info.push_back( iteminfo( "DESCRIPTION",
_( "<bold>Bash Protection:</bold> " ),
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 ),
" <num> ", iteminfo::no_newline, element.second ) );
}
}
if( !bid->cut_protec.empty() ) {
info.push_back( iteminfo( "DESCRIPTION",
_( "<bold>Cut Protection:</bold> " ),
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 ),
" <num> ", iteminfo::no_newline, element.second ) );
}
Expand Down

0 comments on commit 7a0ad59

Please sign in to comment.