mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
- Fixed bug when starting random map with 1 player - Refactoring - Fixed compile bug - Heroes can be selected in map selection screen(RMG map) - Main town gen
This commit is contained in:
parent
5b919d88eb
commit
1cab54b87a
5
Global.h
5
Global.h
@ -394,6 +394,11 @@ namespace vstd
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2)));
|
||||
}
|
||||
template<typename T, typename Arg1, typename Arg2, typename Arg3>
|
||||
std::unique_ptr<T> make_unique(Arg1 &&arg1, Arg2 &&arg2, Arg3 &&arg3)
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3)));
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
typename Container::const_reference circularAt(const Container &r, size_t index)
|
||||
|
@ -1844,6 +1844,8 @@ void RandomMapTab::updateMapInfo()
|
||||
player.canHumanPlay = true;
|
||||
}
|
||||
player.team = i;
|
||||
player.hasMainTown = true;
|
||||
player.generateHeroAtMainTown = true;
|
||||
mapInfo.mapHeader->players.push_back(player);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,11 @@ rett * createAny(std::string dllname, std::string methodName)
|
||||
else if(!getName || !getAI)
|
||||
{
|
||||
tlog1 << dllname << " does not export method " << methodName << std::endl;
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(dll);
|
||||
#else
|
||||
dlclose(dll);
|
||||
#endif
|
||||
throw std::runtime_error("Cannot find method " + methodName);
|
||||
}
|
||||
|
||||
|
@ -898,21 +898,27 @@ void CGameState::init(StartInfo * si)
|
||||
map = mapGen.generate().release();
|
||||
|
||||
// Update starting options
|
||||
for(auto it = scenarioOps->playerInfos.begin(); it != scenarioOps->playerInfos.end();)
|
||||
for(int i = 0; i < map->players.size(); ++i)
|
||||
{
|
||||
PlayerSettings & pSettings = it->second;
|
||||
if(!(map->players[pSettings.color].canHumanPlay || map->players[pSettings.color].canComputerPlay))
|
||||
const PlayerInfo & pInfo = map->players[i];
|
||||
if(pInfo.canComputerPlay || pInfo.canHumanPlay)
|
||||
{
|
||||
scenarioOps->playerInfos.erase(it++);
|
||||
PlayerSettings & pSettings = scenarioOps->playerInfos[i];
|
||||
pSettings.compOnly = !pInfo.canHumanPlay;
|
||||
pSettings.team = pInfo.team;
|
||||
pSettings.castle = pInfo.defaultCastle();
|
||||
if(pSettings.playerID == PlayerSettings::PLAYER_AI && pSettings.name.empty())
|
||||
{
|
||||
pSettings.name = VLC->generaltexth->allTexts[468];
|
||||
}
|
||||
pSettings.color = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
pSettings.compOnly = !(map->players[pSettings.color].canHumanPlay);
|
||||
pSettings.team = map->players[pSettings.color].team;
|
||||
pSettings.castle = map->players[pSettings.color].defaultCastle();
|
||||
++it;
|
||||
scenarioOps->playerInfos.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ std::unique_ptr<CMap> CMapLoaderH3M::loadMap()
|
||||
std::unique_ptr<CMapHeader> CMapLoaderH3M::loadMapHeader()
|
||||
{
|
||||
// Read header
|
||||
mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader);
|
||||
mapHeader = make_unique<CMapHeader>();
|
||||
readHeader();
|
||||
|
||||
return std::move(mapHeader);
|
||||
|
@ -29,11 +29,11 @@ std::unique_ptr<CMap> CMapGenerator::generate()
|
||||
|
||||
//TODO select a template based on the map gen options or adapt it if necessary
|
||||
|
||||
map = std::unique_ptr<CMap>(new CMap());
|
||||
map = make_unique<CMap>();
|
||||
addHeaderInfo();
|
||||
|
||||
terViewPatternConfig = std::unique_ptr<CTerrainViewPatternConfig>(new CTerrainViewPatternConfig());
|
||||
mapMgr = std::unique_ptr<CMapEditManager>(new CMapEditManager(terViewPatternConfig.get(), map.get(), randomSeed));
|
||||
terViewPatternConfig = make_unique<CTerrainViewPatternConfig>();
|
||||
mapMgr = make_unique<CMapEditManager>(terViewPatternConfig.get(), map.get(), randomSeed);
|
||||
genTerrain();
|
||||
genTowns();
|
||||
|
||||
@ -44,7 +44,7 @@ void CMapGenerator::validateOptions() const
|
||||
{
|
||||
int playersCnt = 0;
|
||||
int compOnlyPlayersCnt = 0;
|
||||
BOOST_FOREACH(const tPlayersMap::value_type & pair, players)
|
||||
BOOST_FOREACH(const auto & pair, players)
|
||||
{
|
||||
if(pair.second.getPlayerType() == CPlayerSettings::COMP_ONLY)
|
||||
{
|
||||
@ -94,7 +94,7 @@ void CMapGenerator::validateOptions() const
|
||||
throw std::runtime_error("1 human player is required at least");
|
||||
}
|
||||
|
||||
BOOST_FOREACH(const tPlayersMap::value_type & pair, players)
|
||||
BOOST_FOREACH(const auto & pair, players)
|
||||
{
|
||||
if(pair.first != pair.second.getColor())
|
||||
{
|
||||
@ -212,7 +212,7 @@ std::string CMapGenerator::getMapDescription() const
|
||||
ss << static_cast<int>(mapGenOptions.getCompOnlyPlayersCnt()) << ", water " << waterContentStr[mapGenOptions.getWaterContent()];
|
||||
ss << ", monster " << monsterStrengthStr[mapGenOptions.getMonsterStrength()] << ", second expansion map";
|
||||
|
||||
BOOST_FOREACH(const tPlayersMap::value_type & pair, players)
|
||||
BOOST_FOREACH(const auto & pair, players)
|
||||
{
|
||||
const CPlayerSettings & pSettings = pair.second;
|
||||
if(pSettings.getPlayerType() == CPlayerSettings::HUMAN)
|
||||
@ -265,7 +265,7 @@ void CMapGenerator::addPlayerInfo()
|
||||
}
|
||||
|
||||
// Team numbers are assigned randomly to every player
|
||||
BOOST_FOREACH(const tPlayersMap::value_type & pair, players)
|
||||
BOOST_FOREACH(const auto & pair, players)
|
||||
{
|
||||
const CPlayerSettings & pSettings = pair.second;
|
||||
PlayerInfo player;
|
||||
@ -287,7 +287,7 @@ void CMapGenerator::addPlayerInfo()
|
||||
|
||||
int CMapGenerator::countHumanPlayers() const
|
||||
{
|
||||
return static_cast<int>(std::count_if(players.begin(), players.end(), [](const std::pair<TPlayerColor, CPlayerSettings> & pair)
|
||||
return static_cast<int>(boost::count_if(players, [](const std::pair<TPlayerColor, CPlayerSettings> & pair)
|
||||
{
|
||||
return pair.second.getPlayerType() == CMapGenerator::CPlayerSettings::HUMAN;
|
||||
}));
|
||||
@ -319,8 +319,14 @@ void CMapGenerator::genTowns()
|
||||
town->builtBuildings.insert(EBuilding::FORT);
|
||||
town->builtBuildings.insert(-50);
|
||||
mapMgr->insertObject(town, townPos[side].x, townPos[side].y + (pos / 2) * 5, false);
|
||||
map->players[owner].allowedFactions.clear();
|
||||
map->players[owner].allowedFactions.insert(townTypes[side]);
|
||||
|
||||
// Update player info
|
||||
PlayerInfo & pInfo = map->players[owner];
|
||||
pInfo.allowedFactions.clear();
|
||||
pInfo.allowedFactions.insert(townTypes[side]);
|
||||
pInfo.hasMainTown = true;
|
||||
pInfo.posOfMainTown = town->pos - int3(2, 0, 0);
|
||||
pInfo.generateHeroAtMainTown = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,7 +346,7 @@ TPlayerColor CMapGenerator::getNextPlayerColor() const
|
||||
{
|
||||
for(TPlayerColor i = 0; i < GameConstants::PLAYER_LIMIT; ++i)
|
||||
{
|
||||
if(players.find(i) == players.end())
|
||||
if(!players.count(i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
@ -193,7 +193,4 @@ private:
|
||||
|
||||
/** The random gen player settings. */
|
||||
std::map<TPlayerColor, CPlayerSettings> players;
|
||||
|
||||
/** Typedef of the players map, so that boost foreach can be used. */
|
||||
typedef std::map<TPlayerColor, CPlayerSettings> tPlayersMap;
|
||||
};
|
||||
|
@ -59,7 +59,8 @@ struct PlayerSettings
|
||||
h & compOnly;
|
||||
}
|
||||
|
||||
PlayerSettings() : bonus(RANDOM), castle(NONE), heroPortrait(RANDOM), compOnly(false)
|
||||
PlayerSettings() : bonus(RANDOM), castle(NONE), hero(RANDOM), heroPortrait(RANDOM),
|
||||
color(0), handicap(0), team(0), playerID(PLAYER_AI), compOnly(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user