CvCityReligions::RecomputeFollowers(CvReligiousFollowChangeReason, ReligionTypes, PlayerTypes)
- Defined in
- CvReligionClasses.cpp, line 4403
- Class
- CvCityReligions
- Hook name
CivHooks::CvCityReligions_RecomputeFollowers
Hooks
static bool BeforeCvCityReligions_RecomputeFollowers(CvCityReligions* self, CvReligiousFollowChangeReason eReason, ReligionTypes eOldMajorityReligion, PlayerTypes eResponsibleParty);static void AfterCvCityReligions_RecomputeFollowers(CvCityReligions* self, CvReligiousFollowChangeReason eReason, ReligionTypes eOldMajorityReligion, PlayerTypes eResponsibleParty);static void ReplaceCvCityReligions_RecomputeFollowers(void (*original)(CvCityReligions*, CvReligiousFollowChangeReason, ReligionTypes, PlayerTypes), CvCityReligions* self, CvReligiousFollowChangeReason eReason, ReligionTypes eOldMajorityReligion, PlayerTypes eResponsibleParty);CivRegisterBefore<CivHooks::CvCityReligions_RecomputeFollowers>(host, &BeforeCvCityReligions_RecomputeFollowers);CivRegisterAfter<CivHooks::CvCityReligions_RecomputeFollowers>(host, &AfterCvCityReligions_RecomputeFollowers);CivRegisterReplace<CivHooks::CvCityReligions_RecomputeFollowers>(host, &ReplaceCvCityReligions_RecomputeFollowers);
Code
4402/// Calculate the number of followers for each religion4403void CvCityReligions::RecomputeFollowers(CvReligiousFollowChangeReason eReason, ReligionTypes eOldMajorityReligion, PlayerTypes eResponsibleParty)4404{4405 int iOldFollowers = GetNumFollowers(eOldMajorityReligion);4406 int iUnassignedFollowers = m_pCity->getPopulation();4407 int iPressurePerFollower;44084409 // Safety check to avoid divide by zero4410 if (iUnassignedFollowers < 1)4411 {4412 CvAssertMsg (false, "Invalid city population when recomputing followers");4413 return;4414 }44154416 // Find total pressure4417 int iTotalPressure = 0;4418 ReligionInCityList::iterator it;4419 for(it = m_ReligionStatus.begin(); it != m_ReligionStatus.end(); it++)4420 {4421 iTotalPressure += it->m_iPressure;4422 }44234424 // safety check - if pressure was wiped out somehow, just rebuild pressure of 1 atheist4425 if (iTotalPressure <= 0)4426 {4427 m_ReligionStatus.clear();44284429 CvReligionInCity religion;4430 religion.m_bFoundedHere = false;4431 religion.m_eReligion = NO_RELIGION;4432 religion.m_iFollowers = 1;4433 religion.m_iPressure = GC.getRELIGION_ATHEISM_PRESSURE_PER_POP();4434 m_ReligionStatus.push_back(religion);44354436 iTotalPressure = GC.getRELIGION_ATHEISM_PRESSURE_PER_POP();4437 }44384439 iPressurePerFollower = iTotalPressure / iUnassignedFollowers;44404441 // Loop through each religion4442 for(it = m_ReligionStatus.begin(); it != m_ReligionStatus.end(); it++)4443 {4444 it->m_iFollowers = it->m_iPressure / iPressurePerFollower;4445 iUnassignedFollowers -= it->m_iFollowers;4446 it->m_iTemp = it->m_iPressure - (it->m_iFollowers * iPressurePerFollower); // Remainder4447 }44484449 // Assign out the remainder4450 for (int iI = 0; iI < iUnassignedFollowers; iI++)4451 {4452 ReligionInCityList::iterator itLargestRemainder = NULL;4453 int iLargestRemainder = 0;44544455 for (it = m_ReligionStatus.begin(); it != m_ReligionStatus.end(); it++)4456 {4457 if (it->m_iTemp > iLargestRemainder)4458 {4459 iLargestRemainder = it->m_iTemp;4460 itLargestRemainder = it;4461 }4462 }44634464 if (itLargestRemainder && iLargestRemainder > 0)4465 {4466 itLargestRemainder->m_iFollowers++;4467 itLargestRemainder->m_iTemp = 0;4468 }4469 }44704471 ReligionTypes eMajority = GetReligiousMajority();4472 int iFollowers = GetNumFollowers(eMajority);44734474 if(eMajority != eOldMajorityReligion || iFollowers != iOldFollowers)4475 {4476 CityConvertsReligion(eMajority, eOldMajorityReligion, eResponsibleParty);4477 GC.GetEngineUserInterface()->setDirty(CityInfo_DIRTY_BIT, true);4478 LogFollowersChange(eReason);4479 }4480}
Calls
BaseVector::beginBaseVector::clearBaseVector::end- CvCity::getPopulation(bool) const
- CvCityReligions::CityConvertsReligion(ReligionTypes, ReligionTypes, PlayerTypes)
- CvCityReligions::GetNumFollowers(ReligionTypes)
- CvCityReligions::GetReligiousMajority()
- CvCityReligions::LogFollowersChange(CvReligiousFollowChangeReason)
- CvGlobals::GetEngineUserInterface()
- CvGlobals::getRELIGION_ATHEISM_PRESSURE_PER_POP()
- CvReligionInCity::CvReligionInCity()
FStaticVector::push_backICvUserInterface1::setDirty
Called by
- CvCityReligions::AddHolyCityPressure()
- CvCityReligions::AddProphetSpread(ReligionTypes, int, PlayerTypes)
- CvCityReligions::AddReligiousPressure(CvReligiousFollowChangeReason, ReligionTypes, int, PlayerTypes)
- CvCityReligions::AddSpyPressure(ReligionTypes, int)
- CvCityReligions::AdoptReligionFully(ReligionTypes)
- CvCityReligions::DoPopulationChange(int)
- CvCityReligions::DoReligionFounded(ReligionTypes)
- CvCityReligions::RemoveFormerPantheon()
- CvCityReligions::RemoveOtherReligions(ReligionTypes, PlayerTypes)