Hooks
static bool BeforeSetPlayerInitialItems(CvPlayer& kGameplayPlayer, const CvWorldBuilderMap::Player& kSavedPlayer);static void AfterSetPlayerInitialItems(CvPlayer& kGameplayPlayer, const CvWorldBuilderMap::Player& kSavedPlayer);static void ReplaceSetPlayerInitialItems(void (*original)(CvPlayer&, const CvWorldBuilderMap::Player&), CvPlayer& kGameplayPlayer, const CvWorldBuilderMap::Player& kSavedPlayer);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::SetPlayerInitialItems::ID, CIV_HOOK_BEFORE, (void*)&BeforeSetPlayerInitialItems);host->RegisterHook(host->pluginIndex, CivHooks::SetPlayerInitialItems::ID, CIV_HOOK_AFTER, (void*)&AfterSetPlayerInitialItems);host->RegisterHook(host->pluginIndex, CivHooks::SetPlayerInitialItems::ID, CIV_HOOK_REPLACE, (void*)&ReplaceSetPlayerInitialItems);
Code
440void SetPlayerInitialItems(CvPlayer& kGameplayPlayer, const CvWorldBuilderMap::Player& kSavedPlayer)441{442 CvTreasury* pkTreasury = kGameplayPlayer.GetTreasury();443 FAssertMsg(pkTreasury, "Unable to set gold amount. Treasury Missing!");444 if(pkTreasury != NULL)445 pkTreasury->SetGold(kSavedPlayer.m_uiGold);446447 kGameplayPlayer.setJONSCulture(kSavedPlayer.m_uiCulture);448449 const int iPolicyCount = GC.getNumPolicyInfos();450 for(int iPolicy = 0; iPolicy < iPolicyCount; ++iPolicy)451 {452 const PolicyTypes ePolicy = (PolicyTypes)iPolicy;453 if(kSavedPlayer.m_kPolicies[iPolicy])454 {455 // Check the policy branch456 CvPlayerPolicies* pkPlayerPolicies = kGameplayPlayer.GetPlayerPolicies();457 const CvPolicyEntry* pkPolicy = GC.getPolicyInfo(ePolicy);458 if(pkPolicy != NULL && pkPlayerPolicies != NULL)459 {460 PolicyBranchTypes ePolicyBranch = (PolicyBranchTypes)pkPolicy->GetPolicyBranchType();461462 // NO_POLICY_BRANCH_TYPE means that this is probably a free policy.463 // We'll have to look through the policy branches to find a matching one.464 if(ePolicyBranch == NO_POLICY_BRANCH_TYPE)465 {466 const int iPolicyBranchCount = GC.getNumPolicyBranchInfos();467 for(int iPolicyBranch = 0; iPolicyBranch < iPolicyBranchCount; ++iPolicyBranch)468 {469 const PolicyBranchTypes eCurrentBranch = (PolicyBranchTypes)iPolicyBranch;470 const CvPolicyBranchEntry* pkBranch = GC.getPolicyBranchInfo(eCurrentBranch);471 if(pkBranch != NULL && pkBranch->GetFreePolicy() == ePolicy)472 {473 ePolicyBranch = eCurrentBranch;474 break;475 }476 }477 }478479 // Unlock the policy branch if it hasn't been unlocked yet480 if(ePolicyBranch != NO_POLICY_BRANCH_TYPE &&481 !pkPlayerPolicies->IsPolicyBranchUnlocked(ePolicyBranch))482 {483 pkPlayerPolicies->SetPolicyBranchUnlocked(ePolicyBranch, true, false);484485 // Also, unlock the free policy for the branch486 const CvPolicyBranchEntry* pkBranch = GC.getPolicyBranchInfo(ePolicyBranch);487 if(pkBranch != NULL)488 {489 PolicyTypes eFreePolicy = (PolicyTypes)pkBranch->GetFreePolicy();490 if(eFreePolicy != NO_POLICY)491 kGameplayPlayer.setHasPolicy(eFreePolicy, true);492 }493 }494 }495496 // Finally, unlock the policy497 kGameplayPlayer.setHasPolicy(ePolicy, true);498 }499 }500501 const TeamTypes eTeam = kGameplayPlayer.getTeam();502 if(eTeam != NO_TEAM)503 {504 CvTeam& kTeam = GET_TEAM(eTeam);505506 int iStartingEra = 0;507 const int iEraCount = GC.getNumEraInfos();508 for(int iEra = 0; iEra < iEraCount; ++iEra)509 {510 const EraTypes eEra = (EraTypes)iEra;511 const CvEraInfo* pkEra = GC.getEraInfo(eEra);512 if(pkEra != NULL && strcmp(pkEra->GetType(), kSavedPlayer.m_szEra) == 0)513 {514 iStartingEra = iEra;515 break;516 }517 }518519 if(iStartingEra > 0)520 {521 const int iTechCount = GC.getNumTechInfos();522 for(int iTech = 0; iTech < iTechCount; ++iTech)523 {524 const TechTypes eTech = (TechTypes)iTech;525 const CvTechEntry* pkTech = GC.getTechInfo(eTech);526 if(pkTech != NULL && pkTech->GetEra() < iStartingEra)527 kTeam.setHasTech(eTech, true, kGameplayPlayer.GetID(), false, false);528 }529 }530 }531}