My personal thread: Clarification of certain game mechanics

Moderator Action: Please return to the discussion topic of the thread. Please stop trolling and flaming each other by making this personal. Report the offensive posts and continue the discussion without the trolling.
Please read the forum rules: http://forums.civfanatics.com/showthread.php?t=422889
 
An AI can occasionally gears its resources towards missionaries for spreading the religion it has available towards its own empire or outside it.
An internal spread is within the said AI is directed for the empire while an external spread is for neighbours. Of course, it's a probability value. Let's see the factors that goads the AI for manual religious spread.
In summary, for internal spread, a cultural victory dramatically increases for manual relgious spreads. Otherwise, in normal events, it's the state religion aspect along the shrines that work best for increasing odds of missionaries.
For external spread, again, state religion is important factor along the existence of shrines. On rare occasion, a missionary will be sent in foreign lands despite not being state religion because of the non-state shrine. Hence the important to let the AI founds shrines. But chances are internal spread will prevail over that weak external spread value. For external spread, the AI strategy called AI_STRATEGY_MISSIONARY boosts the odds even more.

Internal Spread

Scales are presented in parentheses.

Whereas an external spread, the internal spread has a minimum RNG value, which means even weak, there is always a chance of internal spread. (100)

An AI is coded to have four levels towards a cultural victory. Indeed, being in one of those levels help in internal spread odds. Nevertheless, for an odd reason, there is supposed to be one line for each cultural level, but I see the first cultural level stage mentionend trice. It sounds like a bug. Still, it boosts the chance by a big margin.
(5000)

State religions are favored. (1000)

For other religions, it has a lower odd depending of its spread success (by external factors like other AI's, natural spread, etc). (500+%ofCitiesWithPaganReligion)


Having a holy city boosts moderately.
If the holy city corresponds to the state religion, then its (1000) versus (200) otherwise.

Having on top of that a shrine, it helps even more. (1000 [state religion shrine] vs 500 [non-state religion shrine]).

Related to the shrine, the AI does consider the gold value that each city brings to the shrine.

After all that, there is a multiplier that enforces even more the odds through that formula:


Of course, if all cities within the empire is already converted to the said religion, the internal spread odd drops to nil.


External Spread

The base seed for external spread is nil.

If the AI has a holy city that corresponds to the state religion, then (1000), otherwise it's irrelevant.

If possessing a shrine, when corresponding to the state religion, it's (600), otherwise (100). We see the first case of a non-state religion affecting probabilities of external spreads.

The gold brought by the shrine is also pondered, but approximately in a halved value than internal spreads.

Afterwards, we have some special parameters as multipliers.
  • For a civ with which the AI has OB, if the AI is under the Missionary Strategy, then a multiplier of 60. Otherwise, it's normally a multiplier of 25.
  • If the target civilization for spread is not under Theocracy and has adopted the AI religion state, then another multiplier is in effet.

Finally, the missionaries built for foreign purposes aren't spread everywhere in a disorganized manner. It affects the best target at a time. The one that gives the best multiplier.

Is External and Internal Spreads simultaneous?

Not at all. It's either one or the other one. It's a value battle between Internal Spread versus External Spread values and the one that has best value is chosen for future missionaries missions.

Code​

In CvPlayerAI.cpp

Spoiler :
Code:
int CvPlayerAI::AI_missionaryValue(CvArea* pArea, ReligionTypes eReligion, PlayerTypes* peBestPlayer) const
{
	CvTeam& kTeam = GET_TEAM(getTeam());
	CvGame& kGame = GC.getGame();
	
	int iSpreadInternalValue = 100;
	int iSpreadExternalValue = 0;
	if (AI_isDoStrategy(AI_STRATEGY_CULTURE1))
	{
		iSpreadInternalValue += 500;
		if (AI_isDoStrategy(AI_STRATEGY_CULTURE1))
		{
			iSpreadInternalValue += 1500;
			if (AI_isDoStrategy(AI_STRATEGY_CULTURE1))
			{
				iSpreadInternalValue += 3000;
			}
		}
	}
	bool bStateReligion = (getStateReligion() == eReligion);
	if (bStateReligion)
	{
		iSpreadInternalValue += 1000;
	}
	else
	{
		iSpreadInternalValue += (500 * getHasReligionCount(eReligion)) / std::max(1, getNumCities());
	}
	
	if (kTeam.hasHolyCity(eReligion))
	{
		iSpreadInternalValue += bStateReligion ? 1000 : 200;
		iSpreadExternalValue += bStateReligion ? 1000 : 0;
		if (kTeam.hasShrine(eReligion))
		{
			iSpreadInternalValue += bStateReligion ? 1000 : 500;
			iSpreadExternalValue += bStateReligion ? 600 : 100;
			int iGoldMultiplier = kGame.getHolyCity(eReligion)->getTotalCommerceRateModifier(COMMERCE_GOLD);
			iSpreadInternalValue += 10 * std::max(0, (iGoldMultiplier - 100));
			iSpreadExternalValue += 5 * std::max(0, (iGoldMultiplier - 150));
		}
	}
	
	int iOurCitiesHave = 0;
	int iOurCitiesCount = 0;
	
	if (NULL == pArea)
	{
		iOurCitiesHave = kTeam.getHasReligionCount(eReligion);
		iOurCitiesCount = kTeam.getNumCities();
	}
	else
	{
		iOurCitiesHave = pArea->countHasReligion(eReligion, getID());
		iOurCitiesCount = pArea->getCitiesPerPlayer(getID());
	}
	
	if (iOurCitiesHave < iOurCitiesCount)
	{
		iSpreadInternalValue *= 50 + 50 * (iOurCitiesCount - iOurCitiesHave);
		iSpreadInternalValue /= 100 * iOurCitiesCount;
	}
	else
	{
		iSpreadInternalValue = 0;
	}
	
	if (iSpreadExternalValue > 0)
	{
		int iBestPlayer = NO_PLAYER;
		int iBestValue = 0;
		for (int iPlayer = 0; iPlayer < MAX_PLAYERS; iPlayer++)
		{
			if (iPlayer != getID())
			{
				CvPlayer& kLoopPlayer = GET_PLAYER((PlayerTypes)iPlayer);
				if (kLoopPlayer.isAlive() && kLoopPlayer.getTeam() != getTeam() && kLoopPlayer.getNumCities() > 0)
				{
					if (GET_TEAM(kLoopPlayer.getTeam()).isOpenBorders(getTeam()))
					{
						int iCitiesCount = 0;
						int iCitiesHave = 0;
						int iMultiplier = AI_isDoStrategy(AI_STRATEGY_MISSIONARY) ? 60 : 25;
						if (!kLoopPlayer.isNoNonStateReligionSpread() || (kLoopPlayer.getStateReligion() == eReligion))
						{
							if (NULL == pArea)
							{
								iCitiesCount += 1 + (kLoopPlayer.getNumCities() * 75) / 100;
								iCitiesHave += std::min(iCitiesCount, kLoopPlayer.getHasReligionCount(eReligion));
							}
							else
							{
								int iPlayerSpreadPercent = (100 * kLoopPlayer.getHasReligionCount(eReligion)) / kLoopPlayer.getNumCities();
								iCitiesCount += pArea->getCitiesPerPlayer((PlayerTypes)iPlayer);
								iCitiesHave += std::min(iCitiesCount, (iCitiesCount * iPlayerSpreadPercent) / 75);
							}
						}
						
						if (kLoopPlayer.getStateReligion() == NO_RELIGION)
						{
							if (kLoopPlayer.getStateReligionCount() > 0)
							{
								int iTotalReligions = kLoopPlayer.countTotalHasReligion();
								iMultiplier += 100 * std::max(0, kLoopPlayer.getNumCities() - iTotalReligions);
								iMultiplier += (iTotalReligions == 0) ? 100 : 0;
							}
						}
						
						int iValue = (iMultiplier * iSpreadExternalValue * (iCitiesCount - iCitiesHave)) / std::max(1, iCitiesCount);
						iValue /= 100;
						if (iValue > iBestValue)
						{
							iBestValue = iValue;
							iBestPlayer = iPlayer;
						}
					}
				}
			}
		}

		if (iBestValue > iSpreadInternalValue)
		{
			if (NULL != peBestPlayer)
			{
				*peBestPlayer = (PlayerTypes)iBestPlayer;
			}
			return iBestValue;
		}

	}
	
	if (NULL != peBestPlayer)
	{
		*peBestPlayer = getID();
	}		
	return iSpreadInternalValue;
 
He has 301 :hammers: invested in the current build.

Easier formula for the lazy:

(Sabotage Production / Influence Civics) * 100

Is it possible that this formula is far off? I just played a round of Small / Marathon (yes, I know, cheese :D ) and Pericles built the Mids with maybe 5000 sabotage production and 800 influence Civics. I calculated that those would be about 600 :hammers: , Mids on Marathon are 1500 :hammers: though.
 
It is modified by game speed:

Hammers = SabotageCost / InfluenceCivicsCost * 67 (Quick speed)
Hammers = SabotageCost / InfluenceCivicsCost * 150 (Epic speed)
Hammers = SabotageCost / InfluenceCivicsCost * 200 (Marathon speed)​
(5000 / 800) * 200 = 1250/1500H

Sorry if this ruined your cheese victory. :p
 
It is modified by game speed:

Hammers = SabotageCost / InfluenceCivicsCost * 67 (Quick speed)
Hammers = SabotageCost / InfluenceCivicsCost * 150 (Epic speed)
Hammers = SabotageCost / InfluenceCivicsCost * 200 (Marathon speed)​
(5000 / 800) * 200 = 1250/1500H

Sorry if this ruined your cheese victory. :p

Ah, thx.

Then the formula is really decently adequate.

And no worries, of course I wanted Pericles to build the Mids for me, I was just very surprised that he finished them in half of the time that I estimated. Due to chance my fighters were just in the area anyhow, so they still came in time to the erection-party. Mids are definately an argument to make a little detour and continue the originally planned war a little later.
 
And no worries, of course I wanted Pericles to build the Mids for me, I was just very surprised that he finished them in half of the time that I estimated. Due to chance my fighters were just in the area anyhow

You had Fighters when the Mids were completed? :eek: I normally don't learn Flight until at least 500 AD. :mischief:
 
Say, do you know the formula for how many population points per hammers a unit subtracts from a city when being drafted?
 
It's on a per-unit basis, not hammer AFAIK.

Up to Riflemen: 1 pop.
Infantry: 2 pop
Mech Inf. is 3 pop if my memory has not decayed too much.

<\normal speed>
 
But what about pre-Rifling Units? They can be drafted too, all for one pop. Also in Legends of Revolution there is a Motorized Infantry Unit between Infantry and Mechanized Infantry and it can be drafted for two pop. I´m pretty sure it´s based on hammer costs, or there would have to be an XML-tag for every draftable unit saying how much pop it costs. From a quick search through UnitInfos.xml or somesuch I learned that while there is a <iconscription> Tag it only seems to say if a unit can be drafted and if yes with what priority.
 
From a quick search through UnitInfos.xml or somesuch I learned that while there is a <iconscription> Tag it only seems to say if a unit can be drafted and if yes with what priority.
The priorities are odd too as many units that are outright impossible to draft have values of 1, such as Swords, Grenadiers, Paratroopers and Anti-Tanks :eek:
Others seem like they *may* be possible in outright absurd hyptheticals, such as spears for having hunting and trading for copper without BW while having Nationalism..... Sounds like an Attacko strategy in the making :lol:
Also in Legends of Revolution there is a Motorized Infantry Unit between Infantry and Mechanized Infantry and it can be drafted for two pop.
Would be nice to know where the cost is defined rather than just the calculation for BTS as it could be nice when playing/making mods
 
Would be nice to know where the cost is defined rather than just the calculation for BTS as it could be nice when playing/making mods

Think it might be one pop for every 100 Hammers? I don't have exact numbers in my head but Mechanized Infantry costs more than 200 and requires 3 pop to draft while Infantry costs between 100 and 200 and subtracts 2, with everything below only taking a single pop point, although Riflemen are pretty close to 100 AFAIK which would explain their good Food->Hammer ratio.
 
Rifles are 110 so that idea can't be right :p
I wouldn't be so certain its tied directly to :hammers: cost anyway. While it would be sensible, sensible isn't something civ code does well :lol:

For reference Infatry cost 140, Sam Infantry cost 150 and Mech inf cost 200 on normal speed.
I suppose you could test your pop->Hammers relation idea by modding the hammer values, if it is the case then changing a Rifles cost to 140 would make it cost 2 pop.
 
I'd still rather have the exact formula, but I think I'll try your suggestion tomorrow.
 
Top Bottom