浏览代码

EntityIdentifiers.h getDwellingFromLevel modify to avoid exceptions

Mircea TheHonestCTO 3 月之前
父节点
当前提交
fdf6ba5a2f
共有 1 个文件被更改,包括 4 次插入8 次删除
  1. 4 8
      lib/constants/EntityIdentifiers.h

+ 4 - 8
lib/constants/EntityIdentifiers.h

@@ -369,16 +369,12 @@ public:
 		throw std::runtime_error("Call to getMageGuildLevel with building '" + std::to_string(getNum()) +"' that is not mages guild!");
 	}
 
-	static BuildingID getDwellingFromLevel(int levelIndex, int upgradeIndex)
+	static BuildingID getDwellingFromLevel(const int levelIndex, const int upgradeIndex)
 	{
-		try
-		{
-			return getDwellings().at(upgradeIndex).at(levelIndex);
-		}
-		catch (const std::out_of_range &)
-		{
+		if (upgradeIndex >= getDwellings().size() || levelIndex >= getDwellings()[upgradeIndex].size())
 			return Type::NONE;
-		}
+
+		return getDwellings().at(upgradeIndex).at(levelIndex);
 	}
 
 	/// @return 0 for the first one, going up to the supported no. of dwellings - 1