Skip to content

Commit

Permalink
feat: firing message instead of printing all player-made combat sound…
Browse files Browse the repository at this point in the history
…s, allow fragmentation explosions to create sounds (#5344)

* commit for remote

* feat: firing message instead of printing all player-made combat sounds, allow fragmentation explosions to create sounds

* Fix a lil oops
  • Loading branch information
chaosvolt authored Sep 13, 2024
1 parent da15597 commit 0f81ec7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
18 changes: 18 additions & 0 deletions data/json/ammo_effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@
"type": "ammo_effect",
"explosion": { "fragment": { "impact": { "damage_type": "bullet", "amount": 30, "armor_multiplier": 2.5 }, "range": 3 } }
},
{
"id": "EXPLOSIVE_PLUS_FRAG",
"type": "ammo_effect",
"explosion": {
"damage": 50,
"radius": 3,
"fragment": { "impact": { "damage_type": "bullet", "amount": 50, "armor_multiplier": 2 }, "range": 5 }
}
},
{
"id": "EXPLOSIVE_BIG_PLUS_FRAG",
"type": "ammo_effect",
"explosion": {
"damage": 70,
"radius": 5,
"fragment": { "impact": { "damage_type": "bullet", "amount": 50, "armor_multiplier": 2 }, "range": 5 }
}
},
{
"id": "MININUKE_MOD",
"type": "ammo_effect",
Expand Down
4 changes: 2 additions & 2 deletions data/json/items/ammo/84x246mm.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"recoil": 45,
"count": 4,
"stack_size": 1,
"effects": [ "COOKOFF", "EXPLOSIVE_BIG", "FRAG", "NEVER_MISFIRES" ]
"effects": [ "COOKOFF", "EXPLOSIVE_BIG_PLUS_FRAG", "NEVER_MISFIRES" ]
},
{
"type": "AMMO",
Expand Down Expand Up @@ -52,6 +52,6 @@
"range": 140,
"dispersion": 30,
"extend": { "effects": [ "SMOKE_BIG" ] },
"delete": { "effects": [ "EXPLOSIVE_BIG", "FRAG" ] }
"delete": { "effects": [ "EXPLOSIVE_BIG_PLUS_FRAG" ] }
}
]
2 changes: 1 addition & 1 deletion data/json/items/ammo/rpg.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"range": 60,
"dispersion": 75,
"recoil": 450,
"effects": [ "COOKOFF", "EXPLOSIVE", "FRAG", "TRAIL", "NEVER_MISFIRES" ]
"effects": [ "COOKOFF", "EXPLOSIVE_PLUS_FRAG", "TRAIL", "NEVER_MISFIRES" ]
},
{
"type": "AMMO",
Expand Down
9 changes: 7 additions & 2 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,14 @@ void explosion_funcs::regular( const queued_explosion &qe )
{
const tripoint &p = qe.pos;
const explosion_data &ex = qe.exp_data;
auto &shr = ex.fragment;

int base_noise = ex.damage;
if( shr ) {
base_noise = shr.value().impact.total_damage();
}

const int noise = ex.damage / explosion_handler::power_to_dmg_mult * ( ex.fire ? 2 : 10 );
const int noise = base_noise / explosion_handler::power_to_dmg_mult * ( ex.fire ? 2 : 10 );
if( noise >= 30 ) {
sounds::sound( p, noise, sounds::sound_t::combat, _( "a huge explosion!" ), false, "explosion",
"huge" );
Expand All @@ -1450,7 +1456,6 @@ void explosion_funcs::regular( const queued_explosion &qe )

std::map<const Creature *, int> damaged_by_blast;
std::map<const Creature *, int> damaged_by_shrapnel;
auto &shr = ex.fragment;

if( get_option<bool>( "OLD_EXPLOSIONS" ) ) {
if( shr ) {
Expand Down
32 changes: 23 additions & 9 deletions src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,20 @@ dispersion_sources calculate_dispersion( const map &m, const Character &who, con
return dispersion;
}

static int calc_gun_volume( const item &gun )
{
int noise = gun.type->gun->loudness;
for( const auto mod : gun.gunmods() ) {
noise += mod->type->gunmod->loudness;
}
if( gun.ammo_data() ) {
noise += gun.ammo_data()->ammo->loudness;
}

noise = std::max( noise, 0 );
return noise;
}

int ranged::fire_gun( Character &who, const tripoint &target, int shots )
{
return fire_gun( who, target, shots, who.primary_weapon(), nullptr );
Expand Down Expand Up @@ -934,6 +948,14 @@ int ranged::fire_gun( Character &who, const tripoint &target, int max_shots, ite
}
curshot++;

int noise = calc_gun_volume( gun );
if( !who.is_deaf() && noise > 0 ) {
who.add_msg_if_player( m_warning, _( "You fire your %s, %s" ),
gun.tname(), gun.gun_noise( shots > 1 ).sound );
} else {
who.add_msg_if_player( m_warning, _( "You fire your %s!" ),
gun.tname() );
}
ranged::make_gun_sound_effect( who, shots > 1, gun );

cycle_action( gun, who.pos() );
Expand Down Expand Up @@ -1842,15 +1864,7 @@ item::sound_data item::gun_noise( const bool burst ) const
return { 0, "" };
}

int noise = type->gun->loudness;
for( const auto mod : gunmods() ) {
noise += mod->type->gunmod->loudness;
}
if( ammo_data() ) {
noise += ammo_data()->ammo->loudness;
}

noise = std::max( noise, 0 );
int noise = calc_gun_volume( *this );

if( type->weapon_category.count( weapon_cat_WATER_CANNONS ) ) {
return { noise, _( "Splash!" ) };
Expand Down
2 changes: 1 addition & 1 deletion src/sounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ static bool describe_sound( sounds::sound_t category, bool from_player_position
case sounds::sound_t::movement:
case sounds::sound_t::activity:
case sounds::sound_t::destructive_activity:
case sounds::sound_t::combat:
case sounds::sound_t::alert:
case sounds::sound_t::order:
case sounds::sound_t::speech:
return false;
case sounds::sound_t::electronic_speech:
case sounds::sound_t::alarm:
case sounds::sound_t::combat:
return true;
}
} else {
Expand Down

0 comments on commit 0f81ec7

Please sign in to comment.