Hooks
static bool BeforeCvGameReligions_GetReligionToFound(CvGameReligions* self, PlayerTypes ePlayer, ReligionTypes& result);static void AfterCvGameReligions_GetReligionToFound(CvGameReligions* self, PlayerTypes ePlayer, ReligionTypes& result);static ReligionTypes ReplaceCvGameReligions_GetReligionToFound(ReligionTypes (*original)(CvGameReligions*, PlayerTypes), CvGameReligions* self, PlayerTypes ePlayer);CivRegisterBefore<CivHooks::CvGameReligions_GetReligionToFound>(host, &BeforeCvGameReligions_GetReligionToFound);CivRegisterAfter<CivHooks::CvGameReligions_GetReligionToFound>(host, &AfterCvGameReligions_GetReligionToFound);CivRegisterReplace<CivHooks::CvGameReligions_GetReligionToFound>(host, &ReplaceCvGameReligions_GetReligionToFound);
Code
719/// Get the appropriate religion for this player to found next720ReligionTypes CvGameReligions::GetReligionToFound(PlayerTypes ePlayer)721{722#if defined(MOD_RELIGION_NO_PREFERRENCES)723 if (!MOD_RELIGION_NO_PREFERRENCES) {724 // Choose the civs preferred religion if not disabled and available725#endif726 ReligionTypes eCivReligion;727 eCivReligion = GET_PLAYER(ePlayer).getCivilizationInfo().GetReligion();728 729#if defined(MOD_EVENTS_FOUND_RELIGION)730 if (MOD_EVENTS_FOUND_RELIGION) {731 int iValue = 0;732 if (GAMEEVENTINVOKE_VALUE(iValue, GAMEEVENT_GetReligionToFound, ePlayer, eCivReligion, HasBeenFounded(eCivReligion)) == GAMEEVENTRETURN_VALUE) {733 // Defend against modder stupidity!734 if (iValue > RELIGION_PANTHEON && iValue < GC.getNumReligionInfos()) {735 // CUSTOMLOG("GetReligionToFound: Before=%i, After=%i", eCivReligion, iValue);736 eCivReligion = (ReligionTypes)iValue;737 }738 }739 } else {740#endif741 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();742 if(pkScriptSystem) 743 {744 CvLuaArgsHandle args;745 args->Push(ePlayer);746 args->Push(eCivReligion);747 args->Push(HasBeenFounded(eCivReligion));748749 int iValue = 0;750 if (LuaSupport::CallAccumulator(pkScriptSystem, "GetReligionToFound", args.get(), iValue)) 751 {752 if (iValue >= 0 && iValue < GC.getNumReligionInfos() && iValue != RELIGION_PANTHEON)753 {754 eCivReligion = (ReligionTypes)iValue;755 }756 }757 }758#if defined(MOD_EVENTS_FOUND_RELIGION)759 }760#endif761762 if(!HasBeenFounded(eCivReligion))763 {764 CvReligionEntry* pEntry = GC.getReligionInfo(eCivReligion);765 if(pEntry)766 {767 // CUSTOMLOG("GetReligionToFound: Using preferred %i", eCivReligion);768 return eCivReligion;769 }770 }771#if defined(MOD_RELIGION_NO_PREFERRENCES)772 }773#endif774775#if defined(MOD_RELIGION_RANDOMISE)776 // No preferred religion, so find all the possible religions777 std::vector<ReligionTypes> availableReligions;778#endif779 780 // Need to "borrow" from another civ. Loop through all religions looking for one that is eligible781 for(int iI = 0; iI < GC.getNumReligionInfos(); iI++)782 {783 ReligionTypes eReligion = (ReligionTypes)iI;784 CvReligionEntry* pEntry = GC.getReligionInfo(eReligion);785 if(!pEntry)786 {787 continue;788 }789790 if(pEntry->GetID() == RELIGION_PANTHEON)791 {792 continue;793 }794 795#if defined(MOD_RELIGION_LOCAL_RELIGIONS)796 if (MOD_RELIGION_LOCAL_RELIGIONS && pEntry->IsLocalReligion()) {797 continue;798 }799#endif800801 if(HasBeenFounded((ReligionTypes)pEntry->GetID()))802 {803 continue;804 }805806#if defined(MOD_RELIGION_NO_PREFERRENCES)807 // Only excluded religions preferred by other civs if not disabled808 if (!MOD_RELIGION_NO_PREFERRENCES) {809#endif810 if(IsPreferredByCivInGame(eReligion))811 {812 continue;813 }814#if defined(MOD_RELIGION_NO_PREFERRENCES)815 }816#endif817818#if defined(MOD_RELIGION_RANDOMISE)819 if (MOD_RELIGION_RANDOMISE) {820 // If we want a random religion, remember this as a possible candidate ...821 availableReligions.push_back(eReligion);822 } else {823 // ... otherwise just return it824#endif825 // CUSTOMLOG("GetReligionToFound: Using spare %i", eReligion);826 return (eReligion);827#if defined(MOD_RELIGION_RANDOMISE)828 }829#endif830 }831832#if defined(MOD_RELIGION_RANDOMISE)833 if (availableReligions.empty()) {834#endif835836 // Will have to use a religion that someone else prefers837 for(int iI = 0; iI < GC.getNumReligionInfos(); iI++)838 {839 ReligionTypes eReligion = (ReligionTypes)iI;840 CvReligionEntry* pEntry = GC.getReligionInfo(eReligion);841 if(!pEntry)842 {843 continue;844 }845846 if(pEntry->GetID() == RELIGION_PANTHEON)847 {848 continue;849 }850851#if defined(MOD_RELIGION_LOCAL_RELIGIONS)852 if (MOD_RELIGION_LOCAL_RELIGIONS && pEntry->IsLocalReligion()) {853 continue;854 }855#endif856857 if(HasBeenFounded((ReligionTypes)pEntry->GetID()))858 {859 continue;860 }861862#if defined(MOD_RELIGION_RANDOMISE)863 if (MOD_RELIGION_RANDOMISE) {864 // If we want a random religion, remember this as a possible candidate ...865 availableReligions.push_back(eReligion);866 } else {867 // ... otherwise just return it868#endif869 // CUSTOMLOG("GetReligionToFound: Using borrowed %i", eReligion);870 return (eReligion);871#if defined(MOD_RELIGION_RANDOMISE)872 }873#endif874 }875876#if defined(MOD_RELIGION_RANDOMISE)877 }878#endif879880#if defined(MOD_RELIGION_RANDOMISE)881 // Pick a random religion882 if (!availableReligions.empty()) {883 int index = 0;884 885 // Pick a random one if required886 if (MOD_RELIGION_RANDOMISE) {887 index = GC.getGame().getJonRandNum(availableReligions.size(), "Random Religion To Found");888 }889 890 // CUSTOMLOG("GetReligionToFound: Using random %i", availableReligions[index]);891 return availableReligions[index];892 }893#endif894895 // CUSTOMLOG("GetReligionToFound: Using NO_RELIGION");896 return NO_RELIGION;897}