浏览代码

Fixed crash due to incorrect RMG options.

DjWarmonger 11 年之前
父节点
当前提交
495c39304d
共有 3 个文件被更改,包括 11 次插入2 次删除
  1. 1 0
      client/mapHandler.cpp
  2. 4 1
      lib/rmg/CMapGenOptions.cpp
  3. 6 1
      lib/rmg/CMapGenerator.cpp

+ 1 - 0
client/mapHandler.cpp

@@ -212,6 +212,7 @@ void CMapHandler::roadsRiverTerrainInit()
 	}
 	}
 
 
 	// Create enough room for the whole map and its frame
 	// Create enough room for the whole map and its frame
+
 	ttiles.resize(sizes.x, frameW, frameW);
 	ttiles.resize(sizes.x, frameW, frameW);
 	for (int i=0-frameW;i<ttiles.size()-frameW;i++)
 	for (int i=0-frameW;i<ttiles.size()-frameW;i++)
 	{
 	{

+ 4 - 1
lib/rmg/CMapGenOptions.cpp

@@ -183,8 +183,8 @@ void CMapGenOptions::finalize(CRandomGenerator & rand)
 	if(!mapTemplate)
 	if(!mapTemplate)
 	{
 	{
 		mapTemplate = getPossibleTemplate(rand);
 		mapTemplate = getPossibleTemplate(rand);
-		assert(mapTemplate);
 	}
 	}
+	assert(mapTemplate);
 
 
 	if(playerCount == RANDOM_SIZE)
 	if(playerCount == RANDOM_SIZE)
 	{
 	{
@@ -220,6 +220,9 @@ void CMapGenOptions::finalize(CRandomGenerator & rand)
 		monsterStrength = static_cast<EMonsterStrength::EMonsterStrength>(rand.nextInt(EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG));
 		monsterStrength = static_cast<EMonsterStrength::EMonsterStrength>(rand.nextInt(EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG));
 	}
 	}
 
 
+	assert (vstd::iswithin(waterContent, EWaterContent::NONE, EWaterContent::ISLANDS));
+	assert (vstd::iswithin(monsterStrength, EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG));
+
 	//rectangular maps are the future of gaming
 	//rectangular maps are the future of gaming
 	//setHeight(20);
 	//setHeight(20);
 	//setWidth(50);
 	//setWidth(50);

+ 6 - 1
lib/rmg/CMapGenerator.cpp

@@ -112,15 +112,20 @@ std::unique_ptr<CMap> CMapGenerator::generate(CMapGenOptions * mapGenOptions, in
 
 
 std::string CMapGenerator::getMapDescription() const
 std::string CMapGenerator::getMapDescription() const
 {
 {
+	assert(mapGenOptions);
+	assert(map);
+
 	const std::string waterContentStr[3] = { "none", "normal", "islands" };
 	const std::string waterContentStr[3] = { "none", "normal", "islands" };
 	const std::string monsterStrengthStr[3] = { "weak", "normal", "strong" };
 	const std::string monsterStrengthStr[3] = { "weak", "normal", "strong" };
 
 
+	int monsterStrengthIndex = mapGenOptions->getMonsterStrength() - EMonsterStrength::GLOBAL_WEAK; //does not start from 0
+
     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, second expansion map") % mapGenOptions->getMapTemplate()->getName() %
         ", levels %s, humans %d, computers %d, water %s, monster %s, second expansion 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[mapGenOptions->getMonsterStrength()]);
+		monsterStrengthStr[monsterStrengthIndex]);
 
 
 	for(const auto & pair : mapGenOptions->getPlayersSettings())
 	for(const auto & pair : mapGenOptions->getPlayersSettings())
 	{
 	{