class TerrainGenerator:
"If iDesertPercent=35, then about 35% of all land will be desert. Plains is similar. \
Note that all percentages are approximate, as values have to be roughened to achieve a natural look."
def __init__(self, iDesertPercent=32, iPlainsPercent=18,
fSnowLatitude=0.7, fTundraLatitude=0.6,
fGrassLatitude=0.1, fDesertBottomLatitude=0.2,
fDesertTopLatitude=0.5, fracXExp=-1,
fracYExp=-1, grain_amount=4):
self.gc = CyGlobalContext()
self.map = CyMap()
grain_amount += self.gc.getWorldInfo(self.map.getWorldSize()).getTerrainGrainChange()
self.grain_amount = grain_amount
self.iWidth = self.map.getGridWidth()
self.iHeight = self.map.getGridHeight()
self.mapRand = self.gc.getGame().getMapRand()
self.iFlags = 0 # Disallow FRAC_POLAR flag, to prevent "zero row" problems.
if self.map.isWrapX(): self.iFlags += CyFractal.FracVals.FRAC_WRAP_X
if self.map.isWrapY(): self.iFlags += CyFractal.FracVals.FRAC_WRAP_Y
self.deserts=CyFractal()
self.plains=CyFractal()
self.variation=CyFractal()
iDesertPercent += self.gc.getClimateInfo(self.map.getClimate()).getDesertPercentChange()
iDesertPercent = min(iDesertPercent, 100)
iDesertPercent = max(iDesertPercent, 0)
self.iDesertPercent = iDesertPercent
self.iPlainsPercent = iPlainsPercent
self.iDesertTopPercent = 100
self.iDesertBottomPercent = max(0,int(100-iDesertPercent))
self.iPlainsTopPercent = 100
self.iPlainsBottomPercent = max(0,int(100-iDesertPercent-iPlainsPercent))
self.iMountainTopPercent = 75
self.iMountainBottomPercent = 60
fSnowLatitude += self.gc.getClimateInfo(self.map.getClimate()).getSnowLatitudeChange()
fSnowLatitude = min(fSnowLatitude, 1.0)
fSnowLatitude = max(fSnowLatitude, 0.0)
self.fSnowLatitude = fSnowLatitude
fTundraLatitude += self.gc.getClimateInfo(self.map.getClimate()).getTundraLatitudeChange()
fTundraLatitude = min(fTundraLatitude, 1.0)
fTundraLatitude = max(fTundraLatitude, 0.0)
self.fTundraLatitude = fTundraLatitude
fGrassLatitude += self.gc.getClimateInfo(self.map.getClimate()).getGrassLatitudeChange()
fGrassLatitude = min(fGrassLatitude, 1.0)
fGrassLatitude = max(fGrassLatitude, 0.0)
self.fGrassLatitude = fGrassLatitude
fDesertBottomLatitude += self.gc.getClimateInfo(self.map.getClimate()).getDesertBottomLatitudeChange()
fDesertBottomLatitude = min(fDesertBottomLatitude, 1.0)
fDesertBottomLatitude = max(fDesertBottomLatitude, 0.0)
self.fDesertBottomLatitude = fDesertBottomLatitude
fDesertTopLatitude += self.gc.getClimateInfo(self.map.getClimate()).getDesertTopLatitudeChange()
fDesertTopLatitude = min(fDesertTopLatitude, 1.0)
fDesertTopLatitude = max(fDesertTopLatitude, 0.0)
self.fDesertTopLatitude = fDesertTopLatitude
self.fracXExp = fracXExp
self.fracYExp = fracYExp
self.initFractals()