diff --git a/src/advanced_inv_listitem.cpp b/src/advanced_inv_listitem.cpp index 77ebbd5139a94..b1b52c32286d3 100644 --- a/src/advanced_inv_listitem.cpp +++ b/src/advanced_inv_listitem.cpp @@ -16,7 +16,7 @@ advanced_inv_listitem::advanced_inv_listitem( item *an_item, int index, int coun , stacks( count ) , volume( an_item->volume() * stacks ) , weight( an_item->weight() * stacks ) - , cat( &an_item->get_category() ) + , cat( &an_item->get_category_of_contents() ) , from_vehicle( from_vehicle ) { items.push_back( an_item ); @@ -35,7 +35,7 @@ advanced_inv_listitem::advanced_inv_listitem( const std::vector &list, i stacks( list.size() ), volume( list.front()->volume() * stacks ), weight( list.front()->weight() * stacks ), - cat( &list.front()->get_category() ), + cat( &list.front()->get_category_of_contents() ), from_vehicle( from_vehicle ) { assert( stacks >= 1 ); diff --git a/src/clzones.cpp b/src/clzones.cpp index 90f102b9b9758..40f3b93946714 100644 --- a/src/clzones.cpp +++ b/src/clzones.cpp @@ -805,7 +805,7 @@ cata::optional zone_manager::get_nearest( const zone_type_id &type, co zone_type_id zone_manager::get_near_zone_type_for_item( const item &it, const tripoint &where, int range ) const { - const item_category &cat = it.get_category(); + const item_category &cat = it.get_category_of_contents(); if( has_near( zone_type_id( "LOOT_CUSTOM" ), where, range ) ) { if( !get_near( zone_type_id( "LOOT_CUSTOM" ), where, range, &it ).empty() ) { diff --git a/src/item.cpp b/src/item.cpp index 188a27fb3d39b..f605d290f118c 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -102,6 +102,7 @@ static const ammotype ammo_plutonium( "plutonium" ); static const item_category_id item_category_drugs( "drugs" ); static const item_category_id item_category_food( "food" ); static const item_category_id item_category_maps( "maps" ); +static const item_category_id item_category_container( "container" ); static const efftype_id effect_cig( "cig" ); static const efftype_id effect_shakes( "shakes" ); @@ -8421,6 +8422,15 @@ const item_category &item::get_category() const return type->category_force.is_valid() ? type->category_force.obj() : null_category; } +const item_category &item::get_category_of_contents() const +{ + if( type->category_force == item_category_container && contents.num_item_stacks() == 1 ) { + return contents.only_item().get_category(); + } else { + return this->get_category(); + } +} + iteminfo::iteminfo( const std::string &Type, const std::string &Name, const std::string &Fmt, flags Flags, double Value ) { diff --git a/src/item.h b/src/item.h index 02073cd0dd66a..9b39ec302da55 100644 --- a/src/item.h +++ b/src/item.h @@ -463,6 +463,9 @@ class item : public visitable // Returns the category of this item. const item_category &get_category() const; + // Returns the category of item inside this item. I.e. "can of meat" would be food, instead of container. + // If there are multiple items/stacks or none then it defaults to category of this item. + const item_category &get_category_of_contents() const; class reload_option {