Skip to content

Commit

Permalink
Modernize the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-derevenetz committed Dec 29, 2024
1 parent 9cddaa7 commit 0ea65b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
33 changes: 14 additions & 19 deletions src/fheroes2/army/army.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,47 +237,42 @@ Troops::~Troops()
} );
}

void Troops::Assign( const Troop * itbeg, const Troop * itend )
void Troops::Assign( const Troop * troopsBegin, const Troop * troopsEnd )
{
Clean();

iterator it = begin();
for ( iterator iter = begin(); iter != end() && troopsBegin != troopsEnd; ++iter, ++troopsBegin ) {
assert( *iter != nullptr && troopsBegin != nullptr );

while ( it != end() && itbeg != itend ) {
if ( itbeg->isValid() ) {
( *it )->Set( *itbeg );
if ( troopsBegin->isValid() ) {
( *iter )->Set( *troopsBegin );
}

++it;
++itbeg;
}
}

void Troops::Assign( const Troops & troops )
{
Clean();

iterator it1 = begin();
const_iterator it2 = troops.begin();
for ( auto [thisIter, troopsIter] = std::make_pair( begin(), troops.begin() ); thisIter != end() && troopsIter != troops.end(); ++thisIter, ++troopsIter ) {
assert( *thisIter != nullptr && *troopsIter != nullptr );

while ( it1 != end() && it2 != troops.end() ) {
if ( ( *it2 )->isValid() ) {
( *it1 )->Set( **it2 );
if ( ( *troopsIter )->isValid() ) {
( *thisIter )->Set( **troopsIter );
}

++it2;
++it1;
}
}

void Troops::Insert( const Troops & troops )
{
for ( const_iterator it = troops.begin(); it != troops.end(); ++it ) {
push_back( new Troop( **it ) );
for ( const Troop * troop : troops ) {
assert( troop != nullptr );

push_back( new Troop( *troop ) );
}
}

void Troops::PushBack( const Monster & mons, uint32_t count )
void Troops::PushBack( const Monster & mons, const uint32_t count )
{
push_back( new Troop( mons, count ) );
}
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/army/army.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class Troops : protected std::vector<Troop *>

Troops & operator=( const Troops & ) = delete;

void Assign( const Troop * itbeg, const Troop * itend );
void Assign( const Troop * troopsBegin, const Troop * troopsEnd );
void Assign( const Troops & troops );
void Insert( const Troops & troops );
void PushBack( const Monster &, uint32_t );
void PushBack( const Monster & mons, const uint32_t count );
void PopBack();

size_t Size() const
Expand Down

0 comments on commit 0ea65b3

Please sign in to comment.