CvCityReligions::SimulateFollowers()
- Defined in
- CvReligionClasses.cpp, line 4483
- Class
- CvCityReligions
- Hook name
CivHooks::CvCityReligions_SimulateFollowers
Hooks
static bool BeforeCvCityReligions_SimulateFollowers(CvCityReligions* self);static void AfterCvCityReligions_SimulateFollowers(CvCityReligions* self);static void ReplaceCvCityReligions_SimulateFollowers(void (*original)(CvCityReligions*), CvCityReligions* self);CivRegisterBefore<CivHooks::CvCityReligions_SimulateFollowers>(host, &BeforeCvCityReligions_SimulateFollowers);CivRegisterAfter<CivHooks::CvCityReligions_SimulateFollowers>(host, &AfterCvCityReligions_SimulateFollowers);CivRegisterReplace<CivHooks::CvCityReligions_SimulateFollowers>(host, &ReplaceCvCityReligions_SimulateFollowers);
Code
4482/// Calculate the number of followers for each religion from simulated data4483void CvCityReligions::SimulateFollowers()4484{4485 int iUnassignedFollowers = m_pCity->getPopulation();4486 int iPressurePerFollower;44874488 // Find total pressure4489 int iTotalPressure = 0;4490 ReligionInCityList::iterator it;4491 for(it = m_SimulatedStatus.begin(); it != m_SimulatedStatus.end(); it++)4492 {4493 iTotalPressure += it->m_iPressure;4494 }44954496 // safety check4497 if (iTotalPressure == 0 || iUnassignedFollowers == 0)4498 {4499 CvAssertMsg(false, "Internal religion data error. Send save to Ed");4500 return;4501 }45024503 iPressurePerFollower = iTotalPressure / iUnassignedFollowers;45044505 // Loop through each religion4506 for(it = m_SimulatedStatus.begin(); it != m_SimulatedStatus.end(); it++)4507 {4508 it->m_iFollowers = it->m_iPressure / iPressurePerFollower;4509 iUnassignedFollowers -= it->m_iFollowers;4510 it->m_iTemp = it->m_iPressure - (it->m_iFollowers * iPressurePerFollower); // Remainder4511 }45124513 // Assign out the remainder4514 for (int iI = 0; iI < iUnassignedFollowers; iI++)4515 {4516 ReligionInCityList::iterator itLargestRemainder = NULL;4517 int iLargestRemainder = 0;45184519 for (it = m_SimulatedStatus.begin(); it != m_SimulatedStatus.end(); it++)4520 {4521 if (it->m_iTemp > iLargestRemainder)4522 {4523 iLargestRemainder = it->m_iTemp;4524 itLargestRemainder = it;4525 }4526 }45274528 if (itLargestRemainder && iLargestRemainder > 0)4529 {4530 itLargestRemainder->m_iFollowers++;4531 itLargestRemainder->m_iTemp = 0;4532 }4533 }4534}
Calls
BaseVector::beginBaseVector::end- CvCity::getPopulation(bool) const