Code
2731/// Determine our general approach to each Player we've met2732void CvDiplomacyAI::DoUpdateMajorCivApproaches()2733{2734 int iPlayerLoop;2735 PlayerTypes eLoopPlayer;27362737 // Transfer Approaches from last turn to a separate array so we still have access to the info, then clear out the real one2738 for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)2739 {2740 m_paeApproachScratchPad[iPlayerLoop] = -1;27412742 eLoopPlayer = (PlayerTypes) iPlayerLoop;27432744 if(IsPlayerValid(eLoopPlayer))2745 {2746 m_paeApproachScratchPad[iPlayerLoop] = GetMajorCivApproach(eLoopPlayer, /*bHideTrueFeelings*/ false);2747 SetMajorCivApproach(eLoopPlayer, NO_MAJOR_CIV_APPROACH);2748 }2749 }27502751 int iHighestWeight;27522753 MajorCivOpinionTypes eOpinion;2754 int iNumCivsWeHaveThisOpinionTowards;27552756 FStaticVector<PlayerTypes, NUM_MAJOR_CIV_OPINION_TYPES* MAX_MAJOR_CIVS, true, c_eCiv5GameplayDLL, 0> vePlayerApproachOrder;2757 CvWeightedVector<PlayerTypes, MAX_MAJOR_CIVS, true> veTiedPlayerApproachWeights;2758 int iTiedPlayerVectorIndex;27592760 int iNumCivsWereLookingAt = 0;27612762 bool bAssert;27632764 // Look at the players we feel are our biggest opponents first2765 for(int iOpinionLoop = 0; iOpinionLoop < NUM_MAJOR_CIV_OPINION_TYPES; iOpinionLoop++)2766 {2767 eOpinion = (MajorCivOpinionTypes) iOpinionLoop;27682769 iNumCivsWeHaveThisOpinionTowards = GetNumMajorCivOpinion(eOpinion);27702771 if(iNumCivsWeHaveThisOpinionTowards > 0)2772 {2773 veTiedPlayerApproachWeights.clear();27742775 WarFaceTypes eWarFace; // This is not used, but must be passed into GetBestApproachTowardsMajorCiv() below27762777 // Loop through all (known) Majors and determine the order of who we pick our Approach for first2778 for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)2779 {2780 eLoopPlayer = (PlayerTypes) iPlayerLoop;27812782 if(IsPlayerValid(eLoopPlayer))2783 {2784 if(GetMajorCivOpinion(eLoopPlayer) == eOpinion)2785 {2786 // If there's only civ we feel this way about then there's no need to look at anything else2787 if(iNumCivsWeHaveThisOpinionTowards == 1)2788 {2789 iNumCivsWereLookingAt++;2790 vePlayerApproachOrder.push_back(eLoopPlayer);2791 break;2792 }2793 // More than one other leader we feel this way about - have to rank them now2794 else2795 {2796 // Just grab the highest weight for sorting later2797 GetBestApproachTowardsMajorCiv(eLoopPlayer, /*Passed by Ref*/ iHighestWeight, /*bLookAtOtherPlayers*/ false, /*bLog*/ false, /*Passed by Ref, but we won't use it*/ eWarFace);2798 veTiedPlayerApproachWeights.push_back(eLoopPlayer, iHighestWeight);2799 }2800 }2801 }2802 }28032804 // Order players2805 if(iNumCivsWeHaveThisOpinionTowards > 1)2806 {2807 veTiedPlayerApproachWeights.SortItems();28082809 // Now add sorted players to the overall vector that we'll look at in the next code block2810 for(iTiedPlayerVectorIndex = 0; iTiedPlayerVectorIndex < (int) veTiedPlayerApproachWeights.size(); iTiedPlayerVectorIndex++)2811 {2812 eLoopPlayer = (PlayerTypes) veTiedPlayerApproachWeights.GetElement(iTiedPlayerVectorIndex);28132814 // Assert for Release build!2815 if(eLoopPlayer < 0 || eLoopPlayer >= MAX_CIV_PLAYERS)2816 {2817 bAssert = true;2818 CvAssert(false);2819 }28202821 iNumCivsWereLookingAt++;2822 vePlayerApproachOrder.push_back(eLoopPlayer);2823 }2824 }2825 }2826 }28272828 // Assert for Release build!2829 if(iNumCivsWereLookingAt != (int) vePlayerApproachOrder.size())2830 {2831 bAssert = true;2832 CvAssert(false);2833 }28342835 MajorCivApproachTypes eApproach;28362837 WarFaceTypes eWarFace;28382839 // Now that we have our order for who to decide Approaches for, actually decide now!2840 for(int iPlayerVectorIndex = 0; iPlayerVectorIndex < (int) vePlayerApproachOrder.size(); iPlayerVectorIndex++)2841 {2842 eLoopPlayer = vePlayerApproachOrder[iPlayerVectorIndex];28432844 // See which Approach is best2845 eApproach = GetBestApproachTowardsMajorCiv(eLoopPlayer, /*Passed by Ref, but we won't use it*/ iHighestWeight, /*bLookAtOtherPlayers*/ true, /*bLog*/ true, /*Passed by Ref, used below*/ eWarFace);28462847 // If we're going to war and we haven't picked a War Face yet choose one2848 if(eApproach == MAJOR_CIV_APPROACH_WAR && GetWarFaceWithPlayer(eLoopPlayer) == NO_WAR_FACE_TYPE)2849 SetWarFaceWithPlayer(eLoopPlayer, eWarFace);28502851 CvAssertMsg(eApproach >= 0, "DIPLOMACY_AI: Invalid MajorCivApproachType. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");28522853 // Actually assign the (possibly) new Approach2854 SetMajorCivApproach(eLoopPlayer, eApproach);2855 }2856}