Skip to content

Commit

Permalink
Minimize the code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-derevenetz committed Oct 19, 2024
1 parent 7f5db24 commit ffa181c
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/fheroes2/resource/artifact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,24 +897,16 @@ void BagArtifacts::exchangeArtifacts( Heroes & taker, Heroes & giver )

std::vector<Artifact> combined;

for ( Artifact & artifact : takerBag ) {
if ( !artifact.isValid() || artifact.GetID() == Artifact::MAGIC_BOOK ) {
continue;
}
for ( BagArtifacts & bag : std::array<std::reference_wrapper<BagArtifacts>, 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 ) {
Expand Down

0 comments on commit ffa181c

Please sign in to comment.