/// Update diplo victory parameters, such as how many votes are needed to win
void CvGame::DoUpdateDiploVictory()
{
int iVotesForHost = 1;
int iVotesPerCiv = 1;
int iVotesPerCityState = 1;
for (int i = 0; i < GC.getNumLeagueSpecialSessionInfos(); i++)
{
LeagueSpecialSessionTypes e = (LeagueSpecialSessionTypes)i;
CvLeagueSpecialSessionEntry* pInfo = GC.getLeagueSpecialSessionInfo(e);
CvAssert(pInfo != NULL);
if (pInfo != NULL)
{
if (pInfo->IsUnitedNations())
{
iVotesForHost = pInfo->GetHostDelegates();
iVotesPerCiv = pInfo->GetCivDelegates();
iVotesPerCityState = pInfo->GetCityStateDelegates();
}
}
}
float fCivsToCount = 0.0f;
float fCityStatesToCount = 0.0f;
for (uint i = 0; i < MAX_CIV_PLAYERS; i++)
{
PlayerTypes e = (PlayerTypes)i;
CvPlayer* pPlayer = &GET_PLAYER(e);
if (pPlayer != NULL && pPlayer->isEverAlive())
{
// Minor civ
if (pPlayer->isMinorCiv())
{
// Bought out does not count (they are no longer in the pool of teams, cannot be liberated, etc.)
if (!pPlayer->GetMinorCivAI()->IsBoughtOut())
{
if (pPlayer->isAlive())
{
fCityStatesToCount += 1.0f;
}
else
{
fCityStatesToCount += 0.5f;
}
}
}
// Major civ
else
{
if (pPlayer->isAlive())
{
fCivsToCount += 1.0f;
}
else
{
fCivsToCount += 0.5f;
}
}
}
}
// Number of delegates needed to win increases the more civs and city-states there are in the game,
// but these two scale differently since civs' delegates are harder to secure. These functions
// are based on a logarithmic regression.
float fCivVotesPortion = (GC.getDIPLO_VICTORY_CIV_DELEGATES_COEFFICIENT() * (float)log(fCivsToCount)) + GC.getDIPLO_VICTORY_CIV_DELEGATES_CONSTANT();
if (fCivVotesPortion < 0.0f)
{
fCivVotesPortion = 0.0f;
}
float fCityStateVotesPortion = (GC.getDIPLO_VICTORY_CS_DELEGATES_COEFFICIENT() * (float)log(fCityStatesToCount)) + GC.getDIPLO_VICTORY_CS_DELEGATES_CONSTANT();
if (fCityStateVotesPortion < 0.0f)
{
fCityStateVotesPortion = 0.0f;
}
int iVotesToWin = (int)floor(fCivVotesPortion + fCityStateVotesPortion);
iVotesToWin = MAX(iVotesForHost + iVotesPerCiv + 1, iVotesToWin);
iVotesToWin = MIN(iVotesForHost + (iVotesPerCiv * (int)fCivsToCount) + (iVotesPerCityState * (int)fCityStatesToCount), iVotesToWin);
SetVotesNeededForDiploVictory(iVotesToWin);
GC.GetEngineUserInterface()->setDirty(LeagueScreen_DIRTY_BIT, true);
}