| 925 | } |
| 926 | |
| 927 | bool HouseExt::ReachedBuildLimit(const HouseClass* pHouse, const TechnoTypeClass* pType, bool ignoreQueued) |
| 928 | { |
| 929 | const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pType); |
| 930 | |
| 931 | if (pTypeExt->BuildLimitGroup_Types.empty() || pTypeExt->BuildLimitGroup_Nums.empty()) |
| 932 | return false; |
| 933 | |
| 934 | std::vector<int> limits = pTypeExt->BuildLimitGroup_Nums; |
| 935 | |
| 936 | if (!pTypeExt->BuildLimitGroup_ExtraLimit_Types.empty() && !pTypeExt->BuildLimitGroup_ExtraLimit_Nums.empty()) |
| 937 | { |
| 938 | for (size_t i = 0; i < pTypeExt->BuildLimitGroup_ExtraLimit_Types.size(); i++) |
| 939 | { |
| 940 | auto pTmpType = pTypeExt->BuildLimitGroup_ExtraLimit_Types[i]; |
| 941 | const auto pBuildingType = abstract_cast<BuildingTypeClass*>(pTmpType); |
| 942 | int count = 0; |
| 943 | |
| 944 | if (pBuildingType && (BuildingTypeExt::ExtMap.Find(pBuildingType)->PowersUp_Buildings.size() > 0 || BuildingTypeClass::Find(pBuildingType->PowersUpBuilding))) |
| 945 | count = BuildingTypeExt::GetUpgradesAmount(pBuildingType, const_cast<HouseClass*>(pHouse)); |
| 946 | else |
| 947 | count = pHouse->CountOwnedNow(pTmpType); |
| 948 | |
| 949 | if (i < pTypeExt->BuildLimitGroup_ExtraLimit_MaxCount.size() && pTypeExt->BuildLimitGroup_ExtraLimit_MaxCount[i] > 0) |
| 950 | count = Math::min(count, pTypeExt->BuildLimitGroup_ExtraLimit_MaxCount[i]); |
| 951 | |
| 952 | for (auto& limit : limits) |
| 953 | { |
| 954 | if (i < pTypeExt->BuildLimitGroup_ExtraLimit_Nums.size() && pTypeExt->BuildLimitGroup_ExtraLimit_Nums[i] > 0) |
| 955 | { |
| 956 | limit += count * pTypeExt->BuildLimitGroup_ExtraLimit_Nums[i]; |
| 957 | |
| 958 | if (pTypeExt->BuildLimitGroup_ExtraLimit_MaxNum > 0) |
| 959 | limit = Math::min(limit, pTypeExt->BuildLimitGroup_ExtraLimit_MaxNum); |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | if (limits.size() == 1) |
| 966 | { |
| 967 | int count = 0; |
| 968 | int queued = 0; |
| 969 | bool inside = false; |
| 970 | |
| 971 | for (TechnoTypeClass* pTmpType : pTypeExt->BuildLimitGroup_Types) |
| 972 | { |
| 973 | const auto pTmpTypeExt = TechnoTypeExt::ExtMap.Find(pTmpType); |
| 974 | |
| 975 | if (!ignoreQueued) |
| 976 | queued += QueuedNum(pHouse, pTmpType) * pTmpTypeExt->BuildLimitGroup_Factor; |
| 977 | |
| 978 | int owned = 0; |
| 979 | const auto pBuildingType = abstract_cast<BuildingTypeClass*>(pTmpType); |
| 980 | |
| 981 | if (pBuildingType && (BuildingTypeExt::ExtMap.Find(pBuildingType)->PowersUp_Buildings.size() > 0 || BuildingTypeClass::Find(pBuildingType->PowersUpBuilding))) |
| 982 | owned = BuildingTypeExt::GetUpgradesAmount(pBuildingType, const_cast<HouseClass*>(pHouse)); |
| 983 | else |
| 984 | owned = pHouse->CountOwnedNow(pTmpType); |