Bazaar developer reference

CvDealAI::GetOpenBordersValue(bool, PlayerTypes, bool)

Defined in
CvDealAI.cpp, line 1571
Class
CvDealAI
Hook name
CivHooks::CvDealAI_GetOpenBordersValue

Hooks

static bool BeforeCvDealAI_GetOpenBordersValue(CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, int& result);static void AfterCvDealAI_GetOpenBordersValue(CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, int& result);static int ReplaceCvDealAI_GetOpenBordersValue(int (*original)(CvDealAI*, bool, PlayerTypes, bool), CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue);CivRegisterBefore<CivHooks::CvDealAI_GetOpenBordersValue>(host, &BeforeCvDealAI_GetOpenBordersValue);CivRegisterAfter<CivHooks::CvDealAI_GetOpenBordersValue>(host, &AfterCvDealAI_GetOpenBordersValue);CivRegisterReplace<CivHooks::CvDealAI_GetOpenBordersValue>(host, &ReplaceCvDealAI_GetOpenBordersValue);

Code

1570/// How much in V-POINTS (aka value) is Open Borders worth?  You gotta admit that V-POINTS sound pretty cool though1571int CvDealAI::GetOpenBordersValue(bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue)1572{1573	CvAssertMsg(GetPlayer()->GetID() != eOtherPlayer, "DEAL_AI: Trying to check value of Open Borders with oneself.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");15741575	MajorCivApproachTypes eApproach = GetPlayer()->GetDiplomacyAI()->GetMajorCivApproach(eOtherPlayer, /*bHideTrueFeelings*/ true);15761577	// If we're friends, then OB is always equally valuable to both parties1578	if(eApproach == MAJOR_CIV_APPROACH_FRIENDLY)1579		return 50;15801581	int iItemValue = 0;15821583	// Me giving Open Borders to the other guy1584	if(bFromMe)1585	{1586		// Approach is important1587		switch(eApproach)1588		{1589		case MAJOR_CIV_APPROACH_HOSTILE:1590			iItemValue = 1000;1591			break;1592		case MAJOR_CIV_APPROACH_GUARDED:1593			iItemValue = 100;1594			break;1595		case MAJOR_CIV_APPROACH_AFRAID:1596			iItemValue = 20;1597			break;1598		case MAJOR_CIV_APPROACH_FRIENDLY:1599			iItemValue = 50;1600			break;1601		case MAJOR_CIV_APPROACH_NEUTRAL:1602			iItemValue = 75;1603			break;1604		default:1605			CvAssertMsg(false, "DEAL_AI: AI player has no valid Approach for Open Borders valuation.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.")1606			iItemValue = 100;1607			break;1608		}16091610		// Opinion also matters1611		switch(GetPlayer()->GetDiplomacyAI()->GetMajorCivOpinion(eOtherPlayer))1612		{1613		case MAJOR_CIV_OPINION_ALLY:1614			iItemValue = 0;1615			break;1616		case MAJOR_CIV_OPINION_FRIEND:1617			iItemValue *= 35;1618			iItemValue /= 100;1619			break;1620		case MAJOR_CIV_OPINION_FAVORABLE:1621			iItemValue *= 70;1622			iItemValue /= 100;1623			break;1624		case MAJOR_CIV_OPINION_NEUTRAL:1625			break;1626		case MAJOR_CIV_OPINION_COMPETITOR:1627			iItemValue *= 150;1628			iItemValue /= 100;1629			break;1630		case MAJOR_CIV_OPINION_ENEMY:1631			iItemValue *= 400;1632			iItemValue /= 100;1633			break;1634		case MAJOR_CIV_OPINION_UNFORGIVABLE:1635			iItemValue = 10000;1636			break;1637		default:1638			CvAssertMsg(false, "DEAL_AI: AI player has no valid Opinion for Open Borders valuation.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.")1639			break;1640		}16411642		// If they're at war with our enemies then we're more likely to give them OB1643		int iNumEnemiesAtWarWith = GetPlayer()->GetDiplomacyAI()->GetNumOurEnemiesPlayerAtWarWith(eOtherPlayer);1644		if(iNumEnemiesAtWarWith >= 2)1645		{1646			iItemValue *= 10;1647			iItemValue /= 100;1648		}1649		else if(iNumEnemiesAtWarWith == 1)1650		{1651			iItemValue *= 25;1652			iItemValue /= 100;1653		}16541655		// Do we think he's going for culture victory?1656		AIGrandStrategyTypes eCultureStrategy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CULTURE");1657		if (eCultureStrategy != NO_AIGRANDSTRATEGY && GetPlayer()->GetGrandStrategyAI()->GetGuessOtherPlayerActiveGrandStrategy(eOtherPlayer) == eCultureStrategy)1658		{1659			CvPlayer &kOtherPlayer = GET_PLAYER(eOtherPlayer);16601661			// If he has tourism and he's not influential on us yet, resist!1662			if (kOtherPlayer.GetCulture()->GetTourism() > 0 && kOtherPlayer.GetCulture()->GetInfluenceOn(GetPlayer()->GetID()) < INFLUENCE_LEVEL_INFLUENTIAL)1663			{1664				iItemValue *= 500;1665				iItemValue /= 100;1666			}1667		}1668	}1669	// Other guy giving me Open Borders1670	else1671	{1672		// Proximity is very important1673		switch(GetPlayer()->GetProximityToPlayer(eOtherPlayer))1674		{1675		case PLAYER_PROXIMITY_DISTANT:1676			iItemValue = 5;1677			break;1678		case PLAYER_PROXIMITY_FAR:1679			iItemValue = 10;1680			break;1681		case PLAYER_PROXIMITY_CLOSE:1682			iItemValue = 15;1683			break;1684		case PLAYER_PROXIMITY_NEIGHBORS:1685			iItemValue = 30;1686			break;1687		default:1688			CvAssertMsg(false, "DEAL_AI: AI player has no valid Proximity for Open Borders valuation.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.")1689			iItemValue = 0;1690			break;1691		}16921693		// Reduce value by half if the other guy only has a single City1694		if(GET_PLAYER(eOtherPlayer).getNumCities() == 1)1695		{1696			iItemValue *= 50;1697			iItemValue /= 100;1698		}16991700		// Boost value greatly if we are going for a culture win1701		// If going for culture win always want open borders against civs we need influence on1702		AIGrandStrategyTypes eCultureStrategy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CULTURE");1703		if (eCultureStrategy != NO_AIGRANDSTRATEGY && GetPlayer()->GetGrandStrategyAI()->GetActiveGrandStrategy() == eCultureStrategy && GetPlayer()->GetCulture()->GetTourism() > 0 )1704		{1705			// The civ we need influence on the most should ALWAYS be included1706			if (GetPlayer()->GetCulture()->GetCivLowestInfluence(false /*bCheckOpenBorders*/) == eOtherPlayer)1707			{1708				iItemValue *= 1000;1709				iItemValue /= 100;1710			}17111712			// If have influence over half the civs, want OB with the other half1713			else if (GetPlayer()->GetCulture()->GetNumCivsToBeInfluentialOn() <= GetPlayer()->GetCulture()->GetNumCivsInfluentialOn())1714			{1715				if (GetPlayer()->GetCulture()->GetInfluenceLevel(eOtherPlayer) < INFLUENCE_LEVEL_INFLUENTIAL)1716				{1717					iItemValue *= 500;1718					iItemValue /= 100;1719				}1720			}17211722			else if (GetPlayer()->GetProximityToPlayer(eOtherPlayer) == PLAYER_PROXIMITY_NEIGHBORS)1723			{1724				// If we're cramped then we want OB more with our neighbors1725				if(GetPlayer()->IsCramped())1726				{1727					iItemValue *= 300;1728					iItemValue /= 100;1729				}1730			}1731		}1732	}17331734	// Are we trying to find the middle point between what we think this item is worth and what another player thinks it's worth?1735	if(bUseEvenValue)1736	{1737		iItemValue += GET_PLAYER(eOtherPlayer).GetDealAI()->GetOpenBordersValue(!bFromMe, GetPlayer()->GetID(), /*bUseEvenValue*/ false);17381739		iItemValue /= 2;1740	}17411742	return iItemValue;1743}

Calls

Called by