Missionaries and Inquisitors new logic

I think a crucial (almost hard-coded) part of the code would be to always have two inquisitors in your holy city and to use one if the holy city no longer follows your religion. It's quite frustrating to see an AI with Divine Inheritance let its holy city get overwhelmed by foreign religions and never again regain its religion.
 
One has to consider the large amount needed to buy missionaries and faith. The problem is that the AI also spends equivalent amount of faith to counteract your spread. What happens is that you "waste" those faith points in a severe religious competition.

Recently I was in such rivalry against Carthage. Holy moly she would not give up. Once a city will switch to my religion, then to her religion, then back to mine, and so on. And in the meantime I am severely bleeding faith to keep up to her. At the end I drew the line and said this is not even worth it, wasting precisious faith for a bunch of cities which lasts only for a while until she gets them back to her. It is like trying to fill a bucket with a hole in it.

And I realized it is much better to buy scientists, artists, and engineers rather than starting a perpetual religious war wasting faith.
 
Current functions:
ScoreCityforMissionary --> It's what missionaries use for choosing targets. A city gets a better score for being closer, when the owner is not a founder of other religion and when spreading will 'make a dent'.
ScoreCityforInquisitor --> Where it is better to use the remove heresy action.
BuyMissionaryorInquisitor --> It chooses if it is better to purchase a missionary or an inquisitor (or nothing) and purchase it (or not).
BuyMissionary --> Find the city where missionaries are cheaper and purchase one there.
BuyInquisitor --> The same as above.
HaveNearbyConversionTarget(ReligionTypes eReligion, bool bCanIncludeReligionStarter, bool bHeathensOnly) --> Checks if cities in range have a suitable target for missionaries. It can be set to ignore cities that are already converted to the founded religion of the city owner, and to look only at cities without a majority religion.
AreAllOurCitiesHaveFaithBuilding --> Checks if any of our cities can build a religious building.
HaveEnoughInquisitors --> Counts the number of our cities that are following a different religion and checks if we have already one missionary for every city that not belongs to our religion.

Let's try this logic...

STEP 1 Check if we better save faith for a Great Prophet.

// We should prioritize enhancing when there is a rival religion nearby that is taking advantage. We need a function that counts how many cities in range are suitable for spreading, and how many of them are turned to a rival religion. Let's call it NearbyCitiesCanConvert(ReligionTypes eReligion, bool bCanIncludeReligionStarter, bool bOwnCitiesOnly)
__If the number of cities in range that already belong to another religion is bigger than our own cities without a religion, then we are at risk and we need to enhance fast if we haven't done it yet.
// We must enhance in any case once ...
__If all our cities are already converted and the number of potential targets is less than the cities we have already converted, then it is time to enhance.
// Extra GP after enhanced
__If we have any owned city that it is heathen, skip. // Should convert all our cities before commiting to a second prophet.
__If we don't have enough inquisitors, skip.
__If the number of potential good targets is bigger than the cities following our religion, skip. // Easy targets are best with missionaries.
__If we have religious buildings to build, skip.
__// The real choice comes now, should we surrender our religion?
__If foreign pressure in our cities is bigger than local then
____If faith yield is low, then
______surrender religion, no more prophets, or inquisitors o missionaries. Only buildings, great people and military units are to be built.
____else
______save prophets for sacred sites. // Sacred sites increases faith and pressure, so it helps with religious strength.
__else // Our pressure is bigger locally
____If faith yield is high and there are benefits for spreading then
______save prophets for aggressive spreading
__otherwise save for other GreatPeople

STEP 2 Religious buildings
// These usually give extra pressure and extra faith yields and are usually better than purchasing inquisitors or missionaries when are available. The only reason I see
// rushing a missionary over a religious building is to convert a owned city that is not receiving any pressure.
if (!AreAllOurCitiesHaveFaithBuilding) && (pCity->Pressure(eReligion) <= 0) then
__purchase religious building

STEP 3 Inquisitor garrisons
// This is not accounted in any part of the current code. I think we need at least one inquisitor in holy city and one in every city that is receiving noticeable foreign influence.
Make a new function, HaveEnoughInquisitorGarrison, that checks if there are at least the same number of inquisitors than the cities where foreign pressure is at least the 33% of the total pressure, and one more inquisitor for the Holy City.
Then if there are not enough inquisitor garrisons, order an inquisitor.

STEP 4. Inquisitors for duty
// This is what HaveEnoughIquisitors currently does. It should only add an account for the inquisitor garrisons.
If there are owned cities with a different religion that require removing heresy, and current number of inquisitors are fewer than EnoughInquisitorGarrison + one for every city that needs removing heresy then
__purchase inquisitor.

STEP 5. Missionaries
// Question here is when is it time to stop producing missionaries.
If there are no easy targets and there's no bonus for spreading and such (city state quest?) then
__skip missionaries
otherwise
__purchase missionary

STEP 6. Purchasing inquisitors
Look for the owned city that has the highest foreign pressure and has no inquisitor garrisoned
__Look if this city has a foreign pressure that is higher than 33%
__This is our target city.
__Look for the closest city that can produce religious units that has a faith discount or
__if there is no faith discount, look for the closest city that can produce religious units.
__This is our origin city. // It could be the same as the target city
__Purchase an inquisitor in origin city
if no city needs a garrison, then
__Look for the owned city closest to the Holy City that requires removing heresy (ScoreCityForInquisitor can be used)
__This is our target city.
__Look for the closest city that can produce religious units that has a faith discount or
__if there is no faith discount, look for the closest city that can produce religious units.
__This is our origin city. // It can't be the same as the target city
__Purchase an inquisitor in origin city

STEP 7. Purchasing buildings
Just find the closest city to the Holy City that can build a religious building and build it there.

STEP 8. Purchasing missionaries
Look for the best city target (ScoreCityForMissionary can be used)
Look for the closest city that can produce religious units that has a faith discount or
if there is no faith discount, look for the closest city that can produce religious units.
This is our origin city. // It can't be the same as the target city
__Purchase a missionary in origin city

STEP 9. Moving religious units
Begin with the Great Prophet.
If it can enhance, then enhance.
If player has surrendered then use it for a sacred site.
If a city requires removing heresy and there are no inquisitors at all and faith generation is low, then use it for removing heresy.
If the conditions are right for a Sacred Site as seen in STEP 1, then go create it at the converted city that has the lowest owned religious pressure.
If the conditions are right for an aggressive spreading as seen in STEP 1, then find the sweetest foreign religion city
and send the prophet to the closest safe spot to the target city avoiding unfriendly territory.
When the GP arrives at the safe spot, send it to the target city for conversion.
If we have nothing better for it, let it wait in the Holy City until an opportunity appears.
Beginning Atomic Era, any Great Prophet not used could go for sacred sites.

Then Inquisitors.
If a city requires an inquisitor garrisoned and there is no inquisitor on the way, send it there
If a city requires removing heresy, send it there to remove heresy.
If there are more inquisitors than required, let them rest at the Holy City.
If money is negative, go expend one inquisitor to the city with the highest unfaithful citizens,
If that can't be done, remove one inquisitor.

Last missionaries.
Order the best city targets using ScoreCityForMissionary
Take next best city target and if no missionary is on the way, send one there using the same logic as the Great Prophet.
If there are more missionaries than required, then let them rest in the Holy City.
If money is low, go expend one missionary at the best close target.

*Most of the code is already doing this, it only needs a bit of shuffling in the order of the code, and a couple of new functions (garrisons and number of good targets), but they don't look especially difficult.


@ilteroi , @Gazebo , what do you think? Is it feasible like that?
 
Last edited:
Does the AI currently know when's the best time to use an inquisitor? Most of the time when the inquisitor arrives at the city it's already too late (turned neutral).
 
Now they work on neutral cities. Finally. No need to sen one missionary and one inquisitor on a new conquered asset.
 
I'd also recommend an AI-friendly change -> have the holy cities enjoy the same protection Spanish UA gives, i.e. you can't use missionaries/GPs on the Holy City nor does it suffer from passive religious pressures. The human players will always protect their holy city, whereas the AI isn't that good at it. Instead of "teaching" the AI how to protect it, you could simply have it automatically protected (unless it's captured, of course).
 
I'd also recommend an AI-friendly change -> have the holy cities enjoy the same protection Spanish UA gives, i.e. you can't use missionaries/GPs on the Holy City nor does it suffer from passive religious pressures. The human players will always protect their holy city, whereas the AI isn't that good at it. Instead of "teaching" the AI how to protect it, you could simply have it automatically protected (unless it's captured, of course).
This will not be needed if a logic for inquisitor garrison is added, as suggested.
 
Inquisition garrison will not prevent an AI Holy City from being overwhelmed with foreign influence to the point the AI has no inquisitors left and must wait for a GP to spawn to reclaim its holy city back. I think it's better to include this fail-safe precaution than to bank on the inquisition logic working perfectly. That logic can still be used for other cities, but holy cities should be citadels of your religion where you needn't ever spend faith to keep it.
 
so i've made two small changes:

* AI always considers buying inquisitors before missionaries
* AI will keep up to two 'defensive' missionaries around

let's see how this goes.

ps: protecting the holy city from conversion might be a good idea ...
 
Garrisoned inquisitors do halve foreign pressure now, so they can be useful in defense against both active and passive conversion.
 
so i've made two small changes:

* AI always considers buying inquisitors before missionaries
* AI will keep up to two 'defensive' missionaries around

let's see how this goes.

ps: protecting the holy city from conversion might be a good idea ...
It should be extra defensive inquisitors. If you produce extra missionaries not to be used then it's a waste of resources. If you produce them and wait for the right moment to use them, even in the best case, they don't protect the same as inquisitors who halve foreign pressure.

Hardcoding holy cities against conversion is not a good idea, in my opinion. That would make impossible to erase anyone's religion. It's good that ai defend properly their religion but there's a moment when it is wise to surrender the religion, may be for the diplomatic bonus, and focus resources on other things.

I've provided a simplified method for ai to choose a stance (is it too hard to code? Inefficient?). Without that, all ai will behave similarly, not making the right choice for their situations. The only difference right now is for civs who have a bonus for spreading, which are encouraged to spread more often but that's all.
Without some ai deciding that they should enhance before converting all core cities, weaker civs would be gobbled too soon. Without some civs deciding that they should use the chance to spread wide even before building religious buildings, they miss the opportunity to become worldwide religions peacefully.
Also, by being too predictable, they make human players to rely on the same tactics over and over.
 
Back
Top Bottom