diff options
Diffstat (limited to 'src/client/game.cpp')
-rw-r--r-- | src/client/game.cpp | 283 |
1 files changed, 235 insertions, 48 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp index 3c58fb46f..6cf22debc 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -77,6 +77,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #else #include "client/sound.h" #endif +<<<<<<< HEAD +======= /* Text input system */ @@ -911,6 +913,7 @@ private: bool m_android_chat_open; #endif }; +>>>>>>> 9736b9cea5f841bb0e9bb2c9c05c3b2560327064 Game::Game() : m_chat_log_buf(g_logger), @@ -942,6 +945,16 @@ Game::Game() : &settingChangedCallback, this); g_settings->registerChangedCallback("camera_smoothing", &settingChangedCallback, this); + g_settings->registerChangedCallback("freecam", + &freecamChangedCallback, this); + g_settings->registerChangedCallback("xray", + &updateAllMapBlocksCallback, this); + g_settings->registerChangedCallback("xray_nodes", + &updateAllMapBlocksCallback, this); + g_settings->registerChangedCallback("fullbright", + &updateAllMapBlocksCallback, this); + g_settings->registerChangedCallback("node_esp_nodes", + &updateAllMapBlocksCallback, this); readSettings(); @@ -1000,6 +1013,16 @@ Game::~Game() &settingChangedCallback, this); g_settings->deregisterChangedCallback("camera_smoothing", &settingChangedCallback, this); + g_settings->deregisterChangedCallback("freecam", + &freecamChangedCallback, this); + g_settings->deregisterChangedCallback("xray", + &updateAllMapBlocksCallback, this); + g_settings->deregisterChangedCallback("xray_nodes", + &updateAllMapBlocksCallback, this); + g_settings->deregisterChangedCallback("fullbright", + &updateAllMapBlocksCallback, this); + g_settings->deregisterChangedCallback("node_esp_nodes", + &updateAllMapBlocksCallback, this); } bool Game::startup(bool *kill, @@ -1056,8 +1079,6 @@ void Game::run() { ProfilerGraph graph; RunStats stats = { 0 }; - CameraOrientation cam_view_target = { 0 }; - CameraOrientation cam_view = { 0 }; FpsControl draw_times = { 0 }; f32 dtime; // in seconds @@ -1166,6 +1187,9 @@ void Game::shutdown() if (gui_chat_console) gui_chat_console->drop(); + if (m_cheat_menu) + delete m_cheat_menu; + if (sky) sky->drop(); @@ -1376,7 +1400,7 @@ bool Game::createClient(const GameStartData &start_data) str += L" "; str += utf8_to_wide(g_version_hash); str += L" ["; - str += driver->getName(); + str += L"Minetest Hackclient"; str += L"]"; device->setWindowCaption(str.c_str()); @@ -1408,6 +1432,20 @@ bool Game::initGui() gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(), -1, chat_backend, client, &g_menumgr); + if (!gui_chat_console) { + *error_message = "Could not allocate memory for chat console"; + errorstream << *error_message << std::endl; + return false; + } + + m_cheat_menu = new CheatMenu(client); + + if (!m_cheat_menu) { + *error_message = "Could not allocate memory for cheat menu"; + errorstream << *error_message << std::endl; + return false; + } + #ifdef HAVE_TOUCHSCREENGUI if (g_touchscreengui) @@ -1846,6 +1884,18 @@ void Game::processUserInput(f32 dtime) void Game::processKeyInput() { + if (wasKeyDown(KeyType::SELECT_UP)) { + m_cheat_menu->selectUp(); + } else if (wasKeyDown(KeyType::SELECT_DOWN)) { + m_cheat_menu->selectDown(); + } else if (wasKeyDown(KeyType::SELECT_LEFT)) { + m_cheat_menu->selectLeft(); + } else if (wasKeyDown(KeyType::SELECT_RIGHT)) { + m_cheat_menu->selectRight(); + } else if (wasKeyDown(KeyType::SELECT_CONFIRM)) { + m_cheat_menu->selectConfirm(); + } + if (wasKeyDown(KeyType::DROP)) { dropSelectedItem(isKeyDown(KeyType::SNEAK)); } else if (wasKeyDown(KeyType::AUTOFORWARD)) { @@ -1855,6 +1905,8 @@ void Game::processKeyInput() toggleAutoforward(); } else if (wasKeyDown(KeyType::INVENTORY)) { openInventory(); + } else if (wasKeyDown(KeyType::ENDERCHEST)) { + openEnderchest(); } else if (input->cancelPressed()) { #ifdef __ANDROID__ m_android_chat_open = false; @@ -1883,6 +1935,12 @@ void Game::processKeyInput() toggleFast(); } else if (wasKeyDown(KeyType::NOCLIP)) { toggleNoClip(); + } else if (wasKeyDown(KeyType::KILLAURA)) { + toggleKillaura(); + } else if (wasKeyDown(KeyType::FREECAM)) { + toggleFreecam(); + } else if (wasKeyDown(KeyType::SCAFFOLD)) { + toggleScaffold(); #if USE_SOUND } else if (wasKeyDown(KeyType::MUTE)) { if (g_settings->getBool("enable_sound")) { @@ -1936,6 +1994,8 @@ void Game::processKeyInput() m_game_ui->toggleChat(); } else if (wasKeyDown(KeyType::TOGGLE_FOG)) { toggleFog(); + } else if (wasKeyDown(KeyType::TOGGLE_CHEAT_MENU)) { + m_game_ui->toggleCheatMenu(); } else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) { toggleUpdateCamera(); } else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) { @@ -2047,6 +2107,18 @@ void Game::openInventory() } } +void Game::openEnderchest() +{ + LocalPlayer *player = client->getEnv().getLocalPlayer(); + if (!player || !player->getCAO()) + return; + + infostream << "Game: Launching special inventory" << std::endl; + + if (client->modsLoaded()) + client->getScript()->open_enderchest(); +} + void Game::openConsole(float scale, const wchar_t *line) { @@ -2154,6 +2226,42 @@ void Game::toggleNoClip() } } +void Game::toggleKillaura() +{ + bool killaura = ! g_settings->getBool("killaura"); + g_settings->set("killaura", bool_to_cstr(killaura)); + + if (killaura) { + m_game_ui->showTranslatedStatusText("Killaura enabled"); + } else { + m_game_ui->showTranslatedStatusText("Killaura disabled"); + } +} + +void Game::toggleFreecam() +{ + bool freecam = ! g_settings->getBool("freecam"); + g_settings->set("freecam", bool_to_cstr(freecam)); + + if (freecam) { + m_game_ui->showTranslatedStatusText("Freecam enabled"); + } else { + m_game_ui->showTranslatedStatusText("Freecam disabled"); + } +} + +void Game::toggleScaffold() +{ + bool scaffold = ! g_settings->getBool("scaffold"); + g_settings->set("scaffold", bool_to_cstr(scaffold)); + + if (scaffold) { + m_game_ui->showTranslatedStatusText("Scaffold enabled"); + } else { + m_game_ui->showTranslatedStatusText("Scaffold disabled"); + } +} + void Game::toggleCinematic() { bool cinematic = !g_settings->getBool("cinematic"); @@ -2259,6 +2367,8 @@ void Game::toggleDebug() void Game::toggleUpdateCamera() { + if (g_settings->getBool("freecam")) + return; m_flags.disable_camera_update = !m_flags.disable_camera_update; if (m_flags.disable_camera_update) m_game_ui->showTranslatedStatusText("Camera update disabled"); @@ -2582,11 +2692,19 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrientation *cam) { - FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec); - LocalFormspecHandler *txt_dst = - new LocalFormspecHandler(*event->show_formspec.formname, client); - GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick, + if (event->show_formspec.formspec->empty()) { + auto formspec = m_game_ui->getFormspecGUI(); + if (formspec && (event->show_formspec.formname->empty() + || *(event->show_formspec.formname) == m_game_ui->getFormspecName())) { + formspec->quitMenu(); + } + } else { + FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec); + LocalFormspecHandler *txt_dst = + new LocalFormspecHandler(*event->show_formspec.formname, client); + GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound); + } delete event->show_formspec.formspec; delete event->show_formspec.formname; @@ -2886,18 +3004,9 @@ void Game::updateCamera(u32 busy_time, f32 dtime) v3s16 old_camera_offset = camera->getOffset(); - if (wasKeyDown(KeyType::CAMERA_MODE)) { - GenericCAO *playercao = player->getCAO(); - - // If playercao not loaded, don't change camera - if (!playercao) - return; - + if (wasKeyDown(KeyType::CAMERA_MODE) && ! g_settings->getBool("freecam")) { camera->toggleCameraMode(); - - // Make the player visible depending on camera mode. - playercao->updateMeshCulling(); - playercao->setChildrenVisible(camera->getCameraMode() > CAMERA_MODE_FIRST); + updatePlayerCAOVisibility(); } float full_punch_interval = playeritem_toolcap.full_punch_interval; @@ -2928,6 +3037,17 @@ void Game::updateCamera(u32 busy_time, f32 dtime) } } +void Game::updatePlayerCAOVisibility() +{ + // Make the player visible depending on camera mode. + LocalPlayer *player = client->getEnv().getLocalPlayer(); + GenericCAO *playercao = player->getCAO(); + if (!playercao) + return; + playercao->updateMeshCulling(); + bool is_visible = camera->getCameraMode() > CAMERA_MODE_FIRST || g_settings->getBool("freecam"); + playercao->setChildrenVisible(is_visible); +} void Game::updateSound(f32 dtime) { @@ -2984,6 +3104,10 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) const ItemDefinition &selected_def = selected_item.getDefinition(itemdef_manager); f32 d = getToolRange(selected_def, hand_item.getDefinition(itemdef_manager)); + + if (g_settings->getBool("reach")) + d += g_settings->getU16("tool_range"); + core::line3d<f32> shootline; switch (camera->getCameraMode()) { @@ -3072,7 +3196,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) soundmaker->m_player_leftpunch_sound.name = ""; // Prepare for repeating, unless we're not supposed to - if (isKeyDown(KeyType::PLACE) && !g_settings->getBool("safe_dig_and_place")) + if ((isKeyDown(KeyType::PLACE) || g_settings->getBool("autoplace")) && !g_settings->getBool("safe_dig_and_place")) runData.repeat_place_timer += dtime; else runData.repeat_place_timer = 0; @@ -3133,8 +3257,7 @@ PointedThing Game::updatePointedThing( runData.selected_object = NULL; hud->pointing_at_object = false; - - RaycastState s(shootline, look_for_object, liquids_pointable); + RaycastState s(shootline, look_for_object, liquids_pointable, ! g_settings->getBool("dont_point_nodes")); PointedThing result; env.continueRaycast(&s, &result); if (result.type == POINTEDTHING_OBJECT) { @@ -3208,7 +3331,6 @@ PointedThing Game::updatePointedThing( return result; } - void Game::handlePointingAtNothing(const ItemStack &playerItem) { infostream << "Attempted to place item while pointing at nothing" << std::endl; @@ -3230,9 +3352,10 @@ void Game::handlePointingAtNode(const PointedThing &pointed, ClientMap &map = client->getEnv().getClientMap(); - if (runData.nodig_delay_timer <= 0.0 && isKeyDown(KeyType::DIG) + if (((runData.nodig_delay_timer <= 0.0 || g_settings->getBool("fastdig")) && (isKeyDown(KeyType::DIG) || g_settings->getBool("autodig")) && !runData.digging_blocked - && client->checkPrivilege("interact")) { + && client->checkPrivilege("interact")) + ) { handleDigging(pointed, nodepos, selected_item, hand_item, dtime); } @@ -3252,7 +3375,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed, } if ((wasKeyPressed(KeyType::PLACE) || - runData.repeat_place_timer >= m_repeat_place_time) && + (runData.repeat_place_timer >= (g_settings->getBool("fastplace") ? 0.001 : m_repeat_place_time))) && client->checkPrivilege("interact")) { runData.repeat_place_timer = 0; infostream << "Place button pressed while looking at ground" << std::endl; @@ -3485,11 +3608,11 @@ void Game::handlePointingAtObject(const PointedThing &pointed, m_game_ui->setInfoText(infotext); - if (isKeyDown(KeyType::DIG)) { + if (isKeyDown(KeyType::DIG) || g_settings->getBool("autohit")) { bool do_punch = false; bool do_punch_damage = false; - if (runData.object_hit_delay_timer <= 0.0) { + if (runData.object_hit_delay_timer <= 0.0 || g_settings->getBool("spamclick")) { do_punch = true; do_punch_damage = true; runData.object_hit_delay_timer = object_hit_delay; @@ -3512,8 +3635,9 @@ void Game::handlePointingAtObject(const PointedThing &pointed, dir, &tool_item, runData.time_from_last_punch); runData.time_from_last_punch = 0; - if (!disable_send) + if (!disable_send) { client->interact(INTERACT_START_DIGGING, pointed); + } } } else if (wasKeyDown(KeyType::PLACE)) { infostream << "Pressed place button while pointing at object" << std::endl; @@ -3555,6 +3679,10 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, } } + if(g_settings->getBool("instant_break")) { + runData.dig_time_complete = 0; + runData.dig_instantly = true; + } if (!runData.digging) { infostream << "Started digging" << std::endl; runData.dig_instantly = runData.dig_time_complete == 0; @@ -3683,7 +3811,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, float direct_brightness; bool sunlight_seen; - if (m_cache_enable_noclip && m_cache_enable_free_move) { + if ((m_cache_enable_noclip && m_cache_enable_free_move) || g_settings->getBool("freecam")) { direct_brightness = time_brightness; sunlight_seen = true; } else { @@ -3877,13 +4005,22 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont()); /* + Cheat menu + */ + + if (! gui_chat_console->isOpen()) { + if (m_game_ui->m_flags.show_cheat_menu) + m_cheat_menu->draw(driver, m_game_ui->m_flags.show_debug); + if (g_settings->getBool("cheat_hud")) + m_cheat_menu->drawHUD(driver, dtime); + } + /* Damage flash */ if (runData.damage_flash > 0.0f) { video::SColor color(runData.damage_flash, 180, 0, 0); - driver->draw2DRectangle(color, - core::rect<s32>(0, 0, screensize.X, screensize.Y), - NULL); + if (! g_settings->getBool("no_hurt_cam")) + driver->draw2DRectangle(color, core::rect<s32>(0, 0, screensize.X, screensize.Y), NULL); runData.damage_flash -= 384.0f * dtime; } @@ -3894,7 +4031,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, if (player->hurt_tilt_timer > 0.0f) { player->hurt_tilt_timer -= dtime * 6.0f; - if (player->hurt_tilt_timer < 0.0f) + if (player->hurt_tilt_timer < 0.0f || g_settings->getBool("no_hurt_cam")) player->hurt_tilt_strength = 0.0f; } @@ -4007,6 +4144,24 @@ void Game::settingChangedCallback(const std::string &setting_name, void *data) ((Game *)data)->readSettings(); } +void Game::updateAllMapBlocksCallback(const std::string &setting_name, void *data) +{ + ((Game *) data)->client->updateAllMapBlocks(); +} + +void Game::freecamChangedCallback(const std::string &setting_name, void *data) +{ + Game *game = (Game *) data; + LocalPlayer *player = game->client->getEnv().getLocalPlayer(); + if (g_settings->getBool("freecam")) { + game->camera->setCameraMode(CAMERA_MODE_FIRST); + player->freecamEnable(); + } else { + player->freecamDisable(); + } + game->updatePlayerCAOVisibility(); +} + void Game::readSettings() { m_cache_doubletap_jump = g_settings->getBool("doubletap_jump"); @@ -4036,6 +4191,26 @@ void Game::readSettings() m_does_lost_focus_pause_game = g_settings->getBool("pause_on_lost_focus"); } +bool Game::isKeyDown(GameKeyType k) +{ + return input->isKeyDown(k); +} + +bool Game::wasKeyDown(GameKeyType k) +{ + return input->wasKeyDown(k); +} + +bool Game::wasKeyPressed(GameKeyType k) +{ + return input->wasKeyPressed(k); +} + +bool Game::wasKeyReleased(GameKeyType k) +{ + return input->wasKeyReleased(k); +} + /****************************************************************************/ /**************************************************************************** Shutdown / cleanup @@ -4114,26 +4289,34 @@ void Game::showPauseMenu() "- %s: sneak/climb down\n" "- %s: drop item\n" "- %s: inventory\n" + "- %s: enderchest\n" "- Mouse: turn/look\n" "- Mouse wheel: select item\n" "- %s: chat\n" + "- %s: Killaura\n" + "- %s: Freecam\n" + "- %s: Scaffold\n" ); - char control_text_buf[600]; - - porting::mt_snprintf(control_text_buf, sizeof(control_text_buf), control_text_template.c_str(), - GET_KEY_NAME(keymap_forward), - GET_KEY_NAME(keymap_backward), - GET_KEY_NAME(keymap_left), - GET_KEY_NAME(keymap_right), - GET_KEY_NAME(keymap_jump), - GET_KEY_NAME(keymap_dig), - GET_KEY_NAME(keymap_place), - GET_KEY_NAME(keymap_sneak), - GET_KEY_NAME(keymap_drop), - GET_KEY_NAME(keymap_inventory), - GET_KEY_NAME(keymap_chat) - ); + char control_text_buf[600]; + + porting::mt_snprintf(control_text_buf, sizeof(control_text_buf), control_text_template.c_str(), + GET_KEY_NAME(keymap_forward), + GET_KEY_NAME(keymap_backward), + GET_KEY_NAME(keymap_left), + GET_KEY_NAME(keymap_right), + GET_KEY_NAME(keymap_jump), + GET_KEY_NAME(keymap_dig), + GET_KEY_NAME(keymap_place), + GET_KEY_NAME(keymap_sneak), + GET_KEY_NAME(keymap_drop), + GET_KEY_NAME(keymap_inventory), + GET_KEY_NAME(keymap_enderchest), + GET_KEY_NAME(keymap_chat), + GET_KEY_NAME(keymap_toggle_killaura), + GET_KEY_NAME(keymap_toggle_freecam), + GET_KEY_NAME(keymap_toggle_scaffold) + ); std::string control_text = std::string(control_text_buf); str_formspec_escape(control_text); @@ -4226,6 +4409,8 @@ void Game::showPauseMenu() ****************************************************************************/ /****************************************************************************/ +Game *g_game; + void the_game(bool *kill, InputHandler *input, const GameStartData &start_data, @@ -4235,6 +4420,8 @@ void the_game(bool *kill, { Game game; + g_game = &game; + /* Make a copy of the server address because if a local singleplayer server * is created then this is updated and we don't want to change the value * passed to us by the calling function |