2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2010-10-25 19:06:48 +03:00
|
|
|
#include "CMapInfo.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
|
|
|
#include "StartInfo.h"
|
2010-10-25 19:06:48 +03:00
|
|
|
#include "map.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CCampaignHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "GameConstants.h"
|
2010-10-25 19:06:48 +03:00
|
|
|
|
|
|
|
void CMapInfo::countPlayers()
|
|
|
|
{
|
2012-08-01 15:02:54 +03:00
|
|
|
actualHumanPlayers = playerAmnt = humanPlayers = 0;
|
2011-12-14 00:23:17 +03:00
|
|
|
for(int i=0;i<GameConstants::PLAYER_LIMIT;i++)
|
2010-10-25 19:06:48 +03:00
|
|
|
{
|
|
|
|
if(mapHeader->players[i].canHumanPlay)
|
|
|
|
{
|
|
|
|
playerAmnt++;
|
2012-08-01 15:02:54 +03:00
|
|
|
humanPlayers++;
|
2010-10-25 19:06:48 +03:00
|
|
|
}
|
|
|
|
else if(mapHeader->players[i].canComputerPlay)
|
|
|
|
{
|
|
|
|
playerAmnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(scenarioOpts)
|
2012-09-24 19:14:53 +03:00
|
|
|
for (auto i = scenarioOpts->playerInfos.cbegin(); i != scenarioOpts->playerInfos.cend(); i++)
|
2010-10-25 19:06:48 +03:00
|
|
|
if(i->second.human)
|
|
|
|
actualHumanPlayers++;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMapInfo::CMapInfo(bool map)
|
|
|
|
: mapHeader(NULL), campaignHeader(NULL), scenarioOpts(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
void CMapInfo::mapInit(const std::string &fname, const ui8 *map )
|
2010-10-25 19:06:48 +03:00
|
|
|
{
|
2012-08-01 15:02:54 +03:00
|
|
|
fileURI = fname;
|
2010-10-25 19:06:48 +03:00
|
|
|
int i = 0;
|
|
|
|
mapHeader = new CMapHeader();
|
|
|
|
mapHeader->version = CMapHeader::invalid;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mapHeader->initFromMemory(map, i);
|
|
|
|
countPlayers();
|
|
|
|
}
|
2012-04-23 22:56:37 +03:00
|
|
|
catch (const std::exception &e)
|
2010-10-25 19:06:48 +03:00
|
|
|
{
|
2012-04-23 22:56:37 +03:00
|
|
|
tlog1 << "\t\tWarning: evil map file: " << fname << ": " << e.what() << std::endl;
|
2010-10-25 19:06:48 +03:00
|
|
|
delete mapHeader;
|
|
|
|
mapHeader = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CMapInfo::~CMapInfo()
|
|
|
|
{
|
|
|
|
delete mapHeader;
|
|
|
|
delete campaignHeader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapInfo::campaignInit()
|
|
|
|
{
|
2012-08-01 15:02:54 +03:00
|
|
|
campaignHeader = new CCampaignHeader( CCampaignHandler::getHeader(fileURI) );
|
2010-10-25 19:06:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapInfo::setHeader(CMapHeader *header)
|
|
|
|
{
|
|
|
|
mapHeader = header;
|
|
|
|
}
|
|
|
|
|