AI spies making a coup in my CS allies: what it does?

FinsT

Chieftain
Joined
Dec 23, 2013
Messages
84
Few games ago, on King, i went Freedom and took that 3rd-tier tenet which gives +4 to a city-state's influence each turn per each trade route i send to them. Being at a (massive) lead scientifically, i was unwilling to trade with other civs any much (to not help them with beakers), trading only with city-states with (eventually) 11 caravans / cargo ships. This quickly raised my influence over most city-states above 500, and went on to 700+ after which i stopped checking.

Thing is, now and then, i was getting messages that my influence over one or other particular city-state became weaker - and that it's possibly a result of other civilizations' spy activities. However, i never lost an ally to this kind of event. I _guess_ that was rigging elections they did, and i guess my massive lead in influence prevented them from becoming an ally (throw me out of being ally, that is).

But now i wonder about coups. I can't find precise answers to questions i have about it... So here goes:

1. Do AIs do coups in player-allied city-states, at all?
2. Do coups exactly _switch_ influences?
i.e., Can it happen some lucky AI's spy put me to some ~10 influence over a city state - while the spy's owner will enjoy some 1000+ influence level which i had before the coup?
3. Is there a dependancy between how high my initial influence over a city state is - and what chances AI's spy would have to do a successful coup? If yes, what are the numbers about it?
4. And, last but not least, what would be my options if some AI would indeed do a coup and get some 1000+ influence over a city-state? Are there any ways to get back to be an ally of such a city-state (other than risking my spies to do a "coup back")?

Thanks alot for any help with this! ><
 
Can't give you the exact formulas, but:
  1. Yes, I just had Genghis Kahn coup me from 110 influence down to 0 (!) influence the other day.
  2. Yes.
  3. Yes, the larger the difference between your influence and the couping civs influence is, the less likelyhood there is for them to succeed. I thought they had fixed it so that AI could no longer 0-influence coup you to ally state, but apparently they can (in fact, it happened twice in the same game to me).
  4. I don't think they could succeed with that big a difference. Like I said, the other day it happened to me with some ~110 influence, but I think with a difference much bigger than this, chances will go to 0.

Below is a screenshot of Mongolia performing a coup in budapest to become ally. Notice how my influence bar is down to complete 0 with them after the coup.
Spoiler :
 
On their given turn, the AI opponents could conceivably do anything human can do, so it's likely they did not "just" use the spy to try to coup. Before the coup they probably, as you might, gave the CS money, gave the CS a unit, or completed a quest. You wouldn't see these values as they're changing, only the end result.
 
Actually, he had 20 influence, you switched, and you dropped 20 after the coup.


Code:
		<Row Name="ESPIONAGE_COUP_NOBODY_BONUS">
			<Value>0.5</Value>
		</Row>
		<Row Name="ESPIONAGE_COUP_MULTIPLY_CONSTANT">
			<Value>3.0</Value>
		</Row>
		<Row Name="ESPIONAGE_COUP_SPY_LEVEL_DELTA_ZERO">
			<Value>0.0</Value>
		</Row>
		<Row Name="ESPIONAGE_COUP_SPY_LEVEL_DELTA_ONE">
			<Value>1.5</Value>
		</Row>
		<Row Name="ESPIONAGE_COUP_SPY_LEVEL_DELTA_TWO">
			<Value>2.25</Value>
		</Row>
		<Row Name="ESPIONAGE_COUP_SPY_LEVEL_DELTA_THREE">
			<Value>2.60</Value>
		</Row>
		<Row Name="ESPIONAGE_COUP_SPY_LEVEL_DELTA_FOUR">
			<Value>2.80</Value>
		</Row>

Code:
/// GetCoupChangeOfSuccess - What is the % chance of success that a spy will be able to pull off a coup?
int CvPlayerEspionage::GetCoupChanceOfSuccess(uint uiSpyIndex)
{
	// if you can't stage a coup, then the likelihood is zero!
	if(!CanStageCoup(uiSpyIndex))
	{
		return 0;
	}

	CvCity* pCity = GetCityWithSpy(uiSpyIndex);
	CvAssertMsg(pCity, "No city");
	if(!pCity)
	{
		return 0;
	}

	CvCityEspionage* pCityEspionage = pCity->GetCityEspionage();
	CvAssertMsg(pCityEspionage, "No city espionage");
	if(!pCityEspionage)
	{
		return 0;
	}

	PlayerTypes eCityOwner = pCity->getOwner();
	CvAssertMsg(GET_PLAYER(eCityOwner).isMinorCiv(), "Owner is not a minor civ");
	if(!GET_PLAYER(eCityOwner).isMinorCiv())
	{
		return 0;
	}

	CvMinorCivAI* pMinorCivAI = GET_PLAYER(eCityOwner).GetMinorCivAI();
	CvAssertMsg(pMinorCivAI, "pMinorCivAI is null");
	if(!pMinorCivAI)
	{
		return 0;
	}

	PlayerTypes eAllyPlayer = pMinorCivAI->GetAlly();
	int iAllySpyRank = 0;
	bool bNoAllySpy = true;
	if(pCityEspionage->m_aiSpyAssignment[eAllyPlayer] != -1)
	{
		int iAllySpyIndex = pCityEspionage->m_aiSpyAssignment[eAllyPlayer];
		iAllySpyRank = GET_PLAYER(eAllyPlayer).GetEspionage()->m_aSpyList[iAllySpyIndex].m_eRank;
		bNoAllySpy = true;
	}

	int iAllyInfluence = pMinorCivAI->GetEffectiveFriendshipWithMajorTimes100(eAllyPlayer);
	int iMyInfluence = pMinorCivAI->GetEffectiveFriendshipWithMajorTimes100(m_pPlayer->GetID());
	int iDeltaInfluence = iAllyInfluence - iMyInfluence;

	float fNobodyBonus = GC.getESPIONAGE_COUP_NOBODY_BONUS();
	float fMultiplyConstant = GC.getESPIONAGE_COUP_MULTIPLY_CONSTANT();
	float fSpyLevelDeltaZero = GC.getESPIONAGE_COUP_SPY_LEVEL_DELTA_ZERO();
	float fSpyLevelDeltaOne = GC.getESPIONAGE_COUP_SPY_LEVEL_DELTA_ONE();
	float fSpyLevelDeltaTwo = GC.getESPIONAGE_COUP_SPY_LEVEL_DELTA_TWO();
	float fSpyLevelDeltaThree = GC.getESPIONAGE_COUP_SPY_LEVEL_DELTA_THREE();
	float fSpyLevelDeltaFour = GC.getESPIONAGE_COUP_SPY_LEVEL_DELTA_FOUR();

	float fAllySpyValue = 0.0f;
	float fMySpyValue = 0.0;

	int iMySpyRank = m_aSpyList[uiSpyIndex].m_eRank;
	iMySpyRank += m_pPlayer->GetCulture()->GetInfluenceCityStateSpyRankBonus(eCityOwner);
	switch (iMySpyRank)
	{
	case 0:
		fMySpyValue = fSpyLevelDeltaZero;
		break;
	case 1:
		fMySpyValue = fSpyLevelDeltaOne;
		break;
	case 2:
		fMySpyValue = fSpyLevelDeltaTwo;
		break;
	case 3:
		fMySpyValue = fSpyLevelDeltaThree;
		break;
	case 4:
		fMySpyValue = fSpyLevelDeltaFour;
		break;
	}

	switch (iAllySpyRank)
	{
	case 0:
		fAllySpyValue = fSpyLevelDeltaZero;
		break;
	case 1:
		fAllySpyValue = fSpyLevelDeltaOne;
		break;
	case 2:
		fAllySpyValue = fSpyLevelDeltaTwo;
		break;
	}	

	float fSpyMultipier = fAllySpyValue - fMySpyValue + fMultiplyConstant;
	if (bNoAllySpy)
	{
		fSpyMultipier *= fNobodyBonus;
	}

	int iResultPercentage = 100 - (int)((iDeltaInfluence * fSpyMultipier) / 100);

	if(iResultPercentage > 85)
	{
		iResultPercentage = 85;
	}
	else if(iResultPercentage < 0)
	{
		iResultPercentage = 0;
	}

	return iResultPercentage;
}

He had 20, you had 110, delta is 9000 (getEffectiveFriendshipWithMajorTimes100). Let's assume he used his best spy to pull it off, and you had no spy in the city.
fSpyMultiplier = 0 - 2.8 + 3 = 0.2
No ally spy fNobodyBonus
fSpyMultiplier = 0.2 * 0.5 = 0.1

success chance = 100 - (int)((9000 * 0.1)/100) = 91%, too high, becomes 85%

Unless I'm reading this wrong, influence alone will not protect you very well from a rank 3 spy
 
Oh, so you not *only* switch influence, you also get an additional -20? Wonderful ...

Anyway, I hate coups with a vengeance and wanted to remove them with a mod, but haven't been able to decode those values, but you seem to have a good understanding of them, so maybe you can help. I reckon that setting all the ESPIONAGE_COUP_SPY_LEVEL_DELTA_XXX values to 0.0 will remove the bonus from higher levels spies, right? But I don't really understand the ESPIONAGE_COUP_NOBODY_BONUS and ESPIONAGE_COUP_MULTIPLY_CONSTANT entries - can you explain their significance to me and/or what values I should set them to in order to minimize chance of coup success?
 
I don't know much about modding, but I do know C++, sort of. The nobody bonus is 0.5, so if the allied player has no spy in the cs, it doubles the chance of coup success. The multiply constant is 3 and fMySpyValue is always less than 3. That means without a spy belonging to the allied player in the cs fSpyMultiplier is always greater than 0. Without this number, there would always be a 100% (ie 85%) chance of success, regardless of influence. The higher this number, the harder to coup. The smaller fSpyMultiplier, the less the difference in influence matters.
 
Magma Dragoon - thank you ALOT, this is exactly what i was looking for!

Say, what would be the chance if in the example above the delta would be not 9000, but 90000 (more like my case which i described in the 1st post)? I guess it'll be this (please check if i am not wrong if you can):

success chance = 100 - (int)((90000 * 0.1)/100) = 10%

Which in my case is awesome news. Furthermore, with delta = 100000 (which is me having 1000 more influence over a city-state than the AI which tries to coup) - the chance drops to 0%, right? Would be real nice if true. %)
 
I don't know much about modding, but I do know C++, sort of. The nobody bonus is 0.5, so if the allied player has no spy in the cs, it doubles the chance of coup success. The multiply constant is 3 and fMySpyValue is always less than 3. That means without a spy belonging to the allied player in the cs fSpyMultiplier is always greater than 0. Without this number, there would always be a 100% (ie 85%) chance of success, regardless of influence. The higher this number, the harder to coup. The smaller fSpyMultiplier, the less the difference in influence matters.
Awesome, so I'll just blow up the multiply constant, and hopefully see the coups go away for good. Wonder if AI will be smart enough not to try if chance is always 0.
 
There is also a function that determines if a coup can be carried out in this city. If you made that always return false, the AI would never coup. Humans too, probably.
 
Yeah, I'm not too good with lua programming or stuff more advanced (read that as zero skills :p), so if I can fix it through XML, that's good enough for me. If I see AI mass-suiciding their spies, I'll take it to the next level.
 
Top Bottom