Bazaar developer reference

CvPlayerEspionage::ProcessSpy(uint)

Defined in
CvEspionageClasses.cpp, line 298
Class
CvPlayerEspionage
Hook name
CivHooks::CvPlayerEspionage_ProcessSpy

Hooks

static bool BeforeCvPlayerEspionage_ProcessSpy(CvPlayerEspionage* self, uint uiSpyIndex);static void AfterCvPlayerEspionage_ProcessSpy(CvPlayerEspionage* self, uint uiSpyIndex);static void ReplaceCvPlayerEspionage_ProcessSpy(void (*original)(CvPlayerEspionage*, uint), CvPlayerEspionage* self, uint uiSpyIndex);CivRegisterBefore<CivHooks::CvPlayerEspionage_ProcessSpy>(host, &BeforeCvPlayerEspionage_ProcessSpy);CivRegisterAfter<CivHooks::CvPlayerEspionage_ProcessSpy>(host, &AfterCvPlayerEspionage_ProcessSpy);CivRegisterReplace<CivHooks::CvPlayerEspionage_ProcessSpy>(host, &ReplaceCvPlayerEspionage_ProcessSpy);

Code

297/// Process a spy and run their missions298void CvPlayerEspionage::ProcessSpy(uint uiSpyIndex)299{300	CvEspionageSpy* pSpy = &(m_aSpyList[uiSpyIndex]);301	bool bLastQualified;302	CvPlot* pCityPlot = GC.getMap().plot(pSpy->m_iCityX, pSpy->m_iCityY);303	CvCity* pCity = NULL;304	CvCityEspionage* pCityEspionage = NULL;305	PlayerTypes ePlayer = m_pPlayer->GetID();306	PlayerTypes eCityOwner = NO_PLAYER;307	if(pCityPlot)308	{309		pCity = pCityPlot->getPlotCity();310		if(pCity)311		{312			eCityOwner = pCity->getOwner();313			pCityEspionage = pCity->GetCityEspionage();314		}315	}316317	bool bHadSurveillance = HasEstablishedSurveillance(uiSpyIndex);318319	switch(pSpy->m_eSpyState)320	{321	case SPY_STATE_UNASSIGNED:322		// spy is idling323		return;324		break;325	case SPY_STATE_TRAVELLING:326		// spy is traveling to location327		CvAssertMsg(pCity, "pCity not defined. What?");328		if(!pCity)329		{330			return;331		}332		// if the spy has completed travelling, move to location333		pCityEspionage->Process(ePlayer);334		if(pCityEspionage->HasReachedGoal(ePlayer))335		{336			pCityEspionage->ResetProgress(ePlayer);337			if (pSpy->m_bIsDiplomat)338			{339#if defined(MOD_API_ESPIONAGE)340				pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_MAKING_INTRODUCTIONS);341#else342				pSpy->m_eSpyState = SPY_STATE_MAKING_INTRODUCTIONS;343#endif344				int iRate = CalcPerTurn(SPY_STATE_MAKING_INTRODUCTIONS, pCity, uiSpyIndex);345				int iGoal = CalcRequired(SPY_STATE_MAKING_INTRODUCTIONS, pCity, uiSpyIndex);346				pCityEspionage->SetActivity(ePlayer, 0, iRate, iGoal);				347			}348			else if(pCity->getTeam() == m_pPlayer->getTeam())  // moved to a friendly city349			{350				// moving to a defensive location351#if defined(MOD_API_ESPIONAGE)352				pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_COUNTER_INTEL);353#else354				pSpy->m_eSpyState = SPY_STATE_COUNTER_INTEL;355#endif356			}357			else // moved to an opponent's city358			{359#if defined(MOD_API_ESPIONAGE)360				pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_SURVEILLANCE);361#else362				pSpy->m_eSpyState = SPY_STATE_SURVEILLANCE;363#endif364				int iRate = CalcPerTurn(SPY_STATE_SURVEILLANCE, pCity, uiSpyIndex);365				int iGoal = CalcRequired(SPY_STATE_SURVEILLANCE, pCity, uiSpyIndex);366				pCityEspionage->SetActivity(ePlayer, 0, iRate, iGoal);367			}368		}369		break;370	case SPY_STATE_SURVEILLANCE:371		CvAssertMsg(pCity, "pCity not defined. What?");372		if(!pCity)373		{374			return;375		}376377		bLastQualified = pCityEspionage->HasReachedGoal(ePlayer);378		pCityEspionage->Process(ePlayer);379		if(pCityEspionage->HasReachedGoal(ePlayer))380		{381			if(GET_PLAYER(eCityOwner).isMinorCiv())382			{383#if defined(MOD_API_ESPIONAGE)384				if (!pSpy->m_bPassive) {385#endif386#if defined(MOD_API_ESPIONAGE)387				pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_RIG_ELECTION);388#else389				pSpy->m_eSpyState = SPY_STATE_RIG_ELECTION;390#endif391				pCityEspionage->ResetProgress(ePlayer);392				int iRate = CalcPerTurn(SPY_STATE_RIG_ELECTION, pCity, uiSpyIndex);393				int iGoal = CalcRequired(SPY_STATE_RIG_ELECTION, pCity, uiSpyIndex);394				pCityEspionage->SetActivity(ePlayer, 0, iRate, iGoal);395				pCityEspionage->SetLastProgress(ePlayer, iRate);396#if defined(MOD_API_ESPIONAGE)397				}398#endif399			}400			else401			{402#if defined(MOD_API_ESPIONAGE)403				if (!pSpy->m_bPassive) {404#endif405				BuildStealableTechList(eCityOwner);406				// moved rate out here to set the potential407				int iBasePotentialRate = CalcPerTurn(SPY_STATE_GATHERING_INTEL, pCity, -1);408				pCityEspionage->SetLastBasePotential(ePlayer, iBasePotentialRate);409410				if(m_aaPlayerStealableTechList[eCityOwner].size() > 0)411				{412					// TODO: need to proclaim surveillance somehow413#if defined(MOD_API_ESPIONAGE)414					pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_GATHERING_INTEL);415#else416					pSpy->m_eSpyState = SPY_STATE_GATHERING_INTEL;417#endif418					pCityEspionage->ResetProgress(ePlayer);419					int iPotentialRate = CalcPerTurn(SPY_STATE_GATHERING_INTEL, pCity, uiSpyIndex);420					int iGoal = CalcRequired(SPY_STATE_GATHERING_INTEL, pCity, uiSpyIndex);421					pCityEspionage->SetActivity(ePlayer, 0, iPotentialRate, iGoal);422					pCityEspionage->SetLastProgress(ePlayer, iPotentialRate);423					pCityEspionage->SetLastPotential(ePlayer, iPotentialRate);424				}425				else426				{427					// if this is the first time they crossed the threshold428					if(!bLastQualified)429					{430						CvNotifications* pNotifications = m_pPlayer->GetNotifications();431						if(pNotifications)432						{433							Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_CANT_STEAL_TECH_S");434							strSummary << GET_PLAYER(eCityOwner).getCivilizationInfo().getShortDescriptionKey();435							Localization::String strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_CANT_STEAL_TECH");436							strNotification << GetSpyRankName(pSpy->m_eRank);;437#if defined(MOD_BUGFIX_SPY_NAMES)438							strNotification << pSpy->GetSpyName(m_pPlayer);439#else440							strNotification << m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName);441#endif442							strNotification << GET_PLAYER(eCityOwner).getCivilizationInfo().getShortDescriptionKey();443							pNotifications->Add(NOTIFICATION_SPY_CANT_STEAL_TECH, strNotification.toUTF8(), strSummary.toUTF8(), -1, -1, -1);444						}445					}446					int iRate = CalcPerTurn(SPY_STATE_SURVEILLANCE, pCity, uiSpyIndex);447					pCityEspionage->SetLastProgress(ePlayer, iRate);448					pCityEspionage->SetLastPotential(ePlayer, -1); // set the last potential back to zero so that 449					pSpy->m_bEvaluateReassignment = true; // flag to re-evaluate because we can't steal450					if(GC.getLogging())451					{452						CvString strMsg;453						strMsg.Format("Re-eval: can't steal research, %d,", uiSpyIndex);454#if defined(MOD_BUGFIX_SPY_NAMES)455						strMsg += GetLocalizedText(pSpy->GetSpyName(m_pPlayer));456#else457						strMsg += GetLocalizedText(m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName));458#endif459						LogEspionageMsg(strMsg);460					}461462				}463#if defined(MOD_API_ESPIONAGE)464				}465#endif466				UncoverIntrigue(uiSpyIndex);467			}468		}469		break;470	case SPY_STATE_GATHERING_INTEL:471		CvAssertMsg(pCity, "pCity not defined. What?");472		if(!pCity)473		{474			return;475		}476		BuildStealableTechList(eCityOwner);477		pCityEspionage->Process(ePlayer);478		// if the rate is too low, reassign the spy479		if (pCityEspionage->m_aiRate[m_pPlayer->GetID()] < 100)480		{481			pSpy->m_bEvaluateReassignment = true;482			if(GC.getLogging())483			{484				CvString strMsg;485				strMsg.Format("Re-eval: potential too low, %d,", uiSpyIndex);486#if defined(MOD_BUGFIX_SPY_NAMES)487				strMsg += GetLocalizedText(pSpy->GetSpyName(m_pPlayer));488#else489				strMsg += GetLocalizedText(m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName));490#endif491				LogEspionageMsg(strMsg);492			}493		}494495		if(m_aaPlayerStealableTechList[eCityOwner].size() == 0)496		{497			// set the spy back to surveillance mode498			pCityEspionage->ResetProgress(ePlayer);499#if defined(MOD_API_ESPIONAGE)500			pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_SURVEILLANCE);501#else502			pSpy->m_eSpyState = SPY_STATE_SURVEILLANCE;503#endif504			pSpy->m_bEvaluateReassignment = true; // flag for reassignment505			if(GC.getLogging())506			{507				CvString strMsg;508				strMsg.Format("Re-eval: m_aaPlayerStealableTechList[eCityOwner].size() == 0, %d,", uiSpyIndex);509#if defined(MOD_BUGFIX_SPY_NAMES)510				strMsg += GetLocalizedText(pSpy->GetSpyName(m_pPlayer));511#else512				strMsg += GetLocalizedText(m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName));513#endif514				LogEspionageMsg(strMsg);515			}516517			int iRate = CalcPerTurn(SPY_STATE_SURVEILLANCE, pCity, uiSpyIndex);518			int iGoal = CalcRequired(SPY_STATE_SURVEILLANCE, pCity, uiSpyIndex);519			int iAmount = iGoal; // put the player back at surveillance levels520			pCityEspionage->SetActivity(ePlayer, iAmount, iRate, iGoal);521522			// set last progress rate523			iRate = CalcPerTurn(SPY_STATE_GATHERING_INTEL, pCity, uiSpyIndex);524			pCityEspionage->SetLastProgress(ePlayer, iRate);525526			// can't steal any techs from this civ527			m_aiNumTechsToStealList[eCityOwner] = 0;528529			CvNotifications* pNotifications = m_pPlayer->GetNotifications();530			if(pNotifications)531			{532				Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_CANT_STEAL_TECH_S");533				strSummary << GET_PLAYER(eCityOwner).getCivilizationInfo().getShortDescriptionKey();534				Localization::String strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_CANT_STEAL_TECH");535				strNotification << GetSpyRankName(pSpy->m_eRank);;536#if defined(MOD_BUGFIX_SPY_NAMES)537				strNotification << pSpy->GetSpyName(m_pPlayer);538#else539				strNotification << m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName);540#endif541				strNotification << GET_PLAYER(eCityOwner).getCivilizationInfo().getShortDescriptionKey();542				pNotifications->Add(NOTIFICATION_SPY_CANT_STEAL_TECH, strNotification.toUTF8(), strSummary.toUTF8(), -1, -1, -1);543			}544		}545		else if(pCityEspionage->HasReachedGoal(ePlayer))546		{547			HeistLocation kHeistLocation;548			kHeistLocation.m_iX = pCity->getX();549			kHeistLocation.m_iY = pCity->getY();550			m_aHeistLocations[eCityOwner].push_back(kHeistLocation);551552			int iSpyResult;553			if(pCityEspionage->HasCounterSpy())554			{555				iSpyResult = GC.getGame().getJonRandNum(300, "Random roll for the result of a spy mission with a counterspy in the city");556				int iCounterspyIndex = GET_PLAYER(eCityOwner).GetEspionage()->GetSpyIndexInCity(pCity);557				iSpyResult += GET_PLAYER(eCityOwner).GetEspionage()->m_aSpyList[iCounterspyIndex].m_eRank * 30;558				iSpyResult *= (100 + GET_PLAYER(pCity->getOwner()).GetPlayerPolicies()->GetNumericModifier(POLICYMOD_CATCH_SPIES_MODIFIER));559				iSpyResult /= 100;560				if(iSpyResult < 100)561				{562#if defined(MOD_EVENTS_ESPIONAGE)563					pCityEspionage->SetSpyResult(ePlayer, uiSpyIndex, SPY_RESULT_DETECTED);564#else565					pCityEspionage->SetSpyResult(ePlayer, SPY_RESULT_DETECTED);566#endif567				}568				else if(iSpyResult < 200)569				{570#if defined(MOD_EVENTS_ESPIONAGE)571					pCityEspionage->SetSpyResult(ePlayer, uiSpyIndex, SPY_RESULT_IDENTIFIED);572#else573					pCityEspionage->SetSpyResult(ePlayer, SPY_RESULT_IDENTIFIED);574#endif575				}576				else577				{578#if defined(MOD_EVENTS_ESPIONAGE)579					pCityEspionage->SetSpyResult(ePlayer, uiSpyIndex, SPY_RESULT_KILLED);580#else581					pCityEspionage->SetSpyResult(ePlayer, SPY_RESULT_KILLED);582#endif583584#if !defined(NO_ACHIEVEMENTS)585					CvPlayerAI& kCityOwner = GET_PLAYER(eCityOwner);586					CvPlayerAI& kSpyOwner = GET_PLAYER(ePlayer);587588					if(	strcmp(kCityOwner.getCivilizationTypeKey(), "CIVILIZATION_RUSSIA") == 0 &&589						strcmp(kSpyOwner.getCivilizationTypeKey(), "CIVILIZATION_ENGLAND") == 0)590					{591						//Do not trigger achievement if we're in the Smokey Skies scenario.592						bool bUsingXP1Scenario3 = gDLL->IsModActivated(CIV5_XP1_SCENARIO3_MODID);593						if(!bUsingXP1Scenario3)594						{595							if(eCityOwner == GC.getGame().getActivePlayer())596								gDLL->UnlockAchievement(ACHIEVEMENT_XP1_25);597						}598					}599#endif600				}601			}602			else603			{604				iSpyResult = GC.getGame().getJonRandNum(300, "Random roll for the result of a spying mission without a counterspy in the city");605				iSpyResult *= (100 + GET_PLAYER(pCity->getOwner()).GetPlayerPolicies()->GetNumericModifier(POLICYMOD_CATCH_SPIES_MODIFIER));606				iSpyResult /= 100;607				if(iSpyResult < 100)608				{609#if defined(MOD_EVENTS_ESPIONAGE)610					pCityEspionage->SetSpyResult(ePlayer, uiSpyIndex, SPY_RESULT_UNDETECTED);611#else612					pCityEspionage->SetSpyResult(ePlayer, SPY_RESULT_UNDETECTED);613#endif614				}615				else if(iSpyResult < 200)616				{617#if defined(MOD_EVENTS_ESPIONAGE)618					pCityEspionage->SetSpyResult(ePlayer, uiSpyIndex, SPY_RESULT_DETECTED);619#else620					pCityEspionage->SetSpyResult(ePlayer, SPY_RESULT_DETECTED);621#endif622				}623				else624				{625#if defined(MOD_EVENTS_ESPIONAGE)626					pCityEspionage->SetSpyResult(ePlayer, uiSpyIndex, SPY_RESULT_IDENTIFIED);627#else628					pCityEspionage->SetSpyResult(ePlayer, SPY_RESULT_IDENTIFIED);629#endif630				}631			}632633			CvPlayerEspionage* pDefendingPlayerEspionage = GET_PLAYER(eCityOwner).GetEspionage();634			CvAssertMsg(pDefendingPlayerEspionage, "Defending player espionage is null");635			if(pDefendingPlayerEspionage)636			{637				pDefendingPlayerEspionage->AddSpyMessage(pCity->getX(), pCity->getY(), m_pPlayer->GetID(), pCityEspionage->m_aiResult[ePlayer], NO_TECH);638			}639640			CvDiplomacyAI* pDefendingPlayerDiploAI = GET_PLAYER(eCityOwner).GetDiplomacyAI();641			CvAssertMsg(pDefendingPlayerDiploAI, "Defending player diplo AI is null");642			if(pDefendingPlayerDiploAI)643			{644				if(pCityEspionage->m_aiResult[ePlayer] == SPY_RESULT_IDENTIFIED || pCityEspionage->m_aiResult[ePlayer] == SPY_RESULT_KILLED)645				{646					pDefendingPlayerDiploAI->ChangeNumTimesRobbedBy(ePlayer, 1);647				}648			}649650			// spy killed in action651			if(pCityEspionage->m_aiResult[ePlayer] == SPY_RESULT_KILLED)652			{653				CvNotifications* pNotifications = m_pPlayer->GetNotifications();654				if(pNotifications)655				{656					Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_WAS_KILLED_S");657#if defined(MOD_BUGFIX_SPY_NAMES)658					strSummary << pSpy->GetSpyName(m_pPlayer);659#else660					strSummary << m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName);661#endif662					Localization::String strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_WAS_KILLED");663					strNotification << GetSpyRankName(pSpy->m_eRank);664#if defined(MOD_BUGFIX_SPY_NAMES)665					strNotification << pSpy->GetSpyName(m_pPlayer);666#else667					strNotification << m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName);668#endif669					strNotification << GET_PLAYER(eCityOwner).getCivilizationInfo().getShortDescriptionKey();670					strNotification << pCity->getNameKey();671					pNotifications->Add(NOTIFICATION_SPY_WAS_KILLED, strNotification.toUTF8(), strSummary.toUTF8(), -1, -1, -1);672673				}674675				CvEspionageAI* pEspionageAI = m_pPlayer->GetEspionageAI();676				CvAssertMsg(pEspionageAI, "pEspionageAI is null");677				if(pEspionageAI)678				{679					pEspionageAI->m_aiTurnLastSpyDied[eCityOwner] = GC.getGame().getGameTurn();680					pEspionageAI->m_aiNumSpiesDied[eCityOwner]++;681				}682				CvEspionageAI* pDefenderEspionageAI = GET_PLAYER(eCityOwner).GetEspionageAI();683				CvAssertMsg(pDefenderEspionageAI, "pDefenderEspionageAI is null");684				if(pDefenderEspionageAI)685				{686					pDefenderEspionageAI->m_aiTurnLastSpyKilled[m_pPlayer->GetID()] = GC.getGame().getGameTurn();687					pDefenderEspionageAI->m_aiNumSpiesKilled[m_pPlayer->GetID()]++;688				}689690				// level up the defending spy691				int iDefendingSpy = pCityEspionage->m_aiSpyAssignment[eCityOwner];692				if(pDefendingPlayerEspionage)693				{694					CvAssertMsg(iDefendingSpy >= 0, "No defending spy. This is ok if debugging and killing a spy without having a defending spy present, but should not occur when playing the game normally.");695					if(iDefendingSpy >= 0)696					{697						pDefendingPlayerEspionage->LevelUpSpy(iDefendingSpy);698					}699				}700701				// kill spy off702				ExtractSpyFromCity(uiSpyIndex); // move the dead body out so that someone else can move in703#if defined(MOD_API_ESPIONAGE)704				pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_DEAD); // have to official kill him after the extraction705#else706				pSpy->m_eSpyState = SPY_STATE_DEAD; // have to official kill him after the extraction707#endif708709				if(GC.getLogging())710				{711					CvString strMsg;712					strMsg.Format("Killed, %d,", uiSpyIndex);713#if defined(MOD_BUGFIX_SPY_NAMES)714					strMsg += GetLocalizedText(m_aSpyList[uiSpyIndex].GetSpyName(m_pPlayer));715#else716					strMsg += GetLocalizedText(m_pPlayer->getCivilizationInfo().getSpyNames(m_aSpyList[uiSpyIndex].m_iName));717#endif718					strMsg += ",";719					strMsg += ",";720					strMsg += ",";721					strMsg += GET_PLAYER(eCityOwner).getCivilizationShortDescription();722					strMsg += ",";723					strMsg += pCity->getName();724					strMsg += ",";725					strMsg += "Killed";726					LogEspionageMsg(strMsg);727				}728			}729			else // spy successfully completed mission730			{731				pSpy->m_bEvaluateReassignment = true; // flag spy for reassignment732				if(GC.getLogging())733				{734					CvString strMsg;735					strMsg.Format("Re-eval: spy completed mission, %d,", uiSpyIndex);736#if defined(MOD_BUGFIX_SPY_NAMES)737					strMsg += GetLocalizedText(pSpy->GetSpyName(m_pPlayer));738#else739					strMsg += GetLocalizedText(m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName));740#endif741					LogEspionageMsg(strMsg);742				}743				int iCityOwner = (int)eCityOwner;744				m_aiNumTechsToStealList[iCityOwner] = m_aiNumTechsToStealList[iCityOwner] + 1;745				pCityEspionage->ResetProgress(ePlayer);746				int iRate = CalcPerTurn(SPY_STATE_GATHERING_INTEL, pCity, uiSpyIndex);747				int iGoal = CalcRequired(SPY_STATE_GATHERING_INTEL, pCity, uiSpyIndex);748				pCityEspionage->SetActivity(ePlayer, 0, iRate, iGoal);749				pCityEspionage->SetLastProgress(ePlayer, iRate);750				pCityEspionage->m_aiNumTimesCityRobbed[eCityOwner]++;751752				if(pCityEspionage->m_aiResult[ePlayer] == SPY_RESULT_IDENTIFIED)753				{754					CvEspionageAI* pDefenderEspionageAI = GET_PLAYER(eCityOwner).GetEspionageAI();755					CvAssertMsg(pDefenderEspionageAI, "pDefenderEspionageAI is null");756					if(pDefenderEspionageAI)757					{758						pDefenderEspionageAI->m_aiTurnLastSpyCaught[m_pPlayer->GetID()] = GC.getGame().getGameTurn();759						pDefenderEspionageAI->m_aiNumSpiesCaught[m_pPlayer->GetID()]++;760					}761				}762763				// this check was added because m_aiNumTechsToStealList was getting out of whack somehow and this is a check to prevent the UI from going haywire764				CvAssertMsg(m_aiNumTechsToStealList[iCityOwner] > 0, "m_aiNumTechsToStealList[iCityOwner] <= 0, which shouldn't happen after you succeed at stealing");765				if (m_aiNumTechsToStealList[iCityOwner] > 0)766				{767					CvNotifications* pNotifications = m_pPlayer->GetNotifications();768					if(pNotifications)769					{770						Localization::String strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SPY_STEAL_TECH_S");771						Localization::String strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_STEAL_TECH");772						strNotification << GetSpyRankName(pSpy->m_eRank);773#if defined(MOD_BUGFIX_SPY_NAMES)774						strNotification << pSpy->GetSpyName(m_pPlayer);775#else776						strNotification << m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName);777#endif778						strNotification << pCity->getNameKey();779						strNotification << GET_PLAYER(eCityOwner).getCivilizationInfo().getShortDescriptionKey();780						pNotifications->Add(NOTIFICATION_SPY_STOLE_TECH, strNotification.toUTF8(), strSummary.toUTF8(), -1, -1, eCityOwner);781					}782				}783				else784				{785					m_aiNumTechsToStealList[iCityOwner] = 0;786				}787788#if !defined(NO_ACHIEVEMENTS)789				//Achievements!790				if(m_pPlayer->GetID() == GC.getGame().getActivePlayer())791				{792					gDLL->UnlockAchievement(ACHIEVEMENT_XP1_12);793				}794#endif795796				LevelUpSpy(uiSpyIndex);797798				if(GC.getLogging())799				{800					CvString strMsg;801					strMsg.Format("Stealing tech, %d,", uiSpyIndex);802#if defined(MOD_BUGFIX_SPY_NAMES)803					strMsg += GetLocalizedText(m_aSpyList[uiSpyIndex].GetSpyName(m_pPlayer));804#else805					strMsg += GetLocalizedText(m_pPlayer->getCivilizationInfo().getSpyNames(m_aSpyList[uiSpyIndex].m_iName));806#endif807					strMsg += ",";808					strMsg += ",";809					strMsg += ",";810					strMsg += GET_PLAYER(eCityOwner).getCivilizationShortDescription();811					strMsg += ",";812					strMsg += pCity->getName();813					strMsg += ",";814					switch(pCityEspionage->m_aiResult[ePlayer])815					{816					case SPY_RESULT_UNDETECTED:817						strMsg += "Undetected";818						break;819					case SPY_RESULT_DETECTED:820						strMsg += "Detected";821						break;822					case SPY_RESULT_IDENTIFIED:823						strMsg += "Identified";824						break;825					}826					LogEspionageMsg(strMsg);827				}828			}829#if defined(MOD_API_ESPIONAGE)830			if(pSpy->m_eSpyState != SPY_STATE_DEAD && pSpy->m_eSpyState != SPY_STATE_TERMINATED)831#else832			if(pSpy->m_eSpyState != SPY_STATE_DEAD)833#endif834			{835				UncoverIntrigue(uiSpyIndex);836			}837		}838		break;839	case SPY_STATE_RIG_ELECTION:840		// resetting the value is done in MinorCivAI841		pCityEspionage->Process(ePlayer);842		break;843	case SPY_STATE_COUNTER_INTEL:844		break;845	case SPY_STATE_MAKING_INTRODUCTIONS:846		// spy is traveling to location847		CvAssertMsg(pCity, "pCity not defined. What?");848		if(!pCity)849		{850			return;851		}852		// if the spy has completed travelling, move to location853		pCityEspionage->Process(ePlayer);854		if(pCityEspionage->HasReachedGoal(ePlayer))855		{856			pCityEspionage->ResetProgress(ePlayer);857#if defined(MOD_API_ESPIONAGE)858			pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_SCHMOOZE);859#else860			pSpy->m_eSpyState = SPY_STATE_SCHMOOZE;861#endif862		}863		break;864	case SPY_STATE_SCHMOOZE:865		if(pSpy->m_eSpyState != SPY_STATE_DEAD)866		{867			UncoverIntrigue(uiSpyIndex);868		}869		break;870	case SPY_STATE_DEAD:871		pSpy->m_iReviveCounter++;872		if(pSpy->m_iReviveCounter >= iSpyTurnsToRevive)873		{874#if defined(MOD_BUGFIX_SPY_NAMES)875			GetNextSpyName(pSpy);876#else877			pSpy->m_iName = GetNextSpyName();878#endif879			pSpy->m_eRank = (CvSpyRank)m_pPlayer->GetStartingSpyRank();880#if defined(MOD_API_ESPIONAGE)881			pSpy->SetSpyState(m_pPlayer->GetID(), uiSpyIndex, SPY_STATE_UNASSIGNED);882#else883			pSpy->m_eSpyState = SPY_STATE_UNASSIGNED;884#endif885			pSpy->m_iCityX = -1;886			pSpy->m_iCityY = -1;887			pSpy->m_iReviveCounter = 0;888			pSpy->m_bEvaluateReassignment = true;889#if defined(MOD_API_ESPIONAGE)890			pSpy->m_bPassive = false;891#endif892			if(GC.getLogging())893			{894				CvString strMsg;895				strMsg.Format("Re-eval: spy killed, %d,", uiSpyIndex);896#if defined(MOD_BUGFIX_SPY_NAMES)897				strMsg += GetLocalizedText(pSpy->GetSpyName(m_pPlayer));898#else899				strMsg += GetLocalizedText(m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName));900#endif901				LogEspionageMsg(strMsg);902			}903904			CvNotifications* pNotifications = m_pPlayer->GetNotifications();905			if(pNotifications)906			{907				Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_REVIVED_S");908				Localization::String strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_REVIVED");909				strNotification << GetSpyRankName(pSpy->m_eRank);910#if defined(MOD_BUGFIX_SPY_NAMES)911				strNotification << pSpy->GetSpyName(m_pPlayer);912#else913				strNotification << m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName);914#endif915				pNotifications->Add(NOTIFICATION_SPY_REPLACEMENT, strNotification.toUTF8(), strSummary.toUTF8(), -1, -1, -1);916			}917918			if(GC.getLogging())919			{920				CvString strMsg;921				strMsg.Format("Respawned spy, %d,", uiSpyIndex);922#if defined(MOD_BUGFIX_SPY_NAMES)923				strMsg += GetLocalizedText(pSpy->GetSpyName(m_pPlayer));924#else925				strMsg += GetLocalizedText(m_pPlayer->getCivilizationInfo().getSpyNames(pSpy->m_iName));926#endif927				LogEspionageMsg(strMsg);928			}929		}930		break;931	}932933	// if we just established surveillance in the city, turn the lights on934	if(HasEstablishedSurveillance(uiSpyIndex) && !bHadSurveillance)935	{936#if defined(MOD_API_EXTENSIONS)937		pCity->plot()->changeAdjacentSight(m_pPlayer->getTeam(), GC.getESPIONAGE_SURVEILLANCE_SIGHT_RANGE(), true, NO_INVISIBLE, NO_DIRECTION);938#else939		pCity->plot()->changeAdjacentSight(m_pPlayer->getTeam(), GC.getESPIONAGE_SURVEILLANCE_SIGHT_RANGE(), true, NO_INVISIBLE, NO_DIRECTION, false);940#endif941	}942}

Calls

Called by