Exemplo n.º 1
0
def gen(rng, dim=(500, 150), num_mountain_ranges=5, num_guaranteed_paths=5, num_lakes=20, num_rivers=20, num_cities=20, num_forests=30, num_deserts=60, terrain_info=default_terrain_info):
	margin = int(dim[1] / 4)
	range_dist = int(dim[0] / (num_mountain_ranges + 1))
	max_point_offset = int(range_dist / 10)
	ending_point = clamp_point(dim, (int(range_dist / 2) + rng.randint(-max_point_offset, max_point_offset), rng.randint(margin, dim[1] - margin)))
	starting_point = clamp_point(dim, (dim[0] - int(range_dist / 2) + rng.randint(-max_point_offset, max_point_offset), rng.randint(margin, dim[1] - margin)))

	noise = tcod.noise.Noise(2, seed=rng)
	height = make_base_heightmap(dim, noise)
	height_pather = tcod.path.AStar(height)
	mountain_spines = carve_mountains(height, dim, num_mountain_ranges, height_pather, rng)
	lake_points = carve_lakes(height, dim, num_mountain_ranges, height_pather, rng)
	height[:] += 1
	smooth(height, dim, rng)

	norm_height = tcod.heightmap_new(*dim)
	tcod.heightmap_copy(height, norm_height)
	tcod.heightmap_normalize(norm_height, 0, 1)

	terrain = tilemap.Tilemap(dim, init=lambda _: things.desert)
	assign_base_terrain(terrain, norm_height, dim, terrain_info)
	make_forests(terrain, height, dim, num_forests, height_pather, rng)
	run_rivers(terrain, height, lake_points, dim, num_rivers, rng, max_x_offset=range_dist)
	walkability = make_walk_map(terrain, height, dim)
	walk_pather = tcod.path.AStar(walkability)
	make_guaranteed_paths(terrain, height, dim, starting_point, ending_point, num_guaranteed_paths, num_mountain_ranges, walk_pather, rng)
	make_deserts(terrain, height, dim, num_deserts, height_pather, rng)
	city_points = make_cities(terrain, dim, num_cities, rng, range_dist)
	make_roads(terrain, height, city_points, dim, walk_pather, rng)

	return terrain, starting_point, ending_point, city_points, mountain_spines
Exemplo n.º 2
0
def make_walk_map(terrain, height, dim, water_cost=100):
	walkability = tcod.heightmap_new(*dim)
	tcod.heightmap_copy(height, walkability)
	for x in range(dim[0]):
		for y in range(dim[1]):
			if terrain[x, y] == things.water:
				walkability[y, x] = water_cost
	return walkability
Exemplo n.º 3
0
def run_rivers(terrain, height, lake_points, dim, num_rivers, rng, max_x_offset):
	blocking = tcod.heightmap_new(*dim)
	tcod.heightmap_copy(height, blocking)
	pather = tcod.path.AStar(blocking, diagonal=100)
	for i in range(num_rivers):
		start = lake_points[rng.randint(0, len(lake_points) - 1)]
		end = clamp_point(dim, (max(0, min(dim[0], start[0] + rng.randint(-max_x_offset, max_x_offset))), rng.randint(0, dim[1] - 1)))
		left_source = False
		for x, y in pather.get_path(start[0], start[1], end[0], end[1]):
			if (terrain[x, y] == things.water and left_source) or terrain[x, y] == things.mountains:
				break
			if terrain[x, y] != things.water:
				left_source = True
			terrain[x, y] = things.water
			tcod.heightmap_dig_hill(blocking, x, y, 4, 100)
Exemplo n.º 4
0
def test_heightmap():
    hmap = libtcodpy.heightmap_new(16, 16)
    repr(hmap)
    noise = libtcodpy.noise_new(2)

    # basic operations
    libtcodpy.heightmap_set_value(hmap, 0, 0, 1)
    libtcodpy.heightmap_add(hmap, 1)
    libtcodpy.heightmap_scale(hmap, 1)
    libtcodpy.heightmap_clear(hmap)
    libtcodpy.heightmap_clamp(hmap, 0, 0)
    libtcodpy.heightmap_copy(hmap, hmap)
    libtcodpy.heightmap_normalize(hmap)
    libtcodpy.heightmap_lerp_hm(hmap, hmap, hmap, 0)
    libtcodpy.heightmap_add_hm(hmap, hmap, hmap)
    libtcodpy.heightmap_multiply_hm(hmap, hmap, hmap)

    # modifying the heightmap
    libtcodpy.heightmap_add_hill(hmap, 0, 0, 4, 1)
    libtcodpy.heightmap_dig_hill(hmap, 0, 0, 4, 1)
    libtcodpy.heightmap_rain_erosion(hmap, 1, 1, 1)
    libtcodpy.heightmap_kernel_transform(hmap, 3, [-1, 1, 0], [0, 0, 0],
                                    [.33, .33, .33], 0, 1)
    libtcodpy.heightmap_add_voronoi(hmap, 10, 3, [1,3,5])
    libtcodpy.heightmap_add_fbm(hmap, noise, 1, 1, 1, 1, 4, 1, 1)
    libtcodpy.heightmap_scale_fbm(hmap, noise, 1, 1, 1, 1, 4, 1, 1)
    libtcodpy.heightmap_dig_bezier(hmap, [0, 16, 16, 0], [0, 0, 16, 16],
                              1, 1, 1, 1)

    # read data
    libtcodpy.heightmap_get_value(hmap, 0, 0)
    libtcodpy.heightmap_get_interpolated_value(hmap, 0, 0)

    libtcodpy.heightmap_get_slope(hmap, 0, 0)
    libtcodpy.heightmap_get_normal(hmap, 0, 0, 0)
    libtcodpy.heightmap_count_cells(hmap, 0, 0)
    libtcodpy.heightmap_has_land_on_border(hmap, 0)
    libtcodpy.heightmap_get_minmax(hmap)

    libtcodpy.noise_delete(noise)
    libtcodpy.heightmap_delete(hmap)
Exemplo n.º 5
0
def test_heightmap():
    hmap = libtcodpy.heightmap_new(16, 16)
    repr(hmap)
    noise = libtcodpy.noise_new(2)

    # basic operations
    libtcodpy.heightmap_set_value(hmap, 0, 0, 1)
    libtcodpy.heightmap_add(hmap, 1)
    libtcodpy.heightmap_scale(hmap, 1)
    libtcodpy.heightmap_clear(hmap)
    libtcodpy.heightmap_clamp(hmap, 0, 0)
    libtcodpy.heightmap_copy(hmap, hmap)
    libtcodpy.heightmap_normalize(hmap)
    libtcodpy.heightmap_lerp_hm(hmap, hmap, hmap, 0)
    libtcodpy.heightmap_add_hm(hmap, hmap, hmap)
    libtcodpy.heightmap_multiply_hm(hmap, hmap, hmap)

    # modifying the heightmap
    libtcodpy.heightmap_add_hill(hmap, 0, 0, 4, 1)
    libtcodpy.heightmap_dig_hill(hmap, 0, 0, 4, 1)
    libtcodpy.heightmap_rain_erosion(hmap, 1, 1, 1)
    libtcodpy.heightmap_kernel_transform(hmap, 3, [-1, 1, 0], [0, 0, 0],
                                         [.33, .33, .33], 0, 1)
    libtcodpy.heightmap_add_voronoi(hmap, 10, 3, [1, 3, 5])
    libtcodpy.heightmap_add_fbm(hmap, noise, 1, 1, 1, 1, 4, 1, 1)
    libtcodpy.heightmap_scale_fbm(hmap, noise, 1, 1, 1, 1, 4, 1, 1)
    libtcodpy.heightmap_dig_bezier(hmap, [0, 16, 16, 0], [0, 0, 16, 16], 1, 1,
                                   1, 1)

    # read data
    libtcodpy.heightmap_get_value(hmap, 0, 0)
    libtcodpy.heightmap_get_interpolated_value(hmap, 0, 0)

    libtcodpy.heightmap_get_slope(hmap, 0, 0)
    libtcodpy.heightmap_get_normal(hmap, 0, 0, 0)
    libtcodpy.heightmap_count_cells(hmap, 0, 0)
    libtcodpy.heightmap_has_land_on_border(hmap, 0)
    libtcodpy.heightmap_get_minmax(hmap)

    libtcodpy.noise_delete(noise)
    libtcodpy.heightmap_delete(hmap)
Exemplo n.º 6
0
 def copy(self):
     nhm = Heightmap(self.width, self.height)
     tcod.heightmap_copy(self._data, nhm._data)
     return nhm
Exemplo n.º 7
0
 def copy(self):
     h_new = Heightmap(self.width, self.height)
     tcod.heightmap_copy(self._data, h_new._data)
     return h_new