1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-17 00:07:41 +02:00

Works more or less

This commit is contained in:
Tomasz Zieliński
2023-10-28 20:30:38 +02:00
parent a817e481d0
commit 07dac8b6d4
7 changed files with 414 additions and 207 deletions

View File

@ -104,7 +104,7 @@ void CMapGenerator::initPrisonsRemaining()
if (isAllowed)
allowedPrisons++;
}
allowedPrisons = std::max<int> (0, allowedPrisons - 16 * mapGenOptions.getPlayerCount()); //so at least 16 heroes will be available for every player
allowedPrisons = std::max<int> (0, allowedPrisons - 16 * mapGenOptions.getHumanOrCpuPlayerCount()); //so at least 16 heroes will be available for every player
}
void CMapGenerator::initQuestArtsRemaining()
@ -162,7 +162,7 @@ std::string CMapGenerator::getMapDescription() const
std::stringstream ss;
ss << boost::str(boost::format(std::string("Map created by the Random Map Generator.\nTemplate was %s, size %dx%d") +
", levels %d, players %d, computers %d, water %s, monster %s, VCMI map") % mapTemplate->getName() %
map->width() % map->height() % static_cast<int>(map->levels()) % static_cast<int>(mapGenOptions.getPlayerCount()) %
map->width() % map->height() % static_cast<int>(map->levels()) % static_cast<int>(mapGenOptions.getHumanOrCpuPlayerCount()) %
static_cast<int>(mapGenOptions.getCompOnlyPlayerCount()) % waterContentStr[mapGenOptions.getWaterContent()] %
monsterStrengthStr[monsterStrengthIndex]);
@ -185,84 +185,120 @@ std::string CMapGenerator::getMapDescription() const
void CMapGenerator::addPlayerInfo()
{
// Calculate which team numbers exist
// Teams are already configured in CMapGenOptions. However, it's not the case when it comes to map editor
enum ETeams {CPHUMAN = 0, CPUONLY = 1, AFTER_LAST = 2}; // Used as a kind of a local named array index, so left as enum, not enum class
std::array<std::list<int>, 2> teamNumbers;
std::set<int> teamsTotal;
int teamOffset = 0;
int playerCount = 0;
int teamCount = 0;
for (int i = CPHUMAN; i < AFTER_LAST; ++i)
if (mapGenOptions.arePlayersCustomized())
{
if (i == CPHUMAN)
{
playerCount = mapGenOptions.getPlayerCount();
teamCount = mapGenOptions.getTeamCount();
}
else
{
playerCount = mapGenOptions.getCompOnlyPlayerCount();
teamCount = mapGenOptions.getCompOnlyTeamCount();
}
// Simply copy existing settings set in GUI
if(playerCount == 0)
for (const auto & player : mapGenOptions.getPlayersSettings())
{
continue;
PlayerInfo playerInfo;
playerInfo.team = player.second.getTeam();
if (player.second.getPlayerType() == EPlayerType::COMP_ONLY)
{
playerInfo.canHumanPlay = false;
}
else
{
playerInfo.canHumanPlay = true;
}
map->getMap(this).players[player.first.getNum()] = playerInfo;
teamsTotal.insert(player.second.getTeam());
}
int playersPerTeam = playerCount / (teamCount == 0 ? playerCount : teamCount);
int teamCountNorm = teamCount;
if(teamCountNorm == 0)
}
else
{
// Assign standard teams (in map editor)
// Calculate which team numbers exist
enum ETeams {CPHUMAN = 0, CPUONLY = 1, AFTER_LAST = 2}; // Used as a kind of a local named array index, so left as enum, not enum class
std::array<std::list<int>, 2> teamNumbers;
int teamOffset = 0;
int playerCount = 0;
int teamCount = 0;
// FIXME: Player can be any color, not just 0
for (int i = CPHUMAN; i < AFTER_LAST; ++i)
{
teamCountNorm = playerCount;
}
for(int j = 0; j < teamCountNorm; ++j)
{
for(int k = 0; k < playersPerTeam; ++k)
if (i == CPHUMAN)
{
playerCount = mapGenOptions.getHumanOrCpuPlayerCount();
teamCount = mapGenOptions.getTeamCount();
}
else
{
playerCount = mapGenOptions.getCompOnlyPlayerCount();
teamCount = mapGenOptions.getCompOnlyTeamCount();
}
if(playerCount == 0)
{
continue;
}
int playersPerTeam = playerCount / (teamCount == 0 ? playerCount : teamCount);
int teamCountNorm = teamCount;
if(teamCountNorm == 0)
{
teamCountNorm = playerCount;
}
for(int j = 0; j < teamCountNorm; ++j)
{
for(int k = 0; k < playersPerTeam; ++k)
{
teamNumbers[i].push_back(j + teamOffset);
}
}
for(int j = 0; j < playerCount - teamCountNorm * playersPerTeam; ++j)
{
teamNumbers[i].push_back(j + teamOffset);
}
teamOffset += teamCountNorm;
}
for(int j = 0; j < playerCount - teamCountNorm * playersPerTeam; ++j)
{
teamNumbers[i].push_back(j + teamOffset);
}
teamOffset += teamCountNorm;
}
logGlobal->info("Current player settings size: %d", mapGenOptions.getPlayersSettings().size());
// 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) ? CPUONLY : CPHUMAN;
if (j == CPHUMAN)
// Team numbers are assigned randomly to every player
//TODO: allow to customize teams in rmg template
for(const auto & pair : mapGenOptions.getPlayersSettings())
{
player.canHumanPlay = true;
}
if(pSettings.getTeam() != TeamID::NO_TEAM)
{
player.team = pSettings.getTeam();
}
else
{
if (teamNumbers[j].empty())
const auto & pSettings = pair.second;
PlayerInfo player;
player.canComputerPlay = true;
int j = (pSettings.getPlayerType() == EPlayerType::COMP_ONLY) ? CPUONLY : CPHUMAN;
if (j == CPHUMAN)
{
logGlobal->error("Not enough places in team for %s player", ((j == CPUONLY) ? "CPU" : "CPU or human"));
assert (teamNumbers[j].size());
player.canHumanPlay = true;
}
auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], rand);
player.team = TeamID(*itTeam);
teamNumbers[j].erase(itTeam);
if(pSettings.getTeam() != TeamID::NO_TEAM)
{
player.team = pSettings.getTeam();
}
else
{
if (teamNumbers[j].empty())
{
logGlobal->error("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);
}
teamsTotal.insert(player.team.getNum());
map->getMap(this).players[pSettings.getColor().getNum()] = player;
}
teamsTotal.insert(player.team.getNum());
map->getMap(this).players[pSettings.getColor().getNum()] = player;
logGlobal->info("Current team count: %d", teamsTotal.size());
}
// FIXME: 0
// Can't find info for player 0 (starting zone)
// Can't find info for player 1 (starting zone)
map->getMap(this).howManyTeams = teamsTotal.size();
}