Esempio n. 1
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 xrange(WORLD_WIDTH / 10, WORLD_WIDTH - WORLD_WIDTH / 10):
        for y in xrange(WORLD_HEIGHT / 10, WORLD_HEIGHT - WORLD_HEIGHT / 10):
            if TecTiles[x][y] == 1 and libtcod.heightmap_get_value(hm, x,
                                                                   y) > 0.25:
                libtcod.heightmap_add_hill(hm, x, y, randint(2, 4),
                                           uniform(0.15, 0.18))

    return
Esempio n. 2
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 xrange(WORLD_WIDTH/10,WORLD_WIDTH - WORLD_WIDTH/10):
        for y in xrange(WORLD_HEIGHT/10,WORLD_HEIGHT - WORLD_HEIGHT/10):
                if TecTiles[x][y] == 1 and libtcod.heightmap_get_value(hm, x, y) > 0.25:
                    libtcod.heightmap_add_hill(hm, x, y, randint(2,4), uniform(0.15,0.18))                        

    return
Esempio n. 3
0
def addHill(hm,nbHill,baseRadius,radiusVar,height) :
    for i in range(nbHill) :
        hillMinRadius=baseRadius*(1.0-radiusVar)
        hillMaxRadius=baseRadius*(1.0+radiusVar)
        radius = libtcod.random_get_float(rnd,hillMinRadius, hillMaxRadius)
        theta = libtcod.random_get_float(rnd,0.0, 6.283185) # between 0 and 2Pi
        dist = libtcod.random_get_float(rnd,0.0, float(min(HM_WIDTH,HM_HEIGHT))/2 - radius)
        xh = int(HM_WIDTH/2 + math.cos(theta) * dist)
        yh = int(HM_HEIGHT/2 + math.sin(theta) * dist)
        libtcod.heightmap_add_hill(hm,float(xh),float(yh),radius,height)
Esempio n. 4
0
    def add_hill(self, x, y):
        r = 5
        xh = self.w
        yh = self.h

        one = (x - xh) * (x - xh)
        two = (y - yh) * (y - yh)

        hill_height = ((r * r) + one + two) / 4

        if hill_height > 0:
            libtcod.heightmap_add_hill(self.hm, x, y, 10, 20)
            libtcod.heightmap_normalize(self.hm, 0, 255)
Esempio n. 5
0
	def add_landmass(self):
		print 'Creating landmass....'
		t0 = libtcod.sys_elapsed_seconds()
		for i in range(int(game.WORLDMAP_WIDTH * 0.55)):
			radius = self.randomize('float', 50 * (1.0 - 0.7), 50 * (1.0 + 0.7), 3)
			x = self.randomize('int', 0, game.WORLDMAP_WIDTH, 3)
			y = self.randomize('int', 0, game.WORLDMAP_HEIGHT, 3)
			libtcod.heightmap_add_hill(game.heightmap, x, y, radius, 0.3)
		libtcod.heightmap_normalize(game.heightmap)
		libtcod.heightmap_add_fbm(game.heightmap, self.noise, 6.5, 6.5, 0, 0, 8.0, 1.0, 4.0)
		libtcod.heightmap_normalize(game.heightmap)
		t1 = libtcod.sys_elapsed_seconds()
		print '    done! (%.3f seconds)' % (t1 - t0)
Esempio n. 6
0
 def add_hill(self,x,y):
     r = 5
     xh = self.w
     yh = self.h
     
     one = (x - xh )*(x - xh )
     two = (y - yh)*(y - yh)
     
     hill_height = ((r*r) + one + two)/4
     
     if hill_height > 0:
         libtcod.heightmap_add_hill(self.hm, x, y, 10, 20)
         libtcod.heightmap_normalize(self.hm, 0, 255)
Esempio 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)
Esempio n. 8
0
 def randomizeHeightmap(self) :
   print "Setting up heightmap"
   hills = 1000
   hillSize = 7
   
   halfX = self.width / 2
   halfY = self.height / 2
   libtcod.heightmap_clear(self._hm)
   for i in range(hills) :
     size = random.randint(0,hillSize)
     
     hillX1 = random.randint(0,halfX - hillSize / 2)
     hillY1 = random.randint(0,self.height)
     
     hillX2 = random.randint(halfX + hillSize / 2, self.width)
     hillY2 = random.randint(0,self.height)
     
     libtcod.heightmap_add_hill(self._hm,hillX1, hillY1, size, size)
     libtcod.heightmap_add_hill(self._hm,hillX2, hillY2, size, size)
   
   libtcod.heightmap_normalize(self._hm, 0.0, 2.0)
Esempio n. 9
0
def MasterWorldGen(
):  #------------------------------------------------------- * MASTER GEN * -------------------------------------------------------------

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

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

    for i in range(50):
        libtcod.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(200):
        libtcod.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 -'

    libtcod.heightmap_normalize(hm, 0.0, 1.0)

    noisehm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    noise2d = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                                libtcod.NOISE_DEFAULT_LACUNARITY)
    libtcod.heightmap_add_fbm(noisehm, noise2d, 4, 4, 0, 0, 32, 1, 1)
    libtcod.heightmap_normalize(noisehm, 0.0, 1.0)
    libtcod.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 -'

    libtcod.heightmap_rain_erosion(hm, WORLD_WIDTH * WORLD_HEIGHT, 0.07, 0, 0)
    print '- Erosion -'

    libtcod.heightmap_clamp(hm, 0.0, 1.0)

    #Temperature
    temp = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    Temperature(temp, hm)
    libtcod.heightmap_normalize(temp, 0.0, 0.8)
    print '- Temperature Calculation -'

    #Precipitation

    preciphm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    Percipitaion(preciphm, temp)
    libtcod.heightmap_normalize(preciphm, 0.0, 0.8)
    print '- Percipitaion Calculation -'

    #Drainage

    drainhm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    drain = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                              libtcod.NOISE_DEFAULT_LACUNARITY)
    libtcod.heightmap_add_fbm(drainhm, drain, 2, 2, 0, 0, 32, 1, 1)
    libtcod.heightmap_normalize(drainhm, 0.0, 0.8)
    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)]  #100x100 array
    for x in xrange(WORLD_WIDTH):
        for y in xrange(WORLD_HEIGHT):
            World[x][y] = Tile(libtcod.heightmap_get_value(hm, x, y),
                               libtcod.heightmap_get_value(temp, x, y),
                               libtcod.heightmap_get_value(preciphm, x, y),
                               libtcod.heightmap_get_value(drainhm, x, y), 0)

    print '- Tiles Initialized -'

    #Prosperity

    Prosperity(World)
    print '- Prosperity Calculation -'

    #Biome info to Tile

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

            if World[x][y].height > 0.2:
                World[x][y].biomeID = 3
                if randint(1, 10) < 3:
                    World[x][y].biomeID = 5
            if World[x][y].height > 0.4:
                World[x][y].biomeID = 14
                if randint(1, 10) < 3:
                    World[x][y].biomeID = 5
            if World[x][y].height > 0.5:
                World[x][y].biomeID = 8
                if randint(1, 10) < 3:
                    World[x][y].biomeID = 14

            if World[x][y].temp <= 0.5 and World[x][y].precip >= 0.5:
                World[x][y].biomeID = 5
                if randint(1, 10) < 3:
                    World[x][y].biomeID = 14
            if World[x][y].temp >= 0.5 and World[x][y].precip >= 0.7:
                World[x][y].biomeID = 6

            if World[x][y].precip >= 0.7 and World[x][
                    y].height > 0.2 and World[x][y].height <= 0.4:
                World[x][y].biomeID = 2

            if World[x][y].temp > 0.75 and World[x][y].precip < 0.35:
                World[x][y].biomeID = 4

            if World[x][y].temp <= 0.22 and World[x][y].height > 0.2:
                World[x][y].biomeID = randint(11, 13)
            if World[x][y].temp <= 0.3 and World[x][y].temp > 0.2 and World[x][
                    y].height > 0.2 and World[x][y].precip >= 0.6:
                World[x][y].biomeID = 7

            if World[x][y].height > 0.75:
                World[x][y].biomeID = 9
            if World[x][y].height > 0.999:
                World[x][y].biomeID = 10
            if World[x][y].height <= 0.2:
                World[x][y].biomeID = 0
            if World[x][y].height <= 0.1:
                World[x][y].biomeID = 0

    print '- BiomeIDs Atributed -'

    #River Gen

    for x in range(5):
        RiverGen(World)
    print '- River Gen -'

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

    print ' * Biomes/Rivers Sorted *'

    return World
def generateHeightmap(_map):
    print("Particle Deposition Generation...")

    _rand = tcod.random_get_instance()
    _hm = tcod.heightmap_new(_map.width, _map.height)

    #half-width and -height
    _hw = _map.width / 2
    _hh = _map.height / 2

    #quarter-width and -height
    _qw = _map.width / 4
    _qh = _map.height / 4

    #define our four "continental centers"
    _continents = [
        (_qw, _qh),  #top-left
        (_map.width - _qw, _qh),  #top-right
        (_qw, _map.height - _qh),  #btm-left
        (_map.width - _qw, _map.height - _qh)
    ]  #btm-right

    print("Continents:", _continents)

    _avg = min(_map.width, _map.height)

    _maxHillHeight = _avg / 4
    _maxHillRad = _avg / 8
    _iterations = _avg * 32

    for i in range(0, _iterations):

        _quadrant = tcod.random_get_int(_rand, 0, 3)

        _qx = _continents[_quadrant][0]
        _qy = _continents[_quadrant][1]

        _minX = _qx - ((_qw * CONT_SIZE) / 10)
        _maxX = _qx + ((_qw * CONT_SIZE) / 10)

        _minY = _qy - _qh
        _maxY = _qy + _qh

        x = tcod.random_get_int(_rand, _minX, _maxX)
        y = tcod.random_get_int(_rand, _minY, _maxY)

        height = tcod.random_get_int(_rand, -1 * _maxHillHeight,
                                     _maxHillHeight)
        rad = tcod.random_get_int(_rand, 0, _maxHillRad)

        tcod.heightmap_add_hill(_hm, x, y, rad, height)

    #"dig out" the space  around the edge of the map
    x = _hw
    for y in range(0, _map.height, max(1, _maxHillRad / 8)):

        height = tcod.random_get_int(_rand, _maxHillHeight / -2,
                                     -1 * _maxHillHeight)
        rad = tcod.random_get_int(_rand, 0, _maxHillRad * 2)

        tcod.heightmap_add_hill(_hm, 0, y, rad, height)
        tcod.heightmap_add_hill(_hm, _map.width - 1, y, rad, height)

    for x in range(0, _map.width, max(1, _maxHillRad / 4)):

        height = tcod.random_get_int(_rand, _maxHillHeight / -2,
                                     -1 * _maxHillHeight)
        rad = tcod.random_get_int(_rand, 0, _maxHillRad * 2)

        tcod.heightmap_add_hill(_hm, x, 0, rad, height)
        tcod.heightmap_add_hill(_hm, x, _map.height - 1, rad, height)

    tcod.heightmap_rain_erosion(
        _hm,
        _map.width * _map.height,  #number of raindrops
        0.2,  #erosion cooef (f)
        0.2)  #sediment cooef (f)

    _dx = [-2, -1, 0, 1, 2]
    _dy = [-2, -1, 0, 1, 2]
    _weight = [0.1, 0.1, 0.2, 0.3, 0.3]

    tcod.heightmap_kernel_transform(_hm, 5, _dx, _dy, _weight, -64, 255)

    tcod.heightmap_normalize(_hm, -255, 392)
    for y in range(0, _map.height):
        for x in range(0, _map.width):
            _map.coords[x][y].setAltitude(tcod.heightmap_get_value(_hm, x, y))

    return True
Esempio n. 11
0
def MasterWorldGen():    #------------------------------------------------------- * MASTER GEN * -------------------------------------------------------------

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

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

    for i in range(50):
        libtcod.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(200):
        libtcod.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 -'

    libtcod.heightmap_normalize(hm, 0.0, 1.0)

    noisehm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    noise2d = libtcod.noise_new(2,libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
    libtcod.heightmap_add_fbm(noisehm, noise2d,4, 4, 0, 0, 64, 1, 1)
    libtcod.heightmap_normalize(noisehm, 0.0, 1.0)
    libtcod.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 -'

    libtcod.heightmap_rain_erosion(hm, WORLD_WIDTH*WORLD_HEIGHT ,0.07,0,0)
    print '- Erosion -'

    libtcod.heightmap_clamp(hm, 0.0, 1.0)
      
    #Temperature
    temp = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)   
    Temperature(temp,hm)
    libtcod.heightmap_normalize(temp, 0.0, 0.8)
    print '- Temperature Calculation -'     

    #Precipitation

    preciphm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    Percipitaion(preciphm)
    libtcod.heightmap_normalize(preciphm, 0.0, 0.8)
    print '- Percipitaion Calculation -'  
      
    # VOLCANISM - RARE AT SEA FOR NEW ISLANDS (?) RARE AT MOUNTAINS > 0.9 (?) RARE AT TECTONIC BORDERS (?)

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

    print '- Tiles Initialized -'

    # - Biome info to Tiles -

    for x in xrange(WORLD_WIDTH):
        for y in xrange(WORLD_HEIGHT):
            
            if World[x][y].height > 0.2:
                World[x][y].biomeID = 3
                if randint(1,10) < 3:
                    World[x][y].biomeID = 5
            if World[x][y].height > 0.4:
                World[x][y].biomeID = 14
                if randint(1,10) < 3:
                    World[x][y].biomeID = 5
            if World[x][y].height > 0.5:
                World[x][y].biomeID = 8
                if randint(1,10) < 3:
                    World[x][y].biomeID = 14

            if World[x][y].temp <= 0.5 and World[x][y].precip >= 0.5:
                World[x][y].biomeID = 5
                if randint(1,10) < 3:
                    World[x][y].biomeID = 14
            if World[x][y].temp >= 0.5 and World[x][y].precip >= 0.7:
                World[x][y].biomeID = 6

            if World[x][y].precip >= 0.7 and World[x][y].height > 0.2 and World[x][y].height <= 0.4:
                World[x][y].biomeID = 2

            if World[x][y].temp > 0.75 and World[x][y].precip < 0.35:
                World[x][y].biomeID = 4

            if World[x][y].temp <= 0.22 and World[x][y].height > 0.2:
                World[x][y].biomeID = randint(11,13)
            if World[x][y].temp <= 0.3 and World[x][y].temp > 0.2 and World[x][y].height > 0.2 and World[x][y].precip >= 0.6:
                World[x][y].biomeID = 7
                  
            if World[x][y].height > 0.75:
                World[x][y].biomeID = 9
            if World[x][y].height > 0.999:
                World[x][y].biomeID = 10                  
            if World[x][y].height <= 0.2:
                World[x][y].biomeID = 0
            if World[x][y].height <= 0.1:
                World[x][y].biomeID = 0                  

    print '- BiomeIDs Atributed -'
      
    #River Gen
      
    for x in range(2):
        RiverGen(hm, World)
    print '- River Gen -'

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

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

    return World