From ffa181c78766f272a73dbbb6f690107624b76168 Mon Sep 17 00:00:00 2001 From: Oleg Derevenetz Date: Sat, 19 Oct 2024 15:04:59 +0300 Subject: [PATCH] Minimize the code duplication --- src/fheroes2/resource/artifact.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/fheroes2/resource/artifact.cpp b/src/fheroes2/resource/artifact.cpp index 0981a7a309..4cdc6f59dd 100644 --- a/src/fheroes2/resource/artifact.cpp +++ b/src/fheroes2/resource/artifact.cpp @@ -897,24 +897,16 @@ void BagArtifacts::exchangeArtifacts( Heroes & taker, Heroes & giver ) std::vector combined; - for ( Artifact & artifact : takerBag ) { - if ( !artifact.isValid() || artifact.GetID() == Artifact::MAGIC_BOOK ) { - continue; - } + for ( BagArtifacts & bag : std::array, 2>{ takerBag, giverBag } ) { + for ( Artifact & artifact : bag ) { + if ( !artifact.isValid() || artifact.GetID() == Artifact::MAGIC_BOOK ) { + continue; + } - combined.push_back( artifact ); + combined.push_back( artifact ); - artifact.Reset(); - } - - for ( Artifact & artifact : giverBag ) { - if ( !artifact.isValid() || artifact.GetID() == Artifact::MAGIC_BOOK ) { - continue; + artifact.Reset(); } - - combined.push_back( artifact ); - - artifact.Reset(); } const auto isPureCursedArtifact = []( const Artifact & artifact ) {