void CvDiplomacyAI::DoRelationshipPairing()
{
// Loop through all (known) Players
for (int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)
{
PlayerTypes ePlayer = (PlayerTypes)iPlayerLoop;
int iEnemyWeight = GetMeanness();
int iDPWeight = GetDiploBalance();
int iDoFWeight = GetDoFWillingness();
m_paiCompetitorValue[ePlayer] = 0;
m_paiDefensivePactValue[ePlayer] = 0;
m_paiDoFValue[ePlayer] = 0;
if (IsPlayerValid(ePlayer))
{
//Let's build the competitor list first.
MajorCivApproachTypes eApproach = GetMajorCivApproach(ePlayer, /*bHideTrueFeelings*/ false);
MajorCivOpinionTypes eOpinion = GetMajorCivOpinion(ePlayer);
switch (eApproach)
{
case MAJOR_CIV_APPROACH_WAR:
iEnemyWeight += 10;
iDPWeight -= 10;
iDoFWeight -= 10;
break;
case MAJOR_CIV_APPROACH_HOSTILE:
iEnemyWeight += 7;
iDPWeight -= 7;
iDoFWeight -= 7;
break;
case MAJOR_CIV_APPROACH_GUARDED:
iEnemyWeight += 5;
iDPWeight -= 5;
iDoFWeight -= 5;
break;
case MAJOR_CIV_APPROACH_DECEPTIVE:
iEnemyWeight += 3;
iDPWeight += 3;
iDoFWeight += 1;
break;
case MAJOR_CIV_APPROACH_NEUTRAL:
iEnemyWeight += 0;
iDPWeight += 1;
iDoFWeight += 1;
break;
case MAJOR_CIV_APPROACH_AFRAID:
iEnemyWeight += 1;
iDPWeight += 5;
iDoFWeight += 3;
break;
case MAJOR_CIV_APPROACH_FRIENDLY:
iEnemyWeight += -5;
iDPWeight += 5;
iDoFWeight += 5;
break;
}
switch (eOpinion)
{
case MAJOR_CIV_OPINION_UNFORGIVABLE:
iEnemyWeight += 10;
iDPWeight += -10;
iDoFWeight += -10;
break;
case MAJOR_CIV_OPINION_ENEMY:
iEnemyWeight += 5;
iDPWeight += -5;
iDoFWeight += -5;
break;
case MAJOR_CIV_OPINION_COMPETITOR:
iEnemyWeight += 3;
iDPWeight += -3;
iDoFWeight += -3;
break;
case MAJOR_CIV_OPINION_NEUTRAL:
iEnemyWeight += 0;
iDPWeight += 1;
iDoFWeight += 1;
break;
case MAJOR_CIV_OPINION_FAVORABLE:
iEnemyWeight += -3;
iDPWeight += 3;
iDoFWeight += 3;
break;
case MAJOR_CIV_OPINION_FRIEND:
iEnemyWeight += -5;
iDPWeight += 5;
iDoFWeight += 5;
break;
case MAJOR_CIV_OPINION_ALLY:
iEnemyWeight += -10;
iDPWeight += 10;
iDoFWeight += 10;
break;
}
// Military Strength compared to us
switch (GetPlayerMilitaryStrengthComparedToUs(ePlayer))
{
case STRENGTH_PATHETIC:
iEnemyWeight += -5;
iDPWeight += -5;
iDoFWeight += -5;
break;
case STRENGTH_WEAK:
iEnemyWeight += -3;
iDPWeight += -3;
iDoFWeight += 1;
break;
case STRENGTH_POOR:
iEnemyWeight += -1;
iDPWeight += -1;
iDoFWeight += 2;
break;
case STRENGTH_AVERAGE:
iEnemyWeight += 1;
iDPWeight += 3;
iDoFWeight += 5;
break;
case STRENGTH_STRONG:
iEnemyWeight += 3;
iDPWeight += 5;
iDoFWeight += 3;
break;
case STRENGTH_POWERFUL:
iEnemyWeight += 5;
iDPWeight += 7;
iDoFWeight += 1;
break;
case STRENGTH_IMMENSE:
iEnemyWeight += 7;
iDPWeight += 10;
iDoFWeight += -3;
break;
}
// Economic Strength compared to us
switch (GetPlayerEconomicStrengthComparedToUs(ePlayer))
{
case STRENGTH_PATHETIC:
iEnemyWeight += -5;
iDPWeight += -5;
iDoFWeight += -5;
break;
case STRENGTH_WEAK:
iEnemyWeight += -3;
iDPWeight += -3;
iDoFWeight += 1;
break;
case STRENGTH_POOR:
iEnemyWeight += -1;
iDPWeight += -1;
iDoFWeight += 2;
break;
case STRENGTH_AVERAGE:
iEnemyWeight += 1;
iDPWeight += 3;
iDoFWeight += 5;
break;
case STRENGTH_STRONG:
iEnemyWeight += 3;
iDPWeight += 5;
iDoFWeight += 3;
break;
case STRENGTH_POWERFUL:
iEnemyWeight += 5;
iDPWeight += 7;
iDoFWeight += 1;
break;
case STRENGTH_IMMENSE:
iEnemyWeight += 7;
iDPWeight += 10;
iDoFWeight += -3;
break;
}
switch (GetPlayer()->GetProximityToPlayer(ePlayer))
{
case PLAYER_PROXIMITY_NEIGHBORS:
iEnemyWeight += 3;
iDPWeight += 5;
iDoFWeight += 3;
break;
case PLAYER_PROXIMITY_CLOSE:
iEnemyWeight += 1;
iDPWeight += 2;
iDoFWeight += 1;
break;
case PLAYER_PROXIMITY_FAR:
iEnemyWeight += -1;
iDPWeight += -1;
iDoFWeight += 1;
break;
case PLAYER_PROXIMITY_DISTANT:
iEnemyWeight += -5;
iDPWeight += -5;
iDoFWeight += 2;
break;
}
// We denounced them
if (IsDenouncedPlayer(ePlayer) || GET_PLAYER(ePlayer).GetDiplomacyAI()->IsDenouncedPlayer(GetPlayer()->GetID()))
{
iEnemyWeight += 10;
iDPWeight += -10;
iDoFWeight += -10;
}
// We were friends and they betrayed us!
if (IsFriendDenouncedUs(ePlayer))
{
iEnemyWeight += 25;
iDPWeight += -25;
iDoFWeight += -25;
}
////////////////////////////////////
// MILITARY THREAT
////////////////////////////////////
switch (GetMilitaryThreat(ePlayer))
{
case THREAT_CRITICAL:
iEnemyWeight += 15;
iDPWeight += 15;
iDoFWeight += -15;
break;
case THREAT_SEVERE:
iEnemyWeight += 10;
iDPWeight += 10;
iDoFWeight += -10;
break;
case THREAT_MAJOR:
iEnemyWeight += 5;
iDPWeight += 5;
iDoFWeight += -5;
break;
case THREAT_MINOR:
iEnemyWeight += 1;
iDPWeight += -5;
iDoFWeight += 5;
break;
case THREAT_NONE:
iEnemyWeight += -5;
iDPWeight += -10;
iDoFWeight += 10;
break;
}
switch (GetWarmongerThreat(ePlayer))
{
case THREAT_CRITICAL:
iEnemyWeight += 15;
iDPWeight += 15;
iDoFWeight += -15;
break;
case THREAT_SEVERE:
iEnemyWeight += 10;
iDPWeight += 10;
iDoFWeight += -10;
break;
case THREAT_MAJOR:
iEnemyWeight += 5;
iDPWeight += 5;
iDoFWeight += -5;
break;
case THREAT_MINOR:
iEnemyWeight += 1;
iDPWeight += -5;
iDoFWeight += 5;
break;
case THREAT_NONE:
iEnemyWeight += -5;
iDPWeight += -10;
iDoFWeight += 10;
break;
}
switch (GetVictoryBlockLevel(ePlayer))
{
case BLOCK_LEVEL_NONE:
iEnemyWeight += -5;
iDPWeight += 1;
iDoFWeight += 1;
break;
case BLOCK_LEVEL_WEAK:
iEnemyWeight += 5;
iDPWeight += -5;
iDoFWeight += -5;
break;
case BLOCK_LEVEL_STRONG:
iEnemyWeight += 10;
iDPWeight += -10;
iDoFWeight += -10;
break;
case BLOCK_LEVEL_FIERCE:
iEnemyWeight += 15;
iDPWeight += -15;
iDoFWeight += -15;
break;
}
// Weight for victory issues
switch (GetVictoryDisputeLevel(ePlayer))
{
case DISPUTE_LEVEL_NONE:
iEnemyWeight += -5;
iDPWeight += 1;
iDoFWeight += 1;
break;
case DISPUTE_LEVEL_WEAK:
iEnemyWeight += 5;
iDPWeight += -5;
iDoFWeight += -5;
break;
case DISPUTE_LEVEL_STRONG:
iEnemyWeight += 10;
iDPWeight += -10;
iDoFWeight += -10;
break;
case DISPUTE_LEVEL_FIERCE:
iEnemyWeight += 15;
iDPWeight += -15;
iDoFWeight += -15;
break;
}
switch (GetLandDisputeLevel(ePlayer))
{
case DISPUTE_LEVEL_NONE:
iEnemyWeight += -5;
iDPWeight += 1;
iDoFWeight += 1;
break;
case DISPUTE_LEVEL_WEAK:
iEnemyWeight += 3;
iDPWeight += -3;
iDoFWeight += -3;
break;
case DISPUTE_LEVEL_STRONG:
iEnemyWeight += 5;
iDPWeight += -5;
iDoFWeight += -5;
break;
case DISPUTE_LEVEL_FIERCE:
iEnemyWeight += 10;
iDPWeight += -10;
iDoFWeight += -10;
break;
}
//Do we already have a DP? Let's keep this alive then.
if (GET_TEAM(GetTeam()).IsHasDefensivePact(GET_PLAYER(ePlayer).getTeam()))
{
iDPWeight += 10;
iDoFWeight += 15;
iEnemyWeight += -10;
}
if (GET_PLAYER(ePlayer).GetDiplomacyAI()->IsCloseToDominationVictory())
{
if (GET_PLAYER(ePlayer).isHuman())
{
int EnemyMod = 15 * GC.getGame().getHandicapInfo().getAIDeclareWarProb();
EnemyMod /= 100;
iEnemyWeight += EnemyMod;
iDPWeight += -EnemyMod;
iDoFWeight += -EnemyMod;
}
else
{
iEnemyWeight += 20;
iDPWeight += -10;
iDoFWeight += -10;
}
}
if (GET_PLAYER(ePlayer).GetDiplomacyAI()->IsCloseToSSVictory())
{
if (GET_PLAYER(ePlayer).isHuman())
{
int EnemyMod = 15 * GC.getGame().getHandicapInfo().getAIDeclareWarProb();
EnemyMod /= 100;
iEnemyWeight += EnemyMod;
iDPWeight += -EnemyMod;
iDoFWeight += -EnemyMod;
}
else
{
iEnemyWeight += 20;
iDPWeight += -10;
iDoFWeight += -10;
}
}
if (GET_PLAYER(ePlayer).GetDiplomacyAI()->IsCloseToDiploVictory())
{
if (GET_PLAYER(ePlayer).isHuman())
{
int EnemyMod = 15 * GC.getGame().getHandicapInfo().getAIDeclareWarProb();
EnemyMod /= 100;
iEnemyWeight += EnemyMod;
iDPWeight += -EnemyMod;
iDoFWeight += -EnemyMod;
}
else
{
iEnemyWeight += 20;
iDPWeight += -10;
iDoFWeight += -10;
}
}
if (GET_PLAYER(ePlayer).GetDiplomacyAI()->IsCloseToCultureVictory())
{
if (GET_PLAYER(ePlayer).isHuman())
{
int EnemyMod = 15 * GC.getGame().getHandicapInfo().getAIDeclareWarProb();
EnemyMod /= 100;
iEnemyWeight += EnemyMod;
iDPWeight += -EnemyMod;
iDoFWeight += -EnemyMod;
}
else
{
iEnemyWeight += 20;
iDPWeight += -10;
iDoFWeight += -10;
}
}
if (GET_TEAM(GET_PLAYER(ePlayer).getTeam()).GetMaster() == GetPlayer()->getTeam())
{
iEnemyWeight += -25;
iDPWeight += 25;
iDoFWeight += 25;
}
if (GET_TEAM(GetPlayer()->getTeam()).GetMaster() == GET_PLAYER(ePlayer).getTeam())
{
iEnemyWeight += -25;
iDPWeight += 25;
iDoFWeight += 25;
}
//Let's not have too many defensive pacts.
iDPWeight -= (GetNumDefensePacts() * 15);
//Subtract for # of existing DoFs - want only a few close friends.
iDoFWeight -= (GetNumDoF() * 15);
//He hates who we hate? We love this guy!
if (!GET_PLAYER(ePlayer).isHuman())
{
if (GET_PLAYER(ePlayer).GetDiplomacyAI()->GetBiggestCompetitor() == GetBiggestCompetitor())
{
iDPWeight += 5;
iDoFWeight += 5;
iEnemyWeight += -5;
}
}
if (GET_PLAYER(ePlayer).GetCulture()->GetInfluenceLevel(GetPlayer()->GetID()) == INFLUENCE_LEVEL_POPULAR)
{
if (GET_PLAYER(ePlayer).GetCulture()->GetInfluenceTrend(GetPlayer()->GetID()) == INFLUENCE_TREND_RISING)
{
iDoFWeight -= 5;
iDPWeight += -5;
iEnemyWeight += 5;
}
}
// Loop through all (known) Players and see who he likes/hates - if he likes/hates who we like/hate, then add those points in!
for (int iPlayerLoop2 = 0; iPlayerLoop2 < MAX_MAJOR_CIVS; iPlayerLoop2++)
{
PlayerTypes eOtherPlayer = (PlayerTypes)iPlayerLoop2;
if (eOtherPlayer == ePlayer)
continue;
if (eOtherPlayer == GetPlayer()->GetID())
continue;
if (IsPlayerValid(eOtherPlayer))
{
//Friend or DP?
if (IsDoFAccepted(eOtherPlayer) || GET_TEAM(GET_PLAYER(eOtherPlayer).getTeam()).IsHasDefensivePact(GetPlayer()->getTeam()))
{
//At war?
if (GET_PLAYER(eOtherPlayer).GetDiplomacyAI()->IsAtWar(ePlayer))
{
iEnemyWeight += 5;
iDPWeight += -5;
iDoFWeight += -5;
}
if (GET_PLAYER(eOtherPlayer).GetDiplomacyAI()->IsDenouncedPlayer(ePlayer))
{
iEnemyWeight += 5;
iDPWeight += -5;
iDoFWeight += -5;
}
if (GET_PLAYER(ePlayer).GetDiplomacyAI()->IsDenouncedPlayer(eOtherPlayer))
{
iEnemyWeight += 5;
iDPWeight += -5;
iDoFWeight += -5;
}
}
//We dislike the same people? Good!
if (!GET_PLAYER(ePlayer).isHuman())
{
if (GET_PLAYER(ePlayer).GetDiplomacyAI()->GetCompetitorValue(eOtherPlayer) > GC.getDOF_THRESHOLD() && GetCompetitorValue(eOtherPlayer) > GC.getDOF_THRESHOLD())
{
iDPWeight += 5;
iDoFWeight += 5;
iEnemyWeight += -5;
}
}
//We have defensive pacts with the same people? Good!
if (GET_TEAM(GET_PLAYER(ePlayer).getTeam()).IsHasDefensivePact(GET_PLAYER(eOtherPlayer).getTeam()) && GET_TEAM(GetPlayer()->getTeam()).IsHasDefensivePact(GET_PLAYER(eOtherPlayer).getTeam()))
{
iDPWeight += 5;
iDoFWeight += 5;
iEnemyWeight += -5;
}
//We have DoFs with the same people? Good!
if (GET_PLAYER(ePlayer).GetDiplomacyAI()->IsDoFAccepted(eOtherPlayer) && IsDoFAccepted(eOtherPlayer))
{
iDPWeight += 5;
iDoFWeight += 5;
iEnemyWeight += -5;
}
//War? Are we threatened?
if (GET_PLAYER(ePlayer).IsAtWarWith(eOtherPlayer))
{
if (GetPlayer()->IsAtWarWith(eOtherPlayer))
{
iDPWeight += 5;
iDoFWeight += 5;
iEnemyWeight += -5;
}
//Close? We might be next!
if (GetPlayer()->GetProximityToPlayer(eOtherPlayer) >= PLAYER_PROXIMITY_CLOSE)
{
iDPWeight += 5;
iDoFWeight += 5;
iEnemyWeight += -5;
}
//Warmonger? We might be next!
if (GetWarmongerThreat(eOtherPlayer) >= THREAT_MAJOR)
{
iDPWeight += 5;
iDoFWeight += 5;
iEnemyWeight += -5;
}
}
}
}
if (GET_TEAM(GetPlayer()->getTeam()).IsVassalOfSomeone() || GET_TEAM(GET_PLAYER(ePlayer).getTeam()).IsVassalOfSomeone())
{
iDPWeight = 0;
iDoFWeight /= 2;
iEnemyWeight /= 2;
}
}
//Total it up and add it to the pool of values.
m_paiCompetitorValue[ePlayer] = iEnemyWeight;
m_paiDoFValue[ePlayer] = iDoFWeight;
m_paiDefensivePactValue[ePlayer] = iDPWeight;
}
//Let's log this data
if (GC.getLogging() && GC.getAILogging())
{
CvString strLogName;
CvString strOutBuf1;
CvString strOutBuf2 = "";
CvString strBaseString;
CvString playerName;
CvString otherPlayerName;
CvString strTemp;
playerName = GetPlayer()->getCivilizationShortDescription();
// Open the log file
if (GC.getPlayerAndCityAILogSplit())
{
strLogName = "DiplomacyAI_GlobalRelations_Log_" + playerName + ".csv";
}
else
{
strLogName = "DiplomacyAI_GlobalRelations_Log.csv";
}
FILogFile* pLog;
pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp);
// Turn number
strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
// Our Name
strBaseString += playerName;
strOutBuf1 = strBaseString;
strOutBuf2 = strBaseString;
// Loop through all (known) Players
int iNumPlayers = 0;
for (int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)
{
PlayerTypes ePlayer = (PlayerTypes)iPlayerLoop;
if (IsPlayerValid(ePlayer))
{
if (iNumPlayers != 0)
{
strTemp.Format("\n -");
strOutBuf1 += strTemp;
}
// Strategy Info
strTemp.Format(" ** %s Valuation: Competitor - %d; DoF - %d, DP - %d **", GET_PLAYER(ePlayer).getCivilizationShortDescription(), GetCompetitorValue(ePlayer), GetDoFValue(ePlayer), GetDefensivePactValue(ePlayer));
strOutBuf1 += strTemp;
iNumPlayers++;
}
}
if (GetBiggestCompetitor() != NO_PLAYER)
{
strTemp.Format("\n - ** Our biggest COMPETITOR: %s", GET_PLAYER(GetBiggestCompetitor()).getCivilizationShortDescription());
strOutBuf2 += strTemp;
}
if (GetMostValuableDefensivePact(false) != NO_PLAYER)
{
strTemp.Format("\n - ** Our best DEFENSIVE PACT: %s", GET_PLAYER(GetMostValuableDefensivePact(false)).getCivilizationShortDescription());
strOutBuf2 += strTemp;
}
if (GetMostValuableDoF(false) != NO_PLAYER)
{
strTemp.Format("\n - ** Our best FRIENSHIP: %s", GET_PLAYER(GetMostValuableDoF(false)).getCivilizationShortDescription());
strOutBuf2 += strTemp;
}
pLog->Msg(strOutBuf1);
if (strOutBuf2 != "")
{
pLog->Msg(strOutBuf2);
}
}
}