Skip to content

Commit

Permalink
Prevent container item appearing twice in AIM (#56335)
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyBerube authored Mar 27, 2022
1 parent 2dd4029 commit f68abb0
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,12 @@ void advanced_inventory::recalc_pane( side p )
advanced_inventory_pane &pane = panes[p];
pane.recalc = false;
pane.items.clear();
advanced_inventory_pane &there = panes[-p + 1];
advanced_inv_area &other = squares[there.get_area()];
// Add items from the source location or in case of all 9 surrounding squares,
// add items from several locations.
if( pane.get_area() == AIM_ALL ) {
advanced_inv_area &alls = squares[AIM_ALL];
advanced_inventory_pane &there = panes[-p + 1];
advanced_inv_area &other = squares[there.get_area()];
alls.volume = 0_ml;
alls.weight = 0_gram;
for( advanced_inv_area &s : squares ) {
Expand Down Expand Up @@ -668,6 +668,30 @@ void advanced_inventory::recalc_pane( side p )
} else {
pane.add_items_from_area( squares[pane.get_area()] );
}

// Prevent same container item appearing in this pane when other pane is the container view.
if( there.get_area() == AIM_CONTAINER ) {
item_location loc = other.get_container();
std::vector<advanced_inv_listitem>::iterator outer_iter = pane.items.begin();
while( outer_iter != pane.items.end() ) {
if( !outer_iter->items.empty() ) {
std::vector<item_location>::iterator iter = outer_iter->items.begin();
while( iter != outer_iter->items.end() ) {
if( loc == *iter ) {
iter = outer_iter->items.erase( iter );
} else {
iter++;
}
}
}
if( outer_iter->items.empty() ) {
outer_iter = pane.items.erase( outer_iter );
} else {
outer_iter++;
}
}
}

// Sort all items
std::stable_sort( pane.items.begin(), pane.items.end(), advanced_inv_sorter( pane.sortby ) );
}
Expand Down

0 comments on commit f68abb0

Please sign in to comment.