Hooks
static bool BeforeCvDiplomacyAI_GetCoopWarScore(CvDiplomacyAI* self, PlayerTypes ePlayer, PlayerTypes eTargetPlayer, bool bAskedByPlayer, int& result);static void AfterCvDiplomacyAI_GetCoopWarScore(CvDiplomacyAI* self, PlayerTypes ePlayer, PlayerTypes eTargetPlayer, bool bAskedByPlayer, int& result);static int ReplaceCvDiplomacyAI_GetCoopWarScore(int (*original)(CvDiplomacyAI*, PlayerTypes, PlayerTypes, bool), CvDiplomacyAI* self, PlayerTypes ePlayer, PlayerTypes eTargetPlayer, bool bAskedByPlayer);CivRegisterBefore<CivHooks::CvDiplomacyAI_GetCoopWarScore>(host, &BeforeCvDiplomacyAI_GetCoopWarScore);CivRegisterAfter<CivHooks::CvDiplomacyAI_GetCoopWarScore>(host, &AfterCvDiplomacyAI_GetCoopWarScore);CivRegisterReplace<CivHooks::CvDiplomacyAI_GetCoopWarScore>(host, &ReplaceCvDiplomacyAI_GetCoopWarScore);
Code
20324/// Does this AI want to ask ePlayer to go to war with eTargetPlayer?20325int CvDiplomacyAI::GetCoopWarScore(PlayerTypes ePlayer, PlayerTypes eTargetPlayer, bool bAskedByPlayer)20326{20327 MajorCivApproachTypes eApproachTowardsPlayer = GetMajorCivApproach(ePlayer, /*bHideTrueFeelings*/ false);20328 MajorCivOpinionTypes eOpinionTowardsPlayer = GetMajorCivOpinion(ePlayer);20329 MajorCivApproachTypes eApproachTowardsTarget = GetMajorCivApproach(eTargetPlayer, /*bHideTrueFeelings*/ false);20330 MajorCivOpinionTypes eOpinionTowardsTarget = GetMajorCivOpinion(eTargetPlayer);2033120332 // Both players must be able to declare war20333 TeamTypes eTargetTeam = GET_PLAYER(eTargetPlayer).getTeam();20334#if defined(MOD_EVENTS_WAR_AND_PEACE)20335 if(!GET_TEAM(GetPlayer()->getTeam()).canDeclareWar(eTargetTeam, ePlayer))20336#else20337 if(!GET_TEAM(GetPlayer()->getTeam()).canDeclareWar(eTargetTeam))20338#endif20339 return 0;20340#if defined(MOD_EVENTS_WAR_AND_PEACE)20341 if(!GET_TEAM(GET_PLAYER(ePlayer).getTeam()).canDeclareWar(eTargetTeam, ePlayer))20342#else20343 if(!GET_TEAM(GET_PLAYER(ePlayer).getTeam()).canDeclareWar(eTargetTeam))20344#endif20345 return 0;2034620347 // If player is inquiring, he has to be planning a war already20348 if(!bAskedByPlayer)20349 {20350 if((eApproachTowardsTarget != MAJOR_CIV_APPROACH_WAR) && (eApproachTowardsTarget != MAJOR_CIV_APPROACH_DECEPTIVE))20351 return 0;20352 }2035320354 // If player is planning War, always say no20355 if(eApproachTowardsPlayer == MAJOR_CIV_APPROACH_WAR)20356 return 0;20357 // If player is Hostile, always say no20358 else if(eApproachTowardsPlayer == MAJOR_CIV_APPROACH_HOSTILE)20359 return 0;2036020361 // If player is unforgivable, always say no20362 if(eOpinionTowardsPlayer == MAJOR_CIV_OPINION_UNFORGIVABLE)20363 return 0;20364 // If player is an enemy, always say no20365 //else if (eOpinion == MAJOR_CIV_OPINION_ENEMY)20366 // return false;2036720368 // Only players we've met, are alive, etc.20369 if(!IsPlayerValid(eTargetPlayer))20370 return 0;2037120372 // Don't work Target people we're working WITH!20373 if(IsDoFAccepted(eTargetPlayer))20374 return 0;2037520376 int iWeight = 0;2037720378 // ePlayer asked us, so if we like him we're more likely to accept20379 if(bAskedByPlayer)20380 {20381 if(eApproachTowardsPlayer == MAJOR_CIV_APPROACH_FRIENDLY || eApproachTowardsPlayer == MAJOR_CIV_APPROACH_DECEPTIVE)20382 iWeight += 2;20383 else if(eOpinionTowardsPlayer >= MAJOR_CIV_OPINION_FAVORABLE)20384 iWeight += 2;20385 }2038620387 // Weight for Approach20388 if(eApproachTowardsTarget == MAJOR_CIV_APPROACH_WAR)20389 iWeight += 5;20390 if(eApproachTowardsTarget == MAJOR_CIV_APPROACH_HOSTILE)20391 iWeight += 2;2039220393 if (IsGoingForWorldConquest())20394 {20395 iWeight += 3;20396 if(eApproachTowardsTarget == MAJOR_CIV_APPROACH_DECEPTIVE)20397 iWeight += 2;20398 }20399 else if (IsGoingForDiploVictory())20400 {20401 iWeight -= 2;20402 }2040320404 // Weight for Opinion20405 if(eOpinionTowardsTarget == MAJOR_CIV_OPINION_UNFORGIVABLE)20406 iWeight += 12;20407 else if(eOpinionTowardsTarget == MAJOR_CIV_OPINION_ENEMY)20408 iWeight += 8;20409 else if(eOpinionTowardsTarget == MAJOR_CIV_OPINION_COMPETITOR)20410 iWeight += 4;20411 else if(eOpinionTowardsTarget == MAJOR_CIV_OPINION_FAVORABLE)20412 iWeight += -1;20413 else if(eOpinionTowardsTarget == MAJOR_CIV_OPINION_FRIEND)20414 iWeight += -5;20415 else if(eOpinionTowardsTarget == MAJOR_CIV_OPINION_ALLY)20416 iWeight += -10;2041720418 // Are we getting money from trade with them20419 int iCurrentTradeValue = GetPlayer()->GetTrade()->GetAllTradeValueFromPlayerTimes100(YIELD_GOLD, ePlayer) / 100;20420 if(iCurrentTradeValue > 0)20421 {20422 iWeight -= 2;2042320424 // sanity check - if we will go negative from war with this player, don't go to war20425 int iGPT = GetPlayer()->calculateGoldRate();20426 if (iGPT >= 0 && (iGPT-iCurrentTradeValue < 0))20427 {20428 iWeight -= 5;20429 }20430 }2043120432 // Weight for expanding too fast20433 if(IsPlayerRecklessExpander(eTargetPlayer))20434 {20435 iWeight += 4;20436 }2043720438 // Weight for warmonger threat20439 switch(GetWarmongerThreat(eTargetPlayer))20440 {20441 case THREAT_MINOR:20442 iWeight += 1;20443 break;20444 case THREAT_MAJOR:20445 iWeight += 3;20446 break;20447 case THREAT_SEVERE:20448 iWeight += 5;20449 break;20450 case THREAT_CRITICAL:20451 iWeight += 7;20452 break;20453 }2045420455 // If we're working with ePlayer then increase weight (if we're already willing to work Target this guy)20456 if(iWeight > 0 && IsDoFAccepted(ePlayer))20457 iWeight += 5;2045820459 // If we're working with ePlayer then increase weight (if we're already willing to work Target this guy)20460 //if (iWeight > 0 && IsWorkingAgainstPlayer(eTargetPlayer))20461 // iWeight += 4;2046220463 // Base Personality value; ranges from 0 to 10 (ish)20464 //iWeight += GetWorkTargetWillingness();2046520466 // Weight mod for target value20467 switch(GetPlayerTargetValue(eTargetPlayer))20468 {20469 case TARGET_VALUE_IMPOSSIBLE:20470 iWeight *= 66;20471 iWeight /= 100;20472 break;20473 case TARGET_VALUE_BAD:20474 iWeight *= 75;20475 iWeight /= 100;20476 break;20477 case TARGET_VALUE_AVERAGE:20478 iWeight *= 100;20479 iWeight /= 100;20480 break;20481 case TARGET_VALUE_FAVORABLE:20482 iWeight *= 110;20483 iWeight /= 100;20484 break;20485 case TARGET_VALUE_SOFT:20486 iWeight *= 120;20487 iWeight /= 100;20488 break;20489 }2049020491 // Rand20492 iWeight += GC.getGame().getJonRandNum(5, "Diplomacy AI: Rand for whether AI wants to enter a coop war.");2049320494 // Weight must be high enough for us to return a true desire20495 if(iWeight >= 15)20496 return iWeight;2049720498 return 0;20499}