Cataclysm-DDA
Cataclysm-DDA copied to clipboard
Fix ammo belts not scaling volume/weight with current amount of ammo
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:
250:
1:
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.
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:
- Wear a subject suit (my test character spawns in one)
- spawn in and wear a high-volume rucksack
- pickup 250
5.56 NATO M855
and 250.223 ammo belt linkages
- (A)ctivate the belt linkages, creating an ammo belt with 250 charges
- try to move
- error:
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.
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. 😎
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.
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
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.
Oh wait, thats another error
so i dont really know what to do with it or how to fix it
Did you check if it works (mostly) properly with #58191 merged?
Did you check if it works (mostly) properly with #58191 merged?
yeah, error 2 still happens, but error 1 doesn't.
That's a fun bug exposing PR you have here.
Does this work properly now?
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:
When the actual destination is the high-volume rucksack (as it should be):
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.
understood, I guess this PR is finally ready to go then.
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.
The item density test seems to actually be failing due to the change in the ammo belts
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.
It still seems to be failing these tests. Am I doing this right?
Yeah, the failures aren't your fault.