def get_vision(life): if not 'CAN_SEE' in life['life_flags']: return 0 #if 'player' in life: _fov_mod = 1 #else: # _fov_mod = bad_numbers.clip(1-(life['think_rate']/float(life['think_rate_max'])), 0.5, 1) _world_light = tcod.white-weather.get_lighting() _light_percentage = bad_numbers.clip(((_world_light.r+_world_light.g+_world_light.b)*.30)/200.0, 0, 1) return int(round((life['vision_max']*_light_percentage)*_fov_mod))
def get_vision(life): if not 'CAN_SEE' in life['life_flags']: return 0 #if 'player' in life: _fov_mod = 1 #else: # _fov_mod = bad_numbers.clip(1-(life['think_rate']/float(life['think_rate_max'])), 0.5, 1) _world_light = tcod.white - weather.get_lighting() _light_percentage = bad_numbers.clip( ((_world_light.r + _world_light.g + _world_light.b) * .30) / 200.0, 0, 1) return int(round((life['vision_max'] * _light_percentage) * _fov_mod))
def render_lights(size=MAP_WINDOW_SIZE, show_weather=True): if not SETTINGS['draw lights']: return False reset_lights(size=size) _weather_light = weather.get_lighting() #Not entirely my code. Made some changes to someone's code from libtcod's Python forum. RGB_LIGHT_BUFFER[0] = numpy.add(RGB_LIGHT_BUFFER[0], _weather_light[0]) RGB_LIGHT_BUFFER[1] = numpy.add(RGB_LIGHT_BUFFER[1], _weather_light[1]) RGB_LIGHT_BUFFER[2] = numpy.add(RGB_LIGHT_BUFFER[2], _weather_light[2]) (x, y) = SETTINGS['light mesh grid'] if show_weather: weather.generate_effects(size) _remove_lights = [] for light in WORLD_INFO['lights']: _x_range = light['pos'][0] - CAMERA_POS[0] _y_range = light['pos'][1] - CAMERA_POS[1] if _x_range <= -20 or _x_range >= size[0] + 20: continue if _y_range <= -20 or _y_range >= size[1] + 20: continue if not 'old_pos' in light: light['old_pos'] = (0, 0, -2) else: light['old_pos'] = light['pos'][:] if 'follow_item' in light: if not light['follow_item'] in ITEMS: _remove_lights.append(light) continue light['pos'] = items.get_pos(light['follow_item'])[:] _render_x = light['pos'][0] - CAMERA_POS[0] _render_y = light['pos'][1] - CAMERA_POS[1] _x = bad_numbers.clip(light['pos'][0] - (size[0] / 2), 0, MAP_SIZE[0]) _y = bad_numbers.clip(light['pos'][1] - (size[1] / 2), 0, MAP_SIZE[1]) _top_left = (_x, _y, light['pos'][2]) #TODO: Render only on move if not tuple(light['pos']) == tuple(light['old_pos']): light['los'] = cython_render_los.render_los( (light['pos'][0], light['pos'][1]), light['brightness'] * 2, view_size=size, top_left=_top_left) los = light['los'].copy() _x_scroll = _x - CAMERA_POS[0] _x_scroll_over = 0 _y_scroll = _y - CAMERA_POS[1] _y_scroll_over = 0 if _x_scroll < 0: _x_scroll_over = _x_scroll _x_scroll = los.shape[1] + _x_scroll if _y_scroll < 0: _y_scroll_over = _y_scroll _y_scroll = los.shape[0] + _y_scroll los = numpy.roll(los, _y_scroll, axis=0) los = numpy.roll(los, _x_scroll, axis=1) los[_y_scroll_over:_y_scroll, ] = 1 los[:, _x_scroll_over:_x_scroll] = 1 if SETTINGS['diffuse light']: _y, _x = diffuse_light((y, x)) (x, y) = numpy.meshgrid(_x, _y) sqr_distance = (x - (_render_x))**2.0 + (y - (_render_y))**2.0 brightness = bad_numbers.clip( random.uniform(light['brightness'] * light['shake'], light['brightness']), 0.01, 50) / sqr_distance brightness *= los #brightness *= LOS_BUFFER[0] #_mod = (abs((WORLD_INFO['length_of_day']/2)-WORLD_INFO['real_time_of_day'])/float(WORLD_INFO['length_of_day']))*5.0 #_mod = bad_numbers.clip(_mod-1, 0, 1) #(255*_mod, 165*_mod, 0*_mod) #print brightness #light['brightness'] = 25 #light['color'][0] = 255*(light['brightness']/255.0) #light['color'][1] = (light['brightness']/255.0) #light['color'][2] = 255*(light['brightness']/255.0) RGB_LIGHT_BUFFER[0] -= ( brightness.clip(0, 2) * (light['color'][0]) ) #numpy.subtract(RGB_LIGHT_BUFFER[0], light['color'][0]).clip(0, 255) RGB_LIGHT_BUFFER[1] -= ( brightness.clip(0, 2) * (light['color'][1]) ) #numpy.subtract(RGB_LIGHT_BUFFER[1], light['color'][1]).clip(0, 255) RGB_LIGHT_BUFFER[2] -= ( brightness.clip(0, 2) * (light['color'][2]) ) #numpy.subtract(RGB_LIGHT_BUFFER[2], light['color'][2]).clip(0, 255)
def render_lights(size=MAP_WINDOW_SIZE, show_weather=True): if not SETTINGS['draw lights']: return False reset_lights(size=size) _weather_light = weather.get_lighting() #Not entirely my code. Made some changes to someone's code from libtcod's Python forum. RGB_LIGHT_BUFFER[0] = numpy.add(RGB_LIGHT_BUFFER[0], _weather_light[0]) RGB_LIGHT_BUFFER[1] = numpy.add(RGB_LIGHT_BUFFER[1], _weather_light[1]) RGB_LIGHT_BUFFER[2] = numpy.add(RGB_LIGHT_BUFFER[2], _weather_light[2]) (x, y) = SETTINGS['light mesh grid'] if show_weather: weather.generate_effects(size) _remove_lights = [] for light in WORLD_INFO['lights']: _x_range = light['pos'][0]-CAMERA_POS[0] _y_range = light['pos'][1]-CAMERA_POS[1] if _x_range <= -20 or _x_range>=size[0]+20: continue if _y_range <= -20 or _y_range>=size[1]+20: continue if not 'old_pos' in light: light['old_pos'] = (0, 0, -2) else: light['old_pos'] = light['pos'][:] if 'follow_item' in light: if not light['follow_item'] in ITEMS: _remove_lights.append(light) continue light['pos'] = items.get_pos(light['follow_item'])[:] _render_x = light['pos'][0]-CAMERA_POS[0] _render_y = light['pos'][1]-CAMERA_POS[1] _x = numbers.clip(light['pos'][0]-(size[0]/2),0,MAP_SIZE[0]) _y = numbers.clip(light['pos'][1]-(size[1]/2),0,MAP_SIZE[1]) _top_left = (_x,_y,light['pos'][2]) #TODO: Render only on move if not tuple(light['pos']) == tuple(light['old_pos']): light['los'] = cython_render_los.render_los((light['pos'][0],light['pos'][1]), light['brightness']*2, view_size=size, top_left=_top_left) los = light['los'].copy() _x_scroll = _x-CAMERA_POS[0] _x_scroll_over = 0 _y_scroll = _y-CAMERA_POS[1] _y_scroll_over = 0 if _x_scroll<0: _x_scroll_over = _x_scroll _x_scroll = los.shape[1]+_x_scroll if _y_scroll<0: _y_scroll_over = _y_scroll _y_scroll = los.shape[0]+_y_scroll los = numpy.roll(los, _y_scroll, axis=0) los = numpy.roll(los, _x_scroll, axis=1) los[_y_scroll_over:_y_scroll,] = 1 los[:,_x_scroll_over:_x_scroll] = 1 if SETTINGS['diffuse light']: _y, _x = diffuse_light((y, x)) (x, y) = numpy.meshgrid(_x, _y) sqr_distance = (x - (_render_x))**2.0 + (y - (_render_y))**2.0 brightness = numbers.clip(random.uniform(light['brightness']*light['shake'], light['brightness']), 0.01, 50) / sqr_distance brightness *= los #brightness *= LOS_BUFFER[0] #_mod = (abs((WORLD_INFO['length_of_day']/2)-WORLD_INFO['real_time_of_day'])/float(WORLD_INFO['length_of_day']))*5.0 #_mod = numbers.clip(_mod-1, 0, 1) #(255*_mod, 165*_mod, 0*_mod) #print brightness #light['brightness'] = 25 #light['color'][0] = 255*(light['brightness']/255.0) #light['color'][1] = (light['brightness']/255.0) #light['color'][2] = 255*(light['brightness']/255.0) RGB_LIGHT_BUFFER[0] -= (brightness.clip(0, 2)*(light['color'][0]))#numpy.subtract(RGB_LIGHT_BUFFER[0], light['color'][0]).clip(0, 255) RGB_LIGHT_BUFFER[1] -= (brightness.clip(0, 2)*(light['color'][1]))#numpy.subtract(RGB_LIGHT_BUFFER[1], light['color'][1]).clip(0, 255) RGB_LIGHT_BUFFER[2] -= (brightness.clip(0, 2)*(light['color'][2]))#numpy.subtract(RGB_LIGHT_BUFFER[2], light['color'][2]).clip(0, 255)