From cb1a2b1e258fea9b2d108fbeece2777faf281dd6 Mon Sep 17 00:00:00 2001 From: Fantasmos Date: Sat, 28 Oct 2017 12:51:49 +1100 Subject: [PATCH] Rename m_num_karts to be more appropriate, removed redundant variables I've made --- src/challenges/challenge_data.cpp | 12 ++++----- src/challenges/challenge_data.hpp | 4 +-- src/config/user_config.cpp | 3 ++- src/config/user_config.hpp | 13 ++++------ src/main.cpp | 10 ++++---- src/modes/demo_world.cpp | 6 ++--- src/modes/demo_world.hpp | 4 +-- src/race/race_manager.cpp | 32 ++++++++++++------------ src/race/race_manager.hpp | 8 +++--- src/states_screens/gp_info_screen.cpp | 4 +-- src/states_screens/track_info_screen.cpp | 14 ++++------- 11 files changed, 52 insertions(+), 58 deletions(-) diff --git a/src/challenges/challenge_data.cpp b/src/challenges/challenge_data.cpp index 6a0e6c52c..3b7c55bc3 100644 --- a/src/challenges/challenge_data.cpp +++ b/src/challenges/challenge_data.cpp @@ -47,7 +47,7 @@ ChallengeData::ChallengeData(const std::string& filename) for (int d=0; dget("number", &num_karts)) error("karts"); - m_num_karts[d] = num_karts; + m_default_num_karts[d] = num_karts; std::string replay_file; if (karts_node->get("replay_file", &replay_file)) @@ -385,7 +385,7 @@ void ChallengeData::setRace(RaceManager::Difficulty d) const race_manager->setMinorMode(m_minor); race_manager->setTrack(m_track_id); race_manager->setNumLaps(m_num_laps); - race_manager->setNumKarts(m_num_karts[d]); + race_manager->setNumKarts(m_default_num_karts[d]); race_manager->setNumPlayers(1); race_manager->setCoinTarget(m_energy[d]); race_manager->setDifficulty(d); @@ -400,7 +400,7 @@ void ChallengeData::setRace(RaceManager::Difficulty d) const race_manager->setMinorMode(m_minor); race_manager->setGrandPrix(*grand_prix_manager->getGrandPrix(m_gp_id)); race_manager->setDifficulty(d); - race_manager->setNumKarts(m_num_karts[d]); + race_manager->setNumKarts(m_default_num_karts[d]); race_manager->setNumPlayers(1); } @@ -444,7 +444,7 @@ bool ChallengeData::isChallengeFulfilled() const if (kart->isEliminated() ) return false; if (track_name != m_track_id ) return false; - if ((int)world->getNumKarts() < m_num_karts[d] ) return false; + if ((int)world->getNumKarts() < m_default_num_karts[d] ) return false; if (m_energy[d] > 0 && kart->getEnergy() < m_energy[d] ) return false; if (m_position[d] > 0 && kart->getPosition() > m_position[d]) return false; @@ -491,7 +491,7 @@ bool ChallengeData::isGPFulfilled() const if (race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX || race_manager->getMinorMode() != m_minor || race_manager->getGrandPrix().getId() != m_gp_id || - race_manager->getNumberOfKarts() < (unsigned int)m_num_karts[d] || + race_manager->getNumberOfKarts() < (unsigned int)m_default_num_karts[d] || race_manager->getNumPlayers() > 1) return false; // check if the player came first. diff --git a/src/challenges/challenge_data.hpp b/src/challenges/challenge_data.hpp index 0cebc4556..6e45f23c2 100644 --- a/src/challenges/challenge_data.hpp +++ b/src/challenges/challenge_data.hpp @@ -84,7 +84,7 @@ private: int m_num_laps; int m_position[RaceManager::DIFFICULTY_COUNT]; - int m_num_karts[RaceManager::DIFFICULTY_COUNT]; + int m_default_num_karts[RaceManager::DIFFICULTY_COUNT]; std::string m_ai_kart_ident[RaceManager::DIFFICULTY_COUNT]; std::string m_replay_files[RaceManager::DIFFICULTY_COUNT]; float m_time[RaceManager::DIFFICULTY_COUNT]; @@ -208,7 +208,7 @@ public: */ int getNumKarts(RaceManager::Difficulty difficulty) const { - return m_num_karts[difficulty]; + return m_default_num_karts[difficulty]; } // getNumKarts // ------------------------------------------------------------------------ /** Returns the maximum time in which the kart must finish. diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index e2d92c30c..6184debd0 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -346,7 +346,7 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, // add the default list va_list arguments; va_start(arguments, nb_elements); - typedef std::pair PairType; //Necessary to prevent compile error below + typedef std::pair PairType; //Necessary to prevent compile error below for (int i = 0; i < nb_elements; i++) { std::pair key_value_pair = va_arg(arguments, PairType); m_elements.insert(key_value_pair); @@ -381,6 +381,7 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, va_list arguments; va_start(arguments, nb_elements); typedef std::pair PairType; //Necessary to prevent compile error below + for (int i = 0; i < nb_elements; i++) { std::pair key_value_pair = va_arg(arguments, PairType); m_elements.insert(key_value_pair); diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index bdaeb4f77..c11dea614 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -384,7 +384,7 @@ namespace UserConfigParams PARAM_DEFAULT( GroupUserConfigParam("RaceSetup", "Race Setup Settings") ); - PARAM_PREFIX IntUserConfigParam m_num_karts + PARAM_PREFIX IntUserConfigParam m_default_num_karts PARAM_DEFAULT( IntUserConfigParam(4, "numkarts", &m_race_setup_group, "Default number of karts. -1 means use all") ); @@ -759,13 +759,10 @@ namespace UserConfigParams "stun.voxgratia.org", "stun.xten.com") ); PARAM_PREFIX IntToIntUserConfigParam m_karts_per_gamemode - PARAM_DEFAULT(IntToIntUserConfigParam("karts_per_gamemode", "The karts per gamemode" - "Number of karts per gamemode. Order corresponds to Enum value", - 4, - std::make_pair(0, 1), - std::make_pair(1, 2), - std::make_pair(3, 4), - std::make_pair(4, 5) + PARAM_DEFAULT(IntToIntUserConfigParam("karts_per_gamemode", + "The Number of karts per gamemode.", + 1, + std::make_pair(1100, 4) )); PARAM_PREFIX BoolUserConfigParam m_log_packets PARAM_DEFAULT( BoolUserConfigParam(false, "log-network-packets", diff --git a/src/main.cpp b/src/main.cpp index c6b5932a5..5eefa3f1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1189,16 +1189,16 @@ int handleCmdLine() if(CommandLine::has("--numkarts", &n) ||CommandLine::has("-k", &n)) { - UserConfigParams::m_num_karts = n; - if(UserConfigParams::m_num_karts > stk_config->m_max_karts) + UserConfigParams::m_default_num_karts = n; + if(UserConfigParams::m_default_num_karts > stk_config->m_max_karts) { Log::warn("main", "Number of karts reset to maximum number %d.", stk_config->m_max_karts); - UserConfigParams::m_num_karts = stk_config->m_max_karts; + UserConfigParams::m_default_num_karts = stk_config->m_max_karts; } - race_manager->setNumKarts( UserConfigParams::m_num_karts ); + race_manager->setNumKarts( UserConfigParams::m_default_num_karts ); Log::verbose("main", "%d karts will be used.", - (int)UserConfigParams::m_num_karts); + (int)UserConfigParams::m_default_num_karts); } // --numkarts if(CommandLine::has( "--no-start-screen") || diff --git a/src/modes/demo_world.cpp b/src/modes/demo_world.cpp index 867b6ad15..078ba1268 100644 --- a/src/modes/demo_world.cpp +++ b/src/modes/demo_world.cpp @@ -29,7 +29,7 @@ #include "tracks/track_manager.hpp" std::vector DemoWorld::m_demo_tracks; -int DemoWorld::m_num_karts = 2; +int DemoWorld::m_default_num_karts = 2; float DemoWorld::m_max_idle_time = 99999.0f; float DemoWorld::m_current_idle_time = 0; bool DemoWorld::m_do_demo = false; @@ -49,7 +49,7 @@ DemoWorld::DemoWorld() race_manager->setReverseTrack(false); race_manager->setMinorMode (RaceManager::MINOR_MODE_NORMAL_RACE); race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD); - race_manager->setNumKarts(m_num_karts); + race_manager->setNumKarts(m_default_num_karts); race_manager->setNumPlayers(1); race_manager->setPlayerKart(0, UserConfigParams::m_default_kart); @@ -149,7 +149,7 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt) input_manager->getDeviceManager()->setAssignMode(ASSIGN); m_do_demo = true; - race_manager->setNumKarts(m_num_karts); + race_manager->setNumKarts(m_default_num_karts); race_manager->setPlayerKart(0, "tux"); race_manager->setupPlayerKartInfo(); race_manager->startSingleRace(m_demo_tracks[0], m_num_laps, false); diff --git a/src/modes/demo_world.hpp b/src/modes/demo_world.hpp index a2d047a2f..bce6940be 100644 --- a/src/modes/demo_world.hpp +++ b/src/modes/demo_world.hpp @@ -40,7 +40,7 @@ private: static std::vector m_demo_tracks; /** Number of karts to use in demo mode. */ - static int m_num_karts; + static int m_default_num_karts; /** Idle time after which demo mode should be started. */ static float m_max_idle_time; @@ -66,7 +66,7 @@ public: static void setNumLaps(unsigned int num_laps) { m_num_laps = num_laps; } // ------------------------------------------------------------------------ /** Sets the number of karts to use in demo mode. */ - static void setNumKarts(unsigned int num_karts) { m_num_karts = num_karts;} + static void setNumKarts(unsigned int num_karts) { m_default_num_karts = num_karts;} // ------------------------------------------------------------------------ static void setTracks(const std::vector &tracks); // ------------------------------------------------------------------------ diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index 7808712a1..13483d965 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -66,7 +66,7 @@ RaceManager::RaceManager() { // Several code depends on this, e.g. kart_properties assert(DIFFICULTY_FIRST == 0); - m_num_karts = UserConfigParams::m_num_karts; + m_default_num_karts = UserConfigParams::m_default_num_karts; m_difficulty = DIFFICULTY_HARD; m_major_mode = MAJOR_MODE_SINGLE; m_minor_mode = MINOR_MODE_NORMAL_RACE; @@ -266,16 +266,16 @@ void RaceManager::setTrack(const std::string& track) */ void RaceManager::computeRandomKartList() { - int n = m_num_karts - (int)m_player_karts.size(); + int n = m_default_num_karts - (int)m_player_karts.size(); if(UserConfigParams::logMisc()) - Log::info("RaceManager", "AI karts count = %d for m_num_karts = %d and " - "m_player_karts.size() = %d", n, m_num_karts, m_player_karts.size()); + Log::info("RaceManager", "AI karts count = %d for m_default_num_karts = %d and " + "m_player_karts.size() = %d", n, m_default_num_karts, m_player_karts.size()); // If less kart selected than there are player karts, adjust the number of // karts to the minimum if(n<0) { - m_num_karts -= n; + m_default_num_karts -= n; n = 0; } @@ -363,20 +363,20 @@ void RaceManager::startNew(bool from_overworld) } // if grand prix // command line parameters: negative numbers=all karts - if(m_num_karts < 0 ) m_num_karts = stk_config->m_max_karts; - if((size_t)m_num_karts < m_player_karts.size()) - m_num_karts = (int)m_player_karts.size(); + if(m_default_num_karts < 0 ) m_default_num_karts = stk_config->m_max_karts; + if((size_t)m_default_num_karts < m_player_karts.size()) + m_default_num_karts = (int)m_player_karts.size(); // Create the kart status data structure to keep track of scores, times, ... // ========================================================================== m_kart_status.clear(); if (gk > 0) - m_num_karts += gk; + m_default_num_karts += gk; Log::verbose("RaceManager", "Nb of karts=%u, ghost karts:%u ai:%lu players:%lu\n", - (unsigned int) m_num_karts, gk, m_ai_kart_list.size(), m_player_karts.size()); + (unsigned int) m_default_num_karts, gk, m_ai_kart_list.size(), m_player_karts.size()); - assert((unsigned int)m_num_karts == gk+m_ai_kart_list.size()+m_player_karts.size()); + assert((unsigned int)m_default_num_karts == gk+m_ai_kart_list.size()+m_player_karts.size()); // First add the ghost karts (if any) // ---------------------------------------- @@ -550,7 +550,7 @@ void RaceManager::startNextRace() // The race is rerun, and the points and scores get reset ... but if // a kart hasn't finished the race at this stage, last_score and time // would be undefined. - for(int i=0; igetNumGhostKart(); + m_default_num_karts = ReplayPlay::get()->getNumGhostKart(); m_kart_status.clear(); Log::verbose("RaceManager", "%u ghost kart(s) for watching replay only\n", - (unsigned int)m_num_karts); + (unsigned int)m_default_num_karts); int init_gp_rank = 0; - for(int i = 0; i < m_num_karts; i++) + for(int i = 0; i < m_default_num_karts; i++) { m_kart_status.push_back(KartStatus(ReplayPlay::get()->getGhostKartName(i), i, -1, -1, init_gp_rank, KT_GHOST, PLAYER_DIFFICULTY_NORMAL)); diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp index 7be0e8227..e218be502 100644 --- a/src/race/race_manager.hpp +++ b/src/race/race_manager.hpp @@ -329,7 +329,7 @@ private: int m_track_number; GrandPrixData m_grand_prix; SavedGrandPrix* m_saved_gp; - int m_num_karts; + int m_default_num_karts; unsigned int m_num_spare_tire_karts; unsigned int m_num_finished_karts; unsigned int m_num_finished_players; @@ -469,7 +469,7 @@ public: // ------------------------------------------------------------------------ void setNumKarts(int num) { - m_num_karts = num; + m_default_num_karts = num; m_ai_kart_override = ""; m_ai_superpower = SUPERPOWER_NONE; } // setNumKarts @@ -492,7 +492,7 @@ public: // ------------------------------------------------------------------------ /** Returns the selected number of karts (selected number of players and * AI karts. */ - unsigned int getNumberOfKarts() const {return m_num_karts; } + unsigned int getNumberOfKarts() const {return m_default_num_karts; } // ------------------------------------------------------------------------ MajorRaceModeType getMajorMode() const { return m_major_mode; } // ------------------------------------------------------------------------ @@ -759,7 +759,7 @@ public: m_kart_status.push_back(KartStatus(name, 0, -1, -1, -1, KT_SPARE_TIRE, PLAYER_DIFFICULTY_NORMAL)); m_num_spare_tire_karts++; - m_num_karts++; + m_default_num_karts++; } // addSpareTireKart // ------------------------------------------------------------------------ void setSpareTireKartNum(unsigned int i) diff --git a/src/states_screens/gp_info_screen.cpp b/src/states_screens/gp_info_screen.cpp index 161de15e8..c45fc6af8 100644 --- a/src/states_screens/gp_info_screen.cpp +++ b/src/states_screens/gp_info_screen.cpp @@ -235,7 +235,7 @@ void GPInfoScreen::init() // Avoid negative numbers (which can happen if e.g. the number of karts // in a previous race was lower than the number of players now. - int num_ai = UserConfigParams::m_num_karts - race_manager->getNumLocalPlayers(); + int num_ai = UserConfigParams::m_default_num_karts - race_manager->getNumLocalPlayers(); if (num_ai < 0) num_ai = 0; m_ai_kart_spinner->setValue(num_ai); race_manager->setNumKarts(num_ai + race_manager->getNumLocalPlayers()); @@ -345,7 +345,7 @@ void GPInfoScreen::eventCallback(Widget *, const std::string &name, { const int num_ai = m_ai_kart_spinner->getValue(); race_manager->setNumKarts( race_manager->getNumLocalPlayers() + num_ai ); - UserConfigParams::m_num_karts = race_manager->getNumLocalPlayers() + num_ai; + UserConfigParams::m_default_num_karts = race_manager->getNumLocalPlayers() + num_ai; } else if(name=="back") { diff --git a/src/states_screens/track_info_screen.cpp b/src/states_screens/track_info_screen.cpp index b1d51e0fb..4cec05e86 100644 --- a/src/states_screens/track_info_screen.cpp +++ b/src/states_screens/track_info_screen.cpp @@ -164,14 +164,11 @@ void TrackInfoScreen::init() m_ai_kart_spinner->setVisible(has_AI); getWidget("ai-text")->setVisible(has_AI); - - std::map karts_per_gamemode = UserConfigParams::m_karts_per_gamemode; - if (has_AI) { m_ai_kart_spinner->setActive(true); - int gamemode = race_manager->getMinorMode(); - int num_ai = karts_per_gamemode[gamemode]; + + int num_ai = UserConfigParams::m_karts_per_gamemode[race_manager->getMinorMode()] - local_players; // Avoid negative numbers (which can happen if e.g. the number of karts // in a previous race was lower than the number of players now. @@ -248,8 +245,7 @@ void TrackInfoScreen::init() m_ai_kart_spinner->setActive(false); race_manager->setNumKarts(race_manager->getNumLocalPlayers()); - karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumPlayers(); - UserConfigParams::m_karts_per_gamemode = karts_per_gamemode; + UserConfigParams::m_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumLocalPlayers(); } else if (record_available) { @@ -430,7 +426,7 @@ void TrackInfoScreen::eventCallback(Widget* widget, const std::string& name, { m_ai_kart_spinner->setActive(false); race_manager->setNumKarts(race_manager->getNumLocalPlayers()); - UserConfigParams::m_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumberOfKarts(); + UserConfigParams::m_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumLocalPlayers(); } else { @@ -449,7 +445,7 @@ void TrackInfoScreen::eventCallback(Widget* widget, const std::string& name, { const int num_ai = m_ai_kart_spinner->getValue(); race_manager->setNumKarts( race_manager->getNumLocalPlayers() + num_ai ); - UserConfigParams::m_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumberOfKarts(); + UserConfigParams::m_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumLocalPlayers() + num_ai; updateHighScores(); } } // eventCallback