For instance in CvPlayerAI::AI_doReligion() there is this part:
Code:
if (eBestReligion == NO_RELIGION)
{
eBestReligion = getStateReligion();
}
which means that Izzy would never switch out of Judaism again if say Confucianism spread to her 5th city so that Judaism is not pure enough anymore and NO_RELIGION would be her best religion again.
Is this actually a bad thing? If Izzy decides that Free Religion is her best civic, she will be forced out of her state religion regardless. If, however, she is running something other than FR, there is no benefit to dropping the State Religion even if NO_RELIGION is suddenly determined to be the best. Switching from Judaism to NSR while running OR/Theo/Pac would only ever be beneficial for diplomacy reasons; if you ignore diplomacy, staying in the state religion will always be better than running one of those civics without a state religion. And since the AI doesn't consider diplomacy in its choice of religion (and changing that would be beyond the scope of this patch) the rule makes perfect sense to me.
She's also not completely trapped in Judaism forever with the current AI_doReligion() rules. Here is an example based on the test save.
Izzy starts out with the following cities:
- Braga (1) No religions
- Faro (1) Bu
- Leiria (1) Is
- Lagos (1) Jw
- Evora (5) Jw
She chooses Theocracy/Judaism as discussed previously.
Now, Hannibal and Joao start giving her loads of missionaries which she uses (a whole other issue we're ignoring) and she also founds another city resulting in the following situation:
- Braga (2) Bu, Cn, Tao
- Faro (2) Bu, Cn, Tao
- Leiria (4) Is, Bu, Cn, Tao
- Lagos (2) Jw, Cn, Tao
- Evora (6) Jw, Cn, Tao
- Madrid (1) Is
At this point, Izzy determines Free Religion is in her best interests (value is 148 and crushes everything else which has a value in the 30s and 40s) and so she revolts. Free Religion, by design, forces her into No State Religion as well.
But then there is war from Joao. Joao captures the 3 Southern cities and Buddhism spreads (with Hannibal's help) to Madrid putting Izzy in this situation:
- Braga (3) Bu, Cn, Tao
- Faro (3) Bu, Cn, Tao
- Madrid (2) Is, Bu
At this point, Buddhism is the preferred religion and Theocracy the highest valued civic (111 vs FR's 57 thanks, in part, to being at war), resulting in a switch to Theo/Budd.
==========================================
While interesting, the above is really just a diversion. The key is to recognize that AI_bestReligion() isn't always the preferred state religion because of the above mentioned check so let's get back on task.
So I think we need more checks to allow a civic switch that would benefit from an anticipated (future) conversion:
...
Code:
if (getStateReligion() != eBestReligion && eBestReligion == NO_RELIGION) // we would like to convert
{
eBestReligion = getStateReligion();
}
Since our goal is to make the civic valuator base its calculations on the (most likely) state religion, and do_Religion has this special case, this seems a reasonable improvement.
I will switch the order of the if check so that we don't bother calling getStateReligion() unless it's necessary, but that's just an optimization issue and doesn't alter the logic.
When testing using the same procedure as my above example, the primary difference when making this change seems to be that an AI is less likely to switch to Free Religion than they would be using the previous suggestion. This is probably better since it would be closer to the existing game behavior in that regard and avoiding unintended consequences is a good thing.
During the previous test, at checkpoint 2, the value of Free Religion was nearly 4 times the value of any other civic. This was due to the fact that the civic valuator was assuming a switch to NO_RELIGION. However, as Dan showed, the AI wouldn't voluntarily choose NO_RELIGION and would instead stay in its current religion and so now Free Religion's value has gone down slightly to 138 (the happiness increase is smaller) and Theocracy's value is up to 128 since it'd actually have useful benefits. OR and Pac have also doubled in value though they're still non-factors. As a result, Izzy still revolts to FR, but it's a much closer call now.
At checkpoint 3, since the best religion is Buddhism, it's exactly the same as before. Theo (111) is vastly superior to FR (57), so she goes to Theo/Budd. Obviously this needs testing (everything always does) but I think this will do the job. For clarity the full current proposal follows:
Code:
ReligionTypes eBestReligion = AI_bestReligion();
if ( (eBestReligion == NO_RELIGION) && (getStateReligion() != eBestReligion) )
{
eBestReligion = getStateReligion();
}
iHighestReligionCount = ((eBestReligion == NO_RELIGION) ? 0 : getHasReligionCount(eBestReligion));
===========================================
Now there might be periods of Theo + no SR again when the conversion timer doesn't allow an instant conversion. BTW why are there 2 different timers for CvPlayer and CvPlayerAI (both for civics and religions)?
Small periods of questionable civic/religion choices due to having to wait for the timer are unavoidable and have never been a problem; as long as the long-term issue is addressed then we've done our job. Regarding the timer difference, it looks like the AI has a little extra delay built-in to prevent a non-spiritual civ from changing its civics and religions so often that it spends half its time in Anarchy.