Example #1
0
 def add_noise(self):
     libtcod.heightmap_normalize(self.hm, 0, 1)
     self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                                    libtcod.NOISE_DEFAULT_LACUNARITY)
     libtcod.noise_set_type(self.noise, libtcod.NOISE_PERLIN)
     libtcod.heightmap_add_fbm(self.hm, self.noise, 1, 1, 1, 1, 8, 0.5, 0.5)
     libtcod.heightmap_normalize(self.hm, 0, 255)
Example #2
0
	def generate(self):
		print 'Starting world map generation....'
		t0 = libtcod.sys_elapsed_seconds()
		accepted = False
		world = 1
		while not accepted:
			print 'World #' + str(world) + '....'
			self.noise = libtcod.noise_new(2, self.rnd)
			libtcod.noise_set_type(self.noise, libtcod.NOISE_PERLIN)
			game.heightmap = libtcod.heightmap_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
			#game.precipitation = libtcod.heightmap_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
			#game.temperature = libtcod.heightmap_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
			#game.biome = libtcod.heightmap_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)

			self.add_landmass()
			self.smooth_edges()
			self.set_landmass(self.randomize('float', 0.30, 0.45, 3), self.sandheight)
			self.add_rivers()
			self.create_map_images()
			self.place_dungeons()
			accepted = self.analyse_world()
			world += 1
			print '-------------'
		t1 = libtcod.sys_elapsed_seconds()
		print 'World map generation finished.... (%.3f seconds)' % (t1 - t0)
Example #3
0
def test_noise():
    noise = libtcodpy.noise_new(1)
    libtcodpy.noise_set_type(noise, libtcodpy.NOISE_SIMPLEX)
    libtcodpy.noise_get(noise, [0])
    libtcodpy.noise_get_fbm(noise, [0], 4)
    libtcodpy.noise_get_turbulence(noise, [0], 4)
    libtcodpy.noise_delete(noise)
Example #4
0
def make_map():
    global map, objects
 
    #the list of objects with just the player
    objects = [player]
    player.x = MAP_WIDTH / 2
    player.y = MAP_HEIGHT / 2
 
    myrng = libtcod.random_new(123)
    noise2d = libtcod.noise_new(2,libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY, myrng)
    libtcod.noise_set_type(noise2d, libtcod.NOISE_PERLIN)

    #fill map with "normal" tiles
    map = [[Tile(False, libtcod.light_gray)
        for y in range(MAP_HEIGHT)]
            for x in range(MAP_WIDTH)]

    #add color
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            value = int((libtcod.noise_get_fbm(noise2d,[x/float(MAP_WIDTH),y/float(MAP_HEIGHT)],32) + 1) * 96 )
            map[x][y] = Tile(False, libtcod.Color(value,value,value))

    r = [libtcod.random_get_int(0, CRATER_MIN_SIZE, (CRATER_MIN_SIZE + (CRATER_MAX_SIZE - CRATER_MIN_SIZE) * (MAX_CRATERS - i)**2/(MAX_CRATERS**2)) ) for i in range(MAX_CRATERS)]
    r.sort(reverse=True)
    for i in range(MAX_CRATERS):
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - 1)
        # r = libtcod.random_get_int(0, CRATER_MIN_SIZE, (CRATER_MIN_SIZE + (CRATER_MAX_SIZE - CRATER_MIN_SIZE) * (MAX_CRATERS - i)/MAX_CRATERS) )
        make_crater(x, y, r[i])

    spawn_silicon(noise2d)
Example #5
0
 def __init__(self, w, h):
     global TROPICS_THRESHOLD, TEMPERATE_THRESHOLD, TAIGA_THRESHOLD
     
     self.w = w
     self.h = h
     
     self.equator = h/2
     TROPICS_THRESHOLD = (self.equator/2)/3
     TEMPERATE_THRESHOLD = self.equator/2
     TAIGA_THRESHOLD = self.equator - self.equator*0.1
     self.tiles = [[ Tile(ix,iy, False, map_tile=True)
         for iy in range(h) ]
             for ix in range(w)]
     x,y = 0,0
     self.traffic = [[0
                      for y in range(h)]
                         for x in range(w)]
     #this holds the *colour* value of the tiles temps.
     self.temperature_map = [[0
                      for y in range(h)]
                         for x in range(w)]
     self.moisture_map = [[0
                      for y in range(h)]
                         for x in range(w)]
     
     self.hm = libtcod.heightmap_new(self.w, self.h)
     self.hm2 = libtcod.heightmap_new(self.w, self.h)
     self.hm3 = libtcod.heightmap_new(self.w, self.h)
     
     self.generate_land(self.hm)
     self.generate_land(self.hm2)
     self.generate_land(self.hm3)
     
     libtcod.noise_set_type(self.noise, libtcod.NOISE_SIMPLEX)
     self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
     #libtcod.heightmap_add_fbm(self.hm3, self.noise, 1, 1, 0, 0, 8, 0.8, 0.5)
     #self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
     #libtcod.heightmap_add_fbm(self.hm3, self.noise, 1, 1, 0, 0, 8, 0.8, 0.5)
     #self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
     #libtcod.heightmap_add_fbm(self.hm3, self.noise, 1, 1, 0, 0, 8, 0.8, 0.5)
     self.multiply_noise()
     self.multiply_noise()
     libtcod.heightmap_normalize(self.hm, 0, 255)
     #libtcod.heightmap_normalize(self.hm2, 0, 255)
     #libtcod.heightmap_normalize(self.hm3, 0, 255)
     #libtcod.heightmap_rain_erosion(self.hm, (self.w + self.h)*4, 0.5, 0.1, None)
     
     self.add_noise()
     self.turn_to_tiles()
     self.determine_temperatures()
     self.normalise_temperatures()
     self.wind_gen = Particle_Map(self,1500)
     self.generate_mini_map(10)
     self.cities = []
     self.dungeons = []
     self.generate_city(libtcod.random_get_int(0, 4, 10))
     self.generate_dungeons(10)
Example #6
0
    def __init__(self, w, h):
        global TROPICS_THRESHOLD, TEMPERATE_THRESHOLD, TAIGA_THRESHOLD

        self.w = w
        self.h = h

        self.equator = h / 2
        TROPICS_THRESHOLD = (self.equator / 2) / 3
        TEMPERATE_THRESHOLD = self.equator / 2
        TAIGA_THRESHOLD = self.equator - self.equator * 0.1
        self.tiles = [[Tile(ix, iy, False, map_tile=True) for iy in range(h)]
                      for ix in range(w)]
        x, y = 0, 0
        self.traffic = [[0 for y in range(h)] for x in range(w)]
        #this holds the *colour* value of the tiles temps.
        self.temperature_map = [[0 for y in range(h)] for x in range(w)]
        self.moisture_map = [[0 for y in range(h)] for x in range(w)]

        self.hm = libtcod.heightmap_new(self.w, self.h)
        self.hm2 = libtcod.heightmap_new(self.w, self.h)
        self.hm3 = libtcod.heightmap_new(self.w, self.h)

        self.generate_land(self.hm)
        self.generate_land(self.hm2)
        self.generate_land(self.hm3)

        libtcod.noise_set_type(self.noise, libtcod.NOISE_SIMPLEX)
        self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                                       libtcod.NOISE_DEFAULT_LACUNARITY)
        #libtcod.heightmap_add_fbm(self.hm3, self.noise, 1, 1, 0, 0, 8, 0.8, 0.5)
        #self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
        #libtcod.heightmap_add_fbm(self.hm3, self.noise, 1, 1, 0, 0, 8, 0.8, 0.5)
        #self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
        #libtcod.heightmap_add_fbm(self.hm3, self.noise, 1, 1, 0, 0, 8, 0.8, 0.5)
        self.multiply_noise()
        self.multiply_noise()
        libtcod.heightmap_normalize(self.hm, 0, 255)
        #libtcod.heightmap_normalize(self.hm2, 0, 255)
        #libtcod.heightmap_normalize(self.hm3, 0, 255)
        #libtcod.heightmap_rain_erosion(self.hm, (self.w + self.h)*4, 0.5, 0.1, None)

        self.add_noise()
        self.turn_to_tiles()
        self.determine_temperatures()
        self.normalise_temperatures()
        self.wind_gen = Particle_Map(self, 1500)
        self.generate_mini_map(10)
        self.cities = []
        self.dungeons = []
        self.generate_city(libtcod.random_get_int(0, 4, 10))
        self.generate_dungeons(10)
Example #7
0
def initialze(scale=50, weather=False):
    global noise_field, height_map
    noise_field = libtcod.noise_new(2, 0.5, 2.0, rnd)  # 0.5f  and 2.0f
    libtcod.noise_set_type(noise_field, libtcod.NOISE_SIMPLEX)

    height_map = libtcod.heightmap_new(Constants.MAP_WIDTH, Constants.MAP_HEIGHT)

    for y in range(Constants.MAP_HEIGHT):
        for x in range(Constants.MAP_WIDTH):
            libtcod.heightmap_set_value(height_map, x, y, get_noise_value(x, y, scale=scale))

    libtcod.heightmap_normalize(height_map, 0.0, 1.0)
    # libtcod.heightmap_add_hill(height_map, 40, 40, 6, 0.8)
    if weather:
        libtcod.heightmap_rain_erosion(height_map, 5000, 0.75, .75)
Example #8
0
 def _build_background(self):
     """
     Make a background noise that will more or less look like
     an old map.
     """
     noise = tcod.noise_new(2)
     tcod.noise_set_type(noise, tcod.NOISE_SIMPLEX)
     background = []
     for y in range(self.height):
         background.append([])
         for x in range(self.width):
             background[y].append(
                 tcod.noise_get_turbulence(noise, [y / 100.0, x / 100.0],
                                           32.0))
     tcod.noise_delete(noise)
     return background
Example #9
0
 def _build_background(self):
     """
     Make a background noise that will more or less look like
     an old map.
     """
     noise = tcod.noise_new(2)
     tcod.noise_set_type(noise, tcod.NOISE_SIMPLEX)
     background = []
     for y in range(self.height):
         background.append([])
         for x in range(self.width):
             background[y].append(
                 tcod.noise_get_turbulence(noise,
                                           [y / 100.0, x / 100.0], 32.0))
     tcod.noise_delete(noise)
     return background
Example #10
0
def initialze(scale=50, weather=False):
    global noise_field, height_map
    noise_field = libtcod.noise_new(2, 0.5, 2.0, rnd)  # 0.5f  and 2.0f
    libtcod.noise_set_type(noise_field, libtcod.NOISE_SIMPLEX)

    height_map = libtcod.heightmap_new(Constants.MAP_WIDTH,
                                       Constants.MAP_HEIGHT)

    for y in range(Constants.MAP_HEIGHT):
        for x in range(Constants.MAP_WIDTH):
            libtcod.heightmap_set_value(height_map, x, y,
                                        get_noise_value(x, y, scale=scale))

    libtcod.heightmap_normalize(height_map, 0.0, 1.0)
    # libtcod.heightmap_add_hill(height_map, 40, 40, 6, 0.8)
    if weather:
        libtcod.heightmap_rain_erosion(height_map, 5000, 0.75, .75)
Example #11
0
def map_init_noise(width, height):
    map_gen = []
    noise = libtcodpy.noise_new(2)
    libtcodpy.noise_set_type(noise, libtcodpy.NOISE_SIMPLEX)
    for x in range(0, width):
        aux = []
        for y in range(0, height):
            if libtcodpy.noise_get(noise, [(x + 1) / 3, y / 3]) > 0.6:
                aux.append(
                    Tile(False, True, False, 0,
                         GAME.tiles.image_at((0, 0, 32, 32)),
                         GAME.tiles.image_at((0, 32, 32, 32))))  # WALL
            else:
                aux.append(
                    Tile(True, False, True, 0,
                         GAME.tiles.image_at((32, 0, 32, 32)),
                         GAME.tiles.image_at((32, 32, 32, 32))))  #F LOOR
        map_gen.append(aux)
    map_gen = map_set_borders(map_gen, width - 1, height - 1)  # BORDERS
    return map_gen
Example #12
0
    def generate_land(self,hm):
        
        print hm.w, hm.h
        #self.noise = perlin_noise.PerlinNoiseGenerator()
        #self.noise.generate_noise(self.w, self.h, 1, 16)
        #print str(self.noise.noise[1][1])
        self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
        libtcod.heightmap_add_fbm(hm, self.noise, 1, 1, 0, 0, 8, 0.5, 0.8)
        print "scale", str(libtcod.heightmap_get_value(hm, 1, 1))
        self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
        libtcod.noise_set_type(self.noise, libtcod.NOISE_PERLIN)
        libtcod.heightmap_scale_fbm(hm, self.noise, 1, 1, 0, 0, 8, 0.5, 0.8)
        
#        self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
#        libtcod.heightmap_add_fbm(hm, self.noise, 1, 1, 0, 0, 8, 0.8, 0.5)
#        
        libtcod.heightmap_normalize(hm, 0, 255)
        print "normalized", str(libtcod.heightmap_get_value(hm, 1, 1))
        
        return hm
Example #13
0
    def __init__(self, width, height):
        self.size = width 
        self.width = width
        self.height = height
        self.units = []
        self.selected_unit = None

        self.world_img = libtcod.image_new(self.width, self.height)
        self.ground_map = libtcod.map_new(width, height)
        self.deepsea_map = libtcod.map_new(width, height)
        
        self.noise_zoom = 5.0
        self.noise_octaves = 8.0

        self.center = [self.width/2, self.height/2]

        self.map_list = [[Tile(True, libtcod.black) for y in range(height)] for x in range(width)]

        self.world_noise = libtcod.noise_new(2)
        self.ocean_noise = libtcod.noise_new(2)
        libtcod.noise_set_type(self.world_noise, libtcod.NOISE_PERLIN)
        self.generate_land()
Example #14
0
    def generate_land(self, hm):

        print hm.w, hm.h
        #self.noise = perlin_noise.PerlinNoiseGenerator()
        #self.noise.generate_noise(self.w, self.h, 1, 16)
        #print str(self.noise.noise[1][1])
        self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                                       libtcod.NOISE_DEFAULT_LACUNARITY)
        libtcod.heightmap_add_fbm(hm, self.noise, 1, 1, 0, 0, 8, 0.5, 0.8)
        print "scale", str(libtcod.heightmap_get_value(hm, 1, 1))
        self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                                       libtcod.NOISE_DEFAULT_LACUNARITY)
        libtcod.noise_set_type(self.noise, libtcod.NOISE_PERLIN)
        libtcod.heightmap_scale_fbm(hm, self.noise, 1, 1, 0, 0, 8, 0.5, 0.8)

        #        self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
        #        libtcod.heightmap_add_fbm(hm, self.noise, 1, 1, 0, 0, 8, 0.8, 0.5)
        #
        libtcod.heightmap_normalize(hm, 0, 255)
        print "normalized", str(libtcod.heightmap_get_value(hm, 1, 1))

        return hm
Example #15
0
def generate(width, height):
    _weight_map, _tile_map, _solids, _node_grid = mapgen.create_map(
        width, height)
    _zoom = .95
    _noise = tcod.noise_new(3)
    _low_grass = 25
    _fsl = {}
    _building_space = set()
    _walls = set()
    _possible_trees = set()
    _river_start_x = random.randint(int(round(width * .35)),
                                    int(round(width * .65)))
    _river_start_y = 0  #random.randint(int(round(height * .15)), int(round(height * .85)))
    _x = _river_start_x
    _y = _river_start_y
    _px, _py = _river_start_x, _river_start_y
    _river_direction = 270
    _turn_rate = random.randint(-1, 1)
    _river_tiles = set()
    _river_size = random.randint(7, 10)
    _ground_tiles = set()
    _possible_camps = set()

    while 1:
        for i in range(4, 10):
            for __x, __y in shapes.circle(_x, _y, _river_size):
                if __x < 0 or __y < 0 or __x >= width or __y >= height or (
                        __x, __y) in _solids:
                    continue

                _river_tiles.add((__x, __y))
                _tile = tiles.swamp_water(__x, __y)
                _tile_map[__y][__x] = _tile
                _weight_map[__y][__x] = _tile['w']

            _river_direction += _turn_rate
            _xv, _yv = numbers.velocity(_river_direction, 1)
            _px += _xv
            _py += _yv
            _x = int(round(_px))
            _y = int(round(_py))

            if _x < 0 or _y < 0 or _x >= width or _y >= height or (
                    _x, _y) in _solids:
                break

        if _x < 0 or _y < 0 or _x >= width or _y >= height:
            break

        _turn_rate = random.uniform(-2.5, 2.5)
        _river_size = numbers.clip(_river_size + random.randint(-1, 1), 7, 10)

    for y in range(height):
        for x in range(width):
            if (x, y) in _river_tiles:
                continue

            _tile = tiles.grass(x, y)
            _tile_map[y][x] = _tile
            _weight_map[y][x] = _tile['w']

            _ground_tiles.add((x, y))

    tcod.noise_set_type(_noise, tcod.NOISE_WAVELET)

    for y in range(height):
        for x in range(width):
            if (x, y) in _river_tiles:
                continue

            _noise_values = [(_zoom * x / (constants.MAP_VIEW_WIDTH)),
                             (_zoom * y / (constants.MAP_VIEW_HEIGHT))]
            _noise_value = 100 * tcod.noise_get_turbulence(
                _noise, _noise_values, tcod.NOISE_WAVELET)

            if _low_grass <= _noise_value <= 100:
                _tile = tiles.tall_grass(x, y)

                if _noise_value >= 40:
                    if not x < width * .15 and not x > width * .85 and not y < height * .15 and not y > height * .85:
                        _possible_camps.add((x, y))

                if random.uniform(0, 1) > .5:
                    _possible_trees.add((x, y))

            elif _noise_value >= _low_grass - 10 and 10 * random.uniform(
                    0, 1) > _low_grass - _noise_value:
                _tile = tiles.grass(x, y)

            else:
                _tile = tiles.rock(x, y)
                _solids.add((x, y))

            _tile_map[y][x] = _tile
            _weight_map[y][x] = _tile['w']

    _trees = {}
    _tree_plots = _possible_trees - _solids - _river_tiles
    _used_trees = random.sample(
        _tree_plots,
        numbers.clip(int(round((width * height) * .002)), 0, len(_tree_plots)))

    for x, y in _used_trees:
        _size = random.randint(1, 3)

        for _x, _y in shapes.circle(x, y, _size):
            if _x < 0 or _y < 0 or _x >= width or _y >= height or (
                    _x, _y) in _solids:
                break

            _tile = tiles.tree(_x, _y)
            _weight_map[_y][_x] = _tile['w']
            _tile_map[_y][_x] = _tile
            _trees[_x, _y] = random.uniform(2, 3.5) * _size

            _solids.add((_x, _y))

    _ground_tiles = _ground_tiles - _solids
    _plot_pole_x, _plot_pole_y = width / 2, height / 2
    _bushes = random.sample(
        _ground_tiles,
        numbers.clip(int(round((width * height) * .0003)), 0,
                     len(_ground_tiles)))
    _camps = set()

    while len(_possible_camps):
        _camp_1 = random.choice(list(_possible_camps))
        _possible_camps.remove(_camp_1)
        _camps.add(_camp_1)

        for camp_2 in _possible_camps.copy():
            _dist = numbers.distance(_camp_1, camp_2)

            if _dist <= 250:
                _possible_camps.remove(camp_2)

    for x, y in _bushes:
        _walker_x = x
        _walker_y = y
        _last_dir = -2, -2

        for i in range(random.randint(10, 15)):
            _tile = tiles.tree(_walker_x, _walker_y)
            _weight_map[_walker_y][_walker_x] = _tile['w']
            _tile_map[_walker_y][_walker_x] = _tile

            _dir = random.randint(-1, 1), random.randint(-1, 1)
            _n_x = _walker_x + _dir[0]
            _n_y = _walker_y + _dir[1]

            if _n_x < 0 or _n_y < 0 or _n_x >= width or _n_y >= height or (
                    _n_x, _n_y) in _solids:
                break

            _last_dir = _dir[0] * -1, _dir[0] * -1
            _walker_x = _n_x
            _walker_y = _n_y

    _camp_info = {}

    for c_x, c_y in _camps:
        _building_walls = random.sample(['north', 'south', 'east', 'west'],
                                        random.randint(2, 3))
        _broken_walls = random.sample(
            _building_walls,
            numbers.clip(random.randint(0, 3), 0, len(_building_walls)))
        _camp = {'center': (c_x, c_y)}
        _camp_ground = []

        for y in range(-10, 10 + 1):
            for x in range(-10, 10 + 1):
                _x = x + c_x
                _y = y + c_y

                if (_x, _y) in _solids or (_x, _y) in _river_tiles:
                    continue

                if (x == -10 and 'west' in _building_walls) or (
                        y == -10 and 'north' in _building_walls) or (
                            x == 10 and 'east' in _building_walls) or (
                                y == 10 and 'south' in _building_walls):
                    if x == -10 and 'west' in _building_walls and 'west' in _broken_walls and random.uniform(
                            0, 1) > .75:
                        continue

                    if x == 10 and 'east' in _building_walls and 'east' in _broken_walls and random.uniform(
                            0, 1) > .75:
                        continue

                    if y == -10 and 'north' in _building_walls and 'north' in _broken_walls and random.uniform(
                            0, 1) > .75:
                        continue

                    if y == 10 and 'south' in _building_walls and 'south' in _broken_walls and random.uniform(
                            0, 1) > .75:
                        continue

                    _tile = tiles.wooden_fence(_x, _y)
                    _weight_map[_y][_x] = _tile['w']
                    _tile_map[_y][_x] = _tile
                    _solids.add((_x, _y))

                elif (x > -10 and x <= 10) and (y > -10 and y <= 10):
                    _camp_ground.append((_x, _y))

        _camp['ground'] = _camp_ground[:]
        _camp_info[c_x, c_y] = _camp

    mapgen.build_node_grid(_node_grid, _solids)

    for c_x, c_y in _camps:
        mapgen.add_plot_pole(c_x, c_y, 40, _solids)

    _fsl = {
        'Terrorists': {
            'bases': 1,
            'squads': 0,
            'trader': False,
            'type': life.human_runner
        }
    }
    #        #'Militia': {'bases': 0, 'squads': 1, 'trader': False, 'type': life.human_bandit},
    #        'Wild Dogs': {'bases': 0, 'squads': 1, 'trader': False, 'type': life.wild_dog}}

    return width, height, _node_grid, mapgen.NODE_SETS.copy(
    ), _weight_map, _tile_map, _solids, _fsl, _trees, _building_space - _walls
Example #16
0
def generate(width, height):
	_weight_map, _tile_map, _solids, _node_grid = mapgen.create_map(width, height)
	_zoom = .95
	_noise = tcod.noise_new(3)
	_low_grass = 25
	_fsl = {}
	_building_space = set()
	_walls = set()
	_possible_trees = set()
	_river_start_x = random.randint(int(round(width * .35)), int(round(width * .65)))
	_river_start_y = 0#random.randint(int(round(height * .15)), int(round(height * .85)))
	_x = _river_start_x
	_y = _river_start_y
	_px, _py = _river_start_x, _river_start_y
	_river_direction = 270
	_turn_rate = random.randint(-1, 1)
	_river_tiles = set()
	_river_size = random.randint(7, 10)
	_ground_tiles = set()
	_possible_camps = set()
	
	while 1:
		for i in range(4, 10):
			for __x, __y in shapes.circle(_x, _y, _river_size):
				if __x < 0 or __y < 0 or __x >= width or __y >= height or (__x, __y) in _solids:
					continue
				
				_river_tiles.add((__x, __y))
				_tile = tiles.swamp_water(__x, __y)
				_tile_map[__y][__x] = _tile
				_weight_map[__y][__x] = _tile['w']
			
			_river_direction += _turn_rate
			_xv, _yv = numbers.velocity(_river_direction, 1)
			_px += _xv
			_py += _yv
			_x = int(round(_px))
			_y = int(round(_py))
			
			if _x < 0 or _y < 0 or _x >= width or _y >= height or (_x, _y) in _solids:
				break
		
		if _x < 0 or _y < 0 or _x >= width or _y >= height:
			break
		
		_turn_rate = random.uniform(-2.5, 2.5)
		_river_size = numbers.clip(_river_size + random.randint(-1, 1), 7, 10)
	
	for y in range(height):
		for x in range(width):
			if (x, y) in _river_tiles:
				continue
			
			_tile = tiles.grass(x, y)
			_tile_map[y][x] = _tile
			_weight_map[y][x] = _tile['w']
			
			_ground_tiles.add((x, y))
	
	tcod.noise_set_type(_noise, tcod.NOISE_WAVELET)
	
	for y in range(height):
		for x in range(width):
			if (x, y) in _river_tiles:
				continue
			
			_noise_values = [(_zoom * x / (constants.MAP_VIEW_WIDTH)),
					         (_zoom * y / (constants.MAP_VIEW_HEIGHT))]
			_noise_value = 100 * tcod.noise_get_turbulence(_noise, _noise_values, tcod.NOISE_WAVELET)
			
			if _low_grass <= _noise_value <= 100:
				_tile = tiles.tall_grass(x, y)
				
				if _noise_value >= 40:
					if not x < width * .15 and not x > width * .85 and not y < height * .15 and not y > height * .85:
						_possible_camps.add((x, y))
				
				if random.uniform(0, 1) > .5:
					_possible_trees.add((x, y))
			
			elif _noise_value >= _low_grass - 10 and 10 * random.uniform(0, 1) > _low_grass-_noise_value:
				_tile = tiles.grass(x, y)
			
			else:
				_tile = tiles.rock(x, y)
				_solids.add((x, y))
			
			_tile_map[y][x] = _tile
			_weight_map[y][x] = _tile['w']
	
	_trees = {}
	_tree_plots = _possible_trees - _solids - _river_tiles
	_used_trees = random.sample(_tree_plots, numbers.clip(int(round((width * height) * .002)), 0, len(_tree_plots)))
	
	for x, y in _used_trees:
		_size = random.randint(1, 3)
		
		for _x, _y in shapes.circle(x, y, _size):
			if _x < 0 or _y < 0 or _x >= width or _y >= height or (_x, _y) in _solids:
				break
			
			_tile = tiles.tree(_x, _y)
			_weight_map[_y][_x] = _tile['w']
			_tile_map[_y][_x] = _tile
			_trees[_x, _y] = random.uniform(2, 3.5) * _size
			
			_solids.add((_x, _y))
	
	_ground_tiles = _ground_tiles - _solids
	_plot_pole_x, _plot_pole_y = width/2, height/2
	_bushes = random.sample(_ground_tiles, numbers.clip(int(round((width * height) * .0003)), 0, len(_ground_tiles)))
	_camps = set()
	
	while len(_possible_camps):
		_camp_1 = random.choice(list(_possible_camps))
		_possible_camps.remove(_camp_1)
		_camps.add(_camp_1)
		
		for camp_2 in _possible_camps.copy():
			_dist = numbers.distance(_camp_1, camp_2)
			
			if _dist <= 250:
				_possible_camps.remove(camp_2)
	
	for x, y in _bushes:
		_walker_x = x
		_walker_y = y
		_last_dir = -2, -2
		
		for i in range(random.randint(10, 15)):
			_tile = tiles.tree(_walker_x, _walker_y)
			_weight_map[_walker_y][_walker_x] = _tile['w']
			_tile_map[_walker_y][_walker_x] =_tile
			
			_dir = random.randint(-1, 1), random.randint(-1, 1)
			_n_x = _walker_x + _dir[0]
			_n_y = _walker_y + _dir[1]

			if _n_x < 0 or _n_y < 0 or _n_x >= width or _n_y >= height or (_n_x, _n_y) in _solids:
				break
			
			_last_dir = _dir[0] * -1, _dir[0] * -1
			_walker_x = _n_x
			_walker_y = _n_y
	
	_camp_info = {}
	
	for c_x, c_y in _camps:
		_building_walls = random.sample(['north', 'south', 'east', 'west'], random.randint(2, 3))
		_broken_walls = random.sample(_building_walls, numbers.clip(random.randint(0, 3), 0, len(_building_walls)))
		_camp = {'center': (c_x, c_y)}
		_camp_ground = []
		
		for y in range(-10, 10+1):
			for x in range(-10, 10+1):
				_x = x + c_x
				_y = y + c_y
				
				if (_x, _y) in _solids or (_x, _y) in _river_tiles:
					continue
				
				if (x == -10 and 'west' in _building_walls) or (y == -10 and 'north' in _building_walls) or (x == 10 and 'east' in _building_walls) or (y == 10 and 'south' in _building_walls):
					if x == -10 and 'west' in _building_walls and 'west' in _broken_walls and random.uniform(0, 1) > .75:
						continue
					
					if x == 10 and 'east' in _building_walls and 'east' in _broken_walls and random.uniform(0, 1) > .75:
						continue
					
					if y == -10 and 'north' in _building_walls and 'north' in _broken_walls and random.uniform(0, 1) > .75:
						continue
					
					if y == 10 and 'south' in _building_walls and 'south' in _broken_walls and random.uniform(0, 1) > .75:
						continue
					
					_tile = tiles.wooden_fence(_x, _y)
					_weight_map[_y][_x] = _tile['w']
					_tile_map[_y][_x] = _tile
					_solids.add((_x, _y))
				
				elif (x > -10 and x <= 10) and (y > -10 and y <= 10):
					_camp_ground.append((_x, _y))
		
		_camp['ground'] = _camp_ground[:]
		_camp_info[c_x, c_y] = _camp
	
	mapgen.build_node_grid(_node_grid, _solids)
	
	for c_x, c_y in _camps:
		mapgen.add_plot_pole(c_x, c_y, 40, _solids)
	
	_fsl = {'Terrorists': {'bases': 1, 'squads': 0, 'trader': False, 'type': life.human_runner}}
	#        #'Militia': {'bases': 0, 'squads': 1, 'trader': False, 'type': life.human_bandit},
	#        'Wild Dogs': {'bases': 0, 'squads': 1, 'trader': False, 'type': life.wild_dog}}
	
	return width, height, _node_grid, mapgen.NODE_SETS.copy(), _weight_map, _tile_map, _solids, _fsl, _trees, _building_space - _walls
Example #17
0
def make_bare_surface_map(player=None):
    """
    Creates a map which is open by default, and then filled with boulders, mesas and rocks.
    Uses a 2D noise generator. The map has an impenetrable border.
    """
    objects_for_this_map = []

    if player is None:
        #Creating the object representing the player:
        fighter_component = Fighter(hp=30, defense=2, power=5, xp=0, death_function=player_death) #creating the fighter aspect of the player
        player = GamePiece(0, 0, 219, 'player', libtcod.white, blocks=False, fighter=fighter_component, speed=PLAYER_SPEED)
        player.level = 1

        objects_for_this_map.append(player)

    else:
        # This must not be a new game. We need to put the pre-existing player into the list and later give them an
        # appropriate spot in the map to have spatial translation continuity.
        objects_for_this_map.append(player)


    noise2d = libtcod.noise_new(2) #create a 2D noise generator
    libtcod.noise_set_type(noise2d, libtcod.NOISE_SIMPLEX) #tell it to use simplex noise for higher contrast

    # Create the map with a default tile choice of empty unblocked squares.
    newmap = [[ Tile(blocked=False, block_sight=False, char=' ', fore=color_ground, back=color_ground) 
        for y in range(MAP_HEIGHT)] 
            for x in range(MAP_WIDTH) ]

    #Put a border around the map so the characters can't go off the edge of the world
    for x in range(0, MAP_WIDTH):
        newmap[x][0].blocked = True
        newmap[x][0].block_sight = True
        newmap[x][0].mapedge = True
        newmap[x][0].fore = color_wall
        newmap[x][0].back = color_wall
        newmap[x][MAP_HEIGHT-1].blocked = True
        newmap[x][MAP_HEIGHT-1].block_sight = True
        newmap[x][MAP_HEIGHT-1].mapedge = True
        newmap[x][MAP_HEIGHT-1].fore = color_wall
        newmap[x][MAP_HEIGHT-1].back = color_wall
    for y in range(0, MAP_HEIGHT):
        newmap[0][y].blocked = True
        newmap[0][y].block_sight = True
        newmap[0][y].mapedge = True
        newmap[0][y].fore = color_wall
        newmap[0][y].back = color_wall
        newmap[MAP_WIDTH-1][y].blocked = True
        newmap[MAP_WIDTH-1][y].block_sight = True
        newmap[MAP_WIDTH-1][y].mapedge = True
        newmap[MAP_WIDTH-1][y].fore = color_wall
        newmap[MAP_WIDTH-1][y].back = color_wall

    # Create natural looking landscape
    for x in range(1, MAP_WIDTH-1):
        for y in range(1, MAP_HEIGHT-1):
            if libtcod.noise_get_turbulence(noise2d, [x, y], 128.0, libtcod.NOISE_SIMPLEX) < 0.4:
                #Turbulent simplex noise returns values between 0.0 and 1.0, with many values greater than 0.9.
                newmap[x][y].blocked = True
                newmap[x][y].block_sight = True
                newmap[x][y].fore = color_wall
                newmap[x][y].back = color_wall

    # Scatter debris around the map to add flavor:
    place_junk(newmap)

    # Choose a spot for the player to start
    player.x, player.y = choose_random_unblocked_spot(newmap)

    return newmap, objects_for_this_map
Example #18
0
def make_surface_map(player=None):
    """
    Creates a map which is open by default, and then filled with boulders, mesas and buildings.
    Uses a 2D noise generator. The map has an impenetrable border.
    """
    objects_for_this_map = []
    new_objects = []
    more_objects = []

    if player is None:
        #Creating the object representing the player:
        fighter_component = Fighter(hp=30, defense=2, power=5, xp=0, death_function=player_death) #creating the fighter aspect of the player
        player = GamePiece(0, 0, 219, 'player', libtcod.white, blocks=False, fighter=fighter_component, speed=PLAYER_SPEED)
        player.level = 1

        objects_for_this_map.append(player)

    else:
        # This must not be a new game. We need to put the pre-existing player into the list and later give them an
        # appropriate spot in the map to have spatial translation continuity.
        objects_for_this_map.append(player)


    noise2d = libtcod.noise_new(2) #create a 2D noise generator
    libtcod.noise_set_type(noise2d, libtcod.NOISE_SIMPLEX) #tell it to use simplex noise for higher contrast

    # Create the map with a default tile choice of empty unblocked squares.
    newmap = [[ Tile(blocked=False, block_sight=False, char=' ', fore=color_ground, back=color_ground) 
        for y in range(MAP_HEIGHT)] 
            for x in range(MAP_WIDTH) ]

    #Put a border around the map so the characters can't go off the edge of the world
    for x in range(0, MAP_WIDTH):
        newmap[x][0].blocked = True
        newmap[x][0].block_sight = True
        newmap[x][0].mapedge = True
        newmap[x][0].fore = color_wall
        newmap[x][0].back = color_wall
        newmap[x][MAP_HEIGHT-1].blocked = True
        newmap[x][MAP_HEIGHT-1].block_sight = True
        newmap[x][MAP_HEIGHT-1].mapedge = True
        newmap[x][MAP_HEIGHT-1].fore = color_wall
        newmap[x][MAP_HEIGHT-1].back = color_wall
    for y in range(0, MAP_HEIGHT):
        newmap[0][y].blocked = True
        newmap[0][y].block_sight = True
        newmap[0][y].mapedge = True
        newmap[0][y].fore = color_wall
        newmap[0][y].back = color_wall
        newmap[MAP_WIDTH-1][y].blocked = True
        newmap[MAP_WIDTH-1][y].block_sight = True
        newmap[MAP_WIDTH-1][y].mapedge = True
        newmap[MAP_WIDTH-1][y].fore = color_wall
        newmap[MAP_WIDTH-1][y].back = color_wall

    # Create natural looking landscape
    for x in range(1, MAP_WIDTH-1):
        for y in range(1, MAP_HEIGHT-1):
            if libtcod.noise_get_turbulence(noise2d, [x, y], 128.0, libtcod.NOISE_SIMPLEX) < 0.4:
                #Turbulent simplex noise returns values between 0.0 and 1.0, with many values greater than 0.9.
                newmap[x][y].blocked = True
                newmap[x][y].block_sight = True
                newmap[x][y].fore = color_wall
                newmap[x][y].back = color_wall

    # Place buildings
    buildings = []
    num_buildings = 0
    for r in range(MAX_BUILDINGS):
        w = libtcod.random_get_int(0, BUILDING_MIN_SIZE, BUILDING_MAX_SIZE)
        h = libtcod.random_get_int(0, BUILDING_MIN_SIZE, BUILDING_MAX_SIZE)
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)
        new_building = Rect(x, y, w, h)
        create_building(newmap, new_building)
        buildings.append(new_building)
        num_buildings += 1

        #Create stairs in the last building
        if num_buildings == MAX_BUILDINGS:
            new_x, new_y = new_building.center()
            stairs = GamePiece(new_x, new_y, '>', 'stairs', libtcod.white, always_visible=True)
            objects_for_this_map.append(stairs)
            #stairs.send_to_back(newmap.objects) #so that it gets drawn below NPCs. I commented this out because
            # it should be at the end anyway, since its being appended.

    #Put doors in buildings. Have to do this AFTER they are built or later ones will overwrite earlier ones
    # door_chances = { 'left': 25, 'right': 25, 'top': 25, 'bottom': 25 }
    for place in buildings:
    #     num_doors = libtcod.random_get_int(0, 2, 4)
    #         for case in switch(num_doors):
    #             if case(2): 
    #                 choice = random_choice(door_chances)
        doorx, doory = place.middle_of_wall('left')
        if newmap[doorx][doory].blocked and not newmap[doorx][doory].mapedge: 
            newmap[doorx][doory].char = LEFT_DOOR
            newmap[doorx][doory].blocked = False 
            newmap[doorx][doory].fore = libtcod.white
            newmap[doorx][doory].back = libtcod.grey
        doorx, doory = place.middle_of_wall('top')
        if newmap[doorx][doory].blocked and not newmap[doorx][doory].mapedge:
            newmap[doorx][doory].char = TOP_DOOR
            newmap[doorx][doory].blocked = False 
            newmap[doorx][doory].fore = libtcod.white
            newmap[doorx][doory].back = libtcod.grey
        doorx, doory = place.middle_of_wall('right')
        if newmap[doorx][doory].blocked and not newmap[doorx][doory].mapedge: 
            newmap[doorx][doory].char = RIGHT_DOOR
            newmap[doorx][doory].blocked = False 
            newmap[doorx][doory].fore = libtcod.white
            newmap[doorx][doory].back = libtcod.grey
        doorx, doory = place.middle_of_wall('bottom')
        if newmap[doorx][doory].blocked and not newmap[doorx][doory].mapedge: 
            newmap[doorx][doory].char = BOTTOM_DOOR
            newmap[doorx][doory].blocked = False 
            newmap[doorx][doory].fore = libtcod.white
            newmap[doorx][doory].back = libtcod.grey

        more_objects = place_objects(newmap, place) #add some contents to this room
        if more_objects is not None:
            for item in more_objects:
                new_objects.append(item)

    # Scatter debris around the map to add flavor:
    place_junk(newmap)

    # Choose a spot for the player to start
    player.x, player.y = choose_random_unblocked_spot(newmap)

    for item in new_objects:
        objects_for_this_map.append(item)

    return newmap, objects_for_this_map
Example #19
0
 def multiply_noise(self):
     self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
     libtcod.noise_set_type(self.noise, libtcod.NOISE_PERLIN)
     libtcod.heightmap_scale_fbm(self.hm, self.noise, 1, 1, 1, 1, 16, 0.5, 0.5)
Example #20
0
 def multiply_noise(self):
     self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                                    libtcod.NOISE_DEFAULT_LACUNARITY)
     libtcod.noise_set_type(self.noise, libtcod.NOISE_PERLIN)
     libtcod.heightmap_scale_fbm(self.hm, self.noise, 1, 1, 1, 1, 16, 0.5,
                                 0.5)
Example #21
0
 def add_noise(self):
     libtcod.heightmap_normalize(self.hm, 0, 1)
     self.noise = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
     libtcod.noise_set_type(self.noise, libtcod.NOISE_PERLIN)
     libtcod.heightmap_add_fbm(self.hm, self.noise, 1, 1, 1, 1, 8, 0.5, 0.5)
     libtcod.heightmap_normalize(self.hm, 0, 255)