Exemplo n.º 1
0
def tectonic_gen(heightmap, hor):
    tectonic_tiles = [[0 for y in range(WORLD_HEIGHT)]
                      for x in range(WORLD_WIDTH)]
    if hor == 1:
        pos = randint(WORLD_HEIGHT / 10, WORLD_HEIGHT - WORLD_HEIGHT / 10)
        for x in range(WORLD_WIDTH):
            tectonic_tiles[x][pos] = 1
            pos += randint(1, 5) - 3
            pos = min(max(0, pos), WORLD_HEIGHT - 1)

    if hor == 0:
        pos = randint(WORLD_WIDTH / 10, WORLD_WIDTH - WORLD_WIDTH / 10)
        for y in range(WORLD_HEIGHT):
            tectonic_tiles[pos][y] = 1
            pos += randint(1, 5) - 3
            pos = min(max(0, pos), WORLD_WIDTH - 1)

    for x in range(WORLD_WIDTH // 10, WORLD_WIDTH - WORLD_WIDTH // 10):
        for y in range(WORLD_HEIGHT // 10, WORLD_HEIGHT - WORLD_HEIGHT // 10):
            if tectonic_tiles[x][y] == 1 and tcod.heightmap_get_value(
                    heightmap, x, y) > 0.3:
                tcod.heightmap_add_hill(heightmap, x, y, randint(2, 4),
                                        uniform(0.15, 0.18))

    return heightmap
Exemplo n.º 2
0
def temperature(heightmap, temp):
    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            height_effect = 0
            if y > WORLD_HEIGHT / 2:
                tcod.heightmap_set_value(temp, x, y,
                                         WORLD_HEIGHT - y - height_effect)
            else:
                tcod.heightmap_set_value(temp, x, y, y - height_effect)
            height_effect = tcod.heightmap_get_value(heightmap, x, y)

            if height_effect > 0.8:
                height_effect *= 5
                if y > WORLD_HEIGHT / 2:
                    tcod.heightmap_set_value(temp, x, y,
                                             WORLD_HEIGHT - y - height_effect)
                else:
                    tcod.heightmap_set_value(temp, x, y, y - height_effect)

            if height_effect < 0.25:
                height_effect *= 10
                if y > WORLD_HEIGHT / 2:
                    tcod.heightmap_set_value(temp, x, y,
                                             WORLD_HEIGHT - y - height_effect)
                else:
                    tcod.heightmap_set_value(temp, x, y, y - height_effect)

    return heightmap, temp
Exemplo n.º 3
0
def TectonicGen(hm, hor):

    TecTiles = [[0 for y in range(WORLD_HEIGHT)] for x in range(WORLD_WIDTH)]

    # Define Tectonic Borders
    if hor == 1:
        pos = randint(WORLD_HEIGHT / 10, WORLD_HEIGHT - WORLD_HEIGHT / 10)
        for x in range(WORLD_WIDTH):
            TecTiles[x][pos] = 1
            pos += randint(1, 5) - 3
            if pos < 0:
                pos = 0
            if pos > WORLD_HEIGHT - 1:
                pos = WORLD_HEIGHT - 1
    if hor == 0:
        pos = randint(WORLD_WIDTH / 10, WORLD_WIDTH - WORLD_WIDTH / 10)
        for y in range(WORLD_HEIGHT):
            TecTiles[pos][y] = 1
            pos += randint(1, 5) - 3
            if pos < 0:
                pos = 0
            if pos > WORLD_WIDTH - 1:
                pos = WORLD_WIDTH - 1

    # Apply elevation to borders
    for x in range(int(WORLD_WIDTH / 10), WORLD_WIDTH - int(WORLD_WIDTH / 10)):
        for y in range(int(WORLD_HEIGHT / 10),
                       WORLD_HEIGHT - int(WORLD_HEIGHT / 10)):
            if TecTiles[x][y] == 1 and tcod.heightmap_get_value(hm, x,
                                                                y) > 0.3:
                tcod.heightmap_add_hill(hm, x, y, randint(2, 4),
                                        uniform(0.15, 0.18))

    return
Exemplo n.º 4
0
 def __getitem__(self, index):
     # Bounds checking?
     x, y = index
     assert x < self.width and y < self.height
     if type(x) is float and type(y) is float:
         return self.interpolated_value(x, y)
     else:
         return tcod.heightmap_get_value(self._data, x, y)
Exemplo n.º 5
0
 def __getitem__(self, index):
     # Bounds checking? Slices?
     x, y = index
     assert x < self.width and y < self.height
     if type(x) is float and type(y) is float:
         return tcod.heightmap_interpolated_value(self._data, x, y)
     else:
         return tcod.heightmap_get_value(self._data, x, y)
Exemplo n.º 6
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.º 7
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.º 8
0
def precipitation(precip_heightmap, temp_heightmap):
    precip_heightmap[:] += 2
    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            temp = tcod.heightmap_get_value(temp_heightmap, x, y)
    precipitation = tcod.noise_new(2, tcod.NOISE_DEFAULT_HURST,
                                   tcod.NOISE_DEFAULT_LACUNARITY)
    tcod.heightmap_add_fbm(precip_heightmap, precipitation, 2, 2, 0, 0, 32, 1,
                           1)
    tcod.heightmap_normalize(precip_heightmap, 0.0, 1.0)

    return precip_heightmap, temp_heightmap
Exemplo n.º 9
0
 def update(self):
     """Update the world's console buffer with current map data."""
     for x in range (0, self.width):
         for y in range (0, self.height):
             cell_value = tcod.heightmap_get_value(self.elevation, x, y)
             cell_value = int(cell_value * 127) + 127
             tcod.map_set_properties(self.map, x, y, (cell_value < 150), (cell_value < 150 and cell_value > 75))
             if not tcod.map_is_transparent(self.map, x, y):
                 cell_color = tcod.white
             elif not tcod.map_is_walkable(self.map, x, y):
                 cell_color = tcod.blue
             else:
                 cell_color = tcod.black
             tcod.console_set_char_background(self.console, x, y, cell_color)
Exemplo n.º 10
0
def Percipitaion(preciphm, temphm):

    tcod.heightmap_add(preciphm, 2)

    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            temp = tcod.heightmap_get_value(temphm, x, y)

    precip = tcod.noise_new(2, tcod.NOISE_DEFAULT_HURST,
                            tcod.NOISE_DEFAULT_LACUNARITY)

    # tcod.heightmap_add_fbm(preciphm,precip ,2, 2, 0, 0, 32, 1, 1)

    tcod.heightmap_normalize(preciphm, 0.0, 1.0)
Exemplo n.º 11
0
def MasterWorldGen():  # ------------------------------------------------------- * MASTER GEN * -------------------------------------------------------------

    print(" * World Gen START * ")
    starttime = time.time()

    # Heightmap
    hm = tcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)

    for i in range(250):
        tcod.heightmap_add_hill(
            hm,
            randint(WORLD_WIDTH / 10, WORLD_WIDTH - WORLD_WIDTH / 10),
            randint(WORLD_HEIGHT / 10, WORLD_HEIGHT - WORLD_HEIGHT / 10),
            randint(12, 16),
            randint(6, 10),
        )
    print("- Main Hills -")

    for i in range(1000):
        tcod.heightmap_add_hill(
            hm,
            randint(WORLD_WIDTH / 10, WORLD_WIDTH - WORLD_WIDTH / 10),
            randint(WORLD_HEIGHT / 10, WORLD_HEIGHT - WORLD_HEIGHT / 10),
            randint(2, 4),
            randint(6, 10),
        )
    print("- Small Hills -")

    tcod.heightmap_normalize(hm, 0.0, 1.0)

    noisehm = tcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    noise2d = tcod.noise_new(
        2, tcod.NOISE_DEFAULT_HURST, tcod.NOISE_DEFAULT_LACUNARITY
    )
    # tcod.heightmap_add_fbm(noisehm, noise2d,6, 6, 0, 0, 32, 1, 1)
    tcod.heightmap_normalize(noisehm, 0.0, 1.0)
    # tcod.heightmap_multiply_hm(hm, noisehm, hm)
    print("- Apply Simplex -")

    PoleGen(hm, 0)
    print("- South Pole -")

    PoleGen(hm, 1)
    print("- North Pole -")

    TectonicGen(hm, 0)
    TectonicGen(hm, 1)
    print("- Tectonic Gen -")

    tcod.heightmap_rain_erosion(hm, WORLD_WIDTH * WORLD_HEIGHT, 0.07, 0, 0)
    print("- Erosion -")

    tcod.heightmap_clamp(hm, 0.0, 1.0)

    # Temperature
    temp = tcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    Temperature(temp, hm)
    tcod.heightmap_normalize(temp, 0.0, 1.0)
    print("- Temperature Calculation -")

    # Precipitation

    preciphm = tcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    Percipitaion(preciphm, temp)
    tcod.heightmap_normalize(preciphm, 0.0, 1.0)
    print("- Percipitaion Calculation -")

    # Drainage

    drainhm = tcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    drain = tcod.noise_new(
        2, tcod.NOISE_DEFAULT_HURST, tcod.NOISE_DEFAULT_LACUNARITY
    )
    # tcod.heightmap_add_fbm(drainhm,drain ,2, 2, 0, 0, 32, 1, 1)
    tcod.heightmap_normalize(drainhm, 0.0, 1.0)
    print("- Drainage Calculation -")

    # VOLCANISM - RARE AT SEA FOR NEW ISLANDS (?) RARE AT MOUNTAINS > 0.9 (?) RARE AT TECTONIC BORDERS (?)

    elapsed_time = time.time() - starttime
    print(" * World Gen DONE *    in: ", elapsed_time, " seconds")

    # Initialize Tiles with Map values
    World = [[0 for y in range(WORLD_HEIGHT)] for x in range(WORLD_WIDTH)]
    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            World[x][y] = Tile(
                tcod.heightmap_get_value(hm, x, y),
                tcod.heightmap_get_value(temp, x, y),
                tcod.heightmap_get_value(preciphm, x, y),
                tcod.heightmap_get_value(drainhm, x, y),
                0,
            )

    print("- Tiles Initialized -")

    # Prosperity

    Prosperity(World)
    print("- Prosperity Calculation -")

    # Biome info to Tile

    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):

            if (
                World[x][y].precip >= 0.10
                and World[x][y].precip < 0.33
                and World[x][y].drainage < 0.5
            ):
                World[x][y].biomeID = 3
                if randint(1, 2) == 2:
                    World[x][y].biomeID = 16

            if World[x][y].precip >= 0.10 and World[x][y].precip > 0.33:
                World[x][y].biomeID = 2
                if World[x][y].precip >= 0.66:
                    World[x][y].biomeID = 1

            if (
                World[x][y].precip >= 0.33
                and World[x][y].precip < 0.66
                and World[x][y].drainage >= 0.33
            ):
                World[x][y].biomeID = 15
                if randint(1, 5) == 5:
                    World[x][y].biomeID = 5

            if (
                World[x][y].temp > 0.2
                and World[x][y].precip >= 0.66
                and World[x][y].drainage > 0.33
            ):
                World[x][y].biomeID = 5
                if World[x][y].precip >= 0.75:
                    World[x][y].biomeID = 6
                if randint(1, 5) == 5:
                    World[x][y].biomeID = 15

            if (
                World[x][y].precip >= 0.10
                and World[x][y].precip < 0.33
                and World[x][y].drainage >= 0.5
            ):
                World[x][y].biomeID = 16
                if randint(1, 2) == 2:
                    World[x][y].biomeID = 14

            if World[x][y].precip < 0.10:
                World[x][y].biomeID = 4
                if World[x][y].drainage > 0.5:
                    World[x][y].biomeID = 16
                    if randint(1, 2) == 2:
                        World[x][y].biomeID = 14
                if World[x][y].drainage >= 0.66:
                    World[x][y].biomeID = 8

            if World[x][y].height <= 0.2:
                World[x][y].biomeID = 0

            if World[x][y].temp <= 0.2 and World[x][y].height > 0.15:
                World[x][y].biomeID = randint(11, 13)

            if World[x][y].height > 0.6:
                World[x][y].biomeID = 9
            if World[x][y].height > 0.9:
                World[x][y].biomeID = 10

    print("- BiomeIDs Atributed -")

    # River Gen

    for x in range(1):
        RiverGen(World)
    print("- River Gen -")

    # Free Heightmaps
    tcod.heightmap_delete(hm)
    tcod.heightmap_delete(temp)
    tcod.heightmap_delete(noisehm)

    print(" * Biomes/Rivers Sorted *")

    return World