RFC's Great Depression Debacle

DorianGray

Chieftain
Joined
Apr 3, 2008
Messages
21
As I've illustrated in the Bug Report post -

http://forums.civfanatics.com/showpost.php?p=8688866&postcount=906

there are some serious issues in the current "Great Depression" mechanisms and modelling algorithms.

"Great Depression" as described in the wiki -

"Great Depression
It happens if a civilization has excessive production over commerce (which causes deflation), while it's running a free market economy. It's a big hit to a country's stability and can affect all the civs which have an open border agreement with this civilization. Switching away from free market is a solution to quit the depression, but it's dangerous! A period of anarchy is definitely the last step towards civil war. You'd better be careful then, and if your total rating is unstable or worse, it's better to improve stability by other means (such as building wonders) and wait until it's over."​

Yet there is no clear display in the UI of exactly what is being considered "commerce" for the purpose of this calculation. As it turns out, even though "production" is displayed and graphed in the "Info" screens, "commerce" is surpisingly absent.

At first glance, it is easy to assume that "GNP (Gold)" is what is being referred to, but it absolutely has nothing to do with the final calculations of when a "Great Depression" is triggered.

The point of this post is to illustrate that if a player has any hope to even a limited ability to avert a "Great Depression", then they need access to meaningful information as to the market conditions that prompt its occurence.

The only advise given being - "switching away from free market" is woefully inadequate.
 
i admit i never really cared how to avoid a Great Depression when i'm on free market, but i do realize that if i spam cottages, have lots of commerce and low production, i never once had a Great Depression.
 
This is probably why Great Depressions seem so random. I'm glad someone finally went through the code. Well done.
 
Well, random depressions and recessions happen in life too. And it's usually the Republicans' fault. (or is it the Democrats' who then take the credit for getting us out of recession) :D
What is seriously needed is a displayable Great Depression gauge that would allow you to adjust commerce. We know more about turn-to-turn stability since Rhye adopted the numeric +/- system, maybe he can put one more piece of code to let us know how much excess production and commerce is present each turn.
 
What is seriously needed is a displayable Great Depression gauge that would allow you to adjust commerce.

Agreed. What I'm thinking is a modfication to the "Info" screen that adds another historical graph similiar to GNP, Production, etc; but would correctly display the "Commerce" value that is used in the "Great Depression" calculations.
(I know how to do this, but it would require a change to the DLL and the save game format.)

I'm thinking this will also help in the final adjustment in the "Great Depression" algorithms to model the occurences more accurately.

Ultimately, there are going to be times when your economy gets so "out of wack" that there are going to be nothing you can do to avert a "Great Depression". ( as when it is inherited from one of you neighbors ) However, a player needs to have reasonable access to key indicators to allow various tweaks along the way and means to help recover from a "Great Depression" when it does occur.
 
Great Depressions should have very low effect on nations in State Property. The Soviet Union was about the only country in the world that had little problems with it.
 
Great Depressions should have very low effect on nations in State Property. The Soviet Union was about the only country in the world that had little problems with it.

You are correct sir. To the best of my knowledge, this is only applicable to "Free Market" economies.
 
Yeah, only Free Markets can get it, but State Properties can get the negative effects of someone else having it.
 
After some more research, it appears that some of the underlying function calls used in Stability.py script to calculate "iIndustry" and "iEconomy" have changed from Civ:Vanilla, Civ:Warlords as described here:

http://www.civfanatics.com/civ4/strategy/demographics.php

Some of these same functions are also used in the "Demographics" screen.

I don't know the history of modifications made to "Stability.py", but there may have been an attempt to compensate for the change in the underlying return values from these functions that just didn't get it right.

As pointed out in the Bug post, the underlying functions that are getting called in Stability.py are inconsistent in their implementation now and do not mirror the use of specialists and building modifiers the same now. At an early time, they may have behaved more consistent.

After review of the referenced link above, it becomes easier to understand how the RFC "Great Depression" model has become so horked now.
 
I have been working to address some of the underlying problems in the "Great Depression" implimentation. Most importantly, a better "iEconomy" representation that takes "Trade Routes", "Merchants", "Corporations" and "Religious" factors into consideration.

I used one of "Sevo" Mods as a baseline for the UI modifications, but added several python scripts to correctly calculate the commerce data. (in the upper left hand corner)

Following are the relevent modifications to CvMainInterface.py

Spoiler :


szBuffer = "Plot Raw Commerce:"

screen.setLabel( "MaintenanceTextb", "Background", szBuffer, CvUtil.FONT_LEFT_JUSTIFY, 15, 146, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )

screen.show( "MaintenanceTextb" )

szBuffer = "Trade Routes:"

screen.setLabel( "MaintenanceTextc", "Background", szBuffer, CvUtil.FONT_LEFT_JUSTIFY, 15, 166, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )

screen.show( "MaintenanceTextc" )

szBuffer = "Buildings and Specialists:"

screen.setLabel( "MaintenanceTextd", "Background", szBuffer, CvUtil.FONT_LEFT_JUSTIFY, 15, 186, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )

screen.show( "MaintenanceTextd" )

szBuffer = "<color=205,180,55,255>Net iEconomy:</color>"

screen.setLabel( "MaintenanceTexte", "Background", szBuffer, CvUtil.FONT_LEFT_JUSTIFY, 15, 206, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )

screen.show( "MaintenanceTexte" )

pPlayer = gc.getPlayer(pHeadSelectedCity.getOwner())

pySelectedCity = PyCity(pPlayer.getID(), pHeadSelectedCity.getID())

iPlotCommerce = pySelectedCity.getWorkingPlotsYield(YieldTypes.YIELD_COMMERCE)

iBuildingsAndSpecialistsCommerce = pySelectedCity.getSpecialistsCommerce(CommerceTypes.COMMERCE_GOLD) + pySelectedCity.getBuildingsCommerce(CommerceTypes.COMMERCE_GOLD)

szBuffer = u"-%d.%02d %c" %(iMaintenance/100, iMaintenance%100, gc.getCommerceInfo(CommerceTypes.COMMERCE_GOLD).getChar())

screen.setLabel( "MaintenanceAmountText", "Background", szBuffer, CvUtil.FONT_RIGHT_JUSTIFY, 220, 126, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_HELP_MAINTENANCE, -1, -1 )

screen.show( "MaintenanceAmountText" )

# Show Plot Commerce
szBuffer = u"%s%d %c" %( "+", iPlotCommerce, gc.getYieldInfo(YieldTypes.YIELD_COMMERCE).getChar())

screen.setLabel( "MaintenanceTextf", "Background", szBuffer, CvUtil.FONT_RIGHT_JUSTIFY, 220, 146, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )

screen.show( "MaintenanceTextf" )

iEconomyTimes100 = iPlotCommerce * 100

# Show Trade Route Commerce
szBuffer = u"%s%d %c" %( "+", iNetTradeAmount, gc.getYieldInfo(YieldTypes.YIELD_COMMERCE).getChar() )

screen.setLabel( "MaintenanceTextg", "Background", szBuffer, CvUtil.FONT_RIGHT_JUSTIFY, 220, 166, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )

screen.show( "MaintenanceTextg" )

iEconomyTimes100 += (iNetTradeAmount * 100)

# Show Buildings and Specialists
szBuffer = u"%s%d %c" %( "+", iBuildingsAndSpecialistsCommerce, gc.getYieldInfo(YieldTypes.YIELD_COMMERCE).getChar())

screen.setLabel( "MaintenanceTexth", "Background", szBuffer, CvUtil.FONT_RIGHT_JUSTIFY, 220, 186, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )

screen.show( "MaintenanceTexth" )

iEconomyTimes100 += (iBuildingsAndSpecialistsCommerce * 100)
iEconomyTimes100 -= iMaintenance

# Show Total iEconomy
szBuffer = u"<color=205,180,55,255>%s%d.%02d</color> %c" %( "+", iEconomyTimes100 / 100, iEconomyTimes100 % 100, gc.getYieldInfo(YieldTypes.YIELD_COMMERCE).getChar() )

screen.setLabel( "MaintenanceTexti", "Background", szBuffer, CvUtil.FONT_RIGHT_JUSTIFY, 220, 206, -0.3, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )

screen.show( "MaintenanceTexti" )


Previously "iEconomy" was not displayed and did not include commerce from "Trade Routes", "Specialists", "Corporations" or "Religions".

This meant that "iProduction" would rapidly outpace "iEconomy" and trigger a "Great Depression" as soon as you switched over to a "Free Market" economy. As it turns out from many players, their solution to the problem was to never play a "Free Market" economy in RFC. :(

In my modifications, I am calculating "iEconomy" as follows:

iCityEconomy = CityPlotCommerce + CityTradeRouteCommerce + CitySpecialistCommerce + CityBuildingCommerce - CityMaintenance

iEconomy = Summation of all iCityEconomies - some kind of Inflation Calculation.

And then, per RFC's current "Great Depression" algorithm, a more reasonable comparision between "iEconomy" and "iProduction" should result in a more manageable "Great Depression" occurrence.

(anyways, that is the theory on paper.... )
 

Attachments

  • Civ4ScreenShot0001.JPG
    Civ4ScreenShot0001.JPG
    342.3 KB · Views: 372
  • Civ4ScreenShot0000.JPG
    Civ4ScreenShot0000.JPG
    332.2 KB · Views: 333
Modifications to PyHelpers.py to support new commerce calculations.

Spoiler :

###################################
# DorianGray - begin
###################################

def isValid(self):
return (self.city.isNone() == False)

def isWorkingPlotByIndex(self, iIndex):
return self.city.isWorkingPlotByIndex(iIndex)

def getCityIndexPlot(self, iIndex):
return self.city.getCityIndexPlot(iIndex)

def getWorkingPlotList(self):
lPlots = []
numCityPlots = gc.getNUM_CITY_PLOTS()
for iIndex in range(numCityPlots):
if (self.isWorkPlotByIndex(iIndex)):
pLoopPlot = self.city.getCityIndexPlot(iIndex)
if (not pLoopPlot.isNone()):
lPlots.append(pLoopPlot)
return lPlots

def getWorkingPlotsYield(self, eYield):
iYield = 0
numCityPlots = gc.getNUM_CITY_PLOTS()
for iIndex in range(numCityPlots):
if (self.isWorkingPlotByIndex(iIndex)):
pLoopPlot = self.city.getCityIndexPlot(iIndex)
if (not pLoopPlot.isNone()):
iYield += pLoopPlot.getYield(eYield)
return iYield

def getSpecialistsCommerce(self, eCommerce):
iSpecialistCommerce = self.city.getSpecialistCommerce(eCommerce)
iExtraCommerce = (self.city.getSpecialistPopulation() + self.city.getNumGreatPeople()) * self.player.getSpecialistExtraCommerce(eCommerce)
iReturn = iSpecialistCommerce + iExtraCommerce
return iReturn

def getBuildingsCommerce(self, eCommerce):
iReturn = 0
iReturn += self.city.getReligionCommerce(eCommerce)
iReturn += self.city.getCorporationCommerce(eCommerce)
iReturn += self.city.getBuildingCommerce(eCommerce)
return iReturn

###################################
# DorianGray - end
###################################
 

Attachments

  • PyHelpers.zip
    12.4 KB · Views: 147
Deanej,

Points noted. I did find it fustrating how everything got reformated. I didn't see the
Code:
 button to denote source code snipet.  But I may have overlooked it.

The "iEconomy" text on the city status screen was more of an interim implementation until a proper moniker could be kicked around that seems to be indicative of the datum.
 
It's in the advanced editor - I think it looks like a # sign.

For the text name, "Economy" or something similar might work.

Is there also a way to get total production so that it can easily be seen how likely a great depression is? Perhaps a Production display below it, with the economy one being total amount traded.
 
Also, the "iEconomy" data that is being displayed on the individual city status screens is really "iCityEconomy" data previously mentioned specific to only that city.

I did not really mean for the "iEconomy" label to stick around and so just left it until later. But it may be a bit confusing in context of my previous post.
 
Deanj,

The total production is already currently displayed in the graphs & demographics screens.

http://www.civfanatics.com/civ4/strategy/demographics.php

Mfg. Goods- The Manufactured Goods is the total of the production you produce on each turn. The raw production is the total hammers you get from each worked tile and specialists.

However, as of BTS 3.17, the GNP being displayed is completely unrelated solely to commerce and irrelevant to the "Great Depression" calculations.

I am working on adding to the demographics screen a value representative of "iEconomy" that could be used to make a meaningful comparison against the current "Mfg Goods" that are displayed now. (this would be a summization of all the "iCityEconomy" values for your civilization)
 
To be fair to the wiki, it was probably written when the GNP (Gold) in the Demographics screen did actually show raw commerce - costs. While that isn't a meaningful value, it's at least less volatile than more "realistic" measures of economy, so I think using that in stability calculations is ok.

The disconnect is that, while the basic stability and great depression framework hasn't changed that much, BTS made two changes (for Civ 4 overall, not just RFC) - the revised GNP (Gold) calculations and corporations. Corporations really throw the great depression calculation out of whack: while the net effect to your cash flow may not be large in either direction (assuming you control the corporation headquarters), there's actually a large increase in maintenance costs (which makes great depression more likely) combined with a large increase in income at the corporation headquarters (which has NO EFFECT on stability calculations).

So if anything needs to be fixed, it's probably that corporation income should be factored into the great depression calculation somehow (or maybe not - I suppose it could be argued that having corporations should make great depression more likely).
 
Soda,

The current mechanism further considers "Engineers" in the production calculations, but ignore "Merchants" in the economy calculations. That is another problem that is being looked at.

IMO, corporations SHOULD be factored into the "Great Depression" calculations (and will be in my modifications). They will be factored in both their "positive" effects and "negative" effects.

The "positive" effects, as Soda noted, come from the corporation headquarters. The "negative" effects are subtly factored into the "city maintenance" calculations and will be directly subtracted from the individual "CityEconomy" values.

The point of this is to allow properly run corporations to be a positive influence on avoiding "Great Depressions", but improperly run corporations to actually increase the likelyhood.
 
Top Bottom