Skip to content

Commit

Permalink
Adjust grenade values (#37585)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian-Otten authored Feb 11, 2020
1 parent 74040d0 commit 6d26b22
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion data/json/items/tool/explosives.json
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@
"sound_volume": 0,
"sound_msg": "Tick.",
"no_deactivate_msg": "You've already pulled the %s's pin; try throwing it instead.",
"explosion": { "power": 185, "shrapnel": 212 }
"explosion": { "power": 240, "shrapnel": { "casing_mass": 217, "fragment_mass": 0.15 } }
},
"flags": [ "BOMB", "TRADER_AVOID" ]
},
Expand Down
6 changes: 3 additions & 3 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ shrapnel_data load_shrapnel_data( const JsonObject &jo )
// Casing mass is mandatory
jo.read( "casing_mass", ret.casing_mass );
// Rest isn't
ret.fragment_mass = jo.get_float( "fragment_mass", 0.005 );
ret.fragment_mass = jo.get_float( "fragment_mass", 0.15 );
ret.recovery = jo.get_int( "recovery", 0 );
ret.drop = itype_id( jo.get_string( "drop", "null" ) );
return ret;
Expand Down Expand Up @@ -448,9 +448,9 @@ static std::vector<tripoint> shrapnel( const tripoint &src, int power,
}
if( g->m.impassable( target ) ) {
if( optional_vpart_position vp = g->m.veh_at( target ) ) {
vp->vehicle().damage( vp->part_index(), damage );
vp->vehicle().damage( vp->part_index(), damage / 100 );
} else {
g->m.bash( target, damage / 10, true );
g->m.bash( target, damage / 100, true );
}
}
}
Expand Down
29 changes: 19 additions & 10 deletions tests/explosion_balance_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@
#include "type_id.h"
#include "point.h"

enum class outcome_type {
Kill, Casualty
};

static void check_lethality( const std::string &explosive_id, const int range, float lethality,
float margin )
float margin, outcome_type expected_outcome )
{
const epsilon_threshold target_lethality{ lethality, margin };
int num_survivors = 0;
int num_subjects = 0;
int num_wounded = 0;
statistics<bool> deaths;
statistics<bool> victims;
std::stringstream survivor_stats;
int total_hp = 0;
do {
Expand Down Expand Up @@ -56,17 +60,22 @@ static void check_lethality( const std::string &explosive_id, const int range, f
num_survivors += survivors.size();
for( Creature *survivor : survivors ) {
survivor_stats << survivor->pos() << " " << survivor->get_hp() << ", ";
num_wounded += ( survivor->get_hp() < survivor->get_hp_max() ) ? 1 : 0;
bool wounded = survivor->get_hp() < survivor->get_hp_max();
num_wounded += wounded ? 1 : 0;
total_hp += survivor->get_hp();
deaths.add( false );
if( expected_outcome == outcome_type::Casualty && wounded ) {
victims.add( true );
} else {
victims.add( false );
}
}
if( !survivors.empty() ) {
survivor_stats << std::endl;
}
for( int i = survivors.size(); i < num_subjects_this_time; ++i ) {
deaths.add( true );
victims.add( true );
}
} while( deaths.uncertain_about( target_lethality ) );
} while( victims.uncertain_about( target_lethality ) );
CAPTURE( margin );
INFO( explosive_id );
INFO( "range " << range );
Expand All @@ -75,7 +84,7 @@ static void check_lethality( const std::string &explosive_id, const int range, f
INFO( "Wounded survivors: " << num_wounded );
const int average_hp = num_survivors ? total_hp / num_survivors : 0;
INFO( "average hp of survivors: " << average_hp );
CHECK( deaths.avg() == Approx( lethality ).margin( margin ) );
CHECK( victims.avg() == Approx( lethality ).margin( margin ) );
}

static std::vector<int> get_part_hp( vehicle *veh )
Expand Down Expand Up @@ -125,11 +134,11 @@ static void check_vehicle_damage( const std::string &explosive_id, const std::st

TEST_CASE( "grenade_lethality", "[grenade],[explosion],[balance]" )
{
check_lethality( "grenade_act", 5, 0.95, 0.06 );
check_lethality( "grenade_act", 15, 0.40, 0.06 );
check_lethality( "grenade_act", 5, 0.95, 0.06, outcome_type::Kill );
check_lethality( "grenade_act", 15, 0.40, 0.06, outcome_type::Casualty );
}

TEST_CASE( "grenade_vs_vehicle", "[grenade],[explosion],[balance]" )
{
check_vehicle_damage( "grenade_act", "car", 5 );
}
}

0 comments on commit 6d26b22

Please sign in to comment.