From a84094e55ebbc5b3ff173d06bb28830af2662d5f Mon Sep 17 00:00:00 2001 From: Flakebi Date: Tue, 29 Jul 2014 22:54:42 +0200 Subject: [PATCH] Add difficulty to karts --- data/stk_config.xml | 82 +++++++++++++++-- src/karts/player_difficulty.cpp | 87 ++++++++++--------- src/network/game_setup.hpp | 2 + src/network/protocols/start_game_protocol.cpp | 2 + src/race/race_manager.cpp | 12 ++- src/race/race_manager.hpp | 4 + src/states_screens/kart_selection.cpp | 53 ++++++++++- src/states_screens/kart_selection.hpp | 9 ++ 8 files changed, 199 insertions(+), 52 deletions(-) diff --git a/data/stk_config.xml b/data/stk_config.xml index 59fda6583..cdff5684d 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -336,22 +336,92 @@ + These values are multiplied with the current values of a car. --> - + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + diff --git a/src/karts/player_difficulty.cpp b/src/karts/player_difficulty.cpp index 501c1839c..3cd19a311 100644 --- a/src/karts/player_difficulty.cpp +++ b/src/karts/player_difficulty.cpp @@ -97,48 +97,8 @@ void PlayerDifficulty::load(const std::string &filename, const std::string &node */ void PlayerDifficulty::getAllData(const XMLNode * root) { - if(const XMLNode *nitro_node = root->getNode("nitro")) - { - nitro_node->get("consumption", &m_nitro_consumption ); - nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase); - nitro_node->get("engine-force", &m_nitro_engine_force ); - nitro_node->get("duration", &m_nitro_duration ); - nitro_node->get("fade-out-time", &m_nitro_fade_out_time ); - } - - if(const XMLNode *bubble_node = root->getNode("bubblegum")) - { - bubble_node->get("time", &m_bubblegum_time ); - bubble_node->get("speed-fraction", &m_bubblegum_speed_fraction); - bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time ); - bubble_node->get("torque", &m_bubblegum_torque ); - } - - if(const XMLNode *rescue_node = root->getNode("rescue")) - { - rescue_node->get("time", &m_rescue_time ); - } - - if(const XMLNode *explosion_node = root->getNode("explosion")) - { - explosion_node->get("time", &m_explosion_time ); - explosion_node->get("invulnerability-time", - &m_explosion_invulnerability_time); - } - - if(const XMLNode *slipstream_node = root->getNode("slipstream")) - { - slipstream_node->get("length", &m_slipstream_length ); - slipstream_node->get("width", &m_slipstream_width ); - slipstream_node->get("collect-time", &m_slipstream_collect_time ); - slipstream_node->get("use-time", &m_slipstream_use_time ); - slipstream_node->get("add-power", &m_slipstream_add_power ); - slipstream_node->get("min-speed", &m_slipstream_min_speed ); - slipstream_node->get("max-speed-increase", - &m_slipstream_max_speed_increase); - slipstream_node->get("duration", &m_slipstream_duration ); - slipstream_node->get("fade-out-time",&m_slipstream_fade_out_time ); - } + if(const XMLNode *mass_node = root->getNode("mass")) + mass_node->get("value", &m_mass); if(const XMLNode *engine_node = root->getNode("engine")) { @@ -146,7 +106,48 @@ void PlayerDifficulty::getAllData(const XMLNode * root) engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio); engine_node->get("power", &m_engine_power); engine_node->get("max-speed", &m_max_speed); - } // if getNode("engine") + } + + if(const XMLNode *nitro_node = root->getNode("nitro")) + { + nitro_node->get("consumption", &m_nitro_consumption ); + nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase); + nitro_node->get("engine-force", &m_nitro_engine_force ); + nitro_node->get("duration", &m_nitro_duration ); + nitro_node->get("fade-out-time", &m_nitro_fade_out_time ); + } + + if(const XMLNode *bubble_node = root->getNode("bubblegum")) + { + bubble_node->get("time", &m_bubblegum_time ); + bubble_node->get("speed-fraction", &m_bubblegum_speed_fraction); + bubble_node->get("torque", &m_bubblegum_torque ); + bubble_node->get("fade-in-time", &m_bubblegum_fade_in_time ); + } + + if(const XMLNode *rescue_node = root->getNode("rescue")) + rescue_node->get("time", &m_rescue_time); + + if(const XMLNode *explosion_node = root->getNode("explosion")) + { + explosion_node->get("time", &m_explosion_time); + explosion_node->get("invulnerability-time", + &m_explosion_invulnerability_time); + } + + if(const XMLNode *slipstream_node = root->getNode("slipstream")) + { + slipstream_node->get("length", &m_slipstream_length ); + slipstream_node->get("width", &m_slipstream_width ); + slipstream_node->get("collect-time", &m_slipstream_collect_time ); + slipstream_node->get("use-time", &m_slipstream_use_time ); + slipstream_node->get("add-power", &m_slipstream_add_power ); + slipstream_node->get("min-speed", &m_slipstream_min_speed ); + slipstream_node->get("max-speed-increase", + &m_slipstream_max_speed_increase); + slipstream_node->get("duration", &m_slipstream_duration ); + slipstream_node->get("fade-out-time", &m_slipstream_fade_out_time ); + } if(const XMLNode *plunger_node= root->getNode("plunger")) { diff --git a/src/network/game_setup.hpp b/src/network/game_setup.hpp index b5fc84f3a..f2dc0fd88 100644 --- a/src/network/game_setup.hpp +++ b/src/network/game_setup.hpp @@ -23,6 +23,7 @@ #define GAME_SETUP_HPP #include "network/race_config.hpp" +#include "network/remote_kart_info.hpp" #include #include @@ -43,6 +44,7 @@ class NetworkPlayerProfile std::string kart_name; //!< The selected kart. Online::OnlineProfile* user_profile; //!< Pointer to the lobby profile uint8_t world_kart_id; //!< the kart id in the World class (pointer to AbstractKart) + PerPlayerDifficulty difficulty; }; /*! \class GameSetup diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index b8aec7be2..156994e15 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -112,6 +112,7 @@ void StartGameProtocol::update() NetworkPlayerProfile* profile = players[i]; RemoteKartInfo rki(profile->race_id, profile->kart_name, profile->user_profile->getUserName(), profile->race_id, !is_me); + rki.setDifficulty(profile->difficulty); rki.setGlobalPlayerId(profile->race_id); rki.setLocalPlayerId(is_me?0:1); rki.setHostId(profile->race_id); @@ -140,6 +141,7 @@ void StartGameProtocol::update() NetworkPlayerProfile* profile = players[i]; RemoteKartInfo rki(profile->race_id, profile->kart_name, profile->user_profile->getUserName(), profile->race_id, !is_me); + rki.setDifficulty(profile->difficulty); rki.setGlobalPlayerId(profile->race_id); // on the server, the race id must be the local one. rki.setLocalPlayerId(m_listener->isServer()?profile->race_id:(is_me?0:1)); diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index 43ad391f0..8888d79e0 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -156,11 +156,21 @@ void RaceManager::setLocalKartInfo(unsigned int player_id, */ void RaceManager::setLocalKartSoccerTeam(unsigned int player_id, SoccerTeam team) { - assert(player_id m_kart_widgets.size(); + for (int n=0; nm_kart_widgets[n].getPlayerID() == playerID) + { + // If player is done, don't do anything with focus + if (m_parent->m_kart_widgets[n].isReady()) + return GUIEngine::EVENT_BLOCK; + + m_parent->m_kart_widgets[n].m_difficulty + ->setFocusForPlayer(playerID); + + return GUIEngine::EVENT_BLOCK; + } + } + + return GUIEngine::EVENT_LET; +} // focused + +static FocusDispatcher *g_dispatcher = NULL; +static FocusDispatcher2 *g_dispatcher2 = NULL; #if 0 #pragma mark - @@ -235,6 +269,7 @@ KartSelectionScreen* KartSelectionScreen::getRunningInstance() void KartSelectionScreen::loadedFromFile() { g_dispatcher = new FocusDispatcher(this); + g_dispatcher2 = new FocusDispatcher2(this); m_first_widget = g_dispatcher; m_game_master_confirmed = false; m_multiplayer_message = NULL; @@ -307,6 +342,7 @@ void KartSelectionScreen::init() // FIXME : The reserved id value is -1 when we switch from KSS to NKSS and vice-versa g_dispatcher->setRootID(placeholder->m_reserved_id); + g_dispatcher2->setRootID(placeholder->m_reserved_id); g_root_id = placeholder->m_reserved_id; if (!m_widgets.contains(g_dispatcher)) @@ -318,6 +354,15 @@ void KartSelectionScreen::init() // other widgets. g_dispatcher->add(); } + if (!m_widgets.contains(g_dispatcher2)) + { + m_widgets.push_back(g_dispatcher2); + + // this is only needed if the dispatcher wasn't already in + // the list of widgets. If it already was, it was added along + // other widgets. + g_dispatcher2->add(); + } m_game_master_confirmed = false; @@ -417,6 +462,7 @@ void KartSelectionScreen::unloaded() { // these pointers are no more valid (have been deleted along other widgets) g_dispatcher = NULL; + g_dispatcher2 = NULL; } // ---------------------------------------------------------------------------- @@ -428,6 +474,7 @@ bool KartSelectionScreen::joinPlayer(InputDevice* device, bool first_player) if (!m_multiplayer && !first_player) return false; assert (g_dispatcher != NULL); + assert (g_dispatcher2 != NULL); DynamicRibbonWidget* w = getWidget("karts"); if (w == NULL) @@ -1097,7 +1144,7 @@ void KartSelectionScreen::allPlayersDone() if(UserConfigParams::logGUI()) { Log::info("[KartSelectionScreen]", "players : %d",players.size()); - + for (unsigned int n=0; n