Hooks
static bool BeforeCvPlayerEspionage_UncoverIntrigue(CvPlayerEspionage* self, uint uiSpyIndex);static void AfterCvPlayerEspionage_UncoverIntrigue(CvPlayerEspionage* self, uint uiSpyIndex);static void ReplaceCvPlayerEspionage_UncoverIntrigue(void (*original)(CvPlayerEspionage*, uint), CvPlayerEspionage* self, uint uiSpyIndex);CivRegisterBefore<CivHooks::CvPlayerEspionage_UncoverIntrigue>(host, &BeforeCvPlayerEspionage_UncoverIntrigue);CivRegisterAfter<CivHooks::CvPlayerEspionage_UncoverIntrigue>(host, &AfterCvPlayerEspionage_UncoverIntrigue);CivRegisterReplace<CivHooks::CvPlayerEspionage_UncoverIntrigue>(host, &ReplaceCvPlayerEspionage_UncoverIntrigue);
Code
944/// UncoverIntrigue - Determine if the spy uncovers any secret information and pass it along to the player945void CvPlayerEspionage::UncoverIntrigue(uint uiSpyIndex)946{947 CvEspionageSpy* pSpy = &(m_aSpyList[uiSpyIndex]);948 CvPlot* pCityPlot = GC.getMap().plot(pSpy->m_iCityX, pSpy->m_iCityY);949 CvCity* pCity = NULL;950 CvCityEspionage* pCityEspionage = NULL;951 PlayerTypes ePlayer = m_pPlayer->GetID();952 PlayerTypes eCityOwner = NO_PLAYER;953 if(pCityPlot)954 {955 pCity = pCityPlot->getPlotCity();956 eCityOwner = pCity->getOwner();957 pCityEspionage = pCity->GetCityEspionage();958 }959960 CvAssertMsg(pCity, "Spy needs to be in city to uncover intrigue");961 if(!pCity)962 {963 return;964 }965966 CvAssertMsg(ePlayer != eCityOwner, "Uncover intrigue should not occur when a spy is in their own city");967 if(ePlayer == eCityOwner)968 {969 return;970 }971972 // make a list of the active civs973 std::vector<int> aiMajorCivIndex;974 for(int i = 0; i < MAX_MAJOR_CIVS; i++)975 {976 if(GET_PLAYER((PlayerTypes)i).isAlive())977 {978 aiMajorCivIndex.push_back(i);979 }980 }981982 // randomize that list983 for(uint ui = 0; ui < aiMajorCivIndex.size(); ui++)984 {985 int iTempValue;986 uint uiTargetSlot = GC.getGame().getJonRandNum(aiMajorCivIndex.size(), "Randomizing aiMajorCivIndex list within UncoverIntrigue");987 iTempValue = aiMajorCivIndex[ui];988 aiMajorCivIndex[ui] = aiMajorCivIndex[uiTargetSlot];989 aiMajorCivIndex[uiTargetSlot] = iTempValue;990 }991992 // go through to determine any intrigue993994 // sending out a sneak attack995 for(uint ui = 0; ui < aiMajorCivIndex.size(); ui++)996 {997 PlayerTypes eTargetPlayer = (PlayerTypes)aiMajorCivIndex[ui];998 // a player shouldn't target themselves for a sneak attack. That's strange.999 if(eTargetPlayer == eCityOwner)1000 {1001 continue;1002 }10031004 // Don't tell other civs about what the shadow ai is thinking because that's incorrect information!1005 if(GET_PLAYER(eCityOwner).isHuman())1006 {1007 continue;1008 }10091010 CvAIOperation* pSneakAttackOperation = GET_PLAYER(eCityOwner).GetMilitaryAI()->GetSneakAttackOperation(eTargetPlayer);1011 if(!pSneakAttackOperation)1012 {1013 continue;1014 }10151016 CvCity* pTargetCity = NULL;1017 int iSpyRank = m_aSpyList[uiSpyIndex].m_eRank;1018 iSpyRank += m_pPlayer->GetCulture()->GetInfluenceMajorCivSpyRankBonus(eCityOwner);10191020 if(iSpyRank >= SPY_RANK_AGENT)1021 {1022 CvPlot* pPlot = pSneakAttackOperation->GetTargetPlot();1023 if(pPlot)1024 {1025 pTargetCity = pPlot->getPlotCity();1026 }1027 }10281029 PlayerTypes eRevealedTargetPlayer = NO_PLAYER;1030 if (iSpyRank == SPY_RANK_RECRUIT)1031 {1032 eRevealedTargetPlayer = (PlayerTypes)MAX_MAJOR_CIVS; // hack to indicate that we shouldn't know the target due to our low spy rank1033 }1034 else1035 {1036 if(GET_TEAM(m_pPlayer->getTeam()).isHasMet(GET_PLAYER(eTargetPlayer).getTeam()))1037 {1038 eRevealedTargetPlayer = eTargetPlayer;1039 }1040 }10411042 switch(pSneakAttackOperation->GetOperationType())1043 {1044 case AI_OPERATION_SNEAK_CITY_ATTACK:1045 {1046 AddIntrigueMessage(m_pPlayer->GetID(), eCityOwner, eRevealedTargetPlayer, NO_BUILDING, NO_PROJECT, INTRIGUE_TYPE_ARMY_SNEAK_ATTACK, uiSpyIndex, pTargetCity, true);1047 }1048 break;1049 case AI_OPERATION_NAVAL_SNEAK_ATTACK:1050 {1051 AddIntrigueMessage(m_pPlayer->GetID(), eCityOwner, eRevealedTargetPlayer, NO_BUILDING, NO_PROJECT, INTRIGUE_TYPE_AMPHIBIOUS_SNEAK_ATTACK, uiSpyIndex, pTargetCity, true);1052 }1053 break;1054 }10551056 // If a sneak attack is reported, bust out of the loop1057 break;1058 }10591060 // building up an army1061 if(!GET_PLAYER(eCityOwner).isHuman())1062 {1063 ArmyType eArmyType = GET_PLAYER(eCityOwner).GetMilitaryAI()->GetArmyBeingBuilt();1064 if(eArmyType != NO_ARMY_TYPE)1065 {1066 switch(eArmyType)1067 {1068 case ARMY_TYPE_LAND:1069 AddIntrigueMessage(m_pPlayer->GetID(), eCityOwner, NO_PLAYER, NO_BUILDING, NO_PROJECT, INTRIGUE_TYPE_BUILDING_ARMY, uiSpyIndex, pCity, true);1070 break;1071 case ARMY_TYPE_NAVAL_INVASION:1072 AddIntrigueMessage(m_pPlayer->GetID(), eCityOwner, NO_PLAYER, NO_BUILDING, NO_PROJECT, INTRIGUE_TYPE_BUILDING_AMPHIBIOUS_ARMY, uiSpyIndex, pCity, true);1073 break;1074 }1075 }1076 }10771078 // deception!1079 CvDiplomacyAI* pTargetDiploAI = GET_PLAYER(eCityOwner).GetDiplomacyAI();1080 CvAssertMsg(pTargetDiploAI, "pTargetDiploAI is null");1081 if(!pTargetDiploAI)1082 {1083 return;1084 }10851086 for(uint ui = 0; ui < aiMajorCivIndex.size(); ui++)1087 {1088 PlayerTypes eOtherOtherPlayer = (PlayerTypes)aiMajorCivIndex[ui];1089 // doesn't make sense for player to give information on themselves1090 if(eOtherOtherPlayer == eCityOwner)1091 {1092 continue;1093 }10941095 // Don't tell other civs about what the shadow ai is thinking because that's incorrect information!1096 if(GET_PLAYER(eCityOwner).isHuman())1097 {1098 continue;1099 }11001101 MajorCivApproachTypes eSurfaceApproach = pTargetDiploAI->GetMajorCivApproach(eOtherOtherPlayer, true);1102 MajorCivApproachTypes eHonestApproach = pTargetDiploAI->GetMajorCivApproach(eOtherOtherPlayer, false);11031104 // if the current approach is a dangerous approach1105 if(eHonestApproach == MAJOR_CIV_APPROACH_DECEPTIVE || eHonestApproach == MAJOR_CIV_APPROACH_WAR)1106 {1107 // if the surface approach hides this1108 if(eSurfaceApproach == MAJOR_CIV_APPROACH_FRIENDLY || eSurfaceApproach == MAJOR_CIV_APPROACH_NEUTRAL)1109 {1110 if(GET_TEAM(GET_PLAYER(eCityOwner).getTeam()).isAtWar(GET_PLAYER(eOtherOtherPlayer).getTeam()))1111 {1112 // If the teams are already at war, this isn't notable1113 continue;1114 }11151116 if(GET_TEAM(m_pPlayer->getTeam()).isHasMet(GET_PLAYER(eOtherOtherPlayer).getTeam()))1117 {1118 AddIntrigueMessage(m_pPlayer->GetID(), eCityOwner, eOtherOtherPlayer, NO_BUILDING, NO_PROJECT, INTRIGUE_TYPE_DECEPTION, uiSpyIndex, pCity, true);1119 }1120 else1121 {1122 AddIntrigueMessage(m_pPlayer->GetID(), eCityOwner, NO_PLAYER, NO_BUILDING, NO_PROJECT, INTRIGUE_TYPE_DECEPTION, uiSpyIndex, pCity, true);1123 }1124 break; // we reported intrigue, now bail out1125 }1126 }1127 }11281129 ProjectTypes eProject = pCity->getProductionProject();1130 BuildingTypes eBuilding = pCity->getProductionBuilding();1131 bool bNotifyAboutConstruction = false;1132 if (eProject != NO_PROJECT)1133 {1134 bNotifyAboutConstruction = true;1135 }1136 else if (eBuilding != NO_BUILDING)1137 {1138 CvBuildingEntry* pBuildingInfo = GC.getBuildingInfo(eBuilding);1139 CvAssertMsg(pBuildingInfo, "pBuildingInfo is null");1140 if (pBuildingInfo)1141 {1142 if (::isWorldWonderClass(pBuildingInfo->GetBuildingClassInfo()))1143 {1144 bNotifyAboutConstruction = true;1145 }1146 }1147 }11481149 if (bNotifyAboutConstruction)1150 {1151 AddIntrigueMessage(m_pPlayer->GetID(), eCityOwner, NO_PLAYER, eBuilding, eProject, INTRIGUE_TYPE_CONSTRUCTING_WONDER, uiSpyIndex, pCity, true);1152 }1153}