mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
- Fixed improper use of playersCount. Now RMG can generate maps up to 8 players, with CPU players only as well.
- Fixes for template scheme
This commit is contained in:
parent
4388566342
commit
6890ae9f02
@ -1671,7 +1671,7 @@ CRandomMapTab::CRandomMapTab()
|
|||||||
{
|
{
|
||||||
mapGenOptions.setPlayerCount(btnId);
|
mapGenOptions.setPlayerCount(btnId);
|
||||||
deactivateButtonsFrom(teamsCntGroup, btnId);
|
deactivateButtonsFrom(teamsCntGroup, btnId);
|
||||||
deactivateButtonsFrom(compOnlyPlayersCntGroup, 8 - btnId + 1);
|
deactivateButtonsFrom(compOnlyPlayersCntGroup, btnId);
|
||||||
validatePlayersCnt(btnId);
|
validatePlayersCnt(btnId);
|
||||||
if(!SEL->isGuest())
|
if(!SEL->isGuest())
|
||||||
updateMapInfo();
|
updateMapInfo();
|
||||||
@ -1694,7 +1694,6 @@ CRandomMapTab::CRandomMapTab()
|
|||||||
compOnlyPlayersCntGroup->pos.y += 285;
|
compOnlyPlayersCntGroup->pos.y += 285;
|
||||||
compOnlyPlayersCntGroup->pos.x += BTNS_GROUP_LEFT_MARGIN;
|
compOnlyPlayersCntGroup->pos.x += BTNS_GROUP_LEFT_MARGIN;
|
||||||
addButtonsWithRandToGroup(compOnlyPlayersCntGroup, numberDefs, 0, 7, NUMBERS_WIDTH, 224, 232);
|
addButtonsWithRandToGroup(compOnlyPlayersCntGroup, numberDefs, 0, 7, NUMBERS_WIDTH, 224, 232);
|
||||||
compOnlyPlayersCntGroup->setSelected(0);
|
|
||||||
compOnlyPlayersCntGroup->addCallback([&](int btnId)
|
compOnlyPlayersCntGroup->addCallback([&](int btnId)
|
||||||
{
|
{
|
||||||
mapGenOptions.setCompOnlyPlayerCount(btnId);
|
mapGenOptions.setCompOnlyPlayerCount(btnId);
|
||||||
@ -1808,9 +1807,9 @@ void CRandomMapTab::validatePlayersCnt(int playersCnt)
|
|||||||
mapGenOptions.setTeamCount(playersCnt - 1);
|
mapGenOptions.setTeamCount(playersCnt - 1);
|
||||||
teamsCntGroup->setSelected(mapGenOptions.getTeamCount());
|
teamsCntGroup->setSelected(mapGenOptions.getTeamCount());
|
||||||
}
|
}
|
||||||
if(mapGenOptions.getCompOnlyPlayerCount() > 8 - playersCnt)
|
if(mapGenOptions.getCompOnlyPlayerCount() >= playersCnt)
|
||||||
{
|
{
|
||||||
mapGenOptions.setCompOnlyPlayerCount(8 - playersCnt);
|
mapGenOptions.setCompOnlyPlayerCount(playersCnt - 1);
|
||||||
compOnlyPlayersCntGroup->setSelected(mapGenOptions.getCompOnlyPlayerCount());
|
compOnlyPlayersCntGroup->setSelected(mapGenOptions.getCompOnlyPlayerCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
{
|
{
|
||||||
"zone":{
|
"zone":{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required" : ["type", "monsters", "size", "level"],
|
"required" : ["type", "monsters", "size"],
|
||||||
"properties":{
|
"properties":{
|
||||||
"type":{"$ref" : "#/definitions/type"},
|
"type":{"$ref" : "#/definitions/type"},
|
||||||
"size":{"$ref" : "#/definitions/size"},
|
"size":{"$ref" : "#/definitions/size"},
|
||||||
@ -35,9 +35,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type" :{
|
"type" :{
|
||||||
"type" : "object",
|
"enum": ["playerStart", "cpuStart", "treasure", "junction"],
|
||||||
"enum": ["playerStart", "treasure", "junction"]
|
"additionalProperties" : false,
|
||||||
"additionalProperties" : false
|
|
||||||
"type":"string"
|
"type":"string"
|
||||||
},
|
},
|
||||||
"size":{
|
"size":{
|
||||||
@ -50,13 +49,13 @@
|
|||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
"zones":{
|
"zones":{
|
||||||
"type": "array",
|
"type": "object",
|
||||||
"items":{"$ref" : "#/definitions/zone" }
|
"additionalProperties":{"$ref" : "#/definitions/zone" }
|
||||||
},
|
},
|
||||||
"connections":{
|
"connections":{
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items":{"$ref" : "#/definitions/connection"}
|
"items":{"$ref" : "#/definitions/connection"}
|
||||||
}
|
},
|
||||||
"required" : ["zones", "connections"],
|
"required" : ["zones", "connections"],
|
||||||
"additionalProperties" : false
|
"additionalProperties" : false
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "../CTownHandler.h"
|
#include "../CTownHandler.h"
|
||||||
|
|
||||||
CMapGenOptions::CMapGenOptions() : width(CMapHeader::MAP_SIZE_MIDDLE), height(CMapHeader::MAP_SIZE_MIDDLE), hasTwoLevels(false),
|
CMapGenOptions::CMapGenOptions() : width(CMapHeader::MAP_SIZE_MIDDLE), height(CMapHeader::MAP_SIZE_MIDDLE), hasTwoLevels(false),
|
||||||
playerCount(RANDOM_SIZE), teamCount(RANDOM_SIZE), compOnlyPlayerCount(0), compOnlyTeamCount(RANDOM_SIZE),
|
playerCount(RANDOM_SIZE), teamCount(RANDOM_SIZE), compOnlyPlayerCount(RANDOM_SIZE), compOnlyTeamCount(RANDOM_SIZE), humanPlayersCount(0),
|
||||||
waterContent(EWaterContent::RANDOM), monsterStrength(EMonsterStrength::RANDOM), mapTemplate(nullptr)
|
waterContent(EWaterContent::RANDOM), monsterStrength(EMonsterStrength::RANDOM), mapTemplate(nullptr)
|
||||||
{
|
{
|
||||||
resetPlayersMap();
|
resetPlayersMap();
|
||||||
@ -67,9 +67,11 @@ void CMapGenOptions::setPlayerCount(si8 value)
|
|||||||
{
|
{
|
||||||
assert((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE);
|
assert((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE);
|
||||||
playerCount = value;
|
playerCount = value;
|
||||||
auto possibleCompPlayersCount = PlayerColor::PLAYER_LIMIT_I-value;
|
auto possibleCompPlayersCount = value;
|
||||||
if(compOnlyPlayerCount > possibleCompPlayersCount)
|
if (compOnlyPlayerCount > possibleCompPlayersCount)
|
||||||
setCompOnlyPlayerCount(possibleCompPlayersCount);
|
setCompOnlyPlayerCount(possibleCompPlayersCount);
|
||||||
|
|
||||||
|
humanPlayersCount = playerCount - compOnlyPlayerCount;
|
||||||
resetPlayersMap();
|
resetPlayersMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +93,9 @@ si8 CMapGenOptions::getCompOnlyPlayerCount() const
|
|||||||
|
|
||||||
void CMapGenOptions::setCompOnlyPlayerCount(si8 value)
|
void CMapGenOptions::setCompOnlyPlayerCount(si8 value)
|
||||||
{
|
{
|
||||||
assert(value == RANDOM_SIZE || (value >= 0 && value <= PlayerColor::PLAYER_LIMIT_I - playerCount));
|
assert(value == RANDOM_SIZE || (value >= 0 && value <= playerCount));
|
||||||
compOnlyPlayerCount = value;
|
compOnlyPlayerCount = value;
|
||||||
|
humanPlayersCount = playerCount - compOnlyPlayerCount;
|
||||||
resetPlayersMap();
|
resetPlayersMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,12 +133,13 @@ void CMapGenOptions::setMonsterStrength(EMonsterStrength::EMonsterStrength value
|
|||||||
void CMapGenOptions::resetPlayersMap()
|
void CMapGenOptions::resetPlayersMap()
|
||||||
{
|
{
|
||||||
players.clear();
|
players.clear();
|
||||||
int realPlayersCnt = playerCount == RANDOM_SIZE ? static_cast<int>(PlayerColor::PLAYER_LIMIT_I) : playerCount;
|
int realPlayersCnt = humanPlayersCount;
|
||||||
int realCompOnlyPlayersCnt = compOnlyPlayerCount == RANDOM_SIZE ? (PlayerColor::PLAYER_LIMIT_I - realPlayersCnt) : compOnlyPlayerCount;
|
int realCompOnlyPlayersCnt = (compOnlyPlayerCount == RANDOM_SIZE) ? (PlayerColor::PLAYER_LIMIT_I - realPlayersCnt) : compOnlyPlayerCount;
|
||||||
int totalPlayersLimit = realPlayersCnt + realCompOnlyPlayersCnt;
|
int totalPlayersLimit = realPlayersCnt + realCompOnlyPlayersCnt;
|
||||||
if(playerCount == RANDOM_SIZE || compOnlyPlayerCount == RANDOM_SIZE)
|
if(playerCount == RANDOM_SIZE || compOnlyPlayerCount == RANDOM_SIZE)
|
||||||
totalPlayersLimit = static_cast<int>(PlayerColor::PLAYER_LIMIT_I);
|
totalPlayersLimit = static_cast<int>(PlayerColor::PLAYER_LIMIT_I);
|
||||||
|
|
||||||
|
//FIXME: what happens with human players here?
|
||||||
for(int color = 0; color < totalPlayersLimit; ++color)
|
for(int color = 0; color < totalPlayersLimit; ++color)
|
||||||
{
|
{
|
||||||
CPlayerSettings player;
|
CPlayerSettings player;
|
||||||
@ -262,14 +266,12 @@ void CMapGenOptions::updatePlayers()
|
|||||||
|
|
||||||
void CMapGenOptions::updateCompOnlyPlayers()
|
void CMapGenOptions::updateCompOnlyPlayers()
|
||||||
{
|
{
|
||||||
auto totalPlayersCnt = playerCount + compOnlyPlayerCount;
|
|
||||||
|
|
||||||
// Remove comp only players only from the end of the players map if necessary
|
// Remove comp only players only from the end of the players map if necessary
|
||||||
for(auto itrev = players.end(); itrev != players.begin();)
|
for(auto itrev = players.end(); itrev != players.begin();)
|
||||||
{
|
{
|
||||||
auto it = itrev;
|
auto it = itrev;
|
||||||
--it;
|
--it;
|
||||||
if(players.size() <= totalPlayersCnt) break;
|
if (players.size() <= playerCount) break;
|
||||||
if(it->second.getPlayerType() == EPlayerType::COMP_ONLY)
|
if(it->second.getPlayerType() == EPlayerType::COMP_ONLY)
|
||||||
{
|
{
|
||||||
players.erase(it);
|
players.erase(it);
|
||||||
@ -281,7 +283,7 @@ void CMapGenOptions::updateCompOnlyPlayers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add some comp only players if necessary
|
// Add some comp only players if necessary
|
||||||
auto compOnlyPlayersToAdd = totalPlayersCnt - players.size();
|
auto compOnlyPlayersToAdd = playerCount - players.size();
|
||||||
for(int i = 0; i < compOnlyPlayersToAdd; ++i)
|
for(int i = 0; i < compOnlyPlayersToAdd; ++i)
|
||||||
{
|
{
|
||||||
CPlayerSettings pSettings;
|
CPlayerSettings pSettings;
|
||||||
@ -340,31 +342,34 @@ const CRmgTemplate * CMapGenOptions::getPossibleTemplate(CRandomGenerator & rand
|
|||||||
bool isPlayerCountValid = false;
|
bool isPlayerCountValid = false;
|
||||||
if(playerCount != RANDOM_SIZE)
|
if(playerCount != RANDOM_SIZE)
|
||||||
{
|
{
|
||||||
if(tpl->getPlayers().isInRange(playerCount)) isPlayerCountValid = true;
|
if (tpl->getPlayers().isInRange(playerCount))
|
||||||
|
isPlayerCountValid = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Human players shouldn't be banned when playing with random player count
|
// Human players shouldn't be banned when playing with random player count
|
||||||
auto playerNumbers = tpl->getPlayers().getNumbers();
|
auto playerNumbers = tpl->getPlayers().getNumbers();
|
||||||
if(playerNumbers.lower_bound(countHumanPlayers()) != playerNumbers.end())
|
if(countHumanPlayers() <= *boost::min_element(playerNumbers))
|
||||||
{
|
{
|
||||||
isPlayerCountValid = true;
|
isPlayerCountValid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isPlayerCountValid)
|
if (isPlayerCountValid)
|
||||||
{
|
{
|
||||||
bool isCpuPlayerCountValid = false;
|
bool isCpuPlayerCountValid = false;
|
||||||
if(compOnlyPlayerCount != RANDOM_SIZE)
|
if(compOnlyPlayerCount != RANDOM_SIZE)
|
||||||
{
|
{
|
||||||
if(tpl->getCpuPlayers().isInRange(compOnlyPlayerCount)) isCpuPlayerCountValid = true;
|
if (tpl->getCpuPlayers().isInRange(compOnlyPlayerCount))
|
||||||
|
isCpuPlayerCountValid = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isCpuPlayerCountValid = true;
|
isCpuPlayerCountValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isCpuPlayerCountValid) potentialTpls.push_back(tpl);
|
if(isCpuPlayerCountValid)
|
||||||
|
potentialTpls.push_back(tpl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public:
|
|||||||
bool getHasTwoLevels() const;
|
bool getHasTwoLevels() const;
|
||||||
void setHasTwoLevels(bool value);
|
void setHasTwoLevels(bool value);
|
||||||
|
|
||||||
/// The count of the players ranging from 1 to PlayerColor::PLAYER_LIMIT or RANDOM_SIZE for random. If you call
|
/// The count of all (human or computer) players ranging from 1 to PlayerColor::PLAYER_LIMIT or RANDOM_SIZE for random. If you call
|
||||||
/// this method, all player settings are reset to default settings.
|
/// this method, all player settings are reset to default settings.
|
||||||
si8 getPlayerCount() const;
|
si8 getPlayerCount() const;
|
||||||
void setPlayerCount(si8 value);
|
void setPlayerCount(si8 value);
|
||||||
@ -162,7 +162,7 @@ private:
|
|||||||
|
|
||||||
si32 width, height;
|
si32 width, height;
|
||||||
bool hasTwoLevels;
|
bool hasTwoLevels;
|
||||||
si8 playerCount, teamCount, compOnlyPlayerCount, compOnlyTeamCount;
|
si8 playerCount, teamCount, humanPlayersCount, compOnlyPlayerCount, compOnlyTeamCount;
|
||||||
EWaterContent::EWaterContent waterContent;
|
EWaterContent::EWaterContent waterContent;
|
||||||
EMonsterStrength::EMonsterStrength monsterStrength;
|
EMonsterStrength::EMonsterStrength monsterStrength;
|
||||||
std::map<PlayerColor, CPlayerSettings> players;
|
std::map<PlayerColor, CPlayerSettings> players;
|
||||||
@ -173,7 +173,7 @@ public:
|
|||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & width & height & hasTwoLevels & playerCount & teamCount & compOnlyPlayerCount;
|
h & width & height & hasTwoLevels & playerCount & teamCount & compOnlyPlayerCount;
|
||||||
h & compOnlyTeamCount & waterContent & monsterStrength & players;
|
h & compOnlyTeamCount & waterContent & monsterStrength & players & humanPlayersCount;
|
||||||
//TODO add name of template to class, enables selection of a template by a user
|
//TODO add name of template to class, enables selection of a template by a user
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -144,7 +144,7 @@ std::string CMapGenerator::getMapDescription() const
|
|||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << boost::str(boost::format(std::string("Map created by the Random Map Generator.\nTemplate was %s, Random seed was %d, size %dx%d") +
|
ss << boost::str(boost::format(std::string("Map created by the Random Map Generator.\nTemplate was %s, Random seed was %d, size %dx%d") +
|
||||||
", levels %s, humans %d, computers %d, water %s, monster %s, VCMI map") % mapGenOptions->getMapTemplate()->getName() %
|
", levels %s, players %d, computers %d, water %s, monster %s, VCMI map") % mapGenOptions->getMapTemplate()->getName() %
|
||||||
randomSeed % map->width % map->height % (map->twoLevel ? "2" : "1") % static_cast<int>(mapGenOptions->getPlayerCount()) %
|
randomSeed % map->width % map->height % (map->twoLevel ? "2" : "1") % static_cast<int>(mapGenOptions->getPlayerCount()) %
|
||||||
static_cast<int>(mapGenOptions->getCompOnlyPlayerCount()) % waterContentStr[mapGenOptions->getWaterContent()] %
|
static_cast<int>(mapGenOptions->getCompOnlyPlayerCount()) % waterContentStr[mapGenOptions->getWaterContent()] %
|
||||||
monsterStrengthStr[monsterStrengthIndex]);
|
monsterStrengthStr[monsterStrengthIndex]);
|
||||||
|
Loading…
Reference in New Issue
Block a user