diff --git a/lib/logging/CLogger.cpp b/lib/logging/CLogger.cpp index c4450c8a5..4091adab0 100644 --- a/lib/logging/CLogger.cpp +++ b/lib/logging/CLogger.cpp @@ -345,7 +345,7 @@ CColorMapping::CColorMapping() void CColorMapping::setColorFor(const CLoggerDomain & domain, ELogLevel::ELogLevel level, EConsoleTextColor::EConsoleTextColor color) { - if(level == ELogLevel::NOT_SET) throw std::runtime_error("Log level NOT_SET not allowed for configuring the color mapping."); + assert(level != ELogLevel::NOT_SET); map[domain.getName()][level] = color; } @@ -375,7 +375,7 @@ EConsoleTextColor::EConsoleTextColor CColorMapping::getColorFor(const CLoggerDom break; } } - throw std::runtime_error("No color mapping found. Should not happen."); + assert(0); } CLogConsoleTarget::CLogConsoleTarget(CConsoleHandler * console) : console(console), threshold(ELogLevel::INFO), coloredOutputEnabled(true) diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index f9dde43fb..dea5eca93 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -244,23 +244,15 @@ bool CMap::isInTheMap(const int3 & pos) const } } -void CMap::getTileRangeCheck(const int3 & tile) const -{ - if(!isInTheMap(tile)) - { - throw std::runtime_error(boost::str(boost::format("Cannot get map tile for position x '%d', y '%d', z '%d'.") % tile.x % tile.y % tile.z)); - } -} - TerrainTile & CMap::getTile(const int3 & tile) { - getTileRangeCheck(tile); + assert(isInTheMap(tile)); return terrain[tile.x][tile.y][tile.z]; } const TerrainTile & CMap::getTile(const int3 & tile) const { - getTileRangeCheck(tile); + assert(isInTheMap(tile)); return terrain[tile.x][tile.y][tile.z]; } diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index 8b29a8496..99b8db8ea 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -367,8 +367,6 @@ public: unique_ptr editManager; private: - void getTileRangeCheck(const int3 & tile) const; - TerrainTile*** terrain; public: diff --git a/lib/mapping/CMapEditManager.cpp b/lib/mapping/CMapEditManager.cpp index db16a4077..261297df3 100644 --- a/lib/mapping/CMapEditManager.cpp +++ b/lib/mapping/CMapEditManager.cpp @@ -114,7 +114,7 @@ int CMapUndoManager::getUndoRedoLimit() const void CMapUndoManager::setUndoRedoLimit(int value) { - if(value < 0) throw std::runtime_error("Cannot set a negative value for the undo redo limit."); + assert(value >= 0); undoStack.resize(std::min(undoStack.size(), static_cast(value))); redoStack.resize(std::min(redoStack.size(), static_cast(value))); } diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index a1d079560..45fcf88ae 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -24,14 +24,8 @@ si32 CMapGenOptions::getWidth() const void CMapGenOptions::setWidth(si32 value) { - if(value > 0) - { - width = value; - } - else - { - throw std::runtime_error("A map width lower than 1 is not allowed."); - } + assert(value >= 1); + width = value; } si32 CMapGenOptions::getHeight() const @@ -41,14 +35,8 @@ si32 CMapGenOptions::getHeight() const void CMapGenOptions::setHeight(si32 value) { - if(value > 0) - { - height = value; - } - else - { - throw std::runtime_error("A map height lower than 1 is not allowed."); - } + assert(value >= 1); + height = value; } bool CMapGenOptions::getHasTwoLevels() const @@ -68,16 +56,9 @@ si8 CMapGenOptions::getPlayersCnt() const void CMapGenOptions::setPlayersCnt(si8 value) { - if((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE) - { - playersCnt = value; - resetPlayersMap(); - } - else - { - throw std::runtime_error("Players count of RMG options should be between 1 and " + - boost::lexical_cast(PlayerColor::PLAYER_LIMIT_I) + " or CMapGenOptions::RANDOM_SIZE for random."); - } + assert((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE); + playersCnt = value; + resetPlayersMap(); } si8 CMapGenOptions::getTeamsCnt() const @@ -87,15 +68,8 @@ si8 CMapGenOptions::getTeamsCnt() const void CMapGenOptions::setTeamsCnt(si8 value) { - if(playersCnt == RANDOM_SIZE || (value >= 0 && value < playersCnt) || value == RANDOM_SIZE) - { - teamsCnt = value; - } - else - { - throw std::runtime_error("Teams count of RMG options should be between 0 and <" + - boost::lexical_cast(playersCnt) + "(players count) - 1> or CMapGenOptions::RANDOM_SIZE for random."); - } + assert(playersCnt == RANDOM_SIZE || (value >= 0 && value < playersCnt) || value == RANDOM_SIZE); + teamsCnt = value; } si8 CMapGenOptions::getCompOnlyPlayersCnt() const @@ -105,17 +79,9 @@ si8 CMapGenOptions::getCompOnlyPlayersCnt() const void CMapGenOptions::setCompOnlyPlayersCnt(si8 value) { - if(value == RANDOM_SIZE || (value >= 0 && value <= PlayerColor::PLAYER_LIMIT_I - playersCnt)) - { - compOnlyPlayersCnt = value; - resetPlayersMap(); - } - else - { - throw std::runtime_error(std::string("Computer only players count of RMG options should be ") + - "between 0 and (playersCnt) + - "(playersCount)> or CMapGenOptions::RANDOM_SIZE for random."); - } + assert(value == RANDOM_SIZE || (value >= 0 && value <= PlayerColor::PLAYER_LIMIT_I - playersCnt)); + compOnlyPlayersCnt = value; + resetPlayersMap(); } si8 CMapGenOptions::getCompOnlyTeamsCnt() const @@ -125,16 +91,8 @@ si8 CMapGenOptions::getCompOnlyTeamsCnt() const void CMapGenOptions::setCompOnlyTeamsCnt(si8 value) { - if(value == RANDOM_SIZE || compOnlyPlayersCnt == RANDOM_SIZE || (value >= 0 && value <= std::max(compOnlyPlayersCnt - 1, 0))) - { - compOnlyTeamsCnt = value; - } - else - { - throw std::runtime_error(std::string("Computer only teams count of RMG options should be ") + - "between 0 and <" + boost::lexical_cast(compOnlyPlayersCnt) + - "(compOnlyPlayersCnt) - 1> or CMapGenOptions::RANDOM_SIZE for random."); - } + assert(value == RANDOM_SIZE || compOnlyPlayersCnt == RANDOM_SIZE || (value >= 0 && value <= std::max(compOnlyPlayersCnt - 1, 0))); + compOnlyTeamsCnt = value; } EWaterContent::EWaterContent CMapGenOptions::getWaterContent() const @@ -179,15 +137,15 @@ const std::map & CMapGenOptions::g void CMapGenOptions::setStartingTownForPlayer(PlayerColor color, si32 town) { auto it = players.find(color); - if(it == players.end()) throw std::runtime_error(boost::str(boost::format("Cannot set starting town for the player with the color '%s'.") % color)); + if(it == players.end()) assert(0); it->second.setStartingTown(town); } void CMapGenOptions::setPlayerTypeForStandardPlayer(PlayerColor color, EPlayerType::EPlayerType playerType) { + assert(playerType != EPlayerType::COMP_ONLY); auto it = players.find(color); - if(it == players.end()) throw std::runtime_error(boost::str(boost::format("Cannot set player type for the player with the color '%s'.") % color)); - if(playerType == EPlayerType::COMP_ONLY) throw std::runtime_error("Cannot set player type computer only to a standard player."); + if(it == players.end()) assert(0); it->second.setPlayerType(playerType); } @@ -305,7 +263,8 @@ PlayerColor CMapGenOptions::getNextPlayerColor() const return i; } } - throw std::runtime_error("Shouldn't happen. No free player color exists."); + assert(0); + return PlayerColor(0); } CMapGenOptions::CPlayerSettings::CPlayerSettings() : color(0), startingTown(RANDOM_TOWN), playerType(EPlayerType::AI) @@ -320,14 +279,8 @@ PlayerColor CMapGenOptions::CPlayerSettings::getColor() const void CMapGenOptions::CPlayerSettings::setColor(PlayerColor value) { - if(value >= PlayerColor(0) && value < PlayerColor::PLAYER_LIMIT) - { - color = value; - } - else - { - throw std::runtime_error("The color of the player is not in a valid range."); - } + assert(value >= PlayerColor(0) && value < PlayerColor::PLAYER_LIMIT); + color = value; } si32 CMapGenOptions::CPlayerSettings::getStartingTown() const @@ -337,14 +290,8 @@ si32 CMapGenOptions::CPlayerSettings::getStartingTown() const void CMapGenOptions::CPlayerSettings::setStartingTown(si32 value) { - if(value >= -1 && value < static_cast(VLC->townh->factions.size())) - { - startingTown = value; - } - else - { - throw std::runtime_error("The starting town of the player is not in a valid range."); - } + assert(value >= -1 && value < static_cast(VLC->townh->factions.size())); + startingTown = value; } EPlayerType::EPlayerType CMapGenOptions::CPlayerSettings::getPlayerType() const