Bazaar developer reference

CvDiplomacyAI::DoUpdateMinorCivApproaches()

Defined in
CvDiplomacyAI.cpp, line 3730
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoUpdateMinorCivApproaches

Hooks

static bool BeforeCvDiplomacyAI_DoUpdateMinorCivApproaches(CvDiplomacyAI* self);static void AfterCvDiplomacyAI_DoUpdateMinorCivApproaches(CvDiplomacyAI* self);static void ReplaceCvDiplomacyAI_DoUpdateMinorCivApproaches(void (*original)(CvDiplomacyAI*), CvDiplomacyAI* self);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateMinorCivApproaches>(host, &BeforeCvDiplomacyAI_DoUpdateMinorCivApproaches);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateMinorCivApproaches>(host, &AfterCvDiplomacyAI_DoUpdateMinorCivApproaches);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateMinorCivApproaches>(host, &ReplaceCvDiplomacyAI_DoUpdateMinorCivApproaches);

Code

3729/// Determine our general approach to each Minor Civ we've met3730void CvDiplomacyAI::DoUpdateMinorCivApproaches()3731{3732	int iPlayerLoop;3733	PlayerTypes eLoopPlayer;37343735	// Transfer Approaches from last turn to a separate array so we still have access to the info, then clear out the real one3736	for(iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)3737	{3738		m_paeApproachScratchPad[iPlayerLoop] = -1;37393740		eLoopPlayer = (PlayerTypes) iPlayerLoop;37413742		if(GET_PLAYER(eLoopPlayer).isMinorCiv())3743		{3744			if(IsPlayerValid(eLoopPlayer))3745			{3746				m_paeApproachScratchPad[eLoopPlayer] = GetMinorCivApproach(eLoopPlayer);3747				SetMinorCivApproach(eLoopPlayer, NO_MINOR_CIV_APPROACH);3748			}3749		}3750	}37513752	int iHighestWeight;37533754	CvWeightedVector<PlayerTypes, MAX_MINOR_CIVS, true> vePlayerApproachWeights;3755	int iPlayerVectorIndex;37563757	// Loop through all (known) Minors and determine the order of who we pick our Approach for first based on PROXIMITY - this is different from Majors3758	for(iPlayerLoop = MAX_MAJOR_CIVS; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)3759	{3760		eLoopPlayer = (PlayerTypes) iPlayerLoop;37613762		if(IsPlayerValid(eLoopPlayer))3763		{3764			iHighestWeight = GetPlayer()->GetProximityToPlayer(eLoopPlayer);	// Note that the order in the PlayerProximityTYpes enum is very important here: be sure to verify that NEIGHBORS is the last entry3765			vePlayerApproachWeights.push_back(eLoopPlayer, iHighestWeight);3766		}3767	}37683769	MinorCivApproachTypes eApproach;3770	MinorCivApproachTypes eLastTurnApproach;37713772	// Now sort the list if there's anything in it3773	if(vePlayerApproachWeights.size() > 0)3774	{3775		vePlayerApproachWeights.SortItems();37763777		// Now that Minors are sorted, ACTUALLY figure out what our Approach will be, taking everything into account3778		for(iPlayerVectorIndex = 0; iPlayerVectorIndex < (int) vePlayerApproachWeights.size(); iPlayerVectorIndex++)3779		{3780			eLoopPlayer = (PlayerTypes) vePlayerApproachWeights.GetElement(iPlayerVectorIndex);37813782			// See which Approach is best3783			eApproach = GetBestApproachTowardsMinorCiv(eLoopPlayer, /*Passed by Ref, but we won't use it*/ iHighestWeight, /*bLookAtOtherPlayers*/ true, /*bLog*/ true);37843785			eLastTurnApproach = (MinorCivApproachTypes) m_paeApproachScratchPad[eLoopPlayer];37863787			CvAssertMsg(eApproach >= 0, "DIPLOMACY_AI: Invalid MinorCivApproachType.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");37883789			SetMinorCivApproach(eLoopPlayer, eApproach);3790		}3791	}37923793	// Debug check37943795#ifndef FINAL_RELEASE3796	for(iPlayerLoop = 0; iPlayerLoop < MAX_MINOR_CIVS; iPlayerLoop++)3797	{3798		eLoopPlayer = (PlayerTypes) iPlayerLoop;37993800		if(GET_PLAYER(eLoopPlayer).isMinorCiv())3801		{3802			if(IsPlayerValid(eLoopPlayer))3803			{3804				if(GetMinorCivApproach(eLoopPlayer) == NO_MINOR_CIV_APPROACH)3805					CvAssertMsg(false, "DIPLOMACY_AI: Invalid MinorCivApproachType. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");3806			}3807		}3808	}3809#endif3810}

Calls

Called by