Hooks
static bool BeforeCvDiplomacyAI_DoTestCoopWarDesire(CvDiplomacyAI* self, PlayerTypes ePlayer, PlayerTypes& eChosenTargetPlayer, bool& result);static void AfterCvDiplomacyAI_DoTestCoopWarDesire(CvDiplomacyAI* self, PlayerTypes ePlayer, PlayerTypes& eChosenTargetPlayer, bool& result);static bool ReplaceCvDiplomacyAI_DoTestCoopWarDesire(bool (*original)(CvDiplomacyAI*, PlayerTypes, PlayerTypes&), CvDiplomacyAI* self, PlayerTypes ePlayer, PlayerTypes& eChosenTargetPlayer);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoTestCoopWarDesire>(host, &BeforeCvDiplomacyAI_DoTestCoopWarDesire);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoTestCoopWarDesire>(host, &AfterCvDiplomacyAI_DoTestCoopWarDesire);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoTestCoopWarDesire>(host, &ReplaceCvDiplomacyAI_DoTestCoopWarDesire);
Code
20242/// Do we want to declare war on anyone with ePlayer?20243bool CvDiplomacyAI::DoTestCoopWarDesire(PlayerTypes ePlayer, PlayerTypes& eChosenTargetPlayer)20244{20245 MajorCivApproachTypes eApproach = GetMajorCivApproach(ePlayer, /*bHideTrueFeelings*/ false);2024620247 // If player is planning War, always say no20248 if(eApproach == MAJOR_CIV_APPROACH_WAR)20249 return false;20250 // If player is Hostile, always say no20251 else if(eApproach == MAJOR_CIV_APPROACH_HOSTILE)20252 return false;2025320254 MajorCivOpinionTypes eOpinion = GetMajorCivOpinion(ePlayer);2025520256 // If player is unforgivable, always say no20257 if(eOpinion == MAJOR_CIV_OPINION_UNFORGIVABLE)20258 return false;20259 // If player is an enemy, always say no20260 //else if (eOpinion == MAJOR_CIV_OPINION_ENEMY)20261 // return false;2026220263 PlayerTypes eBestPlayer = NO_PLAYER;20264 int iBestPlayerScore = 0;2026520266 int iTempScore;2026720268 // Loop through all players to see if we can find a good target20269 PlayerTypes eTargetPlayerLoop;20270 for(int iTargetPlayerLoop = 0; iTargetPlayerLoop < MAX_MAJOR_CIVS; iTargetPlayerLoop++)20271 {20272 eTargetPlayerLoop = (PlayerTypes) iTargetPlayerLoop;2027320274 // Player must be valid20275 if(!IsPlayerValid(eTargetPlayerLoop))20276 continue;2027720278 // Don't test player Target himself20279 if(eTargetPlayerLoop == ePlayer)20280 continue;2028120282 // Have we already made the agreement?20283 if(GetCoopWarAcceptedState(ePlayer, eTargetPlayerLoop) != NO_COOP_WAR_STATE)20284 continue;2028520286 // 30 turn buffer if we've been rejected before20287 if(GetCoopWarCounter(ePlayer, eTargetPlayerLoop) >= 0 && GetCoopWarCounter(ePlayer, eTargetPlayerLoop) < 30)20288 continue;2028920290 iTempScore = GetCoopWarScore(ePlayer, eTargetPlayerLoop, /*bAskedByPlayer*/ false);2029120292 if(iTempScore > iBestPlayerScore)20293 {20294 iBestPlayerScore = iTempScore;20295 eBestPlayer = eTargetPlayerLoop;20296 }20297 }2029820299 // Found someone?20300 if(eBestPlayer != NO_PLAYER)20301 {20302 eChosenTargetPlayer = eBestPlayer;20303 return true;20304 }2030520306 return false;20307}