From 34a59a27884f52e47dcefef43ff4f7d83eddd234 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Wed, 27 May 2015 18:58:14 +0200 Subject: [PATCH] - Fixed issues with number of players selection - Added new template for testing multiple players --- .../defaultTemplates/coldshadowsFantasy.json | 239 ++++++++++++++++++ .../Mods/Coldshadows Fantasy/mod.json | 12 + lib/rmg/CMapGenOptions.cpp | 45 ++-- 3 files changed, 280 insertions(+), 16 deletions(-) create mode 100644 Mods/vcmi/Mods/defaultTemplates/Mods/Coldshadows Fantasy/Content/config/defaultTemplates/coldshadowsFantasy.json create mode 100644 Mods/vcmi/Mods/defaultTemplates/Mods/Coldshadows Fantasy/mod.json diff --git a/Mods/vcmi/Mods/defaultTemplates/Mods/Coldshadows Fantasy/Content/config/defaultTemplates/coldshadowsFantasy.json b/Mods/vcmi/Mods/defaultTemplates/Mods/Coldshadows Fantasy/Content/config/defaultTemplates/coldshadowsFantasy.json new file mode 100644 index 000000000..1d47aef49 --- /dev/null +++ b/Mods/vcmi/Mods/defaultTemplates/Mods/Coldshadows Fantasy/Content/config/defaultTemplates/coldshadowsFantasy.json @@ -0,0 +1,239 @@ +{ + "Coldshadow's Fantasy": + { + "minSize" : "xl+u", "maxSize" : "xl+u", + "players" : "4-8", "cpu" : "3-6", + "zones": + { + "1": + { + "type" : "playerStart", "size" : 30, "owner" : 1, + "playerTowns" : { "castles" : 1 }, + "neutralTowns" : { "towns" : 1 }, + "monsters" : "normal", + "mines" : {"wood" : 2, "ore" : 2, "gems" : 1, "crystal" : 1, "sulfur" : 1, "mercury" : 1, "gold" : 1}, + "treasure" : [ + {"min" : 7500, "max": 25000, "density": 4}, + {"min" : 3000, "max": 9000, "density": 6}, + {"min" : 300, "max": 3000, "density": 8} + ] + }, + "2": + { + "type" : "cpuStart", "size" : 30, "owner" : 2, + "playerTowns" : { "castles" : 1 }, + "neutralTowns" : { "towns" : 1 }, + "monsters" : "weak", + "minesLikeZone" : 1, + "treasureLikeZone" : 1 + }, + "3": + { + "type" : "cpuStart", "size" : 30, "owner" : 3, + "playerTowns" : { "castles" : 1 }, + "neutralTowns" : { "towns" : 1 }, + "monsters" : "weak", + "minesLikeZone" : 1, + "treasureLikeZone" : 1 + }, + "4": + { + "type" : "cpuStart", "size" : 30, "owner" : 4, + "playerTowns" : { "castles" : 1 }, + "neutralTowns" : { "towns" : 1 }, + "monsters" : "weak", + "minesLikeZone" : 1, + "treasureLikeZone" : 1 + }, + "5": + { + "type" : "playerStart", "size" : 30, "owner" : 5, + "playerTowns" : { "castles" : 1 }, + "neutralTowns" : { "towns" : 1 }, + "monsters" : "normal", + "minesLikeZone" : 1, + "treasureLikeZone" : 1 + }, + "6": + { + "type" : "cpuStart", "size" : 30, "owner" : 6, + "playerTowns" : { "castles" : 1 }, + "neutralTowns" : { "towns" : 1 }, + "monsters" : "weak", + "minesLikeZone" : 1, + "treasureLikeZone" : 1 + }, + "7": + { + "type" : "cpuStart", "size" : 30, "owner" : 7, + "playerTowns" : { "castles" : 1 }, + "neutralTowns" : { "towns" : 1 }, + "monsters" : "weak", + "minesLikeZone" : 1, + "treasureLikeZone" : 1 + }, + "8": + { + "type" : "cpuStart", "size" : 30, "owner" : 8, + "playerTowns" : { "castles" : 1 }, + "neutralTowns" : { "towns" : 1 }, + "monsters" : "weak", + "minesLikeZone" : 1, + "treasureLikeZone" : 1 + }, + "9": + { + "type" : "treasure", "size" : 15, + "terrainTypes" : ["subterra"], "matchTerrainToTown" : false, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "strong", + "mines" : {"gems" : 1, "sulfur" : 1, "mercury" : 1, "crystal" : 1}, + "treasure" : [ + {"min" : 45000, "max": 75000, "density": 3}, + {"min" : 15000, "max": 50000, "density": 3}, + {"min" : 3080, "max": 12500, "density": 4} + ] + }, + "10": + { + "type" : "treasure", "size" : 15, + "terrainTypeLikeZone" : 9, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "normal", + "minesLikeZone" : 9, + "treasureLikeZone" : 9 + }, + "11": + { + "type" : "treasure", "size" : 15, + "terrainTypeLikeZone" : 9, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "normal", + "minesLikeZone" : 9, + "treasureLikeZone" : 9 + }, + "12": + { + "type" : "treasure", "size" : 15, + "terrainTypeLikeZone" : 9, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "normal", + "minesLikeZone" : 9, + "treasureLikeZone" : 9 + }, + "13": + { + "type" : "treasure", "size" : 15, + "terrainTypeLikeZone" : 9, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "strong", + "minesLikeZone" : 9, + "treasureLikeZone" : 9 + }, + "14": + { + "type" : "treasure", "size" : 15, + "terrainTypeLikeZone" : 9, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "normal", + "minesLikeZone" : 9, + "treasureLikeZone" : 9 + }, + "15": + { + "type" : "treasure", "size" : 15, + "terrainTypeLikeZone" : 9, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "normal", + "minesLikeZone" : 9, + "treasureLikeZone" : 9 + }, + "16": + { + "type" : "treasure", "size" : 15, + "terrainTypeLikeZone" : 9, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "normal", + "minesLikeZone" : 9, + "treasureLikeZone" : 9 + }, + "17": + { + "type" : "junction", "size" : 30, + "terrainTypeLikeZone" : 9, + "allowedTowns" : ["neutral"], + "monsters" : "strong", + "mines" : {"gold" : 1}, + "treasure" : [ + {"min" : 65000, "max": 100000, "density": 3}, + {"min" : 50000, "max": 100000, "density": 3}, + {"min" : 10000, "max": 15000, "density": 3} + ] + }, + "18": + { + "type" : "junction", "size" : 30, + "terrainTypeLikeZone" : 9, + "allowedTowns" : ["neutral"], + "monsters" : "strong", + "minesLikeZone" : 17, + "treasureLikeZone" : 17 + }, + "19": + { + "type" : "junction", "size" : 30, + "terrainTypeLikeZone" : 9, + "allowedTowns" : ["neutral"], + "monsters" : "strong", + "minesLikeZone" : 17, + "treasureLikeZone" : 17 + }, + "20": + { + "type" : "junction", "size" : 30, + "terrainTypeLikeZone" : 9, + "allowedTowns" : ["neutral"], + "monsters" : "strong", + "minesLikeZone" : 17, + "treasureLikeZone" : 17 + }, + "21": + { + "type" : "treasure", "size" : 20, + "terrainTypeLikeZone" : 9, + "neutralTowns" : { "castles" : 1 }, + "monsters" : "strong", + "treasure" : [ + {"min" : 100000, "max": 130000, "density": 3}, + {"min" : 100000, "max": 150000, "density": 3}, + {"min" : 20000, "max": 60000, "density": 3} + ] + } + }, + "connections" : + [ + { "a" : "1", "b" : "9", "guard" : 36000 }, + { "a" : "2", "b" : "10", "guard" : 12000 }, + { "a" : "3", "b" : "11", "guard" : 12000 }, + { "a" : "4", "b" : "12", "guard" : 12000 }, + { "a" : "5", "b" : "13", "guard" : 36000 }, + { "a" : "6", "b" : "14", "guard" : 12000 }, + { "a" : "7", "b" : "15", "guard" : 12000 }, + { "a" : "8", "b" : "16", "guard" : 12000 }, + { "a" : "9", "b" : "17", "guard" : 75000 }, + { "a" : "10", "b" : "17", "guard" : 25000 }, + { "a" : "11", "b" : "18", "guard" : 25000 }, + { "a" : "12", "b" : "18", "guard" : 25000 }, + { "a" : "13", "b" : "19", "guard" : 75000 }, + { "a" : "14", "b" : "19", "guard" : 25000 }, + { "a" : "15", "b" : "20", "guard" : 25000 }, + { "a" : "16", "b" : "20", "guard" : 25000 }, + { "a" : "17", "b" : "18", "guard" : 50000 }, + { "a" : "19", "b" : "20", "guard" : 50000 }, + { "a" : "17", "b" : "21", "guard" : 60000 }, + { "a" : "18", "b" : "21", "guard" : 60000 }, + { "a" : "19", "b" : "21", "guard" : 60000 }, + { "a" : "20", "b" : "21", "guard" : 60000 } + ] + } +} diff --git a/Mods/vcmi/Mods/defaultTemplates/Mods/Coldshadows Fantasy/mod.json b/Mods/vcmi/Mods/defaultTemplates/Mods/Coldshadows Fantasy/mod.json new file mode 100644 index 000000000..d185c8521 --- /dev/null +++ b/Mods/vcmi/Mods/defaultTemplates/Mods/Coldshadows Fantasy/mod.json @@ -0,0 +1,12 @@ +{ + "name" : "Coldshadow's Fantasy", + "description" : "Random map template, 4-8p XL+U", + + "version" : "0.99", + "author" : "Coldshadow, ported by VCMI Team", + "contact" : "http://forum.vcmi.eu/index.php", + "modType" : "Templates", + "templates" : [ + "config/defaultTemplates/coldshadowsFantasy" + ], +} diff --git a/lib/rmg/CMapGenOptions.cpp b/lib/rmg/CMapGenOptions.cpp index 1213e4709..391af84f6 100644 --- a/lib/rmg/CMapGenOptions.cpp +++ b/lib/rmg/CMapGenOptions.cpp @@ -67,11 +67,14 @@ void CMapGenOptions::setPlayerCount(si8 value) { assert((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE); playerCount = value; + auto possibleCompPlayersCount = value; if (compOnlyPlayerCount > possibleCompPlayersCount) setCompOnlyPlayerCount(possibleCompPlayersCount); - humanPlayersCount = playerCount - compOnlyPlayerCount; + if (getPlayerCount() != RANDOM_SIZE && getCompOnlyPlayerCount() != RANDOM_SIZE) + humanPlayersCount = getPlayerCount() - getCompOnlyPlayerCount(); + resetPlayersMap(); } @@ -82,7 +85,7 @@ si8 CMapGenOptions::getTeamCount() const void CMapGenOptions::setTeamCount(si8 value) { - assert(playerCount == RANDOM_SIZE || (value >= 0 && value < playerCount) || value == RANDOM_SIZE); + assert(getPlayerCount() == RANDOM_SIZE || (value >= 0 && value < getPlayerCount()) || value == RANDOM_SIZE); teamCount = value; } @@ -93,9 +96,12 @@ si8 CMapGenOptions::getCompOnlyPlayerCount() const void CMapGenOptions::setCompOnlyPlayerCount(si8 value) { - assert(value == RANDOM_SIZE || (value >= 0 && value <= playerCount)); + assert(value == RANDOM_SIZE || (value >= 0 && value <= getPlayerCount())); compOnlyPlayerCount = value; - humanPlayersCount = playerCount - compOnlyPlayerCount; + + if (getPlayerCount() != RANDOM_SIZE && getCompOnlyPlayerCount() != RANDOM_SIZE) + humanPlayersCount = getPlayerCount() - getCompOnlyPlayerCount(); + resetPlayersMap(); } @@ -136,7 +142,7 @@ void CMapGenOptions::resetPlayersMap() int realPlayersCnt = humanPlayersCount; int realCompOnlyPlayersCnt = (compOnlyPlayerCount == RANDOM_SIZE) ? (PlayerColor::PLAYER_LIMIT_I - realPlayersCnt) : compOnlyPlayerCount; int totalPlayersLimit = realPlayersCnt + realCompOnlyPlayersCnt; - if(playerCount == RANDOM_SIZE || compOnlyPlayerCount == RANDOM_SIZE) + if (getPlayerCount() == RANDOM_SIZE || compOnlyPlayerCount == RANDOM_SIZE) totalPlayersLimit = static_cast(PlayerColor::PLAYER_LIMIT_I); //FIXME: what happens with human players here? @@ -145,7 +151,7 @@ void CMapGenOptions::resetPlayersMap() CPlayerSettings player; player.setColor(PlayerColor(color)); auto playerType = EPlayerType::AI; - if((playerCount != RANDOM_SIZE && color >= realPlayersCnt) + if ((getPlayerCount() != RANDOM_SIZE && color >= realPlayersCnt) || (compOnlyPlayerCount != RANDOM_SIZE && color >= (PlayerColor::PLAYER_LIMIT_I-compOnlyPlayerCount))) { playerType = EPlayerType::COMP_ONLY; @@ -195,7 +201,7 @@ const std::map & CMapGenOptions::getAvailableTempla void CMapGenOptions::finalize(CRandomGenerator & rand) { logGlobal->infoStream() << boost::format ("RMG settings: players %d, teams %d, computer players %d, computer teams %d, water %d, monsters %d") - % playerCount % teamCount % compOnlyPlayerCount % compOnlyTeamCount % waterContent % monsterStrength; + % getPlayerCount() % getTeamCount() % getCompOnlyPlayerCount() % getCompOnlyTeamCount() % getWaterContent() % getMonsterStrength(); if(!mapTemplate) { @@ -203,17 +209,17 @@ void CMapGenOptions::finalize(CRandomGenerator & rand) } assert(mapTemplate); - if(playerCount == RANDOM_SIZE) + if (getPlayerCount() == RANDOM_SIZE) { auto possiblePlayers = mapTemplate->getPlayers().getNumbers(); possiblePlayers.erase(possiblePlayers.begin(), possiblePlayers.lower_bound(countHumanPlayers())); assert(!possiblePlayers.empty()); - playerCount = *RandomGeneratorUtil::nextItem(possiblePlayers, rand); + setPlayerCount (*RandomGeneratorUtil::nextItem(possiblePlayers, rand)); updatePlayers(); } if(teamCount == RANDOM_SIZE) { - teamCount = rand.nextInt(playerCount - 1); + teamCount = rand.nextInt(getPlayerCount() - 1); if (teamCount == 1) teamCount = 0; } @@ -252,7 +258,7 @@ void CMapGenOptions::updatePlayers() { auto it = itrev; --it; - if(players.size() == playerCount) break; + if (players.size() == getPlayerCount()) break; if(it->second.getPlayerType() == EPlayerType::AI) { players.erase(it); @@ -271,7 +277,7 @@ void CMapGenOptions::updateCompOnlyPlayers() { auto it = itrev; --it; - if (players.size() <= playerCount) break; + if (players.size() <= getPlayerCount()) break; if(it->second.getPlayerType() == EPlayerType::COMP_ONLY) { players.erase(it); @@ -283,7 +289,13 @@ void CMapGenOptions::updateCompOnlyPlayers() } // Add some comp only players if necessary - auto compOnlyPlayersToAdd = playerCount - players.size(); + int compOnlyPlayersToAdd = getPlayerCount() - players.size(); + + if (compOnlyPlayersToAdd < 0) + { + logGlobal->errorStream() << boost::format("Incorrect number of players to add. Requested players %d, current players %d") % playerCount % players.size(); + assert (compOnlyPlayersToAdd < 0); + } for(int i = 0; i < compOnlyPlayersToAdd; ++i) { CPlayerSettings pSettings; @@ -310,7 +322,8 @@ PlayerColor CMapGenOptions::getNextPlayerColor() const return i; } } - assert(0); + logGlobal->errorStream() << "Failed to get next player color"; + assert(false); return PlayerColor(0); } @@ -340,9 +353,9 @@ const CRmgTemplate * CMapGenOptions::getPossibleTemplate(CRandomGenerator & rand if(tplSize >= tpl->getMinSize() && tplSize <= tpl->getMaxSize()) { bool isPlayerCountValid = false; - if(playerCount != RANDOM_SIZE) + if (getPlayerCount() != RANDOM_SIZE) { - if (tpl->getPlayers().isInRange(playerCount)) + if (tpl->getPlayers().isInRange(getPlayerCount())) isPlayerCountValid = true; } else