# Finances
iGoldRate = pPlayer.calculateGoldRate()
iGold = pPlayer.getGold()
goldPerc = pPlayer.getCommercePercent( CommerceTypes.COMMERCE_GOLD )
sciPerc = pPlayer.getCommercePercent( CommerceTypes.COMMERCE_RESEARCH )
# This is calculation AI does to figure out if it's in financial trouble
iNetCommerce = 1 + pPlayer.getCommerceRate(CommerceTypes.COMMERCE_GOLD) + pPlayer.getCommerceRate(CommerceTypes.COMMERCE_RESEARCH) + max([0, pPlayer.getGoldPerTurn()])
iNetExpenses = pPlayer.calculateInflatedCosts() + max([0, -pPlayer.getGoldPerTurn()])
iFundedPercent = (100 * (iNetCommerce - iNetExpenses)) / max([1, iNetCommerce])
iThresholdPercent = 75
iNumWars = pTeam.getAtWarCount(True)
if( iNumWars > 0 ) :
iThresholdPercent -= 10 + 2*min([iNumWars, 5])
if( pPlayer.isCurrentResearchRepeat() ) :
# Have all techs, research no longer important
iThresholdPercent *= 2
iThresholdPercent /= 3
if( cultPerc > 70 ) :
# Going for cultural victory, research no longer important
iThresholdPercent *= 2
iThresholdPercent /= 3
if( pPlayer.hasTrait(gc.getInfoTypeForString("TRAIT_ORGANIZED")) ):
iThresholdPercent *= 10
iThresholdPercent /= 11
if( self.LOG_DEBUG and (bVerbose or iGameTurn%25 == 0) ) : CvUtil.pyPrint(" Revolt - The %s financial status: commerce %d, expenses %d, funded %d, thresh = %d, num wars %d, gold %d, rate %d, gold perc %.2f"%(pPlayer.getCivilizationDescription(0), iNetCommerce, iNetExpenses, iFundedPercent, iThresholdPercent, iNumWars, iGold, iGoldRate,goldPerc))
taxesIdx = 0
finIdx = 0
if( iNetCommerce > 20 and iFundedPercent > iThresholdPercent + 5 and not pPlayer.isMinorCiv() and not pPlayer.isAnarchy() ) :
# Great long-term financial situation
finIdx = min([((iFundedPercent - iThresholdPercent)/4 + cultPerc/5),4 + iEra])
if( bIsRevWatch ) :
posList.append( (finIdx, localText.getText("TXT_KEY_REV_WATCH_FINANCIAL_POS",())) )
if( self.LOG_DEBUG and (bVerbose or iGameTurn%25 == 0) ) : CvUtil.pyPrint(" Revolt - The %s is in a good long-term financial situation")
elif( iFundedPercent < iThresholdPercent ) :
iPercentShort = iThresholdPercent - iFundedPercent
finIdx = -min([20, 1+ iPercentShort/3])
if( iGoldRate > 2 + 5*iEra ) :
# Civ is making money
finIdx /=2
elif( iGold > 100 + 100*iEra ) :
# Civ has plenty of reserves
finIdx /=2
elif( goldPerc > 50 and iGold < (35 + 10*iEra) and iGoldRate < 0 ) :
# Civ in danger of running out of gold soon
finIdx *=2
if( self.LOG_DEBUG and (bVerbose or iGameTurn%25 == 0) ) : CvUtil.pyPrint(" Revolt - The %s is in serious financial trouble")
if( bIsRevWatch ) :
if(finIdx < 0):
negList.append( (finIdx, localText.getText("TXT_KEY_REV_WATCH_FINANCIAL_NEG",())) )
revIdxHistEvents += finIdx
civRevIdx -= finIdx
civStabilityIdx += finIdx