If your GlobalReligionYield tag has been added to BuildingInfo or BuildingClassInfo, you really have no choice but to tell
every city to update its yields when a religion's count changes.
I expect you'll be limiting the use of this tag to Shrines which means holy cities. In that case, whatever CvGame function that tracks the spread of religions can tell just the holy city for the religion in question to update its yields.
I don't know if this is clear or not: functions perform actions while fields (class variables such as m_aiGlobalReligionYields) hold data. When you say, "the game updates countReligionLevels," you're mixing the two a bit. It could be just your wording, but if you're thinking that countReligionLevels holds values that can be changed, you are mixing the concepts.
Think of functions as procedural instructions that you can follow and variables as buckets where you can save values to use later. You typically call functions to have them modify variables, but the functions themselves don't hold any data.
Back to the task at hand, I followed the calling chain back from CvCity::updateBuildingCommerce() which is responsible for summing up all of the commerce sources for each building. Every player's building commerce is recalculated by CvGame::updateBuildingCommerce() every turn. More importantly for your feature, it's also called by CvPlayer::changeHasReligionCount(). So every time a player's religion count is changed, every player is told to update the building commerce for every one of its cities.
You definitely don't want to rewrite all of the yield-handling code to work like commerce, so my recommendation is to create a new function in CvGame that you call from CvPlayer::changeHasReligionCount():
Code:
void CvGame::updateGlobalReligionYield(ReligionTypes eReligion)
find holy city for eReligion
city->updateGlobalReligionYield(eReligion)
It should find the holy city for the religion and call another new function with the same name but on CvCity.
Code:
void CvCity::updateGlobalReligionYield(ReligionTypes eReligion)
if this city has the building that gains yields for eReligion
int iCount = GC.getGameINLINE().countReligionSpread(eReligion);
for each yield
setGlobalReligionYield(eReligion, eYield, iNewValue) // your function
You must change the array in CvCity to be an array of arrays so it can track the yields for each religion separately. You function needs to know the previous total
for that religion and yield combination in order to apply the difference via changeBaseYieldRate().