Skip to content
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

Hide bullets and magazines in guns when character wielding items #53437

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,18 +1617,29 @@ static hint_rating rate_action_collapse( const item &it )
}
}
return hint_rating::cant;
} else if( it.is_gun() ) {
for( const item_pocket *magazine_well : it.get_all_magazine_wells().value() ) {
if( !magazine_well->settings.is_collapsed() ) {
return hint_rating::good;
}
}
}
return hint_rating::cant;
}

static hint_rating rate_action_expand( const item &it )
{
if( !it.is_container() ) {
return hint_rating::cant;
}
for( const item_pocket *pocket : it.get_all_contained_pockets().value() ) {
if( pocket->settings.is_collapsed() ) {
return hint_rating::good;
if( it.is_container() ) {
for( const item_pocket *pocket : it.get_all_contained_pockets().value() ) {
if( pocket->settings.is_collapsed() ) {
return hint_rating::good;
}
}
} else if( it.is_gun() ) {
for( const item_pocket *magazine_well : it.get_all_magazine_wells().value() ) {
if( magazine_well->settings.is_collapsed() ) {
return hint_rating::good;
}
}
}
return hint_rating::cant;
Expand Down Expand Up @@ -2036,6 +2047,10 @@ int game::inventory_item_menu( item_location locThisItem,
for( item_pocket *pocket : oThisItem.get_all_contained_pockets().value() ) {
pocket->settings.set_collapse( cMenu == '>' );
}
} else if( oThisItem.is_gun() ) {
for( item_pocket *magazine_well : oThisItem.get_all_magazine_wells().value() ) {
magazine_well->settings.set_collapse( cMenu == '>' );
}
}
break;
default:
Expand Down
5 changes: 5 additions & 0 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@ void inventory_column::set_collapsed( inventory_entry &entry, const bool collaps
pocket->settings.set_collapse( collapse );
collapsed = true;
}
} else if( loc.get_item()->is_gun() ) {
for( item_pocket *magazine_well : loc->get_all_magazine_wells().value() ) {
magazine_well->settings.set_collapse( collapse );
collapsed = true;
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ item::item( const itype *type, time_point turn, int qty ) : type( type ), bday(
}
}

if( is_gun() ) {
for( item_pocket *pocket : get_all_magazine_wells().value() ) {
pocket->settings.set_collapse( true );
}
}

if( has_flag( flag_NANOFAB_TEMPLATE ) ) {
itype_id nanofab_recipe =
item_group::item_from( type->nanofab_template_group ).typeId();
Expand Down Expand Up @@ -8128,6 +8134,16 @@ ret_val<std::vector<item_pocket *>> item::get_all_contained_pockets()
return contents.get_all_contained_pockets();
}

ret_val<std::vector<const item_pocket *>> item::get_all_magazine_wells() const
{
return contents.get_all_magazine_wells();
}

ret_val<std::vector<item_pocket *>> item::get_all_magazine_wells()
{
return contents.get_all_magazine_wells();
}

item_pocket *item::contained_where( const item &contained )
{
return contents.contained_where( contained );
Expand Down
3 changes: 3 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ class item : public visitable
ret_val<std::vector<const item_pocket *>> get_all_contained_pockets() const;
ret_val<std::vector<item_pocket *>> get_all_contained_pockets();

// gets all magazine well in this item
ret_val<std::vector<const item_pocket *>> get_all_magazine_wells() const;
ret_val<std::vector<item_pocket *>> get_all_magazine_wells();
/**
* Updates the pockets of this item to be correct based on the mods that are installed.
* Pockets which are modified that contain an item will be spilled
Expand Down
36 changes: 36 additions & 0 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,42 @@ ret_val<std::vector<item_pocket *>> item_contents::get_all_contained_pockets()
}
}

ret_val<std::vector<const item_pocket *>> item_contents::get_all_magazine_wells() const
{
std::vector<const item_pocket *> magazine_wells;
bool found = false;

for( const item_pocket &magazine_well : contents ) {
if( magazine_well.is_type( item_pocket::pocket_type::MAGAZINE_WELL ) ) {
found = true;
magazine_wells.push_back( &magazine_well );
}
}
if( found ) {
return ret_val<std::vector<const item_pocket *>>::make_success( magazine_wells );
} else {
return ret_val<std::vector<const item_pocket *>>::make_failure( magazine_wells );
}
}

ret_val<std::vector<item_pocket *>> item_contents::get_all_magazine_wells()
{
std::vector<item_pocket *> magazine_wells;
bool found = false;

for( item_pocket &magazine_well : contents ) {
if( magazine_well.is_type( item_pocket::pocket_type::MAGAZINE_WELL ) ) {
found = true;
magazine_wells.push_back( &magazine_well );
}
}
if( found ) {
return ret_val<std::vector<item_pocket *>>::make_success( magazine_wells );
} else {
return ret_val<std::vector<item_pocket *>>::make_failure( magazine_wells );
}
}

std::vector<const item *> item_contents::get_added_pockets() const
{
std::vector<const item *> items_added;
Expand Down
4 changes: 4 additions & 0 deletions src/item_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class item_contents
ret_val<std::vector<const item_pocket *>> get_all_contained_pockets() const;
ret_val<std::vector<item_pocket *>> get_all_contained_pockets();

// gets all magazine well in this item
ret_val<std::vector<const item_pocket *>> get_all_magazine_wells() const;
ret_val<std::vector<item_pocket *>> get_all_magazine_wells();

// called when adding an item as pockets
// to a molle item
void add_pocket( const item &pocket );
Expand Down