예제 #1
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)
예제 #2
0
def create():
	display.create_surface('background')
	display.create_surface('text')
	display.blit_background('background')
	
	roll()
	
	NOISE = tcod.noise_new(2, h=tcod.NOISE_DEFAULT_HURST, random=tcod.random_new())
	
	for y in range(0, constants.WINDOW_HEIGHT):
		for x in range(0, constants.WINDOW_WIDTH):
			_noise_values = [(ZOOM * x / (constants.WINDOW_WIDTH)),
			                 (ZOOM * y / (constants.WINDOW_HEIGHT))]
			_height = 1 - tcod.noise_get_turbulence(NOISE, _noise_values, tcod.NOISE_SIMPLEX)
			_dist_to_crosshair = 30
			_crosshair_mod = abs((_dist_to_crosshair - 1))
			
			if _height > .4:
				_height = (_height - .4) / .4
				_r, _g, _b = numbers.clip(30 * _height, 20, 255), 50 * _height, numbers.clip(30 * _height, 30, 255)
			
			else:
				_r, _g, _b = 20, 0, 30
			
			_r += 30# * _crosshair_mod
			
			if x < SIDEBAR_WIDTH:
				if y < 7:
					_r = numbers.interp(_r, .0, .4)
					_g = numbers.interp(_g, .0, .4)
					_b = numbers.interp(_b, .0, .4)
					
				elif y < 43:
					_r = numbers.interp(_r, .0, .6)
					_g = numbers.interp(_g, .0, .6)
					_b = numbers.interp(_b, .0, .6)
					
				elif y < constants.WINDOW_HEIGHT:
					_r = numbers.interp(_r, 1, .7)
					_g = numbers.interp(_g, 1, .7)
					_b = numbers.interp(_b, 1, .7)

				else:
					_r = (int(round(_r * 1.0)))
					_g = (int(round(_g * .2)))
					_b = (int(round(_b * .2)))
			
			if x > SIDEBAR_WIDTH + 3 and x < constants.WINDOW_WIDTH - 6:
				if y > 18 and y < 36:
					_r = numbers.interp(_r, 255, .1)
					_g = numbers.interp(_g, 255, .1)
					_b = numbers.interp(_b, 255, .1)
			
			if x > SIDEBAR_WIDTH + 3 and x < constants.WINDOW_WIDTH - 6:
				if y > 10 and y < 16:
					_r = numbers.interp(_r, .0, .4)
					_g = numbers.interp(_g, .0, .4)
					_b = numbers.interp(_b, .0, .4)
			
			display._set_char('background', x, y, ' ', (0, 0, 0), (_r, _g, _b))
예제 #3
0
def get_noise_value(x, y, scale=16, type='FBM'):
    nx, ny = float(x) / scale, float(y) / scale

    if type == 'DEFAULT':
        pre_value = libtcod.noise_get(noise_field, (nx, ny) , libtcod.NOISE_PERLIN)
    elif type == 'FBM':
        pre_value = libtcod.noise_get_fbm(noise_field, (nx, ny), 8, libtcod.NOISE_DEFAULT)
    elif type == 'TURB':
        pre_value = libtcod.noise_get_turbulence(noise_field, (nx, ny), 1, libtcod.NOISE_PERLIN)
    return pre_value
예제 #4
0
def paint_map(initial=False):
    global SPARK_SIZE, REDRAW_RATE

    if REDRAW_RATE:
        REDRAW_RATE -= 1

        return

    REDRAW_RATE = 0.0

    if initial:
        _x_range = 0, constants.WINDOW_WIDTH
        _y_range = 0, constants.WINDOW_HEIGHT

    else:
        _x_range = 30, 50
        _y_range = 5, 20

    SPARK_SIZE = numbers.clip(SPARK_SIZE + random.uniform(-3, 3), 6.0, 12.0)

    for y in range(_y_range[0], _y_range[1]):
        for x in range(_x_range[0], _x_range[1]):
            _noise_values = [(ZOOM * x / (constants.WINDOW_WIDTH)),
                             (ZOOM * y / (constants.WINDOW_HEIGHT))]
            _height = 1 - tcod.noise_get_turbulence(NOISE, _noise_values,
                                                    tcod.NOISE_SIMPLEX)
            _dist_to_crosshair = numbers.clip(
                (abs(y - 12) *
                 (abs(x - 38))) / (SPARK_SIZE + random.uniform(-3.5, 1)), 0, 1)
            #_height *= _dist_to_crosshair

            _crosshair_mod = abs((_dist_to_crosshair - 1))

            #if not initial and not _crosshair_mod:
            #	continue

            if _height > .4:
                _height = (_height - .4) / .4
                _r, _g, _b = numbers.clip(30 * _height, 20,
                                          255), 50 * _height, numbers.clip(
                                              30 * _height, 30, 255)

            else:
                _r, _g, _b = 20, 0, 30
                #_height = 1 - (_height / .5)
                #_r, _g, _b = 60 * _height, 60 * _height, 100 * _height

            _r += 80 * _crosshair_mod

            display._set_char('background', x, y, ' ', (0, 0, 0), (_r, _g, _b))

    display.blit_background('background')
예제 #5
0
def get_noise_value(x, y, scale=16, type='FBM'):
    nx, ny = float(x) / scale, float(y) / scale

    if type == 'DEFAULT':
        pre_value = libtcod.noise_get(noise_field, (nx, ny),
                                      libtcod.NOISE_PERLIN)
    elif type == 'FBM':
        pre_value = libtcod.noise_get_fbm(noise_field, (nx, ny), 8,
                                          libtcod.NOISE_DEFAULT)
    elif type == 'TURB':
        pre_value = libtcod.noise_get_turbulence(noise_field, (nx, ny), 1,
                                                 libtcod.NOISE_PERLIN)
    return pre_value
예제 #6
0
    def make_house():
        bsp_tree = tcod.bsp_new_with_size(0, 0, HOUSE_WIDTH - 1, HOUSE_HEIGHT - 1)
        tcod.bsp_split_recursive(bsp_tree, 0, BSP_DEPTH, MIN_ROOM_WIDTH, MIN_ROOM_HEIGHT,
                                 MAX_H_RATIO, MAX_V_RATIO)

        tcod.bsp_traverse_inverted_level_order(bsp_tree, handle_node)
        house_array[-1][-1] = Tile("wall", True, True)

        noise = tcod.noise_new(2, HURST, LACNULARITY)
        for x in xrange(HOUSE_WIDTH):
            for y in xrange(HOUSE_HEIGHT):
                if tcod.noise_get_turbulence(noise, [x, y], 32.0, tcod.NOISE_SIMPLEX) > THRESHOLD:
                    house_array[y][x] = Tile("floor", True, True)
예제 #7
0
def paint_map(initial=False):
    global SPARK_SIZE, REDRAW_RATE

    if REDRAW_RATE:
        REDRAW_RATE -= 1

        return

    REDRAW_RATE = 0.0

    if initial:
        _x_range = 0, constants.WINDOW_WIDTH
        _y_range = 0, constants.WINDOW_HEIGHT

    else:
        _x_range = 30, 50
        _y_range = 5, 20

    SPARK_SIZE = numbers.clip(SPARK_SIZE + random.uniform(-3, 3), 6.0, 12.0)

    for y in range(_y_range[0], _y_range[1]):
        for x in range(_x_range[0], _x_range[1]):
            _noise_values = [(ZOOM * x / (constants.WINDOW_WIDTH)), (ZOOM * y / (constants.WINDOW_HEIGHT))]
            _height = 1 - tcod.noise_get_turbulence(NOISE, _noise_values, tcod.NOISE_SIMPLEX)
            _dist_to_crosshair = numbers.clip(
                (abs(y - 12) * (abs(x - 38))) / (SPARK_SIZE + random.uniform(-3.5, 1)), 0, 1
            )
            # _height *= _dist_to_crosshair

            _crosshair_mod = abs((_dist_to_crosshair - 1))

            # if not initial and not _crosshair_mod:
            # 	continue

            if _height > 0.4:
                _height = (_height - 0.4) / 0.4
                _r, _g, _b = numbers.clip(30 * _height, 20, 255), 50 * _height, numbers.clip(30 * _height, 30, 255)

            else:
                _r, _g, _b = 20, 0, 30
                # _height = 1 - (_height / .5)
                # _r, _g, _b = 60 * _height, 60 * _height, 100 * _height

            _r += 80 * _crosshair_mod

            display._set_char("background", x, y, " ", (0, 0, 0), (_r, _g, _b))

    display.blit_background("background")
예제 #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
예제 #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
예제 #10
0
def _post_process_clouds(x, y, clouds, zoom, clouds_x, clouds_y, size, sunlight, noise, inside):
	_noise_values = [(zoom * x / (constants.MAP_VIEW_WIDTH)) + clouds_x,
	                 (zoom * y / (constants.MAP_VIEW_HEIGHT)) + clouds_y]
	_shade = tcod.noise_get_turbulence(noise, _noise_values, tcod.NOISE_SIMPLEX)
	_shade_mod = numbers.clip(abs(_shade), sunlight, 1)
	
	#TODO: Inside lighting
	#if not (camera.X+x, camera.Y+y) in inside:
	clouds[y][x] -= _shade_mod
	clouds[y][x] *= SHADOWS[camera.Y+y][camera.X+x].clip(SUNLIGHT-.5, 1)
	#else:
	#	clouds[y][x] *= SHADOWS[camera.Y+y][camera.X+x] #TODO: Inside lighting here
	
	#TODO: Future
	#clouds *= LIGHTS[camera.Y:camera.Y+y, camera.X:camera.X+x]
	
	clouds[y][x] *= LIGHTS[camera.Y+y, camera.X+x]
예제 #11
0
def get_cylindrical_projection(stars, width=360, height=180):
    """
    Return a tcod console instance of width and height that renders an equirectangular projection of the given list of stars.
    """
    console = tcod.console_new(width, height)

    for star in stars:
        azimuthal = int((star.azimuthal * width) / (2 * math.pi))
        polar = int((star.polar / math.pi) * height)

        # Color Work
        rgb = temperature_to_rgb(random.uniform(4000, 20000))
        brightness = 1.0 - star.radial * 0.75

        color = tcod.Color(rgb[0], rgb[1], rgb[2])
        (h, s, v) = tcod.color_get_hsv(color)
        tcod.color_set_hsv(color, h, s, brightness)

        tcod.console_put_char_ex(console, azimuthal, polar, star.sprite, color,
                                 tcod.black)

    # Background Texture
    noise3d = tcod.noise_new(3)
    for map_x in range(width):
        for map_y in range(height):
            azimuthal = (map_x / (width * 1.0)) * 2.0 * math.pi
            polar = (map_y / (height * 1.0)) * math.pi
            x = math.sin(polar) * math.cos(azimuthal)
            y = math.sin(polar) * math.sin(azimuthal)
            z = math.cos(polar)
            blue = int(
                tcod.noise_get_turbulence(noise3d, [x, y, z], 32.0) * 16.0 +
                16.0)
            green = int(tcod.noise_get(noise3d, [x, y, z]) * 8.0 + 8.0)
            red = int(tcod.noise_get_fbm(noise3d, [x, y, z], 32.0) * 4.0 + 4.0)
            background = tcod.Color(red, green, blue)

            if map_y == height / 2 or map_x == 0 or map_x == width / 2:
                background = tcod.darkest_yellow

            tcod.console_set_char_background(console, map_x, map_y, background)

    tcod.noise_delete(noise3d)
    return console
예제 #12
0
def _post_process_clouds(x, y, clouds, zoom, clouds_x, clouds_y, size,
                         sunlight, noise, inside):
    _noise_values = [(zoom * x / (constants.MAP_VIEW_WIDTH)) + clouds_x,
                     (zoom * y / (constants.MAP_VIEW_HEIGHT)) + clouds_y]
    _shade = tcod.noise_get_turbulence(noise, _noise_values,
                                       tcod.NOISE_SIMPLEX)
    _shade_mod = numbers.clip(abs(_shade), sunlight, 1)

    #TODO: Inside lighting
    #if not (camera.X+x, camera.Y+y) in inside:
    clouds[y][x] -= _shade_mod
    clouds[y][x] *= SHADOWS[camera.Y + y][camera.X + x].clip(SUNLIGHT - .5, 1)
    #else:
    #	clouds[y][x] *= SHADOWS[camera.Y+y][camera.X+x] #TODO: Inside lighting here

    #TODO: Future
    #clouds *= LIGHTS[camera.Y:camera.Y+y, camera.X:camera.X+x]

    clouds[y][x] *= LIGHTS[camera.Y + y, camera.X + x]
예제 #13
0
def activate(zone_id):
    global ACTIVE_ZONE

    ACTIVE_ZONE = zone_id

    _zone = ZONES[zone_id]
    _noise = tcod.noise_new(2)

    logging.info('Bringing zone \'%s\' online...' % _zone['name'])

    _zone['astar_map'] = pathfinding.setup(_zone['width'], _zone['height'],
                                           _zone['solids'])
    _zone['los_map'] = mapgen.generate_los_map(_zone['width'], _zone['height'],
                                               _zone['solids'])

    display.create_surface('tiles',
                           width=_zone['width'],
                           height=_zone['height'])

    maps.render_map(_zone['tile_map'], _zone['width'], _zone['height'])

    post_processing.start()

    events.register_event('logic', post_processing.tick_sun)

    _static_lighting = display.create_shader(_zone['width'],
                                             _zone['height'],
                                             start_offset=1)
    _zone['shaders'].append(
        post_processing.generate_shadow_map(_zone['width'], _zone['height'],
                                            _zone['solids'], _zone['trees'],
                                            _zone['inside']))
    _zone['shaders'].append(
        post_processing.generate_light_map(_zone['width'], _zone['height'],
                                           _zone['solids'], _zone['trees']))
    _zone['light_maps']['static_lighting'] = _static_lighting
    _zone['shaders'].append(_static_lighting)

    _noise = tcod.noise_new(3)
    _zoom = 2.0
    _zone['fader'] = display.create_shader(_zone['width'], _zone['height'])
    _shader = display.create_shader(_zone['width'], _zone['height'])

    for y in range(0, _zone['height']):
        for x in range(0, _zone['width']):
            if (x, y) in _zone['inside']:
                _height = .75
            else:
                _noise_values = [(_zoom * x / _zone['width']),
                                 (_zoom * y / _zone['height'])]
                _height = .35 + numbers.clip(
                    tcod.noise_get_turbulence(_noise, _noise_values,
                                              tcod.NOISE_SIMPLEX), .35, 1)

            _shader[0][y, x] = 1.3 * _height
            _shader[1][y, x] = 1.3 * _height
            _shader[2][y, x] = 1.1 * _height

    _zone['shaders'].append(_shader)

    for light in _zone['lights']:
        effects.light(light[0],
                      light[1],
                      light[2],
                      r=light[3],
                      g=light[4],
                      b=light[5],
                      light_map='static_lighting')

    #if not '--no-fx' in sys.argv:
    #	post_processing.run(time=8,
    #		                repeat=-1,
    #		                repeat_callback=lambda _: post_processing.post_process_clouds(constants.MAP_VIEW_WIDTH,
    #		                                                                              constants.MAP_VIEW_HEIGHT,
    #		                                                                              8,
    #		                                                                              _noise,
    #		                                                                              _zone['inside']))
    post_processing.run(
        time=0,
        repeat=-1,
        repeat_callback=lambda _: post_processing.post_process_lights())
    #post_processing.run(time=0,
    #                    repeat=-1,
    #                    repeat_callback=lambda _: post_processing.sunlight())

    camera.set_limits(0, 0, _zone['width'] - constants.MAP_VIEW_WIDTH,
                      _zone['height'] - constants.MAP_VIEW_HEIGHT)

    logging.info('Zone \'%s\' is online' % _zone['name'])
예제 #14
0
파일: zones.py 프로젝트: witheld9/r3-tdw
def activate(zone_id):
	global ACTIVE_ZONE
	
	ACTIVE_ZONE = zone_id
	
	_zone = ZONES[zone_id]
	_noise = tcod.noise_new(2)
	
	logging.info('Bringing zone \'%s\' online...' % _zone['name'])
	
	_zone['astar_map'] = pathfinding.setup(_zone['width'], _zone['height'], _zone['solids'])
	_zone['los_map'] = mapgen.generate_los_map(_zone['width'], _zone['height'], _zone['solids'])
	
	display.create_surface('tiles', width=_zone['width'], height=_zone['height'])
	
	maps.render_map(_zone['tile_map'], _zone['width'], _zone['height'])
	
	post_processing.start()
	
	events.register_event('logic', post_processing.tick_sun)
	
	_static_lighting = display.create_shader(_zone['width'], _zone['height'], start_offset=1)
	_zone['shaders'].append(post_processing.generate_shadow_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees'], _zone['inside']))
	_zone['shaders'].append(post_processing.generate_light_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees']))
	_zone['light_maps']['static_lighting'] = _static_lighting
	_zone['shaders'].append(_static_lighting)
	
	_noise = tcod.noise_new(3)
	_zoom = 2.0
	_zone['fader'] = display.create_shader(_zone['width'], _zone['height'])
	_shader = display.create_shader(_zone['width'], _zone['height'])
	
	for y in range(0, _zone['height']):
		for x in range(0, _zone['width']):
			if (x, y) in _zone['inside']:
				_height = .75
			else:
				_noise_values = [(_zoom * x / _zone['width']),
					             (_zoom * y / _zone['height'])]
				_height = .35 + numbers.clip(tcod.noise_get_turbulence(_noise, _noise_values, tcod.NOISE_SIMPLEX), .35, 1)
			
			_shader[0][y, x] = 1.3 * _height
			_shader[1][y, x] = 1.3 * _height
			_shader[2][y, x] = 1.1 * _height
	
	_zone['shaders'].append(_shader)
	
	for light in _zone['lights']:
		effects.light(light[0], light[1], light[2], r=light[3], g=light[4], b=light[5], light_map='static_lighting')
	
	#if not '--no-fx' in sys.argv:
	#	post_processing.run(time=8,
	#		                repeat=-1,
	#		                repeat_callback=lambda _: post_processing.post_process_clouds(constants.MAP_VIEW_WIDTH,
	#		                                                                              constants.MAP_VIEW_HEIGHT,
	#		                                                                              8,
	#		                                                                              _noise,
	#		                                                                              _zone['inside']))
	post_processing.run(time=0,
		                repeat=-1,
		                repeat_callback=lambda _: post_processing.post_process_lights())
	#post_processing.run(time=0,
	#                    repeat=-1,
	#                    repeat_callback=lambda _: post_processing.sunlight())
	
	camera.set_limits(0, 0, _zone['width']-constants.MAP_VIEW_WIDTH, _zone['height']-constants.MAP_VIEW_HEIGHT)
	
	logging.info('Zone \'%s\' is online' % _zone['name'])
예제 #15
0
def create():
    display.create_surface('background')
    display.create_surface('text')
    display.blit_background('background')

    roll()

    NOISE = tcod.noise_new(2,
                           h=tcod.NOISE_DEFAULT_HURST,
                           random=tcod.random_new())

    for y in range(0, constants.WINDOW_HEIGHT):
        for x in range(0, constants.WINDOW_WIDTH):
            _noise_values = [(ZOOM * x / (constants.WINDOW_WIDTH)),
                             (ZOOM * y / (constants.WINDOW_HEIGHT))]
            _height = 1 - tcod.noise_get_turbulence(NOISE, _noise_values,
                                                    tcod.NOISE_SIMPLEX)
            _dist_to_crosshair = 30
            _crosshair_mod = abs((_dist_to_crosshair - 1))

            if _height > .4:
                _height = (_height - .4) / .4
                _r, _g, _b = numbers.clip(30 * _height, 20,
                                          255), 50 * _height, numbers.clip(
                                              30 * _height, 30, 255)

            else:
                _r, _g, _b = 20, 0, 30

            _r += 30  # * _crosshair_mod

            if x < SIDEBAR_WIDTH:
                if y < 7:
                    _r = numbers.interp(_r, .0, .4)
                    _g = numbers.interp(_g, .0, .4)
                    _b = numbers.interp(_b, .0, .4)

                elif y < 43:
                    _r = numbers.interp(_r, .0, .6)
                    _g = numbers.interp(_g, .0, .6)
                    _b = numbers.interp(_b, .0, .6)

                elif y < constants.WINDOW_HEIGHT:
                    _r = numbers.interp(_r, 1, .7)
                    _g = numbers.interp(_g, 1, .7)
                    _b = numbers.interp(_b, 1, .7)

                else:
                    _r = (int(round(_r * 1.0)))
                    _g = (int(round(_g * .2)))
                    _b = (int(round(_b * .2)))

            if x > SIDEBAR_WIDTH + 3 and x < constants.WINDOW_WIDTH - 6:
                if y > 18 and y < 36:
                    _r = numbers.interp(_r, 255, .1)
                    _g = numbers.interp(_g, 255, .1)
                    _b = numbers.interp(_b, 255, .1)

            if x > SIDEBAR_WIDTH + 3 and x < constants.WINDOW_WIDTH - 6:
                if y > 10 and y < 16:
                    _r = numbers.interp(_r, .0, .4)
                    _g = numbers.interp(_g, .0, .4)
                    _b = numbers.interp(_b, .0, .4)

            display._set_char('background', x, y, ' ', (0, 0, 0), (_r, _g, _b))
예제 #16
0
def generate(width, height):
	_weight_map, _tile_map, _solids, _node_grid = mapgen.create_map(width, height)
	
	_c_x, _c_y = width/2, height/2
	_zoom = 1.2
	_noise = tcod.noise_new(3)
	_possible_trees = set()
	
	for y in range(height):
		for x in range(width):
			_c_dist = numbers.float_distance((x, y), (_c_x, _c_y)) / float(max([width, height]))
			_noise_values = [(_zoom * x / (constants.MAP_VIEW_WIDTH)),
					         (_zoom * y / (constants.MAP_VIEW_HEIGHT))]
			_noise_value = numbers.clip(tcod.noise_get_turbulence(_noise, _noise_values, tcod.NOISE_SIMPLEX) - .7, .5-_c_dist, 1)
			
			if _noise_value > .3:
				_tile = tiles.grass(x, y)
				_possible_trees.add((x, y))
				
			elif _noise_value > .2:
				if random.uniform(.2, .3) + (_noise_value-.2) > .3:
					if _c_dist < .35:
						_tile = tiles.grass(x, y)
						_possible_trees.add((x, y))
					else:
						_tile = tiles.grass(x, y)
						_possible_trees.add((x, y))
				else:
					#TODO: Slowly dither in swamp water
					if _c_dist < .35:
						_tile = tiles.swamp_water(x, y)
					else:
						_tile = tiles.swamp_water(x, y)
			
			elif _noise_value >= 0:
				_r_val = random.uniform(0, .2) + (_noise_value)
				
				if _r_val > .2:
					_tile = tiles.swamp_water(x, y)
				else:
					if random.uniform(0, .2) + (_noise_value) > .2:
						_tile = tiles.swamp_water(x, y)
					else:
						_tile = tiles.tall_grass(x, y)
			
			elif _noise_value < 0:
				_tile = tiles.tall_grass(x, y)
				_possible_trees.add((x, y))
			
			else:
				_tile = tiles.swamp(x, y)
				
			_tile_map[y][x] = _tile
			_weight_map[y][x] = _tile['w']
	
	#############
	#Trader camp#
	#############
	
	_s_x, _s_y = ((width/2)-20, (height/2)-20)
	_building_space = set()
	_walls = set()
	
	#Building
	_width, _height = random.choice([(20, 20), (12, 20), (20, 12)])
	_random_dir = random.randint(0, 3)
	
	if _random_dir == 1:
		_door_x = _width / 2
		_door_y = 0
	
	elif _random_dir == 2:
		_door_x = _width / 2
		_door_y = _height
	
	elif _random_dir == 3:
		_door_x = 0
		_door_y = _height / 2
	
	else:
		_door_x = _width
		_door_y = _height / 2
	
	if _width > _height:
		if _random_dir in [1, 3]:
			_mod = .75
		else:
			_mod = .25
		
		_trade_room_x = int(round(_width * _mod))
		_trade_room_y = -1
		_trade_window_x = _trade_room_x
		_trade_window_y = _height / 2
	else:
		if _random_dir == 1:
			_mod = .75
		else:
			_mod = .25
		
		_trade_room_x = -1
		_trade_room_y = int(round(_height * _mod))
		_trade_window_x = _width / 2
		_trade_window_y = _trade_room_y
	
	for y in range(_height+1):
		_y = _s_y+y
		
		for x in range(_width+1):
			_x = _s_x+x
			
			if (x, y) == (_door_x, _door_y):
				_tile = tiles.concrete(_x, _y)
			
			elif x == 0 or y == 0 or x == _width or y == _height:
				_tile = tiles.wooden_fence(_x, _y)
				_solids.add((_x, _y))
				_walls.add((_x, _y))
			
			else:
				if x == _trade_window_x and y == _trade_window_y:
					_tile = tiles.trade_window(_x, _y)
					
				elif x == _trade_room_x or y == _trade_room_y:
					_tile = tiles.wooden_fence(_x, _y)
					_solids.add((_x, _y))
					_walls.add((_x, _y))
				
				else:
					_tile = tiles.wood_floor(_x, _y)
			
			_weight_map[_y][_x] = _tile['w']
			_tile_map[_y][_x] = _tile
			_building_space.add((_x, _y))
	
	#Wall
	_width, _height = _width * 4, _height * 4
	_ground_space = set()
	
	for y in range(_height + 1):
		_y = _s_y + y
		_yy = _y - int(round(_height * .4))
		
		for x in range(_width + 1):
			_x = _s_x + x
			_xx = _x - int(round(_width * .4))
			
			if random.uniform(0, 1) >= .75:
				continue
			
			if x == 0 or y == 0 or x == _width or y == _height:
				_tile = tiles.wooden_fence(_xx, _yy)
			else:
				if (_xx, _yy) in _building_space:
					continue
				
				_ground_space.add((_xx, _yy))
				
				continue
			
			_weight_map[_yy][_xx] = _tile['w']
			_tile_map[_yy][_xx] = _tile
			_solids.add((_xx, _yy))
	
	#Ground: Inside wall - outside building
	_ground_seeds = random.sample(list(_ground_space - _building_space), 50)
	
	for x, y in _ground_seeds:
		_walker_x = x
		_walker_y = y
		_last_dir = -2, -2
		
		for i in range(random.randint(80, 90)):
			_tile = tiles.concrete_striped(_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]
			
			while (_n_x, _n_y) in _building_space or (_n_x, _n_y) in _solids or _last_dir == _dir:
				_dir = random.randint(-1, 1), random.randint(-1, 1)
				_n_x = _walker_x + _dir[0]
				_n_y = _walker_y + _dir[1]
			
			_last_dir = _dir[0] * -1, _dir[0] * -1
			_walker_x = _n_x
			_walker_y = _n_y
	
	#Bushes around outside wall
	
	#Campfires

	"""for room in _rooms:
		_build_doors = []

		for plot_x, plot_y in room['plots']:
			_room = _building[(plot_x, plot_y)]
			_build_walls = ['north', 'south', 'east', 'west']

			for n_plot_x, n_plot_y in [(plot_x-1, plot_y), (plot_x+1, plot_y), (plot_x, plot_y-1), (plot_x, plot_y+1)]:
				if ((n_plot_x, n_plot_y) == _room['door_plot']) or (not _build_doors and not (n_plot_x, n_plot_y) in room['plots'] and (n_plot_x, n_plot_y) in _building):
					if n_plot_x - plot_x == -1:
						_build_doors.append('west')

						if 'west' in _build_walls:
							_build_walls.remove('west')

					elif n_plot_x - plot_x == 1:
						_build_doors.append('east')

						if 'east' in _build_walls:
							_build_walls.remove('east')

					if n_plot_y - plot_y == -1:
						_build_doors.append('north')

						if 'north' in _build_walls:
							_build_walls.remove('north')

					elif n_plot_y - plot_y == 1:
						_build_doors.append('south')

						if 'south' in _build_walls:
							_build_walls.remove('south')

				if (n_plot_x, n_plot_y) in _building:
					if n_plot_x - plot_x == -1 and not _building[(n_plot_x, n_plot_y)]['type'] in buildinggen.ROOM_TYPES[room['type']]['avoid_rooms']:
						if 'west' in _build_walls:
							_build_walls.remove('west')

					elif n_plot_x - plot_x == 1 and not _building[(n_plot_x, n_plot_y)]['type'] in buildinggen.ROOM_TYPES[room['type']]['avoid_rooms']:
						if 'east' in _build_walls:
							_build_walls.remove('east')

					if n_plot_y - plot_y == -1 and not _building[(n_plot_x, n_plot_y)]['type'] in buildinggen.ROOM_TYPES[room['type']]['avoid_rooms']:
						if 'north' in _build_walls:
							_build_walls.remove('north')

					elif n_plot_y - plot_y == 1 and not _building[(n_plot_x, n_plot_y)]['type'] in buildinggen.ROOM_TYPES[room['type']]['avoid_rooms']:
						if 'south' in _build_walls:
							_build_walls.remove('south')

			_x, _y = (_s_x + (plot_x*_room_size)), (_s_y + (plot_y*_room_size))

			for y in range(_y, _y+_room_size):
				for x in range(_x, _x+_room_size):
					if ((x-_x == 0 and 'west' in _build_walls) or (y-_y == 0 and 'north' in _build_walls) or (x-_x == _room_size-1 and 'east' in _build_walls) or (y-_y == _room_size-1 and 'south' in _build_walls)):
						_weight_map[y][x] = _tile['w']
						_tile_map[y][x] = tiles.wooden_fence(x, y)
						_solids.add((x, y))

					else:
						_tile_map[y][x] = buildinggen.ROOM_TYPES[room['type']]['tiles'](x, y)
						_building_space.add((x, y))

			for y in range(_y, _y+_room_size):
				for x in range(_x-1, _x+_room_size+1):
					if (x-_x in [-1, 0] and 'west' in _build_doors and (y-_y<=2 or y-_y>=_room_size-3)) or (x-_x in [_room_size, _room_size+1] and 'east' in _build_doors and (y-_y<=2 or y-_y>=_room_size-3)):
						_weight_map[y][x] = _tile['w']
						_tile_map[y][x] = tiles.wooden_fence(x, y)

						_solids.add((x, y))

			for y in range(_y-1, _y+_room_size+1):
				for x in range(_x, _x+_room_size):
					if (y-_y in [-1, 0] and 'north' in _build_doors and (x-_x<=2 or x-_x>=_room_size-3)) or (y-_y in [_room_size, _room_size+1] and 'south' in _build_doors and (x-_x<=2 or x-_x>=_room_size-3)):
						_weight_map[y][x] = _tile['w']
						_tile_map[y][x] = tiles.wooden_fence(x, y)
						_solids.add((x, y))

			_last_plot_x, _last_plot_y = plot_x, plot_y

	#TODO: Make this into a function?
	_min_x, _max_x = (width, 0)
	_min_y, _max_y = (height, 0)

	for x, y in _building:
		_x, _y = (_s_x + (x*_room_size)), (_s_y + (y*_room_size))

		if _x > _max_x:
			_max_x = _x

		if _x < _min_x:
			_min_x = _x

		if _y > _max_y:
			_max_y = _y

		if _y < _min_y:
			_min_y = _y"""

	_plot_pole_x, _plot_pole_y = _s_x, _s_y
	_tree_plots = _possible_trees - _solids
	_tree_plots = list(_tree_plots - _building_space)
	_trees = {}
	_used_trees = random.sample(_tree_plots, numbers.clip(int(round((width * height) * .001)), 0, len(_tree_plots)))
	_bush_plots = set(_tree_plots) - set(_used_trees)
	_used_bush = random.sample(_bush_plots, numbers.clip(int(round((width * height) * .003)), 0, len(_bush_plots)))
	_swamp_plots = set(_tree_plots) - set(_used_bush)
	_used_swamp = random.sample(_swamp_plots, numbers.clip(int(round((width * height) * .003)), 0, len(_swamp_plots)))
	
	for x, y in _used_trees:
		_size = random.randint(7, 12)
		_trees[x, y] = _size
		
		for w in range(random.randint(1, 2)):
			_walker_x = x
			_walker_y = y
			_walker_direction = random.randint(0, 359)
			
			for i in range(random.randint(_size/4, _size/2)):
				_actual_x, _actual_y = int(round(_walker_x)), int(round(_walker_y))
				
				if _actual_x < 0 or _actual_y < 0 or _actual_x >= width or _actual_y >= height or (_actual_x, _actual_y) in _solids:
					break
				
				_center_mod = numbers.float_distance((_actual_x, _actual_y), (x, y)) / float(_size)
				_tile = tiles.tree(_actual_x, _actual_y)
				_weight_map[_actual_y][_actual_x] = _tile['w']
				_tile_map[_actual_y][_actual_x] = _tile
				
				if random.randint(0, 3):
					_trees[_actual_x, _actual_y] = random.randint(1, _size)
				
				_solids.add((_actual_x, _actual_y))
				_walker_direction += random.randint(-45, 45)
				_n_x, _n_y = numbers.velocity(_walker_direction, 1)
				
				_walker_x += _n_x
				_walker_y += _n_y
	
	for x, y in _used_bush:
		_center_mod = numbers.float_distance((x, y), (_plot_pole_x, _plot_pole_y)) / 60.0
		_walker_x = x
		_walker_y = y
		
		for i in range(int(round(random.randint(44, 55) * _center_mod))):
			_tile = tiles.swamp_water(_walker_x, _walker_y)
			_weight_map[_walker_y][_walker_x] = _tile['w']
			_tile_map[_walker_y][_walker_x] =_tile
			
			_walker_x += random.randint(-1, 1)
			_walker_y += random.randint(-1, 1)
			
			if _walker_x < 0 or _walker_y < 0 or _walker_x >= width or _walker_y >= height or (_walker_x, _walker_y) in _solids:
				break
	
	for x, y in _used_swamp:
		_center_mod = numbers.float_distance((x, y), (_plot_pole_x, _plot_pole_y)) / 120.0
		_walker_x = x
		_walker_y = y
		
		for i in range(int(round(random.randint(44, 55) * (1-_center_mod)))):
			_tile = tiles.swamp(_walker_x, _walker_y)
			_weight_map[_walker_y][_walker_x] = _tile['w']
			_tile_map[_walker_y][_walker_x] =_tile
			
			_walker_x += random.randint(-1, 1)
			_walker_y += random.randint(-1, 1)
			
			if _walker_x < 0 or _walker_y < 0 or _walker_x >= width or _walker_y >= height or (_walker_x, _walker_y) in _solids:
				break

	mapgen.build_node_grid(_node_grid, _solids)
	mapgen.add_plot_pole(_plot_pole_x, _plot_pole_y, 40, _solids)
	
	_fsl = {'Terrorists': {'bases': 1, 'squads': 0, 'trader': True, '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
예제 #17
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
예제 #18
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
예제 #19
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
예제 #20
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
예제 #21
0
파일: worldgen.py 프로젝트: penny64/r3-tdw
def create_map():
	_grid = world_strategy.MAP['grid']
	_color_map = world_strategy.MAP['color_map']
	_ownable_plots = set()
	_banned_plots = set()
	
	#Mountains
	_noise = tcod.noise_new(3)
	_zoom = 1.25
	_c_pos = constants.STRAT_MAP_WIDTH/2, constants.STRAT_MAP_HEIGHT/2
	_solids = set()
	
	for y in range(0, constants.STRAT_MAP_HEIGHT):
		for x in range(0, constants.STRAT_MAP_WIDTH):
			_m_x = x / constants.MAP_CELL_SPACE
			_m_y = y / constants.MAP_CELL_SPACE
			
			_m_x = numbers.clip(_m_x, 1, (constants.STRAT_MAP_WIDTH/constants.MAP_CELL_SPACE) - 2)
			_m_y = numbers.clip(_m_y, 1, (constants.STRAT_MAP_HEIGHT/constants.MAP_CELL_SPACE) - 2)
			_c_mod = numbers.float_distance(_c_pos, (x, y))/max([constants.STRAT_MAP_WIDTH/2, constants.STRAT_MAP_HEIGHT/2])
			_noise_values = [(_zoom * x / (constants.STRAT_MAP_WIDTH)),
					         (_zoom * y / (constants.STRAT_MAP_HEIGHT))]
			_height = tcod.noise_get_turbulence(_noise, _noise_values, tcod.NOISE_SIMPLEX) * _c_mod
			_char = ' '
			
			#Mountain
			if _height > .55:
				_color_map[x, y] = random.choice([constants.DARKER_GRAY_1,
				                                  constants.DARKER_GRAY_2,
				                                  constants.DARKER_GRAY_3])
				
				_grid[_m_x, _m_y]['is_ownable'] = False
				_banned_plots.add((_m_x, _m_y))
				
				_c_1 = int(round(_color_map[x, y][0] * (1.8 * _height)))
				_c_2 = int(round(_color_map[x, y][1] * (1.8 * _height)))
				_c_3 = int(round(_color_map[x, y][2] * (1.8 * _height)))
			
			else:
				_color_map[x, y] = random.choice([constants.FOREST_GREEN_1,
				                                  constants.FOREST_GREEN_2,
				                                  constants.FOREST_GREEN_3])
				
				_ownable_plots.add((_m_x, _m_y))

				if _height <= .2:
					_char = random.choice([',', '.', '\'', ' ' * (1 + (20 * int(round(_height))))])
				
				_height -= .1

				_c_1 = int(round(_color_map[x, y][0] * (.7 + _height * 2.8)))
				_c_2 = int(round(_color_map[x, y][1] * (1.0 + _height * .9)))
				_c_3 = int(round(_color_map[x, y][2] * (.75 + _height * 1.2)))
			
			display._set_char('map', x, y, _char, (int(round(_c_1 * .8)), int(round(_c_2 * .8)), int(round(_c_3 * .8))), (_c_1, _c_2, _c_3))
	
	_solids = [(x, y) for x, y in list(_banned_plots)]
	
	world_strategy.MAP['astar_map'] = pathfinding.setup(constants.STRAT_MAP_WIDTH/constants.MAP_CELL_SPACE,
	                                                    constants.STRAT_MAP_HEIGHT/constants.MAP_CELL_SPACE,
	                                                    _solids)
	
	return list(_ownable_plots - _banned_plots)