From d7680eb273c3f3cab7e7439d76c9454173f57b9b Mon Sep 17 00:00:00 2001 From: David Seguin Date: Mon, 11 Oct 2021 21:59:12 -0400 Subject: [PATCH 1/2] Compare item mods when stacking --- src/item.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/item.cpp b/src/item.cpp index 6e3e61813912c..f67b68fb16b21 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1187,6 +1187,22 @@ bool item::stacks_with( const item &rhs, bool check_components, bool combine_liq } } } + const std::vector this_mods = mods(); + const std::vector that_mods = rhs.mods(); + if( this_mods.size() != that_mods.size() ) { + return false; + } + for( unsigned i = 0; i < this_mods.size(); i++ ) { + if( this_mods[i] == that_mods[i] ) { + // Both pointers are null + continue; + } else if( ( this_mods[i] == nullptr && that_mods[i] != nullptr ) || + ( this_mods[i] != nullptr && that_mods[i] == nullptr ) ) { + return false; + } else if( this_mods[i]->typeId() != that_mods[i]->typeId() ) { + return false; + } + } return contents.stacks_with( rhs.contents ); } From be1a8b9b8149edabf848d424d8a5f6ad52ab017b Mon Sep 17 00:00:00 2001 From: David Seguin Date: Mon, 11 Oct 2021 22:30:45 -0400 Subject: [PATCH 2/2] Check mods independently of order --- src/item.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index f67b68fb16b21..a7aa1ddde9e91 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1192,14 +1192,19 @@ bool item::stacks_with( const item &rhs, bool check_components, bool combine_liq if( this_mods.size() != that_mods.size() ) { return false; } - for( unsigned i = 0; i < this_mods.size(); i++ ) { - if( this_mods[i] == that_mods[i] ) { - // Both pointers are null - continue; - } else if( ( this_mods[i] == nullptr && that_mods[i] != nullptr ) || - ( this_mods[i] != nullptr && that_mods[i] == nullptr ) ) { - return false; - } else if( this_mods[i]->typeId() != that_mods[i]->typeId() ) { + for( const item *it1 : this_mods ) { + bool match = false; + const bool i1_isnull = it1 == nullptr; + for( const item *it2 : that_mods ) { + const bool i2_isnull = it2 == nullptr; + if( i1_isnull != i2_isnull ) { + continue; + } else if( it1 == it2 || it1->typeId() == it2->typeId() ) { + match = true; + break; + } + } + if( !match ) { return false; } }