Bazaar developer reference

CvDealAI::GetVoteCommitmentValue(bool, PlayerTypes, int, int, int, bool, bool)

Defined in
CvDealAI.cpp, line 2261
Class
CvDealAI
Hook name
CivHooks::CvDealAI_GetVoteCommitmentValue

Hooks

static bool BeforeCvDealAI_GetVoteCommitmentValue(CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, int iProposalID, int iVoteChoice, int iNumVotes, bool bRepeal, bool bUseEvenValue, int& result);static void AfterCvDealAI_GetVoteCommitmentValue(CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, int iProposalID, int iVoteChoice, int iNumVotes, bool bRepeal, bool bUseEvenValue, int& result);static int ReplaceCvDealAI_GetVoteCommitmentValue(int (*original)(CvDealAI*, bool, PlayerTypes, int, int, int, bool, bool), CvDealAI* self, bool bFromMe, PlayerTypes eOtherPlayer, int iProposalID, int iVoteChoice, int iNumVotes, bool bRepeal, bool bUseEvenValue);CivRegisterBefore<CivHooks::CvDealAI_GetVoteCommitmentValue>(host, &BeforeCvDealAI_GetVoteCommitmentValue);CivRegisterAfter<CivHooks::CvDealAI_GetVoteCommitmentValue>(host, &AfterCvDealAI_GetVoteCommitmentValue);CivRegisterReplace<CivHooks::CvDealAI_GetVoteCommitmentValue>(host, &ReplaceCvDealAI_GetVoteCommitmentValue);

Code

2260/// What is the value of trading a vote commitment?2261int CvDealAI::GetVoteCommitmentValue(bool bFromMe, PlayerTypes eOtherPlayer, int iProposalID, int iVoteChoice, int iNumVotes, bool bRepeal, bool bUseEvenValue)2262{2263	int iValue = 0;22642265	// Giving our votes to them - Higher value for voting on things we dislike2266	if (bFromMe)2267	{2268		// Adjust based on LeagueAI2269		CvLeagueAI::DesireLevels eDesire = GetPlayer()->GetLeagueAI()->EvaluateVoteForTrade(iProposalID, iVoteChoice, iNumVotes, bRepeal);2270		switch(eDesire)2271		{2272		case CvLeagueAI::DESIRE_NEVER:2273		case CvLeagueAI::DESIRE_STRONG_DISLIKE:2274			iValue += 100000;2275			break;2276		case CvLeagueAI::DESIRE_DISLIKE:2277			iValue += 300;2278			break;2279		case CvLeagueAI::DESIRE_WEAK_DISLIKE:2280			iValue += 200;2281			break;2282		case CvLeagueAI::DESIRE_NEUTRAL:2283		case CvLeagueAI::DESIRE_WEAK_LIKE:2284		case CvLeagueAI::DESIRE_LIKE:2285			iValue += 150;2286			break;2287		case CvLeagueAI::DESIRE_STRONG_LIKE:2288		case CvLeagueAI::DESIRE_ALWAYS:2289			iValue += 50;2290			break;2291		default:2292			iValue += 100000;2293			break;2294		}22952296		// Adjust based on relationship2297		CvAssert(eOtherPlayer != NO_PLAYER);2298		if (eOtherPlayer != NO_PLAYER)2299		{2300			CvLeagueAI::AlignmentLevels eAlignment = GetPlayer()->GetLeagueAI()->EvaluateAlignment(eOtherPlayer);2301			switch (eAlignment)2302			{2303			case CvLeagueAI::ALIGNMENT_LIBERATOR:2304			case CvLeagueAI::ALIGNMENT_LEADER:2305				iValue += -50;2306				break;2307			case CvLeagueAI::ALIGNMENT_SELF:2308				CvAssertMsg(false, "ALIGNMENT_SELF found when evaluating a trade deal for delegates. Please send Anton your save file and version.");2309				break;2310			case CvLeagueAI::ALIGNMENT_ALLY:2311				iValue += -35;2312				break;2313			case CvLeagueAI::ALIGNMENT_CONFIDANT:2314			case CvLeagueAI::ALIGNMENT_FRIEND:2315				iValue += -25;2316				break;2317			case CvLeagueAI::ALIGNMENT_NEUTRAL:2318				break;2319			case CvLeagueAI::ALIGNMENT_RIVAL:2320				iValue += 25;2321				break;2322			case CvLeagueAI::ALIGNMENT_HATRED:2323				iValue += 50;2324				break;2325			case CvLeagueAI::ALIGNMENT_ENEMY:2326			case CvLeagueAI::ALIGNMENT_WAR:2327				iValue += 100000;2328				break;2329			default:2330				break;2331			}23322333			MajorCivApproachTypes eOtherPlayerApproach = GetPlayer()->GetDiplomacyAI()->GetMajorCivApproach(eOtherPlayer, /*bHideTrueFeelings*/ false);2334			if (eOtherPlayerApproach == MAJOR_CIV_APPROACH_HOSTILE || eOtherPlayerApproach == MAJOR_CIV_APPROACH_WAR)2335			{2336				iValue += 100000;2337			}2338		}2339	}2340	// Giving their votes to us - Higher value for voting on things we like2341	else2342	{2343		// Adjust based on LeagueAI2344		CvLeagueAI::DesireLevels eDesire = GetPlayer()->GetLeagueAI()->EvaluateVoteForTrade(iProposalID, iVoteChoice, iNumVotes, bRepeal);2345		switch(eDesire)2346		{2347		case CvLeagueAI::DESIRE_NEVER:2348		case CvLeagueAI::DESIRE_STRONG_DISLIKE:2349		case CvLeagueAI::DESIRE_WEAK_DISLIKE:2350		case CvLeagueAI::DESIRE_NEUTRAL:2351			iValue += -100000;2352			break;2353		case CvLeagueAI::DESIRE_WEAK_LIKE:2354			iValue += 50;2355			break;2356		case CvLeagueAI::DESIRE_LIKE:2357			iValue += 100;2358			break;2359		case CvLeagueAI::DESIRE_STRONG_LIKE:2360			iValue += 150;2361			break;2362		case CvLeagueAI::DESIRE_ALWAYS:2363			iValue += 200;2364			break;2365		default:2366			iValue += -100000;2367			break;2368		}23692370		// Adjust based on their vote total - Having lots of votes left means they could counter these ones and exploit us2371		if (GC.getGame().GetGameLeagues()->GetNumActiveLeagues() > 0)2372		{2373			CvLeague* pLeague = GC.getGame().GetGameLeagues()->GetActiveLeague();2374			if (pLeague)2375			{2376				float fVotesRatio = (float)iNumVotes / (float)pLeague->CalculateStartingVotesForMember(eOtherPlayer);2377				if (fVotesRatio > 0.5f)2378				{2379					// More than half their votes...they probably aren't going to screw us2380				}2381				else if (fVotesRatio > 0.25f)2382				{2383					// They have a lot of remaining votes2384					iValue += -20;2385				}2386				else2387				{2388					// They have a hoard of votes2389					iValue += -40;2390				}2391			}2392		}2393	}23942395	iValue = MAX(iValue, 0);23962397	// Adjust based on how many votes2398	iValue *= iNumVotes;23992400	// Are we trying to find the middle point between what we think this item is worth and what another player thinks it's worth?2401	if (bUseEvenValue)2402	{2403		iValue += GET_PLAYER(eOtherPlayer).GetDealAI()->GetVoteCommitmentValue(!bFromMe, GetPlayer()->GetID(), iProposalID, iVoteChoice, iNumVotes, bRepeal, /*bUseEvenValue*/ false);24042405		iValue /= 2;2406	}24072408	return iValue;2409}

Calls

Called by