Bazaar developer reference

CvTeam::GetTeamVotingForInDiplo() const

Defined in
CvTeam.cpp, line 1952
Class
CvTeam
Hook name
CivHooks::CvTeam_GetTeamVotingForInDiplo

Hooks

static bool BeforeCvTeam_GetTeamVotingForInDiplo(const CvTeam* self, TeamTypes& result);static void AfterCvTeam_GetTeamVotingForInDiplo(const CvTeam* self, TeamTypes& result);static TeamTypes ReplaceCvTeam_GetTeamVotingForInDiplo(TeamTypes (*original)(const CvTeam*), const CvTeam* self);CivRegisterBefore<CivHooks::CvTeam_GetTeamVotingForInDiplo>(host, &BeforeCvTeam_GetTeamVotingForInDiplo);CivRegisterAfter<CivHooks::CvTeam_GetTeamVotingForInDiplo>(host, &AfterCvTeam_GetTeamVotingForInDiplo);CivRegisterReplace<CivHooks::CvTeam_GetTeamVotingForInDiplo>(host, &ReplaceCvTeam_GetTeamVotingForInDiplo);

Code

1951/// Who will this team vote for!1952TeamTypes CvTeam::GetTeamVotingForInDiplo() const1953{1954	TeamTypes eVoteTeam = NO_TEAM;1955	1956	if(isBarbarian())1957	{1958		// Barbarians do not vote!1959		CvAssertMsg(false, "Barbarian team should not be voting for diplo victory. Please send Anton your save file and verison.");1960	}1961	else if(isMinorCiv())1962	{1963		// Minor civs vote for their favored nation (liberator or ally)1964		if(GetLiberatedByTeam() != NO_TEAM && GET_TEAM(GetLiberatedByTeam()).isAlive())1965		{1966			eVoteTeam = GetLiberatedByTeam();1967		}1968		else1969		{1970			PlayerTypes eAlly = GET_PLAYER(getLeaderID()).GetMinorCivAI()->GetAlly();1971			if(eAlly != NO_PLAYER && GET_PLAYER(eAlly).isAlive())1972				eVoteTeam = GET_PLAYER(eAlly).getTeam();1973		}1974	}1975	else1976	{1977		// Major civs vote for other majors based on opinion weight (our team leader towards their team leader)1978		CvWeightedVector<TeamTypes, MAX_CIV_TEAMS, true> veVoteCandidates;1979		for (int iTeamLoop = 0; iTeamLoop < MAX_CIV_TEAMS; iTeamLoop++)1980		{1981			TeamTypes eTeamLoop = (TeamTypes) iTeamLoop;1982			if (GetID() != eTeamLoop && GET_TEAM(eTeamLoop).isAlive() && !GET_TEAM(eTeamLoop).isMinorCiv() && !GET_TEAM(eTeamLoop).isBarbarian() && isHasMet(eTeamLoop))1983			{1984				PlayerTypes eLeaderLoop = (PlayerTypes) GET_TEAM(eTeamLoop).getLeaderID();1985				CvAssertMsg(getLeaderID() != NO_PLAYER, "Our team leader ID should not be NO_PLAYER. Please send Anton your save file and version.");1986				CvAssertMsg(eLeaderLoop != NO_PLAYER, "Other team leader ID should not be NO_PLAYER. Please send Anton your save file and version.");1987				if (getLeaderID() != NO_PLAYER && eLeaderLoop != NO_PLAYER)1988				{1989					int kiBase = 10000;1990					1991					// What is our leader's opinion of the other team's leader? Remember, bad opinion is positive, good opinion is negative.1992					int iOpinion = GET_PLAYER(getLeaderID()).GetDiplomacyAI()->GetMajorCivOpinionWeight(eLeaderLoop);1993					if (isAtWar(eTeamLoop))1994						iOpinion = kiBase; // Don't vote for someone we are at war with, if we can help it19951996					// Weight cannot be negative. This calculation makes good opinions > 10000 and bad opinions < 10000.1997					int iWeight = kiBase - iOpinion;1998					if (iWeight < 0)1999						iWeight = 0;20002001					veVoteCandidates.push_back(eTeamLoop, iWeight);2002				}2003			}2004		}20052006		if (veVoteCandidates.size() > 0)2007		{2008			// Our most favored other team ends up at the top after sorting2009			veVoteCandidates.SortItems();2010			int iTopWeight = veVoteCandidates.GetWeight(0);20112012			// If there is a tie at the top, choose randomly from those that tied2013			int iNumAtTop = 0;2014			for (int iIndex = 0; iIndex < veVoteCandidates.size(); iIndex++)2015			{2016				int iWeight = veVoteCandidates.GetWeight(iIndex);2017				CvAssertMsg(iWeight <= iTopWeight, "Vote opinion weight should not be higher than the top team's weight! Please send Anton your save file and version.");2018				if (iWeight >= iTopWeight)2019				{2020					iNumAtTop++;2021				}2022				else2023				{2024					break;2025				}2026			}2027			CvAssertMsg(iNumAtTop > 0, "Should have at least one vote candidate at the top of the list for consideration. Please send Anton your save file and version.");2028			CvAssertMsg(iNumAtTop <= veVoteCandidates.size(), "Should not have more top vote candidates than there are total candidates. Please send Anton your save file and version.");2029			if (iNumAtTop > 0 && iNumAtTop <= veVoteCandidates.size())2030			{2031				RandomNumberDelegate randFn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum);2032				eVoteTeam = veVoteCandidates.ChooseFromTopChoices(iNumAtTop, &randFn, "Tie for most favored other team to vote for. Rolling to choose.");2033			}2034		}2035	}20362037	// If all else fails, vote for ourselves2038	if (eVoteTeam == NO_TEAM)2039		eVoteTeam = GetID();20402041	return eVoteTeam;2042}

Calls

Called by