-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Refactor item templates [RDY] #15908
Conversation
Rebased against master |
@@ -589,6 +588,10 @@ void Item_factory::check_definitions() const | |||
if( type->item_tags.count( "BIO_WEAPON" ) ) { | |||
msg << "BIO_WEAPON must not be specified with an ammo type" << "\n"; | |||
} | |||
|
|||
if( !type->magazines.empty() && !type->magazine_default.count( type->gun->ammo ) ) { | |||
msg << "specified magazine but none provided for default ammo type" << "\n"; |
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.
Causes errors with mods, specifically Generic Guns.
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.
I'll take a look now
Worse: it seems to cause a segfault with the no magazines mod. |
I have debug symbols for that build so I'll take a look. |
Almost certainly 90db4e1 but I'm struggling to see why |
Maybe you're checking the magazine field of a gun that no longer has one? |
I think I have it, the conditional for |
be84b8c fixes the segfault but the generic guns mod is still unhappy |
Have candidate fix for generic guns, waiting on |
Fixed in 387bf07 |
There were only two instances where
itype
templates were modified after loading. The first was the charge rifle (dropped in #15713) and the second in defense mode where for some reason2x4
is set to have zeroweight
andvolume
(dropped in 6b7a8dd).This PR refactors
Item_factory::find_template
to returnconst itype *
and changes the storage of template to be backed bystd::unique_ptr
. Item templates are now effectively immutable after loading although new templates can still be added. Nothing prevents the later addition of an explicitmutate_template
method if such a need arises.Incidentally noted during refactoring the parsing of
magazine
is insufficiently strict and I suspectnullptr
references are possible dependent upon theJSON
data. This is fixed in c057f35 which adds an additional test toItem_factory::check_definitions()
Item_factory::get_all_itypes()
questionably breaks encapsulation so a future PR could consider deprecating that also.Trivial merge conflict with #15901 should be easily resolvable when merge testing.