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)
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'])
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'])