| 764 | } |
| 765 | |
| 766 | CanBuildResult HouseExt::BuildLimitGroupCheck(const HouseClass* pThis, const TechnoTypeClass* pItem, bool buildLimitOnly, bool includeQueued) |
| 767 | { |
| 768 | const auto pItemExt = TechnoTypeExt::ExtMap.Find(pItem); |
| 769 | |
| 770 | if (pItemExt->BuildLimitGroup_Types.empty()) |
| 771 | return CanBuildResult::Buildable; |
| 772 | |
| 773 | std::vector<int> limits = pItemExt->BuildLimitGroup_Nums; |
| 774 | |
| 775 | if (!pItemExt->BuildLimitGroup_ExtraLimit_Types.empty() && !pItemExt->BuildLimitGroup_ExtraLimit_Nums.empty()) |
| 776 | { |
| 777 | for (size_t i = 0; i < pItemExt->BuildLimitGroup_ExtraLimit_Types.size(); i++) |
| 778 | { |
| 779 | int count = 0; |
| 780 | auto pTmpType = pItemExt->BuildLimitGroup_ExtraLimit_Types[i]; |
| 781 | auto const pBuildingType = abstract_cast<BuildingTypeClass*>(pTmpType); |
| 782 | |
| 783 | if (pBuildingType && (BuildingTypeExt::ExtMap.Find(pBuildingType)->PowersUp_Buildings.size() > 0 || BuildingTypeClass::Find(pBuildingType->PowersUpBuilding))) |
| 784 | count = BuildingTypeExt::GetUpgradesAmount(pBuildingType, const_cast<HouseClass*>(pThis)); |
| 785 | else |
| 786 | count = pThis->CountOwnedNow(pTmpType); |
| 787 | |
| 788 | if (i < pItemExt->BuildLimitGroup_ExtraLimit_MaxCount.size() && pItemExt->BuildLimitGroup_ExtraLimit_MaxCount[i] > 0) |
| 789 | count = Math::min(count, pItemExt->BuildLimitGroup_ExtraLimit_MaxCount[i]); |
| 790 | |
| 791 | for (auto& limit : limits) |
| 792 | { |
| 793 | if (i < pItemExt->BuildLimitGroup_ExtraLimit_Nums.size() && pItemExt->BuildLimitGroup_ExtraLimit_Nums[i] > 0) |
| 794 | { |
| 795 | limit += count * pItemExt->BuildLimitGroup_ExtraLimit_Nums[i]; |
| 796 | |
| 797 | if (pItemExt->BuildLimitGroup_ExtraLimit_MaxNum > 0) |
| 798 | limit = Math::min(limit, pItemExt->BuildLimitGroup_ExtraLimit_MaxNum); |
| 799 | } |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | if (pItemExt->BuildLimitGroup_ContentIfAnyMatch.Get()) |
| 805 | { |
| 806 | bool reachedLimit = false; |
| 807 | |
| 808 | for (size_t i = 0; i < std::min(pItemExt->BuildLimitGroup_Types.size(), pItemExt->BuildLimitGroup_Nums.size()); i++) |
| 809 | { |
| 810 | TechnoTypeClass* pType = pItemExt->BuildLimitGroup_Types[i]; |
| 811 | const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pType); |
| 812 | const auto pBuildingType = abstract_cast<BuildingTypeClass*>(pType); |
| 813 | int ownedNow = 0; |
| 814 | |
| 815 | if (pBuildingType && (BuildingTypeExt::ExtMap.Find(pBuildingType)->PowersUp_Buildings.size() > 0 || BuildingTypeClass::Find(pBuildingType->PowersUpBuilding))) |
| 816 | ownedNow = BuildingTypeExt::GetUpgradesAmount(pBuildingType, const_cast<HouseClass*>(pThis)); |
| 817 | else |
| 818 | ownedNow = CountOwnedIncludeDeploy(pThis, pType); |
| 819 | |
| 820 | ownedNow *= pTypeExt->BuildLimitGroup_Factor; |
| 821 | |
| 822 | if (ownedNow >= limits[i] + 1 - pItemExt->BuildLimitGroup_Factor) |
| 823 | reachedLimit |= (includeQueued && FactoryClass::FindByOwnerAndProduct(pThis, pType)) ? false : true; |
nothing calls this directly
no test coverage detected