Hooks
static bool BeforeCvGameReligions_DoPlayerTurn(CvGameReligions* self, CvPlayer& kPlayer);static void AfterCvGameReligions_DoPlayerTurn(CvGameReligions* self, CvPlayer& kPlayer);static void ReplaceCvGameReligions_DoPlayerTurn(void (*original)(CvGameReligions*, CvPlayer&), CvGameReligions* self, CvPlayer& kPlayer);CivRegisterBefore<CivHooks::CvGameReligions_DoPlayerTurn>(host, &BeforeCvGameReligions_DoPlayerTurn);CivRegisterAfter<CivHooks::CvGameReligions_DoPlayerTurn>(host, &AfterCvGameReligions_DoPlayerTurn);CivRegisterReplace<CivHooks::CvGameReligions_DoPlayerTurn>(host, &ReplaceCvGameReligions_DoPlayerTurn);
Code
398/// Religious activities at the start of a player's turn399void CvGameReligions::DoPlayerTurn(CvPlayer& kPlayer)400{401 AI_PERF_FORMAT("AI-perf.csv", ("CvGameReligions::DoPlayerTurn, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), kPlayer.getCivilizationShortDescription()) );402#if defined(MOD_RELIGION_RECURRING_PURCHASE_NOTIFIY)403 int iFaithAtStart = kPlayer.GetFaith();404#else405 bool bCouldAtStartAffordFaithPurchase = kPlayer.GetReligions()->CanAffordFaithPurchase();406#endif407 const PlayerTypes ePlayer = kPlayer.GetID();408409 int iFaithPerTurn = kPlayer.GetTotalFaithPerTurn();410 if(iFaithPerTurn > 0)411 {412 kPlayer.ChangeFaith(iFaithPerTurn);413 }414415 // If just now can afford missionary, add a notification416#if defined(MOD_RELIGION_RECURRING_PURCHASE_NOTIFIY)417 bool bSendFaithPurchaseNotification = (kPlayer.GetFaithPurchaseType() == NO_AUTOMATIC_FAITH_PURCHASE);418419 if (bSendFaithPurchaseNotification) {420 if (MOD_RELIGION_RECURRING_PURCHASE_NOTIFIY) {421 bSendFaithPurchaseNotification = kPlayer.GetReligions()->CanAffordNextPurchase();422 } else {423 bool bCouldAtStartAffordFaithPurchase = kPlayer.GetReligions()->CanAffordFaithPurchase(iFaithAtStart);424 bool bCanNowAffordFaithPurchase = kPlayer.GetReligions()->CanAffordFaithPurchase(kPlayer.GetFaith());425426 bSendFaithPurchaseNotification = !bCouldAtStartAffordFaithPurchase && bCanNowAffordFaithPurchase;427 }428 }429430 if (bSendFaithPurchaseNotification)431#else432 bool bCanNowAffordFaithPurchase = kPlayer.GetReligions()->CanAffordFaithPurchase();433 if (kPlayer.GetFaithPurchaseType() == NO_AUTOMATIC_FAITH_PURCHASE && !bCouldAtStartAffordFaithPurchase && bCanNowAffordFaithPurchase)434#endif435 {436 CvNotifications* pNotifications = kPlayer.GetNotifications();437 if(pNotifications)438 {439 CvString strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_ENOUGH_FAITH_FOR_MISSIONARY");440 CvString strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_ENOUGH_FAITH_FOR_MISSIONARY");441 pNotifications->Add(NOTIFICATION_CAN_BUILD_MISSIONARY, strBuffer, strSummary, -1, -1, -1);442443#if defined(MOD_RELIGION_RECURRING_PURCHASE_NOTIFIY)444 kPlayer.GetReligions()->SetFaithAtLastNotify(kPlayer.GetFaith());445#endif446 }447 }448449 // Check for pantheon or great prophet spawning (now restricted so must occur before Industrial era)450#if defined(MOD_CONFIG_GAME_IN_XML)451 if(kPlayer.GetFaith() > 0 && !kPlayer.isMinorCiv() && kPlayer.GetCurrentEra() <= GD_INT_GET(RELIGION_LAST_FOUND_ERA))452#else453 if(kPlayer.GetFaith() > 0 && !kPlayer.isMinorCiv() && kPlayer.GetCurrentEra() < GC.getInfoTypeForString("ERA_INDUSTRIAL"))454#endif455 {456 if(CanCreatePantheon(kPlayer.GetID(), true) == FOUNDING_OK)457 {458 // Create the pantheon459 if(kPlayer.isHuman())460 {461 //If the player is human then a net message will be received which will pick the pantheon.462 CvNotifications* pNotifications = kPlayer.GetNotifications();463 if(pNotifications)464 {465 CvString strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_ENOUGH_FAITH_FOR_PANTHEON");466467 CvString strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_ENOUGH_FAITH_FOR_PANTHEON");468 pNotifications->Add(NOTIFICATION_FOUND_PANTHEON, strBuffer, strSummary, -1, -1, -1);469 }470 }471 else472 {473#if defined(MOD_EVENTS_ACQUIRE_BELIEFS)474 const BeliefTypes eBelief = kPlayer.GetReligionAI()->ChoosePantheonBelief(ePlayer);475#else476 const BeliefTypes eBelief = kPlayer.GetReligionAI()->ChoosePantheonBelief();477#endif478479 FoundPantheon(ePlayer, eBelief);480 }481 }482483 switch (kPlayer.GetFaithPurchaseType())484 {485 case NO_AUTOMATIC_FAITH_PURCHASE:486 case FAITH_PURCHASE_SAVE_PROPHET:487 CheckSpawnGreatProphet(kPlayer);488 break;489 }490 }491492 // Pick a Reformation belief?493 ReligionTypes eReligionCreated = GetReligionCreatedByPlayer(ePlayer);494 if (eReligionCreated > RELIGION_PANTHEON && !HasAddedReformationBelief(ePlayer) && kPlayer.GetPlayerPolicies()->HasPolicyGrantingReformationBelief())495 {496 if (!kPlayer.isHuman())497 {498#if defined(MOD_EVENTS_ACQUIRE_BELIEFS)499 BeliefTypes eReformationBelief = kPlayer.GetReligionAI()->ChooseReformationBelief(ePlayer, eReligionCreated);500#else501 BeliefTypes eReformationBelief = kPlayer.GetReligionAI()->ChooseReformationBelief();502#endif503 AddReformationBelief(ePlayer, eReligionCreated, eReformationBelief);504 }505 else506 {507 CvNotifications* pNotifications;508 pNotifications = kPlayer.GetNotifications();509 if(pNotifications)510 {511 CvString strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_ADD_REFORMATION_BELIEF");512 CvString strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_ADD_REFORMATION_BELIEF");513 pNotifications->Add(NOTIFICATION_ADD_REFORMATION_BELIEF, strBuffer, strSummary, -1, -1, -1);514 }515 }516 }517518 // Automatic faith purchases?519 bool bSelectionStillValid = true;520 CvString szItemName = "";521 ReligionTypes eReligion = kPlayer.GetReligionAI()->GetReligionToSpread();522523 switch (kPlayer.GetFaithPurchaseType())524 {525 case FAITH_PURCHASE_SAVE_PROPHET:526 if (eReligion <= RELIGION_PANTHEON && GetNumReligionsStillToFound() <= 0)527 {528#if defined(MOD_BUGFIX_UNITCLASS_NOT_UNIT)529 UnitTypes eProphetType = kPlayer.GetSpecificUnitType("UNITCLASS_PROPHET", true);530 szItemName = GetLocalizedText("TXT_KEY_RO_AUTO_FAITH_PROPHET_PARAM", GC.getUnitInfo(eProphetType)->GetDescription());531#else532 szItemName = GetLocalizedText("TXT_KEY_RO_AUTO_FAITH_PROPHET");533#endif534 bSelectionStillValid = false;535 }536#if defined(MOD_CONFIG_GAME_IN_XML)537 else if (kPlayer.GetCurrentEra() > GD_INT_GET(RELIGION_LAST_FOUND_ERA))538#else539 else if (kPlayer.GetCurrentEra() >= GC.getInfoTypeForString("ERA_INDUSTRIAL"))540#endif541 {542#if defined(MOD_BUGFIX_UNITCLASS_NOT_UNIT)543 UnitTypes eProphetType = kPlayer.GetSpecificUnitType("UNITCLASS_PROPHET", true);544 szItemName = GetLocalizedText("TXT_KEY_RO_AUTO_FAITH_PROPHET_PARAM", GC.getUnitInfo(eProphetType)->GetDescription());545#else546 szItemName = GetLocalizedText("TXT_KEY_RO_AUTO_FAITH_PROPHET");547#endif548 bSelectionStillValid = false;549 }550 break;551552 case FAITH_PURCHASE_UNIT:553 {554 UnitTypes eUnit = (UnitTypes)kPlayer.GetFaithPurchaseIndex();555 CvUnitEntry *pkUnit = GC.getUnitInfo(eUnit);556 if (pkUnit)557 {558 szItemName = pkUnit->GetDescriptionKey();559 }560561 if (!kPlayer.IsCanPurchaseAnyCity(false, false /* Don't worry about faith balance */, eUnit, NO_BUILDING, YIELD_FAITH))562 {563 bSelectionStillValid = false;564 }565 else566 {567 if (kPlayer.IsCanPurchaseAnyCity(true, true /* Check faith balance */, eUnit, NO_BUILDING, YIELD_FAITH))568 {569 CvCity *pCity = CvReligionAIHelpers::GetBestCityFaithUnitPurchase(kPlayer, eUnit, eReligion);570 if (pCity)571 {572 pCity->Purchase(eUnit, NO_BUILDING, NO_PROJECT, YIELD_FAITH);573574 CvNotifications* pNotifications = kPlayer.GetNotifications();575 if(pNotifications)576 {577 CvString strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_AUTOMATIC_FAITH_PURCHASE", szItemName, pCity->getNameKey());578 CvString strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_AUTOMATIC_FAITH_PURCHASE");579 pNotifications->Add(NOTIFICATION_CAN_BUILD_MISSIONARY, strBuffer, strSummary, pCity->getX(), pCity->getY(), -1);580 }581 }582 else583 {584 bSelectionStillValid = false;585 }586 }587 }588 }589 break;590 case FAITH_PURCHASE_BUILDING:591 {592 BuildingTypes eBuilding = (BuildingTypes)kPlayer.GetFaithPurchaseIndex();593 CvBuildingEntry *pkBuilding = GC.getBuildingInfo(eBuilding);594 if (pkBuilding)595 {596 szItemName = pkBuilding->GetDescriptionKey();597 }598599 if (!kPlayer.IsCanPurchaseAnyCity(false, false, NO_UNIT, eBuilding, YIELD_FAITH))600 {601 bSelectionStillValid = false;602 }603 else604 {605 if (kPlayer.IsCanPurchaseAnyCity(true, true /* Check faith balance */, NO_UNIT, eBuilding, YIELD_FAITH))606 {607 CvCity *pCity = CvReligionAIHelpers::GetBestCityFaithBuildingPurchase(kPlayer, eBuilding, eReligion);608 if (pCity)609 {610 pCity->Purchase(NO_UNIT, eBuilding, NO_PROJECT, YIELD_FAITH);611612 CvNotifications* pNotifications = kPlayer.GetNotifications();613 if(pNotifications)614 {615 CvString strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_AUTOMATIC_FAITH_PURCHASE", szItemName, pCity->getNameKey());616 CvString strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_AUTOMATIC_FAITH_PURCHASE");617 pNotifications->Add(NOTIFICATION_CAN_BUILD_MISSIONARY, strBuffer, strSummary, -1, -1, -1);618 }619 }620 else621 {622 bSelectionStillValid = false;623 }624 }625 }626 }627 break;628 }629630 if (!bSelectionStillValid)631 {632 CvNotifications* pNotifications = kPlayer.GetNotifications();633 if(pNotifications)634 {635 CvString strBuffer = GetLocalizedText("TXT_KEY_NOTIFICATION_NEED_NEW_AUTOMATIC_FAITH_SELECTION", szItemName);636 CvString strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SUMMARY_NEED_NEW_AUTOMATIC_FAITH_SELECTION");637 pNotifications->Add(NOTIFICATION_AUTOMATIC_FAITH_PURCHASE_STOPPED, strBuffer, strSummary, -1, -1, -1);638 }639640 gDLL->SendFaithPurchase(kPlayer.GetID(), NO_AUTOMATIC_FAITH_PURCHASE, 0);641 }642}