Example #1
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_direction = 270
    _turn_rate = random.randint(-1, 1)
    _river_tiles = set()
    _river_size = random.randint(7, 10)
    _ground_tiles = set()
    _possible_camps = set()
    _trees = {}
    _blueprint = sculpted.create_blueprint(sculpted.ROOMS)
    _room_size = 17
    _door_width = 1
    _place_x, _place_y = 5, 10
    _floor = set()
    _lights = []
    _spawns = {'defending': set(), 'attacking': set()}
    #_room_bitmask_maps = {}

    _min_door_pos = (_room_size / 2) - _door_width
    _max_door_pos = (_room_size / 2) + _door_width

    for y in range(_blueprint['height']):
        for x in range(_blueprint['width']):
            _o_bitmask = _blueprint['bitmask_map'][y, x]
            _bitmask = _blueprint['bitmask_map'][y, x]
            _door_bitmask = _blueprint['bitmask_door_map'][y, x]

            if not _bitmask:
                continue

            if _bitmask < 100:
                _bitmask += 100

            else:
                _room_name = _blueprint['room_lookup'][_blueprint['room_map'][
                    y, x]]
                _wall_offset = 0  #Don't even think about touching this...
                _wall_padding = range(
                    _blueprint['rooms'][_room_name]['wall_padding'] + 1)
                _wall_padding_actual = range(
                    _wall_offset,
                    _blueprint['rooms'][_room_name]['wall_padding'] + 1)
                _wall_padding_2_actual = [(_room_size - 1) - i for i in range(
                    _wall_offset,
                    _blueprint['rooms'][_room_name]['wall_padding'] + 1)]
                _wall_padding_2 = [(_room_size - 1) - i for i in range(
                    _blueprint['rooms'][_room_name]['wall_padding'] + 1)]
                _wall_padding_3 = range(
                    _blueprint['rooms'][_room_name]['doorway_padding'] + 1)
                _wall_padding_3_actual = range(
                    _wall_offset,
                    _blueprint['rooms'][_room_name]['doorway_padding'] + 1)
                _wall_padding_4 = [(_room_size - 1) - i for i in range(
                    _blueprint['rooms'][_room_name]['doorway_padding'] + 1)]
                _wall_padding_4_actual = [(_room_size - 1) - i for i in range(
                    _wall_offset,
                    _blueprint['rooms'][_room_name]['doorway_padding'] + 1)]
                _wall_bitmask = 0

                logging.debug('Building: %s' % _room_name)

                if _o_bitmask > 100 and _o_bitmask < 200:
                    _wall_bitmask = _o_bitmask

            for y1 in range(_room_size):
                for x1 in range(_room_size):
                    _placed = False
                    _p_x, _p_y = (x * _room_size) + x1, (y * _room_size) + y1

                    if _o_bitmask > 100 and _o_bitmask < 200:
                        if y1 in _wall_padding and not _bitmask in [
                                101, 103, 105, 107, 109, 111, 113, 115
                        ]:
                            if y1 in _wall_padding_actual:
                                _solids.add((_place_x + _p_x, _place_y + _p_y))

                            _placed = True

                        elif y1 in _wall_padding_2 and not _bitmask in [
                                104, 105, 106, 107, 112, 113, 114, 115
                        ]:
                            if y1 in _wall_padding_2_actual:
                                _solids.add((_place_x + _p_x, _place_y + _p_y))

                            _placed = True

                        if x1 in _wall_padding_2 and not _bitmask in [
                                102, 103, 106, 107, 110, 111, 114, 115
                        ]:
                            if x1 in _wall_padding_2_actual:
                                _solids.add((_place_x + _p_x, _place_y + _p_y))

                            _placed = True

                        elif x1 in _wall_padding and not _bitmask in [
                                108, 109, 110, 111, 112, 113, 114, 115
                        ]:
                            if x1 in _wall_padding_actual:
                                _solids.add((_place_x + _p_x, _place_y + _p_y))

                            _placed = True

                    else:
                        if y1 == 0 and _bitmask in [
                                101, 103, 105, 107, 109, 111, 113, 115
                        ]:
                            _solids.add((_place_x + _p_x, _place_y + _p_y))
                            _placed = True

                        elif y1 == _room_size - 1 and _bitmask in [
                                104, 105, 106, 107, 112, 113, 114, 115
                        ]:
                            _solids.add((_place_x + _p_x, _place_y + _p_y))
                            _placed = True

                        if x1 == _room_size - 1 and _bitmask in [
                                102, 103, 106, 107, 110, 111, 114, 115
                        ]:
                            _solids.add((_place_x + _p_x, _place_y + _p_y))
                            _placed = True

                        elif x1 == 0 and _bitmask in [
                                108, 109, 110, 111, 112, 113, 114, 115
                        ]:
                            _solids.add((_place_x + _p_x, _place_y + _p_y))
                            _placed = True

                    if not _placed and _o_bitmask > 100 and not _door_bitmask:
                        _floor.add(
                            (_place_x + _p_x, _place_y + _p_y, _room_name))

                    elif _door_bitmask:
                        _doorway_placed = False

                        if y1 in _wall_padding_3 and _door_bitmask in [
                                101, 103, 105, 107, 109, 111, 113, 115
                        ]:
                            if x1 < _min_door_pos or x1 > _max_door_pos:
                                #if x1 in _wall_padding_3_actual:
                                _solids.add((_place_x + _p_x, _place_y + _p_y))
                                _doorway_placed = True

                            elif (_place_x + _p_x, _place_y + _p_y) in _solids:
                                _solids.remove(
                                    (_place_x + _p_x, _place_y + _p_y))

                        elif y1 in _wall_padding_4 and _door_bitmask in [
                                104, 105, 106, 107, 112, 113, 114, 115
                        ]:
                            if x1 < _min_door_pos or x1 > _max_door_pos:
                                _solids.add((_place_x + _p_x, _place_y + _p_y))
                                _doorway_placed = True

                            elif (_place_x + _p_x, _place_y + _p_y) in _solids:
                                _solids.remove(
                                    (_place_x + _p_x, _place_y + _p_y))

                        if x1 in _wall_padding_4 and _door_bitmask in [
                                102, 103, 106, 107, 110, 111, 114, 115
                        ]:
                            if y1 < _min_door_pos or y1 > _max_door_pos:
                                _solids.add((_place_x + _p_x, _place_y + _p_y))
                                _doorway_placed = True

                            elif (_place_x + _p_x, _place_y + _p_y) in _solids:
                                _solids.remove(
                                    (_place_x + _p_x, _place_y + _p_y))

                        elif x1 in _wall_padding_3 and _door_bitmask in [
                                108, 109, 110, 111, 112, 113, 114, 115
                        ]:
                            if y1 < _min_door_pos or y1 > _max_door_pos:
                                _solids.add((_place_x + _p_x, _place_y + _p_y))
                                _doorway_placed = True

                            elif (_place_x + _p_x, _place_y + _p_y) in _solids:
                                _solids.remove(
                                    (_place_x + _p_x, _place_y + _p_y))

                        if not _doorway_placed and not _placed:
                            _floor.add(
                                (_place_x + _p_x, _place_y + _p_y, _room_name))

    _lookup = {(0, -1): 1, (1, 0): 2, (0, 1): 4, (-1, 0): 8}

    _new_floors, _new_solids, _windows, _new_lights, _new_spawns = roomgen.spawn_items(
        _blueprint['rooms'], _blueprint['bitmask_map'],
        _blueprint['bitmask_door_map'], _floor, _solids, _room_size,
        _room_size, (_place_x, _place_y), _tile_map, _weight_map)
    _floor_new = set()

    for x, y, room_name in _floor.copy():
        _floor_new.add((x, y))

    _spawns['defending'].update(_new_spawns)
    _spawns['attacking'].add((70, 5))
    _floor = _floor_new
    _floor.update(_new_floors)
    _solids.update(_new_solids)
    _remove_solids = set()
    _solids = _solids - _windows
    _lights.extend(_new_lights)

    for x, y in _solids:
        #_count = 0
        _delete = True

        for x1, y1 in [(0, -1), (1, 0), (0, 1), (-1, 0), (-1, -1), (1, -1),
                       (-1, 1), (1, 1)]:
            _x = x + x1
            _y = y + y1

            if (_x, _y) in _floor:
                _delete = False
                #_count += 1

        if _delete:
            _remove_solids.add((x, y))
            _ground_tiles.add((x, y))

    _solids = _solids - _remove_solids

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

            _ground_tiles.add((x, y))

    #This generates the outside walls
    for pos in _solids:
        _tile = tiles.wooden_fence(pos[0], pos[1])
        _tile_map[pos[1]][pos[0]] = _tile
        _weight_map[pos[1]][pos[0]] = _tile['w']

    _ground_tiles = _ground_tiles - _windows

    for x, y in _ground_tiles - _floor:
        _tile = tiles.grass(x, y)
        _tile_map[y][x] = _tile
        _weight_map[y][x] = _tile['w']

    mapgen.build_node_grid(_node_grid, _solids)
    _floor.update(_windows)

    return width, height, _node_grid, mapgen.NODE_SETS.copy(
    ), _weight_map, _tile_map, _solids, {}, _trees, _floor, _lights, _spawns
Example #2
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 #3
0
def spawn_items(room_list, bitmask_map, bitmask_door_map, floor_list, solids, room_size, divisor, offsets, tile_map, weight_map):
	_item_positions = set()
	_placed_map = numpy.zeros((room_size, room_size))
	_room_spawns = {}
	_floors = set()
	_solids = set()
	_windows = set()
	_lights = []
	_spawn_positions = set()
	
	for x, y, room_name in floor_list:
		_r_x, _r_y = (x - offsets[0]) / divisor, (y - offsets[1]) / divisor
		_room = room_list[room_name]
		_room_x, _room_y = (x / room_size) * room_size, (y / room_size) * room_size
		
		if not room_name in _room_spawns:
			_room_spawns[room_name] = {}
		
		if not (_r_x, _r_y) in _room_spawns[room_name]:
			_room_spawns[room_name][_r_x, _r_y] = {'against_wall': set(),
			                                       'away_from_wall': set(),
			                                       'floor': set(),
			                                       'direction': None,
			                                       'width': 0,
			                                       'height': 0,
			                                       'min_x': 9999,
			                                       'max_x': 0,
			                                       'min_y': 9999,
			                                       'max_y': 0}
			
		
		_spawn_list = _room_spawns[room_name][_r_x, _r_y]
		_hit_solid = False
		
		if x < _spawn_list['min_x']:
			_spawn_list['min_x'] = x
		
		if x > _spawn_list['max_x']:
			_spawn_list['max_x'] = x
		
		if y < _spawn_list['min_y']:
			_spawn_list['min_y'] = y
		
		if y > _spawn_list['max_y']:
			_spawn_list['max_y'] = y
		
		for x1, y1 in [(0, -1), (1, 0), (0, 1), (-1, 0)]:
			_neighbor_x, _neighbor_y = x + x1, y + y1
			
			if _neighbor_x < _room_x or _neighbor_x >= _room_x + room_size or _neighbor_y < _room_y or _neighbor_y >= _room_y + room_size:
				continue
			
			if (_neighbor_x, _neighbor_y) in solids:
				_spawn_list['against_wall'].add((x, y))
				_hit_solid = True
		
		if not _hit_solid:
			_spawn_list['away_from_wall'].add((x, y))
		
		_spawn_list['floor'].add((x, y))
	
	for room_name in _room_spawns:
		_rooms = _room_spawns[room_name]
		#_min_x = 9999
		#_max_x = 0
		#_min_y = 9999
		#_max_y = 0
		
		for r_x, r_y in _rooms:
			_spawns = _rooms[r_x, r_y]
			_spawns['width'] = _spawns['max_x'] - _spawns['min_x']
			_spawns['height'] = _spawns['max_y'] - _spawns['min_y']
			
			if _spawns['width'] > _spawns['height']:
				_spawns['direction'] = 'horizontal'
			
			else:
				_spawns['direction'] = 'vertical'
			
			#if _spawns['min_x'] < _min_x:
			#	_min_x = _spawns['min_x']
			
			#if _spawns['min_y'] < _min_y:
			#	_min_y = _spawns['min_y']
			
			#if _spawns['max_x'] > _max_x:
			#	_max_x = _spawns['max_x']
			
			#if _spawns['max_y'] > _max_y:
			#	_max_y = _spawns['max_y']
		
		#_width_of_all_rooms = _max_x - _min_x
		#height_of_all_rooms = _max_y - _min_y
	
	for room_name in _room_spawns:
		_rooms = _room_spawns[room_name]
		
		for r_x, r_y in _rooms:
			_wall_bitmask = bitmask_map[r_y, r_x]
			_door_bitmask = bitmask_door_map[r_y, r_x]
			_spawns = _rooms[r_x, r_y]
			_new_floor = set()
			
			if room_name == 'bunks':
				print 'Spawn here:', _wall_bitmask
				
				if _wall_bitmask in [105]:
					for x, y in _spawns['against_wall']:
						if not y % 4:
							_solids.add((x, y))
							
							for x1, y1 in list(neighbors_in_any_sets(x, y, [_spawns['against_wall'], _spawns['away_from_wall']])):
								if (x1, y1) in _item_positions:
									continue
								
								_solids.add((x1, y1))
				
				elif _wall_bitmask in [110]:
					for x, y in _spawns['against_wall']:
						if not x % 4:
							_solids.add((x, y))
							
							for x1, y1 in list(neighbors_in_any_sets(x, y, [_spawns['against_wall'], _spawns['away_from_wall']])):
								if (x1, y1) in _item_positions:
									continue
								
								_solids.add((x1, y1))
			
			elif room_name == 'landing':
				_carpet = set()
				
				for x, y in _spawns['floor']:
					_xx = x - _spawns['min_x']
					_yy = y - _spawns['min_y']
					
					if _xx == _spawns['width'] / 2 and _yy == _spawns['height'] / 2:
						_lights.append((x, y, 16, 1.5, 1.5, 1.5))
					
					if _spawns['width'] * .15 < _xx < _spawns['width'] * .85 and _spawns['height'] * .15 < _yy < _spawns['height'] * .85:
						if _xx < _spawns['width'] * .3 or _xx > _spawns['width'] * .7 or _yy < _spawns['height'] * .3 or _yy > _spawns['height'] * .7:
							if random.uniform(0, 1) > .5:
								_tile = tiles.carpet_light_blue(x, y)
								_carpet.add((x, y))
							
							else:
								_tile = tiles.carpet_blue(x, y)
								_carpet.add((x, y))
						
						else:
							_tile = tiles.carpet_burgandy_specs(x, y)
							_carpet.add((x, y))
					
					elif _spawns['width'] * .10 < _xx < _spawns['width'] * .90 and _spawns['height'] * .10 < _yy < _spawns['height'] * .90:
						_tile = tiles.carpet_burgandy(x, y)
						_carpet.add((x, y))
					
					else:
						_tile = tiles.carpet_brown(x, y)
					
					tile_map[y][x] = _tile
					weight_map[y][x] = _tile['w']
					
					_new_floor.add((x, y))
				
				#Placing tables
				_placed_tables = set()
				
				for x, y in _spawns['against_wall']:
					if neighbors_in_set(x, y, [_carpet]):
						continue
					
					if random.uniform(0, 1) > .87:
						if neighbors_in_set(x, y, _placed_tables):
							continue
						
						_neighbors = neighbors_in_set(x, y, _spawns['against_wall'])
						
						if len(_neighbors) >= 2:
							_neighbors.add((x, y))
							_placed_tables.add(tuple(_neighbors))
				
				_windows_placed = 0
				
				for table in _placed_tables:
					_temp_windows = set()
					
					for x, y in table:
						_tile = tiles.countertop(x, y)
						tile_map[y][x] = _tile
						weight_map[y][x] = _tile['w']
						
						_wood_blocks = set()
						_new_floor.add((x, y))
						
						for x1, y1 in neighbors_in_set(x, y, _spawns['floor'], diag=True) - neighbors_in_set(x, y, table, diag=True):
							_tile = tiles.wood_block(x1, y1)
							tile_map[y1][x1] = _tile
							weight_map[y1][x1] = _tile['w']
							
							_new_floor.add((x1, y1))
							_wood_blocks.add((x1, y1))
						
						if _windows_placed > 2:
							continue
						
						for x1, y1 in neighbors_in_set(x, y, solids, diag=True):
							_temp_windows.add((x1, y1))
					
					_windows_placed += 1
					
					for x, y in _temp_windows:
						pass
						#if neighbors_in_set(x, y, solids) - neighbors_in_set(x, y, _temp_windows):
						#	break
					else:
						for x, y in _temp_windows:
							_tile = tiles.water(x, y)
							tile_map[y][x] = _tile
							weight_map[y][x] = _tile['w']
						
						_windows.update(_temp_windows)
			
			elif room_name == 'hall':
				_pillars = set()
				
				if _door_bitmask:
					_xx = _spawns['min_x'] + int(round((_spawns['width'] * .5))) - 1
					_yy = _spawns['min_y'] + int(round((_spawns['height'] * .5))) - 1
					
					for x1, y1 in [(0, 0), (1, 0), (0, 1), (1, 1)]:
						_solids.add((_xx + x1, _yy + y1))
						_pillars.add((_xx + x1, _yy + y1))
				
				else:
					for x, y in [(_spawns['min_x'] + 2, _spawns['min_y'] + 2),
					             (_spawns['min_x'] + 2, _spawns['min_y'] + _spawns['height'] - 3)]:
						for x1, y1 in [(0, 0), (1, 0), (0, 1), (1, 1)]:
							_solids.add((x + x1, y + y1))
							_pillars.add((x + x1, y + y1))
				
				for x, y in _spawns['floor'] - _spawns['away_from_wall']:
					if (x, y) in _pillars:
						continue
					
					_tile = tiles.wood_floor(x, y)
					tile_map[y][x] = _tile
					weight_map[y][x] = _tile['w']
					
					_new_floor.add((x, y))
					#_solids.add((x, y))
			
			elif room_name == 'lab':
				#_x_split = 0
				#_y_split = 0
				
				#print _spawns['direction'], r_x, r_y
				#if _spawns['direction'] == 'horizontal':
				#	_start_x_dist_split = 6
				#	_start_y_dist_split = 4
				
				#else:
				#	_start_x_dist_split = 4
				#	_start_y_dist_split = 5
				
				#for dist_split in range(_start_x_dist_split, 9):
				#	if not _spawns['width'] % (dist_split):
				#		_x_split = dist_split
				#		
				#		break
				
				
				#for dist_split in range(_start_y_dist_split, 9):
				#	if not _spawns['height'] % (dist_split):
				#		_y_split = dist_split
				#		
				#		break
				
				for x, y in get_corner_points(_spawns):
					for m_x, m_y in [(0, 0), (1, 0), (0, 1), (1, 1)]:
						_x = x + m_x
						_y = y + m_y
						
						_tile = tiles.carpet_burgandy(_x, _y)
						tile_map[_y][_x] = _tile
						weight_map[_y][_x] = _tile['w']
						_new_floor.add((_x, _y))
			
			_floor_tiles = _spawns['floor'] - _solids
			_floor_tiles = _floor_tiles - _new_floor
			
			for x, y in list(_floor_tiles):
				_tile = room_list[room_name]['tile'](x, y)
				tile_map[y][x] = _tile
				weight_map[y][x] = _tile['w']
				_spawn_positions.add((x, y))
			
			for x, y in list(_solids):
				_tile = tiles.wooden_fence(x, y)
				tile_map[y][x] = _tile
				weight_map[y][x] = _tile['w']
			
			_floors.update(_floor_tiles)
	
	return _floors, _solids, _windows, _lights, _spawn_positions
Example #4
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 #5
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
Example #6
0
def spawn_items(room_list, bitmask_map, bitmask_door_map, floor_list, solids,
                room_size, divisor, offsets, tile_map, weight_map):
    _item_positions = set()
    _placed_map = numpy.zeros((room_size, room_size))
    _room_spawns = {}
    _floors = set()
    _solids = set()
    _windows = set()
    _lights = []
    _spawn_positions = set()

    for x, y, room_name in floor_list:
        _r_x, _r_y = (x - offsets[0]) / divisor, (y - offsets[1]) / divisor
        _room = room_list[room_name]
        _room_x, _room_y = (x / room_size) * room_size, (y /
                                                         room_size) * room_size

        if not room_name in _room_spawns:
            _room_spawns[room_name] = {}

        if not (_r_x, _r_y) in _room_spawns[room_name]:
            _room_spawns[room_name][_r_x, _r_y] = {
                'against_wall': set(),
                'away_from_wall': set(),
                'floor': set(),
                'direction': None,
                'width': 0,
                'height': 0,
                'min_x': 9999,
                'max_x': 0,
                'min_y': 9999,
                'max_y': 0
            }

        _spawn_list = _room_spawns[room_name][_r_x, _r_y]
        _hit_solid = False

        if x < _spawn_list['min_x']:
            _spawn_list['min_x'] = x

        if x > _spawn_list['max_x']:
            _spawn_list['max_x'] = x

        if y < _spawn_list['min_y']:
            _spawn_list['min_y'] = y

        if y > _spawn_list['max_y']:
            _spawn_list['max_y'] = y

        for x1, y1 in [(0, -1), (1, 0), (0, 1), (-1, 0)]:
            _neighbor_x, _neighbor_y = x + x1, y + y1

            if _neighbor_x < _room_x or _neighbor_x >= _room_x + room_size or _neighbor_y < _room_y or _neighbor_y >= _room_y + room_size:
                continue

            if (_neighbor_x, _neighbor_y) in solids:
                _spawn_list['against_wall'].add((x, y))
                _hit_solid = True

        if not _hit_solid:
            _spawn_list['away_from_wall'].add((x, y))

        _spawn_list['floor'].add((x, y))

    for room_name in _room_spawns:
        _rooms = _room_spawns[room_name]
        #_min_x = 9999
        #_max_x = 0
        #_min_y = 9999
        #_max_y = 0

        for r_x, r_y in _rooms:
            _spawns = _rooms[r_x, r_y]
            _spawns['width'] = _spawns['max_x'] - _spawns['min_x']
            _spawns['height'] = _spawns['max_y'] - _spawns['min_y']

            if _spawns['width'] > _spawns['height']:
                _spawns['direction'] = 'horizontal'

            else:
                _spawns['direction'] = 'vertical'

            #if _spawns['min_x'] < _min_x:
            #	_min_x = _spawns['min_x']

            #if _spawns['min_y'] < _min_y:
            #	_min_y = _spawns['min_y']

            #if _spawns['max_x'] > _max_x:
            #	_max_x = _spawns['max_x']

            #if _spawns['max_y'] > _max_y:
            #	_max_y = _spawns['max_y']

        #_width_of_all_rooms = _max_x - _min_x
        #height_of_all_rooms = _max_y - _min_y

    for room_name in _room_spawns:
        _rooms = _room_spawns[room_name]

        for r_x, r_y in _rooms:
            _wall_bitmask = bitmask_map[r_y, r_x]
            _door_bitmask = bitmask_door_map[r_y, r_x]
            _spawns = _rooms[r_x, r_y]
            _new_floor = set()

            if room_name == 'bunks':
                print 'Spawn here:', _wall_bitmask

                if _wall_bitmask in [105]:
                    for x, y in _spawns['against_wall']:
                        if not y % 4:
                            _solids.add((x, y))

                            for x1, y1 in list(
                                    neighbors_in_any_sets(
                                        x, y, [
                                            _spawns['against_wall'],
                                            _spawns['away_from_wall']
                                        ])):
                                if (x1, y1) in _item_positions:
                                    continue

                                _solids.add((x1, y1))

                elif _wall_bitmask in [110]:
                    for x, y in _spawns['against_wall']:
                        if not x % 4:
                            _solids.add((x, y))

                            for x1, y1 in list(
                                    neighbors_in_any_sets(
                                        x, y, [
                                            _spawns['against_wall'],
                                            _spawns['away_from_wall']
                                        ])):
                                if (x1, y1) in _item_positions:
                                    continue

                                _solids.add((x1, y1))

            elif room_name == 'landing':
                _carpet = set()

                for x, y in _spawns['floor']:
                    _xx = x - _spawns['min_x']
                    _yy = y - _spawns['min_y']

                    if _xx == _spawns['width'] / 2 and _yy == _spawns[
                            'height'] / 2:
                        _lights.append((x, y, 16, 1.5, 1.5, 1.5))

                    if _spawns['width'] * .15 < _xx < _spawns[
                            'width'] * .85 and _spawns[
                                'height'] * .15 < _yy < _spawns['height'] * .85:
                        if _xx < _spawns['width'] * .3 or _xx > _spawns[
                                'width'] * .7 or _yy < _spawns[
                                    'height'] * .3 or _yy > _spawns[
                                        'height'] * .7:
                            if random.uniform(0, 1) > .5:
                                _tile = tiles.carpet_light_blue(x, y)
                                _carpet.add((x, y))

                            else:
                                _tile = tiles.carpet_blue(x, y)
                                _carpet.add((x, y))

                        else:
                            _tile = tiles.carpet_burgandy_specs(x, y)
                            _carpet.add((x, y))

                    elif _spawns['width'] * .10 < _xx < _spawns[
                            'width'] * .90 and _spawns[
                                'height'] * .10 < _yy < _spawns['height'] * .90:
                        _tile = tiles.carpet_burgandy(x, y)
                        _carpet.add((x, y))

                    else:
                        _tile = tiles.carpet_brown(x, y)

                    tile_map[y][x] = _tile
                    weight_map[y][x] = _tile['w']

                    _new_floor.add((x, y))

                #Placing tables
                _placed_tables = set()

                for x, y in _spawns['against_wall']:
                    if neighbors_in_set(x, y, [_carpet]):
                        continue

                    if random.uniform(0, 1) > .87:
                        if neighbors_in_set(x, y, _placed_tables):
                            continue

                        _neighbors = neighbors_in_set(x, y,
                                                      _spawns['against_wall'])

                        if len(_neighbors) >= 2:
                            _neighbors.add((x, y))
                            _placed_tables.add(tuple(_neighbors))

                _windows_placed = 0

                for table in _placed_tables:
                    _temp_windows = set()

                    for x, y in table:
                        _tile = tiles.countertop(x, y)
                        tile_map[y][x] = _tile
                        weight_map[y][x] = _tile['w']

                        _wood_blocks = set()
                        _new_floor.add((x, y))

                        for x1, y1 in neighbors_in_set(
                                x, y, _spawns['floor'],
                                diag=True) - neighbors_in_set(
                                    x, y, table, diag=True):
                            _tile = tiles.wood_block(x1, y1)
                            tile_map[y1][x1] = _tile
                            weight_map[y1][x1] = _tile['w']

                            _new_floor.add((x1, y1))
                            _wood_blocks.add((x1, y1))

                        if _windows_placed > 2:
                            continue

                        for x1, y1 in neighbors_in_set(x, y, solids,
                                                       diag=True):
                            _temp_windows.add((x1, y1))

                    _windows_placed += 1

                    for x, y in _temp_windows:
                        pass
                        #if neighbors_in_set(x, y, solids) - neighbors_in_set(x, y, _temp_windows):
                        #	break
                    else:
                        for x, y in _temp_windows:
                            _tile = tiles.water(x, y)
                            tile_map[y][x] = _tile
                            weight_map[y][x] = _tile['w']

                        _windows.update(_temp_windows)

            elif room_name == 'hall':
                _pillars = set()

                if _door_bitmask:
                    _xx = _spawns['min_x'] + int(round(
                        (_spawns['width'] * .5))) - 1
                    _yy = _spawns['min_y'] + int(
                        round((_spawns['height'] * .5))) - 1

                    for x1, y1 in [(0, 0), (1, 0), (0, 1), (1, 1)]:
                        _solids.add((_xx + x1, _yy + y1))
                        _pillars.add((_xx + x1, _yy + y1))

                else:
                    for x, y in [(_spawns['min_x'] + 2, _spawns['min_y'] + 2),
                                 (_spawns['min_x'] + 2,
                                  _spawns['min_y'] + _spawns['height'] - 3)]:
                        for x1, y1 in [(0, 0), (1, 0), (0, 1), (1, 1)]:
                            _solids.add((x + x1, y + y1))
                            _pillars.add((x + x1, y + y1))

                for x, y in _spawns['floor'] - _spawns['away_from_wall']:
                    if (x, y) in _pillars:
                        continue

                    _tile = tiles.wood_floor(x, y)
                    tile_map[y][x] = _tile
                    weight_map[y][x] = _tile['w']

                    _new_floor.add((x, y))
                    #_solids.add((x, y))

            elif room_name == 'lab':
                #_x_split = 0
                #_y_split = 0

                #print _spawns['direction'], r_x, r_y
                #if _spawns['direction'] == 'horizontal':
                #	_start_x_dist_split = 6
                #	_start_y_dist_split = 4

                #else:
                #	_start_x_dist_split = 4
                #	_start_y_dist_split = 5

                #for dist_split in range(_start_x_dist_split, 9):
                #	if not _spawns['width'] % (dist_split):
                #		_x_split = dist_split
                #
                #		break

                #for dist_split in range(_start_y_dist_split, 9):
                #	if not _spawns['height'] % (dist_split):
                #		_y_split = dist_split
                #
                #		break

                for x, y in get_corner_points(_spawns):
                    for m_x, m_y in [(0, 0), (1, 0), (0, 1), (1, 1)]:
                        _x = x + m_x
                        _y = y + m_y

                        _tile = tiles.carpet_burgandy(_x, _y)
                        tile_map[_y][_x] = _tile
                        weight_map[_y][_x] = _tile['w']
                        _new_floor.add((_x, _y))

            _floor_tiles = _spawns['floor'] - _solids
            _floor_tiles = _floor_tiles - _new_floor

            for x, y in list(_floor_tiles):
                _tile = room_list[room_name]['tile'](x, y)
                tile_map[y][x] = _tile
                weight_map[y][x] = _tile['w']
                _spawn_positions.add((x, y))

            for x, y in list(_solids):
                _tile = tiles.wooden_fence(x, y)
                tile_map[y][x] = _tile
                weight_map[y][x] = _tile['w']

            _floors.update(_floor_tiles)

    return _floors, _solids, _windows, _lights, _spawn_positions
Example #7
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_direction = 270
	_turn_rate = random.randint(-1, 1)
	_river_tiles = set()
	_river_size = random.randint(7, 10)
	_ground_tiles = set()
	_possible_camps = set()
	_trees = {}
	_blueprint = sculpted.create_blueprint(sculpted.ROOMS)
	_room_size = 17
	_door_width = 1
	_place_x, _place_y = 5, 10
	_floor = set()
	_lights = []
	_spawns = {'defending': set(),
	           'attacking': set()}
	#_room_bitmask_maps = {}
	
	_min_door_pos = (_room_size / 2) - _door_width
	_max_door_pos = (_room_size / 2) + _door_width
	
	for y in range(_blueprint['height']):
		for x in range(_blueprint['width']):
			_o_bitmask = _blueprint['bitmask_map'][y, x]
			_bitmask = _blueprint['bitmask_map'][y, x]
			_door_bitmask = _blueprint['bitmask_door_map'][y, x]
			
			if not _bitmask:
				continue
			
			if _bitmask < 100:
				_bitmask += 100
			
			else:
				_room_name = _blueprint['room_lookup'][_blueprint['room_map'][y, x]]
				_wall_offset = 0 #Don't even think about touching this...
				_wall_padding = range(_blueprint['rooms'][_room_name]['wall_padding'] + 1)
				_wall_padding_actual = range(_wall_offset, _blueprint['rooms'][_room_name]['wall_padding'] + 1)
				_wall_padding_2_actual = [(_room_size-1) - i for i in range(_wall_offset, _blueprint['rooms'][_room_name]['wall_padding'] + 1)]
				_wall_padding_2 = [(_room_size-1) - i for i in range(_blueprint['rooms'][_room_name]['wall_padding'] + 1)]
				_wall_padding_3 = range(_blueprint['rooms'][_room_name]['doorway_padding'] + 1)
				_wall_padding_3_actual = range(_wall_offset, _blueprint['rooms'][_room_name]['doorway_padding'] + 1)
				_wall_padding_4 = [(_room_size-1) - i for i in range(_blueprint['rooms'][_room_name]['doorway_padding'] + 1)]
				_wall_padding_4_actual = [(_room_size-1) - i for i in range(_wall_offset, _blueprint['rooms'][_room_name]['doorway_padding'] + 1)]
				_wall_bitmask = 0
				
				logging.debug('Building: %s' % _room_name)
				
				if _o_bitmask > 100 and _o_bitmask < 200:
					_wall_bitmask = _o_bitmask
			
			for y1 in range(_room_size):
				for x1 in range(_room_size):
					_placed = False
					_p_x, _p_y = (x * _room_size) + x1, (y * _room_size) + y1
					
					if _o_bitmask > 100 and _o_bitmask < 200:
						if y1 in _wall_padding and not _bitmask in [101, 103, 105, 107, 109, 111, 113, 115]:
							if y1 in _wall_padding_actual:
								_solids.add((_place_x + _p_x, _place_y + _p_y))
							
							_placed = True
						
						elif y1 in _wall_padding_2 and not _bitmask in [104, 105, 106, 107, 112, 113, 114, 115]:
							if y1 in _wall_padding_2_actual:
								_solids.add((_place_x + _p_x, _place_y + _p_y))
							
							_placed = True
						
						if x1 in _wall_padding_2 and not _bitmask in [102, 103, 106, 107, 110, 111, 114, 115]:
							if x1 in _wall_padding_2_actual:
								_solids.add((_place_x + _p_x, _place_y + _p_y))
							
							_placed = True
						
						elif x1 in _wall_padding and not _bitmask in [108, 109, 110, 111, 112, 113, 114, 115]:
							if x1 in _wall_padding_actual:
								_solids.add((_place_x + _p_x, _place_y + _p_y))
							
							_placed = True
					
					else:
						if y1 == 0 and _bitmask in [101, 103, 105, 107, 109, 111, 113, 115]:
							_solids.add((_place_x + _p_x, _place_y + _p_y))
							_placed = True
						
						elif y1 == _room_size - 1 and _bitmask in [104, 105, 106, 107, 112, 113, 114, 115]:
							_solids.add((_place_x + _p_x, _place_y + _p_y))
							_placed = True
						
						if x1 == _room_size - 1 and _bitmask in [102, 103, 106, 107, 110, 111, 114, 115]:
							_solids.add((_place_x + _p_x, _place_y + _p_y))
							_placed = True
						
						elif x1 == 0 and _bitmask in [108, 109, 110, 111, 112, 113, 114, 115]:
							_solids.add((_place_x + _p_x, _place_y + _p_y))
							_placed = True
			
					if not _placed and _o_bitmask > 100 and not _door_bitmask:
						_floor.add((_place_x + _p_x, _place_y + _p_y, _room_name))
					
					elif _door_bitmask:
						_doorway_placed = False
						
						if y1 in _wall_padding_3 and _door_bitmask in [101, 103, 105, 107, 109, 111, 113, 115]:
							if x1 < _min_door_pos or x1 > _max_door_pos:
								#if x1 in _wall_padding_3_actual:
								_solids.add((_place_x + _p_x, _place_y + _p_y))
								_doorway_placed = True
							
							elif (_place_x + _p_x, _place_y + _p_y) in _solids:
								_solids.remove((_place_x + _p_x, _place_y + _p_y))
						
						elif y1 in _wall_padding_4 and _door_bitmask in [104, 105, 106, 107, 112, 113, 114, 115]:
							if x1 < _min_door_pos or x1 > _max_door_pos:
								_solids.add((_place_x + _p_x, _place_y + _p_y))
								_doorway_placed = True
							
							elif (_place_x + _p_x, _place_y + _p_y) in _solids:
								_solids.remove((_place_x + _p_x, _place_y + _p_y))
						
						if x1 in _wall_padding_4 and _door_bitmask in [102, 103, 106, 107, 110, 111, 114, 115]:
							if y1 < _min_door_pos or y1 > _max_door_pos:
								_solids.add((_place_x + _p_x, _place_y + _p_y))
								_doorway_placed = True
							
							elif (_place_x + _p_x, _place_y + _p_y) in _solids:
								_solids.remove((_place_x + _p_x, _place_y + _p_y))
						
						elif x1 in _wall_padding_3 and _door_bitmask in [108, 109, 110, 111, 112, 113, 114, 115]:
							if y1 < _min_door_pos or y1 > _max_door_pos:
								_solids.add((_place_x + _p_x, _place_y + _p_y))
								_doorway_placed = True
							
							elif (_place_x + _p_x, _place_y + _p_y) in _solids:
								_solids.remove((_place_x + _p_x, _place_y + _p_y))
						
						if not _doorway_placed and not _placed:
							_floor.add((_place_x + _p_x, _place_y + _p_y, _room_name))
	
	_lookup = {(0, -1): 1,
	           (1, 0): 2,
	           (0, 1): 4,
	           (-1, 0): 8}		
	
	_new_floors, _new_solids, _windows, _new_lights, _new_spawns = roomgen.spawn_items(_blueprint['rooms'], _blueprint['bitmask_map'], _blueprint['bitmask_door_map'], _floor, _solids, _room_size, _room_size, (_place_x, _place_y), _tile_map, _weight_map)
	_floor_new = set()
	
	for x, y, room_name in _floor.copy():
		_floor_new.add((x, y))
	
	_spawns['defending'].update(_new_spawns)
	_spawns['attacking'].add((70, 5))
	_floor = _floor_new
	_floor.update(_new_floors)
	_solids.update(_new_solids)
	_remove_solids = set()
	_solids = _solids - _windows
	_lights.extend(_new_lights)
	
	for x, y in _solids:
		#_count = 0
		_delete = True
		
		for x1, y1 in [(0, -1), (1, 0), (0, 1), (-1, 0), (-1, -1), (1, -1), (-1, 1), (1, 1)]:
			_x = x + x1
			_y = y + y1
			
			if (_x, _y) in _floor:
				_delete = False
				#_count += 1
		
		if _delete:
			_remove_solids.add((x, y))
			_ground_tiles.add((x, y))
	
	_solids = _solids - _remove_solids

	for x in range(width):
		for y in range(height):
			if (x, y) in _solids:
				continue
			
			_ground_tiles.add((x, y))

	#This generates the outside walls	
	for pos in _solids:
		_tile = tiles.wooden_fence(pos[0], pos[1])
		_tile_map[pos[1]][pos[0]] = _tile
		_weight_map[pos[1]][pos[0]] = _tile['w']
	
	_ground_tiles = _ground_tiles - _windows
	
	for x, y in _ground_tiles - _floor:
		_tile = tiles.grass(x, y)
		_tile_map[y][x] = _tile
		_weight_map[y][x] = _tile['w']
	
	mapgen.build_node_grid(_node_grid, _solids)
	_floor.update(_windows)
	
	return width, height, _node_grid, mapgen.NODE_SETS.copy(), _weight_map, _tile_map, _solids, {}, _trees, _floor, _lights, _spawns