/// Priority for opening up this branch int CvPolicyAI::WeighBranch(PolicyBranchTypes eBranch) { int iWeight = 0; CvPolicyBranchEntry* pkPolicyBranchInfo = GC.getPolicyBranchInfo(eBranch); if(pkPolicyBranchInfo) { for(int iPolicyLoop = 0; iPolicyLoop < m_pCurrentPolicies->GetPolicies()->GetNumPolicies(); iPolicyLoop++) { const PolicyTypes ePolicyLoop = static_cast<PolicyTypes>(iPolicyLoop); CvPolicyEntry* pkLoopPolicyInfo = GC.getPolicyInfo(ePolicyLoop); if(pkLoopPolicyInfo) { // Policy we don't have? if(!m_pCurrentPolicies->HasPolicy(ePolicyLoop)) { // From this branch we are considering opening? if(pkLoopPolicyInfo->GetPolicyBranchType() == eBranch) { // With no prereqs? if(pkLoopPolicyInfo->GetPrereqAndPolicies(0) == NO_POLICY) { iWeight += m_PolicyAIWeights.GetWeight(iPolicyLoop); } } } } } // Add weight of free policy from branch iWeight += m_PolicyAIWeights.GetWeight(pkPolicyBranchInfo->GetFreePolicy()); } return iWeight; }
/// 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; }