Code
2751/// Abort or start operations as appropriate given the current threats and war states2752void CvMilitaryAI::UpdateOperations()2753{2754 AI_PERF_FORMAT("Military-AI-perf.csv", ("UpdateOperations, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );27552756 int iOperationID;2757 int iNumRequiredSlots;2758 int iLandReservesUsed;2759 int iFilledSlots;27602761 int iPlayerLoop;2762 PlayerTypes eLoopPlayer;2763 WarStateTypes eWarState;2764 CvAIOperation* pOperation;27652766 MilitaryAIStrategyTypes eStrategyBarbs = (MilitaryAIStrategyTypes) GC.getInfoTypeForString("MILITARYAISTRATEGY_ERADICATE_BARBARIANS");2767 MilitaryAIStrategyTypes eStrategyFightAWar = (MilitaryAIStrategyTypes) GC.getInfoTypeForString("MILITARYAISTRATEGY_AT_WAR");2768 MilitaryAIStrategyTypes eBuildCriticalDefenses = (MilitaryAIStrategyTypes) GC.getInfoTypeForString("MILITARYAISTRATEGY_EMPIRE_DEFENSE_CRITICAL");27692770 // SEE IF THERE ARE OPERATIONS THAT NEED TO BE ABORTED27712772 // Are we willing to risk pressing forward vs. barbarians?2773 bool bWillingToAcceptRisk = (m_iTotalThreatWeight / 2) < GetBarbarianThreatTotal();2774 if(m_pPlayer->GetPlayerTraits()->GetLandBarbarianConversionPercent() > 0)2775 {2776 bWillingToAcceptRisk = true;2777 }27782779 // if they have one of our civilians2780 CvPlayerAI& BarbPlayer = GET_PLAYER(BARBARIAN_PLAYER);2781 CvUnit* pLoopUnit = NULL;2782 int iBarbLoop;2783 for (pLoopUnit = BarbPlayer.firstUnit(&iBarbLoop); pLoopUnit != NULL; pLoopUnit = BarbPlayer.nextUnit(&iBarbLoop))2784 {2785 if (pLoopUnit->GetOriginalOwner() == m_pPlayer->GetID() && (pLoopUnit->AI_getUnitAIType() == UNITAI_SETTLE || pLoopUnit->AI_getUnitAIType() == UNITAI_WORKER))2786 {2787 bWillingToAcceptRisk = true;2788 break;2789 }2790 }27912792 //2793 // Operations vs. Barbarians2794 //2795 // If have aborted the eradicate barbarian strategy or if the threat level from civs is significantly higher than from barbs, we better abort all of them2796 if(!IsUsingStrategy(eStrategyBarbs) || IsUsingStrategy(eStrategyFightAWar) || !bWillingToAcceptRisk)2797 {2798 bool bFoundOneToDelete = true;2799 while(bFoundOneToDelete)2800 {2801 bFoundOneToDelete = false;2802 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_DESTROY_BARBARIAN_CAMP, &iOperationID))2803 {2804 m_pPlayer->getAIOperation(iOperationID)->Kill(AI_ABORT_WAR_STATE_CHANGE);2805 bFoundOneToDelete = true;2806 }2807 }2808 }28092810 //2811 // Operation vs. Other Civs2812 //2813 // Are our wars over?2814 if(!IsUsingStrategy(eStrategyFightAWar))2815 {2816 bool bFoundOneToDelete = true;2817 while(bFoundOneToDelete)2818 {2819 bFoundOneToDelete = false;2820 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_BASIC_CITY_ATTACK, &iOperationID))2821 {2822 m_pPlayer->getAIOperation(iOperationID)->Kill(AI_ABORT_WAR_STATE_CHANGE);2823 bFoundOneToDelete = true;2824 }2825 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_PILLAGE_ENEMY, &iOperationID))2826 {2827 m_pPlayer->getAIOperation(iOperationID)->Kill(AI_ABORT_WAR_STATE_CHANGE);2828 bFoundOneToDelete = true;2829 }2830 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_RAPID_RESPONSE, &iOperationID))2831 {2832 m_pPlayer->getAIOperation(iOperationID)->Kill(AI_ABORT_WAR_STATE_CHANGE);2833 bFoundOneToDelete = true;2834 }2835 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_CITY_CLOSE_DEFENSE, &iOperationID))2836 {2837 m_pPlayer->getAIOperation(iOperationID)->Kill(AI_ABORT_WAR_STATE_CHANGE);2838 bFoundOneToDelete = true;2839 }2840 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_NAVAL_ATTACK, &iOperationID))2841 {2842 m_pPlayer->getAIOperation(iOperationID)->Kill(AI_ABORT_WAR_STATE_CHANGE);2843 bFoundOneToDelete = true;2844 }2845 }2846 }28472848 else2849 {2850 // Are any of our strategies inappropriate given the type of war we are fighting2851 for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)2852 {2853 eLoopPlayer = (PlayerTypes) iPlayerLoop;28542855 // Is this a player we have relations with?2856 if(eLoopPlayer != m_pPlayer->GetID() && m_pPlayer->GetDiplomacyAI()->IsPlayerValid(eLoopPlayer))2857 {2858 // If we've made peace with this player, abort all operations related to him2859 // slewis - added the check for STATE_ALL_WARS_LOSING so that if the player is losing all wars, that they will cancel scheduled attacks2860 if(GET_TEAM(m_pPlayer->getTeam()).isForcePeace(GET_PLAYER(eLoopPlayer).getTeam()) || m_pPlayer->GetDiplomacyAI()->GetStateAllWars() == STATE_ALL_WARS_LOSING)2861 {2862 pOperation = GetSneakAttackOperation(eLoopPlayer);2863 if(pOperation)2864 {2865 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2866 }2867 pOperation = GetBasicAttackOperation(eLoopPlayer);2868 if(pOperation)2869 {2870 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2871 }2872 pOperation = GetShowOfForceOperation(eLoopPlayer);2873 if(pOperation)2874 {2875 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2876 }2877 pOperation = GetPureNavalAttackOperation(eLoopPlayer);2878 if(pOperation)2879 {2880 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2881 }2882 }28832884 eWarState = m_pPlayer->GetDiplomacyAI()->GetWarState(eLoopPlayer);2885 switch(eWarState)2886 {2887 // If we are dominant, shouldn't be running a defensive strategy2888 case WAR_STATE_NEARLY_WON:2889 case WAR_STATE_OFFENSIVE:2890 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_RAPID_RESPONSE, &iOperationID))2891 {2892 pOperation = m_pPlayer->getAIOperation(iOperationID);2893 if(pOperation->GetEnemy() == eLoopPlayer)2894 {2895 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2896 }2897 }2898 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_CITY_CLOSE_DEFENSE, &iOperationID))2899 {2900 pOperation = m_pPlayer->getAIOperation(iOperationID);2901 if(pOperation->GetEnemy() == eLoopPlayer)2902 {2903 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2904 }2905 }2906 break;29072908 // If we are losing, make sure attacks are not running2909 case WAR_STATE_DEFENSIVE:2910 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_BASIC_CITY_ATTACK, &iOperationID))2911 {2912 pOperation = m_pPlayer->getAIOperation(iOperationID);2913 if(pOperation->GetEnemy() == eLoopPlayer)2914 {2915 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2916 }2917 }2918 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_PILLAGE_ENEMY, &iOperationID))2919 {2920 pOperation = m_pPlayer->getAIOperation(iOperationID);2921 if(pOperation->GetEnemy() == eLoopPlayer)2922 {2923 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2924 }2925 }2926 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_NAVAL_ATTACK, &iOperationID))2927 {2928 pOperation = m_pPlayer->getAIOperation(iOperationID);2929 if(pOperation->GetEnemy() == eLoopPlayer)2930 {2931 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2932 }2933 }2934 break;29352936 // If nearly defeated, call off all operations in enemy territory2937 case WAR_STATE_NEARLY_DEFEATED:2938 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_BASIC_CITY_ATTACK, &iOperationID))2939 {2940 pOperation = m_pPlayer->getAIOperation(iOperationID);2941 if(pOperation->GetEnemy() == eLoopPlayer)2942 {2943 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2944 }2945 }2946 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_PILLAGE_ENEMY, &iOperationID))2947 {2948 pOperation = m_pPlayer->getAIOperation(iOperationID);2949 if(pOperation->GetEnemy() == eLoopPlayer)2950 {2951 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2952 }2953 }2954 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_NAVAL_ATTACK, &iOperationID))2955 {2956 pOperation = m_pPlayer->getAIOperation(iOperationID);2957 if(pOperation->GetEnemy() == eLoopPlayer)2958 {2959 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2960 }2961 }2962 break;29632964 case WAR_STATE_CALM:2965 case WAR_STATE_STALEMATE:2966 default:2967 break;2968 }2969 }2970 }29712972 // Are there city defense operations for cities that no longer need defending?2973 CvCity* pLoopCity;2974 int iLoop;2975 for(pLoopCity = m_pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoop))2976 {2977 if(pLoopCity->getThreatValue() == 0)2978 {2979 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_CITY_CLOSE_DEFENSE, &iOperationID, NO_PLAYER, pLoopCity->plot()))2980 {2981 pOperation = m_pPlayer->getAIOperation(iOperationID);2982 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2983 }2984 }2985 }29862987 // Are we running a rapid response tactic and the overall threat level is very low?2988 if(m_iTotalThreatWeight <= GC.getAI_MILITARY_THREAT_WEIGHT_MAJOR())2989 {2990 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_RAPID_RESPONSE, &iOperationID))2991 {2992 pOperation = m_pPlayer->getAIOperation(iOperationID);2993 pOperation->Kill(AI_ABORT_WAR_STATE_CHANGE);2994 }2995 }2996 }29972998 // SEE WHAT OPERATIONS WE SHOULD ADD2999 //3000 // Operation vs. Barbarians3001 //3002 // If running the eradicate barbarian strategy, the threat is low (no higher than 1 major threat), we're not at war, /*and we have enough units*/, then launch a new operation.3003 // Which one is based on whether or not we saw any barbarian camps3004 if(IsUsingStrategy(eStrategyBarbs) && !IsUsingStrategy(eStrategyFightAWar) && !IsUsingStrategy(eBuildCriticalDefenses) && !m_pPlayer->haveAIOperationOfType(AI_OPERATION_DESTROY_BARBARIAN_CAMP)3005 && bWillingToAcceptRisk)3006 {3007 // We should have AI build for this3008 m_pPlayer->addAIOperation(AI_OPERATION_DESTROY_BARBARIAN_CAMP);3009 }30103011 //3012 // Operation vs. Other Civs3013 //3014 // If at war, consider launching an operation3015 if(IsUsingStrategy(eStrategyFightAWar))3016 {3017 // check nuke launches3018 // Loop through each enemy3019 for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)3020 {3021 eLoopPlayer = (PlayerTypes) iPlayerLoop;30223023 // Is this a player we have relations with?3024 if(eLoopPlayer != m_pPlayer->GetID() && m_pPlayer->GetDiplomacyAI()->IsPlayerValid(eLoopPlayer))3025 {3026 bool bLaunchNuke = false;3027 // only evaluate nukes when we have nukes and we've declared war on someone3028 if (m_pPlayer->getNumNukeUnits() > 0 && GET_TEAM(m_pPlayer->getTeam()).isAtWar(GET_PLAYER(eLoopPlayer).getTeam())) 3029 {3030 // they nuked us, so we can nuke them.3031 if (m_pPlayer->GetDiplomacyAI()->GetNumTimesNuked(eLoopPlayer) > 0)3032 { 3033 bLaunchNuke = true;3034 }3035 // if we already nuked them, uhhh, keep it up!3036 else if (GET_PLAYER(eLoopPlayer).GetDiplomacyAI()->GetNumTimesNuked(m_pPlayer->GetID()) > 0)3037 {3038 bLaunchNuke = true;3039 }3040 else 3041 {3042 bool bRollForNuke = false;3043 WarProjectionTypes eLastWarProjection = m_pPlayer->GetDiplomacyAI()->GetLastWarProjection(eLoopPlayer);3044 WarProjectionTypes eCurrentWarProjection = m_pPlayer->GetDiplomacyAI()->GetWarProjection(eLoopPlayer);3045 if (eCurrentWarProjection == WAR_PROJECTION_DESTRUCTION)3046 {3047 // roll every turn3048 bRollForNuke = true;3049 }3050 else if (eCurrentWarProjection != WAR_PROJECTION_UNKNOWN && eCurrentWarProjection != NO_WAR_PROJECTION_TYPE && 3051 eLastWarProjection != WAR_PROJECTION_UNKNOWN && eLastWarProjection != NO_WAR_PROJECTION_TYPE && 3052 eCurrentWarProjection < eLastWarProjection)3053 {3054 // roll for nukes!3055 bRollForNuke = true;3056 }30573058 if (bRollForNuke)3059 {3060 int iFlavorNuke = m_pPlayer->GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes)GC.getInfoTypeForString("FLAVOR_USE_NUKE"));3061 int iRoll = GC.getGame().getJonRandNum(10, "Roll to see if we're going to nuke!");3062 int iRoll2 = GC.getGame().getJonRandNum(10, "Second roll to see if we're going to nuke!");3063 if (iRoll < iFlavorNuke && iRoll2 < iFlavorNuke)3064 {3065 bLaunchNuke = true;3066 }3067 }3068 }3069 }30703071 if (bLaunchNuke)3072 {3073 RequestNukeAttack(eLoopPlayer);3074 }30753076 }3077 }30783079 // if we're not considered to be losing all wars, then consider launching operations against other civs3080 if (m_pPlayer->GetDiplomacyAI()->GetStateAllWars() != STATE_ALL_WARS_LOSING)3081 {3082 static CvWeightedVector<CvMilitaryTarget, SAFE_ESTIMATE_NUM_CITIES* 10, true> weightedTargetList;3083 weightedTargetList.clear();30843085 // make list of scores for each player3086 for (iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)3087 {3088 eLoopPlayer = (PlayerTypes)iPlayerLoop;3089 if (eLoopPlayer == m_pPlayer->GetID() || !m_pPlayer->GetDiplomacyAI()->IsPlayerValid(eLoopPlayer))3090 {3091 continue;3092 }30933094 eWarState = m_pPlayer->GetDiplomacyAI()->GetWarState(eLoopPlayer);30953096 // if we're not at war3097 if (eWarState == NO_WAR_STATE_TYPE)3098 {3099 continue;3100 }31013102 // don't declare any operations if we are in a defensive or nearly defeated state3103 if (eWarState == WAR_STATE_DEFENSIVE || eWarState == WAR_STATE_NEARLY_DEFEATED)3104 {3105 continue;3106 }31073108 bool bRequestAttack = false;31093110 StrengthTypes eMilitaryStrength = m_pPlayer->GetDiplomacyAI()->GetPlayerMilitaryStrengthComparedToUs(eLoopPlayer);3111 TargetValueTypes eTargetType = NO_TARGET_VALUE;31123113 if(eMilitaryStrength <= STRENGTH_AVERAGE || (GC.getAI_MILITARY_IGNORE_BAD_ODDS() == 1))3114 {3115 eTargetType = m_pPlayer->GetDiplomacyAI()->GetPlayerTargetValue(eLoopPlayer);3116 if(eTargetType > TARGET_VALUE_IMPOSSIBLE)3117 {3118 bRequestAttack = true;3119 }3120 }31213122 if (!bRequestAttack)3123 {3124 continue;3125 }31263127 CvMilitaryTarget target;3128 int iScore;3129 target = FindBestAttackTarget(AI_OPERATION_BASIC_CITY_ATTACK, eLoopPlayer, &iScore);3130 if(target.m_pTargetCity)3131 {3132 int iNumUnitsWillingBuild = 1;3133 if(target.m_bAttackBySea)3134 {3135 iFilledSlots = MilitaryAIHelpers::NumberOfFillableSlots(m_pPlayer, MUFORMATION_NAVAL_INVASION, true, &iNumRequiredSlots, &iLandReservesUsed);3136 if((iNumRequiredSlots - iFilledSlots) > iNumUnitsWillingBuild || iLandReservesUsed > GetLandReservesAvailable())3137 {3138 continue;3139 }3140 }3141 else3142 {3143 iFilledSlots = MilitaryAIHelpers::NumberOfFillableSlots(m_pPlayer, (GC.getGame().getHandicapInfo().GetID() > 4 && !(GC.getMap().GetAIMapHint() & 1)) ? MUFORMATION_BIGGER_CITY_ATTACK_FORCE : MUFORMATION_BASIC_CITY_ATTACK_FORCE, false, &iNumRequiredSlots, &iLandReservesUsed);3144 if((iNumRequiredSlots - iFilledSlots) > iNumUnitsWillingBuild || iLandReservesUsed > GetLandReservesAvailable())3145 {3146 continue;3147 }3148 }3149 }3150 else3151 {3152 continue;3153 }31543155 // add logic in here for current war state3156 int iAdjustedByTargetValueScore = iScore * eTargetType;3157 weightedTargetList.push_back(target, iAdjustedByTargetValueScore);3158 }31593160 // roll from list of players3161 // make sure the list has something in it3162 if(weightedTargetList.size() != 0)3163 {3164 weightedTargetList.SortItems();3165 LogAttackTargets(AI_OPERATION_BASIC_CITY_ATTACK, m_pPlayer->GetID(), weightedTargetList);31663167 if(weightedTargetList.GetTotalWeight() > 0)3168 {3169 RandomNumberDelegate fcn;3170 fcn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum);3171 CvMilitaryTarget chosenTarget = weightedTargetList.ChooseByWeight(&fcn, "Choosing attack target by weight");31723173 // declare that attack3174 RequestSpecificAttack(chosenTarget, 1);31753176 LogChosenTarget(AI_OPERATION_BASIC_CITY_ATTACK, m_pPlayer->GetID(), chosenTarget);3177 }3178 }31793180 /*3181 for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)3182 {3183 eLoopPlayer = (PlayerTypes) iPlayerLoop;31843185 // Is this a player we have relations with?3186 if(eLoopPlayer != m_pPlayer->GetID() && m_pPlayer->GetDiplomacyAI()->IsPlayerValid(eLoopPlayer))3187 {3188 eWarState = m_pPlayer->GetDiplomacyAI()->GetWarState(eLoopPlayer);31893190 switch(eWarState)3191 {3192 // If roughly equal in number, let's try to annoy him with raids3193 case WAR_STATE_STALEMATE:3194 //iFilledSlots = MilitaryAIHelpers::NumberOfFillableSlots(m_pPlayer, MUFORMATION_FAST_PILLAGERS, false, &iNumRequiredSlots, &iLandReservesUsed);31953196 //// Not willing to build units to get this off the ground3197 //if(iFilledSlots >= iNumRequiredSlots && iLandReservesUsed <= GetLandReservesAvailable())3198 //{3199 // m_pPlayer->addAIOperation(AI_OPERATION_PILLAGE_ENEMY, eLoopPlayer);3200 //}3201 //break;32023203 // If we are dominant, time to take down one of his cities3204 case WAR_STATE_NEARLY_WON:3205 case WAR_STATE_OFFENSIVE:3206 RequestBasicAttack(eLoopPlayer, 1);3207 break;32083209 // No one near the other, let's look at a strength comparison before deciding what to do3210 case WAR_STATE_CALM:3211 {3212 bool bRequestAttack = false;32133214 // slewis - add callbacks here to see if we need to attack anyways3215 StrengthTypes eMilitaryStrength = m_pPlayer->GetDiplomacyAI()->GetPlayerMilitaryStrengthComparedToUs(eLoopPlayer);32163217 bool bAttackAnyway = true;32183219 if(eMilitaryStrength <= STRENGTH_AVERAGE || bAttackAnyway)3220 {3221 TargetValueTypes eTargetType = m_pPlayer->GetDiplomacyAI()->GetPlayerTargetValue(eLoopPlayer);3222 if(eTargetType > TARGET_VALUE_IMPOSSIBLE)3223 {3224 bRequestAttack = true;3225 }3226 }32273228 if(bRequestAttack)3229 {3230 RequestBasicAttack(eLoopPlayer, 1);3231 }3232 //else3233 //{3234 // iFilledSlots = MilitaryAIHelpers::NumberOfFillableSlots(m_pPlayer, MUFORMATION_FAST_PILLAGERS, false, &iNumRequiredSlots, &iLandReservesUsed);32353236 // // Not willing to build units to get this off the ground3237 // if(iFilledSlots >= iNumRequiredSlots && iLandReservesUsed <= GetLandReservesAvailable())3238 // {3239 // m_pPlayer->addAIOperation(AI_OPERATION_PILLAGE_ENEMY, eLoopPlayer);3240 // }3241 //}3242 }32433244 case WAR_STATE_DEFENSIVE:3245 case WAR_STATE_NEARLY_DEFEATED:3246 {3247 //CvCity *pThreatenedCity;3248 //int iOperationID;32493250 //// Start by seeing if we have a city that needs defense3251 //for (int iI = 0; iI < m_pPlayer->getNumCities(); iI++)3252 //{3253 // pThreatenedCity = GetMostThreatenedCity(iI);3254 // if (pThreatenedCity == NULL)3255 // {3256 // break;3257 // }32583259 // // Do we already have an operation protecting this city?3260 // if (!m_pPlayer->haveAIOperationOfType(AI_OPERATION_CITY_CLOSE_DEFENSE, &iOperationID, NO_PLAYER, pThreatenedCity->plot()))3261 // {3262 // iFilledSlots = MilitaryAIHelpers::NumberOfFillableSlots(m_pPlayer, MUFORMATION_CLOSE_CITY_DEFENSE, false, &iNumRequiredSlots);32633264 // // Not willing to build units to get this off the ground3265 // if (iFilledSlots >= iNumRequiredSlots)3266 // {3267 // m_pPlayer->addAIOperation(AI_OPERATION_CITY_CLOSE_DEFENSE, eLoopPlayer);3268 // }3269 // }3270 //}32713272 //// With any extra defensive bandwidth let's add rapid response forces3273 //iFilledSlots = MilitaryAIHelpers::NumberOfFillableSlots(m_pPlayer, MUFORMATION_RAPID_RESPONSE_FORCE, false, &iNumRequiredSlots);32743275 //// Not willing to build units to get this off the ground3276 //if (iFilledSlots >= iNumRequiredSlots)3277 //{3278 // m_pPlayer->addAIOperation(AI_OPERATION_RAPID_RESPONSE, eLoopPlayer);3279 //}3280 }3281 break;32823283 default:3284 break;3285 }3286 }3287 }*/3288 }3289 3290 // naval attack3291 for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)3292 {3293 eLoopPlayer = (PlayerTypes) iPlayerLoop;3294 // Is this a player we have relations with?3295 if(eLoopPlayer != m_pPlayer->GetID() && m_pPlayer->GetDiplomacyAI()->IsPlayerValid(eLoopPlayer))3296 {3297 eWarState = m_pPlayer->GetDiplomacyAI()->GetWarState(eLoopPlayer);32983299 // if we're not at war3300 if (eWarState == NO_WAR_STATE_TYPE)3301 {3302 continue;3303 }33043305 // Naval operations as part of a war effort, but only one at a time3306 bool bHasOperationUnderway = m_pPlayer->haveAIOperationOfType(AI_OPERATION_PURE_NAVAL_CITY_ATTACK, &iOperationID, NO_PLAYER);3307 if (!bHasOperationUnderway)3308 {3309 RequestPureNavalAttack(eLoopPlayer, 1);3310 }3311 }3312 }3313 }33143315 //3316 // Naval operations (vs. opportunity targets)3317 //3318 // Total number of these operations can't exceed (FLAVOR_NAVAL / 2)3319 int iFlavorNaval = m_pPlayer->GetFlavorManager()->GetPersonalityIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_NAVAL"));3320 int iNumSuperiority = m_pPlayer->numOperationsOfType(AI_OPERATION_NAVAL_SUPERIORITY);3321 int iNumBombard = m_pPlayer->numOperationsOfType(AI_OPERATION_NAVAL_BOMBARDMENT);3322 int iMaxOperations = iFlavorNaval / 2;3323 if(GC.getMap().GetAIMapHint() & 1)3324 {3325 iMaxOperations *= 2;3326 }33273328 if((iNumSuperiority + iNumBombard) <= iMaxOperations)3329 {3330 iFilledSlots = MilitaryAIHelpers::NumberOfFillableSlots(m_pPlayer, MUFORMATION_NAVAL_SQUADRON, true, &iNumRequiredSlots);33313332 // Not willing to build units to get this off the ground3333 if(iFilledSlots >= iNumRequiredSlots)3334 {3335 // If I have a colonization operation underway, start up naval superiority as extra escorts3336 if(m_pPlayer->haveAIOperationOfType(AI_OPERATION_QUICK_COLONIZE, &iOperationID))3337 {3338 m_pPlayer->addAIOperation(AI_OPERATION_NAVAL_SUPERIORITY, NO_PLAYER);3339 return;3340 }3341 else if (IsUsingStrategy(eStrategyFightAWar))3342 {3343 m_pPlayer->addAIOperation(AI_OPERATION_NAVAL_SUPERIORITY, NO_PLAYER);3344 return;3345 }3346 }33473348 iFilledSlots = MilitaryAIHelpers::NumberOfFillableSlots(m_pPlayer, MUFORMATION_NAVAL_BOMBARDMENT, true, &iNumRequiredSlots);33493350 // Not willing to build units to get this off the ground3351 if(iFilledSlots >= iNumRequiredSlots)3352 {3353 // If fighting off barbarians, start naval bombardment, but only if don't have one3354 if(iNumBombard == 0 && IsUsingStrategy(eStrategyBarbs))3355 {3356 m_pPlayer->addAIOperation(AI_OPERATION_NAVAL_BOMBARDMENT, NO_PLAYER);3357 return;3358 }3359 }3360 }3361}