Hooks
static bool BeforeCvPlayerEspionage_GetNextSpyName(CvPlayerEspionage* self, CvEspionageSpy* pSpy);static void AfterCvPlayerEspionage_GetNextSpyName(CvPlayerEspionage* self, CvEspionageSpy* pSpy);static void ReplaceCvPlayerEspionage_GetNextSpyName(void (*original)(CvPlayerEspionage*, CvEspionageSpy*), CvPlayerEspionage* self, CvEspionageSpy* pSpy);CivRegisterBefore<CivHooks::CvPlayerEspionage_GetNextSpyName>(host, &BeforeCvPlayerEspionage_GetNextSpyName);CivRegisterAfter<CivHooks::CvPlayerEspionage_GetNextSpyName>(host, &AfterCvPlayerEspionage_GetNextSpyName);CivRegisterReplace<CivHooks::CvPlayerEspionage_GetNextSpyName>(host, &ReplaceCvPlayerEspionage_GetNextSpyName);
Code
1220#if defined(MOD_BUGFIX_SPY_NAMES)1221void CvPlayerEspionage::GetNextSpyName(CvEspionageSpy* pSpy)1222{1223 // CUSTOMLOG("GetNextSpyName for %s", m_pPlayer->getCivilizationInfo().GetDescription());12241225 // This is a complete rewrite, using similiar logic to that for city names1226 // If there is a spare spy name for this player, use that1227 // Otherwise, pick a spy name not in use at random from the civs not in the game1228 // Otherwise, pick a spy name not in use at random from the civs in the game1229 // Otherwise, use the default unknown spy name12301231 // As there is now no concept of "name index", just set this to -1 (unknown)1232 pSpy->m_iName = -1;12331234 // Try to locate a spy name within the player's civ1235 if (pickSpyName(&(m_pPlayer->getCivilizationInfo()), pSpy)) {1236 return;1237 }12381239 // Try to locate a spy name not in use by a civ not in the game1240 int iMaxCivs = GC.getNumCivilizationInfos();1241 int iCivOffset = GC.getGame().getJonRandNum(iMaxCivs, "Civ offset");12421243 for (int i = 0; i < GC.getNumCivilizationInfos(); i++) {1244 const CivilizationTypes eCiv = static_cast<CivilizationTypes>((i + iCivOffset) % iMaxCivs);1245 CvCivilizationInfo* pkCivilizationInfo = GC.getCivilizationInfo(eCiv);1246 1247 if (pkCivilizationInfo != NULL && pkCivilizationInfo->getNumSpyNames() > 0) {1248 if (isCivInPlay(eCiv)) {1249 continue;1250 }12511252 if (pickSpyName(pkCivilizationInfo, pSpy)) {1253 return;1254 }1255 }1256 }12571258 // Try to locate a spy name not in use by a civ in the game1259 int iPlayerOffset = GC.getGame().getJonRandNum(MAX_MAJOR_CIVS, "Player offset");12601261 for (int i = 0; i < MAX_MAJOR_CIVS; i++) {1262 const PlayerTypes ePlayer = static_cast<PlayerTypes>((i + iPlayerOffset) % MAX_MAJOR_CIVS);1263 CvPlayerAI& thisPlayer = GET_PLAYER(ePlayer);1264 if (thisPlayer.isEverAlive() && thisPlayer.getCivilizationInfo().getNumSpyNames() > 0) {1265 if (pickSpyName(&(thisPlayer.getCivilizationInfo()), pSpy)) {1266 return;1267 }1268 }1269 }12701271 // Just use the unknown spy name1272 pSpy->m_sName = "TXT_KEY_SPY_NAME_UNKNOWN";1273 CUSTOMLOG("Using unknown spy name TXT_KEY_SPY_NAME_UNKNOWN");1274}