1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Fixed generation of CPU teams.

This commit is contained in:
DjWarmonger
2015-06-01 21:57:43 +02:00
parent 34a59a2788
commit c6f714db9c
4 changed files with 71 additions and 13 deletions

View File

@ -169,19 +169,32 @@ std::string CMapGenerator::getMapDescription() const
void CMapGenerator::addPlayerInfo()
{
// Calculate which team numbers exist
std::array<std::list<int>, 2> teamNumbers; // 0= cpu/human, 1= cpu only
int teamOffset = 0;
for(int i = 0; i < 2; ++i)
{
int playerCount = i == 0 ? mapGenOptions->getPlayerCount() : mapGenOptions->getCompOnlyPlayerCount();
int teamCount = i == 0 ? mapGenOptions->getTeamCount() : mapGenOptions->getCompOnlyTeamCount();
enum ETeams {CPHUMAN = 0, CPUONLY = 1, AFTER_LAST = 2};
std::array<std::list<int>, 2> teamNumbers;
int teamOffset = 0;
int playerCount = 0;
int teamCount = 0;
for (int i = CPHUMAN; i < AFTER_LAST; ++i)
{
if (i == CPHUMAN)
{
playerCount = mapGenOptions->getPlayerCount();
teamCount = mapGenOptions->getTeamCount();
}
else
{
playerCount = mapGenOptions->getCompOnlyPlayerCount();
teamCount = mapGenOptions->getCompOnlyTeamCount();
}
if(playerCount == 0)
{
continue;
}
int playersPerTeam = playerCount /
(teamCount == 0 ? playerCount : teamCount);
int playersPerTeam = playerCount / (teamCount == 0 ? playerCount : teamCount);
int teamCountNorm = teamCount;
if(teamCountNorm == 0)
{
@ -202,17 +215,23 @@ void CMapGenerator::addPlayerInfo()
}
// Team numbers are assigned randomly to every player
//TODO: allow customize teams in rmg template
for(const auto & pair : mapGenOptions->getPlayersSettings())
{
const auto & pSettings = pair.second;
PlayerInfo player;
player.canComputerPlay = true;
int j = pSettings.getPlayerType() == EPlayerType::COMP_ONLY ? 1 : 0;
if(j == 0)
int j = (pSettings.getPlayerType() == EPlayerType::COMP_ONLY) ? CPUONLY : CPHUMAN;
if (j == CPHUMAN)
{
player.canHumanPlay = true;
}
if (teamNumbers[j].empty())
{
logGlobal->errorStream() << boost::format("Not enough places in team for %s player") % ((j == CPUONLY) ? "CPU" : "CPU or human");
assert (teamNumbers[j].size());
}
auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], rand);
player.team = TeamID(*itTeam);
teamNumbers[j].erase(itTeam);