/** * \brief This function is called when a game command is released. * \param command A game command. */ void Game::notify_command_released(GameCommands::Command command) { bool handled = get_lua_context().game_on_command_released(*this, command); if (!handled) { handled = get_lua_context().map_on_command_released(get_current_map(), command); if (!handled) { // The Lua script did not override the command: do the built-in behavior. if (!is_suspended()) { // When the game is not suspended, the command apply to the hero. hero->notify_command_released(command); } } } }
/** * \brief This function is called when a game command is pressed. * \param command A game command. */ void Game::notify_command_pressed(GameCommands::Command command) { // Is a built-in dialog box being shown? if (is_dialog_enabled()) { if (dialog_box.notify_command_pressed(command)) { return; } } // See if the game script handles the command. if (get_lua_context().game_on_command_pressed(*this, command)) { return; } // See if the map script handled the command. if (get_lua_context().map_on_command_pressed(get_current_map(), command)) { return; } // Lua scripts did not override the command: do the built-in behavior. if (command == GameCommands::PAUSE) { if (is_paused()) { if (can_unpause()) { set_paused(false); } } else { if (can_pause()) { set_paused(true); } } } else if (!is_suspended()) { // When the game is not suspended, all other commands apply to the hero. hero->notify_command_pressed(command); } }
/** * @brief Returns whether the current map belongs to a dungeon. * @return true if the current map is in a dungeon */ bool Game::is_in_dungeon() { return has_current_map() && get_current_map().is_in_dungeon(); }