CvPlayerPolicies::CanUnlockPolicyBranch(PolicyBranchTypes)
- Defined in
- CvPolicyClasses.cpp, line 3711
- Class
- CvPlayerPolicies
- Hook name
CivHooks::CvPlayerPolicies_CanUnlockPolicyBranch- Lua events
GameEvents.PlayerCanAdoptPolicyBranch
Hooks
static bool BeforeCvPlayerPolicies_CanUnlockPolicyBranch(CvPlayerPolicies* self, PolicyBranchTypes eBranchType, bool& result);static void AfterCvPlayerPolicies_CanUnlockPolicyBranch(CvPlayerPolicies* self, PolicyBranchTypes eBranchType, bool& result);static bool ReplaceCvPlayerPolicies_CanUnlockPolicyBranch(bool (*original)(CvPlayerPolicies*, PolicyBranchTypes), CvPlayerPolicies* self, PolicyBranchTypes eBranchType);CivRegisterBefore<CivHooks::CvPlayerPolicies_CanUnlockPolicyBranch>(host, &BeforeCvPlayerPolicies_CanUnlockPolicyBranch);CivRegisterAfter<CivHooks::CvPlayerPolicies_CanUnlockPolicyBranch>(host, &AfterCvPlayerPolicies_CanUnlockPolicyBranch);CivRegisterReplace<CivHooks::CvPlayerPolicies_CanUnlockPolicyBranch>(host, &ReplaceCvPlayerPolicies_CanUnlockPolicyBranch);
Code
3710/// can the player unlock eBranchType right now?3711bool CvPlayerPolicies::CanUnlockPolicyBranch(PolicyBranchTypes eBranchType)3712{3713 // Must have enough culture to spend a buy opening a new branch3714 if(GetPlayer()->getJONSCulture() < GetPlayer()->getNextPolicyCost())3715 {3716 if(GetPlayer()->GetNumFreePolicies() == 0)3717 return false;3718 }37193720 CvPolicyBranchEntry* pkBranchEntry = m_pPolicies->GetPolicyBranchEntry(eBranchType);3721 if(pkBranchEntry)3722 {3723 // Ideology branches unlocked through a direct call to SetPolicyBranchUnlocked()3724 if (pkBranchEntry->IsPurchaseByLevel())3725 {3726 return false;3727 }37283729 if (pkBranchEntry->IsLockedWithoutReligion())3730 {3731 if (GC.getGame().isOption(GAMEOPTION_NO_RELIGION))3732 {3733 return false;3734 }3735 }37363737 EraTypes ePrereqEra = (EraTypes) pkBranchEntry->GetEraPrereq();37383739 // Must be in the proper Era3740 if(ePrereqEra != NO_ERA)3741 {3742 if(GET_TEAM(GetPlayer()->getTeam()).GetCurrentEra() < ePrereqEra)3743 {3744 return false;3745 }3746 }3747 }37483749 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();3750 if(pkScriptSystem)3751 {3752 CvLuaArgsHandle args;3753 args->Push(m_pPlayer->GetID());3754 args->Push(eBranchType);37553756 // Attempt to execute the game events.3757 // Will return false if there are no registered listeners.3758 bool bResult = false;3759 if(LuaSupport::CallTestAll(pkScriptSystem, "PlayerCanAdoptPolicyBranch", args.get(), bResult))3760 {3761 // Check the result.3762 if(bResult == false)3763 {3764 return false;3765 }3766 }3767 }37683769 return true;3770}
Calls
- CvGame::isOption(GameOptionTypes) const
- CvGlobals::getDLLIFace()
- CvGlobals::getGame()
- CvLuaArgsHandle::CvLuaArgsHandle()
- CvLuaArgsHandle::get() const
- CvLuaArgsHandle::operator->() const
- CvPlayer::GetID() const
- CvPlayer::getJONSCulture() const
- CvPlayer::getNextPolicyCost() const
- CvPlayer::GetNumFreePolicies() const
- CvPlayer::getTeam() const
- CvPlayerPolicies::GetPlayer()
- CvPolicyBranchEntry::GetEraPrereq() const
- CvPolicyBranchEntry::IsLockedWithoutReligion() const
- CvPolicyBranchEntry::IsPurchaseByLevel() const
- CvPolicyXMLEntries::GetPolicyBranchEntry(int)
- CvTeam::GetCurrentEra() const
- CvTeam::getTeam(TeamTypes)
ICvEngineScriptSystemArgs1::PushICvEngineUtility1::GetScriptSystem- LuaSupport::CallTestAll(ICvEngineScriptSystem1 *, const char *, ICvEngineScriptSystemArgs1 *, bool &)