diff --git a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp index aee554a73..d47531c1c 100644 --- a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp @@ -209,7 +209,7 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite( int creatureLevel = -1; int creatureUpgrade = 0; - if(BuildingID::getLevelFromDwelling(toBuild) != -1) + if(BuildingID::DWELL_FIRST <= toBuild && toBuild <= BuildingID::DWELL_UP_LAST) { creatureLevel = BuildingID::getLevelFromDwelling(toBuild); creatureUpgrade = BuildingID::getUpgradedFromDwelling(toBuild); @@ -262,7 +262,7 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite( auto otherDwelling = [](const BuildingID & id) -> bool { - return BuildingID::getLevelFromDwelling(id) != -1; + return BuildingID::DWELL_FIRST <= id && id <= BuildingID::DWELL_UP_LAST; }; if(vstd::contains_if(missingBuildings, otherDwelling)) @@ -405,7 +405,7 @@ BuildingInfo::BuildingInfo( } else { - if(BuildingID::getLevelFromDwelling(id) != -1) + if(BuildingID::DWELL_FIRST <= id && id <= BuildingID::DWELL_UP_LAST) { creatureGrows = creature->getGrowth(); diff --git a/lib/constants/EntityIdentifiers.h b/lib/constants/EntityIdentifiers.h index b4a1cd820..e9087b6e5 100644 --- a/lib/constants/EntityIdentifiers.h +++ b/lib/constants/EntityIdentifiers.h @@ -298,7 +298,7 @@ public: HORDE_2_UPGR, GRAIL, EXTRA_TOWN_HALL, EXTRA_CITY_HALL, EXTRA_CAPITOL, DWELL_FIRST=30, DWELL_LVL_2, DWELL_LVL_3, DWELL_LVL_4, DWELL_LVL_5, DWELL_LVL_6, DWELL_LAST=36, DWELL_UP_FIRST=37, DWELL_LVL_2_UP, DWELL_LVL_3_UP, DWELL_LVL_4_UP, DWELL_LVL_5_UP, - DWELL_LVL_6_UP, DWELL_UP_LAST=43, DWELL_LVL_8=50, DWELL_LVL_8_UP=57, + DWELL_LVL_6_UP, DWELL_UP_LAST=43, DWELL_LVL_8=150, DWELL_LVL_8_UP=151, DWELL_LVL_1 = DWELL_FIRST, DWELL_LVL_7 = DWELL_LAST, @@ -337,7 +337,7 @@ public: if (it != tmp.end()) return std::distance(tmp.begin(), it); } - return -1; + return (dwelling - DWELL_FIRST) % (GameConstants::CREATURES_PER_TOWN - 1); } static int getUpgradedFromDwelling(BuildingIDBase dwelling) @@ -349,7 +349,7 @@ public: if (it != tmp.end()) return i; } - return -1; + return (dwelling - DWELL_FIRST) / (GameConstants::CREATURES_PER_TOWN - 1); } bool IsSpecialOrGrail() const diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 3b4fddc8f..f8fbbf7cf 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2360,7 +2360,7 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID, //Performs stuff that has to be done before new building is built auto processBeforeBuiltStructure = [t, this](const BuildingID buildingID) { - if(BuildingID::getLevelFromDwelling(buildingID) > -1) //dwelling + if(buildingID >= BuildingID::DWELL_FIRST) //dwelling { int level = BuildingID::getLevelFromDwelling(buildingID); int upgradeNumber = BuildingID::getUpgradedFromDwelling(buildingID);