Skip to content

Commit

Permalink
Attempt to re-insert contents of mismatched pockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamayana committed Dec 27, 2023
1 parent 5cc5f57 commit 6163aa6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ void item_contents::read_mods( const item_contents &read_input )
void item_contents::combine( const item_contents &read_input, const bool convert,
const bool into_bottom, bool restack_charges, bool ignore_contents )
{
std::list<item_pocket> mismatched_pockets;
std::vector<item> uninserted_items;
size_t pocket_index = 0;

Expand Down Expand Up @@ -702,6 +703,11 @@ void item_contents::combine( const item_contents &read_input, const bool convert
auto current_pocket_iter = contents.begin();
std::advance( current_pocket_iter, pocket_index );

if( !current_pocket_iter->is_type( pocket.saved_type() ) ) {
mismatched_pockets.push_back( pocket );
continue;
}

for( const item *it : pocket.all_items_top() ) {
const ret_val<item *> inserted = current_pocket_iter->insert_item( *it,
into_bottom, restack_charges, ignore_contents );
Expand All @@ -724,6 +730,17 @@ void item_contents::combine( const item_contents &read_input, const bool convert
++pocket_index;
}

for( const item_pocket &pocket : mismatched_pockets ) {
for( const item *it : pocket.all_items_top() ) {
const ret_val<item *> inserted = insert_item( *it, pocket.saved_type(), ignore_contents );
if( !inserted.success() ) {
uninserted_items.push_back( *it );
debugmsg( "error: item %s cannot fit into any pocket while loading: %s",
it->typeId().str(), inserted.str() );
}
}
}

for( const item &uninserted_item : uninserted_items ) {
insert_item( uninserted_item, pocket_type::MIGRATION, ignore_contents );
}
Expand Down
1 change: 0 additions & 1 deletion src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,6 @@ ret_val<item_pocket::contain_code> item_pocket::is_compatible( const item &it )
return ret_val<item_pocket::contain_code>::make_success();
}


if( data->type == pocket_type::MOD ) {
if( it.is_toolmod() || it.is_gunmod() ) {
return ret_val<item_pocket::contain_code>::make_success();
Expand Down

0 comments on commit 6163aa6

Please sign in to comment.