Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup for Maps::Tiles #7762

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fheroes2/ai/ai_hero_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ namespace

void AIToHeroes( Heroes & hero, const int32_t dstIndex )
{
Heroes * otherHero = world.GetTiles( dstIndex ).GetHeroes();
Heroes * otherHero = world.GetTiles( dstIndex ).getHero();
if ( otherHero == nullptr ) {
// This should never happen
assert( 0 );
Expand Down
14 changes: 7 additions & 7 deletions src/fheroes2/ai/normal/ai_normal_hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ namespace
return isHeroStrongerThan( tile, objectType, ai, heroArmyStrength, ( hero.isLosingGame() ? 1.0 : AI::ARMY_ADVANTAGE_MEDIUM ) );

case MP2::OBJ_HEROES: {
const Heroes * otherHero = tile.GetHeroes();
const Heroes * otherHero = tile.getHero();
assert( otherHero != nullptr );

const bool otherHeroInCastle = ( otherHero->inCastle() != nullptr );
Expand Down Expand Up @@ -953,7 +953,7 @@ namespace AI
return calculateCastleValue( castle );
}
case MP2::OBJ_HEROES: {
const Heroes * otherHero = tile.GetHeroes();
const Heroes * otherHero = tile.getHero();
if ( !otherHero ) {
// How is it even possible?
assert( 0 );
Expand Down Expand Up @@ -1475,7 +1475,7 @@ namespace AI
return calculateCastleValue( castle );
}
case MP2::OBJ_HEROES: {
const Heroes * otherHero = tile.GetHeroes();
const Heroes * otherHero = tile.getHero();
if ( !otherHero ) {
// How is it even possible?
assert( 0 );
Expand Down Expand Up @@ -1672,7 +1672,7 @@ namespace AI

switch ( objectType ) {
case MP2::OBJ_HEROES: {
const Heroes * otherHero = tile.GetHeroes();
const Heroes * otherHero = tile.getHero();
if ( !otherHero ) {
// How is it even possible?
assert( 0 );
Expand Down Expand Up @@ -1898,7 +1898,7 @@ namespace AI

for ( const auto & actionObject : _mapActionObjects ) {
if ( actionObject.second == MP2::OBJ_HEROES ) {
assert( world.GetTiles( actionObject.first ).GetHeroes() != nullptr );
assert( world.GetTiles( actionObject.first ).getHero() != nullptr );
}

const auto [dummy, inserted] = objectIndexes.emplace( actionObject.first );
Expand Down Expand Up @@ -1970,7 +1970,7 @@ namespace AI
break;
}
case MP2::OBJ_HEROES: {
const Heroes * anotherHero = destinationTile.GetHeroes();
const Heroes * anotherHero = destinationTile.getHero();
if ( anotherHero == nullptr ) {
assert( 0 );
break;
Expand Down Expand Up @@ -2144,7 +2144,7 @@ namespace AI
else if ( objectType == MP2::OBJ_HEROES ) {
const Maps::Tiles & tile = world.GetTiles( tileIndex );

const Heroes * anotherHero = tile.GetHeroes();
const Heroes * anotherHero = tile.getHero();
if ( anotherHero == nullptr ) {
// Another hero lost the battle, but he could defend a castle
if ( tile.GetObject() == MP2::OBJ_CASTLE ) {
Expand Down
14 changes: 7 additions & 7 deletions src/fheroes2/ai/normal/ai_normal_kingdom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,25 @@ namespace
assert( hero != nullptr && hero->isActive() );

Maps::Tiles & tile = world.GetTiles( hero->GetIndex() );
if ( tile.GetHeroes() == nullptr ) {
if ( tile.getHero() == nullptr ) {
// This could happen when a hero is moving.
continue;
}

assert( tile.GetHeroes() == hero );
assert( tile.getHero() == hero );
_heroes.emplace_back( hero );

tile.SetHeroes( nullptr );
tile.setHero( nullptr );
}
}

~TemporaryHeroEraser()
{
for ( Heroes * hero : _heroes ) {
Maps::Tiles & tile = world.GetTiles( hero->GetIndex() );
assert( tile.GetHeroes() == nullptr );
assert( tile.getHero() == nullptr );

tile.SetHeroes( hero );
tile.setHero( hero );
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ namespace
const int32_t tileIndex = tile.GetIndex();

if ( object == MP2::OBJ_HEROES ) {
const Heroes * hero = tile.GetHeroes();
const Heroes * hero = tile.getHero();
// TODO: this function can be called when the game world is not fully initialized yet
if ( hero == nullptr ) {
return {};
Expand Down Expand Up @@ -765,7 +765,7 @@ namespace AI
_mapActionObjects.emplace_back( idx, objectType );

if ( objectType == MP2::OBJ_HEROES ) {
const Heroes * hero = tile.GetHeroes();
const Heroes * hero = tile.getHero();
assert( hero != nullptr );

if ( hero->GetColor() == myColor && !hero->Modes( Heroes::PATROL ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ namespace Interface
{
const Maps::Tiles & tile = world.GetTiles( tileIndex );

Heroes * otherHero = tile.GetHeroes();
Heroes * otherHero = tile.getHero();
Castle * otherCastle = world.getCastle( tile.GetCenter() );

if ( otherHero ) {
Expand Down Expand Up @@ -573,7 +573,7 @@ namespace Interface
break;
}
case MP2::OBJ_HEROES: {
const Heroes * heroes = tile.GetHeroes();
const Heroes * heroes = tile.getHero();

if ( heroes ) {
Dialog::QuickInfo( *heroes );
Expand Down
12 changes: 6 additions & 6 deletions src/fheroes2/game/game_startgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void Game::OpenCastleDialog( Castle & castle, bool updateFocus /* = true */, con
adventureMapInterface.SetFocus( myKingdom.GetHeroes()[heroCountBefore], false );
}
else if ( it != myCastles.end() ) {
Heroes * heroInCastle = world.GetTiles( ( *it )->GetIndex() ).GetHeroes();
Heroes * heroInCastle = world.GetTiles( ( *it )->GetIndex() ).getHero();
if ( heroInCastle == nullptr ) {
adventureMapInterface.SetFocus( *it );
}
Expand Down Expand Up @@ -439,7 +439,7 @@ int Interface::AdventureMap::GetCursorFocusCastle( const Castle & castle, const
}

case MP2::OBJ_HEROES: {
const Heroes * hero = tile.GetHeroes();
const Heroes * hero = tile.getHero();

if ( hero ) {
return hero->GetColor() == castle.GetColor() ? Cursor::HEROES : Cursor::POINTER;
Expand Down Expand Up @@ -476,7 +476,7 @@ int Interface::AdventureMap::GetCursorFocusShipmaster( const Heroes & hero, cons
}

case MP2::OBJ_HEROES: {
const Heroes * otherHero = tile.GetHeroes();
const Heroes * otherHero = tile.getHero();

if ( otherHero ) {
if ( !otherHero->isShipMaster() ) {
Expand Down Expand Up @@ -573,7 +573,7 @@ int Interface::AdventureMap::GetCursorFocusHeroes( const Heroes & hero, const Ma
}

case MP2::OBJ_HEROES: {
const Heroes * otherHero = tile.GetHeroes();
const Heroes * otherHero = tile.getHero();

if ( otherHero ) {
if ( otherHero->GetCenter() == hero.GetCenter() ) {
Expand Down Expand Up @@ -1359,7 +1359,7 @@ void Interface::AdventureMap::mouseCursorAreaClickLeft( const int32_t tileIndex

switch ( Cursor::WithoutDistanceThemes( Cursor::Get().Themes() ) ) {
case Cursor::HEROES: {
Heroes * otherHero = tile.GetHeroes();
Heroes * otherHero = tile.getHero();
if ( otherHero == nullptr ) {
break;
}
Expand Down Expand Up @@ -1453,7 +1453,7 @@ void Interface::AdventureMap::mouseCursorAreaPressRight( const int32_t tileIndex
}

case MP2::OBJ_HEROES: {
const Heroes * heroes = tile.GetHeroes();
const Heroes * heroes = tile.getHero();

if ( heroes ) {
Dialog::QuickInfo( *heroes );
Expand Down
6 changes: 3 additions & 3 deletions src/fheroes2/gui/interface_gamearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ namespace

// There is a tile below the current.
const Maps::Tiles & tileBelow = world.GetTiles( x, y + 1 );
const Maps::Addons & lowerTileAddons = tileBelow.getLevel2Addons();
const Maps::Addons & lowerTileAddons = tileBelow.getTopLayerAddons();

for ( const Maps::TilesAddon & lowerAddon : lowerTileAddons ) {
if ( lowerAddon._uid == uid ) {
Expand Down Expand Up @@ -499,7 +499,7 @@ void Interface::GameArea::Redraw( fheroes2::Image & dst, int flag, bool isPuzzle
}

const bool isUpperTileUnderFog = ( posY > 0 ) ? ( world.GetTiles( posX, posY - 1 ).getFogDirection() == DIRECTION_ALL ) : true;
const Heroes * hero = tile.GetHeroes();
const Heroes * hero = tile.getHero();

// Boats are 2 tiles high so for hero on the boat we have to populate info for boat one tile lower than the fog.
if ( isTileUnderFog && ( isUpperTileUnderFog || !hero->isShipMaster() ) ) {
Expand Down Expand Up @@ -658,7 +658,7 @@ void Interface::GameArea::Redraw( fheroes2::Image & dst, int flag, bool isPuzzle
// any other level 2 objects with the same UID.

topLayerTallObjects.clear();
for ( const Maps::TilesAddon & addon : tile.getLevel2Addons() ) {
for ( const Maps::TilesAddon & addon : tile.getTopLayerAddons() ) {
if ( isTallTopLayerObject( x, y, addon._uid ) ) {
topLayerTallObjects.emplace_back( &addon );
}
Expand Down
8 changes: 4 additions & 4 deletions src/fheroes2/heroes/heroes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ bool Heroes::Recruit( const int col, const fheroes2::Point & pt )
army.Reset( false );
}

world.GetTiles( pt.x, pt.y ).SetHeroes( this );
world.GetTiles( pt.x, pt.y ).setHero( this );

kingdom.AddHeroes( this );
// Update the set of recruits in the kingdom
Expand Down Expand Up @@ -1675,7 +1675,7 @@ void Heroes::Dismiss( int reason )
}
SetColor( Color::NONE );

world.GetTiles( GetIndex() ).SetHeroes( nullptr );
world.GetTiles( GetIndex() ).setHero( nullptr );
SetIndex( -1 );

modes = 0;
Expand Down Expand Up @@ -1758,9 +1758,9 @@ void Heroes::Move2Dest( const int32_t dstIndex )
return;
}

world.GetTiles( currentIndex ).SetHeroes( nullptr );
world.GetTiles( currentIndex ).setHero( nullptr );
SetIndex( dstIndex );
world.GetTiles( dstIndex ).SetHeroes( this );
world.GetTiles( dstIndex ).setHero( this );
}

const fheroes2::Sprite & Heroes::GetPortrait( int id, int type )
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/heroes/heroes_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ namespace

void ActionToHeroes( Heroes & hero, const int32_t dstIndex )
{
Heroes * otherHero = world.GetTiles( dstIndex ).GetHeroes();
Heroes * otherHero = world.GetTiles( dstIndex ).getHero();
if ( otherHero == nullptr ) {
// This should never happen
assert( 0 );
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/kingdom/kingdom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ bool Kingdom::isValidKingdomObject( const Maps::Tiles & tile, const MP2::MapObje

// Hero object can overlay other objects when standing on top of it: force check with GetObject( true )
if ( objectType == MP2::OBJ_HEROES ) {
const Heroes * hero = tile.GetHeroes();
const Heroes * hero = tile.getHero();

// Hero can only be met if he either belongs to this kingdom or is an enemy hero (in the latter case, an attack will occur)
return hero && ( color == hero->GetColor() || !Players::isFriends( color, hero->GetColor() ) );
Expand Down Expand Up @@ -618,7 +618,7 @@ void Kingdom::ApplyPlayWithStartingHero()

// check manual set hero (castle position + point(0, 1))?
const fheroes2::Point & cp = castle->GetCenter();
Heroes * hero = world.GetTiles( cp.x, cp.y + 1 ).GetHeroes();
Heroes * hero = world.GetTiles( cp.x, cp.y + 1 ).getHero();

// and move manual set hero to castle
if ( hero && hero->GetColor() == GetColor() ) {
Expand Down
Loading