mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
* fixed bug when starting certain maps in campaigns
* introduced TPlayerColor typedef
This commit is contained in:
@@ -832,8 +832,7 @@ void startGame(StartInfo * options, CConnection *serv/* = NULL*/)
|
||||
SDL_FillRect(screen, 0, 0);
|
||||
if(gOnlyAI)
|
||||
{
|
||||
for(std::map<int, PlayerSettings>::iterator it = options->playerInfos.begin();
|
||||
it != options->playerInfos.end(); ++it)
|
||||
for(auto it = options->playerInfos.begin(); it != options->playerInfos.end(); ++it)
|
||||
{
|
||||
it->second.human = false;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ static void swapPlayers(PlayerSettings &a, PlayerSettings &b)
|
||||
playerColor = b.color;
|
||||
}
|
||||
|
||||
void setPlayer(PlayerSettings &pset, unsigned player, const std::map<ui32, std::string> &playerNames)
|
||||
void setPlayer(PlayerSettings &pset, TPlayerColor player, const std::map<TPlayerColor, std::string> &playerNames)
|
||||
{
|
||||
if(vstd::contains(playerNames, player))
|
||||
pset.name = playerNames.find(player)->second;
|
||||
@@ -134,7 +134,7 @@ void setPlayer(PlayerSettings &pset, unsigned player, const std::map<ui32, std::
|
||||
playerColor = pset.color;
|
||||
}
|
||||
|
||||
void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * mapHeader, const std::map<ui32, std::string> &playerNames)
|
||||
void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * mapHeader, const std::map<TPlayerColor, std::string> &playerNames)
|
||||
{
|
||||
sInfo.playerInfos.clear();
|
||||
if(!filename.size())
|
||||
@@ -144,7 +144,7 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader *
|
||||
sInfo.mapname = filename;
|
||||
playerColor = -1;
|
||||
|
||||
std::map<ui32, std::string>::const_iterator namesIt = playerNames.begin();
|
||||
auto namesIt = playerNames.cbegin();
|
||||
|
||||
for (int i = 0; i < GameConstants::PLAYER_LIMIT; i++)
|
||||
{
|
||||
@@ -156,7 +156,7 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader *
|
||||
|
||||
PlayerSettings &pset = sInfo.playerInfos[i];
|
||||
pset.color = i;
|
||||
if(pinfo.canHumanPlay && namesIt != playerNames.end())
|
||||
if(pinfo.canHumanPlay && namesIt != playerNames.cend())
|
||||
setPlayer(pset, namesIt++->first, playerNames);
|
||||
else
|
||||
setPlayer(pset, 0, playerNames);
|
||||
@@ -537,7 +537,7 @@ void CGPreGame::removeFromGui()
|
||||
GH.popInt(GH.topInt()); //remove background
|
||||
}
|
||||
|
||||
CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/, const std::map<ui32, std::string> *Names /*= NULL*/)
|
||||
CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/, const std::map<TPlayerColor, std::string> *Names /*= NULL*/)
|
||||
: ISelectionScreenInfo(Names), serverHandlingThread(NULL), mx(new boost::recursive_mutex),
|
||||
serv(NULL), ongoingClosing(false), myNameID(255)
|
||||
{
|
||||
@@ -802,12 +802,12 @@ void CSelectionScreen::startGame()
|
||||
if(screenType == CMenuScreen::newGame)
|
||||
{
|
||||
//there must be at least one human player before game can be started
|
||||
std::map<int, PlayerSettings>::const_iterator i;
|
||||
for(i = SEL->sInfo.playerInfos.begin(); i != SEL->sInfo.playerInfos.end(); i++)
|
||||
std::map<TPlayerColor, PlayerSettings>::const_iterator i;
|
||||
for(i = SEL->sInfo.playerInfos.cbegin(); i != SEL->sInfo.playerInfos.cend(); i++)
|
||||
if(i->second.human)
|
||||
break;
|
||||
|
||||
if(i == SEL->sInfo.playerInfos.end())
|
||||
if(i == SEL->sInfo.playerInfos.cend())
|
||||
{
|
||||
GH.pushInt(CInfoWindow::create(CGI->generaltexth->allTexts[530])); //You must position yourself prior to starting the game.
|
||||
return;
|
||||
@@ -900,8 +900,8 @@ void CSelectionScreen::handleConnection()
|
||||
|
||||
void CSelectionScreen::setSInfo(const StartInfo &si)
|
||||
{
|
||||
std::map<int, PlayerSettings>::const_iterator i;
|
||||
for(i = si.playerInfos.begin(); i != si.playerInfos.end(); i++)
|
||||
std::map<TPlayerColor, PlayerSettings>::const_iterator i;
|
||||
for(i = si.playerInfos.cbegin(); i != si.playerInfos.cend(); i++)
|
||||
{
|
||||
if(i->second.human == myNameID)
|
||||
{
|
||||
@@ -910,7 +910,7 @@ void CSelectionScreen::setSInfo(const StartInfo &si)
|
||||
}
|
||||
}
|
||||
|
||||
if(i == si.playerInfos.end()) //not found
|
||||
if(i == si.playerInfos.cend()) //not found
|
||||
playerColor = -1;
|
||||
|
||||
sInfo = si;
|
||||
@@ -1653,9 +1653,9 @@ void InfoCard::showAll(SDL_Surface * to)
|
||||
}
|
||||
else //players list
|
||||
{
|
||||
std::map<ui32, std::string> playerNames = SEL->playerNames;
|
||||
std::map<TPlayerColor, std::string> playerNames = SEL->playerNames;
|
||||
int playerSoFar = 0;
|
||||
for (std::map<int, PlayerSettings>::const_iterator i = SEL->sInfo.playerInfos.begin(); i != SEL->sInfo.playerInfos.end(); i++)
|
||||
for (auto i = SEL->sInfo.playerInfos.cbegin(); i != SEL->sInfo.playerInfos.cend(); i++)
|
||||
{
|
||||
if(i->second.human)
|
||||
{
|
||||
@@ -1665,7 +1665,7 @@ void InfoCard::showAll(SDL_Surface * to)
|
||||
}
|
||||
|
||||
playerSoFar = 0;
|
||||
for (std::map<ui32, std::string>::const_iterator i = playerNames.begin(); i != playerNames.end(); i++)
|
||||
for (auto i = playerNames.cbegin(); i != playerNames.cend(); i++)
|
||||
{
|
||||
printAtLoc(i->second, 193, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, Colors::Cornsilk, to);
|
||||
}
|
||||
@@ -1744,7 +1744,7 @@ void InfoCard::showAll(SDL_Surface * to)
|
||||
else
|
||||
myT = -1;
|
||||
|
||||
for (std::map<int, PlayerSettings>::const_iterator i = SEL->sInfo.playerInfos.begin(); i != SEL->sInfo.playerInfos.end(); i++)
|
||||
for (auto i = SEL->sInfo.playerInfos.cbegin(); i != SEL->sInfo.playerInfos.cend(); i++)
|
||||
{
|
||||
int *myx = ((i->first == playerColor || SEL->current->mapHeader->players[i->first].team == myT) ? &fx : &ex);
|
||||
blitAtLoc(sFlags->ourImages[i->first].bitmap, *myx, 399, to);
|
||||
@@ -2059,8 +2059,7 @@ void OptionsTab::recreate()
|
||||
usedHeroes.clear();
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
for(std::map<int, PlayerSettings>::iterator it = SEL->sInfo.playerInfos.begin();
|
||||
it != SEL->sInfo.playerInfos.end(); ++it)
|
||||
for(auto it = SEL->sInfo.playerInfos.begin(); it != SEL->sInfo.playerInfos.end(); ++it)
|
||||
{
|
||||
entries.insert(std::make_pair(it->first, new PlayerOptionsEntry(this, it->second)));
|
||||
const std::vector<SheroName> &heroes = SEL->current->mapHeader->players[it->first].heroesNames;
|
||||
@@ -2115,7 +2114,7 @@ void OptionsTab::flagPressed( int color )
|
||||
}
|
||||
else //human clicked -> take next
|
||||
{
|
||||
std::map<ui32, std::string>::const_iterator i = SEL->playerNames.find(clickedNameID); //clicked one
|
||||
auto i = SEL->playerNames.find(clickedNameID); //clicked one
|
||||
i++; //player AFTER clicked one
|
||||
|
||||
if(i != SEL->playerNames.end())
|
||||
@@ -2129,7 +2128,7 @@ void OptionsTab::flagPressed( int color )
|
||||
//if that player was somewhere else, we need to replace him with computer
|
||||
if(newPlayer) //not AI
|
||||
{
|
||||
for(std::map<int, PlayerSettings>::iterator i = SEL->sInfo.playerInfos.begin(); i != SEL->sInfo.playerInfos.end(); i++)
|
||||
for(auto i = SEL->sInfo.playerInfos.begin(); i != SEL->sInfo.playerInfos.end(); i++)
|
||||
{
|
||||
int curNameID = i->second.human;
|
||||
if(i->first != color && curNameID == newPlayer)
|
||||
@@ -2560,8 +2559,7 @@ CScenarioInfo::CScenarioInfo(const CMapHeader *mapHeader, const StartInfo *start
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
|
||||
for(std::map<int, PlayerSettings>::const_iterator it = startInfo->playerInfos.begin();
|
||||
it != startInfo->playerInfos.end(); ++it)
|
||||
for(auto it = startInfo->playerInfos.cbegin(); it != startInfo->playerInfos.cend(); ++it)
|
||||
{
|
||||
if(it->second.human)
|
||||
{
|
||||
@@ -2729,7 +2727,7 @@ void CHotSeatPlayers::onChange(std::string newText)
|
||||
|
||||
void CHotSeatPlayers::enterSelectionScreen()
|
||||
{
|
||||
std::map<ui32, std::string> names;
|
||||
std::map<TPlayerColor, std::string> names;
|
||||
for(int i = 0, j = 1; i < ARRAY_COUNT(txt); i++)
|
||||
if(txt[i]->text.length())
|
||||
names[j++] = txt[i]->text;
|
||||
@@ -2937,7 +2935,7 @@ void CBonusSelection::selectMap( int whichOne )
|
||||
ourHeader = new CMapHeader();
|
||||
ourHeader->initFromMemory((const unsigned char*)ourCampaign->camp->mapPieces.find(whichOne)->second.data(), i);
|
||||
|
||||
std::map<ui32, std::string> names;
|
||||
std::map<TPlayerColor, std::string> names;
|
||||
names[1] = settings["general"]["playerName"].String();
|
||||
updateStartInfo(ourCampaign->camp->header.filename, sInfo, ourHeader, names);
|
||||
sInfo.turnTime = 0;
|
||||
@@ -2992,7 +2990,7 @@ void CBonusSelection::show(SDL_Surface * to)
|
||||
int ex = 629 + graphics->fonts[FONT_SMALL]->getWidth(CGI->generaltexth->allTexts[391].c_str());
|
||||
int myT;
|
||||
myT = ourHeader->players[playerColor].team;
|
||||
for (std::map<int, PlayerSettings>::const_iterator i = sInfo.playerInfos.begin(); i != sInfo.playerInfos.end(); i++)
|
||||
for (auto i = sInfo.playerInfos.cbegin(); i != sInfo.playerInfos.cend(); i++)
|
||||
{
|
||||
int *myx = ((i->first == playerColor || ourHeader->players[i->first].team == myT) ? &fx : &ex);
|
||||
blitAtLoc(sFlags->ourImages[i->first].bitmap, pos.x + *myx, pos.y + 405, to);
|
||||
@@ -3054,8 +3052,7 @@ void CBonusSelection::updateBonusSelection()
|
||||
case CScenarioTravel::STravelBonus::BUILDING:
|
||||
{
|
||||
int faction = -1;
|
||||
for(std::map<int, PlayerSettings>::iterator it = sInfo.playerInfos.begin();
|
||||
it != sInfo.playerInfos.end(); ++it)
|
||||
for(auto it = sInfo.playerInfos.begin(); it != sInfo.playerInfos.end(); ++it)
|
||||
{
|
||||
if (it->second.human)
|
||||
{
|
||||
@@ -3225,7 +3222,7 @@ void CBonusSelection::selectBonus( int id )
|
||||
const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
|
||||
if (bonDescs[id].type == CScenarioTravel::STravelBonus::HERO)
|
||||
{
|
||||
std::map<ui32, std::string> names;
|
||||
std::map<TPlayerColor, std::string> names;
|
||||
names[1] = settings["general"]["playerName"].String();
|
||||
for(auto it = sInfo.playerInfos.begin(); it != sInfo.playerInfos.end(); ++it)
|
||||
{
|
||||
@@ -3345,7 +3342,7 @@ CSavingScreen::~CSavingScreen()
|
||||
|
||||
}
|
||||
|
||||
ISelectionScreenInfo::ISelectionScreenInfo(const std::map<ui32, std::string> *Names /*= NULL*/)
|
||||
ISelectionScreenInfo::ISelectionScreenInfo(const std::map<TPlayerColor, std::string> *Names /*= NULL*/)
|
||||
{
|
||||
multiPlayer = CMenuScreen::SINGLE_PLAYER;
|
||||
assert(!SEL);
|
||||
@@ -3369,14 +3366,14 @@ void ISelectionScreenInfo::updateStartInfo(std::string filename, StartInfo & sIn
|
||||
::updateStartInfo(filename, sInfo, mapHeader, playerNames);
|
||||
}
|
||||
|
||||
void ISelectionScreenInfo::setPlayer(PlayerSettings &pset, unsigned player)
|
||||
void ISelectionScreenInfo::setPlayer(PlayerSettings &pset, TPlayerColor player)
|
||||
{
|
||||
::setPlayer(pset, player, playerNames);
|
||||
}
|
||||
|
||||
int ISelectionScreenInfo::getIdOfFirstUnallocatedPlayer()
|
||||
{
|
||||
for(std::map<ui32, std::string>::const_iterator i = playerNames.begin(); i != playerNames.end(); i++)
|
||||
for(auto i = playerNames.cbegin(); i != playerNames.cend(); i++)
|
||||
if(!sInfo.getPlayersSettings(i->first)) //
|
||||
return i->first;
|
||||
|
||||
@@ -3416,7 +3413,7 @@ void PlayerJoined::apply(CSelectionScreen *selScreen)
|
||||
SEL->playerNames[connectionID] = playerName;
|
||||
|
||||
//put new player in first slot with AI
|
||||
for(std::map<int, PlayerSettings>::iterator i = SEL->sInfo.playerInfos.begin(); i != SEL->sInfo.playerInfos.end(); i++)
|
||||
for(auto i = SEL->sInfo.playerInfos.begin(); i != SEL->sInfo.playerInfos.end(); i++)
|
||||
{
|
||||
if(!i->second.human)
|
||||
{
|
||||
|
||||
@@ -255,16 +255,16 @@ public:
|
||||
CMenuScreen::EState screenType; //new/save/load#Game
|
||||
const CMapInfo *current;
|
||||
StartInfo sInfo;
|
||||
std::map<ui32, std::string> playerNames; // id of player <-> player name; 0 is reserved as ID of AI "players"
|
||||
std::map<TPlayerColor, std::string> playerNames; // id of player <-> player name; 0 is reserved as ID of AI "players"
|
||||
|
||||
ISelectionScreenInfo(const std::map<ui32, std::string> *Names = NULL);
|
||||
ISelectionScreenInfo(const std::map<TPlayerColor, std::string> *Names = NULL);
|
||||
virtual ~ISelectionScreenInfo();
|
||||
virtual void update(){};
|
||||
virtual void propagateOptions() {};
|
||||
virtual void postRequest(ui8 what, ui8 dir) {};
|
||||
virtual void postChatMessage(const std::string &txt){};
|
||||
|
||||
void setPlayer(PlayerSettings &pset, unsigned player);
|
||||
void setPlayer(PlayerSettings &pset, TPlayerColor player);
|
||||
void updateStartInfo( std::string filename, StartInfo & sInfo, const CMapHeader * mapHeader );
|
||||
|
||||
int getIdOfFirstUnallocatedPlayer(); //returns 0 if none
|
||||
@@ -294,7 +294,7 @@ public:
|
||||
bool ongoingClosing;
|
||||
ui8 myNameID; //used when networking - otherwise all player are "mine"
|
||||
|
||||
CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer = CMenuScreen::SINGLE_PLAYER, const std::map<ui32, std::string> *Names = NULL);
|
||||
CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer = CMenuScreen::SINGLE_PLAYER, const std::map<TPlayerColor, std::string> *Names = NULL);
|
||||
~CSelectionScreen();
|
||||
void toggleTab(CIntObject *tab);
|
||||
void changeSelection(const CMapInfo *to);
|
||||
|
||||
@@ -269,7 +269,7 @@ void CClient::loadGame( const std::string & fname )
|
||||
tlog0 << "Server opened savegame properly.\n";
|
||||
|
||||
*serv << ui32(gs->scenarioOps->playerInfos.size()+1); //number of players + neutral
|
||||
for(std::map<int, PlayerSettings>::iterator it = gs->scenarioOps->playerInfos.begin();
|
||||
for(auto it = gs->scenarioOps->playerInfos.begin();
|
||||
it != gs->scenarioOps->playerInfos.end(); ++it)
|
||||
{
|
||||
*serv << ui8(it->first); //players
|
||||
@@ -286,7 +286,7 @@ void CClient::loadGame( const std::string & fname )
|
||||
void CClient::newGame( CConnection *con, StartInfo *si )
|
||||
{
|
||||
enum {SINGLE, HOST, GUEST} networkMode = SINGLE;
|
||||
std::set<ui8> myPlayers;
|
||||
std::set<TPlayerColor> myPlayers;
|
||||
|
||||
if (con == NULL)
|
||||
{
|
||||
@@ -299,14 +299,13 @@ void CClient::newGame( CConnection *con, StartInfo *si )
|
||||
networkMode = (con->connectionID == 1) ? HOST : GUEST;
|
||||
}
|
||||
|
||||
for(std::map<int, PlayerSettings>::iterator it =si->playerInfos.begin();
|
||||
it != si->playerInfos.end(); ++it)
|
||||
for(auto it = si->playerInfos.begin(); it != si->playerInfos.end(); ++it)
|
||||
{
|
||||
if((networkMode == SINGLE) //single - one client has all player
|
||||
|| (networkMode != SINGLE && serv->connectionID == it->second.human) //multi - client has only "its players"
|
||||
|| (networkMode == HOST && it->second.human == false)) //multi - host has all AI players
|
||||
{
|
||||
myPlayers.insert(ui8(it->first)); //add player
|
||||
myPlayers.insert(it->first); //add player
|
||||
}
|
||||
}
|
||||
if(networkMode != GUEST)
|
||||
@@ -353,7 +352,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
|
||||
|
||||
int humanPlayers = 0;
|
||||
int sensibleAILimit = settings["session"]["oneGoodAI"].Bool() ? 1 : GameConstants::PLAYER_LIMIT;
|
||||
for(std::map<int, PlayerSettings>::iterator it = gs->scenarioOps->playerInfos.begin();
|
||||
for(auto it = gs->scenarioOps->playerInfos.begin();
|
||||
it != gs->scenarioOps->playerInfos.end(); ++it)//initializing interfaces for players
|
||||
{
|
||||
ui8 color = it->first;
|
||||
|
||||
@@ -5527,7 +5527,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
|
||||
|
||||
//data for information table:
|
||||
// fields[row][column] = list of id's of players for this box
|
||||
static std::vector< std::vector< ui8 > > SThievesGuildInfo::* fields[] =
|
||||
static std::vector< std::vector< TPlayerColor > > SThievesGuildInfo::* fields[] =
|
||||
{ &SThievesGuildInfo::numOfTowns, &SThievesGuildInfo::numOfHeroes, &SThievesGuildInfo::gold,
|
||||
&SThievesGuildInfo::woodOre, &SThievesGuildInfo::mercSulfCrystGems, &SThievesGuildInfo::obelisks,
|
||||
&SThievesGuildInfo::artifacts, &SThievesGuildInfo::army, &SThievesGuildInfo::income };
|
||||
@@ -5559,7 +5559,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
|
||||
{
|
||||
for(int b=0; b<(tgi .* fields[g]).size(); ++b) //by places (1st, 2nd, ...)
|
||||
{
|
||||
std::vector<ui8> &players = (tgi .* fields[g])[b]; //get players with this place in this line
|
||||
std::vector<TPlayerColor> &players = (tgi .* fields[g])[b]; //get players with this place in this line
|
||||
|
||||
//position of box
|
||||
int xpos = 259 + 66 * b;
|
||||
|
||||
@@ -383,7 +383,7 @@ static CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
|
||||
return nobj;
|
||||
}
|
||||
|
||||
CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass /*= NULL*/) const
|
||||
CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, TPlayerColor player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass /*= NULL*/) const
|
||||
{
|
||||
CGHeroInstance *ret = NULL;
|
||||
|
||||
@@ -397,7 +397,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co
|
||||
|
||||
if(native)
|
||||
{
|
||||
for(bmap<ui32, ConstTransitivePtr<CGHeroInstance> >::iterator i=available.begin(); i!=available.end(); i++)
|
||||
for(auto i=available.begin(); i!=available.end(); i++)
|
||||
{
|
||||
if(pavailable.find(i->first)->second & 1<<player
|
||||
&& i->second->type->heroType/2 == town->typeID)
|
||||
@@ -419,7 +419,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co
|
||||
{
|
||||
int sum=0, r;
|
||||
|
||||
for(bmap<ui32, ConstTransitivePtr<CGHeroInstance> >::iterator i=available.begin(); i!=available.end(); i++)
|
||||
for(auto i=available.begin(); i!=available.end(); i++)
|
||||
{
|
||||
if ((!bannedClass && (pavailable.find(i->first)->second & (1<<player))) ||
|
||||
i->second->type->heroClass != bannedClass)
|
||||
@@ -928,7 +928,7 @@ void CGameState::init(StartInfo * si)
|
||||
|
||||
//picking random factions for players
|
||||
tlog4 << "\tPicking random factions for players";
|
||||
for(std::map<int, PlayerSettings>::iterator it = scenarioOps->playerInfos.begin();
|
||||
for(auto it = scenarioOps->playerInfos.begin();
|
||||
it != scenarioOps->playerInfos.end(); ++it)
|
||||
{
|
||||
if(it->second.castle==-1)
|
||||
@@ -962,10 +962,10 @@ void CGameState::init(StartInfo * si)
|
||||
|
||||
/*********creating players entries in gs****************************************/
|
||||
tlog4 << "\tCreating player entries in gs";
|
||||
for(std::map<int, PlayerSettings>::iterator it = scenarioOps->playerInfos.begin();
|
||||
for(auto it = scenarioOps->playerInfos.begin();
|
||||
it != scenarioOps->playerInfos.end(); ++it)
|
||||
{
|
||||
std::pair<int,PlayerState> ins(it->first,PlayerState());
|
||||
std::pair<TPlayerColor,PlayerState> ins(it->first,PlayerState());
|
||||
ins.second.color=ins.first;
|
||||
ins.second.human = it->second.human;
|
||||
ins.second.team = map->players[ins.first].team;
|
||||
@@ -976,22 +976,22 @@ void CGameState::init(StartInfo * si)
|
||||
|
||||
/*********give starting hero****************************************/
|
||||
tlog4 << "\tGiving starting hero";
|
||||
for(int i=0;i<GameConstants::PLAYER_LIMIT;i++)
|
||||
for(auto it = scenarioOps->playerInfos.begin(); it != scenarioOps->playerInfos.end(); ++it)
|
||||
{
|
||||
const PlayerInfo &p = map->players[i];
|
||||
bool campaignGiveHero = scenarioOps->playerInfos[i].human && scenarioOps->mode == StartInfo::CAMPAIGN &&
|
||||
const PlayerInfo &p = map->players[it->first];
|
||||
bool campaignGiveHero = it->second.human && scenarioOps->mode == StartInfo::CAMPAIGN &&
|
||||
scenarioOps->campState->getBonusForCurrentMap().type == CScenarioTravel::STravelBonus::HERO;
|
||||
bool generateHero = (p.generateHeroAtMainTown || campaignGiveHero) && p.hasMainTown;
|
||||
if(generateHero && vstd::contains(scenarioOps->playerInfos, i))
|
||||
if(generateHero && vstd::contains(scenarioOps->playerInfos, it->first))
|
||||
{
|
||||
int3 hpos = p.posOfMainTown;
|
||||
hpos.x+=1;
|
||||
|
||||
int h = pickHero(i);
|
||||
if(scenarioOps->playerInfos[i].hero == -1)
|
||||
scenarioOps->playerInfos[i].hero = h;
|
||||
int h = pickHero(it->first);
|
||||
if(it->second.hero == -1)
|
||||
it->second.hero = h;
|
||||
|
||||
CGHeroInstance * nnn = static_cast<CGHeroInstance*>(createObject(Obj::HERO,h,hpos,i));
|
||||
CGHeroInstance * nnn = static_cast<CGHeroInstance*>(createObject(Obj::HERO,h,hpos,it->first));
|
||||
nnn->id = map->objects.size();
|
||||
nnn->initHero();
|
||||
map->heroes.push_back(nnn);
|
||||
@@ -1079,7 +1079,7 @@ void CGameState::init(StartInfo * si)
|
||||
TResources startresAI(level["ai"]);
|
||||
TResources startresHuman(level["human"]);
|
||||
|
||||
for (std::map<ui8,PlayerState>::iterator i = players.begin(); i!=players.end(); i++)
|
||||
for (auto i = players.begin(); i!=players.end(); i++)
|
||||
{
|
||||
PlayerState &p = i->second;
|
||||
|
||||
@@ -1182,7 +1182,7 @@ void CGameState::init(StartInfo * si)
|
||||
{
|
||||
//find human player
|
||||
int humanPlayer=GameConstants::NEUTRAL_PLAYER;
|
||||
for (std::map<ui8, PlayerState>::iterator it=players.begin(); it != players.end(); ++it)
|
||||
for (auto it=players.begin(); it != players.end(); ++it)
|
||||
{
|
||||
if(it->second.human)
|
||||
{
|
||||
@@ -1225,7 +1225,7 @@ void CGameState::init(StartInfo * si)
|
||||
|
||||
/*************************FOG**OF**WAR******************************************/
|
||||
tlog4 << "\tFog of war";
|
||||
for(std::map<ui8, TeamState>::iterator k=teams.begin(); k!=teams.end(); ++k)
|
||||
for(auto k=teams.begin(); k!=teams.end(); ++k)
|
||||
{
|
||||
k->second.fogOfWarMap.resize(map->width);
|
||||
for(int g=0; g<map->width; ++g)
|
||||
@@ -1254,7 +1254,7 @@ void CGameState::init(StartInfo * si)
|
||||
}
|
||||
|
||||
tlog4 << "\tStarting bonuses";
|
||||
for(std::map<ui8, PlayerState>::iterator k=players.begin(); k!=players.end(); ++k)
|
||||
for(auto k=players.begin(); k!=players.end(); ++k)
|
||||
{
|
||||
//starting bonus
|
||||
if(scenarioOps->playerInfos[k->first].bonus==PlayerSettings::brandom)
|
||||
@@ -1441,7 +1441,7 @@ void CGameState::init(StartInfo * si)
|
||||
|
||||
buildBonusSystemTree();
|
||||
|
||||
for(std::map<ui8, PlayerState>::iterator k=players.begin(); k!=players.end(); ++k)
|
||||
for(auto k=players.begin(); k!=players.end(); ++k)
|
||||
{
|
||||
if(k->first==255)
|
||||
continue;
|
||||
@@ -2149,8 +2149,8 @@ ui8 CGameState::checkForStandardWin() const
|
||||
{
|
||||
//std victory condition is:
|
||||
//all enemies lost
|
||||
ui8 supposedWinner = 255, winnerTeam = 255;
|
||||
for(std::map<ui8,PlayerState>::const_iterator i = players.begin(); i != players.end(); i++)
|
||||
TPlayerColor supposedWinner = 255, winnerTeam = 255;
|
||||
for(auto i = players.begin(); i != players.end(); i++)
|
||||
{
|
||||
if(i->second.status == PlayerState::INGAME && i->first < GameConstants::PLAYER_LIMIT)
|
||||
{
|
||||
@@ -2180,15 +2180,15 @@ bool CGameState::checkForStandardLoss( ui8 player ) const
|
||||
|
||||
struct statsHLP
|
||||
{
|
||||
typedef std::pair< ui8, si64 > TStat;
|
||||
typedef std::pair< TPlayerColor, si64 > TStat;
|
||||
//converts [<player's color, value>] to vec[place] -> platers
|
||||
static std::vector< std::vector< ui8 > > getRank( std::vector<TStat> stats )
|
||||
static std::vector< std::vector< TPlayerColor > > getRank( std::vector<TStat> stats )
|
||||
{
|
||||
std::sort(stats.begin(), stats.end(), statsHLP());
|
||||
|
||||
//put first element
|
||||
std::vector< std::vector<ui8> > ret;
|
||||
std::vector<ui8> tmp;
|
||||
std::vector< std::vector<TPlayerColor> > ret;
|
||||
std::vector<TPlayerColor> tmp;
|
||||
tmp.push_back( stats[0].first );
|
||||
ret.push_back( tmp );
|
||||
|
||||
@@ -2202,7 +2202,7 @@ struct statsHLP
|
||||
else
|
||||
{
|
||||
//create next occupied rank
|
||||
std::vector<ui8> tmp;
|
||||
std::vector<TPlayerColor> tmp;
|
||||
tmp.push_back(stats[g].first);
|
||||
ret.push_back(tmp);
|
||||
}
|
||||
@@ -2249,8 +2249,8 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
{
|
||||
#define FILL_FIELD(FIELD, VAL_GETTER) \
|
||||
{ \
|
||||
std::vector< std::pair< ui8, si64 > > stats; \
|
||||
for(std::map<ui8, PlayerState>::const_iterator g = players.begin(); g != players.end(); ++g) \
|
||||
std::vector< std::pair< TPlayerColor, si64 > > stats; \
|
||||
for(auto g = players.begin(); g != players.end(); ++g) \
|
||||
{ \
|
||||
if(g->second.color == 255) \
|
||||
continue; \
|
||||
@@ -2262,7 +2262,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
tgi.FIELD = statsHLP::getRank(stats); \
|
||||
}
|
||||
|
||||
for(std::map<ui8, PlayerState>::const_iterator g = players.begin(); g != players.end(); ++g)
|
||||
for(auto g = players.begin(); g != players.end(); ++g)
|
||||
{
|
||||
if(g->second.color != 255)
|
||||
tgi.playerColors.push_back(g->second.color);
|
||||
@@ -2275,7 +2275,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
//num of heroes
|
||||
FILL_FIELD(numOfHeroes, g->second.heroes.size())
|
||||
//best hero's portrait
|
||||
for(std::map<ui8, PlayerState>::const_iterator g = players.begin(); g != players.end(); ++g)
|
||||
for(auto g = players.cbegin(); g != players.cend(); ++g)
|
||||
{
|
||||
if(g->second.color == 255)
|
||||
continue;
|
||||
@@ -2320,7 +2320,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
}
|
||||
if(level >= 9) //personality
|
||||
{
|
||||
for(std::map<ui8, PlayerState>::const_iterator g = players.begin(); g != players.end(); ++g)
|
||||
for(auto g = players.cbegin(); g != players.cend(); ++g)
|
||||
{
|
||||
if(g->second.color == 255) //do nothing for neutral player
|
||||
continue;
|
||||
@@ -2338,7 +2338,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
|
||||
if(level >= 10) //best creature
|
||||
{
|
||||
//best creatures belonging to player (highest AI value)
|
||||
for(std::map<ui8, PlayerState>::const_iterator g = players.begin(); g != players.end(); ++g)
|
||||
for(auto g = players.cbegin(); g != players.cend(); ++g)
|
||||
{
|
||||
if(g->second.color == 255) //do nothing for neutral player
|
||||
continue;
|
||||
@@ -2409,8 +2409,8 @@ int CGameState::lossCheck( ui8 player ) const
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > CGameState::unusedHeroesFromPool()
|
||||
{
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > pool = hpool.heroesPool;
|
||||
for ( std::map<ui8, PlayerState>::iterator i = players.begin() ; i != players.end();i++)
|
||||
for(std::vector< ConstTransitivePtr<CGHeroInstance> >::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++)
|
||||
for ( auto i = players.cbegin() ; i != players.cend();i++)
|
||||
for(auto j = i->second.availableHeroes.cbegin(); j != i->second.availableHeroes.cend(); j++)
|
||||
if(*j)
|
||||
pool.erase((**j).subID);
|
||||
|
||||
@@ -2438,7 +2438,7 @@ void CGameState::deserializationFix()
|
||||
|
||||
void CGameState::buildGlobalTeamPlayerTree()
|
||||
{
|
||||
for(std::map<ui8, TeamState>::iterator k=teams.begin(); k!=teams.end(); ++k)
|
||||
for(auto k=teams.begin(); k!=teams.end(); ++k)
|
||||
{
|
||||
TeamState *t = &k->second;
|
||||
t->attachTo(&globalEffects);
|
||||
|
||||
@@ -143,14 +143,14 @@ struct DLL_LINKAGE InfoAboutTown : public InfoAboutArmy
|
||||
|
||||
struct DLL_LINKAGE SThievesGuildInfo
|
||||
{
|
||||
std::vector<ui8> playerColors; //colors of players that are in-game
|
||||
std::vector<TPlayerColor> playerColors; //colors of players that are in-game
|
||||
|
||||
std::vector< std::vector< ui8 > > numOfTowns, numOfHeroes, gold, woodOre, mercSulfCrystGems, obelisks, artifacts, army, income; // [place] -> [colours of players]
|
||||
std::vector< std::vector< TPlayerColor > > numOfTowns, numOfHeroes, gold, woodOre, mercSulfCrystGems, obelisks, artifacts, army, income; // [place] -> [colours of players]
|
||||
|
||||
std::map<ui8, InfoAboutHero> colorToBestHero; //maps player's color to his best heros'
|
||||
std::map<TPlayerColor, InfoAboutHero> colorToBestHero; //maps player's color to his best heros'
|
||||
|
||||
std::map<ui8, si8> personality; // color to personality // -1 - human, AI -> (00 - random, 01 - warrior, 02 - builder, 03 - explorer)
|
||||
std::map<ui8, si32> bestCreature; // color to ID // id or -1 if not known
|
||||
std::map<TPlayerColor, si8> personality; // color to personality // -1 - human, AI -> (00 - random, 01 - warrior, 02 - builder, 03 - explorer)
|
||||
std::map<TPlayerColor, si32> bestCreature; // color to ID // id or -1 if not known
|
||||
|
||||
// template <typename Handler> void serialize(Handler &h, const int version)
|
||||
// {
|
||||
@@ -164,7 +164,7 @@ struct DLL_LINKAGE PlayerState : public CBonusSystemNode
|
||||
{
|
||||
public:
|
||||
enum EStatus {INGAME, LOSER, WINNER};
|
||||
ui8 color;
|
||||
TPlayerColor color;
|
||||
ui8 human; //true if human controlled player, false for AI
|
||||
ui32 currentSelection; //id of hero/town, 0xffffffff if none
|
||||
ui8 team;
|
||||
@@ -201,7 +201,7 @@ struct DLL_LINKAGE TeamState : public CBonusSystemNode
|
||||
{
|
||||
public:
|
||||
ui8 id; //position in gameState::teams
|
||||
std::set<ui8> players; // members of this team
|
||||
std::set<TPlayerColor> players; // members of this team
|
||||
std::vector<std::vector<std::vector<ui8> > > fogOfWarMap; //true - visible, false - hidden
|
||||
|
||||
TeamState();
|
||||
@@ -387,9 +387,9 @@ public:
|
||||
ConstTransitivePtr<BattleInfo> curB; //current battle
|
||||
ui32 day; //total number of days in game
|
||||
ConstTransitivePtr<Mapa> map;
|
||||
bmap<ui8, PlayerState> players; //ID <-> player state
|
||||
bmap<ui8, TeamState> teams; //ID <-> team state
|
||||
bmap<int, ConstTransitivePtr<CGDefInfo> > villages, forts, capitols; //def-info for town graphics
|
||||
bmap<TPlayerColor, PlayerState> players;
|
||||
bmap<TPlayerColor, TeamState> teams;
|
||||
bmap<TPlayerColor, ConstTransitivePtr<CGDefInfo> > villages, forts, capitols; //def-info for town graphics
|
||||
CBonusSystemNode globalEffects;
|
||||
bmap<const CGHeroInstance*, const CGObjectInstance*> ongoingVisits;
|
||||
|
||||
@@ -398,7 +398,7 @@ public:
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > heroesPool; //[subID] - heroes available to buy; NULL if not available
|
||||
bmap<ui32,ui8> pavailable; // [subid] -> which players can recruit hero (binary flags)
|
||||
|
||||
CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass = NULL) const;
|
||||
CGHeroInstance * pickHeroFor(bool native, TPlayerColor player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass = NULL) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ void CMapInfo::countPlayers()
|
||||
}
|
||||
|
||||
if(scenarioOpts)
|
||||
for (std::map<int, PlayerSettings>::const_iterator i = scenarioOpts->playerInfos.begin(); i != scenarioOpts->playerInfos.end(); i++)
|
||||
for (auto i = scenarioOpts->playerInfos.cbegin(); i != scenarioOpts->playerInfos.cend(); i++)
|
||||
if(i->second.human)
|
||||
actualHumanPlayers++;
|
||||
}
|
||||
|
||||
@@ -399,11 +399,11 @@ void CGObjectInstance::getSightTiles(boost::unordered_set<int3, ShashInt3> &tile
|
||||
}
|
||||
void CGObjectInstance::hideTiles(int ourplayer, int radius) const
|
||||
{
|
||||
for (std::map<ui8, TeamState>::iterator i = cb->gameState()->teams.begin(); i != cb->gameState()->teams.end(); i++)
|
||||
for (auto i = cb->gameState()->teams.begin(); i != cb->gameState()->teams.end(); i++)
|
||||
{
|
||||
if ( !vstd::contains(i->second.players, ourplayer ))//another team
|
||||
{
|
||||
for (std::set<ui8>::iterator j = i->second.players.begin(); j != i->second.players.end(); j++)
|
||||
for (auto j = i->second.players.begin(); j != i->second.players.end(); j++)
|
||||
if ( cb->getPlayer(*j)->status == PlayerState::INGAME )//seek for living player (if any)
|
||||
{
|
||||
FoWChange fw;
|
||||
|
||||
@@ -406,3 +406,4 @@ typedef si32 TSlot;
|
||||
typedef si32 TQuantity;
|
||||
typedef si32 TArtifactID;
|
||||
typedef ui32 TCreature; //creature id
|
||||
typedef si8 TPlayerColor;
|
||||
|
||||
@@ -725,7 +725,7 @@ std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(
|
||||
{
|
||||
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>();
|
||||
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
for ( auto i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
{
|
||||
for (size_t j = 0; j < (*i).second.towns.size(); ++j)
|
||||
{
|
||||
|
||||
@@ -2272,7 +2272,7 @@ struct PlayerLeft : public CPregamePackToPropagate
|
||||
struct PlayersNames : public CPregamePackToPropagate
|
||||
{
|
||||
public:
|
||||
std::map<ui32, std::string> playerNames;
|
||||
std::map<TPlayerColor, std::string> playerNames;
|
||||
|
||||
void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
|
||||
|
||||
|
||||
@@ -897,7 +897,7 @@ DLL_LINKAGE void NewTurn::applyGs( CGameState *gs )
|
||||
//TODO not really a single root hierarchy, what about bonuses placed elsewhere? [not an issue with H3 mechanics but in the future...]
|
||||
|
||||
//count days without town
|
||||
for( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
for( auto i=gs->players.begin() ; i!=gs->players.end(); i++)
|
||||
{
|
||||
if(i->second.towns.size() || gs->day == 1)
|
||||
i->second.daysWithoutCastle = 0;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "GameConstants.h"
|
||||
|
||||
/*
|
||||
* StartInfo.h, part of VCMI engine
|
||||
*
|
||||
@@ -21,7 +23,7 @@ struct PlayerSettings
|
||||
heroPortrait; //-1 if default, else ID
|
||||
std::string heroName;
|
||||
si8 bonus; //uses enum type Ebonus
|
||||
ui8 color; //from 0 -
|
||||
TPlayerColor color; //from 0 -
|
||||
ui8 handicap;//0-no, 1-mild, 2-severe
|
||||
ui8 team;
|
||||
|
||||
@@ -57,7 +59,7 @@ struct StartInfo
|
||||
ui8 mode; //uses EMode enum
|
||||
ui8 difficulty; //0=easy; 4=impossible
|
||||
|
||||
typedef bmap<int, PlayerSettings> TPlayerInfos;
|
||||
typedef bmap<TPlayerColor, PlayerSettings> TPlayerInfos;
|
||||
TPlayerInfos playerInfos; //color indexed
|
||||
|
||||
ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
|
||||
@@ -68,7 +70,7 @@ struct StartInfo
|
||||
|
||||
shared_ptr<CCampaignState> campState;
|
||||
|
||||
PlayerSettings & getIthPlayersSettings(int no)
|
||||
PlayerSettings & getIthPlayersSettings(TPlayerColor no)
|
||||
{
|
||||
if(playerInfos.find(no) != playerInfos.end())
|
||||
return playerInfos[no];
|
||||
@@ -78,7 +80,7 @@ struct StartInfo
|
||||
|
||||
PlayerSettings *getPlayersSettings(const ui8 nameID)
|
||||
{
|
||||
for(bmap<int, PlayerSettings>::iterator it=playerInfos.begin(); it != playerInfos.end(); ++it)
|
||||
for(auto it=playerInfos.begin(); it != playerInfos.end(); ++it)
|
||||
if(it->second.human == nameID)
|
||||
return &it->second;
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ static void giveExp(BattleResult &r)
|
||||
}
|
||||
}
|
||||
|
||||
PlayerStatus PlayerStatuses::operator[](ui8 player)
|
||||
PlayerStatus PlayerStatuses::operator[](TPlayerColor player)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> l(mx);
|
||||
if(players.find(player) != players.end())
|
||||
@@ -117,13 +117,13 @@ PlayerStatus PlayerStatuses::operator[](ui8 player)
|
||||
throw std::runtime_error("No such player!");
|
||||
}
|
||||
}
|
||||
void PlayerStatuses::addPlayer(ui8 player)
|
||||
void PlayerStatuses::addPlayer(TPlayerColor player)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> l(mx);
|
||||
players[player];
|
||||
}
|
||||
|
||||
int PlayerStatuses::getQueriesCount(ui8 player)
|
||||
int PlayerStatuses::getQueriesCount(TPlayerColor player)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> l(mx);
|
||||
if(players.find(player) != players.end())
|
||||
@@ -136,7 +136,7 @@ int PlayerStatuses::getQueriesCount(ui8 player)
|
||||
}
|
||||
}
|
||||
|
||||
bool PlayerStatuses::checkFlag(ui8 player, bool PlayerStatus::*flag)
|
||||
bool PlayerStatuses::checkFlag(TPlayerColor player, bool PlayerStatus::*flag)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> l(mx);
|
||||
if(players.find(player) != players.end())
|
||||
@@ -148,7 +148,7 @@ bool PlayerStatuses::checkFlag(ui8 player, bool PlayerStatus::*flag)
|
||||
throw std::runtime_error("No such player!");
|
||||
}
|
||||
}
|
||||
void PlayerStatuses::setFlag(ui8 player, bool PlayerStatus::*flag, bool val)
|
||||
void PlayerStatuses::setFlag(TPlayerColor player, bool PlayerStatus::*flag, bool val)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> l(mx);
|
||||
if(players.find(player) != players.end())
|
||||
@@ -161,7 +161,7 @@ void PlayerStatuses::setFlag(ui8 player, bool PlayerStatus::*flag, bool val)
|
||||
}
|
||||
cv.notify_all();
|
||||
}
|
||||
void PlayerStatuses::addQuery(ui8 player, ui32 id)
|
||||
void PlayerStatuses::addQuery(TPlayerColor player, ui32 id)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> l(mx);
|
||||
if(players.find(player) != players.end())
|
||||
@@ -174,7 +174,7 @@ void PlayerStatuses::addQuery(ui8 player, ui32 id)
|
||||
}
|
||||
cv.notify_all();
|
||||
}
|
||||
void PlayerStatuses::removeQuery(ui8 player, ui32 id)
|
||||
void PlayerStatuses::removeQuery(TPlayerColor player, ui32 id)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> l(mx);
|
||||
if(players.find(player) != players.end())
|
||||
@@ -1072,7 +1072,7 @@ void CGameHandler::init(StartInfo *si)
|
||||
gs->init(si);
|
||||
tlog0 << "Gamestate initialized!" << std::endl;
|
||||
|
||||
for(std::map<ui8,PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
|
||||
for(auto i = gs->players.begin(); i != gs->players.end(); i++)
|
||||
states.addPlayer(i->first);
|
||||
}
|
||||
|
||||
@@ -1188,14 +1188,14 @@ void CGameHandler::newTurn()
|
||||
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > pool = gs->hpool.heroesPool;
|
||||
|
||||
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
for ( auto i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
{
|
||||
if(i->first == 255)
|
||||
continue;
|
||||
else if(i->first >= GameConstants::PLAYER_LIMIT)
|
||||
assert(0); //illegal player number!
|
||||
|
||||
std::pair<ui8,si32> playerGold(i->first,i->second.resources[Res::GOLD]);
|
||||
std::pair<TPlayerColor,si32> playerGold(i->first,i->second.resources[Res::GOLD]);
|
||||
hadGold.insert(playerGold);
|
||||
|
||||
if(newWeek) //new heroes in tavern
|
||||
@@ -1403,7 +1403,7 @@ void CGameHandler::newTurn()
|
||||
iw.text.addReplacement(MetaString::ARRAY_TXT, 43 + rand()%15);
|
||||
}
|
||||
}
|
||||
for (std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end(); i++)
|
||||
for (auto i=gs->players.begin() ; i!=gs->players.end(); i++)
|
||||
{
|
||||
iw.player = i->first;
|
||||
sendAndApply(&iw);
|
||||
@@ -1425,7 +1425,7 @@ void CGameHandler::newTurn()
|
||||
//warn players without town
|
||||
if(gs->day)
|
||||
{
|
||||
for (std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
for (auto i=gs->players.cbegin() ; i!=gs->players.cend();i++)
|
||||
{
|
||||
if(i->second.status || i->second.towns.size() || i->second.color >= GameConstants::PLAYER_LIMIT)
|
||||
continue;
|
||||
@@ -1460,7 +1460,7 @@ void CGameHandler::run(bool resume)
|
||||
BOOST_FOREACH(CConnection *cc, conns)
|
||||
{//init conn.
|
||||
ui32 quantity;
|
||||
ui8 pom;
|
||||
TPlayerColor pom;
|
||||
//ui32 seed;
|
||||
if(!resume)
|
||||
{
|
||||
@@ -1503,7 +1503,7 @@ void CGameHandler::run(bool resume)
|
||||
if(!resume)
|
||||
newTurn();
|
||||
|
||||
std::map<ui8,PlayerState>::iterator i;
|
||||
std::map<TPlayerColor,PlayerState>::iterator i;
|
||||
if(!resume)
|
||||
i = gs->players.begin();
|
||||
else
|
||||
@@ -5005,7 +5005,7 @@ void CGameHandler::checkLossVictory( ui8 player )
|
||||
{
|
||||
iw.text.localStrings.front().second++; //message about losing because enemy won first is just after victory message
|
||||
|
||||
for (bmap<ui8,PlayerState>::const_iterator i = gs->players.begin(); i!=gs->players.end(); i++)
|
||||
for (auto i = gs->players.cbegin(); i!=gs->players.cend(); i++)
|
||||
{
|
||||
if(i->first < GameConstants::PLAYER_LIMIT && i->first != player)//FIXME: skip already eliminated players?
|
||||
{
|
||||
|
||||
@@ -53,17 +53,17 @@ struct PlayerStatus
|
||||
class PlayerStatuses
|
||||
{
|
||||
public:
|
||||
std::map<ui8,PlayerStatus> players;
|
||||
std::map<TPlayerColor,PlayerStatus> players;
|
||||
boost::mutex mx;
|
||||
boost::condition_variable cv; //notifies when any changes are made
|
||||
|
||||
void addPlayer(ui8 player);
|
||||
PlayerStatus operator[](ui8 player);
|
||||
int getQueriesCount(ui8 player); //returns 0 if there is no such player
|
||||
bool checkFlag(ui8 player, bool PlayerStatus::*flag);
|
||||
void setFlag(ui8 player, bool PlayerStatus::*flag, bool val);
|
||||
void addQuery(ui8 player, ui32 id);
|
||||
void removeQuery(ui8 player, ui32 id);
|
||||
void addPlayer(TPlayerColor player);
|
||||
PlayerStatus operator[](TPlayerColor player);
|
||||
int getQueriesCount(TPlayerColor player); //returns 0 if there is no such player
|
||||
bool checkFlag(TPlayerColor player, bool PlayerStatus::*flag);
|
||||
void setFlag(TPlayerColor player, bool PlayerStatus::*flag, bool val);
|
||||
void addQuery(TPlayerColor player, ui32 id);
|
||||
void removeQuery(TPlayerColor player, ui32 id);
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & players;
|
||||
|
||||
Reference in New Issue
Block a user