diff --git a/CMakeLists.txt b/CMakeLists.txt index e48bcb874..64fcec66f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,10 @@ add_definitions( -DSUPERTUXKART_VERSION="${PROJECT_VERSION}" ) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") include(CMakeDependentOption) +if(MSVC) + cmake_policy(SET CMP0043 OLD) +endif() + include(BuildTypeSTKRelease) if(NOT CMAKE_BUILD_TYPE) message(STATUS "No build type selected, default to STKRelease") diff --git a/src/config/player_profile.hpp b/src/config/player_profile.hpp index ed7333465..f70c5fe99 100644 --- a/src/config/player_profile.hpp +++ b/src/config/player_profile.hpp @@ -160,7 +160,9 @@ public: /** Returns the name of this player. */ const core::stringw& getName() const { + #ifdef DEBUG assert(m_magic_number == 0xABCD1234); + #endif return m_local_name; } // getName diff --git a/src/modes/tutorial_utils.cpp b/src/modes/tutorial_utils.cpp new file mode 100644 index 000000000..b727edd38 --- /dev/null +++ b/src/modes/tutorial_utils.cpp @@ -0,0 +1,62 @@ +// SuperTuxKart - a fun racing game with go-kart +// +// Copyright (C) 2024 Alayan +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "modes/tutorial_utils.hpp" + +#include "config/player_manager.hpp" +#include "config/user_config.hpp" +#include "karts/kart_properties_manager.hpp" +#include "input/device_manager.hpp" +#include "input/input_manager.hpp" +#include "race/race_manager.hpp" + +namespace TutorialUtils +{ + void startTutorial(bool from_overworld) + { + RaceManager::get()->setNumPlayers(1); + RaceManager::get()->setMajorMode (RaceManager::MAJOR_MODE_SINGLE); + RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL); + RaceManager::get()->setNumKarts( 1 ); + RaceManager::get()->setTrack( "tutorial" ); + RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY); + RaceManager::get()->setReverseTrack(false); + + // Use the last used device + InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice(); + + // Create player and associate player with device + StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), device); + + if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) + { + Log::warn("HelpScreen1", "Cannot find kart '%s', will revert to default", + UserConfigParams::m_default_kart.c_str()); + UserConfigParams::m_default_kart.revertToDefaults(); + } + RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart); + + // ASSIGN should make sure that only input from assigned devices is read. + input_manager->getDeviceManager()->setAssignMode(ASSIGN); + input_manager->getDeviceManager()->setSinglePlayer( StateManager::get()->getActivePlayer(0) ); + + StateManager::get()->enterGameState(); + RaceManager::get()->setupPlayerKartInfo(); + RaceManager::get()->startNew(from_overworld); + } +} \ No newline at end of file diff --git a/src/modes/tutorial_utils.hpp b/src/modes/tutorial_utils.hpp new file mode 100644 index 000000000..2c5f6745e --- /dev/null +++ b/src/modes/tutorial_utils.hpp @@ -0,0 +1,27 @@ +// SuperTuxKart - a fun racing game with go-kart +// +// Copyright (C) 2024 Alayan +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __HEADER_TUTORIAL_UTILS_HPP__ +#define __HEADER_TUTORIAL_UTILS_HPP__ + +namespace TutorialUtils +{ + void startTutorial(bool from_overworld = false); +} + +#endif \ No newline at end of file diff --git a/src/modes/world.cpp b/src/modes/world.cpp index a4a85fe6d..decf04c5d 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -52,6 +52,7 @@ #include "karts/kart_rewinder.hpp" #include "main_loop.hpp" #include "modes/overworld.hpp" +#include "modes/tutorial_utils.hpp" #include "network/child_loop.hpp" #include "network/protocols/client_lobby.hpp" #include "network/network_config.hpp" @@ -82,12 +83,6 @@ #include "utils/translation.hpp" #include "utils/string_utils.hpp" -#include -#include -#include -#include -#include - #include #include @@ -1016,7 +1011,6 @@ void World::updateWorld(int ticks) assert(m_magic_number == 0xB01D6543); #endif - if (m_schedule_pause) { pause(m_scheduled_pause_phase); @@ -1067,41 +1061,8 @@ void World::updateWorld(int ticks) if (m_schedule_tutorial) { m_schedule_tutorial = false; - RaceManager::get()->setNumPlayers(1); - RaceManager::get()->setMajorMode (RaceManager::MAJOR_MODE_SINGLE); - RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL); - RaceManager::get()->setNumKarts( 1 ); - RaceManager::get()->setTrack( "tutorial" ); - RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY); - RaceManager::get()->setReverseTrack(false); - - // Use keyboard 0 by default (FIXME: let player choose?) - InputDevice* device = input_manager->getDeviceManager()->getKeyboard(0); - - // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), - device); - - if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart)) - { - Log::warn("[World]", - "Cannot find kart '%s', will revert to default.", - UserConfigParams::m_default_kart.c_str()); - UserConfigParams::m_default_kart.revertToDefaults(); - } - RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart); - - // ASSIGN should make sure that only input from assigned devices - // is read. - input_manager->getDeviceManager()->setAssignMode(ASSIGN); - input_manager->getDeviceManager() - ->setSinglePlayer( StateManager::get()->getActivePlayer(0) ); - delete this; - - StateManager::get()->enterGameState(); - RaceManager::get()->setupPlayerKartInfo(); - RaceManager::get()->startNew(true); + TutorialUtils::startTutorial(true /*from overworld*/); } else { @@ -1123,6 +1084,7 @@ void World::updateWorld(int ticks) void World::scheduleTutorial() { + printf("Tutorial scheduled\n"); m_schedule_exit_race = true; m_schedule_tutorial = true; } // scheduleTutorial diff --git a/src/states_screens/help/help_screen_1.cpp b/src/states_screens/help/help_screen_1.cpp index 18d8e5ecf..bb6c6d5ba 100644 --- a/src/states_screens/help/help_screen_1.cpp +++ b/src/states_screens/help/help_screen_1.cpp @@ -18,13 +18,8 @@ // Manages includes common to all help screens #include "states_screens/help/help_common.hpp" -#include "config/player_manager.hpp" -#include "config/user_config.hpp" #include "guiengine/widgets/button_widget.hpp" -#include "input/device_manager.hpp" -#include "input/input_manager.hpp" -#include "karts/kart_properties_manager.hpp" -#include "race/race_manager.hpp" +#include "modes/tutorial_utils.hpp" using namespace GUIEngine; @@ -46,38 +41,7 @@ void HelpScreen1::eventCallback(Widget* widget, const std::string& name, const i { if (name == "startTutorial") { - RaceManager::get()->setNumPlayers(1); - RaceManager::get()->setMajorMode (RaceManager::MAJOR_MODE_SINGLE); - RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL); - RaceManager::get()->setNumKarts( 1 ); - RaceManager::get()->setTrack( "tutorial" ); - RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY); - RaceManager::get()->setReverseTrack(false); - - // Use the last used device - InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice(); - - // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), - device); - - if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) - { - Log::warn("HelpScreen1", "Cannot find kart '%s', will revert to default", - UserConfigParams::m_default_kart.c_str()); - UserConfigParams::m_default_kart.revertToDefaults(); - } - RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart); - - // ASSIGN should make sure that only input from assigned devices - // is read. - input_manager->getDeviceManager()->setAssignMode(ASSIGN); - input_manager->getDeviceManager() - ->setSinglePlayer( StateManager::get()->getActivePlayer(0) ); - - StateManager::get()->enterGameState(); - RaceManager::get()->setupPlayerKartInfo(); - RaceManager::get()->startNew(false); + TutorialUtils::startTutorial(); } else if (name == "category") { diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index a28dc2645..e52995cd6 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -38,8 +38,9 @@ #include "karts/kart_properties_manager.hpp" #include "main_loop.hpp" #include "modes/cutscene_world.hpp" -#include "modes/overworld.hpp" #include "modes/demo_world.hpp" +#include "modes/overworld.hpp" +#include "modes/tutorial_utils.hpp" #include "network/network_config.hpp" #include "online/request_manager.hpp" #include "states_screens/addons_screen.hpp" @@ -258,7 +259,7 @@ void MainMenuScreen::onUpdate(float delta) virtual void onConfirm() { GUIEngine::ModalDialog::dismiss(); - MainMenuScreen::getInstance()->startTutorial(); + TutorialUtils::startTutorial(); } // onConfirm }; // PlayTutorial @@ -271,41 +272,6 @@ void MainMenuScreen::onUpdate(float delta) #endif } // onUpdate -// ---------------------------------------------------------------------------- -void MainMenuScreen::startTutorial() -{ - RaceManager::get()->setNumPlayers(1); - RaceManager::get()->setMajorMode (RaceManager::MAJOR_MODE_SINGLE); - RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL); - RaceManager::get()->setNumKarts( 1 ); - RaceManager::get()->setTrack("tutorial"); - RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY); - RaceManager::get()->setReverseTrack(false); - - // Use the last used device - InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice(); - - // Create player and associate player with device - StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), device); - - if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) - { - Log::warn("MainMenuScreen", "Cannot find kart '%s', will revert to default", - UserConfigParams::m_default_kart.c_str()); - UserConfigParams::m_default_kart.revertToDefaults(); - } - RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart); - - // ASSIGN should make sure that only input from assigned devices is read - input_manager->getDeviceManager()->setAssignMode(ASSIGN); - input_manager->getDeviceManager() - ->setSinglePlayer( StateManager::get()->getActivePlayer(0) ); - - StateManager::get()->enterGameState(); - RaceManager::get()->setupPlayerKartInfo(); - RaceManager::get()->startNew(false); -} // startTutorial - // ---------------------------------------------------------------------------- void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, @@ -509,7 +475,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, } else if (selection == "startTutorial") { - startTutorial(); + TutorialUtils::startTutorial(); } else if (selection == "story") { diff --git a/src/states_screens/main_menu_screen.hpp b/src/states_screens/main_menu_screen.hpp index ce495e3b8..4967d262d 100644 --- a/src/states_screens/main_menu_screen.hpp +++ b/src/states_screens/main_menu_screen.hpp @@ -38,8 +38,6 @@ private: core::stringw m_news_text; MainMenuScreen(); - - void startTutorial(); public: virtual void onUpdate(float delta) OVERRIDE;