Skip to content

Commit

Permalink
More robust test for multi material portions (#55461)
Browse files Browse the repository at this point in the history
* super robust test

* fix divide by 0

* tougher armor to increase values
  • Loading branch information
bombasticSlacks authored Feb 19, 2022
1 parent 6149a27 commit 90b1c80
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 35 deletions.
95 changes: 65 additions & 30 deletions data/mods/TEST_DATA/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -2391,16 +2391,16 @@
"encumbrance": [ 12, 25 ],
"material": [
{ "type": "cotton", "covered_by_mat": 100, "thickness": 1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 }
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 }
]
},
{
Expand All @@ -2409,16 +2409,16 @@
"encumbrance": [ 12, 25 ],
"material": [
{ "type": "cotton", "covered_by_mat": 100, "thickness": 1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 }
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 }
]
},
{
Expand All @@ -2427,16 +2427,51 @@
"encumbrance": [ 12, 25 ],
"material": [
{ "type": "cotton", "covered_by_mat": 100, "thickness": 1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.1 }
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 0.3 }
]
}
]
},
{
"id": "test_portion_segmented_armor",
"type": "ARMOR",
"name": "Segmented armor",
"copy-from": "test_swat_armor",
"armor": [
{
"covers": [ "torso", "head", "mouth", "eyes" ],
"coverage": 100,
"encumbrance": [ 12, 25 ],
"material": [
{ "type": "cotton", "covered_by_mat": 100, "thickness": 1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 3 }
]
},
{
"covers": [ "leg_l", "leg_r", "foot_l", "foot_r" ],
"coverage": 100,
"encumbrance": [ 12, 25 ],
"material": [
{ "type": "cotton", "covered_by_mat": 100, "thickness": 1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 3 }
]
},
{
"covers": [ "arm_l", "arm_r", "hand_l", "hand_r" ],
"coverage": 100,
"encumbrance": [ 12, 25 ],
"material": [
{ "type": "cotton", "covered_by_mat": 100, "thickness": 1 },
{ "type": "steel", "covered_by_mat": 80, "thickness": 3 }
]
}
]
Expand Down
8 changes: 7 additions & 1 deletion src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,13 @@ void Item_factory::finalize_post( itype &obj )
// scale the value of portion covered based on how much total is covered
// if you proportionally only cover 5% of the arm but overall cover 50%
// you actually proportionally cover 10% of the armor
mat.cover = static_cast<float>( mat.cover ) / ( static_cast<float>( it.coverage ) / 100.0f );

// in case of 0 coverage just say the mats cover it all
if( it.coverage == 0 ) {
mat.cover = 100;
} else {
mat.cover = static_cast<float>( mat.cover ) / ( static_cast<float>( it.coverage ) / 100.0f );
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions tests/coverage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static constexpr tripoint badguy_pos( HALF_MAPSIZE_X + 1, HALF_MAPSIZE_Y, 0 );
static void check_near( std::string subject, float actual, const float expected,
const float tolerance )
{
THEN( string_format( "%s is about %.1f (+/- %.1f) with val %.1f", subject, expected, tolerance,
THEN( string_format( "%s is about %.1f (+/- %.2f) with val %.1f", subject, expected, tolerance,
actual ) ) {
CHECK( actual == Approx( expected ).margin( tolerance ) );
}
Expand Down Expand Up @@ -175,10 +175,9 @@ TEST_CASE( "Proportional armor material resistances", "[material]" )

SECTION( "Multi material segmented armor vs. melee" ) {
const float dmg = get_avg_melee_dmg( "test_multi_portion_segmented_armor" );
const float base_line = get_avg_melee_dmg( "test_portion_segmented_armor" );
// our armor should NOT be near 1 mm cloth + 80% of 1mm of steel
// and should be higher (so lower damage) since they can overlap
// this is cut damage of 12 so shouldn't be near 6 with small variance
// if it is someone broke material rolls
check_not_near( "Average damage", dmg, 6.0f, 0.1f );
check_not_near( "Average damage", dmg, base_line, 0.05f );
}
}

0 comments on commit 90b1c80

Please sign in to comment.