Announcement

Collapse
No announcement yet.

How do you fight inflation?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Originally posted by _BuRjaCi_
    Can anyone dig up the source code which deals with inflation?
    I would realy apreciate that, sice I like to understan the "guts" of the games I play.
    The formula is pretty simple. In the XML files, you'll find two inflation-related entries for each speed. There is also one for the difficulty level. The inflation percentage for turn N of the game is:

    InfPct = (N + InflationOffset) * (SpeedInflationPercent/100) * (HandicapInflationPercent/100)

    For instance, for Epic speed, the offset is -160 and the percent is 20. So, at Monarch+ (HandicapInflationPercent=100), you'll have zero inflation through turn 164 (thanks to integer math), then it'll increase 1% every five turns thereafter (to 100% at the end of the game).

    Note that the AI gets a substantial discount on this rate, also specified in the XML for handicap levels.

    The source (from the WL SDK, CvPlayer.cpp:5604):

    Code:
    int CvPlayer::calculateInflationRate()
    {
    	int iTurns;
    	int iRate;
    
    	iTurns = ((GC.getGameINLINE().getGameTurn() + GC.getGameINLINE().getElapsedGameTurns()) / 2);
    	iTurns += GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getInflationOffset();
    
    	if (iTurns < 0)
    	{
    		return 0;
    	}
    
    	iRate = iTurns;
    
    	iRate *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getInflationPercent();
    	iRate /= 100;
    
    	iRate *= GC.getHandicapInfo(getHandicapType()).getInflationPercent();
    	iRate /= 100;
    
    	if (!isHuman() && !isBarbarian())
    	{
    		iRate *= GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIInflationPercent();
    		iRate /= 100;
    
    		iRate *= max(0, ((GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIPerEraModifier() * getCurrentEra()) + 100));
    		iRate /= 100;
    	}
    
    	FAssert(iRate >= 0);
    
    	return iRate;
    }

    Comment


    • #17
      What a messy code. I hope the rest of the game is better written.

      Why does it use both iRate and iTurns? There's absolutely no point.

      Why does it apply both human *and* AI inflation bonusses to the AI? That's just confusing and weird.

      Anyway, it is pretty straightforward. Inflation is zero for a specific number of turns, then rises linearly to 100%, assuming no difficulty modifiers.

      Comment

      Working...
      X