Bazaar developer reference

CvEspionageAI::BuildOffenseCityList(EspionageCityList &)

Defined in
CvEspionageClasses.cpp, line 5460
Class
CvEspionageAI
Hook name
CivHooks::CvEspionageAI_BuildOffenseCityList

Hooks

static bool BeforeCvEspionageAI_BuildOffenseCityList(CvEspionageAI* self, EspionageCityList& aOffenseCityList);static void AfterCvEspionageAI_BuildOffenseCityList(CvEspionageAI* self, EspionageCityList& aOffenseCityList);static void ReplaceCvEspionageAI_BuildOffenseCityList(void (*original)(CvEspionageAI*, EspionageCityList&), CvEspionageAI* self, EspionageCityList& aOffenseCityList);CivRegisterBefore<CivHooks::CvEspionageAI_BuildOffenseCityList>(host, &BeforeCvEspionageAI_BuildOffenseCityList);CivRegisterAfter<CivHooks::CvEspionageAI_BuildOffenseCityList>(host, &AfterCvEspionageAI_BuildOffenseCityList);CivRegisterReplace<CivHooks::CvEspionageAI_BuildOffenseCityList>(host, &ReplaceCvEspionageAI_BuildOffenseCityList);

Code

5460void CvEspionageAI::BuildOffenseCityList(EspionageCityList& aOffenseCityList)5461{5462	CvPlayerEspionage* pEspionage = m_pPlayer->GetEspionage();54635464	aOffenseCityList.clear();5465	PlayerTypes ePlayer = m_pPlayer->GetID();5466	TeamTypes eTeam = GET_PLAYER(ePlayer).getTeam();5467	CvDiplomacyAI* pDiploAI = m_pPlayer->GetDiplomacyAI();54685469	// find the most expensive available research5470	int iMaxTechCost = -1;5471	CvPlayerTechs* pMyPlayerTechs = m_pPlayer->GetPlayerTechs();54725473	for(int iTechLoop = 0; iTechLoop < GC.getNumTechInfos(); iTechLoop++)5474	{5475		const TechTypes eTech = static_cast<TechTypes>(iTechLoop);5476		CvTechEntry* pkTechInfo = GC.getTechInfo(eTech);5477		if(!pkTechInfo)5478		{5479			continue;5480		}54815482		// try to find the most expensive tech that can be researched5483		if(pMyPlayerTechs->CanResearch(eTech))5484		{5485			int iTechCost = m_pPlayer->GetPlayerTechs()->GetResearchCost(eTech) * 100;5486			if(iTechCost > iMaxTechCost)5487			{5488				iMaxTechCost = iTechCost;5489			}5490		}5491	}54925493	std::vector<ScoreCityEntry> aCityScores;5494	CvCity* pLoopCity = NULL;5495	int iLoop = 0;5496	for(uint ui = 0; ui < MAX_MAJOR_CIVS; ui++)5497	{5498		PlayerTypes eTargetPlayer = (PlayerTypes)ui;54995500		// don't count the player's own cities5501		if(eTargetPlayer == ePlayer)5502		{5503			continue;5504		}55055506		TeamTypes eTargetTeam = GET_PLAYER(eTargetPlayer).getTeam();5507		CvDiplomacyAI* pTargetDiploAI = GET_PLAYER(eTargetPlayer).GetDiplomacyAI();55085509		for(pLoopCity = GET_PLAYER(eTargetPlayer).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(eTargetPlayer).nextCity(&iLoop))5510		{5511			CvPlot* pCityPlot = pLoopCity->plot();5512			CvAssertMsg(pCityPlot, "City plot is null!");5513			if(!pCityPlot)5514			{5515				continue;5516			}55175518			if(!pCityPlot->isRevealed(GET_PLAYER(ePlayer).getTeam()))5519			{5520				continue;5521			}55225523			CvCityEspionage* pCityEspionage = pLoopCity->GetCityEspionage();55245525			int iNumRemainingTurns = MAX_INT;5526			int iSpyIndex = pEspionage->GetSpyIndexInCity(pLoopCity);5527			// if there is a spy currently stealing there, use the actual data5528			if(iSpyIndex >= 0 && pEspionage->m_aSpyList[iSpyIndex].m_eSpyState == SPY_STATE_GATHERING_INTEL)5529			{5530				if(pCityEspionage->m_aiRate[ePlayer] != 0)5531				{5532					iNumRemainingTurns = (pCityEspionage->m_aiGoal[ePlayer] - pCityEspionage->m_aiAmount[ePlayer]) / pCityEspionage->m_aiRate[ePlayer];5533				}5534			}5535			// if we have any history with the city, use that data instead5536			else if(pCityEspionage->m_aiLastBasePotential[m_pPlayer->GetID()] > 0)5537			{5538				int iCost = iMaxTechCost;5539				if(pEspionage->m_aiMaxTechCost[eTargetPlayer] > 0)5540				{5541					iCost = pEspionage->m_aiMaxTechCost[eTargetPlayer];5542				}55435544				iNumRemainingTurns = iCost / pCityEspionage->m_aiLastBasePotential[m_pPlayer->GetID()];5545			}5546			// estimate the number of turns using the population5547			else5548			{5549				int iCost = iMaxTechCost;5550				if(pEspionage->m_aiMaxTechCost[eTargetPlayer] > 0)5551				{5552					iCost = pEspionage->m_aiMaxTechCost[eTargetPlayer];5553				}5554				if(pLoopCity->getPopulation() > 0)5555				{5556					iNumRemainingTurns = iCost / (pLoopCity->getPopulation() * 100);5557				}5558			}55595560			int iDiploModifier = 1;5561			if (pDiploAI->GetWarGoal(eTargetPlayer) == WAR_GOAL_PREPARE)5562			{5563				iDiploModifier = 1;5564			}5565			else if (GET_TEAM(eTeam).isAtWar(eTargetTeam))5566			{5567				// ignore promises5568				// bonus targeting!5569				iDiploModifier = 1;5570			}5571			else // we're not at war with them, so look at other factors5572			{5573				// raise our diplo modifier by a scale of 10 so that we're less likely to target those we aren't at war with5574				iDiploModifier = 10;5575				// if we promised not to spy, make it less likely that we will spy5576				if (pDiploAI->IsPlayerStopSpyingRequestAccepted(eTargetPlayer))5577				{5578					// target far less frequently5579					iDiploModifier *= 100;5580				}55815582				// if we've denounced them or they've denounced us, spy bonus!5583				if (pDiploAI->IsDenouncedPlayer(eTargetPlayer) || pTargetDiploAI->IsDenouncedPlayer(ePlayer))5584				{5585					iDiploModifier /= 2;5586				}5587				else if (pDiploAI->IsDoFAccepted(eTargetPlayer))5588				{5589					iDiploModifier *= 50;5590				}55915592				if (GET_TEAM(eTeam).IsHasResearchAgreement(eTargetTeam))5593				{5594					iDiploModifier *= 5;5595				}55965597				if (GET_TEAM(eTeam).IsHasDefensivePact(eTargetTeam))5598				{5599					iDiploModifier *= 50;5600				}56015602				if (GET_TEAM(eTeam).IsAllowsOpenBordersToTeam(eTargetTeam))5603				{5604					iDiploModifier *= 2;5605				}56065607				if (GET_TEAM(eTargetTeam).IsAllowsOpenBordersToTeam(eTeam))5608				{5609					iDiploModifier *= 2;5610				}5611			}56125613			ScoreCityEntry kEntry;5614			kEntry.m_pCity = pLoopCity;56155616			int iScore = iNumRemainingTurns * iDiploModifier;5617			if (m_aiCivOutOfTechTurn[eTargetPlayer] == GC.getGame().getGameTurn())5618			{5619				iScore = MAX_INT;5620			}5621			else if(m_aiCivOutOfTechTurn[eTargetPlayer] > 0)5622			{5623				iScore = iScore * m_aiCivOutOfTechTurn[eTargetPlayer];5624			}56255626			kEntry.m_iScore = iScore;56275628			aCityScores.push_back(kEntry);5629		}5630	}56315632	// sort5633	std::stable_sort(aCityScores.begin(), aCityScores.end(), ScoreCityEntryLowEval());56345635	// transfer values to OffenseCityList5636	for(uint ui = 0; ui < aCityScores.size(); ui++)5637	{5638		aOffenseCityList.push_back(aCityScores[ui].m_pCity);5639	}5640}

Calls

Called by