コード例 #1
0
def generatePlotTypes():
	NiTextOut("Setting Plot Types (Python Balanced) ...")
	global hinted_world
	hinted_world = HintedWorld(16,8)

	mapRand = CyGlobalContext().getGame().getMapRand()

	numBlocks = hinted_world.w * hinted_world.h
	numBlocksLand = int(numBlocks*0.25)
	cont = hinted_world.addContinent(numBlocksLand,mapRand.get(5, "Generate Plot Types PYTHON")+4,mapRand.get(3, "Generate Plot Types PYTHON")+2)
	if not cont:
		print "Couldn't create continent! Reverting to C implementation."
		CyPythonMgr().allowDefaultImpl()
	else:		
		for x in range(hinted_world.w):
			for y in (0, hinted_world.h - 1):
				hinted_world.setValue(x,y, 1) # force ocean at poles
		hinted_world.buildAllContinents()
		return hinted_world.generatePlotTypes(shift_plot_types=True)
コード例 #2
0
	def generateAndysHintedPangaea(self):
		NiTextOut("Setting Plot Types (Python Pangaea Hinted) ...")
		global hinted_world
		hinted_world = HintedWorld(16,8)

		mapRand = CyGame().getMapRand()

		numBlocks = hinted_world.w * hinted_world.h
		numBlocksLand = int(numBlocks*0.33)
		cont = hinted_world.addContinent(numBlocksLand,mapRand.get(5, "Generate Plot Types PYTHON")+4,mapRand.get(3, "Generate Plot Types PYTHON")+2)
		if not cont:
			# Couldn't create continent! Reverting to Soren's Hinted Pangaea
			return self.generateSorensHintedPangaea()
		else:
			for x in range(hinted_world.w):
				for y in (0, hinted_world.h - 1):
					hinted_world.setValue(x,y, 1) # force ocean at poles
			hinted_world.buildAllContinents()
			return hinted_world.generatePlotTypes(shift_plot_types=True)
コード例 #3
0
def generatePlotTypes():
	NiTextOut("Setting Plot Types (Python Balanced) ...")
	global hinted_world
	hinted_world = HintedWorld(16,8)

	mapRand = CyGlobalContext().getGame().getMapRand()

	numBlocks = hinted_world.w * hinted_world.h
	numBlocksLand = int(numBlocks*0.25)
	cont = hinted_world.addContinent(numBlocksLand,mapRand.get(5, "Generate Plot Types PYTHON")+4,mapRand.get(3, "Generate Plot Types PYTHON")+2)
	if not cont:
		print "Couldn't create continent! Reverting to C implementation."
		CyPythonMgr().allowDefaultImpl()
	else:		
		for x in range(hinted_world.w):
			for y in (0, hinted_world.h - 1):
				hinted_world.setValue(x,y, 1) # force ocean at poles
		hinted_world.buildAllContinents()
		return hinted_world.generatePlotTypes(shift_plot_types=True)
コード例 #4
0
	def generateAndysHintedPangaea(self):
		NiTextOut("Setting Plot Types (Python Pangaea Hinted) ...")
		global hinted_world
		hinted_world = HintedWorld(16,8)

		mapRand = CyGlobalContext().getGame().getMapRand()

		numBlocks = hinted_world.w * hinted_world.h
		numBlocksLand = int(numBlocks*0.33)
		cont = hinted_world.addContinent(numBlocksLand,mapRand.get(5, "Generate Plot Types PYTHON")+4,mapRand.get(3, "Generate Plot Types PYTHON")+2)
		if not cont:
			# Couldn't create continent! Reverting to Soren's Hinted Pangaea
			return self.generateSorensHintedPangaea()
		else:		
			for x in range(hinted_world.w):
				for y in (0, hinted_world.h - 1):
					hinted_world.setValue(x,y, 1) # force ocean at poles
			hinted_world.buildAllContinents()
			return hinted_world.generatePlotTypes(shift_plot_types=True)
コード例 #5
0
ファイル: Ring_World.py プロジェクト: AP-ML/DTM
def generatePlotTypes():
	NiTextOut("Setting Plot Types (Python Ring_World) ...")
	global hinted_world, mapRand
	global fractal_world
	gc = CyGlobalContext()
	map = CyMap()
	mapRand = gc.getGame().getMapRand()

	hinted_world = HintedWorld()

	iNumPlotsX = map.getGridWidth()
	iNumPlotsY = map.getGridHeight()

	# Set the top and bottom two tiles to ocean, others to land
	for x in range(iNumPlotsX):
		for y in range(iNumPlotsY):
			if (y <= 3
			or  y >= 8):
				hinted_world.setValue(x,y,0) # ocean
			else:
				hinted_world.setValue(x,y,255) # land

	hinted_world.buildAllContinents()
	plotTypes = hinted_world.generatePlotTypes(water_percent = 0)

	# fix the water and land mix
	for x in range(iNumPlotsX):
		for y in range(iNumPlotsY):
			i = map.plotNum(x, y)
			if (y <= 3
			or  y >= 8):
				if plotTypes[i] != PlotTypes.PLOT_OCEAN:
					plotTypes[i] = PlotTypes.PLOT_OCEAN
			else:
				if plotTypes[i] != PlotTypes.PLOT_LAND:
					plotTypes[i] = PlotTypes.PLOT_LAND

	# Templates are nested by keys: [Land Density, Number of Land tiles]}
	Land_Template = {0: [100.0,100.0,100.0,100.0,100.0],
					 1: [ 70.0, 80.0, 90.0,100.0,100.0],
					 2: [ 40.0, 60.0, 80.0, 90.0,100.0],
					 3: [ 10.0, 20.0, 40.0, 60.0,100.0],
					 4: [ 20.0, 40.0, 60.0, 80.0,100.0]
					}

	userInputPlots = map.getCustomMapOption(0)
	dice = gc.getGame().getMapRand()

	# fix the water and land mix
	for x in range(iNumPlotsX):

		iRand = dice.get(100, "Shuffling Land 1 - TBG PYTHON")
		iNumWater = 0
		while iRand > Land_Template[userInputPlots][iNumWater]:
			print "iRand %i iNumWater %i template %i" % (iRand, iNumWater, Land_Template[userInputPlots][iNumWater])
			iNumWater += 1

		print "iRand %i iNumWater %i" % (iRand, iNumWater)

		if iNumWater == 0:
			# no water tile
			iRand = dice.get(2, "Shuffling Land 2 - TBG PYTHON")

		elif iNumWater == 1:
			# only 1 water tile
			# tiles can be WLLL or LLLW
			iRand = dice.get(2, "Shuffling Land 2a - TBG PYTHON")
			if iRand == 0: # WLLL
				i = map.plotNum(x, 4)
				plotTypes[i] = PlotTypes.PLOT_OCEAN
			else: # LLLW
				i = map.plotNum(x, 7)
				plotTypes[i] = PlotTypes.PLOT_OCEAN

		elif iNumWater == 2:
			# 2 water tiles
			# tiles can be WWLL, LLWW or WLLW
			iRand = dice.get(3, "Shuffling Land 2b - TBG PYTHON")
			if iRand == 0: # WWLL
				i = map.plotNum(x, 4)
				plotTypes[i] = PlotTypes.PLOT_OCEAN
				i = map.plotNum(x, 5)
				plotTypes[i] = PlotTypes.PLOT_OCEAN
			elif iRand == 1: # WLLW
				i = map.plotNum(x, 4)
				plotTypes[i] = PlotTypes.PLOT_OCEAN
				i = map.plotNum(x, 7)
				plotTypes[i] = PlotTypes.PLOT_OCEAN
			else: # LLWW
				i = map.plotNum(x, 6)
				plotTypes[i] = PlotTypes.PLOT_OCEAN
				i = map.plotNum(x, 7)
				plotTypes[i] = PlotTypes.PLOT_OCEAN

		else:
			# either 3 or 4 water tiles
			# set all to water and then set 1 back to land if required
			i = map.plotNum(x, 4)
			plotTypes[i] = PlotTypes.PLOT_OCEAN
			i = map.plotNum(x, 5)
			plotTypes[i] = PlotTypes.PLOT_OCEAN
			i = map.plotNum(x, 6)
			plotTypes[i] = PlotTypes.PLOT_OCEAN
			i = map.plotNum(x, 7)
			plotTypes[i] = PlotTypes.PLOT_OCEAN

			if iNumWater == 3:
				# 3 water tiles
				# tiles can be WWWL, WWLW, WLWW or LWWW
				iRand = dice.get(4, "Shuffling Land 2c - TBG PYTHON")
				if iRand == 0: # WWWL
					i = map.plotNum(x, 7)
					plotTypes[i] = PlotTypes.PLOT_LAND
				elif iRand == 1: # WWLW
					i = map.plotNum(x, 6)
					plotTypes[i] = PlotTypes.PLOT_LAND
				elif iRand == 2: # WLWW
					i = map.plotNum(x, 5)
					plotTypes[i] = PlotTypes.PLOT_LAND
				else: # LWWW
					i = map.plotNum(x, 4)
					plotTypes[i] = PlotTypes.PLOT_LAND

#		calc regional density
#	this calculation determines the probability of a tile at location x being desert, plains or hills
#	the map is broken into 4 regions: no feature (let map scrip decide), desert, plains, hills
#	the desert strength starts at 0 at tile x = 0 x width / 4 + 1  and increases linearly to maximum at tile x = 1 x width / 4
#	  at which point it starts to decrease back to zero at x = 2 x width / 4
#	the plains strength starts at 0 at tile x = 1 x width / 4 + 1 and increases linearly to maximum at tile x = 2 x width / 4
#	  at which point it starts to decrease back to zero at x = 3 x width / 4
#	the hills  strength starts at 0 at tile x = 2 x width / 4 + 1 and increases linearly to maximum at tile x = 3 x width / 4
#	  at which point it starts to decrease back to zero at x = 4 x width / 4

#	the iRegionW (region weight) controls the overall strength of the regionality and is user controlled.
#	A setting of 0 means that no regionality takes place and the balance of the map script does what it does
#	A setting of weak (20) means that each tile has a maximum change of 20% of being adjusted, if not adjusted, then the map script does what it does
#	A setting of moderate (40) means that each tile has a maximum change of 40% of being adjusted, if not adjusted, then the map script does what it does
#	etc ...

#	Region Density
		Region_Template = [0.0, 30.0, 60.0, 90.0, 120.0]

		userRegionDensity = map.getCustomMapOption(1)
		iRegionW = Region_Template[userRegionDensity]
		iW4 = iNumPlotsX / 4

		iDesert =           iRegionW * max(0, 1 - float(abs(x - 1 * iW4)) / float(iW4))
		iPlains = iDesert + iRegionW * max(0, 1 - float(abs(x - 2 * iW4)) / float(iW4))
		iHills  = iPlains + iRegionW * max(0, 1 - float(abs(x - 3 * iW4)) / float(iW4))

#		loop over land tiles and change to hill if required
		for y in range(4, 7):
			i = map.plotNum(x, y)
			
			if plotTypes[i] == PlotTypes.PLOT_LAND:
				iRand = dice.get(100, "Region Determination 1 - TBG PYTHON")
				if (iRand > iPlains
				and iRand <= iHills):
					plotTypes[i] = PlotTypes.PLOT_HILLS

	return plotTypes
コード例 #6
0
def generatePlotTypes():
    NiTextOut("Setting Plot Types (Python Ring_World) ...")
    global hinted_world, mapRand
    global fractal_world
    gc = CyGlobalContext()
    map = CyMap()
    mapRand = gc.getGame().getMapRand()

    hinted_world = HintedWorld()

    iNumPlotsX = map.getGridWidth()
    iNumPlotsY = map.getGridHeight()

    # Set the top and bottom two tiles to ocean, others to land
    for x in range(iNumPlotsX):
        for y in range(iNumPlotsY):
            if (y <= 3 or y >= 8):
                hinted_world.setValue(x, y, 0)  # ocean
            else:
                hinted_world.setValue(x, y, 255)  # land

    hinted_world.buildAllContinents()
    plotTypes = hinted_world.generatePlotTypes(water_percent=0)

    # fix the water and land mix
    for x in range(iNumPlotsX):
        for y in range(iNumPlotsY):
            i = map.plotNum(x, y)
            if (y <= 3 or y >= 8):
                if plotTypes[i] != PlotTypes.PLOT_OCEAN:
                    plotTypes[i] = PlotTypes.PLOT_OCEAN
            else:
                if plotTypes[i] != PlotTypes.PLOT_LAND:
                    plotTypes[i] = PlotTypes.PLOT_LAND

    # Templates are nested by keys: [Land Density, Number of Land tiles]}
    Land_Template = {
        0: [100.0, 100.0, 100.0, 100.0, 100.0],
        1: [70.0, 80.0, 90.0, 100.0, 100.0],
        2: [40.0, 60.0, 80.0, 90.0, 100.0],
        3: [10.0, 20.0, 40.0, 60.0, 100.0],
        4: [20.0, 40.0, 60.0, 80.0, 100.0]
    }

    userInputPlots = map.getCustomMapOption(0)
    dice = gc.getGame().getMapRand()

    # fix the water and land mix
    for x in range(iNumPlotsX):

        iRand = dice.get(100, "Shuffling Land 1 - TBG PYTHON")
        iNumWater = 0
        while iRand > Land_Template[userInputPlots][iNumWater]:
            print "iRand %i iNumWater %i template %i" % (
                iRand, iNumWater, Land_Template[userInputPlots][iNumWater])
            iNumWater += 1

        print "iRand %i iNumWater %i" % (iRand, iNumWater)

        if iNumWater == 0:
            # no water tile
            iRand = dice.get(2, "Shuffling Land 2 - TBG PYTHON")

        elif iNumWater == 1:
            # only 1 water tile
            # tiles can be WLLL or LLLW
            iRand = dice.get(2, "Shuffling Land 2a - TBG PYTHON")
            if iRand == 0:  # WLLL
                i = map.plotNum(x, 4)
                plotTypes[i] = PlotTypes.PLOT_OCEAN
            else:  # LLLW
                i = map.plotNum(x, 7)
                plotTypes[i] = PlotTypes.PLOT_OCEAN

        elif iNumWater == 2:
            # 2 water tiles
            # tiles can be WWLL, LLWW or WLLW
            iRand = dice.get(3, "Shuffling Land 2b - TBG PYTHON")
            if iRand == 0:  # WWLL
                i = map.plotNum(x, 4)
                plotTypes[i] = PlotTypes.PLOT_OCEAN
                i = map.plotNum(x, 5)
                plotTypes[i] = PlotTypes.PLOT_OCEAN
            elif iRand == 1:  # WLLW
                i = map.plotNum(x, 4)
                plotTypes[i] = PlotTypes.PLOT_OCEAN
                i = map.plotNum(x, 7)
                plotTypes[i] = PlotTypes.PLOT_OCEAN
            else:  # LLWW
                i = map.plotNum(x, 6)
                plotTypes[i] = PlotTypes.PLOT_OCEAN
                i = map.plotNum(x, 7)
                plotTypes[i] = PlotTypes.PLOT_OCEAN

        else:
            # either 3 or 4 water tiles
            # set all to water and then set 1 back to land if required
            i = map.plotNum(x, 4)
            plotTypes[i] = PlotTypes.PLOT_OCEAN
            i = map.plotNum(x, 5)
            plotTypes[i] = PlotTypes.PLOT_OCEAN
            i = map.plotNum(x, 6)
            plotTypes[i] = PlotTypes.PLOT_OCEAN
            i = map.plotNum(x, 7)
            plotTypes[i] = PlotTypes.PLOT_OCEAN

            if iNumWater == 3:
                # 3 water tiles
                # tiles can be WWWL, WWLW, WLWW or LWWW
                iRand = dice.get(4, "Shuffling Land 2c - TBG PYTHON")
                if iRand == 0:  # WWWL
                    i = map.plotNum(x, 7)
                    plotTypes[i] = PlotTypes.PLOT_LAND
                elif iRand == 1:  # WWLW
                    i = map.plotNum(x, 6)
                    plotTypes[i] = PlotTypes.PLOT_LAND
                elif iRand == 2:  # WLWW
                    i = map.plotNum(x, 5)
                    plotTypes[i] = PlotTypes.PLOT_LAND
                else:  # LWWW
                    i = map.plotNum(x, 4)
                    plotTypes[i] = PlotTypes.PLOT_LAND


#    calc regional density
#  this calculation determines the probability of a tile at location x being desert, plains or hills
#  the map is broken into 4 regions: no feature (let map scrip decide), desert, plains, hills
#  the desert strength starts at 0 at tile x = 0 x width / 4 + 1  and increases linearly to maximum at tile x = 1 x width / 4
#    at which point it starts to decrease back to zero at x = 2 x width / 4
#  the plains strength starts at 0 at tile x = 1 x width / 4 + 1 and increases linearly to maximum at tile x = 2 x width / 4
#    at which point it starts to decrease back to zero at x = 3 x width / 4
#  the hills  strength starts at 0 at tile x = 2 x width / 4 + 1 and increases linearly to maximum at tile x = 3 x width / 4
#    at which point it starts to decrease back to zero at x = 4 x width / 4

#  the iRegionW (region weight) controls the overall strength of the regionality and is user controlled.
#  A setting of 0 means that no regionality takes place and the balance of the map script does what it does
#  A setting of weak (20) means that each tile has a maximum change of 20% of being adjusted, if not adjusted, then the map script does what it does
#  A setting of moderate (40) means that each tile has a maximum change of 40% of being adjusted, if not adjusted, then the map script does what it does
#  etc ...

#  Region Density
        Region_Template = [0.0, 30.0, 60.0, 90.0, 120.0]

        userRegionDensity = map.getCustomMapOption(1)
        iRegionW = Region_Template[userRegionDensity]
        iW4 = iNumPlotsX / 4

        iDesert = iRegionW * max(0, 1 - float(abs(x - 1 * iW4)) / float(iW4))
        iPlains = iDesert + iRegionW * max(
            0, 1 - float(abs(x - 2 * iW4)) / float(iW4))
        iHills = iPlains + iRegionW * max(
            0, 1 - float(abs(x - 3 * iW4)) / float(iW4))

        #    loop over land tiles and change to hill if required
        for y in range(4, 7):
            i = map.plotNum(x, y)

            if plotTypes[i] == PlotTypes.PLOT_LAND:
                iRand = dice.get(100, "Region Determination 1 - TBG PYTHON")
                if (iRand > iPlains and iRand <= iHills):
                    plotTypes[i] = PlotTypes.PLOT_HILLS

    return plotTypes
コード例 #7
0
	def generateSorensHintedPangaea(self):
		NiTextOut("Setting Plot Types (Python Pangaea) ...")
		global hinted_world
		hinted_world = HintedWorld(8,4)

		mapRand = CyGame().getMapRand()

		for y in range(hinted_world.h):
			for x in range(hinted_world.w):
				if x in (0, hinted_world.w-1) or y in (0, hinted_world.h-1):
					hinted_world.setValue(x,y,0)
				else:
					hinted_world.setValue(x,y,200 + mapRand.get(55, "Plot Types - Pangaea PYTHON"))

		hinted_world.setValue(1, 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		hinted_world.setValue(2 + mapRand.get(2, "Plot Types - Pangaea PYTHON"), 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		hinted_world.setValue(4 + mapRand.get(2, "Plot Types - Pangaea PYTHON"), 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		hinted_world.setValue(6, 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		if (mapRand.get(2, "Plot Types - Pangaea PYTHON") == 0):
			hinted_world.setValue(2, 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		else:
			hinted_world.setValue(5, 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))

		hinted_world.buildAllContinents()
		return hinted_world.generatePlotTypes(shift_plot_types=True)
コード例 #8
0
	def generateSorensHintedPangaea(self):
		NiTextOut("Setting Plot Types (Python Pangaea) ...")
		global hinted_world
		hinted_world = HintedWorld(8,4)

		mapRand = CyGlobalContext().getGame().getMapRand()

		for y in range(hinted_world.h):
			for x in range(hinted_world.w):
				if x in (0, hinted_world.w-1) or y in (0, hinted_world.h-1):
					hinted_world.setValue(x,y,0)
				else:
					hinted_world.setValue(x,y,200 + mapRand.get(55, "Plot Types - Pangaea PYTHON"))

		hinted_world.setValue(1, 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		hinted_world.setValue(2 + mapRand.get(2, "Plot Types - Pangaea PYTHON"), 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		hinted_world.setValue(4 + mapRand.get(2, "Plot Types - Pangaea PYTHON"), 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		hinted_world.setValue(6, 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		if (mapRand.get(2, "Plot Types - Pangaea PYTHON") == 0):
			hinted_world.setValue(2, 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))
		else:
			hinted_world.setValue(5, 1 + mapRand.get(3, "Plot Types - Pangaea PYTHON"), mapRand.get(64, "Plot Types - Pangaea PYTHON"))

		hinted_world.buildAllContinents()
		return hinted_world.generatePlotTypes(shift_plot_types=True)
コード例 #9
0
def generatePlotTypes():
	NiTextOut("Setting Plot Types (Python Team Battleground) ...")
	global hinted_world, mapRand
	global fractal_world
	gc = CyGlobalContext()
	map = CyMap()
	mapRand = gc.getGame().getMapRand()
	userInputPlots = map.getCustomMapOption(0)
	
	if userInputPlots == 2: # Four Corners
		hinted_world = HintedWorld()
		iNumPlotsX = map.getGridWidth()
		iNumPlotsY = map.getGridHeight()

		centery = (hinted_world.h - 1)//2
		centerx = (hinted_world.w - 1)//2
	
		iCenterXList = []
		iCenterXList.append(centerx-1)
		iCenterXList.append(centerx)
		iCenterXList.append(centerx+1)
	
		iCenterYList = []
		iCenterYList.append(centery-1)
		iCenterYList.append(centery)
		iCenterYList.append(centery+1)

		bridgey = centery

		# Set all blocks to land except a strip in the center
		for x in range(hinted_world.w):
			for y in range(hinted_world.h):
				if x == centerx:
					if y == bridgey:
						hinted_world.setValue(x,y,128) # coast
					else:
						hinted_world.setValue(x,y,0)
				else:
					hinted_world.setValue(x,y,255)
					if y in iCenterYList:
						hinted_world.setValue(x,y,128) # coast
					if y == centery:
						hinted_world.setValue(x,y,0) # ocean

		hinted_world.buildAllContinents()
		plotTypes = hinted_world.generatePlotTypes(20)
	
		# Remove any land bridge that exists
		centerplotx = (iNumPlotsX - 1)//2
		dx = 1
		for x in range(centerplotx-dx, centerplotx+dx+1):
			for y in range(iNumPlotsY):
				i = map.plotNum(x, y)
				if plotTypes[i] != PlotTypes.PLOT_OCEAN:
					plotTypes[i] = PlotTypes.PLOT_OCEAN
		centerploty = (iNumPlotsY - 1)//2
		dy = 1
		for y in range(centerploty-dy, centerploty+dy+1):
			for x in range(iNumPlotsX):
				i = map.plotNum(x, y)
				if plotTypes[i] != PlotTypes.PLOT_OCEAN:
					plotTypes[i] = PlotTypes.PLOT_OCEAN
		
		# Now add the bridge across the center!
		sizekey = map.getWorldSize()
		sizevalues = {
			WorldSizeTypes.WORLDSIZE_DUEL:		3,
			WorldSizeTypes.WORLDSIZE_TINY:		4,
			WorldSizeTypes.WORLDSIZE_SMALL:		5,
			WorldSizeTypes.WORLDSIZE_STANDARD:	6,
			WorldSizeTypes.WORLDSIZE_LARGE:		8,
			WorldSizeTypes.WORLDSIZE_HUGE:		10
			}
# Rise of Mankind 2.53
		if ( not sizekey in sizevalues ):
			shift = 12
		else:
			shift = sizevalues[sizekey]
			
# Rise of Mankind 2.53			
		linewidth = 3
		offsetstart = 0 - int(linewidth/2)
		offsetrange = range(offsetstart, offsetstart + linewidth)
		westX1, southY1, eastX1, northY1 = centerplotx - shift, centerploty - shift, centerplotx + shift, centerploty + shift
		westX2, southY2, eastX2, northY2 = centerplotx - shift, centerploty - shift, centerplotx + shift, centerploty + shift
		bridge_data = [[westX1, southY1, eastX1, northY1], [westX2, northY2, eastX2, southY2]]
		for bridge_loop in range(2):
			[startx, starty, endx, endy] = bridge_data[bridge_loop]

			if abs(endy-starty) < abs(endx-startx):
				# line is closer to horizontal
				if startx > endx:
					startx, starty, endx, endy = endx, endy, startx, starty # swap start and end
				dx = endx-startx
				dy = endy-starty
				if dx == 0 or dy == 0:
					slope = 0
				else:
					slope = float(dy)/float(dx)
				y = starty
				for x in range(startx, endx+1):
					for offset in offsetrange:
						if map.isPlot(x, int(round(y+offset))):
							i = map.plotNum(x, int(round(y+offset)))
							plotTypes[i] = PlotTypes.PLOT_LAND
					y += slope
			else:
				# line is closer to vertical
				if starty > endy:
					startx, starty, endx, endy = endx, endy, startx, starty # swap start and end
				dx, dy = endx-startx, endy-starty
				if dx == 0 or dy == 0:
					slope = 0
				else:
					slope = float(dx)/float(dy)
				x = startx
				for y in range(starty, endy+1):
					for offset in offsetrange:
						if map.isPlot(int(round(x+offset)), y):
							i = map.plotNum(int(round(x+offset)), y)
							plotTypes[i] = PlotTypes.PLOT_LAND
					x += slope
		
		return plotTypes

	if (userInputPlots == 4   # round
	or  userInputPlots == 5): # donut
		hinted_world = HintedWorld()
		iNumPlotsX = map.getGridWidth()
		iNumPlotsY = map.getGridHeight()

		centery = (iNumPlotsY - 1)//2
		centerx = (iNumPlotsX - 1)//2
		radii = centery - 1

		# Set all blocks to ocean except the inner circle
		for x in range(iNumPlotsX):
			for y in range(iNumPlotsY):
				dist_xy_c = sqrt( (x - centerx) ** 2 + (y - centery) ** 2)
				if dist_xy_c < radii:
					hinted_world.setValue(x,y,255)
				else:
					hinted_world.setValue(x,y,0) # ocean

		hinted_world.buildAllContinents()
		plotTypes = hinted_world.generatePlotTypes(water_percent = 0)

		if userInputPlots == 5: # donut
			# get the size of the hole
			map_size = map.getWorldSize()
			sizevalues = {
				WorldSizeTypes.WORLDSIZE_DUEL:		2,
				WorldSizeTypes.WORLDSIZE_TINY:		3,
				WorldSizeTypes.WORLDSIZE_SMALL:		4,
				WorldSizeTypes.WORLDSIZE_STANDARD:	5,
				WorldSizeTypes.WORLDSIZE_LARGE:		7,
				WorldSizeTypes.WORLDSIZE_HUGE:		8
				}
# Rise of Mankind 2.53
			if ( not map_size in sizevalues ):
				hole_radii = 9
			else:
				hole_radii = sizevalues[map_size]
# Rise of Mankind 2.53

		# Set all blocks to ocean except the inner circle
		for x in range(iNumPlotsX):
			for y in range(iNumPlotsY):
				i = map.plotNum(x, y)
				dist_xy_c = sqrt( (x - centerx) ** 2 + (y - centery) ** 2)
				if (dist_xy_c < radii):
					plotTypes[i] = PlotTypes.PLOT_LAND
				else:
					plotTypes[i] = PlotTypes.PLOT_OCEAN

				if (userInputPlots == 5 # donut
				and dist_xy_c < hole_radii):
					plotTypes[i] = PlotTypes.PLOT_OCEAN

		return plotTypes

	elif userInputPlots == 1: # Top vs Bottom
		fractal_world = FractalWorld(fracXExp=6, fracYExp=6)
		fractal_world.initFractal(continent_grain = 4, rift_grain = -1, has_center_rift = False, invert_heights = True)
		plot_types = fractal_world.generatePlotTypes(water_percent = 8)
		return plot_types

	else: # Left vs Right
		iNumPlotsX = map.getGridWidth()
		iNumPlotsY = map.getGridHeight()
	
		hinted_world = HintedWorld(4,2)
		centerx = (hinted_world.w - 1)//2	
		centery = (hinted_world.h - 1)//2
		bridgey = centery

		# set all blocks to land except a strip in the center
		for x in range(hinted_world.w):
			for y in range(hinted_world.h):
				if x == centerx:
					if y == bridgey:
						hinted_world.setValue(x,y,128) # coast
					else:
						hinted_world.setValue(x,y,0)
				else:
					hinted_world.setValue(x,y,255)
		
		hinted_world.buildAllContinents()
		plotTypes = hinted_world.generatePlotTypes(20)
	
		#fix any land bridge that exists
		centerplotx = (iNumPlotsX - 1)//2
		dx = 1
		for x in range(centerplotx-dx, centerplotx+dx+1):
			for y in range(iNumPlotsY):
				i = map.plotNum(x, y)
				if plotTypes[i] != PlotTypes.PLOT_OCEAN:
					plotTypes[i] = PlotTypes.PLOT_OCEAN

		if userInputPlots == 3: # Left v Right with bridge
			centerplotx = (iNumPlotsX)//2
			centerploty = (iNumPlotsY)//2
			dy = 1
			for x in range(iNumPlotsX):
				for y in range(centerploty-dy, centerploty+dy+1):
					i = map.plotNum(x, y)
					if plotTypes[i] == PlotTypes.PLOT_OCEAN:
						plotTypes[i] = PlotTypes.PLOT_LAND

		return plotTypes
コード例 #10
0
ファイル: Team_Battleground.py プロジェクト: AP-ML/DTM
def generatePlotTypes():
#	BugUtil.debug("Team_Battleground: generatePlotTypes")
	NiTextOut("Setting Plot Types (Python Team Battleground) ...")
	global hinted_world, mapRand
	global fractal_world
	gc = CyGlobalContext()
	map = CyMap()
	mapRand = gc.getGame().getMapRand()
	userInputPlots = map.getCustomMapOption(0)
	
	if userInputPlots == 2: # Four Corners
		hinted_world = HintedWorld()
		iNumPlotsX = map.getGridWidth()
		iNumPlotsY = map.getGridHeight()

		centery = (hinted_world.h - 1)//2
		centerx = (hinted_world.w - 1)//2
	
		iCenterXList = []
		iCenterXList.append(centerx-1)
		iCenterXList.append(centerx)
		iCenterXList.append(centerx+1)
	
		iCenterYList = []
		iCenterYList.append(centery-1)
		iCenterYList.append(centery)
		iCenterYList.append(centery+1)

		bridgey = centery

		# Set all blocks to land except a strip in the center
		for x in range(hinted_world.w):
			for y in range(hinted_world.h):
				if x == centerx:
					if y == bridgey:
						hinted_world.setValue(x,y,128) # coast
					else:
						hinted_world.setValue(x,y,0)
				else:
					hinted_world.setValue(x,y,255)
					if y in iCenterYList:
						hinted_world.setValue(x,y,128) # coast
					if y == centery:
						hinted_world.setValue(x,y,0) # ocean

		hinted_world.buildAllContinents()
		plotTypes = hinted_world.generatePlotTypes(20)
	
		# Remove any land bridge that exists
		centerplotx = (iNumPlotsX - 1)//2
		dx = 1
		for x in range(centerplotx-dx, centerplotx+dx+1):
			for y in range(iNumPlotsY):
				i = map.plotNum(x, y)
				if plotTypes[i] != PlotTypes.PLOT_OCEAN:
					plotTypes[i] = PlotTypes.PLOT_OCEAN
		centerploty = (iNumPlotsY - 1)//2
		dy = 1
		for y in range(centerploty-dy, centerploty+dy+1):
			for x in range(iNumPlotsX):
				i = map.plotNum(x, y)
				if plotTypes[i] != PlotTypes.PLOT_OCEAN:
					plotTypes[i] = PlotTypes.PLOT_OCEAN
		
		# Now add the bridge across the center!
		sizekey = map.getWorldSize()
		sizevalues = {
			WorldSizeTypes.WORLDSIZE_DUEL:		3,
			WorldSizeTypes.WORLDSIZE_TINY:		4,
			WorldSizeTypes.WORLDSIZE_SMALL:		5,
			WorldSizeTypes.WORLDSIZE_STANDARD:	6,
			WorldSizeTypes.WORLDSIZE_LARGE:		8,
			WorldSizeTypes.WORLDSIZE_HUGE:		10
			}
		shift = sizevalues[sizekey]
		linewidth = 3
		offsetstart = 0 - int(linewidth/2)
		offsetrange = range(offsetstart, offsetstart + linewidth)
		westX1, southY1, eastX1, northY1 = centerplotx - shift, centerploty - shift, centerplotx + shift, centerploty + shift
		westX2, southY2, eastX2, northY2 = centerplotx - shift, centerploty - shift, centerplotx + shift, centerploty + shift
		bridge_data = [[westX1, southY1, eastX1, northY1], [westX2, northY2, eastX2, southY2]]
		for bridge_loop in range(2):
			[startx, starty, endx, endy] = bridge_data[bridge_loop]

			if abs(endy-starty) < abs(endx-startx):
				# line is closer to horizontal
				if startx > endx:
					startx, starty, endx, endy = endx, endy, startx, starty # swap start and end
				dx = endx-startx
				dy = endy-starty
				if dx == 0 or dy == 0:
					slope = 0
				else:
					slope = float(dy)/float(dx)
				y = starty
				for x in range(startx, endx+1):
					for offset in offsetrange:
						if map.isPlot(x, int(round(y+offset))):
							i = map.plotNum(x, int(round(y+offset)))
							plotTypes[i] = PlotTypes.PLOT_LAND
					y += slope
			else:
				# line is closer to vertical
				if starty > endy:
					startx, starty, endx, endy = endx, endy, startx, starty # swap start and end
				dx, dy = endx-startx, endy-starty
				if dx == 0 or dy == 0:
					slope = 0
				else:
					slope = float(dx)/float(dy)
				x = startx
				for y in range(starty, endy+1):
					for offset in offsetrange:
						if map.isPlot(int(round(x+offset)), y):
							i = map.plotNum(int(round(x+offset)), y)
							plotTypes[i] = PlotTypes.PLOT_LAND
					x += slope
		
		return plotTypes

	if (userInputPlots == 4   # round
	or  userInputPlots == 5): # donut
		hinted_world = HintedWorld()
		iNumPlotsX = map.getGridWidth()
		iNumPlotsY = map.getGridHeight()

		centery = (iNumPlotsY - 1)//2
		centerx = (iNumPlotsX - 1)//2
		radii = centery - 1

		# Set all blocks to ocean except the inner circle
		for x in range(iNumPlotsX):
			for y in range(iNumPlotsY):
				dist_xy_c = sqrt( (x - centerx) ** 2 + (y - centery) ** 2)
				if dist_xy_c < radii:
					hinted_world.setValue(x,y,255)
				else:
					hinted_world.setValue(x,y,0) # ocean

		hinted_world.buildAllContinents()
		plotTypes = hinted_world.generatePlotTypes(water_percent = 0)

		if userInputPlots == 5: # donut
			# get the size of the hole
			map_size = map.getWorldSize()
			sizevalues = {
				WorldSizeTypes.WORLDSIZE_DUEL:		2,
				WorldSizeTypes.WORLDSIZE_TINY:		3,
				WorldSizeTypes.WORLDSIZE_SMALL:		4,
				WorldSizeTypes.WORLDSIZE_STANDARD:	5,
				WorldSizeTypes.WORLDSIZE_LARGE:		7,
				WorldSizeTypes.WORLDSIZE_HUGE:		8
				}
			hole_radii = sizevalues[map_size]

		# Set all blocks to ocean except the inner circle
		for x in range(iNumPlotsX):
			for y in range(iNumPlotsY):
				i = map.plotNum(x, y)
				dist_xy_c = sqrt( (x - centerx) ** 2 + (y - centery) ** 2)

#				if (dist_xy_c < radii):
#					if not (plotTypes[i] == PlotTypes.PLOT_LAND
#					and plotTypes[i] == PlotTypes.PLOT_PEAK
#					and plotTypes[i] == PlotTypes.PLOT_HILLS):
#						plotTypes[i] = PlotTypes.PLOT_LAND
#				else:
#					plotTypes[i] = PlotTypes.PLOT_OCEAN

				if (dist_xy_c >= radii):
					plotTypes[i] = PlotTypes.PLOT_OCEAN

				if (userInputPlots == 5 # donut
				and dist_xy_c < hole_radii):
					plotTypes[i] = PlotTypes.PLOT_OCEAN

		return plotTypes

	elif userInputPlots == 1: # Top vs Bottom
		fractal_world = FractalWorld(fracXExp=6, fracYExp=6)
		fractal_world.initFractal(continent_grain = 4, rift_grain = -1, has_center_rift = False, invert_heights = True)
		plot_types = fractal_world.generatePlotTypes(water_percent = 8)
		return plot_types

	else: # Left vs Right
		iNumPlotsX = map.getGridWidth()
		iNumPlotsY = map.getGridHeight()
	
		hinted_world = HintedWorld(4,2)
		centerx = (hinted_world.w - 1)//2	
		centery = (hinted_world.h - 1)//2
		bridgey = centery

		# set all blocks to land except a strip in the center
		for x in range(hinted_world.w):
			for y in range(hinted_world.h):
				if x == centerx:
					if y == bridgey:
						hinted_world.setValue(x,y,128) # coast
					else:
						hinted_world.setValue(x,y,0)
				else:
					hinted_world.setValue(x,y,255)
		
		hinted_world.buildAllContinents()
		plotTypes = hinted_world.generatePlotTypes(20)
	
		#fix any land bridge that exists
		centerplotx = (iNumPlotsX - 1)//2
		dx = 1
		for x in range(centerplotx-dx, centerplotx+dx+1):
			for y in range(iNumPlotsY):
				i = map.plotNum(x, y)
				if plotTypes[i] != PlotTypes.PLOT_OCEAN:
					plotTypes[i] = PlotTypes.PLOT_OCEAN

		if userInputPlots == 3: # Left v Right with bridge
			centerplotx = (iNumPlotsX)//2
			centerploty = (iNumPlotsY)//2
			dy = 1
			for x in range(iNumPlotsX):
				for y in range(centerploty-dy, centerploty+dy+1):
					i = map.plotNum(x, y)
					if plotTypes[i] == PlotTypes.PLOT_OCEAN:
						plotTypes[i] = PlotTypes.PLOT_LAND

		return plotTypes