Bazaar developer reference

CvDiplomacyAI::GetBestApproachTowardsMinorCiv(PlayerTypes, int &, bool, bool)

Defined in
CvDiplomacyAI.cpp, line 3814
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_GetBestApproachTowardsMinorCiv

Hooks

static bool BeforeCvDiplomacyAI_GetBestApproachTowardsMinorCiv(CvDiplomacyAI* self, PlayerTypes ePlayer, int& iHighestWeight, bool bLookAtOtherPlayers, bool bLog, MinorCivApproachTypes& result);static void AfterCvDiplomacyAI_GetBestApproachTowardsMinorCiv(CvDiplomacyAI* self, PlayerTypes ePlayer, int& iHighestWeight, bool bLookAtOtherPlayers, bool bLog, MinorCivApproachTypes& result);static MinorCivApproachTypes ReplaceCvDiplomacyAI_GetBestApproachTowardsMinorCiv(MinorCivApproachTypes (*original)(CvDiplomacyAI*, PlayerTypes, int&, bool, bool), CvDiplomacyAI* self, PlayerTypes ePlayer, int& iHighestWeight, bool bLookAtOtherPlayers, bool bLog);CivRegisterBefore<CivHooks::CvDiplomacyAI_GetBestApproachTowardsMinorCiv>(host, &BeforeCvDiplomacyAI_GetBestApproachTowardsMinorCiv);CivRegisterAfter<CivHooks::CvDiplomacyAI_GetBestApproachTowardsMinorCiv>(host, &AfterCvDiplomacyAI_GetBestApproachTowardsMinorCiv);CivRegisterReplace<CivHooks::CvDiplomacyAI_GetBestApproachTowardsMinorCiv>(host, &ReplaceCvDiplomacyAI_GetBestApproachTowardsMinorCiv);

Code

3813/// What is the best approach to take towards a Minor Civ?  Can also pass in iHighestWeight by reference if you just want to know what the player feels most strongly about without actually caring about WHAT it is3814MinorCivApproachTypes CvDiplomacyAI::GetBestApproachTowardsMinorCiv(PlayerTypes ePlayer, int& iHighestWeight, bool bLookAtOtherPlayers, bool bLog)3815{3816	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.");3817	CvAssertMsg(ePlayer < MAX_CIV_PLAYERS, "DIPLOMACY_AI: Invalid Player Index.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");38183819	TeamTypes eTeam = GET_PLAYER(ePlayer).getTeam();38203821	MinorCivApproachTypes eApproach;3822	// This vector is what we'll stuff the values into first, and pass it into our logging function (which can't take a CvWeightedVector, which we need to sort...)3823	FStaticVector< int, 128, true, c_eCiv5GameplayDLL > viApproachWeights;38243825	int iApproachLoop;38263827	viApproachWeights.clear();38283829	for(iApproachLoop = 0; iApproachLoop < NUM_MINOR_CIV_APPROACHES; iApproachLoop++)3830	{3831		viApproachWeights.push_back(0);3832	}38333834	////////////////////////////////////3835	// NEUTRAL DEFAULT WEIGHT3836	////////////////////////////////////38373838	viApproachWeights[MINOR_CIV_APPROACH_IGNORE] += /*1*/ GC.getMINOR_APPROACH_IGNORE_DEFAULT();38393840	////////////////////////////////////3841	// CURRENT SITUATION BIASES3842	////////////////////////////////////38433844	// Bias for our current Approach.  This should prevent it from jumping around from turn-to-turn as much3845	// We use the scratch pad here since the normal array has been cleared so that we have knowledge of who we've already assigned an Approach for this turn; this should be the only place the scratch pad is used3846	CvAssertMsg(m_paeApproachScratchPad[ePlayer] >= NO_MINOR_CIV_APPROACH && m_paeApproachScratchPad[ePlayer] < NUM_MINOR_CIV_APPROACHES, "m_paeApproachScratchPad[iScratchPadID] is out of bounds for minor civ approaches. Show Jon!");3847	if(m_paeApproachScratchPad[ePlayer] < NO_MINOR_CIV_APPROACH || m_paeApproachScratchPad[ePlayer] >= NUM_MINOR_CIV_APPROACHES)3848	{3849		return NO_MINOR_CIV_APPROACH;3850	}38513852	MinorCivApproachTypes eOldApproach = (MinorCivApproachTypes) m_paeApproachScratchPad[ePlayer];3853	viApproachWeights[eOldApproach] += /*2*/ GC.getMINOR_APPROACH_BIAS_FOR_CURRENT();38543855	// If we're planning a war then give it a bias so that we don't get away from it too easily3856	if(eOldApproach == MINOR_CIV_APPROACH_CONQUEST)3857	{3858		// Add some bias to Ignore to help us get out in case things get sticky3859		viApproachWeights[MINOR_CIV_APPROACH_IGNORE] += /*3*/ GC.getMINOR_APPROACH_IGNORE_CURRENTLY_WAR();38603861		// Don't give this bias if war is going poorly3862		WarStateTypes eWarState = GetWarState(ePlayer);3863		if(eWarState > WAR_STATE_STALEMATE)3864		{3865			viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*4*/ GC.getAPPROACH_WAR_CURRENTLY_WAR();3866		}3867	}3868	// If we're Protective then knock Conquest down & pump Protective up3869	else if(eOldApproach == MINOR_CIV_APPROACH_PROTECTIVE)3870	{3871		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-10*/ GC.getMINOR_APPROACH_WAR_CURRENTLY_PROTECTIVE();3872		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*10*/ GC.getMINOR_APPROACH_PROTECTIVE_CURRENTLY_PROTECTIVE();3873		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += -10; //antonjs: todo: constant/XML3874	}38753876	// If we're ALREADY at war with this player then we're much less likely to be Protective3877	if(IsAtWar(ePlayer))3878	{3879		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*-15*/ GC.getMINOR_APPROACH_PROTECTIVE_CURRENTLY_WAR();3880		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*-6*/ GC.getMINOR_APPROACH_FRIENDLY_CURRENTLY_WAR();3881	}38823883	////////////////////////////////////3884	// RESOURCES3885	////////////////////////////////////38863887	int iNumWeLack = GET_PLAYER(ePlayer).GetMinorCivAI()->GetNumResourcesMajorLacks(GetPlayer()->GetID());3888	if(iNumWeLack > 0)3889	{3890		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += (iNumWeLack* /*1*/ GC.getMINOR_APPROACH_FRIENDLY_RESOURCES());3891		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += (iNumWeLack* /*1*/ GC.getMINOR_APPROACH_PROTECTIVE_RESOURCES());3892		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += (iNumWeLack/***/ /*1*/ /*GC.getMINOR_APPROACH_PROTECTIVE_RESOURCES()*/); // we could just take them after all3893	}38943895	////////////////////////////////////3896	// FRIENDS WITH MINOR3897	////////////////////////////////////38983899	if(GET_PLAYER(ePlayer).GetMinorCivAI()->IsFriends(GetPlayer()->GetID()))3900	{3901		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-100*/ GC.getMINOR_APPROACH_WAR_FRIENDS();3902		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*4*/ GC.getMINOR_APPROACH_FRIENDLY_FRIENDS();3903		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*2*/ GC.getMINOR_APPROACH_PROTECTIVE_FRIENDS(); //antonjs: todo: increase3904		viApproachWeights[MINOR_CIV_APPROACH_BULLY] -= 10; //antonjs: todo: constant/XML3905	}39063907	////////////////////////////////////3908	// PLEDGE TO PROTECT - have we pledged to protect this minor?3909	////////////////////////////////////3910	//antonjs: consider: disable this weight after a certain amount of turns, to have this player "reevaluate" its PtP3911	if(GET_PLAYER(ePlayer).GetMinorCivAI()->IsProtectedByMajor(GetPlayer()->GetID()))3912	{3913		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += 2; //antonjs: todo: constant/XML3914		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += -1; //antonjs: todo: constant/XML3915		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += -2; //antonjs: todo: constant/XML3916	}39173918	////////////////////////////////////3919	// PERSONALITY3920	////////////////////////////////////39213922	for(iApproachLoop = 0; iApproachLoop < NUM_MINOR_CIV_APPROACHES; iApproachLoop++)3923	{3924		viApproachWeights[iApproachLoop] += GetPersonalityMinorCivApproachBias((MinorCivApproachTypes) iApproachLoop);3925	}39263927	bool bIsGoodWarTarget = false;3928	bool bCheckIfGoodWarTarget = false;39293930	////////////////////////////////////3931	// CONQUEST GRAND STRATEGY3932	////////////////////////////////////39333934	if(IsGoingForWorldConquest())3935	{3936		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*10*/ GC.getMINOR_APPROACH_WAR_CONQUEST_GRAND_STRATEGY();3937		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*-15*/ GC.getMINOR_APPROACH_PROTECTIVE_CONQUEST_GRAND_STRATEGY();3938		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*-5*/ GC.getMINOR_APPROACH_FRIENDLY_CONQUEST_GRAND_STRATEGY();3939		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += 8; //antonjs: todo: constant/XML39403941		// if we're neighbors, make it even more likely we'll go to war3942		if(GetPlayer()->GetProximityToPlayer(ePlayer) == PLAYER_PROXIMITY_NEIGHBORS)3943		{3944			bIsGoodWarTarget = true;3945		}3946	}39473948	////////////////////////////////////3949	// DIPLO GRAND STRATEGY3950	////////////////////////////////////39513952	else if(IsGoingForDiploVictory())3953	{3954		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-20*/ GC.getMINOR_APPROACH_WAR_DIPLO_GRAND_STRATEGY();3955		viApproachWeights[MINOR_CIV_APPROACH_IGNORE] += /*-15*/ GC.getMINOR_APPROACH_IGNORE_DIPLO_GRAND_STRATEGY();3956		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += -15; //antonjs: todo: constant/XML39573958		// Neighbors and Close: +5 to Protective3959		if(GetPlayer()->GetProximityToPlayer(ePlayer) >= PLAYER_PROXIMITY_CLOSE)3960			viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*5*/ GC.getMINOR_APPROACH_PROTECTIVE_DIPLO_GRAND_STRATEGY_NEIGHBORS();3961	}39623963	////////////////////////////////////3964	// CULTURE GRAND STRATEGY3965	////////////////////////////////////39663967	else if(IsGoingForCultureVictory())3968	{3969		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-20*/ GC.getMINOR_APPROACH_WAR_CULTURE_GRAND_STRATEGY();3970		viApproachWeights[MINOR_CIV_APPROACH_IGNORE] += /*-15*/ GC.getMINOR_APPROACH_IGNORE_CULTURE_GRAND_STRATEGY();3971		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += -10; //antonjs: todo: constant/XML39723973		// Minor is cultural3974		if(GET_PLAYER(ePlayer).GetMinorCivAI()->GetTrait() == MINOR_CIV_TRAIT_CULTURED) 3975		{3976			viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*5*/ GC.getMINOR_APPROACH_PROTECTIVE_CULTURE_GRAND_STRATEGY_CST();3977		}3978		else3979		{3980			bCheckIfGoodWarTarget = true;3981		}3982	}39833984	////////////////////////////////////3985	// SCIENCE GRAND STRATEGY3986	////////////////////////////////////3987	else3988	{3989		bCheckIfGoodWarTarget = true;3990	}39913992	// See if this minor is on same continent as a major power we want to attack3993	if (bCheckIfGoodWarTarget)3994	{3995		CvCity *pkMinorCapital = GET_PLAYER(ePlayer).getCapitalCity();3996		if (pkMinorCapital)		// This should always be valid3997		{3998			int iMinorAreaID = pkMinorCapital->getArea();39994000			if (m_pPlayer->getCapitalCity())		// This should always be valid too.4001			{4002				int iMyAreaID = m_pPlayer->getCapitalCity()->getArea();4003				int iPlayerLoop;4004				CvTeam& kMyTeam = GET_TEAM(GetTeam());4005				for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)4006				{4007					PlayerTypes eLoopPlayer = (PlayerTypes) iPlayerLoop;4008					CvPlayer &kLoopPlayer = GET_PLAYER(eLoopPlayer);40094010					// Make sure it is another valid player and not already at war with them4011					if (m_pPlayer->GetID() != eLoopPlayer)4012					{4013						if(IsPlayerValid(eLoopPlayer))4014						{4015							if (!kMyTeam.isAtWar(kLoopPlayer.getTeam()))4016							{4017								// Do we want to attack them?4018								if (GetMajorCivApproach(eLoopPlayer, false) == MAJOR_CIV_APPROACH_WAR)4019								{4020									CvCity* pkLoopPlayerCity = kLoopPlayer.getCapitalCity();4021									if (pkLoopPlayerCity)	// It's possible this is not valid4022									{4023										int iLoopPlayerAreaID = pkLoopPlayerCity->getArea();4024										// All of us neighbors on same landmass?4025										if (iLoopPlayerAreaID == iMinorAreaID &&4026											iMyAreaID == iLoopPlayerAreaID)4027										{4028											if (kLoopPlayer.GetProximityToPlayer(ePlayer) >= PLAYER_PROXIMITY_NEIGHBORS &&4029												m_pPlayer->GetProximityToPlayer(ePlayer) >= PLAYER_PROXIMITY_NEIGHBORS)4030											{4031												bIsGoodWarTarget = true;4032												break;4033											}4034										}4035									}4036								}4037							}4038						}4039					}4040				}4041			}4042		}4043	}4044	if (bIsGoodWarTarget)4045	{4046		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*10*/ GC.getMINOR_APPROACH_WAR_CONQUEST_GRAND_STRATEGY_NEIGHBORS();4047		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += 8; //antonjs: todo: constant/XML4048	}40494050	////////////////////////////////////4051	// TRAITS THAT EFFECT MINORS - These are heavy handed, but that is intentional4052	////////////////////////////////////4053	int iBonusTraitMod = 0;4054	iBonusTraitMod += (m_pPlayer->GetPlayerTraits()->GetCityStateFriendshipModifier() > 0) ? 100 : 0;4055	iBonusTraitMod += (m_pPlayer->GetPlayerTraits()->GetCityStateBonusModifier() > 0) ? 100 : 0;4056	iBonusTraitMod += (m_pPlayer->GetPlayerTraits()->GetCityStateCombatModifier() > 0) ? -100 : 0;4057	if (iBonusTraitMod)4058	{4059		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] -= iBonusTraitMod;4060		viApproachWeights[MINOR_CIV_APPROACH_BULLY] -= iBonusTraitMod / 5;4061		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += iBonusTraitMod / 5;4062		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += iBonusTraitMod;4063	}4064	if (iBonusTraitMod >= 0 && m_pPlayer->getNumCities() <= 1)4065	{4066		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] -= 200;4067	}40684069	////////////////////////////////////4070	// RELIGION4071	////////////////////////////////////4072	//antonjs: todo: befriend/protect religious minors if we have a religion strategy40734074	////////////////////////////////////4075	// HAPPINESS4076	////////////////////////////////////4077	//antonjs: todo: befriend/protect mercantile minors if we are in need of happiness40784079	////////////////////////////////////4080	// MILITARY THREAT4081	////////////////////////////////////40824083	//switch (GetMilitaryThreat(ePlayer))4084	//{4085	//case THREAT_CRITICAL:4086	//	//viApproachWeights[MAJOR_CIV_APPROACH_DECEPTIVE] += /*0*/ GC.getAPPROACH_DECEPTIVE_MILITARY_THREAT_CRITICAL();4087	//	//break;4088	//case THREAT_SEVERE:4089	//case THREAT_MAJOR:4090	//case THREAT_MINOR:4091	//case THREAT_NONE:4092	//	break;4093	//}40944095	int iPlayerLoop;4096	PlayerTypes eLoopPlayer;40974098	////////////////////////////////////4099	// AT WAR RIGHT NOW4100	////////////////////////////////////41014102	for(iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)4103	{4104		eLoopPlayer = (PlayerTypes) iPlayerLoop;41054106		// Don't look at the guy we're already thinking about or anyone on his team4107		if(ePlayer != eLoopPlayer && GET_PLAYER(ePlayer).getTeam() != GET_PLAYER(eLoopPlayer).getTeam())4108		{4109			if(IsPlayerValid(eLoopPlayer))4110			{4111				if(GET_TEAM(GetTeam()).isAtWar(GET_PLAYER(eLoopPlayer).getTeam()))4112				{4113					if(GetStateAllWars() == STATE_ALL_WARS_NEUTRAL)4114						viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-9*/ GC.getAPPROACH_WAR_AT_WAR_WITH_PLAYER_WARS_NEUTRAL();4115					else if(GetStateAllWars() == STATE_ALL_WARS_WINNING)4116						viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-3*/ GC.getAPPROACH_WAR_AT_WAR_WITH_PLAYER_WARS_WINNING();4117					else4118						viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-12*/ GC.getAPPROACH_WAR_AT_WAR_WITH_PLAYER_WARS_LOSING();4119				}4120			}4121		}4122	}41234124	////////////////////////////////////4125	// APPROACHES TOWARDS OTHER PLAYERS4126	////////////////////////////////////41274128	// Look at Approaches we've already adopted for players we feel more strongly about4129	if(bLookAtOtherPlayers)4130	{4131		bool bMinorCiv;41324133		// Major Civs4134		for(iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)4135		{4136			eLoopPlayer = (PlayerTypes) iPlayerLoop;41374138			// Don't look at the guy we're already thinking about4139			if(eLoopPlayer != ePlayer)4140			{4141				if(IsPlayerValid(eLoopPlayer))4142				{4143					bMinorCiv = GET_PLAYER(eLoopPlayer).isMinorCiv();41444145					// Planning war with this player? (Can't ONLY use the War Approach because this could have been cleared before, but we have to also check it because it could have just been set for someone else earlier this turn)4146					if(GetWarGoal(eLoopPlayer) == WAR_GOAL_PREPARE ||4147					        (!bMinorCiv && GetMajorCivApproach(eLoopPlayer, /*bHideTrueFeelings*/ false) == MAJOR_CIV_APPROACH_WAR))	// Major Civs only4148					{4149						viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-20*/ GC.getMINOR_APPROACH_WAR_PLANNING_WAR_WITH_ANOTHER_PLAYER();4150					}41514152					// Approaches already assigned to other higher-priority Minors4153					if(bMinorCiv)4154					{4155						switch(GetMinorCivApproach(eLoopPlayer))4156						{4157						case MINOR_CIV_APPROACH_CONQUEST:4158							viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-20*/ GC.getMINOR_APPROACH_WAR_PLANNING_WAR_WITH_ANOTHER_PLAYER();4159							break;4160						case MINOR_CIV_APPROACH_PROTECTIVE:4161							// If we're already protecting other Minors then we've already been stretched thin4162							viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*-2*/ GC.getMINOR_APPROACH_PROTECTIVE_WITH_ANOTHER_PLAYER();4163							break;4164						case MINOR_CIV_APPROACH_BULLY:4165							// If we're already bullying another player, we don't want to piss off too many4166							viApproachWeights[MINOR_CIV_APPROACH_BULLY] += -2; //antonjs: todo: constant/XML4167							break;4168						}4169					}4170				}4171			}4172		}4173	}41744175	////////////////////////////////////4176	// PROXIMITY4177	////////////////////////////////////41784179	switch(GetPlayer()->GetProximityToPlayer(ePlayer))4180	{4181	case PLAYER_PROXIMITY_NEIGHBORS:4182		viApproachWeights[MINOR_CIV_APPROACH_IGNORE] += /*-2*/ GC.getMINOR_APPROACH_IGNORE_PROXIMITY_NEIGHBORS();4183		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*-1*/ GC.getMINOR_APPROACH_FRIENDLY_PROXIMITY_NEIGHBORS();4184		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*1*/ GC.getMINOR_APPROACH_PROTECTIVE_PROXIMITY_NEIGHBORS();4185		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*1*/ GC.getMINOR_APPROACH_CONQUEST_PROXIMITY_NEIGHBORS();4186		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += 1; //antonjs: todo: constant/XML4187		break;4188	case PLAYER_PROXIMITY_CLOSE:4189		viApproachWeights[MINOR_CIV_APPROACH_IGNORE] += /*-1*/ GC.getMINOR_APPROACH_IGNORE_PROXIMITY_CLOSE();4190		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*1*/ GC.getMINOR_APPROACH_PROTECTIVE_PROXIMITY_CLOSE();4191		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-2*/ GC.getMINOR_APPROACH_CONQUEST_PROXIMITY_CLOSE();4192		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += 1; //antonjs: todo: constant/XML4193		break;4194	case PLAYER_PROXIMITY_FAR:4195		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*2*/ GC.getMINOR_APPROACH_FRIENDLY_PROXIMITY_FAR();4196		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-4*/ GC.getMINOR_APPROACH_CONQUEST_PROXIMITY_FAR();4197		break;4198	case PLAYER_PROXIMITY_DISTANT:4199		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*2*/ GC.getMINOR_APPROACH_FRIENDLY_PROXIMITY_DISTANT();4200		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*-10*/ GC.getMINOR_APPROACH_CONQUEST_PROXIMITY_DISTANT();4201		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += -2; //antonjs: todo: constant/XML4202		break;4203	}42044205	////////////////////////////////////4206	// MINOR PERSONALITY4207	////////////////////////////////////42084209	switch(GET_PLAYER(ePlayer).GetMinorCivAI()->GetPersonality())4210	{4211	case MINOR_CIV_PERSONALITY_FRIENDLY:4212		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*0*/ GC.getMINOR_APPROACH_FRIENDLY_PERSONALITY_FRIENDLY();4213		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*0*/ GC.getMINOR_APPROACH_PROTECTIVE_PERSONALITY_PROTECTIVE();4214		break;4215	case MINOR_CIV_PERSONALITY_NEUTRAL:4216		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*0*/ GC.getMINOR_APPROACH_FRIENDLY_PERSONALITY_NEUTRAL();4217		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*0*/ GC.getMINOR_APPROACH_PROTECTIVE_PERSONALITY_NEUTRAL();4218		break;4219	case MINOR_CIV_PERSONALITY_HOSTILE:4220		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*-1*/ GC.getMINOR_APPROACH_FRIENDLY_PERSONALITY_HOSTILE();4221		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*-2*/ GC.getMINOR_APPROACH_PROTECTIVE_PERSONALITY_HOSTILE();4222		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += /*1*/ GC.getMINOR_APPROACH_CONQUEST_PERSONALITY_HOSTILE();4223		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += 1; //antonjs: todo: constant/XML4224		break;4225	case MINOR_CIV_PERSONALITY_IRRATIONAL:4226		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += /*0*/ GC.getMINOR_APPROACH_FRIENDLY_PERSONALITY_IRRATIONAL();4227		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += /*0*/ GC.getMINOR_APPROACH_PROTECTIVE_PERSONALITY_IRRATIONAL();4228		break;4229	}42304231	////////////////////////////////////4232	// MINOR TRAIT4233	////////////////////////////////////42344235	// Since Militaristic CS are harder to successfully bully4236	if(GET_PLAYER(ePlayer).GetMinorCivAI()->GetTrait() == MINOR_CIV_TRAIT_MILITARISTIC)4237	{4238		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += -2; //antonjs: todo: XML4239	}42404241	////////////////////////////////////4242	// TRIBUTE HISTORY - have we bullied this player before?  If so, we are more likely to keep bullying4243	////////////////////////////////////4244	if(GET_PLAYER(ePlayer).GetMinorCivAI()->IsEverBulliedByMajor(GetPlayer()->GetID()))4245	{4246		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += 2; //antonjs: todo: constant/XML4247	}42484249	////////////////////////////////////4250	// QUESTS - are there any active quests that might sway our decision?4251	////////////////////////////////////4252	if(GET_PLAYER(ePlayer).GetMinorCivAI()->IsActiveQuestForPlayer(GetPlayer()->GetID(), MINOR_CIV_QUEST_PLEDGE_TO_PROTECT))4253	{4254		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += 3; //antonjs: todo: constant/XML4255	}42564257	// Are we getting money from trade with them4258	int iCurrentTradeValue = GetPlayer()->GetTrade()->GetAllTradeValueFromPlayerTimes100(YIELD_GOLD, ePlayer) / 100;4259	if(iCurrentTradeValue > 0)4260	{4261		// todo: constant/XML4262		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += 3;4263		viApproachWeights[MINOR_CIV_APPROACH_BULLY] -= 3;4264		viApproachWeights[MINOR_CIV_APPROACH_FRIENDLY] += 5;4265		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] -= 5;42664267		// sanity check4268		int iGPT = GetPlayer()->calculateGoldRate();4269		int iDeltaGPT = iGPT - iCurrentTradeValue;4270		if (iGPT >= 0 && (iDeltaGPT < 0))4271		{4272			viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += iDeltaGPT;4273		}4274	}42754276	////////////////////////////////////4277	// TARGET VALUE - can we conquer these guys?4278	////////////////////////////////////42794280	int iPTV = GetPlayerTargetValue(ePlayer);4281	if (GetPlayer()->GetPlayerTraits()->GetCityStateCombatModifier() > 0)4282	{4283		iPTV++;4284		iPTV = iPTV > TARGET_VALUE_SOFT ? TARGET_VALUE_SOFT : iPTV;4285	}4286	switch(iPTV)4287	{4288	case TARGET_VALUE_IMPOSSIBLE:4289		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] *= /*10*/ GC.getMINOR_APPROACH_WAR_TARGET_IMPOSSIBLE();4290		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] /= 100;4291		break;4292	case TARGET_VALUE_BAD:4293		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] *= /*20*/ GC.getMINOR_APPROACH_WAR_TARGET_BAD();4294		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] /= 100;4295		break;4296	case TARGET_VALUE_AVERAGE:4297		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] *= /*40*/ GC.getMINOR_APPROACH_WAR_TARGET_AVERAGE();4298		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] /= 100;4299		break;4300	case TARGET_VALUE_FAVORABLE:4301		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] *= /*110*/ GC.getMINOR_APPROACH_WAR_TARGET_FAVORABLE();4302		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] /= 100;4303		break;4304	case TARGET_VALUE_SOFT:4305		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] *= /*130*/ GC.getMINOR_APPROACH_WAR_TARGET_SOFT();4306		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] /= 100;4307		break;4308	default:4309		break;4310	}43114312	//////////////////////////////////////4313	//// WAR PROJECTION - how do we think a war against ePlayer will go?4314	//////////////////////////////////////43154316	//switch (GetWarProjection(ePlayer))4317	//{4318	//case WAR_PROJECTION_DESTRUCTION:4319	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] *= /*25*/ GC.getMINOR_APPROACH_WAR_PROJECTION_DESTRUCTION_PERCENT();4320	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] /= 100;4321	//	break;4322	//case WAR_PROJECTION_DEFEAT:4323	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] *= /*40*/ GC.getMINOR_APPROACH_WAR_PROJECTION_DEFEAT_PERCENT();4324	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] /= 100;4325	//	break;4326	//case WAR_PROJECTION_STALEMATE:4327	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] *= /*60*/ GC.getMINOR_APPROACH_WAR_PROJECTION_STALEMATE_PERCENT();4328	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] /= 100;4329	//	break;4330	//case WAR_PROJECTION_UNKNOWN:4331	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] *= /*70*/ GC.getMINOR_APPROACH_WAR_PROJECTION_UNKNOWN_PERCENT();4332	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] /= 100;4333	//	break;4334	//case WAR_PROJECTION_GOOD:4335	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] *= /*100*/ GC.getMINOR_APPROACH_WAR_PROJECTION_GOOD_PERCENT();4336	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] /= 100;4337	//	break;4338	//case WAR_PROJECTION_VERY_GOOD:4339	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] *= /*110*/ GC.getMINOR_APPROACH_WAR_PROJECTION_VERY_GOOD_PERCENT();4340	//	viApproachWeights[MAJOR_CIV_APPROACH_WAR] /= 100;4341	//	break;4342	//}43434344	////////////////////////////////////4345	// PEACE TREATY - have we made peace with this player before?  If so, reduce war weight4346	////////////////////////////////////43474348	int iPeaceTreatyTurn = GET_TEAM(GetTeam()).GetTurnMadePeaceTreatyWithTeam(eTeam);4349	if(iPeaceTreatyTurn > -1)4350	{4351		int iTurnsSincePeace = GC.getGame().getElapsedGameTurns() - iPeaceTreatyTurn;4352		if(iTurnsSincePeace < /*25*/ GC.getTURNS_SINCE_PEACE_WEIGHT_DAMPENER())4353		{4354			viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] *= /*65*/ GC.getAPPROACH_WAR_HAS_MADE_PEACE_BEFORE_PERCENT();4355			viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] /= 100;4356		}4357	}43584359	////////////////////////////////////4360	// DEBUGGING4361	////////////////////////////////////4362	if(BULLY_DEBUGGING)4363	{4364		viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] += 50;4365		viApproachWeights[MINOR_CIV_APPROACH_BULLY] += 0;4366		viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] += 0;4367	}43684369	////////////////////////////////////4370	// RANDOM FACTOR4371	////////////////////////////////////43724373	int iRandAmount;4374	for(iApproachLoop = 0; iApproachLoop < NUM_MINOR_CIV_APPROACHES; iApproachLoop++)4375	{4376		// Increase weights to hundreds to give us more fidelity4377		viApproachWeights[iApproachLoop] *= 100;43784379		iRandAmount = viApproachWeights[iApproachLoop] * /*15*/ GC.getAPPROACH_RANDOM_PERCENT();43804381		// If the amount is negative, only bad things can happen.  Plus, it's not likely we're going to pick this anyways4382		if(iRandAmount > 0)4383		{4384			iRandAmount /= 100;4385			viApproachWeights[iApproachLoop] += GC.getGame().getJonRandNumVA(iRandAmount, "Randomizing Diplo AI Minor Civ Approach Weight (%d; %d)", (int)GetPlayer()->GetID(), (int)ePlayer);4386		}4387	}43884389	////////////////////////////////////4390	// CAN WE PLEDGE TO PROTECT?4391	////////////////////////////////////4392	if(!GET_PLAYER(ePlayer).GetMinorCivAI()->CanMajorProtect(GetPlayer()->GetID()))4393	{4394		// Disfavor protective if we can't actually pledge protection!4395		if (viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] > 0)4396			viApproachWeights[MINOR_CIV_APPROACH_PROTECTIVE] = 0;4397	}43984399	////////////////////////////////////4400	// CAN WE DECLARE WAR?4401	////////////////////////////////////4402#if defined(MOD_EVENTS_WAR_AND_PEACE)4403	if(!GET_TEAM(GetTeam()).canDeclareWar(GET_PLAYER(ePlayer).getTeam(), GetPlayer()->GetID()))4404#else4405	if(!GET_TEAM(GetTeam()).canDeclareWar(GET_PLAYER(ePlayer).getTeam()))4406#endif4407	{4408		if(!GET_TEAM(GetTeam()).isAtWar(GET_PLAYER(ePlayer).getTeam()))4409		{4410			// Disfavor conquest if we can't even do war with them!4411			if (viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] > 0)4412				viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] = 0;4413		}4414	}4415	4416	////////////////////////////////////4417	// ALLIES WITH MINOR?4418	////////////////////////////////////4419	if(GET_PLAYER(ePlayer).GetMinorCivAI()->GetAlly() == GetPlayer()->GetID())4420	{4421		// Disfavor conquest and bullying if they are our ally44224423		if (viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] > 0)4424			viApproachWeights[MINOR_CIV_APPROACH_CONQUEST] = 0;44254426		if (viApproachWeights[MINOR_CIV_APPROACH_BULLY] > 0)4427			viApproachWeights[MINOR_CIV_APPROACH_BULLY] = 0;4428	}44294430	// This vector is what we'll use to sort4431	CvWeightedVector< MinorCivApproachTypes, 128 > vApproachWeightsForSorting;4432	vApproachWeightsForSorting.clear();44334434	// Transfer values from our normal int vector (which we need for logging) to the Weighted Vector we can sort4435	for(iApproachLoop = 0; iApproachLoop < NUM_MINOR_CIV_APPROACHES; iApproachLoop++)4436	{4437		vApproachWeightsForSorting.push_back((MinorCivApproachTypes) iApproachLoop, viApproachWeights[iApproachLoop]);4438	}44394440	vApproachWeightsForSorting.SortItems();44414442	eApproach = vApproachWeightsForSorting.GetElement(0);4443	iHighestWeight = vApproachWeightsForSorting.GetWeight(0);44444445	// Don't want to log if we're just seeing what the highest weight is and don't care about what Approach we like4446	if(bLog)4447	{4448		LogMinorCivApproachUpdate(ePlayer, viApproachWeights.begin(), eApproach, eOldApproach);4449	}44504451	return eApproach;4452}

Calls

Called by