Hooks
static bool BeforeCvEspionageAI_BuildMinorCityList(CvEspionageAI* self, EspionageCityList& aMinorCityList);static void AfterCvEspionageAI_BuildMinorCityList(CvEspionageAI* self, EspionageCityList& aMinorCityList);static void ReplaceCvEspionageAI_BuildMinorCityList(void (*original)(CvEspionageAI*, EspionageCityList&), CvEspionageAI* self, EspionageCityList& aMinorCityList);CivRegisterBefore<CivHooks::CvEspionageAI_BuildMinorCityList>(host, &BeforeCvEspionageAI_BuildMinorCityList);CivRegisterAfter<CivHooks::CvEspionageAI_BuildMinorCityList>(host, &AfterCvEspionageAI_BuildMinorCityList);CivRegisterReplace<CivHooks::CvEspionageAI_BuildMinorCityList>(host, &ReplaceCvEspionageAI_BuildMinorCityList);
Code
5671void CvEspionageAI::BuildMinorCityList(EspionageCityList& aMinorCityList)5672{5673 CvPlayerEspionage* pEspionage = m_pPlayer->GetEspionage();5674 CvDiplomacyAI* pDiploAI = m_pPlayer->GetDiplomacyAI();56755676 aMinorCityList.clear();56775678 int iGrowthFlavor = m_pPlayer->GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes) GC.getInfoTypeForString("FLAVOR_GROWTH"));5679 PlayerTypes eCurrentDiploThreat = NO_PLAYER;5680 int iCityStatePlan = GetCityStatePlan(&eCurrentDiploThreat);56815682 std::vector<ScoreCityEntry> aCityScores;5683 CvCity* pLoopCity = NULL;5684 int iLoop = 0;5685 for(uint ui = MAX_MAJOR_CIVS; ui < MAX_CIV_PLAYERS; ui++)5686 {5687 PlayerTypes eTargetPlayer = (PlayerTypes)ui;56885689 // only count minor civs5690 if (!GET_PLAYER(eTargetPlayer).isMinorCiv())5691 {5692 continue;5693 }56945695 if (!GET_PLAYER(eTargetPlayer).isAlive())5696 {5697 continue;5698 }56995700 // if we haven't met the civ, ignore5701 if(!GET_TEAM(m_pPlayer->getTeam()).isHasMet((GET_PLAYER(eTargetPlayer).getTeam())))5702 {5703 continue;5704 }57055706 // if at war with the minor civ, do not try to assign a spy in the city5707 if (GET_TEAM(m_pPlayer->getTeam()).isAtWar(GET_PLAYER(eTargetPlayer).getTeam()))5708 {5709 continue;5710 }57115712 CvMinorCivAI* pMinorCivAI = GET_PLAYER(eTargetPlayer).GetMinorCivAI();5713 CvMinorCivInfo* pMinorInfo = GC.getMinorCivInfo(pMinorCivAI->GetMinorCivType());5714 MinorCivApproachTypes eApproach = pDiploAI->GetMinorCivApproach(eTargetPlayer);5715 int iFriendshipWithMinor = pMinorCivAI->GetEffectiveFriendshipWithMajor(m_pPlayer->GetID());5716 5717 bool bAlreadyScoredCity = false;5718 for (pLoopCity = GET_PLAYER(eTargetPlayer).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(eTargetPlayer).nextCity(&iLoop))5719 {5720 if(!pEspionage->CanEverMoveSpyTo(pLoopCity))5721 {5722 continue;5723 }57245725 // if we've already scored a city for this minor civ, we don't need to score another because the values would be the same5726 if (bAlreadyScoredCity)5727 {5728 break;5729 }5730 bAlreadyScoredCity = true;57315732 ScoreCityEntry kEntry;5733 kEntry.m_pCity = pLoopCity;57345735 int iValue = 100;5736 switch (iCityStatePlan)5737 {5738 case PLAN_PLAY_NORMAL:5739 // If we're not protective or friendly, then don't bother with minor diplo5740 if(eApproach == MINOR_CIV_APPROACH_PROTECTIVE || eApproach == MINOR_CIV_APPROACH_FRIENDLY)5741 {5742 // Nearly everyone likes to grow5743 if(pMinorInfo->GetMinorCivTrait() == MINOR_CIV_TRAIT_MARITIME && !m_pPlayer->IsEmpireUnhappy())5744 {5745 iValue += /*20*/ GC.getMC_GIFT_WEIGHT_MARITIME_GROWTH() * iGrowthFlavor * max(1, m_pPlayer->getNumCities() / 3);5746 }57475748 // Slight negative weight towards militaristic5749 if(pMinorInfo->GetMinorCivTrait() == MINOR_CIV_TRAIT_MILITARISTIC && !pDiploAI->IsGoingForWorldConquest())5750 {5751 iValue += /*-50*/ GC.getMC_GIFT_WEIGHT_MILITARISTIC();5752 }57535754 // If they have a resource we don't have, add extra weight5755 int iResourcesWeLack = pMinorCivAI->GetNumResourcesMajorLacks(m_pPlayer->GetID());5756 if(iResourcesWeLack > 0)5757 {5758 iValue += (iResourcesWeLack* /*80*/ GC.getMC_GIFT_WEIGHT_RESOURCE_WE_NEED());5759 }57605761 // If we're protective this is worth more than if we're friendly5762 if(eApproach == MINOR_CIV_APPROACH_PROTECTIVE)5763 {5764 iValue += /*10*/ GC.getMC_GIFT_WEIGHT_PROTECTIVE();5765 }57665767 // If the minor is hostile, then reduce the weighting5768 if(pMinorCivAI->GetPersonality() == MINOR_CIV_PERSONALITY_HOSTILE)5769 {5770 iValue += /*-20*/ GC.getMC_GIFT_WEIGHT_HOSTILE();5771 }57725773 // The closer we are the better5774 if(m_pPlayer->GetProximityToPlayer(eTargetPlayer) == PLAYER_PROXIMITY_NEIGHBORS)5775 iValue += /*5*/ GC.getMC_GIFT_WEIGHT_NEIGHBORS();5776 else if(m_pPlayer->GetProximityToPlayer(eTargetPlayer) == PLAYER_PROXIMITY_CLOSE)5777 iValue += /*4*/ GC.getMC_GIFT_WEIGHT_CLOSE();5778 else if(m_pPlayer->GetProximityToPlayer(eTargetPlayer) == PLAYER_PROXIMITY_FAR)5779 iValue += /*3*/ GC.getMC_GIFT_WEIGHT_FAR();57805781 // Did we bully you recently? If so, giving you gold now would be very odd.5782 if(pMinorCivAI->IsRecentlyBulliedByMajor(m_pPlayer->GetID()))5783 {5784 iValue -= 100; //antonjs: todo: constant/XML5785 }57865787 // if we're allies5788 if (pMinorCivAI->IsAllies(m_pPlayer->GetID()))5789 {5790 // and we're secure as their allies, ignore the scoring5791 if (!pMinorCivAI->IsCloseToNotBeingAllies(m_pPlayer->GetID()))5792 {5793 iValue = 0;5794 }5795 }5796 else5797 {5798 // count however much we've invested into the friendship toward maintaining the friendship5799 iValue += iFriendshipWithMinor;5800 }5801 }58025803 if (pDiploAI->IsGoingForCultureVictory())5804 {5805 // no modifiers5806 }5807 else if (pDiploAI->IsGoingForWorldConquest())5808 {5809 if (pMinorCivAI->GetTrait() == MINOR_CIV_TRAIT_MILITARISTIC)5810 {5811 iValue += 999;5812 }5813 }5814 else if (pDiploAI->IsGoingForDiploVictory())5815 {5816 // no modifiers5817 }5818 else if (pDiploAI->IsGoingForSpaceshipVictory())5819 {5820 // no modifiers5821 }5822 else // the player doesn't know how they're going to try to win yet5823 {5824 // no modifiers5825 }5826 break;58275828 case PLAN_COLLECT_VOTES:5829 // if we're allies5830 if (pMinorCivAI->IsAllies(m_pPlayer->GetID()))5831 {5832 // and we're secure as their allies, ignore the scoring5833 if (!pMinorCivAI->IsCloseToNotBeingAllies(m_pPlayer->GetID()))5834 {5835 iValue = 0;5836 }5837 }5838 else5839 {5840 // if the minor is allied with someone else5841 if (pMinorCivAI->GetAlly() != NO_PLAYER)5842 {5843 iValue += iFriendshipWithMinor;5844 }5845 else5846 {5847 // count however much we've invested into the friendship toward maintaining the friendship5848 iValue += iFriendshipWithMinor * 2;5849 }5850 }5851 break;5852 case PLAN_ATTACK_CS_TO_PREVENT_DEFEAT:5853 // attack the least protected cities5854 if (pMinorCivAI->IsAllies(eCurrentDiploThreat))5855 {5856 iValue = MAX_INT - pMinorCivAI->GetEffectiveFriendshipWithMajor(eCurrentDiploThreat);5857 }5858 break;5859 case PLAN_DEFEND_CS_FOR_WIN:5860 // defend the least defended cities!5861 if (pMinorCivAI->IsAllies(eCurrentDiploThreat))5862 {5863 iValue = MAX_INT - pMinorCivAI->GetEffectiveFriendshipWithMajor(eCurrentDiploThreat);5864 }5865 }58665867 kEntry.m_iScore = iValue;5868 aCityScores.push_back(kEntry);5869 }5870 }58715872 // sort5873 std::stable_sort(aCityScores.begin(), aCityScores.end(), ScoreCityEntryHighEval());58745875 // transfer values to OffenseCityList5876 for(uint ui = 0; ui < aCityScores.size(); ui++)5877 {5878 aMinorCityList.push_back(aCityScores[ui].m_pCity);5879 }5880}