Bläddra i källkod

EntityIdentifiers.h getDwellingFromLevel modify to avoid exceptions

Mircea TheHonestCTO 3 månader sedan
förälder
incheckning
fdf6ba5a2f
1 ändrade filer med 4 tillägg och 8 borttagningar
  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