Ejemplo n.º 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()
Ejemplo n.º 2
0
def placeLocation(x : int, y : int):
	global positionsOkay

	biome = world.getPos(x, y)
	biome.locationConnected = Location(random.choice(biome.getType().possibleLocations).systemName, biome, None)

	for ix in range(x + 1, world.worldSize):
		if world.getPos(ix, y).getType().systemName == "OCEAN":
			break
		setOkay(True, ix, y)

	for ix in range(x - 1, 0, -1):
		if world.getPos(ix, y).getType().systemName == "OCEAN":
			break
		setOkay(True, ix, y)

	for iy in range(y + 1, world.worldSize):
		if world.getPos(x, iy).getType().systemName == "OCEAN":
			break
		setOkay(True, x, iy)

	for iy in range(y - 1, 0, -1):
		if world.getPos(x, iy).getType().systemName == "OCEAN":
			break
		setOkay(True, x, iy)
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!")
Ejemplo n.º 4
0
		def f(lm): # Neccesary because we want to break out from a nested loop
			for i in tqdm(range(int(lm.size * locationDensity)), desc="Landmass #{}".format(lm.id)):
				x,y = getRandomPosFromPositionsOkay()
				if x == None:
					continue
				while len(world.getPos(x, y).getType().possibleLocations) == 0 or world.getPos(x, y).locationConnected != None:
					x,y = getRandomPosFromPositionsOkay()
					if x == None:
						break
				if x == None:
					continue
				placeLocation(x, y)
				lm.nOfLocations+=1
Ejemplo n.º 5
0
	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
Ejemplo n.º 6
0
prgArgs = parser.parse_args(sys.argv[1:])

locationDensity = 0.01 if prgArgs.location_density == None else prgArgs.location_density
locationRange = 2 if prgArgs.location_range == None else prgArgs.location_range
maxRandomTries = 10000 if prgArgs.random_tries == None else prgArgs.random_tries
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()
Ejemplo n.º 7
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!")
from modules.rpgsrc import world, typeloader, worldToImage
from libs import modutil

typeloader.loadAll()
world.loadAll()

worldmap = ""
print("Transforming world to string...")
for iy in range(world.worldSize):
	for ix in range(world.worldSize):
		if world.getPos(ix,iy).getType() == None:
			worldmap+="X"
		else:
			worldmap += world.getPos(ix,iy).getType().emoji
	worldmap += "\n"
		
worldmap.rstrip("\n")
	
print("Transforming string to image...")
worldToImage.represent(worldmap, modutil.absolutePath + "/map.png", cellSize=1)

print("Finished!")