From 073843eaedb64b7542a428596ba2f633dfb87f3a Mon Sep 17 00:00:00 2001 From: bombasticSlacks Date: Sat, 23 Jul 2022 10:26:47 -0300 Subject: [PATCH 1/5] damage scaling appropriately --- src/item.cpp | 196 ++++++++++++++++++++------------------------------- src/item.h | 5 ++ 2 files changed, 83 insertions(+), 118 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 1c7bfce69a042..009b785a82cf1 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -794,6 +794,15 @@ int item::damage_level( int dmg ) const } } +float item::damage_scaling( bool to_self ) const +{ + float scale = damage_level() * .125f; + // caps the scale if this is a hit to the player vs the item itself + // reinforce only effects the item + scale = to_self ? std::min( scale, 0.0f ) : std::max( scale, 0.0f ); + return 100.0f - scale; +} + int item::damage_floor( bool allow_negative ) const { return std::max( min_damage() + degradation(), allow_negative ? min_damage() : 0 ); @@ -8039,32 +8048,30 @@ float item::bash_resist( bool to_self, const bodypart_id &bp, int roll ) const float resist = 0.0f; float mod = get_clothing_mod_val( clothing_mod_type_bash ); - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + + const float damage_scale = damage_scaling( to_self ); if( !bp_null ) { const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->bash_resist() * eff_thic; + resist += m->id->bash_resist() * m->thickness; } } - return resist + mod; + return ( resist + mod ) * damage_scale; } } // base resistance // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = bp_null ? get_thickness() : get_thickness( bp ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8075,7 +8082,7 @@ float item::bash_resist( bool to_self, const bodypart_id &bp, int roll ) const resist /= total; } - return ( resist * eff_thickness ) + mod; + return ( resist + mod ) * damage_scale; } float item::bash_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8086,30 +8093,27 @@ float item::bash_resist( const sub_bodypart_id &bp, bool to_self, int roll ) con float resist = 0.0f; float mod = get_clothing_mod_val( clothing_mod_type_bash ); - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + const float damage_scale = damage_scaling( to_self ); const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->bash_resist() * eff_thic; + resist += m->id->bash_resist() * m->thickness; } } - return resist + mod; + return ( resist + mod ) * damage_scale; } // base resistance this chunk is needed for items defined the old materials way // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = get_thickness( bp->parent ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8120,7 +8124,7 @@ float item::bash_resist( const sub_bodypart_id &bp, bool to_self, int roll ) con resist /= total; } - return ( resist * eff_thickness ) + mod; + return ( resist + mod ) * damage_scale; } @@ -8132,33 +8136,31 @@ float item::cut_resist( bool to_self, const bodypart_id &bp, int roll ) const const bool bp_null = bp == bodypart_id(); float resist = 0.0f; - float mod = get_clothing_mod_val( clothing_mod_type_cut ); - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + + const float damage_scale = damage_scaling( to_self ); if( !bp_null ) { const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->cut_resist() * eff_thic; + resist += m->id->cut_resist() * m->thickness; } } - return resist + mod; + return ( resist + mod ) * damage_scale; } } // base resistance // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = bp_null ? get_thickness() : get_thickness( bp ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8169,7 +8171,7 @@ float item::cut_resist( bool to_self, const bodypart_id &bp, int roll ) const resist /= total; } - return ( resist * eff_thickness ) + mod; + return ( resist + mod ) * damage_scale; } float item::cut_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8179,31 +8181,28 @@ float item::cut_resist( const sub_bodypart_id &bp, bool to_self, int roll ) cons } float resist = 0.0f; - float mod = get_clothing_mod_val( clothing_mod_type_cut ); - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + const float damage_scale = damage_scaling( to_self ); const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->cut_resist() * eff_thic; + resist += m->id->cut_resist() * m->thickness; } } - return resist + mod; + return ( resist + mod ) * damage_scale; } // base resistance this chunk is needed for items defined the old materials way // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = get_thickness( bp->parent ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8214,7 +8213,8 @@ float item::cut_resist( const sub_bodypart_id &bp, bool to_self, int roll ) cons resist /= total; } - return ( resist * eff_thickness ) + mod; + return ( resist + mod ) * damage_scale; + } #if defined(_MSC_VER) @@ -8241,33 +8241,31 @@ float item::bullet_resist( bool to_self, const bodypart_id &bp, int roll ) const const bool bp_null = bp == bodypart_id(); float resist = 0.0f; - float mod = get_clothing_mod_val( clothing_mod_type_bullet ); - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + + const float damage_scale = damage_scaling( to_self ); if( !bp_null ) { const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->bullet_resist() * eff_thic; + resist += m->id->bullet_resist() * m->thickness; } } - return resist + mod; + return ( resist + mod ) * damage_scale; } } // base resistance // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = bp_null ? get_thickness() : get_thickness( bp ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8278,7 +8276,7 @@ float item::bullet_resist( bool to_self, const bodypart_id &bp, int roll ) const resist /= total; } - return ( resist * eff_thickness ) + mod; + return ( resist + mod ) * damage_scale; } float item::bullet_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8288,31 +8286,28 @@ float item::bullet_resist( const sub_bodypart_id &bp, bool to_self, int roll ) c } float resist = 0.0f; - float mod = get_clothing_mod_val( clothing_mod_type_bullet ); - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + const float damage_scale = damage_scaling( to_self ); const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->bullet_resist() * eff_thic; + resist += m->id->bullet_resist() * m->thickness; } } - return resist + mod; + return ( resist + mod ) * damage_scale; } // base resistance this chunk is needed for items defined the old materials way // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = get_thickness( bp->parent ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8323,48 +8318,43 @@ float item::bullet_resist( const sub_bodypart_id &bp, bool to_self, int roll ) c resist /= total; } - return ( resist * eff_thickness ) + mod; + return ( resist + mod ) * damage_scale; + } float item::biological_resist( bool to_self, const bodypart_id &bp, int roll ) const { - if( to_self ) { - // Currently no items are damaged by acid - return std::numeric_limits::max(); - } - if( is_null() ) { return 0.0f; } const bool bp_null = bp == bodypart_id(); float resist = 0.0f; - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + + const float damage_scale = damage_scaling( to_self ); if( !bp_null ) { const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->biological_resist() * eff_thic; + resist += m->id->biological_resist() * m->thickness; } } - return resist; + return ( resist + mod ) * damage_scale; } } // base resistance // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = bp_null ? get_thickness() : get_thickness( bp ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8375,45 +8365,38 @@ float item::biological_resist( bool to_self, const bodypart_id &bp, int roll ) c resist /= total; } - return resist * eff_thickness; + return ( resist + mod ) * damage_scale; } float item::biological_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const { - if( to_self ) { - // Currently no items are damaged by acid - return std::numeric_limits::max(); - } - if( is_null() ) { return 0.0f; } float resist = 0.0f; - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + const float damage_scale = damage_scaling( to_self ); const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->biological_resist() * eff_thic; + resist += m->id->biological_resist() * m->thickness; } } - return resist; + return ( resist + mod ) * damage_scale; } // base resistance this chunk is needed for items defined the old materials way // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = get_thickness( bp->parent ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8424,48 +8407,43 @@ float item::biological_resist( const sub_bodypart_id &bp, bool to_self, int roll resist /= total; } - return resist * eff_thickness; + return ( resist + mod ) * damage_scale; + } float item::electric_resist( bool to_self, const bodypart_id &bp, int roll ) const { - if( to_self ) { - // Currently no items are damaged by acid - return std::numeric_limits::max(); - } - if( is_null() ) { return 0.0f; } const bool bp_null = bp == bodypart_id(); float resist = 0.0f; - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + + const float damage_scale = damage_scaling( to_self ); if( !bp_null ) { const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->elec_resist() * eff_thic; + resist += m->id->elec_resist() * m->thickness; } } - return resist; + return ( resist + mod ) * damage_scale; } } // base resistance // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = bp_null ? get_thickness() : get_thickness( bp ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8476,45 +8454,38 @@ float item::electric_resist( bool to_self, const bodypart_id &bp, int roll ) con resist /= total; } - return resist * eff_thickness; + return ( resist + mod ) * damage_scale; } float item::electric_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const { - if( to_self ) { - // Currently no items are damaged by acid - return std::numeric_limits::max(); - } - if( is_null() ) { return 0.0f; } float resist = 0.0f; - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + const float damage_scale = damage_scaling( to_self ); const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->elec_resist() * eff_thic; + resist += m->id->elec_resist() * m->thickness; } } - return resist; + return ( resist + mod ) * damage_scale; } // base resistance this chunk is needed for items defined the old materials way // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = get_thickness( bp->parent ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8525,48 +8496,43 @@ float item::electric_resist( const sub_bodypart_id &bp, bool to_self, int roll ) resist /= total; } - return resist * eff_thickness; + return ( resist + mod ) * damage_scale; + } float item::cold_resist( bool to_self, const bodypart_id &bp, int roll ) const { - if( to_self ) { - // Currently no items are damaged by acid - return std::numeric_limits::max(); - } - if( is_null() ) { return 0.0f; } const bool bp_null = bp == bodypart_id(); float resist = 0.0f; - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + + const float damage_scale = damage_scaling( to_self ); if( !bp_null ) { const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->cold_resist() * eff_thic; + resist += m->id->cold_resist() * m->thickness; } } - return resist; + return ( resist + mod ) * damage_scale; } } // base resistance // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = bp_null ? get_thickness() : get_thickness( bp ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8577,45 +8543,38 @@ float item::cold_resist( bool to_self, const bodypart_id &bp, int roll ) const resist /= total; } - return resist * eff_thickness; + return ( resist + mod ) * damage_scale; } float item::cold_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const { - if( to_self ) { - // Currently no items are damaged by acid - return std::numeric_limits::max(); - } - if( is_null() ) { return 0.0f; } float resist = 0.0f; - const int dmg = damage_level(); - const float eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 ); + float mod = get_clothing_mod_val( clothing_mod_type_bash ); + const float damage_scale = damage_scaling( to_self ); const std::vector &armor_mats = armor_made_of( bp ); // If we have armour portion materials for this body part, use that instead if( !armor_mats.empty() ) { for( const part_material *m : armor_mats ) { - const float eff_thic = std::max( 0.1f, m->thickness - eff_damage ); // only count the material if it's hit // if roll is -1 each material is rolled at this point individually int internal_roll; roll < 0 ? internal_roll = rng( 0, 99 ) : internal_roll = roll; if( internal_roll < m->cover ) { - resist += m->id->cold_resist() * eff_thic; + resist += m->id->cold_resist() * m->thickness; } } - return resist; + return ( resist + mod ) * damage_scale; } // base resistance this chunk is needed for items defined the old materials way // Don't give reinforced items +armor, just more resistance to ripping const float avg_thickness = get_thickness( bp->parent ); - const float eff_thickness = std::max( 0.1f, avg_thickness - eff_damage ); const int total = type->mat_portion_total == 0 ? 1 : type->mat_portion_total; const std::map mats = made_of(); if( !mats.empty() ) { @@ -8626,7 +8585,8 @@ float item::cold_resist( const sub_bodypart_id &bp, bool to_self, int roll ) con resist /= total; } - return resist * eff_thickness; + return ( resist + mod ) * damage_scale; + } float item::acid_resist( bool to_self, int base_env_resist, const bodypart_id &bp ) const diff --git a/src/item.h b/src/item.h index 5659dcd1a5db2..6a0571028804f 100644 --- a/src/item.h +++ b/src/item.h @@ -1298,6 +1298,11 @@ class item : public visitable */ int damage_level( int dmg = INT_MIN ) const; + /** + * Returns a scaling value for armor values based on damage taken + */ + float damage_scaling( bool to_self = false ) const; + /** * Get the minimum possible damage this item can be repaired to, * accounting for degradation. From c94f908c8b9f95e4e35450264845c654fad2d0bf Mon Sep 17 00:00:00 2001 From: bombasticSlacks Date: Sat, 23 Jul 2022 16:34:26 -0300 Subject: [PATCH 2/5] missed scaling by avg thickness --- src/item.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 009b785a82cf1..f444903c5ccc7 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -8082,7 +8082,7 @@ float item::bash_resist( bool to_self, const bodypart_id &bp, int roll ) const resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } float item::bash_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8124,7 +8124,7 @@ float item::bash_resist( const sub_bodypart_id &bp, bool to_self, int roll ) con resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } @@ -8171,7 +8171,7 @@ float item::cut_resist( bool to_self, const bodypart_id &bp, int roll ) const resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } float item::cut_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8213,7 +8213,7 @@ float item::cut_resist( const sub_bodypart_id &bp, bool to_self, int roll ) cons resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } @@ -8276,7 +8276,7 @@ float item::bullet_resist( bool to_self, const bodypart_id &bp, int roll ) const resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } float item::bullet_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8318,7 +8318,7 @@ float item::bullet_resist( const sub_bodypart_id &bp, bool to_self, int roll ) c resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } @@ -8365,7 +8365,7 @@ float item::biological_resist( bool to_self, const bodypart_id &bp, int roll ) c resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } float item::biological_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8407,7 +8407,7 @@ float item::biological_resist( const sub_bodypart_id &bp, bool to_self, int roll resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } @@ -8454,7 +8454,7 @@ float item::electric_resist( bool to_self, const bodypart_id &bp, int roll ) con resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } float item::electric_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8496,7 +8496,7 @@ float item::electric_resist( const sub_bodypart_id &bp, bool to_self, int roll ) resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } @@ -8543,7 +8543,7 @@ float item::cold_resist( bool to_self, const bodypart_id &bp, int roll ) const resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } float item::cold_resist( const sub_bodypart_id &bp, bool to_self, int roll ) const @@ -8585,7 +8585,7 @@ float item::cold_resist( const sub_bodypart_id &bp, bool to_self, int roll ) con resist /= total; } - return ( resist + mod ) * damage_scale; + return ( resist * avg_thickness + mod ) * damage_scale; } From 8a91ed309d2f4f9c5d300660ec0460ace336e90e Mon Sep 17 00:00:00 2001 From: bombasticSlacks Date: Sat, 23 Jul 2022 19:50:51 -0300 Subject: [PATCH 3/5] I'm bad at math --- src/item.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index f444903c5ccc7..7462d8071f90e 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -798,9 +798,9 @@ float item::damage_scaling( bool to_self ) const { float scale = damage_level() * .125f; // caps the scale if this is a hit to the player vs the item itself - // reinforce only effects the item - scale = to_self ? std::min( scale, 0.0f ) : std::max( scale, 0.0f ); - return 100.0f - scale; + scale = 100.0f - scale; + // reinforce only effects damage to the item proper otherwise max scaling is 100f + return to_self ? scale : std::min( scale, 100.0f ); } int item::damage_floor( bool allow_negative ) const From 857382141001feaefb8c7ec1b69be8388d919273 Mon Sep 17 00:00:00 2001 From: bombasticSlacks Date: Sat, 23 Jul 2022 23:23:23 -0300 Subject: [PATCH 4/5] scaling by 100 not 1 in magnitude --- src/item.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 7462d8071f90e..e43f84eeb24f9 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -798,9 +798,9 @@ float item::damage_scaling( bool to_self ) const { float scale = damage_level() * .125f; // caps the scale if this is a hit to the player vs the item itself - scale = 100.0f - scale; + scale = 1.0f - scale; // reinforce only effects damage to the item proper otherwise max scaling is 100f - return to_self ? scale : std::min( scale, 100.0f ); + return to_self ? scale : std::min( scale, 1.0f ); } int item::damage_floor( bool allow_negative ) const From dbf7529d4628829d77bb54b3c5817cdae8e737fb Mon Sep 17 00:00:00 2001 From: bombasticSlacks Date: Sun, 24 Jul 2022 09:17:07 -0300 Subject: [PATCH 5/5] default thickness for items set to 1mm --- src/item.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index e43f84eeb24f9..091b53247364f 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -7851,8 +7851,10 @@ const armor_portion_data *item::portion_for_bodypart( const sub_bodypart_id &bod float item::get_thickness() const { const islot_armor *t = find_armor_data(); + // if an item isn't armor we assume it is 1mm thick + // TODO: Estimate normal items thickness or protection based on weight and density if( t == nullptr ) { - return is_pet_armor() ? type->pet_armor->thickness : 0.0f; + return is_pet_armor() ? type->pet_armor->thickness : 1.0f; } return t->avg_thickness(); } @@ -7860,6 +7862,7 @@ float item::get_thickness() const float item::get_thickness( const bodypart_id &bp ) const { const islot_armor *t = find_armor_data(); + // don't return a fixed value for this one since an item is never going to be covering a body part if( t == nullptr ) { return is_pet_armor() ? type->pet_armor->thickness : 0.0f; }