From f269b4db91ce483ad5bc5bf31194d1a0644ff84e Mon Sep 17 00:00:00 2001 From: Richard Qian Date: Mon, 8 Mar 2021 21:27:39 -0600 Subject: [PATCH] Make demo mode use less hard-coded items The player kart, difficulty, game mode, and reverse are no longer static values Also ensure that there is a value pressed when exiting demo via a keypress --- src/input/input_manager.cpp | 2 +- src/modes/demo_world.cpp | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index a3301d7c6..539b7c154 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -590,7 +590,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, // Abort demo mode if a key is pressed during the race in demo mode, // if a dialog is not active if(dynamic_cast(World::getWorld()) && - !GUIEngine::ModalDialog::isADialogActive()) + !GUIEngine::ModalDialog::isADialogActive() && value) { RaceManager::get()->exitRace(); StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); diff --git a/src/modes/demo_world.cpp b/src/modes/demo_world.cpp index 032f2bc69..d032eb9a2 100644 --- a/src/modes/demo_world.cpp +++ b/src/modes/demo_world.cpp @@ -48,9 +48,36 @@ DemoWorld::DemoWorld() setPhase(SETUP_PHASE); m_abort = false; ProfileWorld::setProfileModeLaps(m_num_laps); - RaceManager::get()->setReverseTrack(false); - RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_NORMAL_RACE); - RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_HARD); + + // Randomly select whether reverse mode is activated or not. + if (rand() % 2 == 0) + RaceManager::get()->setReverseTrack(true); + else + RaceManager::get()->setReverseTrack(false); + + // Selects the user's current game mode setting (not all modes are supported) + switch (atoi(UserConfigParams::m_game_mode.toString().c_str())) + { + case 0: RaceManager::get()->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE); break; + case 1: RaceManager::get()->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL); break; + case 2: RaceManager::get()->setMinorMode(RaceManager::MINOR_MODE_FOLLOW_LEADER); break; + default: RaceManager::get()->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE); break; + } + // Selects the user's current difficulty setting + switch (atoi(UserConfigParams::m_difficulty.toString().c_str())) + { + case 0: RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY); break; + case 1: RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_MEDIUM); break; + case 2: RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_HARD); break; + case 3: RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_BEST); break; + default: RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_HARD); break; + } + + Log::info("[DemoWorld]", "Reverse mode state: %d", RaceManager::get()->getReverseTrack()); + Log::info("[DemoWorld]", "Current game mode: %s", RaceManager::get()->getMinorModeName().c_str()); + Log::info("[DemoWorld]", "Current difficulty: %s", RaceManager::get()-> + getDifficultyAsString(RaceManager::get()->getDifficulty()).c_str()); + RaceManager::get()->setNumKarts(m_default_num_karts); RaceManager::get()->setNumPlayers(1); RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart); @@ -155,7 +182,8 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt) m_do_demo = true; RaceManager::get()->setNumKarts(m_default_num_karts); - RaceManager::get()->setPlayerKart(0, "tux"); + // Use the user's last selected kart + RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart); RaceManager::get()->setupPlayerKartInfo(); RaceManager::get()->startSingleRace(m_demo_tracks[0], m_num_laps, false); m_demo_tracks.push_back(m_demo_tracks[0]);