class DonutFractalWorld(CvMapGeneratorUtil.FractalWorld):
def generatePlotTypes(self, water_percent=78, shift_plot_types=True, grain_amount=3):
gc = CyGlobalContext() #Why don't they put this at the top of ALL files?
#init plottype fractals for hills and peaks
self.hillsFrac.fracInit(self.iNumPlotsX, self.iNumPlotsY, grain_amount, self.mapRand, self.iFlags, self.fracXExp, self.fracYExp)
self.peaksFrac.fracInit(self.iNumPlotsX, self.iNumPlotsY, grain_amount+1, self.mapRand, self.iFlags, self.fracXExp, self.fracYExp)
iHillsBottom1 = self.hillsFrac.getHeightFromPercent(max((self.hillGroupOneBase - self.hillGroupOneRange), 0))
iHillsTop1 = self.hillsFrac.getHeightFromPercent(min((self.hillGroupOneBase + self.hillGroupOneRange), 100))
iHillsBottom2 = self.hillsFrac.getHeightFromPercent(max((self.hillGroupTwoBase - self.hillGroupTwoRange), 0))
iHillsTop2 = self.hillsFrac.getHeightFromPercent(min((self.hillGroupTwoBase + self.hillGroupTwoRange), 100))
iPeakThreshold = self.peaksFrac.getHeightFromPercent(self.peakPercent)
#orlanth: init terraintype fractals, copied from TerrainGenerator in CvMapGeneratorUtil.py
self.deserts.fracInit(self.iWidth, self.iHeight, self.grain_amount, self.mapRand, self.iFlags, self.fracXExp, self.fracYExp)
iDesertTop = self.deserts.getHeightFromPercent(self.iDesertTopPercent)
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)
iPlainsTop = self.plains.getHeightFromPercent(self.iPlainsTopPercent)
iPlainsBottom = self.plains.getHeightFromPercent(self.iPlainsBottomPercent)
self.marsh.fracInit(self.iWidth, self.iHeight, self.grain_amount, self.mapRand, self.iFlags, self.fracXExp, self.fracYExp)
iMarshTop = self.marsh.getHeightFromPercent(self.iMarshTopPercent)
iMarshBottom = self.marsh.getHeightFromPercent(self.iMarshBottomPercent)
self.variation.fracInit(self.iWidth, self.iHeight, self.grain_amount, self.mapRand, self.iFlags, self.fracXExp, self.fracYExp)
iCoreX = int(self.iNumPlotsX / 2)
iCoreY = int(self.iNumPlotsY / 2)
iNumPlanets = (gc.getMap().getWorldSize() * 2)
for i in range(iNumPlanets):
iAttemptsLeft = 200
while iAttemptsLeft > 0:
iCenterX = CyGame().getSorenRandNum(gc.getMap().getGridWidth(), "Center X")
iCenterY = CyGame().getSorenRandNum(gc.getMap().getGridHeight(), "Center Y")
iRadiusMod = self.getRadius(iCoreX)
iRadius = min((iCoreX - iRadiusMod), (iCoreY - iRadiusMod))
iHoleRadius = int(iRadius / 2)
if not (self.isValidPlanet(iCenterX, iCenterY, iRadius)):
iAttemptsLeft -= 1
continue
#orlanth: choose a Climate Type for planet
iNumClimateTypes = 3
iClimate = CyGame().getSorenRandNum(iNumClimateTypes, "climatetypes")
if iClimate = 1:
#set terrain types for Earthlike planet
terrainDry = self.gc.getInfoTypeForString("TERRAIN_DESERT")
terrainRocky = self.gc.getInfoTypeForString("TERRAIN_PLAINS")
terrainFertile = self.gc.getInfoTypeForString("TERRAIN_GRASS")
terrainWet = self.gc.getInfoTypeForString("TERRAIN_MARSH")
terrainPolar = self.gc.getInfoTypeForString("TERRAIN_TUNDRA")
terrainCoast = self.gc.getInfoTypeForString("TERRAIN_COAST")
terrainOcean = self.gc.getInfoTypeForString("TERRAIN_OCEAN")
elif iClimate = 2:
#set terrain types for Arid planet
terrainDry = self.gc.getInfoTypeForString("TERRAIN_DESERT")
terrainRocky = self.gc.getInfoTypeForString("TERRAIN_BADLANDS")
terrainFertile = self.gc.getInfoTypeForString("TERRAIN_PLAINS")
terrainWet = self.gc.getInfoTypeForString("TERRAIN_GRASS")
terrainPolar = self.gc.getInfoTypeForString("TERRAIN_TUNDRA")
terrainCoast = self.gc.getInfoTypeForString("TERRAIN_COAST")
terrainOcean = self.gc.getInfoTypeForString("TERRAIN_OCEAN")
else:
#set terrain types for Volcanic planet
terrainDry = self.gc.getInfoTypeForString("TERRAIN_DESERT")
terrainRocky = self.gc.getInfoTypeForString("TERRAIN_BATHOLITH")
terrainFertile = self.gc.getInfoTypeForString("TERRAIN_REGOLITH")
terrainWet = self.gc.getInfoTypeForString("TERRAIN_VOLCANIC")
terrainPolar = self.gc.getInfoTypeForString("TERRAIN_TUNDRA")
terrainCoast = self.gc.getInfoTypeForString("TERRAIN_COAST")
terrainOcean = self.gc.getInfoTypeForString("TERRAIN_OCEAN")
for x in range(self.iNumPlotsX):
for y in range(self.iNumPlotsY):
i = y*self.iNumPlotsX + x
if x == iCenterX and y == iCenterY:
fDistance = 0
else:
fDistance = sqrt(((x - iCenterX) ** 2) + ((y - iCenterY) ** 2))
if fDistance < iRadius:
#generate planetary PlotType (hill peak or land, add code for coast or ocean?)
hillVal = self.hillsFrac.getHeight(x,y)
if ((hillVal >= iHillsBottom1 and hillVal <= iHillsTop1) or (hillVal >= iHillsBottom2 and hillVal <= iHillsTop2)):
peakVal = self.peaksFrac.getHeight(x,y)
if (peakVal <= iPeakThreshold):
self.plotTypes[i] = PlotTypes.PLOT_PEAK
else:
self.plotTypes[i] = PlotTypes.PLOT_HILLS
else:
self.plotTypes[i] = PlotTypes.PLOT_LAND
#orlanth: assign TerrainType to plot, using Climate variables of current planet
#adapted from generateTerrainAtPlot in CvMapGeneratorUtil.py
desertVal = self.deserts.getHeight(iX, iY)
plainsVal = self.plains.getHeight(iX, iY)
marshVal = self.marsh.getHeight(iX, iY)
if ((desertVal >= self.iDesertBottom):
terrainVal = self.terrainDry
elif ((marshVal >= self.iMarshBottom) and (marshVal <= self.iMarshTop) and plot.isFlatlands()):
terrainVal = self.terrainWet
elif ((plainsVal >= self.iPlainsBottom) and (plainsVal <= self.iPlainsTop)):
terrainVal = self.terrainRocky
else:
terrainVal = self.terrainFertile
self.terrainTypes[i] = terrainVal
break
if shift_plot_types:
self.shiftPlotTypes()
return self.plotTypes
def isValidPlanet(self, iCenterX, iCenterY, iRadius):
if ((iCenterX - iRadius < 1) or (iCenterY - iRadius < 1) or (iCenterX + iRadius + 1 > self.iNumPlotsX) or (iCenterY + iRadius + 1 > self.iNumPlotsY)):
return false
for x in range(self.iNumPlotsX):
for y in range(self.iNumPlotsY):
i = y*self.iNumPlotsX + x
if x == iCenterX and y == iCenterY:
fDistance = 0
else:
fDistance = sqrt(((x - iCenterX) ** 2) + ((y - iCenterY) ** 2))
if fDistance < iRadius+2:
if self.plotTypes[i] != PlotTypes.PLOT_OCEAN:
return false
return true
def getRadius(self, iCoreX):
bValid = false
for i in range(2000):
iRadiusMod = (iCoreX * (CyGame().getSorenRandNum(3, "Radius")) / 2)
if round(iCoreX * 3 / 4) < iRadiusMod < iCoreX:
bValid = true
break
if bValid == false:
iRadiusMod = round(iCoreX * 3 / 4)
return iRadiusMod