/// Is there a religion that at least half of the population follows?
ReligionTypes CvCityReligions::GetReligiousMajority()
{
int iTotalFollowers = 0;
int iMostFollowerPressure = 0;
int iMostFollowers = -1;
ReligionTypes eMostFollowers = NO_RELIGION;
ReligionInCityList::iterator religionIt;
for(religionIt = m_ReligionStatus.begin(); religionIt != m_ReligionStatus.end(); ++religionIt)
{
iTotalFollowers += religionIt->m_iFollowers;
if(religionIt->m_iFollowers > iMostFollowers || religionIt->m_iFollowers == iMostFollowers && religionIt->m_iPressure > iMostFollowerPressure)
{
iMostFollowers = religionIt->m_iFollowers;
iMostFollowerPressure = religionIt->m_iPressure;
eMostFollowers = religionIt->m_eReligion;
}
}
if ((iMostFollowers * 2) >= iTotalFollowers)
{
return eMostFollowers;
}
else
{
return NO_RELIGION;
}
}
/// Just asked to simulate a conversion - who would be the majority religion?
ReligionTypes CvCityReligions::GetSimulatedReligiousMajority()
{
int iTotalFollowers = 0;
int iMostFollowerPressure = 0;
int iMostFollowers = -1;
ReligionTypes eMostFollowers = NO_RELIGION;
ReligionInCityList::iterator religionIt;
for(religionIt = m_SimulatedStatus.begin(); religionIt != m_SimulatedStatus.end(); ++religionIt)
{
iTotalFollowers += religionIt->m_iFollowers;
if(religionIt->m_iFollowers > iMostFollowers || religionIt->m_iFollowers == iMostFollowers && religionIt->m_iPressure > iMostFollowerPressure)
{
iMostFollowers = religionIt->m_iFollowers;
iMostFollowerPressure = religionIt->m_iPressure;
eMostFollowers = religionIt->m_eReligion;
}
}
if ((iMostFollowers * 2) >= iTotalFollowers)
{
return eMostFollowers;
}
else
{
return NO_RELIGION;
}
}
/// What is the most popular religion in this city?
ReligionTypes CvCityReligions::GetFavoredReligion()
{
int iTotalFollowers = 0;
int iMostFollowers = -1;
ReligionTypes eMostFollowers = NO_RELIGION;
ReligionInCityList::iterator religionIt;
for(religionIt = m_ReligionStatus.begin(); religionIt != m_ReligionStatus.end(); ++religionIt)
{
iTotalFollowers += religionIt->m_iFollowers;
if(religionIt->m_iFollowers >= iMostFollowers && religionIt->m_eReligion != NO_RELIGION)
{
iMostFollowers = religionIt->m_iFollowers;
eMostFollowers = religionIt->m_eReligion;
}
}
CvAssertMsg(eMostFollowers != NO_RELIGION, "Improper call usage: called GetFavoredReligion() with no religion present in city");
return eMostFollowers;
}
/// How many followers are there of religions OTHER than this one?
int CvCityReligions::GetFollowersOtherReligions(ReligionTypes eReligion)
{
int iOtherFollowers = 0;
ReligionInCityList::iterator religionIt;
for(religionIt = m_ReligionStatus.begin(); religionIt != m_ReligionStatus.end(); ++religionIt)
{
if (religionIt->m_eReligion > RELIGION_PANTHEON && religionIt->m_eReligion != eReligion)
{
iOtherFollowers += religionIt->m_iFollowers;
}
}
return iOtherFollowers;
}
/// Total pressure exerted by all religions
int CvCityReligions::GetTotalPressure()
{
int iTotalPressure = 0;
ReligionInCityList::iterator it;
for(it = m_ReligionStatus.begin(); it != m_ReligionStatus.end(); it++)
{
iTotalPressure += it->m_iPressure;
}
return iTotalPressure;
}
/// Pressure exerted by one religion
int CvCityReligions::GetPressure(ReligionTypes eReligion)
{
ReligionInCityList::iterator it;
for(it = m_ReligionStatus.begin(); it != m_ReligionStatus.end(); it++)
{
if(it->m_eReligion == eReligion)
{
return it->m_iPressure;
}
}
return 0;
}
/// Pressure exerted by one religion per turn
int CvCityReligions::GetPressurePerTurn(ReligionTypes eReligion)
{
int iPressure = 0;
// Loop through all the players
for(int iI = 0; iI < MAX_PLAYERS; iI++)
{
CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iI);
if(kPlayer.isAlive())
{
// Loop through each of their cities
int iLoop;
CvCity* pLoopCity;
for(pLoopCity = kPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kPlayer.nextCity(&iLoop))
{
// Ignore the same city
if (m_pCity == pLoopCity)
{
continue;
}
// Does this city have the matching majority religion?
ReligionTypes eMajorityReligion = pLoopCity->GetCityReligions()->GetReligiousMajority();
if(eMajorityReligion == eReligion)
{
iPressure += GC.getGame().GetGameReligions()->GetAdjacentCityReligiousPressure (eMajorityReligion, pLoopCity, m_pCity);
}
}
}
}
// Holy city for this religion?
if (IsHolyCityForReligion(eReligion))
{
int iHolyCityPressure = GC.getGame().getGameSpeedInfo().getReligiousPressureAdjacentCity();
iHolyCityPressure *= GC.getRELIGION_PER_TURN_FOUNDING_CITY_PRESSURE();
iPressure += iHolyCityPressure;
}
return iPressure;
}
It is one of the greater mysteries of the game exactly how pressure is converted to followers, but there is little doubt that some sort of meter that has to be filled is in play - i.e. once you reach a certain threshold of faith, first citizen converts, next threshold second citizen converts etc. - exactly how we need to fill the "food" container for new citizens to grow. Higher pressure will mean that meter fills faster, and hence citizens convert faster.The source code posted above does things like calculate the majority religion in a city or how much pressure there is in a city for a given religion. What it doesn't tell you is how the game calculates how many citizens will follow a particular religion on a given turn.
My assumption has been that, in steady state, the citizens of a city will be apportioned based on the amount of pressure each religion provides. So if three religions each have 12 pressure in a city, then if you let the game go on long enough in that situation, the citizens will be divided up equally among those three religions (because their pressures are equal). If a city gets 12 pressure from a first religion and only 6 from a second religion, then the first religion will have 2/3 of the citizens and the second will have 1/3 of them once you let the game go on for long enough.
A weaker assumption is that the rate at which citizens convert themselves based on pressure is related to the raw amount of pressure provided by a religion. So if a city is getting 6 pressure from a first religion and all of the city's citizens are following that religion, and you convert a bunch of nearby cities in the same turn so it's getting 24 pressure from your religion now, then the citizens will convert to your religion more quickly than if you only converted one nearby city so that it was getting only 6 pressure from your religion.
What I don't know is whether it's tallying up the pressure from each religion turn by turn and then apportioning the citizens according to those totals, although it probably is. If that's true, I also really don't know whether it is doing this as a running total (by which I mean the total pressure incurred over the past N turns) or an absolute total (since the city was built). And I seriously don't know how it factors in non-religious citizens into all of this (i.e., what mechanism keeps non-religious citizens from all converting all at once when the city only has pressure from a single religion in it).