Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ablative armor can cover more than base armor #58331

Merged
merged 2 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions data/mods/TEST_DATA/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,67 @@
}
]
},
{
"id": "test_ghost_vest",
"type": "ARMOR",
"category": "armor",
"//": "Vest with no coverage to test if it still protects",
"name": { "str": "US ghost vest" },
"description": "Ballistic armor with specialized pockets on the front, back and sides for armored plates. The soft armor plate carrier is still protective but it won't stop high energy projectiles.",
"weight": "2911 g",
"volume": "6 L",
"price": 160000,
"price_postapoc": 1000,
"symbol": "[",
"material": [ "nylon", "kevlar" ],
"color": "light_gray",
"warmth": 15,
"flags": [ "STURDY", "OUTER", "WATER_FRIENDLY" ],
"use_action": [ { "type": "attach_molle", "size": 6 }, { "type": "detach_molle" } ],
"pocket_data": [
{
"pocket_type": "CONTAINER",
"ablative": true,
"volume_encumber_modifier": 0,
"max_contains_volume": "1600 ml",
"max_contains_weight": "5 kg",
"moves": 200,
"description": "Pocket for front plate",
"flag_restriction": [ "ABLATIVE_LARGE" ]
},
{
"pocket_type": "CONTAINER",
"ablative": true,
"volume_encumber_modifier": 0,
"max_contains_volume": "1600 ml",
"max_contains_weight": "5 kg",
"moves": 200,
"description": "Pocket for back plate",
"flag_restriction": [ "ABLATIVE_LARGE" ]
},
{
"pocket_type": "CONTAINER",
"ablative": true,
"volume_encumber_modifier": 0,
"max_contains_volume": "800 ml",
"max_contains_weight": "2 kg",
"moves": 200,
"description": "Pocket for right side plate",
"flag_restriction": [ "ABLATIVE_MEDIUM" ]
},
{
"pocket_type": "CONTAINER",
"ablative": true,
"volume_encumber_modifier": 0,
"max_contains_volume": "800 ml",
"max_contains_weight": "2 kg",
"moves": 200,
"description": "Pocket for left side plate",
"flag_restriction": [ "ABLATIVE_MEDIUM" ]
}
],
"armor": [ { "encumbrance": 2, "coverage": 100, "covers": [ "torso" ], "specifically_covers": [ "torso_lower" ] } ]
},
{
"id": "test_plate",
"type": "ARMOR",
Expand Down
21 changes: 5 additions & 16 deletions src/character_armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,15 @@ bool Character::armor_absorb( damage_unit &du, item &armor, const bodypart_id &b
{
item::cover_type ctype = item::get_cover_type( du.type );

if( roll > armor.get_coverage( sbp, ctype ) ) {
return false;
}

// if the armor location has ablative armor apply that first
if( armor.is_ablative() ) {
ablative_armor_absorb( du, armor, sbp, roll );
}

// if we hit the specific location then we should continue with absorption as normal

// if the core armor is missed then exit
if( roll > armor.get_coverage( sbp, ctype ) ) {
return false;
}

// reduce the damage
// -1 is passed as roll so that each material is rolled individually
Expand Down Expand Up @@ -415,16 +413,7 @@ bool Character::ablative_armor_absorb( damage_unit &du, item &armor, const sub_b
// get the contained plate
item &ablative_armor = pocket->front();

float ablative_coverage = ablative_armor.get_coverage( bp, ctype );
float armor_coverage = armor.get_coverage( bp, ctype );

// ablative armor stores its overall coverage ex: covers 30% of the torso
// but if that plate is in a vest that only covers 60% of the torso then
// it covers 50% of the vest so need to scale the coverage appropriately
// since the attack has already hit the vest now we are checking if it hits
// a plate

float coverage = ( ablative_coverage / armor_coverage ) * 100;
float coverage = ablative_armor.get_coverage( bp, ctype );

// if the attack hits this plate
if( roll < coverage ) {
Expand Down
31 changes: 29 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,19 +859,46 @@ bool item::covers( const sub_bodypart_id &bp ) const
}

bool does_cover = false;
bool subpart_cover = false;

iterate_covered_sub_body_parts_internal( get_side(), [&]( const sub_bodypart_str_id & covered ) {
does_cover = does_cover || bp == covered;
} );
return does_cover;

// check if a piece of ablative armor covers the location
for( const item_pocket *pocket : get_all_contained_pockets() ) {
// if the pocket is ablative and not empty we should check it
if( pocket->get_pocket_data()->ablative && !pocket->empty() ) {
// get the contained plate
const item &ablative_armor = pocket->front();

subpart_cover = subpart_cover || ablative_armor.covers( bp );
}
}

return does_cover || subpart_cover;
}

bool item::covers( const bodypart_id &bp ) const
{
bool does_cover = false;
bool subpart_cover = false;
iterate_covered_body_parts_internal( get_side(), [&]( const bodypart_str_id & covered ) {
does_cover = does_cover || bp == covered;
} );
return does_cover;

// check if a piece of ablative armor covers the location
for( const item_pocket *pocket : get_all_contained_pockets() ) {
// if the pocket is ablative and not empty we should check it
if( pocket->get_pocket_data()->ablative && !pocket->empty() ) {
// get the contained plate
const item &ablative_armor = pocket->front();

subpart_cover = subpart_cover || ablative_armor.covers( bp );
}
}

return does_cover || subpart_cover;
}

cata::optional<side> item::covers_overlaps( const item &rhs ) const
Expand Down
54 changes: 54 additions & 0 deletions tests/coverage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,41 @@ static float get_avg_melee_dmg( std::string clothing_id, bool infect_risk = fals
return static_cast<float>( dam_acc ) / num_hits;
}

static float get_avg_melee_dmg( item cloth, bool infect_risk = false )
{
monster zed( mon_manhack, mon_pos );
standard_npc dude( "TestCharacter", dude_pos, {}, 0, 8, 8, 8, 8 );
if( infect_risk ) {
cloth.set_flag( json_flag_FILTHY );
}
int dam_acc = 0;
int num_hits = 0;
for( int i = 0; i < num_iters; i++ ) {
clear_character( dude, true );
dude.setpos( dude_pos );
dude.wear_item( cloth, false );
dude.add_effect( effect_sleep, 1_hours );
if( zed.melee_attack( dude, 10000.0f ) ) {
num_hits++;
}
cloth.set_damage( cloth.min_damage() );
if( !infect_risk ) {
dam_acc += dude.get_hp_max() - dude.get_hp();
} else if( dude.has_effect( effect_bite ) ) {
dam_acc++;
}
if( dude.is_dead() ) {
break;
}
}
CAPTURE( dude.is_dead() );
const std::string ret_type = infect_risk ? "infections" : "damage total";
INFO( string_format( "%s landed %d hits on character, causing %d %s.", zed.get_name(), num_hits,
dam_acc, ret_type ) );
num_hits = num_hits ? num_hits : 1;
return static_cast<float>( dam_acc ) / num_hits;
}

static float get_avg_bullet_dmg( std::string clothing_id )
{
clear_map();
Expand Down Expand Up @@ -181,3 +216,22 @@ TEST_CASE( "Proportional armor material resistances", "[material]" )
check_not_near( "Average damage", dmg, base_line, 0.05f );
}
}

TEST_CASE( "Ghost ablative vest", "[coverage]" )
{
SECTION( "Ablative not covered" ) {
item full = item( "test_ghost_vest" );
full.force_insert_item( item( "test_plate" ), item_pocket::pocket_type::CONTAINER );
full.force_insert_item( item( "test_plate" ), item_pocket::pocket_type::CONTAINER );
item empty = item( "test_ghost_vest" );

// make sure vest only covers torso_upper when it has armor in it
REQUIRE( full.covers( sub_bodypart_id( "torso_upper" ) ) );
REQUIRE( !empty.covers( sub_bodypart_id( "torso_upper" ) ) );
const float dmg_full = get_avg_melee_dmg( full );
const float dmg_empty = get_avg_melee_dmg( empty );
// make sure the armor is counting even if the base vest doesn't do anything
check_not_near( "Average damage", dmg_full, dmg_empty, 0.5f );
}
}