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

Fix ammo belts not scaling volume/weight with current amount of ammo

Open catdach opened this issue 2 years ago • 15 comments

Summary

Bugfixes "Fix ammo belts not scaling volume/weight with current amount of ammo"

Purpose of change

Fixes #57981

Describe the solution

Changed both weight and volume of the base magazine belt to 0. Changed all child belts to "rigid": false so that the volume changes depending on how many bullets are in it.

Describe alternatives you've considered

Logically, the volume and weight of the belt should be the sum of the bullets and linkages, but I couldn't figure out a good way to actually do that. To my surprise the game actually seems to do that on its own, at least for weight (but not for volume). I have no idea where in the code this is being done, but I'll take it a win I guess 🤷; I still don't know how to make it work for volume. 500: image

250: image

1: image

Testing

edit: error 1 no longer occurs as of #58191

error 1 details

Went into the game and spawned some ammo belts. Everything (mostly) seems to work fine except for an unrelated error that pops up when you try to make an ammo belt by activating belt linkage items on the ground. image

edit: error 2 no longer occurs as of #58625

error 2 details

Ok, hold on, I just ran into another error while writing this. to reproduce:

  1. Wear a subject suit (my test character spawns in one)
  2. spawn in and wear a high-volume rucksack
  3. pickup 250 5.56 NATO M855 and 250 .223 ammo belt linkages
  4. (A)ctivate the belt linkages, creating an ammo belt with 250 charges
  5. try to move
  6. error: image

Can be repeated as many times as you want by (U)nloading the belt and repeating steps 4 and 5.

It appears that the game puts the finished ammo belt in the subject suit pockets rather than the rucksack. image I'm not sure exactly how relevant this is to this PR; it could have something to do with me changing the volume of the base item, but the root of the problem seems to be in the logic of where items go when they are created from the ammobelt use_action maybe? Regardless, it's beyond me.

Additional context

The ammo belt class was originally given its weight an volume in #42509

Thanks a ton to mqrause for making #58191 and #58625 you're a legend. 😎

catdach avatar Jun 02 '22 21:06 catdach

I'm not sure exactly how relevant this is to this PR; it could have something to do with me changing the volume of the base item, but the root of the problem seems to be in the logic of where items go when they are created from the ammobelt use_action maybe?

When you create a belt from linkage, it first gets put into your inventory empty and then starts a reload action. I only took a glance at the code, but the reload action should normally handle the belt getting too big/heavy, so no idea what goes wrong there.

mqrause avatar Jun 02 '22 21:06 mqrause

IIRC i got this error even without the belt changes, so i think its not related to your pr Would be great if someone will test it on vanilla version tho

GuardianDll avatar Jun 03 '22 04:06 GuardianDll

IIRC i got this error even without the belt changes, so I think its not related to your pr Would be great if someone will test it on vanilla version tho

(I assume this is regarding the second error) I'm not sure. I assume this wouldn't happen without my changes to the volume of belts; if it was always at max volume like before, then the belt probably would never be placed in the smaller pocket to begin with.

As mqrause said, the reload action code should probably be dealing with this. So I don't the problem itself is because of this PR, but I'm not sure how it would possibly be replicated without this PR.

catdach avatar Jun 03 '22 16:06 catdach

Oh wait, thats another error image so i dont really know what to do with it or how to fix it

GuardianDll avatar Jun 03 '22 17:06 GuardianDll

Did you check if it works (mostly) properly with #58191 merged?

mqrause avatar Jun 21 '22 21:06 mqrause

Did you check if it works (mostly) properly with #58191 merged?

yeah, error 2 still happens, but error 1 doesn't.

catdach avatar Jun 22 '22 00:06 catdach

That's a fun bug exposing PR you have here.

mqrause avatar Jun 22 '22 11:06 mqrause

Does this work properly now?

mqrause avatar Jul 25 '22 22:07 mqrause

Thank-you so much, error 2 is now fixed. 🎉

Just one tiny thing, the game will now incorrectly say that the destination will be the subject suit: image When the actual destination is the high-volume rucksack (as it should be): image

catdach avatar Jul 26 '22 16:07 catdach

I think that is simply the current location of the item you want to reload. It's the destination of the ammo, not the destination of the belt? The empty belt gets spawned before reloading with ammo. And because the empty belt is small and the pocket system prefers the smallest possible pocket, it gets put into the subject suit first before being moved during reload because of the size increase.

mqrause avatar Jul 26 '22 17:07 mqrause

understood, I guess this PR is finally ready to go then.

catdach avatar Jul 26 '22 17:07 catdach

You need to fix cheap_ammo_pouch_belt223 and maybe other related ammo containers that were added in #58016 to fit the new belt volume/weight.

mqrause avatar Jul 26 '22 17:07 mqrause

The item density test seems to actually be failing due to the change in the ammo belts

Fris0uman avatar Aug 04 '22 11:08 Fris0uman

If I understand this right, the failing test is actually saying that the belts are not broken anymore. Above the check there's a comment saying // Failing? Just remove the relevant items from the known_bad list above and it fails only if the item density is not above the max allowed.

Edit: It's also not a critical failure, but should be fixed anyway.

mqrause avatar Aug 04 '22 11:08 mqrause

It still seems to be failing these tests. Am I doing this right?

catdach avatar Aug 10 '22 22:08 catdach

Yeah, the failures aren't your fault.

mqrause avatar Aug 11 '22 04:08 mqrause