Skip to content

Commit

Permalink
Expand the logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ihhub committed Oct 19, 2024
1 parent 5d78905 commit 2b6f90a
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/fheroes2/world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,36 +829,42 @@ MapsIndexes World::GetWhirlpoolEndPoints( const int32_t index ) const
return result;
}

// The exit point from the destination whirlpool must match the entry point in the source whirlpool.
// A whirlpool can be as a main addon / object part or bottom part. This is important to get a proper object part.
const Maps::TilesAddon * objectPart = nullptr;
if ( Maps::getObjectTypeByIcn( entranceTile.getMainObjectPart()._objectIcnType, entranceTile.getMainObjectPart()._imageIndex ) == MP2::OBJ_WHIRLPOOL ) {
objectPart = &entranceTile.getMainObjectPart();
}
else {
bool objectFound = false;
const auto getWhirlPoolObjectPart = []( const Maps::Tiles & tile ) -> const Maps::TilesAddon * {
// The exit point from the destination whirlpool must match the entry point in the source whirlpool.
// A whirlpool can be as a main addon / object part or bottom part. This is important to get a proper object part.
if ( Maps::getObjectTypeByIcn( tile.getMainObjectPart()._objectIcnType, tile.getMainObjectPart()._imageIndex ) == MP2::OBJ_WHIRLPOOL ) {
return &tile.getMainObjectPart();
}

for ( const auto & part : entranceTile.getBottomLayerAddons() ) {
for ( const auto & part : tile.getBottomLayerAddons() ) {
if ( Maps::getObjectTypeByIcn( part._objectIcnType, part._imageIndex ) == MP2::OBJ_WHIRLPOOL ) {
objectPart = ∂
objectFound = true;
break;
return ∂
}
}

if ( !objectFound ) {
// This tile is marked incorrectly!
assert( 0 );
return result;
}
}
assert( 0 );
return nullptr;
};

assert( objectPart != nullptr );
// The exit point from the destination whirlpool must match the entry point in the source whirlpool.
// A whirlpool can be as a main addon / object part or bottom part. This is important to get a proper object part.
const Maps::TilesAddon * entranceObjectPart = getWhirlPoolObjectPart( entranceTile );
if ( entranceObjectPart == nullptr ) {
return result;
}

for ( const int32_t whirlpoolIndex : _allWhirlpools.at( objectPart->_imageIndex ) ) {
for ( const int32_t whirlpoolIndex : _allWhirlpools.at( entranceObjectPart->_imageIndex ) ) {
const Maps::Tiles & whirlpoolTile = GetTiles( whirlpoolIndex );
if ( whirlpoolTile.GetObject() != MP2::OBJ_WHIRLPOOL ) {
continue;
}

const Maps::TilesAddon * destinationObjectPart = getWhirlPoolObjectPart( whirlpoolTile );
if ( destinationObjectPart == nullptr ) {
continue;
}

if ( whirlpoolTile.getMainObjectPart()._uid == objectPart->_uid || whirlpoolTile.GetObject() != MP2::OBJ_WHIRLPOOL ) {
if ( destinationObjectPart->_uid == entranceObjectPart->_uid ) {
continue;
}

Expand Down

0 comments on commit 2b6f90a

Please sign in to comment.