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

Nonsensical shot damage calculation #79573

Open
DragonWizard23 opened this issue Feb 7, 2025 · 1 comment
Open

Nonsensical shot damage calculation #79573

DragonWizard23 opened this issue Feb 7, 2025 · 1 comment
Labels
(S1 - Need confirmation) Report waiting on confirmation of reproducibility

Comments

@DragonWizard23
Copy link
Contributor

Describe the bug

In the wield menu, the shot damage calculations don't always add up. The example in this save file is 0+27=24, but the inventory page for the gun itself has 26-2=24 damage.

Attach save file

Kamrar-trimmed.tar.gz

Steps to reproduce

  1. Check the inventory of the attached save file.

Expected behavior

I expected that the math would check out.

Screenshots

Image
Image

Versions and configuration

  • OS: Windows
    • OS Version: 10.0.26100.2894 (24H2)
  • Game Version: 5ad4199 [64-bit]
  • Graphics Version: Tiles
  • Game Language: System language []
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Portal Storms Ignore NPCs [personal_portal_storms],
    Slowdown Fungal Growth [no_fungal_growth]
    ]

Additional context

This bug does not cause the game to crash.

@DragonWizard23 DragonWizard23 added the (S1 - Need confirmation) Report waiting on confirmation of reproducibility label Feb 7, 2025
@oosyrag
Copy link
Contributor

oosyrag commented Feb 7, 2025

Relevant code lives at

const int total_damage = loc->gun_damage( true ).total_damage();
if( loc->has_ammo() ) {
const int basic_damage = loc->gun_damage( false ).total_damage();
const damage_instance &damage = loc->ammo_data()->ammo->damage;
if( !damage.empty() ) {
const float ammo_mult = damage.damage_units.front().unconditional_damage_mult;
if( ammo_mult != 1.0f ) {
return string_format( "%s<color_light_gray>*</color>%s <color_light_gray>=</color> %s",
get_damage_string( basic_damage, true ),
get_damage_string( ammo_mult, true ),
get_damage_string( total_damage, true )
);
}
}
const int ammo_damage = damage.total_damage();
return string_format( "%s<color_light_gray>+</color>%s <color_light_gray>=</color> %s",
get_damage_string( basic_damage, true ),
get_damage_string( ammo_damage, true ),
get_damage_string( total_damage, true )
);

and I'm presuming

Cataclysm-DDA/src/item.cpp

Lines 11057 to 11089 in baa0ca2

damage_instance item::gun_damage( bool with_ammo, bool shot ) const
{
if( !is_gun() ) {
return damage_instance();
}
units::length bl = barrel_length();
damage_instance ret = type->gun->damage.di_considering_length( bl );
for( const item *mod : gunmods() ) {
ret.add( mod->type->gunmod->damage.di_considering_length( bl ) );
}
if( with_ammo && has_ammo() ) {
if( shot ) {
ret.add( ammo_data()->ammo->shot_damage.di_considering_length( bl ) );
} else {
ret.add( ammo_data()->ammo->damage.di_considering_length( bl ) );
}
}
if( damage() > 0 ) {
// TODO: This isn't a good solution for multi-damage guns/ammos
for( damage_unit &du : ret ) {
if( du.amount <= 1.0 ) {
continue;
}
du.amount = std::max<float>( 1.0f, damage_adjusted_gun_damage( du.amount ) );
}
}
return ret;
}

but I don't know where to go from there or why basic_damage and ammo_damage values are incorrect, but total_damage is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(S1 - Need confirmation) Report waiting on confirmation of reproducibility
Projects
None yet
Development

No branches or pull requests

2 participants