class earth2TerrainGenerator(CvMapGeneratorUtil.TerrainGenerator):
def __init__(self, iDesertPercent=40, iPlainsPercent=26,
fSnowLatitude=0.82, fTundraLatitude=0.75,
fGrassLatitude=0.1, fDesertBottomLatitude=0.1,
fDesertTopLatitude=0.3, fracXExp=-1,
fracYExp=-1, grain_amount=3):
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()
[B] def initFractals(self):[/B]
self.deserts.fracInit(self.iWidth, self.iHeight, self.grain_amount, self.mapRand, self.iFlags, self.fracXExp, self.fracYExp)
self.iDesertTop = self.deserts.getHeightFromPercent(self.iDesertTopPercent)
self.iDesertBottom = self.deserts.getHeightFromPercent(self.iDesertBottomPercent)
self.plains.fracInit(self.iWidth, self.iHeight, self.grain_amount+1, self.mapRand, self.iFlags, self.fracXExp, self.fracYExp)
self.iPlainsTop = self.plains.getHeightFromPercent(self.iPlainsTopPercent)
self.iPlainsBottom = self.plains.getHeightFromPercent(self.iPlainsBottomPercent)
self.variation.fracInit(self.iWidth, self.iHeight, self.grain_amount, self.mapRand, self.iFlags, self.fracXExp, self.fracYExp)
self.terrainDesert = self.gc.getInfoTypeForString("TERRAIN_DESERT")
self.terrainPlains = self.gc.getInfoTypeForString("TERRAIN_PLAINS")
self.terrainIce = self.gc.getInfoTypeForString("TERRAIN_SNOW")
self.terrainTundra = self.gc.getInfoTypeForString("TERRAIN_TUNDRA")
self.terrainGrass = self.gc.getInfoTypeForString("TERRAIN_GRASS")
def getLatitudeAtPlot(self, iX, iY):
"""given a point (iX,iY) such that (0,0) is in the NW,
returns a value between 0.0 (tropical) and 1.0 (polar).
This function can be overridden to change the latitudes; for example,
to make an entire map have temperate terrain, or to make terrain change from east to west
instead of from north to south"""
lat = abs((self.iHeight / 2) - iY)/float(self.iHeight/2) # 0.0 = equator, 1.0 = pole
# Adjust latitude using self.variation fractal, to mix things up:
lat += (128 - self.variation.getHeight(iX, iY))/(255.0 * 5.0)
# Limit to the range [0, 1]:
if lat < 0:
lat = 0.0
if lat > 1:
lat = 1.0
return lat
def generateTerrain(self):
terrainData = [0]*(self.iWidth*self.iHeight)
for x in range(self.iWidth):
for y in range(self.iHeight):
iI = y*self.iWidth + x
terrain = self.generateTerrainAtPlot(x, y)
terrainData[iI] = terrain
return terrainData
def generateTerrainAtPlot(self,iX,iY):
lat = self.getLatitudeAtPlot(iX,iY)
if (self.map.plot(iX, iY).isWater()):
return self.map.plot(iX, iY).getTerrainType()
terrainVal = self.terrainGrass
if lat >= self.fSnowLatitude:
terrainVal = self.terrainIce
elif lat >= self.fTundraLatitude:
terrainVal = self.terrainTundra
elif lat < self.fGrassLatitude:
terrainVal = self.terrainGrass
else:
desertVal = self.deserts.getHeight(iX, iY)
plainsVal = self.plains.getHeight(iX, iY)
if ((desertVal >= self.iDesertBottom) and (desertVal <= self.iDesertTop) and (lat >= self.fDesertBottomLatitude) and (lat < self.fDesertTopLatitude)):
terrainVal = self.terrainDesert
elif ((plainsVal >= self.iPlainsBottom) and (plainsVal <= self.iPlainsTop)):
terrainVal = self.terrainPlains
if (terrainVal == TerrainTypes.NO_TERRAIN):
return self.map.plot(iX, iY).getTerrainType()
return terrainVal
def generateTerrainTypes():
NiTextOut("Generating Terrain (Python Terra) ...")
terraingen = earth2TerrainGenerator()
terrainTypes = terraingen.generateTerrain()
return terrainTypes
def addFeatures():
NiTextOut("Adding Features (Python earth2) ...")
featuregen = FeatureGenerator()
featuregen.addFeatures()
return 0