Questions regarding spy mechanics

FilthyRobot

Chieftain
Joined
Aug 26, 2013
Messages
76
Hey guys, I have a few spy questions I was hoping to have answered.

1) What determines how long it takes for a spy to steal a tech? When I play SP on standard speed, I often get steal times around 8-10 turns, yet when I play MP on quick speed, I almost never get steal times less than ~20. What's the deal?

2) What are the actual numbers on leveled spies? How much faster does a lvl 3 spy steal techs or rig elections than a lvl 1 spy?

3) Does rigging elections or causing a coup in city-states level a spy up?

4) What are the base chances for stealing a tech vs being killed? What's the chance of my counter-spies catching their spies? How does this change with leveling?

Appreciate the help, currently I'm just making decisions based on how it feels, and I'd really like to have some numbers to back it up.
 
1) Most important is the science output of the target city and of course if the antispy buildings are present. Spy level and counter-spy (lvl) have no effect on the duration it takes as far as i know.

2) Not faster at all. CS elections are constantly every x turns (and all at the same time). The higher level spy will rig the election though should several civs have a spy in the same CS.

3) No. Only stealing a tech or catching an enemy spy trying to steal a tech lvls a spy up (and the national security agency).

4) I believe if there is no counter-spy your spy can not die and the success rate is 100%. I have no idea what determines if the target civ finds out about having been stolen from and if they know it was you. A lvl1/2/3 counter-spy has a ~33/36/40% chance to prevent tech thefts.
 
Are you sure higher level spies don't steal faster? It says in the tool tip that higher levels spies steal faster.

What's the point of leveling a spy if it doesn't make tech steals faster or rig elections faster? Only counter spying?
 
didn't know that spy lvl is at least supposed to steal faster. thought it just gave +chance to steal vs. dying.

antispy buildings say that they at least increase the length of time for an enemy spy to finish an attempt to steal a tech from your city.

also the game says a lvled spy has a +chance to succeed in rigging a CS election but nothing about shortened length; that's pretty much a standard turn cycle.
 
"A higher ranking spy will steal technologies faster, discover and kill enemy spies that are trying to steal from you more frequently, rig elections in City-States more effectively, and have a greater chance of pulling off a coup in City-State allied with another civilization. "

I want to know how the steal-time is calculated and how much of a difference each level makes.
 
To the source code!
90 minute download~

Code:
case SPY_STATE_GATHERING_INTEL:
	{
		if(pCity)
		{
			PlayerTypes eCityOwner = pCity->getOwner();
			int iBaseYieldRate = pCity->getYieldRateTimes100(YIELD_SCIENCE, false);
			iBaseYieldRate *= GC.getESPIONAGE_GATHERING_INTEL_RATE_BASE_PERCENT();
			iBaseYieldRate *= GC.getGame().getGameSpeedInfo().getSpyRatePercent();
			iBaseYieldRate /= 10000;
			int iCityEspionageModifier = pCity->GetEspionageModifier();
			int iPlayerEspionageModifier = GET_PLAYER(eCityOwner).GetEspionageModifier();
			int iTheirPoliciesEspionageModifier = GET_PLAYER(eCityOwner).GetPlayerPolicies()->GetNumericModifier(POLICYMOD_STEAL_TECH_SLOWER_MODIFIER);
			int iMyPoliciesEspionageModifier = m_pPlayer->GetPlayerPolicies()->GetNumericModifier(POLICYMOD_STEAL_TECH_FASTER_MODIFIER);
			int iFinalModifier = (iBaseYieldRate * (100 + iCityEspionageModifier + iPlayerEspionageModifier + iTheirPoliciesEspionageModifier + iMyPoliciesEspionageModifier)) / 100;

			int iResult = max(iFinalModifier, 1);
			if(iSpyIndex >= 0)
			{
				iResult *= 100 + (GC.getESPIONAGE_GATHERING_INTEL_RATE_BY_SPY_RANK_PERCENT() * m_aSpyList[iSpyIndex].m_eRank);
				iResult /= 100;
			}

			return iResult;
		}
	}

Code:
iResult *= 100 + (GC.getESPIONAGE_GATHERING_INTEL_RATE_BY_SPY_RANK_PERCENT() * m_aSpyList[iSpyIndex].m_eRank);
This is the important line. The enum for spy ranks is 0, 1, 2 for recruit, agent, and special agent, respectively. Higher ranked spies steal 25% faster per rank.

Code:
<Row Name="ESPIONAGE_GATHERING_INTEL_RATE_BY_SPY_RANK_PERCENT">
	<Value>25</Value>
</Row>
 
90 minute download, that means you've had like 30 minutes to figure out the answer.
 
If you want faster results, you will have to pay me for them.
 
Magma, can you translate that source code for those of us who are unfamiliar with reading it? Specifically in regards to what is determining the base steal rates?

Much love on the +25% steal rate per level up!
 
Code:
int iBaseYieldRate = pCity->getYieldRateTimes100(YIELD_SCIENCE, false);
iBaseYieldRate *= GC.getESPIONAGE_GATHERING_INTEL_RATE_BASE_PERCENT();
iBaseYieldRate *= GC.getGame().getGameSpeedInfo().getSpyRatePercent();
iBaseYieldRate /= 10000;

Base "intel points" per turn is the target city's science yield. (50% of the city's science yield on quick, 100% on all others) city science yield*100/10000, (i.e. science yield/100), modified by game speed.
A recruit is 0, so the second term in
Code:
iResult *= 100 + 
	(GC.getESPIONAGE_GATHERING_INTEL_RATE_BY_SPY_RANK_PERCENT() * 
	m_aSpyList[iSpyIndex].m_eRank);
is 0 and a recruit gathers 100% of normal intel points per turn.
getESPIONAGE_GATHERING_INTEL_RATE_BY_SPY_RANK_PERCENT() calls a callback function to get constants loaded from the XML.

From CalcRequired function, when spy state is gather intel:
Code:
/// CalcRequired - How much the spy is needed to do to accomplish this task
...
uint uiMaxTechCostAdjusted = m_aiMaxTechCost[ePlayer];			
uiMaxTechCostAdjusted *= GC.getESPIONAGE_GATHERING_INTEL_COST_PERCENT();
uiMaxTechCostAdjusted /= 100;
...snipped irrelevant debug lines
return iMaxTechCostAdjusted;

From globaldefines.xml:
Code:
<Row Name="ESPIONAGE_GATHERING_INTEL_COST_PERCENT">
	<Value>125</Value>
</Row>
Thus, the amount of intel points required to steal a tech is 125% of the beaker cost of the most expensive tech available for stealing the victim can research, which is calculated in the function BuildStealableTechList.

Again, GC.getALL_CAPS is calling GC.getDefineINT to retrieve the value from the XML that is loaded when a new game is created. This is why changing the XML doesn't affect existing saves. That is to say, the XML holds all of the "constant" values for the game, even ones which are not currently used (eg policy modifier to slow enemy spies, civ trait modifier to spy steal speed) to make future development easier for modders, including Firaxis itself.

I don't know if target city science yield is calculated before or after the AI cheaty beaker bonus is applied. I'm thinking it is before, since 30 turns to steal a tech would mean <3 turns for most expensive tech... Then again, the AI doesn't beeline like we do to get scientific theory and plastics or dynamite...

Also, I have clearly missed a line that multiplies the rate or divides the cost by 100, or steal times would be measured in hundreds of turns
Derp, espionage base gather intel rate percent is 100
 
The source code indicates that the tech stealing rate is calculated as follows:

Step 1 - The baseline
Baseline = The Science generation of the city, adjusted by the game speed

Step 2 - Multipliers
The following "multipliers" (positive and negative) are added together and multiply the Baseline:
1) Buildings in the target city (ei: Constable, Police Station, Firewall)
2) Spy owner's policies (ei: Autocracy - Industrial Espionage)
3) Target's policies (ei: Order - Double Agents)

Step 3 - Spy rank
Spy rank (1, 2, 3) increases the total (of Baseline * multipliers) by (0%, 25%, 50%)
 
Really cool stuff, I wish I could read the code like that, it'd help answer so many of my questions.

What are the game speed modifiers?
 
Don't think we have this 100% yet.

Thus, the amount of intel points required to steal a tech is 125% of the beaker cost of the most expensive tech the victim can research

Pretty sure that isn't right. Anecdotally, stealing fishing/optics when it's the only available option tends to be lightning fast compared to contemporary techs.

Might it be 125% of the most expensive tech available for stealing? So that if I could steal fishing or a contemporary tech, the steal rate would be based on the contemporary tech, but if I could only steal fishing, it's based on the cost of fishing.

I'm going to do some tests using hotseat and post some numbers
 
Might it be 125% of the most expensive tech available for stealing? So that if I could steal fishing or a contemporary tech, the steal rate would be based on the contemporary tech, but if I could only steal fishing, it's based on the cost of fishing.
I would say that, from a conceptual point of view, it would make much more sense, and from my experience, it's true that stealing early techs when an AI doesn't have any other techs available to steal is very fast.
Now, i couldn't read that code to check for sure. However, considering the amount of pPlayers and iPlayers all over the place, it would sure be hard even for a good coder to figure out which player a variable refers to :rolleyes:
 
So, I set up a hot seat game with England, Korea and Babylon on quick speed. I'm fairly certain that starting in different eras adjusts the tech costs, so I started in ancient.

I teched England on the bottom part of the tree, ignoring pottery and and everything above it and teched Korea and Babylon as equally as I could, ignoring Mining and teching into Acoustics and towards observatories/frigates.

A few turns before I hit Ren, I stopped the cities growing so there wouldn't be changing science scores, I should have saved here, but stupidly didn't and stole a few techs to level 1 of England's spies. At this point, England has stolen pottery and sailing, and (below) is the current situation, complete with timers.

England stealing from Korea with a lvl 1 spy. England has 12 beakers/turn, Korea has 38/turn.
Available techs to steal are optics (49), Calendar (32), Writing (32), Trapping (32) and Currency (103). The average of these values is 49.6.

England's most expensive completed tech is 176 beakers (metal casting)
England's most expensive available tech is 197 (physics)
Korea's most expensive completed tech is 457 (Acoustics)
Korea's most expensive available tech is 499 (whatever the observatory tech is called)
Game speed is fast.
Reported time to steal is 7 turns.

England stealing from Babylon with a lvl 3 spy. England has 12 beakers/turn, Babylon has 39/turn.
Available techs to steal are optics (49), Calendar (32), Writing (32), Trapping (32) and Currency (103). The average of these values is 49.6.

England's most expensive completed tech is 176 beakers (metal casting)
England's most expensive available tech is 197 (physics)
Babylon's most expensive completed tech is 499 (whatever the observatory tech is calleds)
Babylon's most expensive available tech is 809 (frigate tech)
Game speed is fast.
Reported time to steal is 5 turns.

Swapping the spies, so that the level 3 goes to Korea and the level 1 to Babylon results in the times swapping, which makes me think that it probably the tech cost of the available-to-steal techs, not the highest available tech.

Let's see if we can do the math and actually hit these values.

**More Info**
Korean lvl 1 spy takes 24 turns to steal iron working at 112
Babylon lvl 3 spy takes 16 turns to steal iron working at 112
 
Might it be 125% of the most expensive tech available for stealing?

Yeah, my bad, will fix. The function is called getStealableTechList, after all. It gets the most expensive tech the thief can research that the victim has and the thief doesn't. So, what you said.
 
So:

England stealing from Korea with a level 1 spy. Korea's capital makes 38 beakers a turn, on quick this is adjusted by -50% making it 19 beakers. The most expensive tech is currency at 103. 103*1.25 is 128.75. 128.75/19 is 6.78 turns. That checks out

England stealing from Babylon with a level 3 spy. Babylon makes 39 beakers, 19.5 on quick. 19.5*1.5 (lvl 3 spy) is 29.25. 103 is the most expensive tech, 128.75 after multiplier. 128.75/29.25 is 4.4. That reflects the 5 turn in game just fine.

Korea stealing masonry. 12 science/turn, down to 6 after quick speed. Cost of the tech is 112*1.25=140 140/6=23.3, which checks out exactly.

Ok, I'm convinced. Thanks so much for checking and interpreting the code for me guys. Cheers!
 
Last question then:

If higher level spies always rig elections over lower level spies, and election rate is constant, what does the freedom policy "Covert Action" do?

What "chance" of rigging city-state elections are they actually doubling?

Is this policy only benefiting spies in city-states with other spies of the exact same level from another civ?
 
Turns out the code for rigging elections is in CvMinorCivAI.cpp, which makes sense from a programming perspective, but is highly amusing from an abstract political perspective. "Whicha yous guys rigged my election best, huh?"

When stationed in a city state, a spy earns (rank+1)^2 votes per turn. So the "been there longer=more likely to win" part affects the current election cycle only.

A function ChooseByWeight in the class CvWeightedVector determines who wins the election, and this function in turn uses a class RandomNumberDelegate who's source is in a .lib file I don't know how to open and read.

But if I had to guess, I'd say votes for this player/votes for all players is the probability of winning the election. Covert action doubles the number of votes the player has gathered.

So a special agent from a civ with that policy will have a 32/33 chance of rigging successfully against a recruit from a civ without it, assuming they both arrived in the city on the same turn.
 
Back
Top Bottom