Skip to content

Commit

Permalink
Replace body_part in more combat related function (#39931)
Browse files Browse the repository at this point in the history
* deal_damage_handle_type

* on_hit

* get_env_protection

* get_armor_bash

* get_armor_cut

* get_armor_bash_base

* get_armor_cut_base

* get_armor_type

* get_armor_acid

* astyle
  • Loading branch information
ZhilkinSerg authored Apr 28, 2020
2 parents a4034c1 + 7b75bb2 commit cf96ad4
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 174 deletions.
64 changes: 32 additions & 32 deletions data/json/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"name": { "str": "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 ] ],
"bash_protec": [ [ "arm_l", 3 ], [ "arm_r", 3 ] ],
"cut_protec": [ [ "arm_l", 3 ], [ "arm_r", 3 ] ],
"flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ]
},
{
Expand All @@ -53,9 +53,9 @@
"name": { "str": "Protective Lenses" },
"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 ] ],
"env_protec": [ [ "eyes", 7 ] ],
"bash_protec": [ [ "eyes", 3 ] ],
"cut_protec": [ [ "eyes", 3 ] ],
"flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ]
},
{
Expand All @@ -64,8 +64,8 @@
"name": { "str": "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 ] ],
"bash_protec": [ [ "head", 3 ] ],
"cut_protec": [ [ "head", 3 ] ],
"flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ]
},
{
Expand All @@ -74,8 +74,8 @@
"name": { "str": "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 ] ],
"bash_protec": [ [ "leg_l", 3 ], [ "leg_r", 3 ] ],
"cut_protec": [ [ "leg_l", 3 ], [ "leg_r", 3 ] ],
"flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ]
},
{
Expand All @@ -84,8 +84,8 @@
"name": { "str": "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 ] ],
"bash_protec": [ [ "torso", 3 ] ],
"cut_protec": [ [ "torso", 3 ] ],
"flags": [ "BIONIC_NPC_USABLE", "BIONIC_SHOCKPROOF" ]
},
{
Expand Down Expand Up @@ -174,28 +174,28 @@
[ "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 ]
[ "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 ]
[ "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 Expand Up @@ -832,7 +832,7 @@
"name": { "str": "Air Filtration System" },
"description": "Surgically implanted in your trachea is an advanced filtration system. If toxins, or airborne diseases find their way into your windpipe, the filter will attempt to remove them.",
"occupied_bodyparts": [ [ "TORSO", 4 ], [ "MOUTH", 2 ] ],
"env_protec": [ [ "MOUTH", 7 ] ],
"env_protec": [ [ "mouth", 7 ] ],
"flags": [ "BIONIC_NPC_USABLE" ]
},
{
Expand Down
6 changes: 3 additions & 3 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ This section describes each json file and their contents. Each json has their ow
"name": "Air Filtration System",
"description": "Surgically implanted in your trachea is an advanced filtration system. If toxins, or airborne diseases find their way into your windpipe, the filter will attempt to remove them.",
"occupied_bodyparts": [ [ "TORSO", 4 ], [ "MOUTH", 2 ] ],
"env_protec": [ [ "MOUTH", 7 ] ],
"bash_protec": [ [ "LEG_L", 3 ], [ "LEG_R", 3 ] ],
"cut_protec": [ [ "LEG_L", 3 ], [ "LEG_R", 3 ] ],
"env_protec": [ [ "mouth", 7 ] ],
"bash_protec": [ [ "leg_l", 3 ], [ "leg_r", 3 ] ],
"cut_protec": [ [ "leg_l", 3 ], [ "leg_r", 3 ] ],
"flags": [ "BIONIC_NPC_USABLE" ]
}
```
Expand Down
7 changes: 3 additions & 4 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2599,16 +2599,15 @@ void load_bionic( const JsonObject &jsobj )
}

for( JsonArray ja : jsobj.get_array( "env_protec" ) ) {
new_bionic.env_protec.emplace( get_body_part_token( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
new_bionic.env_protec.emplace( bodypart_str_id( ja.get_string( 0 ) ), 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 ) ),
new_bionic.bash_protec.emplace( bodypart_str_id( 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 ) ),
new_bionic.cut_protec.emplace( bodypart_str_id( ja.get_string( 0 ) ),
ja.get_int( 1 ) );
}

Expand Down
6 changes: 3 additions & 3 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ struct bionic_data {
/**Type of field emitted by this bionic when it produces energy*/
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;
std::map<bodypart_str_id, size_t> env_protec;

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

/** bionic enchantments */
std::vector<enchantment_id> enchantments;
Expand Down
62 changes: 31 additions & 31 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6180,7 +6180,7 @@ bool Character::is_immune_field( const field_type_id &fid ) const
bool immune_by_body_part_resistance = !ft.immunity_data_body_part_env_resistance.empty();
for( const std::pair<body_part, int> &fide : ft.immunity_data_body_part_env_resistance ) {
immune_by_body_part_resistance = immune_by_body_part_resistance &&
get_env_resist( fide.first ) >= fide.second;
get_env_resist( convert_bp( fide.first ).id() ) >= fide.second;
}
if( immune_by_body_part_resistance ) {
return true;
Expand All @@ -6192,14 +6192,14 @@ bool Character::is_immune_field( const field_type_id &fid ) const
return has_active_bionic( bio_heatsink ) || is_wearing( "rm13_armor_on" );
}
if( ft.has_acid ) {
return !is_on_ground() && get_env_resist( bp_foot_l ) >= 15 &&
get_env_resist( bp_foot_r ) >= 15 &&
get_env_resist( bp_leg_l ) >= 15 &&
get_env_resist( bp_leg_r ) >= 15 &&
get_armor_type( DT_ACID, bp_foot_l ) >= 5 &&
get_armor_type( DT_ACID, bp_foot_r ) >= 5 &&
get_armor_type( DT_ACID, bp_leg_l ) >= 5 &&
get_armor_type( DT_ACID, bp_leg_r ) >= 5;
return !is_on_ground() && get_env_resist( bodypart_id( "foot_l" ) ) >= 15 &&
get_env_resist( bodypart_id( "foot_r" ) ) >= 15 &&
get_env_resist( bodypart_id( "leg_l" ) ) >= 15 &&
get_env_resist( bodypart_id( "leg_r" ) ) >= 15 &&
get_armor_type( DT_ACID, bodypart_id( "foot_l" ) ) >= 5 &&
get_armor_type( DT_ACID, bodypart_id( "foot_r" ) ) >= 5 &&
get_armor_type( DT_ACID, bodypart_id( "leg_l" ) ) >= 5 &&
get_armor_type( DT_ACID, bodypart_id( "leg_r" ) ) >= 5;
}
// If we haven't found immunity yet fall up to the next level
return Creature::is_immune_field( fid );
Expand Down Expand Up @@ -7080,17 +7080,17 @@ std::string Character::activity_level_str() const
}
}

int Character::get_armor_bash( body_part bp ) const
int Character::get_armor_bash( bodypart_id bp ) const
{
return get_armor_bash_base( bp ) + armor_bash_bonus;
}

int Character::get_armor_cut( body_part bp ) const
int Character::get_armor_cut( bodypart_id bp ) const
{
return get_armor_cut_base( bp ) + armor_cut_bonus;
}

int Character::get_armor_type( damage_type dt, body_part bp ) const
int Character::get_armor_type( damage_type dt, bodypart_id bp ) const
{
switch( dt ) {
case DT_TRUE:
Expand All @@ -7108,12 +7108,12 @@ int Character::get_armor_type( damage_type dt, body_part bp ) const
case DT_ELECTRIC: {
int ret = 0;
for( auto &i : worn ) {
if( i.covers( bp ) ) {
if( i.covers( bp->token ) ) {
ret += i.damage_resist( dt );
}
}

ret += mutation_armor( bp, dt );
ret += mutation_armor( bp->token, dt );
return ret;
}
case DT_NULL:
Expand All @@ -7126,68 +7126,68 @@ int Character::get_armor_type( damage_type dt, body_part bp ) const
return 0;
}

int Character::get_armor_bash_base( body_part bp ) const
int Character::get_armor_bash_base( bodypart_id bp ) const
{
int ret = 0;
for( auto &i : worn ) {
if( i.covers( bp ) ) {
if( i.covers( bp->token ) ) {
ret += i.bash_resist();
}
}
for( const bionic_id &bid : get_bionics() ) {
const auto bash_prot = bid->bash_protec.find( bp );
const auto bash_prot = bid->bash_protec.find( bp.id() );
if( bash_prot != bid->bash_protec.end() ) {
ret += bash_prot->second;
}
}

ret += mutation_armor( bp, DT_BASH );
ret += mutation_armor( bp->token, DT_BASH );
return ret;
}

int Character::get_armor_cut_base( body_part bp ) const
int Character::get_armor_cut_base( bodypart_id bp ) const
{
int ret = 0;
for( auto &i : worn ) {
if( i.covers( bp ) ) {
if( i.covers( bp->token ) ) {
ret += i.cut_resist();
}
}
for( const bionic_id &bid : get_bionics() ) {
const auto cut_prot = bid->cut_protec.find( bp );
const auto cut_prot = bid->cut_protec.find( bp.id() );
if( cut_prot != bid->cut_protec.end() ) {
ret += cut_prot->second;
}
}

ret += mutation_armor( bp, DT_CUT );
ret += mutation_armor( bp->token, DT_CUT );
return ret;
}

int Character::get_env_resist( body_part bp ) const
int Character::get_env_resist( bodypart_id bp ) const
{
int ret = 0;
for( auto &i : worn ) {
// Head protection works on eyes too (e.g. baseball cap)
if( i.covers( bp ) || ( bp == bp_eyes && i.covers( bp_head ) ) ) {
if( i.covers( bp->token ) || ( bp == bodypart_id( "eyes" ) && i.covers( bp_head ) ) ) {
ret += i.get_env_resist();
}
}

for( const bionic_id &bid : get_bionics() ) {
const auto EP = bid->env_protec.find( bp );
const auto EP = bid->env_protec.find( bp.id() );
if( EP != bid->env_protec.end() ) {
ret += EP->second;
}
}

if( bp == bp_eyes && has_trait( trait_SEESLEEP ) ) {
if( bp == bodypart_id( "eyes" ) && has_trait( trait_SEESLEEP ) ) {
ret += 8;
}
return ret;
}

int Character::get_armor_acid( body_part bp ) const
int Character::get_armor_acid( bodypart_id bp ) const
{
return get_armor_type( DT_ACID, bp );
}
Expand Down Expand Up @@ -8310,14 +8310,14 @@ float Character::bionic_armor_bonus( body_part bp, damage_type dt ) const
float result = 0.0f;
if( dt == DT_CUT || dt == DT_STAB ) {
for( const bionic_id &bid : get_bionics() ) {
const auto cut_prot = bid->cut_protec.find( bp );
const auto cut_prot = bid->cut_protec.find( convert_bp( 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 );
const auto bash_prot = bid->bash_protec.find( convert_bp( bp ) );
if( bash_prot != bid->bash_protec.end() ) {
result += bash_prot->second;
}
Expand All @@ -8329,15 +8329,15 @@ float Character::bionic_armor_bonus( body_part bp, damage_type dt ) const

int Character::get_armor_fire( body_part bp ) const
{
return get_armor_type( DT_HEAT, bp );
return get_armor_type( DT_HEAT, convert_bp( bp ).id() );
}

void Character::did_hit( Creature &target )
{
enchantment_cache.cast_hit_you( *this, target );
}

void Character::on_hit( Creature *source, body_part /*bp_hit*/,
void Character::on_hit( Creature *source, bodypart_id /*bp_hit*/,
float /*difficulty*/, dealt_projectile_attack const *const /*proj*/ )
{
enchantment_cache.cast_hit_me( *this, source );
Expand Down
16 changes: 8 additions & 8 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class Character : public Creature, public visitable<Character>
public:

// any side effects that might happen when the Character is hit
void on_hit( Creature *source, body_part /*bp_hit*/,
void on_hit( Creature *source, bodypart_id /*bp_hit*/,
float /*difficulty*/, dealt_projectile_attack const * /*proj*/ ) override;
// any side effects that might happen when the Character hits a Creature
void did_hit( Creature &target );
Expand Down Expand Up @@ -1723,19 +1723,19 @@ class Character : public Creature, public visitable<Character>
std::string activity_level_str() const;

/** Returns overall bashing resistance for the body_part */
int get_armor_bash( body_part bp ) const override;
int get_armor_bash( bodypart_id bp ) const override;
/** Returns overall cutting resistance for the body_part */
int get_armor_cut( body_part bp ) const override;
int get_armor_cut( bodypart_id bp ) const override;
/** Returns bashing resistance from the creature and armor only */
int get_armor_bash_base( body_part bp ) const override;
int get_armor_bash_base( bodypart_id bp ) const override;
/** Returns cutting resistance from the creature and armor only */
int get_armor_cut_base( body_part bp ) const override;
int get_armor_cut_base( bodypart_id bp ) const override;
/** Returns overall env_resist on a body_part */
int get_env_resist( body_part bp ) const override;
int get_env_resist( bodypart_id bp ) const override;
/** Returns overall acid resistance for the body part */
int get_armor_acid( body_part bp ) const;
int get_armor_acid( bodypart_id bp ) const;
/** Returns overall resistance to given type on the bod part */
int get_armor_type( damage_type dt, body_part bp ) const override;
int get_armor_type( damage_type dt, bodypart_id bp ) const override;

int get_stim() const;
void set_stim( int new_stim );
Expand Down
Loading

0 comments on commit cf96ad4

Please sign in to comment.