Bazaar developer reference

CvDiplomacyAI::DoContactMinorCivs()

Defined in
CvDiplomacyAI.cpp, line 12829
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoContactMinorCivs
Lua events
GameEvents.PlayerCanGiftGold

Hooks

static bool BeforeCvDiplomacyAI_DoContactMinorCivs(CvDiplomacyAI* self);static void AfterCvDiplomacyAI_DoContactMinorCivs(CvDiplomacyAI* self);static void ReplaceCvDiplomacyAI_DoContactMinorCivs(void (*original)(CvDiplomacyAI*), CvDiplomacyAI* self);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoContactMinorCivs>(host, &BeforeCvDiplomacyAI_DoContactMinorCivs);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoContactMinorCivs>(host, &AfterCvDiplomacyAI_DoContactMinorCivs);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoContactMinorCivs>(host, &ReplaceCvDiplomacyAI_DoContactMinorCivs);

Code

12828/// Anyone we want to chat with?12829void CvDiplomacyAI::DoContactMinorCivs()12830{12831	// If the player has deleted the DIPLOMACY Flavor we have to account for that12832	int iDiplomacyFlavor = /*5*/ GC.getDEFAULT_FLAVOR_VALUE();12833	int iGoldFlavor = /*5*/ GC.getDEFAULT_FLAVOR_VALUE();12834	int iTileImprovementFlavor = /*5*/ GC.getDEFAULT_FLAVOR_VALUE();12835	int iExpansionFlavor = /*5*/ GC.getDEFAULT_FLAVOR_VALUE();1283612837	for(int iFlavorLoop = 0; iFlavorLoop < GC.getNumFlavorTypes(); iFlavorLoop++)12838	{12839		if(GC.getFlavorTypes((FlavorTypes) iFlavorLoop) == "FLAVOR_DIPLOMACY")12840		{12841			iDiplomacyFlavor = GetPlayer()->GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes) iFlavorLoop);12842		}12843		else if(GC.getFlavorTypes((FlavorTypes) iFlavorLoop) == "FLAVOR_GOLD")12844		{12845			iGoldFlavor = GetPlayer()->GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes) iFlavorLoop);12846		}12847		else if(GC.getFlavorTypes((FlavorTypes) iFlavorLoop) == "FLAVOR_TILE_IMPROVEMENT")12848		{12849			iTileImprovementFlavor = GetPlayer()->GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes) iFlavorLoop);12850		}12851		else if(GC.getFlavorTypes((FlavorTypes) iFlavorLoop) == "FLAVOR_EXPANSION")12852		{12853			iExpansionFlavor = GetPlayer()->GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes) iFlavorLoop);12854		}12855	}12856	EconomicAIStrategyTypes eFoundCity = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_FOUND_CITY");12857	EconomicAIStrategyTypes eExpandLikeCrazy = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_EXPAND_LIKE_CRAZY");12858	EconomicAIStrategyTypes eExpandToOtherContinents = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_EXPAND_TO_OTHER_CONTINENTS");12859	EconomicAIStrategyTypes eNeedHappiness = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_NEED_HAPPINESS");12860	EconomicAIStrategyTypes eNeedHappinessCritical = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_NEED_HAPPINESS_CRITICAL");12861	EconomicAIStrategyTypes eLosingMoney = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_LOSING_MONEY");12862	bool bFoundCity = (eFoundCity != NO_ECONOMICAISTRATEGY) ? GetPlayer()->GetEconomicAI()->IsUsingStrategy(eFoundCity) : false;12863	bool bExpandLikeCrazy = (eExpandLikeCrazy != NO_ECONOMICAISTRATEGY) ? GetPlayer()->GetEconomicAI()->IsUsingStrategy(eExpandLikeCrazy) : false;12864	bool bExpandToOtherContinents = (eExpandToOtherContinents != NO_ECONOMICAISTRATEGY) ? GetPlayer()->GetEconomicAI()->IsUsingStrategy(eExpandToOtherContinents) : false;12865	bool bNeedHappiness = (eNeedHappiness != NO_ECONOMICAISTRATEGY) ? GetPlayer()->GetEconomicAI()->IsUsingStrategy(eNeedHappiness) : false;12866	bool bNeedHappinessCritical = (eNeedHappinessCritical != NO_ECONOMICAISTRATEGY) ? GetPlayer()->GetEconomicAI()->IsUsingStrategy(eNeedHappinessCritical) : false;12867	bool bLosingMoney = (eLosingMoney != NO_ECONOMICAISTRATEGY) ? GetPlayer()->GetEconomicAI()->IsUsingStrategy(eLosingMoney) : false;1286812869	// **************************12870	// Would we like to buyout a minor this turn?  (Austria UA)12871	// **************************12872	bool bWantsToBuyout = false;12873	if(GetPlayer()->IsAbleToAnnexCityStates())12874	{12875		if(bFoundCity || bExpandLikeCrazy || bExpandToOtherContinents ||12876		        GetStateAllWars() == STATE_ALL_WARS_LOSING ||12877		        IsGoingForWorldConquest() ||12878		        m_pPlayer->calculateGoldRate() > 100)12879		{12880			bWantsToBuyout = true;12881		}12882		else12883		{12884			int iThreshold = iExpansionFlavor * 5; //antonjs: todo: xml12885			int iRandRoll = GC.getGame().getJonRandNum(100, "Diplomacy AI: good turn to buyout a minor?");1288612887			if(iRandRoll < iThreshold)12888				bWantsToBuyout = true;12889		}12890	}1289112892	// **************************12893	// Would we like to give a gold gift this turn?12894	// **************************12895	bool bWantsToMakeGoldGift = false;1289612897	// If we're a highly diplomatic leader, then always look for an opportunity12898	if(iDiplomacyFlavor >= /*4*/ GC.getMC_ALWAYS_GIFT_DIPLO_THRESHOLD() ||12899	        IsGoingForDiploVictory() ||12900	        IsGoingForCultureVictory() ||12901	        GetPlayer()->GetEconomicAI()->IsSavingForThisPurchase(PURCHASE_TYPE_MINOR_CIV_GIFT) ||12902	        IsHasActiveGoldQuest() ||12903	        m_pPlayer->calculateGoldRate() > 100) // if we are very wealthy always do this12904	{12905		bWantsToMakeGoldGift = true;12906	}12907	// Otherwise, do a random roll12908	else12909	{12910		int iThreshold = iDiplomacyFlavor* /*5*/ GC.getMC_SOMETIMES_GIFT_RAND_MULTIPLIER();12911		int iRandRoll = GC.getGame().getJonRandNum(100, "Diplomacy AI: good turn to make a gold gift to a minor?");1291212913		// Threshold will be 15 for a player (3 flavor * 5)12914		// Threshold will be 5 for non-diplomatic player (2 flavor * 5)1291512916		if(iRandRoll < iThreshold)12917			bWantsToMakeGoldGift = true;12918	}1291912920	// **************************12921	// Would we like to get a unit by bullying this turn?12922	// **************************12923	bool bWantsToBullyUnit = false;1292412925	if(GetPlayer()->GetEconomicAI()->GetWorkersToCitiesRatio() < 0.25 &&  //antonjs: todo: XML12926	        GetPlayer()->GetEconomicAI()->GetImprovedToImprovablePlotsRatio() < 0.50) //antonjs: todo: XML12927	{12928		bWantsToBullyUnit = true;12929	}12930	// Otherwise, do a random roll12931	else12932	{12933		int iThreshold = iTileImprovementFlavor * 3; //antonjs: todo: XML12934		int iRandRoll = GC.getGame().getJonRandNum(100, "Diplomacy AI: good turn to bully a unit (worker) from a minor?");1293512936		if(iRandRoll < iThreshold)12937			bWantsToBullyUnit = true;12938	}12939	//antonjs: todo: if too many workers then set to false (ex. want to disband workers you have)1294012941	// **************************12942	// Would we like to get some gold by bullying this turn?12943	// **************************12944	bool bWantsToBullyGold = false;1294512946	if(iGoldFlavor >= 6 ||  //antonjs: todo: GC.getMC_ALWAYS_BULLY_GOLD_THRESHOLD()12947	        IsGoingForWorldConquest() ||12948	        GetPlayer()->GetEconomicAI()->IsSavingForThisPurchase(PURCHASE_TYPE_UNIT) ||12949	        GetPlayer()->GetEconomicAI()->IsSavingForThisPurchase(PURCHASE_TYPE_BUILDING) ||12950	        bLosingMoney ||12951	        m_pPlayer->calculateGoldRate() < 0) // if we are losing gold per turn12952	{12953		bWantsToBullyGold = true;12954	}12955	// Otherwise, do a random roll12956	else12957	{12958		int iThreshold = iGoldFlavor * 4; //antonjs: todo: XML12959		int iRandRoll = GC.getGame().getJonRandNum(100, "Diplomacy AI: good turn to bully gold from a minor?");1296012961		if(iRandRoll < iThreshold)12962			bWantsToBullyGold = true;12963	}1296412965	if(BULLY_DEBUGGING)12966	{12967		//bWantsToMakeGoldGift = false;12968		//bWantsToBullyGold = true;12969		//bWantsToBullyUnit = true;12970	}1297112972	CvWeightedVector<PlayerTypes, MAX_PLAYERS, true> veMinorsToBuyout; // Austria UA12973	CvWeightedVector<MinorGoldGiftInfo, MAX_PLAYERS, true> veMinorsToGiveGold;12974	CvWeightedVector<PlayerTypes, MAX_PLAYERS, true> veMinorsToBullyGold;12975	CvWeightedVector<PlayerTypes, MAX_PLAYERS, true> veMinorsToBullyUnit;1297612977	int iLargeGift = /*1000*/ GC.getMINOR_GOLD_GIFT_LARGE();12978	int iMediumGift = /*500*/ GC.getMINOR_GOLD_GIFT_MEDIUM();12979	int iSmallGift = /*250*/ GC.getMINOR_GOLD_GIFT_SMALL();12980	int iLargeGiftFriendship;12981	int iMediumGiftFriendship;12982	int iSmallGiftFriendship;12983	bool bMediumGiftAllies;12984	bool bSmallGiftAllies;1298512986	PlayerTypes eID = GetPlayer()->GetID();1298712988	CvMinorCivInfo* pMinorInfo;12989	CvPlayer* pMinor;12990	CvMinorCivAI* pMinorCivAI;1299112992	bool bIntruding;1299312994	int iOtherMajorLoop;12995	PlayerTypes eOtherMajor;12996	int iFriendshipWithMinor;12997	int iOtherPlayerFriendshipWithMinor;1299812999	bool bWantsToConnect;1300013001	MinorCivApproachTypes eApproach;1300213003	int iGrowthFlavor = GetPlayer()->GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes) GC.getInfoTypeForString("FLAVOR_GROWTH"));1300413005	// Loop through all (known) Minors13006	PlayerTypes eMinor;13007	TeamTypes eMinorTeam;13008	for(int iMinorLoop = MAX_MAJOR_CIVS; iMinorLoop < MAX_CIV_PLAYERS; iMinorLoop++)13009	{13010		eMinor = (PlayerTypes) iMinorLoop;1301113012		pMinor = &GET_PLAYER(eMinor);13013		pMinorCivAI = pMinor->GetMinorCivAI();13014		eMinorTeam = pMinor->getTeam();1301513016		bWantsToConnect = false;13017		bool bWantsToGiveGoldToThisMinor = false;13018		bool bWantsToBullyUnitFromThisMinor = false;13019		bool bWantsToBullyGoldFromThisMinor = false;13020		bool bWantsToBuyoutThisMinor = false;1302113022		if(IsPlayerValid(eMinor))13023		{13024			// Can't do anything with minors we're at war with, besides make peace (which isn't done here, but in DoMakePeaceWithMinors())13025			if(IsAtWar(eMinor))13026				continue;1302713028			eApproach = GetMinorCivApproach(eMinor);1302913030			// Do we want to change our protection of this minor?13031			DoUpdateMinorCivProtection(eMinor, eApproach);1303213033			// Do we want to connect to this player?13034			if(pMinorCivAI->IsActiveQuestForPlayer(eID, MINOR_CIV_QUEST_ROUTE))13035			{13036				if(eApproach == MINOR_CIV_APPROACH_PROTECTIVE ||13037				        eApproach == MINOR_CIV_APPROACH_FRIENDLY)13038				{13039					if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_NEIGHBORS)13040						bWantsToConnect = true;13041				}13042			}1304313044			bIntruding = true;1304513046			// We have open borders so we're definitely not intruding13047			if(pMinorCivAI->IsPlayerHasOpenBorders(eID))13048				bIntruding = false;1304913050			else13051			{13052				// Cares and doesn't yet have enough friendship for Open Borders13053				if(eApproach == MINOR_CIV_APPROACH_PROTECTIVE || eApproach == MINOR_CIV_APPROACH_FRIENDLY)13054					bIntruding = false;13055			}1305613057			pMinorCivAI->SetMajorIntruding(eID, bIntruding);1305813059			// Calculate desirability to buyout this minor13060			if(bWantsToBuyout)13061			{13062				int iValue = 100; //antonjs: todo: xml13063				// Only bother if we actually can buyout13064				CvCity* pMinorCapital = pMinor->getCapitalCity();13065				if(GetPlayer()->IsAbleToAnnexCityStates() && pMinorCivAI->CanMajorBuyout(eID) && pMinorCapital != NULL)13066				{13067					// Determine presence of player cities on this continent13068					int iMinorArea = pMinorCapital->getArea();13069					CvArea* pMinorArea = GC.getMap().getArea(iMinorArea);13070					bool bPresenceInArea = false;13071					int iMajorCapitalsInArea = 0;13072					if(pMinorArea)13073					{13074						// Do we have a city here?13075						if(pMinorArea->getCitiesPerPlayer(eID) > 0)13076							bPresenceInArea = true;1307713078						// Does another major civ have their capital here? (must be visible)13079						for(int iMajorRivalLoop = 0; iMajorRivalLoop < MAX_MAJOR_CIVS; iMajorRivalLoop++)13080						{13081							PlayerTypes eMajorRivalLoop = (PlayerTypes) iMajorRivalLoop;13082							if(eMajorRivalLoop == eID)13083								continue;1308413085							if(GET_PLAYER(eMajorRivalLoop).isAlive())13086							{13087								CvCity* pCapital = GET_PLAYER(eMajorRivalLoop).getCapitalCity();13088								if(pCapital && pCapital->plot())13089								{13090									CvPlot* pPlot = pCapital->plot();13091									if(pPlot->isVisible(GetPlayer()->getTeam()))13092										iMajorCapitalsInArea++;13093								}13094							}13095						}13096					}13097					else13098					{13099						CvAssertMsg(false, "Could not lookup minor civ's area! Please send Anton your save file and version.");13100					}1310113102					// How many units does the city-state have?13103					int iMinorMilitaryUnits = 0;13104					int iMinorUnits = 0;13105					CvUnit* pLoopUnit;13106					int iLoop;13107					for(pLoopUnit = pMinor->firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = pMinor->nextUnit(&iLoop))13108					{13109						if(pLoopUnit->IsCanAttack() && pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE && pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE_SEA)13110						{13111							iMinorMilitaryUnits++;13112						}13113						iMinorUnits++;13114					}1311513116					// Foreign continent13117					if(!bPresenceInArea)13118					{13119						// Military foothold to attack other majors13120						if(IsGoingForWorldConquest() && iMajorCapitalsInArea > 0)13121						{13122							iValue += 100; //antonjs: todo: xml13123						}13124						// Expansion13125						else if(bExpandToOtherContinents)13126						{13127							iValue += 60; //antonjs: todo: xml13128						}13129						else13130						{13131							iValue += -50; //antonjs: todo: xml13132						}13133					}13134					// Continent we have presence on13135					else13136					{13137						// Proximity plays a large factor, since we don't want a remote, isolated city13138						if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_NEIGHBORS)13139						{13140							iValue += 100; //antonjs: todo: xml13141							// Military units could come to our rescue quickly13142							if(GetStateAllWars() == STATE_ALL_WARS_LOSING)13143							{13144								if(iMinorMilitaryUnits > 0)  //antonjs: todo: xml13145								{13146									iValue += (iMinorMilitaryUnits) * 10; //antonjs: todo: xml13147								}13148								else13149								{13150									iValue -= 50; //antonjs: todo: xml13151								}13152							}13153						}13154						else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_CLOSE)13155						{13156							iValue += 10; //antonjs: todo: xml13157						}13158						else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_FAR)13159						{13160							iValue += -50; //antonjs: todo: xml13161						}13162						else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_DISTANT)13163						{13164							iValue += -100; //antonjs: todo: xml13165						}13166					}1316713168					// Military units - How many, and can we support them?13169					if(GetPlayer()->GetNumUnitsSupplied() >= GetPlayer()->getNumUnits() + iMinorUnits)13170					{13171						iValue += (iMinorMilitaryUnits) * 5;13172					}1317313174					// Happiness13175					if(bNeedHappiness)13176						iValue += -50; //antonjs: todo: xml13177					if(bNeedHappinessCritical)13178						iValue += -150; //antonjs: todo: xml1317913180					// Potential bonuses lost13181					MinorCivTraitTypes eTrait = pMinorCivAI->GetTrait();13182					if(eTrait == MINOR_CIV_TRAIT_CULTURED && IsGoingForCultureVictory())13183					{13184						iValue += -70; //antonjs: todo: xml13185					}13186					else if(eTrait == MINOR_CIV_TRAIT_MERCANTILE)13187					{13188						if(bNeedHappiness)13189							iValue += -100; //antonjs: todo: xml13190						if(bNeedHappinessCritical)13191							iValue += -150; //antonjs: todo: xml13192					}1319313194					// Time to decide - Do we want it enough?13195					if(iValue > 100)  //antonjs: todo: xml13196					{13197						veMinorsToBuyout.push_back(eMinor, iValue);13198						bWantsToBuyoutThisMinor = true;13199					}13200				}13201			}1320213203			// Calculate desirability to give this minor gold13204			if(bWantsToMakeGoldGift && !bWantsToBuyoutThisMinor)13205			{13206				int iValue = /*100*/ GC.getMC_GIFT_WEIGHT_THRESHOLD();13207				// If we're not protective or friendly, then don't bother with minor diplo13208				if(eApproach == MINOR_CIV_APPROACH_PROTECTIVE || eApproach == MINOR_CIV_APPROACH_FRIENDLY)13209				{13210					MinorGoldGiftInfo sGiftInfo;13211					sGiftInfo.eMinor = eMinor;13212					sGiftInfo.eMajorRival = NO_PLAYER;13213					sGiftInfo.bQuickBoost = false;13214					sGiftInfo.iGoldAmount = 0;1321513216					// if we are rich we are more likely to, conversely if we are poor...13217					iValue += min(max(0, m_pPlayer->calculateGoldRate() - 50),100);1321813219					pMinorInfo = GC.getMinorCivInfo(pMinorCivAI->GetMinorCivType());1322013221					// Diplo victory makes us more likely to spend gold13222					if(IsGoingForDiploVictory())13223						iValue += /*100*/ GC.getMC_GIFT_WEIGHT_DIPLO_VICTORY();13224					// double up if this is the home stretch13225					if(GC.getGame().IsUnitedNationsActive())13226					{13227						iValue += /*100*/ GC.getMC_GIFT_WEIGHT_DIPLO_VICTORY();13228					}13229					// Going for Culture victory, focus on Cultural city states13230					else if(IsGoingForCultureVictory())13231					{13232						if(pMinorInfo->GetMinorCivTrait() == MINOR_CIV_TRAIT_CULTURED)13233							iValue += /*100*/ GC.getMC_GIFT_WEIGHT_CULTURE_VICTORY();13234					}13235					// Going for Conquest victory, focus on Militaristic city states13236					else if(IsGoingForWorldConquest())13237					{13238						if(pMinorInfo->GetMinorCivTrait() == MINOR_CIV_TRAIT_MILITARISTIC)13239							iValue += /*100*/ GC.getMC_GIFT_WEIGHT_CONQUEST_VICTORY();13240					}1324113242					//antonjs: todo: work extra gold quest INF potential into the friends/allies/passing logic as well13243					// Gold gift quest is active, so we would get more bang for our bucks13244					if(pMinorCivAI->IsActiveQuestForPlayer(eID, MINOR_CIV_QUEST_GIVE_GOLD))13245					{13246						iValue += 150; //antonjs: todo: constant/XML13247					}1324813249					// Invest quest is active, so we would get more bang for our bucks13250					if(pMinorCivAI->IsActiveQuestForPlayer(eID, MINOR_CIV_QUEST_INVEST))13251					{13252						iValue += 100; //antonjs: todo: constant/XML13253					}1325413255					// having traits that give us bonuses also make us want to spend gold13256					if(m_pPlayer->GetPlayerTraits()->GetCityStateFriendshipModifier() > 0 || m_pPlayer->GetPlayerTraits()->GetCityStateBonusModifier())13257					{13258						iValue += /*100*/ GC.getMC_GIFT_WEIGHT_DIPLO_VICTORY();13259					}1326013261					// Nearly everyone likes to grow13262					if(pMinorInfo->GetMinorCivTrait() == MINOR_CIV_TRAIT_MARITIME && !GetPlayer()->IsEmpireUnhappy())13263					{13264						iValue += /*20*/ GC.getMC_GIFT_WEIGHT_MARITIME_GROWTH() * iGrowthFlavor * max(1, GetPlayer()->getNumCities() / 3);13265					}1326613267					// Slight negative weight towards militaristic13268					if(pMinorInfo->GetMinorCivTrait() == MINOR_CIV_TRAIT_MILITARISTIC && !IsGoingForWorldConquest())13269						iValue += /*-50*/ GC.getMC_GIFT_WEIGHT_MILITARISTIC();1327013271					// If they have a resource we don't have, add extra weight13272					int iResourcesWeLack = pMinorCivAI->GetNumResourcesMajorLacks(eID);13273					if(iResourcesWeLack > 0)13274						iValue += (iResourcesWeLack* /*80*/ GC.getMC_GIFT_WEIGHT_RESOURCE_WE_NEED());1327513276					// If we're protective this is worth more than if we're friendly13277					if(eApproach == MINOR_CIV_APPROACH_PROTECTIVE)13278						iValue += /*10*/ GC.getMC_GIFT_WEIGHT_PROTECTIVE();1327913280					// If the minor is hostile, then reduce the weighting13281					if(pMinorCivAI->GetPersonality() == MINOR_CIV_PERSONALITY_HOSTILE)13282						iValue += /*-20*/ GC.getMC_GIFT_WEIGHT_HOSTILE();1328313284					// The closer we are the better13285					if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_NEIGHBORS)13286						iValue += /*5*/ GC.getMC_GIFT_WEIGHT_NEIGHBORS();13287					else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_CLOSE)13288						iValue += /*4*/ GC.getMC_GIFT_WEIGHT_CLOSE();13289					else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_FAR)13290						iValue += /*3*/ GC.getMC_GIFT_WEIGHT_FAR();1329113292					iLargeGiftFriendship = pMinorCivAI->GetFriendshipFromGoldGift(eID, iLargeGift);13293					iMediumGiftFriendship = pMinorCivAI->GetFriendshipFromGoldGift(eID, iMediumGift);13294					iSmallGiftFriendship = pMinorCivAI->GetFriendshipFromGoldGift(eID, iSmallGift);1329513296					iFriendshipWithMinor = pMinorCivAI->GetEffectiveFriendshipWithMajor(eID);1329713298					// Loop through other players to see if we can pass them13299					for(iOtherMajorLoop = 0; iOtherMajorLoop < MAX_MAJOR_CIVS; iOtherMajorLoop++)13300					{13301						eOtherMajor = (PlayerTypes) iOtherMajorLoop;1330213303						// Player must be alive13304						if(!GET_PLAYER(eOtherMajor).isAlive())13305							continue;1330613307						iOtherPlayerFriendshipWithMinor = pMinorCivAI->GetEffectiveFriendshipWithMajor(eOtherMajor);1330813309						// Player must have friendship with this major13310						if(iOtherPlayerFriendshipWithMinor <= 0)13311							continue;1331213313						// They must have more friendship with this guy than us13314						if(iFriendshipWithMinor <= iOtherPlayerFriendshipWithMinor)13315							continue;1331613317						// Only care if we'll actually be Allies or better13318						bMediumGiftAllies = iFriendshipWithMinor + iMediumGiftFriendship >= pMinorCivAI->GetAlliesThreshold();13319						bSmallGiftAllies = iFriendshipWithMinor + iSmallGiftFriendship >= pMinorCivAI->GetAlliesThreshold();1332013321						// If we can pass them with a small gift, great13322						if(bSmallGiftAllies && iOtherPlayerFriendshipWithMinor - iFriendshipWithMinor < iSmallGiftFriendship)13323						{13324							iValue += /*15*/ GC.getMC_SMALL_GIFT_WEIGHT_PASS_OTHER_PLAYER();13325							sGiftInfo.bQuickBoost = true;13326							sGiftInfo.eMajorRival = eOtherMajor;13327						}13328						// If a medium gift passes them up, that's good too13329						else if(bMediumGiftAllies && iOtherPlayerFriendshipWithMinor - iFriendshipWithMinor < iMediumGiftFriendship)13330						{13331							iValue += /*10*/ GC.getMC_GIFT_WEIGHT_PASS_OTHER_PLAYER();13332							sGiftInfo.eMajorRival = eOtherMajor;13333						}13334						// We're behind and we can't catch up right now, so zero-out the value13335						else13336							iValue = 0;13337					}1333813339					// Are we already allies?13340					if(pMinorCivAI->IsAllies(eID))13341					{13342						// Are we close to losing our status?13343						if(pMinorCivAI->IsCloseToNotBeingAllies(eID))13344						{13345							iValue += /*150*/ GC.getMC_GIFT_WEIGHT_ALMOST_NOT_ALLIES();13346							sGiftInfo.bQuickBoost = true;13347						}13348						// Not going to lose status, so not worth going after this guy13349						else13350							iValue = 0;13351					}13352					// Are we already Friends?13353					else if(pMinorCivAI->IsFriends(eID))13354					{13355						// Are we close to losing our status?13356						if(pMinorCivAI->IsCloseToNotBeingFriends(eID))13357						{13358							iValue += /*125*/ GC.getMC_GIFT_WEIGHT_ALMOST_NOT_FRIENDS();13359							sGiftInfo.bQuickBoost = true;13360						}13361						// Not going to lose status, so not worth going after this guy13362						else if(!IsGoingForDiploVictory() || !GC.getGame().IsUnitedNationsActive())13363							iValue = 0;13364					}1336513366					// Did we bully you recently?  If so, giving you gold now would be very odd.13367					if(pMinorCivAI->IsRecentlyBulliedByMajor(eID))13368					{13369						iValue -= 100; //antonjs: todo: constant/XML13370					}1337113372					//antonjs: consider: different behavior to CS that have been bullied by others, bullied by rival, etc.1337313374#if defined(MOD_EVENTS_MINORS_INTERACTION)13375					if (MOD_EVENTS_MINORS_INTERACTION) {13376						if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_PlayerCanGiftGold, eID, eMinor) == GAMEEVENTRETURN_FALSE) {13377							iValue = 0;13378						}13379					}13380#endif				13381					// Do we want it enough?13382					if(iValue > GC.getMC_GIFT_WEIGHT_THRESHOLD())13383					{13384						veMinorsToGiveGold.push_back(sGiftInfo, iValue);13385						bWantsToGiveGoldToThisMinor = true;13386					}13387				}13388			}1338913390			// Calculate desirability to bully a unit from this minor13391			if(bWantsToBullyUnit && !bWantsToBuyoutThisMinor && !bWantsToGiveGoldToThisMinor)  //antonjs: todo: xml13392			{13393				int iValue = 100; //antonjs: todo: XML, bully threshold13394				if(eApproach == MINOR_CIV_APPROACH_BULLY)13395				{13396					// Only bother if we can successfully bully13397					if(pMinor->GetMinorCivAI()->CanMajorBullyUnit(eID))13398					{13399						// The closer we are the better, because the unit travels less distance to get home13400						if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_NEIGHBORS)13401							iValue += 50;13402						else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_CLOSE)13403							iValue += 30;13404						else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_FAR)13405							iValue += -30;13406						else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_DISTANT)13407							iValue += -50;1340813409						//antonjs: consider: knock it down if is there a chance the worker will get captured by a nearby rival1341013411						//antonjs: consider: if military unit, it would be a good thing to get it near a rival or ongoing war1341213413						// If this minor has a PtP from someone, bullying it could have big consequences13414						if(pMinor->GetMinorCivAI()->IsProtectedByAnyMajor())13415						{13416							iValue += -20;13417							//antonjs: consider: scale based on which major is protecting it13418						}13419						else13420						{13421							iValue += 20;13422						}1342313424						//antonjs: consider: allies or friends with another major13425						//antonjs: consider: distance to other majors1342613427						// If we are getting a bonus, don't mess that up!13428						if(pMinor->GetMinorCivAI()->IsAllies(eID) || pMinor->GetMinorCivAI()->IsFriends(eID))13429						{13430							iValue = 0;13431						}1343213433						// Do we want it enough?13434						if(iValue > 100)  //antonjs: todo: XML for threshold13435						{13436							veMinorsToBullyUnit.push_back(eMinor, iValue);13437							bWantsToBullyUnitFromThisMinor = true;13438						}13439					}13440				}13441			}1344213443			// Calculate desirability to bully gold from this minor13444			if(bWantsToBullyGold && !bWantsToBuyoutThisMinor && !bWantsToGiveGoldToThisMinor && !bWantsToBullyUnitFromThisMinor)13445			{13446				int iValue = 100; //antonjs: todo: XML, bully threshold13447				if(eApproach == MINOR_CIV_APPROACH_BULLY)13448				{13449					// Only bother if we can successfully bully13450					if(pMinor->GetMinorCivAI()->CanMajorBullyGold(eID))13451					{13452						// The closer we are the better13453						if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_NEIGHBORS)13454							iValue += 40;13455						else if(GetPlayer()->GetProximityToPlayer(eMinor) == PLAYER_PROXIMITY_CLOSE)13456							iValue += 20;1345713458						// We like to keep bullying the same minor13459						if(pMinor->GetMinorCivAI()->IsEverBulliedByMajor(eID))13460						{13461							iValue += 20;13462						}1346313464						// If we have not bullied this minor recently, but someone else has, it might be good to wait for an opportunity to gain a lot of INF13465						if(!pMinor->GetMinorCivAI()->IsRecentlyBulliedByMajor(eID) && pMinor->GetMinorCivAI()->IsRecentlyBulliedByAnyMajor())13466						{13467							iValue += -10;13468							//antonjs: consider: but if everyone near the minor has bullied it, then there is nobody to come to its rescue, so we can bully safely13469						}1347013471						// If this minor has a PtP from someone, bullying it could have big consequences13472						if(pMinor->GetMinorCivAI()->IsProtectedByAnyMajor())13473						{13474							iValue += -10;13475							//antonjs: consider: scale based on which major is protecting it13476						}13477						else13478						{13479							iValue += 10;13480						}1348113482						//antonjs: consider: allies or friends another major13483						//antonjs: consider: distance to other majors1348413485						// If we are getting a bonus, don't mess that up!13486						if(pMinor->GetMinorCivAI()->IsAllies(eID) || pMinor->GetMinorCivAI()->IsFriends(eID))13487						{13488							iValue = 0;13489						}1349013491						// Do we want it enough?13492						if(iValue > 100)  //antonjs: todo: XML for threshold13493						{13494							veMinorsToBullyGold.push_back(eMinor, iValue);13495							bWantsToBullyGoldFromThisMinor = true;13496						}13497					}13498				}13499			}1350013501		}1350213503		SetWantToRouteConnectToMinor(eMinor, bWantsToConnect);13504	}1350513506	int iGoldReserve = GetPlayer()->GetTreasury()->GetGold();1350713508	// Do we want to buyout a minor?13509	if(veMinorsToBuyout.size() > 0)13510	{13511		veMinorsToBuyout.SortItems();13512		int iGoldLeft = GetPlayer()->GetTreasury()->GetGold();13513		PlayerTypes eLoopMinor = NO_PLAYER;13514		for(int i = 0; i < veMinorsToBuyout.size(); i++)13515		{13516			eLoopMinor = veMinorsToBuyout.GetElement(i);13517			int iBuyoutCost = GET_PLAYER(eLoopMinor).GetMinorCivAI()->GetBuyoutCost(eID);13518			if(iGoldLeft >= iBuyoutCost)13519			{13520				if(GET_PLAYER(eLoopMinor).GetMinorCivAI()->CanMajorBuyout(eID))13521				{13522					GC.getGame().DoMinorBuyout(eID, eLoopMinor);13523					iGoldLeft -= iBuyoutCost;13524					break; // Don't buyout more than once in a single turn13525				}13526				else13527				{13528					CvAssertMsg(false, "Chose a minor to buyout that cannot actually be bought! Please send Anton your save file and version.");13529				}13530			}13531			else13532			{13533				if(!GetPlayer()->GetEconomicAI()->IsSavingForThisPurchase(PURCHASE_TYPE_MINOR_CIV_GIFT))13534				{13535					LogMinorCivBuyout(eLoopMinor, iBuyoutCost, /*bSaving*/ true);1353613537					int iPriority = GC.getAI_GOLD_PRIORITY_BUYOUT_CITY_STATE();13538					GetPlayer()->GetEconomicAI()->StartSaveForPurchase(PURCHASE_TYPE_MINOR_CIV_GIFT, iBuyoutCost, iPriority);13539				}13540			}13541		}13542	}1354313544	// Do we want to give someone Gold enough to actually do it?13545	if(veMinorsToGiveGold.size() > 0)13546	{13547		veMinorsToGiveGold.SortItems(); // Sort from highest desirability to lowest13548		for(int i = 0; i < veMinorsToGiveGold.size(); i++)13549		{13550			int iGoldLeft = GetPlayer()->GetTreasury()->GetGold();13551			MinorGoldGiftInfo sGift = veMinorsToGiveGold.GetElement(i);13552			sGift.iGoldAmount = 0;1355313554			if(iGoldLeft >= iSmallGift && sGift.bQuickBoost)13555				sGift.iGoldAmount = iSmallGift;13556			else if(iGoldLeft >= iLargeGift)13557				sGift.iGoldAmount = iLargeGift;13558			else if(iGoldLeft >= iMediumGift)13559				sGift.iGoldAmount = iMediumGift;1356013561			int iOldFriendship = GET_PLAYER(sGift.eMinor).GetMinorCivAI()->GetEffectiveFriendshipWithMajor(eID);1356213563			// Able to give a gift?  Don't gift more than half of the gold we have in one turn13564			if(sGift.iGoldAmount > 0 && iGoldLeft >= (iGoldReserve / 2))13565			{13566				GET_PLAYER(sGift.eMinor).GetMinorCivAI()->DoGoldGiftFromMajor(GetPlayer()->GetID(), sGift.iGoldAmount); //antonjs: todo: go through CvGame instead?1356713568				LogMinorCivGiftGold(sGift.eMinor, iOldFriendship, sGift.iGoldAmount, /*bSaving*/ false, sGift.bQuickBoost, sGift.eMajorRival);1356913570				if(GetPlayer()->GetEconomicAI()->IsSavingForThisPurchase(PURCHASE_TYPE_MINOR_CIV_GIFT))13571					GetPlayer()->GetEconomicAI()->CancelSaveForPurchase(PURCHASE_TYPE_MINOR_CIV_GIFT);13572			}13573			// Can't afford gift yet, so start saving13574			else13575			{13576				if(!GetPlayer()->GetEconomicAI()->IsSavingForThisPurchase(PURCHASE_TYPE_MINOR_CIV_GIFT))13577				{13578					int iAmountToSaveFor = iMediumGift;1357913580					if(sGift.bQuickBoost)13581						iAmountToSaveFor = iSmallGift;1358213583					LogMinorCivGiftGold(sGift.eMinor, iOldFriendship, iAmountToSaveFor, /*bSaving*/ true, sGift.bQuickBoost, sGift.eMajorRival);1358413585					int iPriority = GC.getAI_GOLD_PRIORITY_DIPLOMACY_BASE();13586					iPriority += GC.getAI_GOLD_PRIORITY_DIPLOMACY_PER_FLAVOR_POINT() * iDiplomacyFlavor;13587					GetPlayer()->GetEconomicAI()->StartSaveForPurchase(PURCHASE_TYPE_MINOR_CIV_GIFT, iAmountToSaveFor, iPriority);13588				}13589			}13590		}13591	}1359213593	// Do we want a unit enough to bully someone?13594	if(veMinorsToBullyUnit.size() > 0)13595	{13596		veMinorsToBullyUnit.SortItems();13597		PlayerTypes eLoopMinor = NO_PLAYER;13598		for(int i = 0; i < veMinorsToBullyUnit.size(); i++)13599		{13600			eLoopMinor = veMinorsToBullyUnit.GetElement(i);13601			CvAssertMsg(eLoopMinor != NO_PLAYER, "Trying to bully a unit from NO_PLAYER! Please send Anton your save file and version.");13602			if(GET_PLAYER(eLoopMinor).GetMinorCivAI()->CanMajorBullyUnit(eID))13603			{13604				GC.getGame().DoMinorBullyUnit(eID, eLoopMinor);13605				break; // Don't bully a unit more than once in a single turn13606			}13607			else13608			{13609				CvAssertMsg(false, "Chose a minor to bully unit from that cannot actually be bullied! Please send Anton your save file and version.");13610			}13611		}13612	}1361313614	// Do we want gold enough to bully someone?13615	if(veMinorsToBullyGold.size() > 0)13616	{13617		veMinorsToBullyGold.SortItems();13618		PlayerTypes eLoopMinor = NO_PLAYER;13619		for(int i = 0; i < veMinorsToBullyGold.size(); i++)13620		{13621			eLoopMinor = veMinorsToBullyGold.GetElement(i);13622			CvAssertMsg(eLoopMinor != NO_PLAYER, "Trying to bully gold from NO_PLAYER! Please send Anton your save file and version.");13623			if(GET_PLAYER(eLoopMinor).GetMinorCivAI()->CanMajorBullyGold(eID))13624			{13625				GC.getGame().DoMinorBullyGold(eID, eLoopMinor);13626			}13627			else13628			{13629				CvAssertMsg(false, "Chose a minor to bully gold from that cannot actually be bullied! Please send Anton your save file and version.");13630			}13631		}13632	}13633}

Calls

Called by