diff --git a/src/fheroes2/campaign/campaign_data.cpp b/src/fheroes2/campaign/campaign_data.cpp index b84fd25fdf8..9a7173dfeef 100644 --- a/src/fheroes2/campaign/campaign_data.cpp +++ b/src/fheroes2/campaign/campaign_data.cpp @@ -744,7 +744,7 @@ namespace Campaign } if ( allAIPlayersInAlliance ) { - const Colors humanColors( mapInfo.colorsAvailableForHumans ); + const Colors humanColors( mapInfo.humanPlayerColors ); // Make sure that this is only one human player on the map. if ( humanColors.size() != 1 ) { // Looks like somebody is modifying the original map. @@ -752,7 +752,7 @@ namespace Campaign return; } - const int aiColors = ( mapInfo.kingdomColors & ( ~mapInfo.colorsAvailableForHumans ) ); + const int aiColors = ( mapInfo.availablePlayerColors & ( ~mapInfo.humanPlayerColors ) ); if ( aiColors == 0 ) { // This is definitely not the map to modify. assert( 0 ); diff --git a/src/fheroes2/dialog/dialog_selectscenario.cpp b/src/fheroes2/dialog/dialog_selectscenario.cpp index 1604eb32140..31a2041be7c 100644 --- a/src/fheroes2/dialog/dialog_selectscenario.cpp +++ b/src/fheroes2/dialog/dialog_selectscenario.cpp @@ -265,7 +265,7 @@ void ScenarioListBox::RedrawBackground( const fheroes2::Point & dst ) void ScenarioListBox::_renderScenarioListItem( const Maps::FileInfo & info, fheroes2::Display & display, const int32_t dsty, const bool current ) const { - fheroes2::Blit( _getPlayersCountIcon( info.kingdomColors ), display, _offsetX + SCENARIO_LIST_COUNT_PLAYERS_OFFSET_X, dsty ); + fheroes2::Blit( _getPlayersCountIcon( info.availablePlayerColors ), display, _offsetX + SCENARIO_LIST_COUNT_PLAYERS_OFFSET_X, dsty ); _renderMapIcon( info.width, display, _offsetX + SCENARIO_LIST_MAP_SIZE_OFFSET_X, dsty ); fheroes2::Blit( _getMapTypeIcon( info.version ), display, _offsetX + SCENARIO_LIST_MAP_TYPE_OFFSET_X, dsty ); if ( _isForEditor ) { @@ -282,7 +282,8 @@ void ScenarioListBox::_renderSelectedScenarioInfo( fheroes2::Display & display, { const Maps::FileInfo & info = GetCurrent(); - fheroes2::Blit( _getPlayersCountIcon( info.kingdomColors ), display, dst.x + SELECTED_SCENARIO_COUNT_PLAYERS_OFFSET_X, dst.y + SELECTED_SCENARIO_GENERAL_OFFSET_Y ); + fheroes2::Blit( _getPlayersCountIcon( info.availablePlayerColors ), display, dst.x + SELECTED_SCENARIO_COUNT_PLAYERS_OFFSET_X, + dst.y + SELECTED_SCENARIO_GENERAL_OFFSET_Y ); _renderMapIcon( info.width, display, dst.x + SELECTED_SCENARIO_MAP_SIZE_OFFSET_X, dst.y + SELECTED_SCENARIO_GENERAL_OFFSET_Y ); fheroes2::Blit( _getMapTypeIcon( info.version ), display, dst.x + SELECTED_SCENARIO_MAP_TYPE_OFFSET_X, dst.y + SELECTED_SCENARIO_GENERAL_OFFSET_Y ); diff --git a/src/fheroes2/editor/editor_save_map_window.cpp b/src/fheroes2/editor/editor_save_map_window.cpp index 84a29028bfc..4a31c80eb33 100644 --- a/src/fheroes2/editor/editor_save_map_window.cpp +++ b/src/fheroes2/editor/editor_save_map_window.cpp @@ -158,7 +158,7 @@ namespace fileNameText.fitToOneRow( maxFileNameWidth - 40 ); fileNameText.draw( posX + 44, posY + 2, display ); - const uint32_t racesCountIcnIndex = static_cast( Color::Count( info.kingdomColors ) + 19 ); + const uint32_t racesCountIcnIndex = static_cast( Color::Count( info.availablePlayerColors ) + 19 ); const fheroes2::Sprite & racesCount = fheroes2::AGG::GetICN( ICN::REQUESTS, racesCountIcnIndex ); fheroes2::Copy( racesCount, 0, 0, display, posX + 6, posY, racesCount.width(), racesCount.height() ); diff --git a/src/fheroes2/gui/player_info.cpp b/src/fheroes2/gui/player_info.cpp index 3c38a8bd5c3..cd1e3e11c12 100644 --- a/src/fheroes2/gui/player_info.cpp +++ b/src/fheroes2/gui/player_info.cpp @@ -363,7 +363,7 @@ bool Interface::PlayersInfo::QueueEventProcessing() else { const int playerColor = player->GetColor(); - if ( playerColor & fi.colorsAvailableForHumans ) { + if ( playerColor & fi.humanPlayerColors ) { const int human = conf.GetPlayers().GetColors( CONTROL_HUMAN, true ); if ( playerColor != human ) { diff --git a/src/fheroes2/maps/maps_fileinfo.cpp b/src/fheroes2/maps/maps_fileinfo.cpp index 9ed4b74c2e9..214817ad38c 100644 --- a/src/fheroes2/maps/maps_fileinfo.cpp +++ b/src/fheroes2/maps/maps_fileinfo.cpp @@ -176,13 +176,13 @@ void Maps::FileInfo::Reset() unions[i] = Color::IndexToColor( i ); } - kingdomColors = 0; - colorsAvailableForHumans = 0; - colorsAvailableForComp = 0; + availablePlayerColors = 0; + humanPlayerColors = 0; + computerPlayerColors = 0; colorsOfRandomRaces = 0; victoryConditionType = VICTORY_DEFEAT_EVERYONE; - compAlsoWins = false; + isVictoryConditionApplicableForAI = false; allowNormalVictory = false; victoryConditionParams.fill( 0 ); @@ -248,25 +248,25 @@ bool Maps::FileInfo::readMP2Map( std::string filePath, const bool isForEditor ) // Colors used by kingdoms: blue, green, red, yellow, orange, purple for ( const int color : colors ) { if ( fs.get() != 0 ) { - kingdomColors |= color; + availablePlayerColors |= color; } } // Colors available for human players: blue, green, red, yellow, orange, purple for ( const int color : colors ) { if ( fs.get() != 0 ) { - colorsAvailableForHumans |= color; + humanPlayerColors |= color; } } // Colors available for computer players: blue, green, red, yellow, orange, purple for ( const int color : colors ) { if ( fs.get() != 0 ) { - colorsAvailableForComp |= color; + computerPlayerColors |= color; } } - if ( !isForEditor && colorsAvailableForHumans == 0 ) { + if ( !isForEditor && humanPlayerColors == 0 ) { // This is not a valid map since no human players exist so it cannot be played. DEBUG_LOG( DBG_GAME, DBG_WARN, "Map " << filename << " does not contain any human players." ) return false; @@ -280,7 +280,7 @@ bool Maps::FileInfo::readMP2Map( std::string filePath, const bool isForEditor ) // Victory condition type. victoryConditionType = fs.get(); // Do the victory conditions apply to AI too? - compAlsoWins = ( fs.get() != 0 ); + isVictoryConditionApplicableForAI = ( fs.get() != 0 ); // Is "normal victory" (defeating all other players) applicable here? allowNormalVictory = ( fs.get() != 0 ); // Parameter of victory condition. @@ -315,7 +315,7 @@ bool Maps::FileInfo::readMP2Map( std::string filePath, const bool isForEditor ) bool skipUnionSetup = false; // If loss conditions are LOSS_HERO and victory conditions are VICTORY_DEFEAT_EVERYONE then we have to verify the color to which this object belongs to. // If the color is under computer control only we have to make it as an ally for human player. - if ( lossConditionType == LOSS_HERO && victoryConditionType == VICTORY_DEFEAT_EVERYONE && Colors( colorsAvailableForHumans ).size() == 1 ) { + if ( lossConditionType == LOSS_HERO && victoryConditionType == VICTORY_DEFEAT_EVERYONE && Colors( humanPlayerColors ).size() == 1 ) { // Each tile needs 16 + 8 + 8 + 8 + 8 + 8 + 8 + 8 + 8 + 16 + 32 + 32 = 160 bits or 20 bytes. fs.seek( MP2::MP2_MAP_INFO_SIZE + ( lossConditionParams[0] + lossConditionParams[1] * width ) * 20 ); @@ -326,9 +326,9 @@ bool Maps::FileInfo::readMP2Map( std::string filePath, const bool isForEditor ) tile.Init( 0, mp2tile ); const std::pair colorRace = getColorRaceFromHeroSprite( tile.getMainObjectPart().icnIndex ); - if ( ( colorRace.first & colorsAvailableForHumans ) == 0 ) { - const int side1 = colorRace.first | colorsAvailableForHumans; - const int side2 = colorsAvailableForComp ^ colorRace.first; + if ( ( colorRace.first & humanPlayerColors ) == 0 ) { + const int side1 = colorRace.first | humanPlayerColors; + const int side2 = computerPlayerColors ^ colorRace.first; FillUnions( side1, side2 ); @@ -351,7 +351,7 @@ bool Maps::FileInfo::readMP2Map( std::string filePath, const bool isForEditor ) int side1 = 0; int side2 = 0; - const Colors availableColors( kingdomColors ); + const Colors availableColors( availablePlayerColors ); if ( availableColors.empty() ) { DEBUG_LOG( DBG_GAME, DBG_WARN, "File " << filename << ": invalid list of kingdom colors during map load" ) return false; @@ -402,7 +402,7 @@ bool Maps::FileInfo::readResurrectionMap( std::string filePath, const bool isFor return false; } - if ( !isForEditor && colorsAvailableForHumans == 0 ) { + if ( !isForEditor && humanPlayerColors == 0 ) { // This is not a valid map since no human players exist so it cannot be played. DEBUG_LOG( DBG_GAME, DBG_WARN, "Map " << filename << " does not contain any human players." ) return false; @@ -429,14 +429,14 @@ bool Maps::FileInfo::loadResurrectionMap( const Map_Format::BaseMapFormat & map, assert( ( map.availablePlayerColors & map.computerPlayerColors ) == map.computerPlayerColors ); assert( ( map.availablePlayerColors & ( map.humanPlayerColors | map.computerPlayerColors ) ) == map.availablePlayerColors ); - kingdomColors = map.availablePlayerColors; - colorsAvailableForHumans = map.humanPlayerColors; - colorsAvailableForComp = map.computerPlayerColors; + availablePlayerColors = map.availablePlayerColors; + humanPlayerColors = map.humanPlayerColors; + computerPlayerColors = map.computerPlayerColors; races = map.playerRace; victoryConditionType = map.victoryConditionType; - compAlsoWins = map.isVictoryConditionApplicableForAI; + isVictoryConditionApplicableForAI = map.isVictoryConditionApplicableForAI; allowNormalVictory = map.allowNormalVictory; lossConditionType = map.lossConditionType; @@ -474,7 +474,7 @@ bool Maps::FileInfo::loadResurrectionMap( const Map_Format::BaseMapFormat & map, // Since this is a normal victory condition. // So, no metadata should exist. assert( map.victoryConditionMetadata.empty() ); - compAlsoWins = true; + isVictoryConditionApplicableForAI = true; allowNormalVictory = true; break; case VICTORY_CAPTURE_TOWN: @@ -630,7 +630,7 @@ uint32_t Maps::FileInfo::ConditionLoss() const bool Maps::FileInfo::WinsCompAlsoWins() const { - return compAlsoWins && ( ( GameOver::WINS_TOWN | GameOver::WINS_GOLD ) & ConditionWins() ); + return isVictoryConditionApplicableForAI && ( ( GameOver::WINS_TOWN | GameOver::WINS_GOLD ) & ConditionWins() ); } OStreamBase & Maps::operator<<( OStreamBase & stream, const FileInfo & fi ) @@ -645,10 +645,10 @@ OStreamBase & Maps::operator<<( OStreamBase & stream, const FileInfo & fi ) stream << fi.races[i] << fi.unions[i]; } - return stream << fi.kingdomColors << fi.colorsAvailableForHumans << fi.colorsAvailableForComp << fi.colorsOfRandomRaces << fi.victoryConditionType << fi.compAlsoWins - << fi.allowNormalVictory << fi.victoryConditionParams[0] << fi.victoryConditionParams[1] << fi.lossConditionType << fi.lossConditionParams[0] - << fi.lossConditionParams[1] << fi.timestamp << fi.startWithHeroInFirstCastle << fi.version << fi.worldDay << fi.worldWeek << fi.worldMonth - << fi.mainLanguage; + return stream << fi.availablePlayerColors << fi.humanPlayerColors << fi.computerPlayerColors << fi.colorsOfRandomRaces << fi.victoryConditionType + << fi.isVictoryConditionApplicableForAI << fi.allowNormalVictory << fi.victoryConditionParams[0] << fi.victoryConditionParams[1] << fi.lossConditionType + << fi.lossConditionParams[0] << fi.lossConditionParams[1] << fi.timestamp << fi.startWithHeroInFirstCastle << fi.version << fi.worldDay << fi.worldWeek + << fi.worldMonth << fi.mainLanguage; } IStreamBase & Maps::operator>>( IStreamBase & stream, FileInfo & fi ) @@ -676,9 +676,10 @@ IStreamBase & Maps::operator>>( IStreamBase & stream, FileInfo & fi ) } } - stream >> fi.kingdomColors >> fi.colorsAvailableForHumans >> fi.colorsAvailableForComp >> fi.colorsOfRandomRaces >> fi.victoryConditionType >> fi.compAlsoWins - >> fi.allowNormalVictory >> fi.victoryConditionParams[0] >> fi.victoryConditionParams[1] >> fi.lossConditionType >> fi.lossConditionParams[0] - >> fi.lossConditionParams[1] >> fi.timestamp >> fi.startWithHeroInFirstCastle >> fi.version >> fi.worldDay >> fi.worldWeek >> fi.worldMonth; + stream >> fi.availablePlayerColors >> fi.humanPlayerColors >> fi.computerPlayerColors >> fi.colorsOfRandomRaces >> fi.victoryConditionType + >> fi.isVictoryConditionApplicableForAI >> fi.allowNormalVictory >> fi.victoryConditionParams[0] >> fi.victoryConditionParams[1] >> fi.lossConditionType + >> fi.lossConditionParams[0] >> fi.lossConditionParams[1] >> fi.timestamp >> fi.startWithHeroInFirstCastle >> fi.version >> fi.worldDay >> fi.worldWeek + >> fi.worldMonth; static_assert( LAST_SUPPORTED_FORMAT_VERSION < FORMAT_VERSION_1103_RELEASE, "Remove the logic below." ); if ( Game::GetVersionOfCurrentSaveFile() < FORMAT_VERSION_1103_RELEASE ) { diff --git a/src/fheroes2/maps/maps_fileinfo.h b/src/fheroes2/maps/maps_fileinfo.h index ab6694c3eb0..527fd91e313 100644 --- a/src/fheroes2/maps/maps_fileinfo.h +++ b/src/fheroes2/maps/maps_fileinfo.h @@ -80,17 +80,17 @@ namespace Maps int AllowCompHumanColors() const { - return colorsAvailableForHumans & colorsAvailableForComp; + return humanPlayerColors & computerPlayerColors; } int HumanOnlyColors() const { - return colorsAvailableForHumans & ~colorsAvailableForComp; + return humanPlayerColors & ~computerPlayerColors; } int ComputerOnlyColors() const { - return colorsAvailableForComp & ~colorsAvailableForHumans; + return computerPlayerColors & ~humanPlayerColors; } int KingdomRace( int color ) const; @@ -132,7 +132,7 @@ namespace Maps void removeHumanColors( const int colors ) { - colorsAvailableForHumans &= ~colors; + humanPlayerColors &= ~colors; } bool AllowChangeRace( const int color ) const @@ -185,14 +185,14 @@ namespace Maps std::array races; std::array unions; - uint8_t kingdomColors; - uint8_t colorsAvailableForHumans; - uint8_t colorsAvailableForComp; + uint8_t availablePlayerColors; + uint8_t humanPlayerColors; + uint8_t computerPlayerColors; uint8_t colorsOfRandomRaces; // Refer to the VictoryCondition enumeration. uint8_t victoryConditionType; - bool compAlsoWins; + bool isVictoryConditionApplicableForAI; bool allowNormalVictory; std::array victoryConditionParams; diff --git a/src/fheroes2/system/players.cpp b/src/fheroes2/system/players.cpp index 31f1bcc9927..0f41114dbc9 100644 --- a/src/fheroes2/system/players.cpp +++ b/src/fheroes2/system/players.cpp @@ -326,13 +326,13 @@ void Players::Init( int colors ) void Players::Init( const Maps::FileInfo & fi ) { - if ( fi.kingdomColors == 0 ) { + if ( fi.availablePlayerColors == 0 ) { DEBUG_LOG( DBG_GAME, DBG_INFO, "No players are set." ) return; } clear(); - const Colors vcolors( fi.kingdomColors ); + const Colors vcolors( fi.availablePlayerColors ); Player * first = nullptr; @@ -344,7 +344,7 @@ void Players::Init( const Maps::FileInfo & fi ) if ( ( color & fi.HumanOnlyColors() ) && Settings::Get().IsGameType( Game::TYPE_MULTI ) ) player->SetControl( CONTROL_HUMAN ); - else if ( color & fi.colorsAvailableForHumans ) + else if ( color & fi.humanPlayerColors ) player->SetControl( player->GetControl() | CONTROL_HUMAN ); if ( !first && ( player->GetControl() & CONTROL_HUMAN ) )