CvDiplomacyAI::DoFYIBefriendedHumanFriend(PlayerTypes, DiploStatementTypes &, int &)
- Defined in
- CvDiplomacyAI.cpp, line 15817
- Class
- CvDiplomacyAI
- Hook name
CivHooks::CvDiplomacyAI_DoFYIBefriendedHumanFriend
Hooks
static bool BeforeCvDiplomacyAI_DoFYIBefriendedHumanFriend(CvDiplomacyAI* self, PlayerTypes ePlayer, DiploStatementTypes& eStatement, int& iData1);static void AfterCvDiplomacyAI_DoFYIBefriendedHumanFriend(CvDiplomacyAI* self, PlayerTypes ePlayer, DiploStatementTypes& eStatement, int& iData1);static void ReplaceCvDiplomacyAI_DoFYIBefriendedHumanFriend(void (*original)(CvDiplomacyAI*, PlayerTypes, DiploStatementTypes&, int&), CvDiplomacyAI* self, PlayerTypes ePlayer, DiploStatementTypes& eStatement, int& iData1);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoFYIBefriendedHumanFriend>(host, &BeforeCvDiplomacyAI_DoFYIBefriendedHumanFriend);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoFYIBefriendedHumanFriend>(host, &AfterCvDiplomacyAI_DoFYIBefriendedHumanFriend);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoFYIBefriendedHumanFriend>(host, &ReplaceCvDiplomacyAI_DoFYIBefriendedHumanFriend);
Code
15816/// Possible Contact Statement15817void CvDiplomacyAI::DoFYIBefriendedHumanFriend(PlayerTypes ePlayer, DiploStatementTypes& eStatement, int& iData1)15818{15819 CvAssertMsg(ePlayer >= 0, "DIPLOMACY_AI: Invalid Player Index. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");15820 CvAssertMsg(ePlayer < MAX_MAJOR_CIVS, "DIPLOMACY_AI: Invalid Player Index. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");1582115822 if(eStatement == NO_DIPLO_STATEMENT_TYPE)15823 {15824 DiploStatementTypes eTempStatement = DIPLO_STATEMENT_FYI_BEFRIEND_HUMAN_FRIEND;1582515826 if(GetNumTurnsSinceStatementSent(ePlayer, eTempStatement) >= 50 &&15827 GetNumTurnsSinceStatementSent(ePlayer, DIPLO_STATEMENT_FYI_BEFRIEND_HUMAN_FRIEND_RANDFAILED) >= 20)15828 {15829 CvDiplomacyAI* pTheirDiploAI = GET_PLAYER(ePlayer).GetDiplomacyAI();1583015831 int iWeight;15832 MajorCivApproachTypes eApproach;15833 MajorCivOpinionTypes eOpinion;1583415835 // Loop through all players until we find one that we just befriended, that ePlayer has befriended15836 PlayerTypes eLoopPlayer;15837 for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)15838 {15839 eLoopPlayer = (PlayerTypes) iPlayerLoop;1584015841 // Must be alive15842 if(!GET_PLAYER(eLoopPlayer).isAlive())15843 continue;1584415845 // Can't be either of us15846 if(eLoopPlayer == GetPlayer()->GetID() || eLoopPlayer == ePlayer)15847 continue;1584815849 // We haven't befriended this guy15850 if(!IsDoFAccepted(eLoopPlayer))15851 continue;1585215853 // They haven't befriended this guy15854 if(!pTheirDiploAI->IsDoFAccepted(eLoopPlayer))15855 continue;1585615857 // Too much time has passed (or maybe we already sent a message recently)15858 if(GetDoFCounter(eLoopPlayer) > 1)15859 continue;1586015861 eOpinion = GetMajorCivOpinion(ePlayer);15862 eApproach = GetMajorCivApproach(ePlayer, /*bHideTrueFeelings*/ true);1586315864 // Don't say nice things if we dislike ePlayer15865 if(eOpinion <= MAJOR_CIV_OPINION_COMPETITOR)15866 continue;15867 if(eApproach == MAJOR_CIV_APPROACH_WAR || eApproach == MAJOR_CIV_APPROACH_HOSTILE)15868 continue;1586915870 iWeight = 0;1587115872 if(eOpinion == MAJOR_CIV_OPINION_FAVORABLE)15873 iWeight += 2;15874 else if(eOpinion == MAJOR_CIV_OPINION_FRIEND)15875 iWeight += 5;15876 else if(eOpinion == MAJOR_CIV_OPINION_ALLY)15877 iWeight += 10;1587815879 if(eOpinion == MAJOR_CIV_APPROACH_FRIENDLY)15880 iWeight += 2;1588115882 iWeight += GetChattiness(); // Usually ranges from 3 to 715883 iWeight += GC.getGame().getJonRandNum(7, "Random roll for AI statement: 0");1588415885 // We're mean enough to say something15886 if(iWeight >= 7)15887 {15888 eStatement = eTempStatement;15889 iData1 = eLoopPlayer;15890 }15891 // We're going to be nice!15892 else15893 {15894 eStatement = DIPLO_STATEMENT_FYI_BEFRIEND_HUMAN_FRIEND_RANDFAILED;15895 }1589615897 // We're done in here15898 break;15899 }15900 }15901 }15902}
Calls
- CvDiplomacyAI::GetChattiness() const
- CvDiplomacyAI::GetDoFCounter(PlayerTypes) const
- CvDiplomacyAI::GetMajorCivApproach(PlayerTypes, bool) const
- CvDiplomacyAI::GetMajorCivOpinion(PlayerTypes) const
- CvDiplomacyAI::GetNumTurnsSinceStatementSent(PlayerTypes, DiploStatementTypes)
- CvDiplomacyAI::GetPlayer()
- CvDiplomacyAI::IsDoFAccepted(PlayerTypes) const
- CvGame::getJonRandNum(int, const char *)
- CvGlobals::getGame()
- CvPlayer::GetDiplomacyAI() const
- CvPlayer::GetID() const
- CvPlayer::isAlive() const
- CvPlayerAI::getPlayer(PlayerTypes)