def check_chunks(self, force=False): if not force and WORLD_INFO['ticks']-self.last_checked<self.check_every: return False self.last_checked = WORLD_INFO['ticks'] for life in [l for l in LIFE.values() if l['online']]: _x_min = bad_numbers.clip(life['pos'][0]-MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0]-1-MAP_WINDOW_SIZE[0]) _y_min = bad_numbers.clip(life['pos'][1]-MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1]-1-MAP_WINDOW_SIZE[1]) _x_max = bad_numbers.clip(life['pos'][0]+MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0]-1) _y_max = bad_numbers.clip(life['pos'][1]+MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1]-1) _refresh = False for y in range(_y_min, _y_max, WORLD_INFO['chunk_size']): for x in range(_x_min, _x_max, WORLD_INFO['chunk_size']): maps.load_cluster_at_position_if_needed((x, y)) SETTINGS['loading'] = True if 'player' in life: _refresh = True if _refresh: gfx.refresh_view('map') SETTINGS['loading'] = False
def check_chunks(self, force=False): if not force and WORLD_INFO["ticks"] - self.last_checked < self.check_every: return False self.last_checked = WORLD_INFO["ticks"] for life in [l for l in LIFE.values() if l["online"]]: _x_min = numbers.clip(life["pos"][0] - MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0] - 1 - MAP_WINDOW_SIZE[0]) _y_min = numbers.clip(life["pos"][1] - MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1] - 1 - MAP_WINDOW_SIZE[1]) _x_max = numbers.clip(life["pos"][0] + MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0] - 1) _y_max = numbers.clip(life["pos"][1] + MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1] - 1) _refresh = False for y in range(_y_min, _y_max, WORLD_INFO["chunk_size"]): for x in range(_x_min, _x_max, WORLD_INFO["chunk_size"]): maps.load_cluster_at_position_if_needed((x, y)) SETTINGS["loading"] = True if "player" in life: _refresh = True if _refresh: gfx.refresh_view("map") SETTINGS["loading"] = False
def regenerate_world(): gfx.title('Generating...') reload(mapgen) pre_setup_world() try: mapgen.generate_map(size=(450, 450, 10), towns=1, factories=0, outposts=2, forests=1, skip_zoning=True, skip_chunking=True, hotload=True) except: import traceback traceback.print_exc() SETTINGS['running'] = 1 return False post_setup_world() gfx.refresh_view('map') return True
def regenerate_world(build_test=False): gfx.title('Generating...') reload(mapgen) if build_test: mapgen.create_buildings() pre_setup_world() try: mapgen.generate_map(towns=1, factories=0, outposts=2, forests=1, skip_zoning=True, skip_chunking=True, hotload=True, build_test=build_test) except: import traceback traceback.print_exc() SETTINGS['running'] = 1 return False post_setup_world() gfx.refresh_view('map') return True
def building_type_selected(entry): gfx.title('Loading...') #pre_setup_world() regenerate_world(build_test=entry['key']) #mapgen.generate_map(build_test=entry['key'], skip_chunking=True, skip_zoning=True) #post_setup_world() gfx.refresh_view('map') SETTINGS['running'] = 2
def move_camera(pos, scroll=False): _orig_pos = CAMERA_POS[:] CAMERA_POS[0] = numbers.clip(pos[0]-(WINDOW_SIZE[0]/2),0,MAP_SIZE[0]-WINDOW_SIZE[0]) CAMERA_POS[1] = numbers.clip(pos[1]-(WINDOW_SIZE[1]/2),0,MAP_SIZE[1]-WINDOW_SIZE[1]) CAMERA_POS[2] = pos[2] if not _orig_pos == CAMERA_POS: gfx.refresh_view('map') elif SETTINGS['controlling'] and not alife.brain.get_flag(LIFE[SETTINGS['controlling']], 'redraw') == pos: gfx.refresh_view('map')
def move_camera(pos, scroll=False): _orig_pos = CAMERA_POS[:] CAMERA_POS[0] = bad_numbers.clip(pos[0]-(WINDOW_SIZE[0]/2),0,MAP_SIZE[0]-WINDOW_SIZE[0]) CAMERA_POS[1] = bad_numbers.clip(pos[1]-(WINDOW_SIZE[1]/2),0,MAP_SIZE[1]-WINDOW_SIZE[1]) CAMERA_POS[2] = pos[2] if not _orig_pos == CAMERA_POS: gfx.refresh_view('map') elif SETTINGS['controlling'] and not alife.brain.get_flag(LIFE[SETTINGS['controlling']], 'redraw') == pos: gfx.refresh_view('map')
def show_next_event(): if not EVENTS: return False EVENTS.pop(0) gfx.refresh_view('map') if not EVENTS: life.focus_on(LIFE[SETTINGS['following']]) return False return True
def move_camera(pos, scroll=False): _orig_pos = CAMERA_POS[:] CAMERA_POS[0] = numbers.clip(pos[0] - (MAP_WINDOW_SIZE[0] / 2), 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0]) CAMERA_POS[1] = numbers.clip(pos[1] - (MAP_WINDOW_SIZE[1] / 2), 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1]) CAMERA_POS[2] = pos[2] if not _orig_pos == CAMERA_POS: gfx.refresh_view("map") elif SETTINGS["controlling"] and not alife.brain.get_flag(LIFE[SETTINGS["controlling"]], "redraw") == pos: gfx.refresh_view("map") if SETTINGS["controlling"]: alife.brain.flag(LIFE[SETTINGS["controlling"]], "redraw", value=pos[:])
def show_next_event(): if not EVENTS: return False _event = None for event in EVENTS: if not event['delay']: _event = event break if not _event: return False EVENTS.remove(_event) gfx.refresh_view('map') if not EVENTS: life.focus_on(LIFE[SETTINGS['following']]) locks.lock('camera_free', reason='No more events') return False return True
def main(): _player_moved = False _refresh_map = False get_input() handle_input() if not LIFE[SETTINGS["controlling"]]["dead"]: if LIFE[SETTINGS["controlling"]]["asleep"]: gfx.fade_to_black(255) gfx.start_of_frame() gfx.end_of_frame() while LIFE[SETTINGS["controlling"]]["asleep"]: _played_moved = True _refresh_map = True gfx.title(LIFE[SETTINGS["controlling"]]["asleep_reason"]) logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True) if LIFE[SETTINGS["controlling"]]["dead"]: break else: _player_moved = True if _refresh_map: gfx.refresh_view("map") if not _player_moved: logic.tick_all_objects(ignore_tickrate=True) draw_targeting() move_camera(SETTINGS["camera_track"]) # TODO: Deselect so we can get rid of this call if SELECTED_TILES[0]: gfx.refresh_view("map") if not SETTINGS["last_camera_pos"] == SETTINGS["camera_track"][:]: if EVENTS or MENUS: _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["following"]], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS["following"]], "visible_chunks", value=_visible_chunks) _cam_x = numbers.clip( LIFE[SETTINGS["following"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2 ) _cam_y = numbers.clip( LIFE[SETTINGS["following"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2 ) else: _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["controlling"]], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS["controlling"]], "visible_chunks", value=_visible_chunks) SETTINGS["last_camera_pos"] = SETTINGS["camera_track"][:] _cam_x = numbers.clip( LIFE[SETTINGS["controlling"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2 ) _cam_y = numbers.clip( LIFE[SETTINGS["controlling"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2 ) maps.render_lights() if "--worldmap" in sys.argv: render_map.render_map(WORLD_INFO["map"], force_camera_pos=(_cam_x, _cam_y, 2)) else: render_map.render_map( WORLD_INFO["map"], los=LIFE[SETTINGS["controlling"]]["fov"], force_camera_pos=(_cam_x, _cam_y, 2) ) items.draw_items() life.draw_life() if LIFE[SETTINGS["controlling"]]["dead"] and not EVENTS: if not death(): return False if SETTINGS["draw life info"] and SETTINGS["following"]: life.draw_life_info() gfx.draw_message_box() menus.align_menus() menus.draw_menus() gfx.draw_status_line() gfx.draw_console() gfx.start_of_frame() gfx.end_of_frame() if "--fps" in sys.argv: print tcod.sys_get_fps() if (SETTINGS["recording"] and logic.can_tick()) or "--worldmap" in sys.argv: gfx.screenshot() if "--worldmap" in sys.argv: SETTINGS["running"] = False
def handle_input(): global PLACING_TILE,RUNNING,SETTINGS,KEYBOARD_STRING if gfx.window_is_closed(): SETTINGS['running'] = False return True elif INPUT['\x1b'] or INPUT['q']: if not ACTIVE_MENU['menu'] == -1 and not SETTINGS['running'] == 1: ACTIVE_MENU['menu'] = -1 return True SETTINGS['running'] = False return True elif INPUT['-']: if SETTINGS['draw console']: SETTINGS['draw console'] = False else: SETTINGS['draw console'] = True elif SETTINGS['draw console']: return elif INPUT['up']: if not ACTIVE_MENU['menu'] == -1: menus.move_up(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index']) else: CURSOR_POS[1] -= SETTINGS['cursor speed'] elif INPUT['down']: if not ACTIVE_MENU['menu'] == -1: menus.move_down(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index']) else: CURSOR_POS[1] += SETTINGS['cursor speed'] elif INPUT['right']: if not ACTIVE_MENU['menu'] == -1: menus.next_item(MENUS[ACTIVE_MENU['menu']],MENUS[ACTIVE_MENU['menu']]['index']) menus.item_changed(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index']) else: CURSOR_POS[0] += SETTINGS['cursor speed'] elif INPUT['left']: if not ACTIVE_MENU['menu'] == -1: menus.previous_item(MENUS[ACTIVE_MENU['menu']],MENUS[ACTIVE_MENU['menu']]['index']) menus.item_changed(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index']) else: CURSOR_POS[0] -= SETTINGS['cursor speed'] elif INPUT[' ']: menus.activate_menu_by_name('Buildings') elif INPUT['n']: for alife in LIFE: life.memory(alife, 'focus_on_chunk', chunk_key=life.get_current_chunk_id(LIFE[SETTINGS['controlling']])) elif INPUT['\r']: if ACTIVE_MENU['menu'] == -1: return False menus.item_selected(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index']) ACTIVE_MENU['menu'] = -1 elif INPUT['\t']: pass elif INPUT['c']: CURSOR_POS[0] = MAP_SIZE[0]/2 CURSOR_POS[1] = MAP_SIZE[1]/2 elif INPUT['m']: if SETTINGS['running'] == 2: gfx.add_view_to_scene_by_name('chunk_map') gfx.set_active_view('chunk_map') SETTINGS['running'] = 3 elif SETTINGS['running'] == 3: gfx.remove_view_from_scene_by_name('chunk_map') gfx.set_active_view('map') SETTINGS['running'] = 2 elif INPUT['r']: if regenerate_world(): SETTINGS['running'] = 2 elif INPUT['s']: items.save_all_items() gfx.title('Generating Chunk Map') maps.update_chunk_map() gfx.title('Zoning...') zones.create_zone_map() gfx.title('Saving...') maps.save_map(str(time.time()), only_cached=False) items.reload_all_items() elif INPUT['l']: SUN_BRIGHTNESS[0] += 4 elif INPUT['k']: SUN_BRIGHTNESS[0] -= 4 elif INPUT['1']: CAMERA_POS[2] = 1 gfx.refresh_view('map') elif INPUT['2']: CAMERA_POS[2] = 2 gfx.refresh_view('map') elif INPUT['3']: CAMERA_POS[2] = 3 gfx.refresh_view('map') elif INPUT['4']: CAMERA_POS[2] = 4 gfx.refresh_view('map') elif INPUT['5']: CAMERA_POS[2] = 5 gfx.refresh_view('map') elif INPUT['6']: CAMERA_POS[2] = 6 gfx.refresh_view('map') elif INPUT['7']: CAMERA_POS[2] = 7 gfx.refresh_view('map') elif INPUT['8']: CAMERA_POS[2] = 8 gfx.refresh_view('map') elif INPUT['9']: CAMERA_POS[2] = 9 gfx.refresh_view('map') elif INPUT['0']: CAMERA_POS[2] = 0 gfx.refresh_view('map')
def handle_input(): global PLACING_TILE, RUNNING, SETTINGS, KEYBOARD_STRING if gfx.window_is_closed(): SETTINGS['running'] = False return True elif INPUT['\x1b'] or INPUT['q']: if not ACTIVE_MENU['menu'] == -1 and not SETTINGS['running'] == 1: ACTIVE_MENU['menu'] = -1 return True SETTINGS['running'] = False return True elif INPUT['-']: if SETTINGS['draw console']: SETTINGS['draw console'] = False else: SETTINGS['draw console'] = True elif SETTINGS['draw console']: return elif INPUT['up']: if not ACTIVE_MENU['menu'] == -1: menus.move_up(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index']) else: CURSOR_POS[1] -= SETTINGS['cursor speed'] elif INPUT['down']: if not ACTIVE_MENU['menu'] == -1: menus.move_down(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index']) else: CURSOR_POS[1] += SETTINGS['cursor speed'] elif INPUT['right']: if not ACTIVE_MENU['menu'] == -1: menus.next_item(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index']) menus.item_changed(ACTIVE_MENU['menu'], MENUS[ACTIVE_MENU['menu']]['index']) else: CURSOR_POS[0] += SETTINGS['cursor speed'] elif INPUT['left']: if not ACTIVE_MENU['menu'] == -1: menus.previous_item(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index']) menus.item_changed(ACTIVE_MENU['menu'], MENUS[ACTIVE_MENU['menu']]['index']) else: CURSOR_POS[0] -= SETTINGS['cursor speed'] elif INPUT[' ']: menus.activate_menu_by_name('Buildings') elif INPUT['n']: for alife in LIFE: life.memory(alife, 'focus_on_chunk', chunk_key=life.get_current_chunk_id( LIFE[SETTINGS['controlling']])) elif INPUT['\r']: if ACTIVE_MENU['menu'] == -1: return False menus.item_selected(ACTIVE_MENU['menu'], MENUS[ACTIVE_MENU['menu']]['index']) ACTIVE_MENU['menu'] = -1 elif INPUT['\t']: pass elif INPUT['c']: CURSOR_POS[0] = MAP_SIZE[0] / 2 CURSOR_POS[1] = MAP_SIZE[1] / 2 elif INPUT['m']: if SETTINGS['running'] == 2: gfx.add_view_to_scene_by_name('chunk_map') gfx.set_active_view('chunk_map') SETTINGS['running'] = 3 elif SETTINGS['running'] == 3: gfx.remove_view_from_scene_by_name('chunk_map') gfx.set_active_view('map') SETTINGS['running'] = 2 elif INPUT['r']: if regenerate_world(): SETTINGS['running'] = 2 elif INPUT['s']: items.save_all_items() gfx.title('Generating Chunk Map') maps.update_chunk_map() gfx.title('Zoning...') zones.create_zone_map() gfx.title('Saving...') maps.save_map(str(time.time()), only_cached=False) items.reload_all_items() elif INPUT['l']: SUN_BRIGHTNESS[0] += 4 elif INPUT['k']: SUN_BRIGHTNESS[0] -= 4 elif INPUT['1']: CAMERA_POS[2] = 1 gfx.refresh_view('map') elif INPUT['2']: CAMERA_POS[2] = 2 gfx.refresh_view('map') elif INPUT['3']: CAMERA_POS[2] = 3 gfx.refresh_view('map') elif INPUT['4']: CAMERA_POS[2] = 4 gfx.refresh_view('map') elif INPUT['5']: CAMERA_POS[2] = 5 gfx.refresh_view('map') elif INPUT['6']: CAMERA_POS[2] = 6 gfx.refresh_view('map') elif INPUT['7']: CAMERA_POS[2] = 7 gfx.refresh_view('map') elif INPUT['8']: CAMERA_POS[2] = 8 gfx.refresh_view('map') elif INPUT['9']: CAMERA_POS[2] = 9 gfx.refresh_view('map') elif INPUT['0']: CAMERA_POS[2] = 0 gfx.refresh_view('map')
def main(): _player_moved = False _refresh_map = False get_input() handle_input() if not LIFE[SETTINGS['controlling']]['dead']: if LIFE[SETTINGS['controlling']]['asleep']: gfx.fade_to_black(255) gfx.start_of_frame() gfx.end_of_frame() while LIFE[SETTINGS['controlling']]['asleep']: _played_moved = True _refresh_map = True gfx.title(LIFE[SETTINGS['controlling']]['asleep_reason']) logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True) if LIFE[SETTINGS['controlling']]['dead']: break else: _player_moved = True if _refresh_map: gfx.refresh_view('map') if not _player_moved: if logic.tick_all_objects(ignore_tickrate=True): _player_moved = True draw_targeting() move_camera(SETTINGS['camera_track']) #TODO: Deselect so we can get rid of this call if SELECTED_TILES[0]: gfx.refresh_view('map') if not SETTINGS['last_camera_pos'] == SETTINGS['camera_track'][:]: if EVENTS or MENUS: _visible_chunks = sight.scan_surroundings( LIFE[SETTINGS['following']], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS['following']], 'visible_chunks', value=_visible_chunks) _cam_x = numbers.clip( LIFE[SETTINGS['following']]['pos'][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2) _cam_y = numbers.clip( LIFE[SETTINGS['following']]['pos'][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2) else: _visible_chunks = sight.scan_surroundings( LIFE[SETTINGS['controlling']], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS['controlling']], 'visible_chunks', value=_visible_chunks) SETTINGS['last_camera_pos'] = SETTINGS['camera_track'][:] _cam_x = numbers.clip( LIFE[SETTINGS['controlling']]['pos'][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2) _cam_y = numbers.clip( LIFE[SETTINGS['controlling']]['pos'][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2) maps.render_lights() if '--worldmap' in sys.argv: render_map.render_map(WORLD_INFO['map'], force_camera_pos=(_cam_x, _cam_y, 2)) else: render_map.render_map(WORLD_INFO['map'], los=LIFE[SETTINGS['controlling']]['fov'], force_camera_pos=(_cam_x, _cam_y, 2)) items.draw_items() life.draw_life() if LIFE[SETTINGS['controlling']]['dead'] and not EVENTS: if not death(): return False if SETTINGS['draw life info'] and SETTINGS['following']: life.draw_life_info() gfx.draw_message_box() menus.align_menus() menus.draw_menus() gfx.draw_status_line() gfx.draw_console() gfx.start_of_frame() gfx.end_of_frame() if '--fps' in sys.argv: print tcod.sys_get_fps() if (SETTINGS['recording'] and _player_moved and not EVENTS and not MENUS) or '--worldmap' in sys.argv: gfx.screenshot() if '--worldmap' in sys.argv: SETTINGS['running'] = False
def move_camera(pos, scroll=False): _orig_pos = CAMERA_POS[:] if SETTINGS['controlling'] and SETTINGS['following'] == SETTINGS[ 'controlling'] and locks.is_locked('camera_free'): _life = LIFE[SETTINGS['controlling']] _top_left = MAP_SIZE[:] _bot_right = [0, 0, 0] _seen = False for life_id in LIFE[SETTINGS['controlling']]['seen']: if LIFE[life_id]['dead']: continue if brain.knows_alife_by_id( LIFE[SETTINGS['controlling']], life_id)['alignment'] in ['trust', 'feign_trust']: continue _seen = True if LIFE[life_id]['pos'][0] < _top_left[0]: _top_left[0] = LIFE[life_id]['pos'][0] if LIFE[life_id]['pos'][1] < _top_left[1]: _top_left[1] = LIFE[life_id]['pos'][1] if LIFE[life_id]['pos'][0] > _bot_right[0]: _bot_right[0] = LIFE[life_id]['pos'][0] if LIFE[life_id]['pos'][1] > _bot_right[1]: _bot_right[1] = LIFE[life_id]['pos'][1] _target_pos = numbers.lerp_velocity(_top_left, _bot_right, 0.5) pos = numbers.lerp_velocity(pos, _target_pos, .35)[:2] pos.append(2) brain.flag(_life, 'camera_lean', value=_target_pos[:]) brain.flag(_life, 'camera_lean_time', value=WORLD_INFO['ticks']) _future_time = brain.get_flag(_life, 'camera_lean_time_future') if not _future_time or WORLD_INFO['ticks'] > _future_time: brain.flag(_life, 'camera_lean_time_future', value=WORLD_INFO['ticks'] + 30) if brain.get_flag(_life, 'camera_lean'): if _seen: _st = WORLD_INFO['ticks'] - ( brain.get_flag(_life, 'camera_lean_time_future') - 30) _et = brain.get_flag(_life, 'camera_lean_time_future') - ( brain.get_flag(_life, 'camera_lean_time_future') - 30) _lerp = 1 - numbers.clip(_st / float(_et), 0, 1.0) pos = numbers.lerp_velocity( pos, brain.get_flag(_life, 'camera_lean'), _lerp)[:2] pos.append(2) else: if WORLD_INFO['ticks'] - brain.get_flag( _life, 'camera_lean_time') <= 20: _lerp = .45 - numbers.clip( (WORLD_INFO['ticks'] - brain.get_flag( _life, 'camera_lean_time')) / 30.0, 0, .45) pos = numbers.lerp_velocity( pos, brain.get_flag(_life, 'camera_lean'), _lerp)[:2] pos.append(2) else: brain.unflag(_life, 'camera_lean') brain.unflag(_life, 'camera_lean_time') CAMERA_POS[0] = int( round( numbers.clip(pos[0] - (MAP_WINDOW_SIZE[0] / 2), 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0]))) CAMERA_POS[1] = int( round( numbers.clip(pos[1] - (MAP_WINDOW_SIZE[1] / 2), 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1]))) CAMERA_POS[2] = int(round(pos[2])) if not _orig_pos == CAMERA_POS: gfx.refresh_view('map') elif SETTINGS['controlling'] and not alife.brain.get_flag( LIFE[SETTINGS['controlling']], 'redraw') == pos: gfx.refresh_view('map') if SETTINGS['controlling']: alife.brain.flag(LIFE[SETTINGS['controlling']], 'redraw', value=pos[:])
def move_camera(pos, scroll=False): _orig_pos = CAMERA_POS[:] if SETTINGS['controlling'] and SETTINGS['following'] == SETTINGS['controlling'] and locks.is_locked('camera_free'): _life = LIFE[SETTINGS['controlling']] _top_left = MAP_SIZE[:] _bot_right = [0, 0, 0] _seen = False for life_id in LIFE[SETTINGS['controlling']]['seen']: if LIFE[life_id]['dead']: continue if brain.knows_alife_by_id(LIFE[SETTINGS['controlling']], life_id)['alignment'] in ['trust', 'feign_trust']: continue _seen = True if LIFE[life_id]['pos'][0] < _top_left[0]: _top_left[0] = LIFE[life_id]['pos'][0] if LIFE[life_id]['pos'][1] < _top_left[1]: _top_left[1] = LIFE[life_id]['pos'][1] if LIFE[life_id]['pos'][0] > _bot_right[0]: _bot_right[0] = LIFE[life_id]['pos'][0] if LIFE[life_id]['pos'][1] > _bot_right[1]: _bot_right[1] = LIFE[life_id]['pos'][1] _target_pos = numbers.lerp_velocity(_top_left, _bot_right, 0.5) pos = numbers.lerp_velocity(pos, _target_pos, .35)[:2] pos.append(2) brain.flag(_life, 'camera_lean', value=_target_pos[:]) brain.flag(_life, 'camera_lean_time', value=WORLD_INFO['ticks']) _future_time = brain.get_flag(_life, 'camera_lean_time_future') if not _future_time or WORLD_INFO['ticks']>_future_time: brain.flag(_life, 'camera_lean_time_future', value=WORLD_INFO['ticks']+30) if brain.get_flag(_life, 'camera_lean'): if _seen: _st = WORLD_INFO['ticks']-(brain.get_flag(_life, 'camera_lean_time_future')-30) _et = brain.get_flag(_life, 'camera_lean_time_future')-(brain.get_flag(_life, 'camera_lean_time_future')-30) _lerp = 1-numbers.clip(_st/float(_et), 0, 1.0) pos = numbers.lerp_velocity(pos, brain.get_flag(_life, 'camera_lean'), _lerp)[:2] pos.append(2) else: if WORLD_INFO['ticks']-brain.get_flag(_life, 'camera_lean_time')<=20: _lerp = .45-numbers.clip((WORLD_INFO['ticks']-brain.get_flag(_life, 'camera_lean_time'))/30.0, 0, .45) pos = numbers.lerp_velocity(pos, brain.get_flag(_life, 'camera_lean'), _lerp)[:2] pos.append(2) else: brain.unflag(_life, 'camera_lean') brain.unflag(_life, 'camera_lean_time') CAMERA_POS[0] = int(round(numbers.clip(pos[0]-(MAP_WINDOW_SIZE[0]/2), 0, MAP_SIZE[0]-MAP_WINDOW_SIZE[0]))) CAMERA_POS[1] = int(round(numbers.clip(pos[1]-(MAP_WINDOW_SIZE[1]/2), 0, MAP_SIZE[1]-MAP_WINDOW_SIZE[1]))) CAMERA_POS[2] = int(round(pos[2])) if not _orig_pos == CAMERA_POS: gfx.refresh_view('map') elif SETTINGS['controlling'] and not alife.brain.get_flag(LIFE[SETTINGS['controlling']], 'redraw') == pos: gfx.refresh_view('map') if SETTINGS['controlling']: alife.brain.flag(LIFE[SETTINGS['controlling']], 'redraw', value=pos[:])