Cataclysm-DDA icon indicating copy to clipboard operation
Cataclysm-DDA copied to clipboard

.22 LR ammo tray+ > .22 LR (50) item in inventory causing negative volume to be reported

Open misterprimus opened this issue 7 months ago • 1 comments

Describe the bug

Volume in drop menu displayed incorrectly.

Attach save file

West Covina-trimmed.tar.gz

Steps to reproduce

  1. d
  2. Observe free volume.

Expected behavior

No negative volume report.

Screenshots

Image

Image

Versions and configuration

  • OS: Windows
    • OS Version: 10.0.19045.5854 (22H2)
  • Game Version: cdda-experimental-2025-05-12-2102 [64-bit]
  • Graphics Version: Tiles
  • Game Language: English [en]
  • Mods loaded: [ Dark Days Ahead [dda], Disable NPC Needs [no_npc_food], Portal Storms Ignore NPCs [personal_portal_storms] ]

Additional context

No response

misterprimus avatar May 15 '25 03:05 misterprimus

/confirm

czyjanek avatar Jun 09 '25 18:06 czyjanek

The issue appears to be in item_contents::get_nested_content_volume_recursive()

https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/item_contents.cpp#L2564-L2566

It's... adding the pocket's unused volume? That just seems to be wrong as implemented.

RenechCDDA avatar Jul 30 '25 21:07 RenechCDDA

Simply removing those lines is not sufficient, this calculation seems to be totally wrong in general.

Image

See it says that we're carrying 0.21L of volume, but we're not. We're carrying 0.12L of volume (the ammo box which contains everything else).

RenechCDDA avatar Jul 30 '25 21:07 RenechCDDA

It's... adding the pocket's unused volume? That just seems to be wrong as implemented.

This is not wrong. The ammo trays are just very special cases. Ammo tray pockets don't have a volume, but an ammo_restriction, which means their volume is still the max volume internally (200,000 L). item_pocket::remaining_volume uses that value through item_pocket::volume_capacity, but for these ammo_restriction cases we have item_pocket::max_contains_volume instead (which however can still be slightly incorrect depending on allowed types and current contents, I believe).

I'm not sure if it's appropriate to simply replace the use in item_pocket::remaining_volume or if that could cause other issues in other places. It'd be a pretty simple fix at least. But to me it looks like ammo_restriction wasn't really designed to be used on container pockets.

mqrause avatar Jul 31 '25 06:07 mqrause

But to me it looks like ammo_restriction wasn't really designed to be used on container pockets.

AFAIK conceptually container pockets should not have ammo_restriction. They should be limited only by max length, rigidity weight capacity etc. They represent a general pocket. While magasine pockets are literally a magasine which is why they have ammo_restriction.

Brambor avatar Jul 31 '25 09:07 Brambor

So do we have a minimum-changes patch for 0.I in mind? I assume ammo_restriction was used for the ammo trays to avoid recalculating all the sizes etc if minor changes are done to the contents in the future.

RenechCDDA avatar Aug 01 '25 13:08 RenechCDDA

Please, see, test, or critique my PR #82179.

Brambor avatar Aug 01 '25 18:08 Brambor