Hooks
static bool BeforeCvPlayerPolicies_SetPolicyBranchUnlocked(CvPlayerPolicies* self, PolicyBranchTypes eBranchType, bool bNewValue, bool bRevolution);static void AfterCvPlayerPolicies_SetPolicyBranchUnlocked(CvPlayerPolicies* self, PolicyBranchTypes eBranchType, bool bNewValue, bool bRevolution);static void ReplaceCvPlayerPolicies_SetPolicyBranchUnlocked(void (*original)(CvPlayerPolicies*, PolicyBranchTypes, bool, bool), CvPlayerPolicies* self, PolicyBranchTypes eBranchType, bool bNewValue, bool bRevolution);CivRegisterBefore<CivHooks::CvPlayerPolicies_SetPolicyBranchUnlocked>(host, &BeforeCvPlayerPolicies_SetPolicyBranchUnlocked);CivRegisterAfter<CivHooks::CvPlayerPolicies_SetPolicyBranchUnlocked>(host, &AfterCvPlayerPolicies_SetPolicyBranchUnlocked);CivRegisterReplace<CivHooks::CvPlayerPolicies_SetPolicyBranchUnlocked>(host, &ReplaceCvPlayerPolicies_SetPolicyBranchUnlocked);
Code
3790/// Accessor: sets that a player has (or hasn't) unlocked eBranchType to pick Policies from3791void CvPlayerPolicies::SetPolicyBranchUnlocked(PolicyBranchTypes eBranchType, bool bNewValue, bool bRevolution)3792{3793 CvAssertMsg(eBranchType >= 0, "eIndex is expected to be non-negative (invalid Index)");3794 CvAssertMsg(eBranchType < m_pPolicies->GetNumPolicyBranches(), "eIndex is expected to be within maximum bounds (invalid Index)");37953796 if(IsPolicyBranchUnlocked(eBranchType) != bNewValue)3797 {3798 // Unlocked?3799 if (bNewValue)3800 {3801 int iFreePolicies = PolicyHelpers::GetNumFreePolicies(eBranchType);38023803 // Late-game tree so want to issue notification?3804 CvPolicyBranchEntry* pkPolicyBranchInfo = GC.getPolicyBranchInfo(eBranchType);3805 if(pkPolicyBranchInfo != NULL)3806 {3807 if (pkPolicyBranchInfo->IsPurchaseByLevel())3808 {3809 m_pPlayer->ChangeNumFreeTenets(iFreePolicies, !bRevolution);38103811 for(int iNotifyLoop = 0; iNotifyLoop < MAX_MAJOR_CIVS; ++iNotifyLoop){3812 PlayerTypes eNotifyPlayer = (PlayerTypes) iNotifyLoop;3813 CvPlayerAI& kCurNotifyPlayer = GET_PLAYER(eNotifyPlayer);38143815 // Issue notification if OTHER than target player3816 if (m_pPlayer->GetID() != eNotifyPlayer)3817 {3818 CvTeam& kNotifyTeam = GET_TEAM(kCurNotifyPlayer.getTeam());3819 const bool bHasMet = kNotifyTeam.isHasMet(m_pPlayer->getTeam());38203821 CvNotifications* pNotifications = kCurNotifyPlayer.GetNotifications();3822 if(pNotifications)3823 {3824 CvString strBuffer;3825 if(bHasMet)3826 {3827 if (bRevolution)3828 strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_IDEOLOGY_CHANGE", m_pPlayer->getCivilizationShortDescriptionKey(), pkPolicyBranchInfo->GetDescriptionKey());3829 else3830 strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_IDEOLOGY_CHOSEN", m_pPlayer->getCivilizationShortDescriptionKey(), pkPolicyBranchInfo->GetDescriptionKey());3831 }3832 else3833 {3834 if (bRevolution)3835 strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_IDEOLOGY_CHANGE_UNMET", pkPolicyBranchInfo->GetDescriptionKey());3836 else3837 strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_IDEOLOGY_CHOSEN_UNMET", pkPolicyBranchInfo->GetDescriptionKey());3838 }38393840 CvString strSummary;3841 if (bRevolution)3842 strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_IDEOLOGY_CHANGE");3843 else3844 strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_IDEOLOGY_CHOSEN");38453846 pNotifications->Add(NOTIFICATION_IDEOLOGY_CHOSEN, strBuffer, strSummary, -1, -1, m_pPlayer->GetID());3847 }3848 }3849 }3850 }3851 else3852 {3853 m_pPlayer->ChangeNumFreePolicies(iFreePolicies);3854 }3855 }3856 }38573858 m_pabPolicyBranchUnlocked[eBranchType] = bNewValue;3859 }3860}