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

Standartize member naming for Maps::FileInfo structure #9237

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/fheroes2/campaign/campaign_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,15 @@ 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.
assert( 0 );
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 );
Expand Down
5 changes: 3 additions & 2 deletions src/fheroes2/dialog/dialog_selectscenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/editor/editor_save_map_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace
fileNameText.fitToOneRow( maxFileNameWidth - 40 );
fileNameText.draw( posX + 44, posY + 2, display );

const uint32_t racesCountIcnIndex = static_cast<uint32_t>( Color::Count( info.kingdomColors ) + 19 );
const uint32_t racesCountIcnIndex = static_cast<uint32_t>( 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() );

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/gui/player_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
57 changes: 29 additions & 28 deletions src/fheroes2/maps/maps_fileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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 );

Expand All @@ -326,9 +326,9 @@ bool Maps::FileInfo::readMP2Map( std::string filePath, const bool isForEditor )
tile.Init( 0, mp2tile );

const std::pair<int, int> 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 );

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down Expand Up @@ -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 ) {
Expand Down
16 changes: 8 additions & 8 deletions src/fheroes2/maps/maps_fileinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +132,7 @@ namespace Maps

void removeHumanColors( const int colors )
{
colorsAvailableForHumans &= ~colors;
humanPlayerColors &= ~colors;
}

bool AllowChangeRace( const int color ) const
Expand Down Expand Up @@ -185,14 +185,14 @@ namespace Maps
std::array<uint8_t, maxNumOfPlayers> races;
std::array<uint8_t, maxNumOfPlayers> unions;

uint8_t kingdomColors;
uint8_t colorsAvailableForHumans;
uint8_t colorsAvailableForComp;
uint8_t availablePlayerColors;
uint8_t humanPlayerColors;
uint8_t computerPlayerColors;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now these names look like these colors are specifically used by human (or computer) players while in fact it may not be really the case, because the same colors may be available both for a human player and for AI. In this regard, "colorsAvailableForXXX" sounds more right IMHO. But this is of course a matter of taste.

uint8_t colorsOfRandomRaces;

// Refer to the VictoryCondition enumeration.
uint8_t victoryConditionType;
bool compAlsoWins;
bool isVictoryConditionApplicableForAI;
bool allowNormalVictory;
std::array<uint16_t, 2> victoryConditionParams;

Expand Down
6 changes: 3 additions & 3 deletions src/fheroes2/system/players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 ) )
Expand Down
Loading