/// What's the total Happiness benefit we could get from all policies/tenets in the branch based on our current buildings? int CvPolicyAI::GetBranchBuildingHappiness(CvPlayer* pPlayer, PolicyBranchTypes eBranch) { // Policy Building Mods int iSpecialPolicyBuildingHappiness = 0; int iBuildingClassLoop; BuildingClassTypes eBuildingClass; for(int iPolicyLoop = 0; iPolicyLoop < GC.getNumPolicyInfos(); iPolicyLoop++) { PolicyTypes ePolicy = (PolicyTypes)iPolicyLoop; CvPolicyEntry* pkPolicyInfo = GC.getPolicyInfo(ePolicy); if(pkPolicyInfo) { if (pkPolicyInfo->GetPolicyBranchType() == eBranch) { for(iBuildingClassLoop = 0; iBuildingClassLoop < GC.getNumBuildingClassInfos(); iBuildingClassLoop++) { eBuildingClass = (BuildingClassTypes) iBuildingClassLoop; CvBuildingClassInfo* pkBuildingClassInfo = GC.getBuildingClassInfo(eBuildingClass); if (!pkBuildingClassInfo) { continue; } if (pkPolicyInfo->GetBuildingClassHappiness(eBuildingClass) != 0) { BuildingTypes eBuilding = (BuildingTypes)pPlayer->getCivilizationInfo().getCivilizationBuildings(eBuildingClass); if (eBuilding != NO_BUILDING) { CvCity *pCity; int iLoop; for (pCity = pPlayer->firstCity(&iLoop); pCity != NULL; pCity = pPlayer->nextCity(&iLoop)) { if (pCity->GetCityBuildings()->GetNumBuilding(eBuilding) > 0) { iSpecialPolicyBuildingHappiness += pkPolicyInfo->GetBuildingClassHappiness(eBuildingClass); } } } } } } } } return iSpecialPolicyBuildingHappiness; }
/// How many policies in this branch help happiness? int CvPolicyAI::GetNumHappinessPolicies(CvPlayer* pPlayer, PolicyBranchTypes eBranch) { int iRtnValue = 0; int iBuildingClassLoop; BuildingClassTypes eBuildingClass; for(int iPolicyLoop = 0; iPolicyLoop < GC.getNumPolicyInfos(); iPolicyLoop++) { PolicyTypes ePolicy = (PolicyTypes)iPolicyLoop; CvPolicyEntry* pkPolicyInfo = GC.getPolicyInfo(ePolicy); if(pkPolicyInfo) { if (pkPolicyInfo->GetPolicyBranchType() == eBranch) { for(iBuildingClassLoop = 0; iBuildingClassLoop < GC.getNumBuildingClassInfos(); iBuildingClassLoop++) { eBuildingClass = (BuildingClassTypes) iBuildingClassLoop; CvBuildingClassInfo* pkBuildingClassInfo = GC.getBuildingClassInfo(eBuildingClass); if (!pkBuildingClassInfo) { continue; } BuildingTypes eBuilding = (BuildingTypes)pPlayer->getCivilizationInfo().getCivilizationBuildings(eBuildingClass); if (eBuilding != NO_BUILDING) { // Don't count a building that can only be built in conquered cities CvBuildingEntry *pkEntry = GC.getBuildingInfo(eBuilding); if (!pkEntry || pkEntry->IsNoOccupiedUnhappiness()) { continue; } if (pkPolicyInfo->GetBuildingClassHappiness(eBuildingClass) != 0) { iRtnValue++; break; } } } } } } return iRtnValue; }