Bazaar developer reference

CvDealAI::GetDefensivePactValue(bool, PlayerTypes, bool)

Defined in
CvDealAI.cpp, line 1746
Class
CvDealAI
Hook name
CivHooks::CvDealAI_GetDefensivePactValue

Hooks

static bool BeforeCvDealAI_GetDefensivePactValue(CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, int& result);static void AfterCvDealAI_GetDefensivePactValue(CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, int& result);static int ReplaceCvDealAI_GetDefensivePactValue(int (*original)(CvDealAI*, bool, PlayerTypes, bool), CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue);CivRegisterBefore<CivHooks::CvDealAI_GetDefensivePactValue>(host, &BeforeCvDealAI_GetDefensivePactValue);CivRegisterAfter<CivHooks::CvDealAI_GetDefensivePactValue>(host, &AfterCvDealAI_GetDefensivePactValue);CivRegisterReplace<CivHooks::CvDealAI_GetDefensivePactValue>(host, &ReplaceCvDealAI_GetDefensivePactValue);

Code

1745/// How much is a Defensive Pact worth?1746int CvDealAI::GetDefensivePactValue(bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue)1747{1748	CvAssertMsg(GetPlayer()->GetID() != eOtherPlayer, "DEAL_AI: Trying to check value of a Defensive Pact with oneself.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");17491750	int iItemValue;17511752	// What is a Defensive Pact with eOtherPlayer worth to US?1753	if(!bFromMe)1754	{1755		iItemValue = 100;1756		//	// How strong are they compared to us?1757		//	switch (GetPlayer()->GetDiplomacyAI()->GetPlayerMilitaryStrengthComparedToUs(eOtherPlayer))1758		//	{1759		//	case STRENGTH_PATHETIC:1760		//		iItemValue = 10;1761		//		break;1762		//	case STRENGTH_WEAK:1763		//		iItemValue = 40;1764		//		break;1765		//	case STRENGTH_POOR:1766		//		iItemValue = 70;1767		//		break;1768		//	case STRENGTH_AVERAGE:1769		//		iItemValue = 100;1770		//		break;1771		//	case STRENGTH_STRONG:1772		//		iItemValue = 130;1773		//		break;1774		//	case STRENGTH_POWERFUL:1775		//		iItemValue = 150;1776		//		break;1777		//	case STRENGTH_IMMENSE:1778		//		iItemValue = 200;1779		//		break;1780		//	default:1781		//		CvAssertMsg(false, "DEAL_AI: AI player has no valid MilitaryStrengthComparedToUs for Defensive Pact valuation.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.")1782		//		iItemValue = 100;1783		//		break;1784		//	}1785	}1786	// How much do we value giving away a Defensive Pact?1787	else1788	{1789		// Opinion also matters1790		switch(GetPlayer()->GetDiplomacyAI()->GetMajorCivOpinion(eOtherPlayer))1791		{1792		case MAJOR_CIV_OPINION_ALLY:1793			iItemValue = 100;1794			break;1795		case MAJOR_CIV_OPINION_FRIEND:1796			iItemValue = 100;1797			break;1798		case MAJOR_CIV_OPINION_FAVORABLE:1799			iItemValue = 100;1800			break;1801		case MAJOR_CIV_OPINION_NEUTRAL:1802			iItemValue = 100000;1803			break;1804		case MAJOR_CIV_OPINION_COMPETITOR:1805			iItemValue = 100000;1806			break;1807		case MAJOR_CIV_OPINION_ENEMY:1808			iItemValue = 100000;1809			break;1810		case MAJOR_CIV_OPINION_UNFORGIVABLE:1811			iItemValue = 100000;1812			break;1813		default:1814			CvAssertMsg(false, "DEAL_AI: AI player has no valid Opinion for Defensive Pact valuation.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.")1815			iItemValue = 100000;1816			break;1817		}18181819		// Approach is important1820		//switch (GetPlayer()->GetDiplomacyAI()->GetMajorCivApproach(eOtherPlayer, /*bHideTrueFeelings*/ true))1821		//{1822		//case MAJOR_CIV_APPROACH_HOSTILE:1823		//	iItemValue *= 200;	// Value should already be increased above by Opinion as well1824		//	break;1825		//case MAJOR_CIV_APPROACH_GUARDED:1826		//	iItemValue *= 100;	// If we're guarded against someone, getting a Defensive Pact is kinda nice1827		//	break;1828		//case MAJOR_CIV_APPROACH_AFRAID:1829		//	iItemValue *= 80;		// If we're afraid of eOtherPlayer, we couldn't be happier to sign a Defensive Pact with them!1830		//	break;1831		//case MAJOR_CIV_APPROACH_FRIENDLY:1832		//	iItemValue *= 100;1833		//	break;1834		//case MAJOR_CIV_APPROACH_NEUTRAL:1835		//	iItemValue *= 100;1836		//	break;1837		//default:1838		//	CvAssertMsg(false, "DEAL_AI: AI player has no valid Approach for Defensive Pact valuation.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.")1839		//	iItemValue *= 100;1840		//	break;1841		//}1842		//iItemValue /= 100;1843	}1844	// Are we trying to find the middle point between what we think this item is worth and what another player thinks it's worth?1845	if(bUseEvenValue)1846	{1847		iItemValue += GET_PLAYER(eOtherPlayer).GetDealAI()->GetDefensivePactValue(!bFromMe, GetPlayer()->GetID(), /*bUseEvenValue*/ false);18481849		iItemValue /= 2;1850	}18511852	return iItemValue;1853}

Calls

Called by