-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
fix ammo_capacity() and implement item_id_restriction infrastructure #40399
fix ammo_capacity() and implement item_id_restriction infrastructure #40399
Conversation
2c1fe2d
to
27eea0f
Compare
I'm trying to validate the JSON changes to the jackhammer (gas powered) using this branch and I'm getting an exception in xtree when reloading the Jackhammer. Error reads: xtree Expression: map/set iterators in range are from different containers I have the callstack if it's useful to you. This was after updating the JSON to have a pocket magazine that can only contain gasoline. Callstack -
|
ok there might be a bit of scop creep here, but i need to get it to where the bugs i introduced with the adjustments to the foundational functions get reduced. i'm going to keep this in draft for a while so that it's transparent what i'm doing |
Did some testing with these changes. Was able to add the new "MAGAZINE_WELL" type pocket to the json of a few items to test out. So far it seems to work better at least - though I still see things like this: 01:07:49.721 ERROR : src\item.cpp:600 [ammo_set] Tried to set invalid magazine of batteries for medium plutonium fuel battery when trying to reload an item that I set with the following:
However when I go to reload them it seems to work fine and only shows me valid items in my list of reload targets. |
d88a94e
to
b93d9b0
Compare
Looks like this unhooked the vehicle tool crafting checks - Save below. |
1bebf0b
to
39430da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. From here the rest of the reloading and ammo consumption work should go much quicker.
|
||
const itype *loaded_ammo = ammo_data(); | ||
if( loaded_ammo == nullptr ) { | ||
return ammo_capacity( item::find_type( ammo_default() )->ammo->type ) - ammo_remaining(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can this give meaningful numbers under the new system without a current ammotype?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is used in a couple places to ask "can this be reloaded?" and sometimes there's no ammo type available. I thought that it would make sense to have the default ammo as a fallback if there was no ammo loaded in order to calculate some number, instead of just returning 0.
This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there: https://discourse.cataclysmdda.org/t/psa-nested-containers-is-now-live-in-experimental/23529/62 |
9fc3ba3
to
d0be7ce
Compare
0891abc
to
93118fd
Compare
Wielded gun, hit 'f'ire, nothing happened. |
93118fd
to
09c475b
Compare
594fb28
to
eef1fcb
Compare
since it will be handled as a container, is it now possible to load a weapon with different types of ammo (for example FMJ and AP)? And if so, what ammo will it use? The one loaded in last? |
eef1fcb
to
6782ad0
Compare
not as of this PR, MAGAZINE type pockets when using ammo_restriction only take 1 stack of items. you might be able to fudge it by using item_restriction maybe, but that would be a pretty hacky solution imo and mod-only because of it, for now |
* Added magazine pocket data to all relevant items, allowing them to be loaded. I'll need to retest after CleverRaven/Cataclysm-DDA#40399 is merged to confirm that unloading will work afterward, but now at least it actually loads and uses charges properly. * Reworked several transforming items to account for the fact that you can no longer change an item with ammo into an active item with null ammotype. * Hammers of the hunter now call their flashbang via spell, needed at bare minimum to YASD-proof it slightly via retaining the needs_wielding boolean. While I had to engage in some dirty hacks to work around the fact that flashbang spells don't do anything to NPCs, this had the side benefit of letting me ditch the never-actually-worked on-hit effect for a more direct subspell, explicitly burning and further debuffing SUNDEATH monsters. * Veinreavers now have to use 3 charges of blood essence instead of just one. The explosion has been buffed slightly and the timer shortened by two turns, as a direct result of this change. * Due to technical issues, I had to effectively choose between ARTC_PORTAL and being able to load it with crystallized essence, because artifact charging doesn't sanely translate into ammo that actually exists. I decided, after soliciting feedback from various people, that retaining ARTC_PORTAL was the more interesting option. As a minor side effect it no longer has a cutting quality, and can store up to 10 charges. * However, I added a less direct way to translate crystallized essence into charges for the restored ritual blade. Slivers of reality, implied to be relevant for backstory rituals like the Dragonblood Sacrament and other non-standard summoning, its function is basically a disposable, single-use portal generator. Since crafting it requires crystallized essence to provide the raw power-spike needed, this can indirectly be used to fuel the restored ritual blade that way. Lore-wise however, doing that is something He From Beyond The Veil would frown upon, and if ter-transform could cite traps I'd make it a spell item in order to add some more interesting side effects.
This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there: https://discourse.cataclysmdda.org/t/psa-nested-containers-is-now-live-in-experimental/23529/94 |
@@ -6143,7 +6179,7 @@ bool item::is_bionic() const | |||
|
|||
bool item::is_magazine() const | |||
{ | |||
return !!type->magazine; | |||
return !!type->magazine || contents.has_pocket_type( item_pocket::pocket_type::MAGAZINE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change means that things that use this to gate accessing type->magazine
will no longer work, and will crash on attempting to access non-existent magazine data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is true, and i have come across these that do cause crashes and fixed them. islot_magazine is on the chopping block in favor of pocket_data (need to check with yutna for sure but i'm confident that this is true), and if i do not have this bool in here it will backpedal a lot of the work on this pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not this one
https://github.com/CleverRaven/Cataclysm-DDA/pull/40399/files#diff-f7ca61cf749eba039da961e8a7be1630L8408
if( !is_magazine() || !type->magazine->protects_contents ) {
Co-authored-by: anothersimulacrum <[email protected]>
Summary
SUMMARY: Infrastructure "fix ammo_capacity() and implement item_id_restriction infrastructure"
Purpose of change
This fixes the bug with not being able to load sewing kits. It also makes it so the magazine code relies more on pockets than the islots. This PR also requires that gun json gets updated first, because copy-from is being very frustratingly broken with the item factory fake pocket loading code.
So, when you get the ammo_capacity() of an item, before you know it could only have 1 type of clip_size whether it's a mag or a gun. however, now, you can have a different clip size (for lack of better term) per ammotype per pocket - so it's imperative that is calculated correctly.
After working on this from the ammo_capacity direction, it became clear to me that i needed to implement item_id_restriction and MAGAZINE_WELL type pockets in order for the gun/reloading/unloading code to work properly.
Describe alternatives you've considered
Testing
TBD - running the tests locally for now is breaking things
Additional Comments
Closes #40382
Fixes #40315
Fixes #40158
Fixes #40307
Fixes #40203
Fixes #40125