コード例 #1
0
def listTerritories():
	print("Extracting territories...")
	territories = {}
	def addTerritory(value):
		if value in territories.keys():
			territories[value] += 1
		else:
			territories[value] = 1

	for ix in range(world.worldSize):
		for iy in range(world.worldSize):
			if (world.getPos(ix,iy).territory == None):
				addTerritory(-1)
			else:
				addTerritory(world.getPos(ix,iy).territory)

	chosenNames = []
	for key, val in territories.items():
		if key == -1:
			print("Ocean;{}".format(val))
		else:
			name = namegen.getRandomName()
			while(name in chosenNames):
				name = namegen.getRandomName()
			l = datatypes.LandMass(key, val, name)
			chosenNames.append(name)
			print("{};{}".format(name, val))
			world.addLandmass(l)
	
	print("Total territories -- {}".format(len(territories) - 1))
	print("Saving world...")
	world.save()
コード例 #2
0
def main(transferToWorld, filename="map.png", save=False, worldseed=None):
    global seed
    print("Creating base world... This might take a few minutes.")
    if worldseed == None:
        generateNewSeed()
    else:
        print("setting seed manually")
        seed = worldseed
    print("seed = " + str(seed))
    createWorld()

    # print("Creating rivers...")
    # createRivers()				# They look awful!! :(

    worldmap = ""
    print("Transforming world to string...")
    for iy in range(pworldSize):
        for ix in range(pworldSize):
            worldmap += getPiece(ix, iy).getEmoji()
        worldmap += "\n"

    worldmap.rstrip("\n")

    print("Transforming string to image...")
    worldToImage.represent(worldmap,
                           modutil.absolutePath + "/" + filename,
                           cellSize=1)

    if not transferToWorld: return

    print("Importing world modules...")
    from modules.rpgsrc import world, worldgen

    print("Importing datatype modules...")
    from modules.rpgsrc import datatypes, typeloader

    print("Loading datatypes...")
    typeloader.loadAll()

    print("Clearing world...")
    worldgen.clearWorld()

    print("Transferring pworld to world...")
    for p in pworld:
        world.getPos(p.x, p.y).stype = Piece.conversionType[p.type]
        world.getPos(p.x, p.y).x = p.x
        world.getPos(p.x, p.y).y = p.y

    print("Checking if successful...")
    if world.getPos(0, 0).stype != None:
        print("Was successful!")
    else:
        raise Exception("Something didn't work!")
    print("Saving world...")
    world.save()

    print("Finished!")
コード例 #3
0
maxRecursion = 50 if prgArgs.max_recursion == None else prgArgs.max_recursion
maxChildren = 1000 if prgArgs.max_recursion == None else prgArgs.max_recursion
maxBifurcations = 3 if prgArgs.max_bifurcations == None else prgArgs.max_bifurcations
maxMultitudeForMaxRecursion = 1000 if prgArgs.max_multitude_for_recursion == None else prgArgs.max_multitude_for_recursion
recursionSlices = 10 if prgArgs.recursion_slices == None else prgArgs.recursion_slices

if(prgArgs.reset_all):
	world.loadAll()
	for iy in tqdm(range(world.worldSize), desc="Resetting all locations"):
		for ix in range(world.worldSize):
			world.getPos(ix,iy).locationConnected = None

	for l in tqdm(world.landmasses, desc="Resetting landmasses' location count"):
		l.nOfLocations = 0

	world.save()

if(prgArgs.reset_recursive):
	world.loadAll()
	for iy in tqdm(range(world.worldSize), desc="Resetting recursive locations"):
		for ix in range(world.worldSize):
			if world.getPos(ix,iy).locationConnected != None:
				world.getPos(ix,iy).locationConnected.connections = []
	
	world.save()

if(prgArgs.generate_surface_locations):
	allPositionsOkay = []
	positionsOkay = []

	for iy in tqdm(range(world.worldSize), desc = "Creating positionsOkay"):
コード例 #4
0
def calculateTerritories():
	print("Initializing territory values...")
	for ix in range(world.worldSize):
		for iy in range(world.worldSize):
			world.getPos(ix,iy).territory = None

	def startFillingTerritory(biome, replacement : int):
		if biome.territory != None:
			return False

		if biome.stype == "OCEAN":
			return False

		biome.territory = replacement
	
		queue = [biome]

		while len(queue) > 0:
			n = queue.pop(0)
			for ix in [n.x - 1, n.x, n.x + 1]:
				for iy in [n.y - 1, n.y, n.y + 1]:
					if ix == n.x and iy == n.y:
						continue

					if world.isPositionValid(ix, iy):
						p = world.getPos(ix, iy)
						if p.territory != None:
							continue
						if p.stype != "OCEAN":
							p.territory = replacement
							queue.append(p)
		return True

	print("Defining territories...")
	t = 1
	for ix in range(world.worldSize):
		for iy in range(world.worldSize):
			if startFillingTerritory(world.getPos(ix, iy), t):
				t+=1

		if ix % 5 == 0:
			print("{}% complete, territories: {}".format(int(ix / world.worldSize * 100), t-1))

	print("Converting world to list...")
	worldmap = []
	for iy in range(world.worldSize):
		worldmap.append([])
		for ix in range(world.worldSize):
				worldmap[iy].append(0 if world.getPos(ix,iy).territory == None else world.getPos(ix,iy).territory)


	print("Defining palette...")
	palette = [(0,0,0)]
	for i in range(1, 100):
		palette.append(((i*21) % 0xff, (i * 7) % 0xff, (i * 29) % 0xff))

	print("Converting to image...")
	worldToImage.representCustom(worldmap, modutil.absolutePath + "/mapland.png", palette)

	print("Saving world...")
	world.save()

	print("Finished!")