/* call this function before leaving the old level, but DO NOT call it when saving the player. it should be called when you're leaving the game (i.e., quitting or reverting, etc.) */ void leaving_map( void) { remove_all_projectiles(); remove_all_nonpersistent_effects(); /* mark our shape collections for unloading */ mark_environment_collections(static_world->environment_code, false); mark_all_monster_collections(false); mark_player_collections(false); mark_map_collections(false); MarkLuaCollections(false); MarkLuaHUDCollections(false); L_Call_Cleanup (); // don't send stats on film replay // don't call player_controlling_game() since game_state.state has changed short user = get_game_controller(); if (user == _single_player || user == _network_player) { // upload the stats! StatsManager::instance()->Process(); } //Close and unload the Lua state CloseLuaScript(); #if !defined(DISABLE_NETWORKING) NetSetChatCallbacks(NULL); #endif // !defined(DISABLE_NETWORKING) Console::instance()->deactivate_input(); /* all we do is mark them for unloading, we don't explicitly dispose of them; whenever the next level is loaded someone (probably entering_map, below) will call load_collections() and the stuff we marked as needed to be ditched will be */ /* stop counting world ticks */ // set_keyboard_controller_status(false); // Hackish. Should probably be in stop_all_sounds(), but that just // doesn't work out. Music::instance()->StopLevelMusic(); SoundManager::instance()->StopAllSounds(); }
static void handle_game_key(const SDL_Event &event) { SDL_Keycode key = event.key.keysym.sym; SDL_Scancode sc = event.key.keysym.scancode; bool changed_screen_mode = false; bool changed_prefs = false; if (!game_is_networked && (event.key.keysym.mod & KMOD_CTRL) && CheatsActive) { int type_of_cheat = process_keyword_key(key); if (type_of_cheat != NONE) handle_keyword(type_of_cheat); } if (Console::instance()->input_active()) { switch(key) { case SDLK_RETURN: case SDLK_KP_ENTER: Console::instance()->enter(); break; case SDLK_ESCAPE: Console::instance()->abort(); break; case SDLK_BACKSPACE: Console::instance()->backspace(); break; case SDLK_DELETE: Console::instance()->del(); break; case SDLK_UP: Console::instance()->up_arrow(); break; case SDLK_DOWN: Console::instance()->down_arrow(); break; case SDLK_LEFT: Console::instance()->left_arrow(); break; case SDLK_RIGHT: Console::instance()->right_arrow(); break; case SDLK_HOME: Console::instance()->line_home(); break; case SDLK_END: Console::instance()->line_end(); break; case SDLK_a: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->line_home(); break; case SDLK_b: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->left_arrow(); break; case SDLK_d: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->del(); break; case SDLK_e: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->line_end(); break; case SDLK_f: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->right_arrow(); break; case SDLK_h: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->backspace(); break; case SDLK_k: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->forward_clear(); break; case SDLK_n: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->down_arrow(); break; case SDLK_p: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->up_arrow(); break; case SDLK_t: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->transpose(); break; case SDLK_u: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->clear(); break; case SDLK_w: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->delete_word(); break; } } else { if (sc == SDL_SCANCODE_ESCAPE) // (ZZZ) Quit gesture (now safer) { if(!player_controlling_game()) do_menu_item_command(mGame, iQuitGame, false); else { if(get_ticks_since_local_player_in_terminal() > 1 * TICKS_PER_SECOND) { if(!game_is_networked) { do_menu_item_command(mGame, iQuitGame, false); } else { #if defined(__APPLE__) && defined(__MACH__) screen_printf("If you wish to quit, press Command-Q"); #else screen_printf("If you wish to quit, press Alt+Q."); #endif } } } } else if (input_preferences->shell_key_bindings[_key_volume_up].count(sc)) { changed_prefs = SoundManager::instance()->AdjustVolumeUp(Sound_AdjustVolume()); } else if (input_preferences->shell_key_bindings[_key_volume_down].count(sc)) { changed_prefs = SoundManager::instance()->AdjustVolumeDown(Sound_AdjustVolume()); } else if (input_preferences->shell_key_bindings[_key_switch_view].count(sc)) { walk_player_list(); render_screen(NONE); } else if (input_preferences->shell_key_bindings[_key_zoom_in].count(sc)) { if (zoom_overhead_map_in()) PlayInterfaceButtonSound(Sound_ButtonSuccess()); else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else if (input_preferences->shell_key_bindings[_key_zoom_out].count(sc)) { if (zoom_overhead_map_out()) PlayInterfaceButtonSound(Sound_ButtonSuccess()); else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else if (input_preferences->shell_key_bindings[_key_inventory_left].count(sc)) { if (player_controlling_game()) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); scroll_inventory(-1); } else decrement_replay_speed(); } else if (input_preferences->shell_key_bindings[_key_inventory_right].count(sc)) { if (player_controlling_game()) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); scroll_inventory(1); } else increment_replay_speed(); } else if (input_preferences->shell_key_bindings[_key_toggle_fps].count(sc)) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); extern bool displaying_fps; displaying_fps = !displaying_fps; } else if (input_preferences->shell_key_bindings[_key_activate_console].count(sc)) { if (game_is_networked) { #if !defined(DISABLE_NETWORKING) Console::instance()->activate_input(InGameChatCallbacks::SendChatMessage, InGameChatCallbacks::prompt()); #endif PlayInterfaceButtonSound(Sound_ButtonSuccess()); } else if (Console::instance()->use_lua_console()) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); Console::instance()->activate_input(ExecuteLuaString, ">"); } else { PlayInterfaceButtonSound(Sound_ButtonFailure()); } } else if (input_preferences->shell_key_bindings[_key_show_scores].count(sc)) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); { extern bool ShowScores; ShowScores = !ShowScores; } } else if (sc == SDL_SCANCODE_F1) // Decrease screen size { if (!graphics_preferences->screen_mode.hud) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.hud = true; changed_screen_mode = changed_prefs = true; } else { int mode = alephone::Screen::instance()->FindMode(get_screen_mode()->width, get_screen_mode()->height); if (mode < alephone::Screen::instance()->GetModes().size() - 1) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.width = alephone::Screen::instance()->ModeWidth(mode + 1); graphics_preferences->screen_mode.height = alephone::Screen::instance()->ModeHeight(mode + 1); graphics_preferences->screen_mode.auto_resolution = false; graphics_preferences->screen_mode.hud = false; changed_screen_mode = changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } } else if (sc == SDL_SCANCODE_F2) // Increase screen size { if (graphics_preferences->screen_mode.hud) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.hud = false; changed_screen_mode = changed_prefs = true; } else { int mode = alephone::Screen::instance()->FindMode(get_screen_mode()->width, get_screen_mode()->height); int automode = get_screen_mode()->fullscreen ? 0 : 1; if (mode > automode) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.width = alephone::Screen::instance()->ModeWidth(mode - 1); graphics_preferences->screen_mode.height = alephone::Screen::instance()->ModeHeight(mode - 1); if ((mode - 1) == automode) graphics_preferences->screen_mode.auto_resolution = true; graphics_preferences->screen_mode.hud = true; changed_screen_mode = changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } } else if (sc == SDL_SCANCODE_F3) // Resolution toggle { if (!OGL_IsActive()) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.high_resolution = !graphics_preferences->screen_mode.high_resolution; changed_screen_mode = changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else if (sc == SDL_SCANCODE_F4) // Reset OpenGL textures { #ifdef HAVE_OPENGL if (OGL_IsActive()) { // Play the button sound in advance to get the full effect of the sound PlayInterfaceButtonSound(Sound_OGL_Reset()); OGL_ResetTextures(); } else #endif PlayInterfaceButtonSound(Sound_ButtonInoperative()); } else if (sc == SDL_SCANCODE_F5) // Make the chase cam switch sides { if (ChaseCam_IsActive()) PlayInterfaceButtonSound(Sound_ButtonSuccess()); else PlayInterfaceButtonSound(Sound_ButtonInoperative()); ChaseCam_SwitchSides(); } else if (sc == SDL_SCANCODE_F6) // Toggle the chase cam { PlayInterfaceButtonSound(Sound_ButtonSuccess()); ChaseCam_SetActive(!ChaseCam_IsActive()); } else if (sc == SDL_SCANCODE_F7) // Toggle tunnel vision { PlayInterfaceButtonSound(Sound_ButtonSuccess()); SetTunnelVision(!GetTunnelVision()); } else if (sc == SDL_SCANCODE_F8) // Toggle the crosshairs { PlayInterfaceButtonSound(Sound_ButtonSuccess()); player_preferences->crosshairs_active = !player_preferences->crosshairs_active; Crosshairs_SetActive(player_preferences->crosshairs_active); changed_prefs = true; } else if (sc == SDL_SCANCODE_F9) // Screen dump { dump_screen(); } else if (sc == SDL_SCANCODE_F10) // Toggle the position display { PlayInterfaceButtonSound(Sound_ButtonSuccess()); { extern bool ShowPosition; ShowPosition = !ShowPosition; } } else if (sc == SDL_SCANCODE_F11) // Decrease gamma level { if (graphics_preferences->screen_mode.gamma_level) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.gamma_level--; change_gamma_level(graphics_preferences->screen_mode.gamma_level); changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else if (sc == SDL_SCANCODE_F12) // Increase gamma level { if (graphics_preferences->screen_mode.gamma_level < NUMBER_OF_GAMMA_LEVELS - 1) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.gamma_level++; change_gamma_level(graphics_preferences->screen_mode.gamma_level); changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else { if (get_game_controller() == _demo) set_game_state(_close_game); } } if (changed_screen_mode) { screen_mode_data temp_screen_mode = graphics_preferences->screen_mode; temp_screen_mode.fullscreen = get_screen_mode()->fullscreen; change_screen_mode(&temp_screen_mode, true); render_screen(0); } if (changed_prefs) write_preferences(); }