Bazaar developer reference

CvDiplomacyAI::DoHappyBefriendedFriend(PlayerTypes, DiploStatementTypes &, int &)

Defined in
CvDiplomacyAI.cpp, line 15445
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoHappyBefriendedFriend

Hooks

static bool BeforeCvDiplomacyAI_DoHappyBefriendedFriend(CvDiplomacyAI* self, PlayerTypes ePlayer, DiploStatementTypes& eStatement, int& iData1);static void AfterCvDiplomacyAI_DoHappyBefriendedFriend(CvDiplomacyAI* self, PlayerTypes ePlayer, DiploStatementTypes& eStatement, int& iData1);static void ReplaceCvDiplomacyAI_DoHappyBefriendedFriend(void (*original)(CvDiplomacyAI*, PlayerTypes, DiploStatementTypes&, int&), CvDiplomacyAI* self, PlayerTypes ePlayer, DiploStatementTypes& eStatement, int& iData1);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoHappyBefriendedFriend>(host, &BeforeCvDiplomacyAI_DoHappyBefriendedFriend);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoHappyBefriendedFriend>(host, &AfterCvDiplomacyAI_DoHappyBefriendedFriend);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoHappyBefriendedFriend>(host, &ReplaceCvDiplomacyAI_DoHappyBefriendedFriend);

Code

15445void CvDiplomacyAI::DoHappyBefriendedFriend(PlayerTypes ePlayer, DiploStatementTypes& eStatement, int& iData1)15446{15447	CvAssertMsg(ePlayer >= 0, "DIPLOMACY_AI: Invalid Player Index.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");15448	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.");1544915450	// We denounced the leader we're talking to - no use talking at this point15451	if(IsDenouncedPlayer(ePlayer) || IsAtWar(ePlayer) || GetMajorCivApproach(ePlayer, /*bHideTrueFeelings*/ true) == MAJOR_CIV_APPROACH_HOSTILE)15452		return;1545315454	if(eStatement == NO_DIPLO_STATEMENT_TYPE)15455	{15456		DiploStatementTypes eTempStatement = DIPLO_STATEMENT_HAPPY_BEFRIENDED_FRIEND;1545715458		if(GetNumTurnsSinceStatementSent(ePlayer, eTempStatement) >= 50 &&15459		        GetNumTurnsSinceStatementSent(ePlayer, DIPLO_STATEMENT_HAPPY_BEFRIENDED_FRIEND_RANDFAILED) >= 20)15460		{15461			CvDiplomacyAI* pTheirDiploAI = GET_PLAYER(ePlayer).GetDiplomacyAI();1546215463			// Loop through all players until we find one that is our friend, that ePlayer DoFed15464			PlayerTypes eLoopPlayer;15465			for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)15466			{15467				eLoopPlayer = (PlayerTypes) iPlayerLoop;1546815469				// Must be alive15470				if(!GET_PLAYER(eLoopPlayer).isAlive())15471					continue;1547215473				// Can't be either of us15474				if(eLoopPlayer == GetPlayer()->GetID() || eLoopPlayer == ePlayer)15475					continue;1547615477				// We haven't DoFed this guy15478				if(!IsDoFAccepted(eLoopPlayer))15479					continue;1548015481				// They haven't DoFed this guy15482				if(!pTheirDiploAI->IsDoFAccepted(eLoopPlayer))15483					continue;1548415485				// Too much time has passed (or maybe we already sent a message recently)15486				if(pTheirDiploAI->GetDoFCounter(eLoopPlayer) > 1)15487					continue;1548815489				// Found a match!1549015491				int iWeight = GetChattiness();		// Usually ranges from 3 to 715492				iWeight += GC.getGame().getJonRandNum(7, "Random roll for AI statement: 0");1549315494				// We're chatty enough to say something15495				if(iWeight >= 7)15496				{15497					eStatement = eTempStatement;15498					iData1 = eLoopPlayer;15499				}15500				// We're going to be nice!15501				else15502				{15503					eStatement = DIPLO_STATEMENT_HAPPY_BEFRIENDED_FRIEND_RANDFAILED;15504				}1550515506				// We're done in here15507				break;15508			}15509		}15510	}15511}

Calls

Called by