diff --git a/CvGameCoreDLL_Expansion2/CvBeliefClasses.cpp b/CvGameCoreDLL_Expansion2/CvBeliefClasses.cpp index 80bba43b4e..7a37d4c986 100644 --- a/CvGameCoreDLL_Expansion2/CvBeliefClasses.cpp +++ b/CvGameCoreDLL_Expansion2/CvBeliefClasses.cpp @@ -4597,11 +4597,11 @@ int CvReligionBeliefs::GetCSYieldBonus(PlayerTypes ePlayer, const CvCity* pCity, } /// Get votes per improvement (fractional) from belief -std::pair CvReligionBeliefs::GetVoteFromOwnedImprovement(ImprovementTypes eImprovement, PlayerTypes ePlayer, const CvCity* pCity, bool bHolyCityOnly) const +fraction CvReligionBeliefs::GetVoteFromOwnedImprovement(ImprovementTypes eImprovement, PlayerTypes ePlayer, const CvCity* pCity, bool bHolyCityOnly) const { CvBeliefXMLEntries* pBeliefs = GC.GetGameBeliefs(); - std::pair fVotes = std::make_pair(0, 1); + fraction fVotes = 0; // if two beliefs give fractional votes for the same improvement, then the fractional vote gets larger (1/2 + 1/3 = 5/6) for (BeliefList::const_iterator it = m_ReligionBeliefs.begin(); it != m_ReligionBeliefs.end(); ++it) @@ -4610,7 +4610,7 @@ std::pair CvReligionBeliefs::GetVoteFromOwnedImprovement(ImprovementTy int iValue = pBeliefs->GetEntry(*it)->GetImprovementVoteChange(eImprovement); if (iValue != 0 && IsBeliefValid((BeliefTypes)*it, GetReligion(), ePlayer, pCity, bHolyCityOnly)) { - AddFractionToReference(fVotes, std::make_pair(1, iValue)); + fVotes += fraction(1, iValue); } } diff --git a/CvGameCoreDLL_Expansion2/CvBeliefClasses.h b/CvGameCoreDLL_Expansion2/CvBeliefClasses.h index 2b6e8c96df..015c35e5a9 100644 --- a/CvGameCoreDLL_Expansion2/CvBeliefClasses.h +++ b/CvGameCoreDLL_Expansion2/CvBeliefClasses.h @@ -588,7 +588,7 @@ class CvReligionBeliefs CivilizationTypes GetUniqueCiv(PlayerTypes ePlayer = NO_PLAYER, bool bHolyCityOnly = false) const; int GetIgnorePolicyRequirementsAmount(EraTypes eEra, PlayerTypes ePlayer = NO_PLAYER, const CvCity* pCity = NULL, bool bHolyCityOnly = false) const; int GetCSYieldBonus(PlayerTypes ePlayer = NO_PLAYER, const CvCity* pCity = NULL, bool bHolyCityOnly = false) const; - std::pair GetVoteFromOwnedImprovement(ImprovementTypes eImprovement, PlayerTypes ePlayer = NO_PLAYER, const CvCity* pCity = NULL, bool bHolyCityOnly = false) const; + fraction GetVoteFromOwnedImprovement(ImprovementTypes eImprovement, PlayerTypes ePlayer = NO_PLAYER, const CvCity* pCity = NULL, bool bHolyCityOnly = false) const; const BeliefList& GetBeliefList() const { return m_ReligionBeliefs; } #endif diff --git a/CvGameCoreDLL_Expansion2/CvGameCoreUtils.cpp b/CvGameCoreDLL_Expansion2/CvGameCoreUtils.cpp index 95991a603c..eee88f6ae8 100644 --- a/CvGameCoreDLL_Expansion2/CvGameCoreUtils.cpp +++ b/CvGameCoreDLL_Expansion2/CvGameCoreUtils.cpp @@ -1502,55 +1502,6 @@ int MapToPercent(int iValue, int iZeroAt, int iHundredAt) return 50; } -//------------------------------------------------------------------------------ -// add a fraction to a referenced fraction without losing information; the referenced fraction is assumed to have the larger dividend & divisor -void AddFractionToReference(pair& A, const pair& B) -{ - // protect from integer overflow (safe, simple max that will probably never be hit) - if (A.first >= (INT_MAX / B.first / B.second) - A.second) - { - // Divisor or Dividend is too large! Start fresh - if (A.first > A.second) - { - A.first /= A.second; - A.second = 1; - } - else - { - A.second /= A.first; - A.first = 1; - } - } - - // N / D = nA / dA + nB / dB - // = (nA*dB + nB*dA) / (dB*dA) - A.first *= B.second; - A.first += B.first * A.second; - - A.second *= B.second; -} - -// add two fractions together without losing information; A is assumed to have the larger dividend & divisor -pair AddFractions(pair& A, pair& B) -{ - AddFractionToReference(A, B); - return A; -} - -// add a list of fractions together (separated numerators and denominators) -pair AddFractions(vector& aDividendList, vector& aDivisorList) -{ - CvAssert(aDividendList.size() == aDivisorList.size()); - - pair result = make_pair(0, 1); - - for (size_t jJ = 0, jlen = aDividendList.size(); jJ < jlen; ++jJ) - { - AddFractionToReference(result, make_pair(aDividendList[jJ], aDivisorList[jJ])); - } - return result; -} - //------------------------------------------------------------------------------ fraction& fraction::operator+=(const fraction &rhs) { diff --git a/CvGameCoreDLL_Expansion2/CvGameCoreUtils.h b/CvGameCoreDLL_Expansion2/CvGameCoreUtils.h index b2c40018c3..86a0c13dbd 100644 --- a/CvGameCoreDLL_Expansion2/CvGameCoreUtils.h +++ b/CvGameCoreDLL_Expansion2/CvGameCoreUtils.h @@ -461,11 +461,6 @@ T PseudoRandomChoiceByWeight(vector>& candidates, const T& de return defaultChoice; } -//------------------------------------------------------------------------------ -void AddFractionToReference(pair& A, const pair& B); -pair AddFractions(pair& A, pair& B); -pair AddFractions(vector& dividendList, vector& divisorList); - //------------------------------------------------------------------------------ class fraction { diff --git a/CvGameCoreDLL_Expansion2/CvPlayer.cpp b/CvGameCoreDLL_Expansion2/CvPlayer.cpp index 3526db0129..777af528be 100644 --- a/CvGameCoreDLL_Expansion2/CvPlayer.cpp +++ b/CvGameCoreDLL_Expansion2/CvPlayer.cpp @@ -23058,7 +23058,7 @@ int CvPlayer::CalculateReligionVotesFromImprovements(const CvReligion *pReligion { int iNumImprovementInfos = GC.getNumImprovementInfos(); - std::pair fTotalVotes = std::make_pair(0, 1); + fraction fTotalVotes = 0; for (int jJ = 0; jJ < iNumImprovementInfos; jJ++) { @@ -23066,14 +23066,11 @@ int CvPlayer::CalculateReligionVotesFromImprovements(const CvReligion *pReligion if (iNumImprovements > 0) { // number of votes per improvement (a fraction less than one) - std::pair fPotentialVotes = pReligion->m_Beliefs.GetVoteFromOwnedImprovement((ImprovementTypes)jJ, m_eID); // more likely to be zero - if (fPotentialVotes.first > 0) - { - AddFractionToReference(fTotalVotes, std::make_pair(iNumImprovements * fPotentialVotes.first, fPotentialVotes.second)); - } + fraction fPotentialVotes = pReligion->m_Beliefs.GetVoteFromOwnedImprovement((ImprovementTypes)jJ, m_eID); // more likely to be zero + fTotalVotes += fPotentialVotes * iNumImprovements; } } - return fTotalVotes.first / fTotalVotes.second; + return fTotalVotes.Truncate(); } /// Extra influence from GPs diff --git a/CvGameCoreDLL_Expansion2/CvReligionClasses.cpp b/CvGameCoreDLL_Expansion2/CvReligionClasses.cpp index 94dc90d570..8fa55fff84 100644 --- a/CvGameCoreDLL_Expansion2/CvReligionClasses.cpp +++ b/CvGameCoreDLL_Expansion2/CvReligionClasses.cpp @@ -10226,17 +10226,17 @@ int CvReligionAI::ScoreBeliefForPlayer(CvBeliefEntry* pEntry, bool bReturnConque } int iNumImprovementInfos = GC.getNumImprovementInfos(); - pair fVoteRatio = make_pair(0, 1); + fraction fVoteRatio = 0; for (int jJ = 0; jJ < iNumImprovementInfos; jJ++) { - int potentialVotes = pEntry->GetImprovementVoteChange((ImprovementTypes)jJ); - if (potentialVotes > 0) + int iPotentialVotes = pEntry->GetImprovementVoteChange((ImprovementTypes)jJ); + if (iPotentialVotes > 0) { - int numImprovements = max(m_pPlayer->getImprovementCount((ImprovementTypes)jJ), 1); - AddFractionToReference(fVoteRatio, make_pair(numImprovements, potentialVotes)); + int iNumImprovements = max(m_pPlayer->getImprovementCount((ImprovementTypes)jJ), 1); + fVoteRatio += fraction(iNumImprovements, iPotentialVotes); } } - iDiploTemp += 80 * fVoteRatio.first / fVoteRatio.second; + iDiploTemp += (fVoteRatio * 80).Truncate(); if (pEntry->GetCityStateInfluenceModifier() > 0) {