Rename m_num_karts to be more appropriate, removed redundant variables I've made

This commit is contained in:
Fantasmos 2017-10-28 12:51:49 +11:00
parent 4a0db1926d
commit cb1a2b1e25
11 changed files with 52 additions and 58 deletions

View File

@ -47,7 +47,7 @@ ChallengeData::ChallengeData(const std::string& filename)
for (int d=0; d<RaceManager::DIFFICULTY_COUNT; d++)
{
m_num_karts[d] = -1;
m_default_num_karts[d] = -1;
m_position[d] = -1;
m_time[d] = -1.0f;
m_energy[d] = -1;
@ -176,7 +176,7 @@ ChallengeData::ChallengeData(const std::string& filename)
int num_karts = -1;
if (!karts_node->get("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.

View File

@ -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.

View File

@ -346,7 +346,7 @@ MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
// add the default list
va_list arguments;
va_start(arguments, nb_elements);
typedef std::pair<T, U> PairType; //Necessary to prevent compile error below
typedef std::pair<T, U> PairType; //Necessary to prevent compile error below
for (int i = 0; i < nb_elements; i++) {
std::pair<T, U> key_value_pair = va_arg(arguments, PairType);
m_elements.insert(key_value_pair);
@ -381,6 +381,7 @@ MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
va_list arguments;
va_start(arguments, nb_elements);
typedef std::pair<T, U> PairType; //Necessary to prevent compile error below
for (int i = 0; i < nb_elements; i++) {
std::pair<T, U> key_value_pair = va_arg(arguments, PairType);
m_elements.insert(key_value_pair);

View File

@ -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",

View File

@ -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") ||

View File

@ -29,7 +29,7 @@
#include "tracks/track_manager.hpp"
std::vector<std::string> 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);

View File

@ -40,7 +40,7 @@ private:
static std::vector<std::string> 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<std::string> &tracks);
// ------------------------------------------------------------------------

View File

@ -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; i<m_num_karts; i++)
for(int i=0; i<m_default_num_karts; i++)
{
m_kart_status[i].m_last_score = m_kart_status[i].m_score;
m_kart_status[i].m_last_time = 0;
@ -881,7 +881,7 @@ void RaceManager::kartFinishedRace(const AbstractKart *kart, float time)
void RaceManager::rerunRace()
{
// Subtract last score from all karts:
for(int i=0; i<m_num_karts; i++)
for(int i=0; i<m_default_num_karts; i++)
{
m_kart_status[i].m_score = m_kart_status[i].m_last_score;
m_kart_status[i].m_overall_time -= m_kart_status[i].m_last_time;
@ -956,15 +956,15 @@ void RaceManager::startWatchingReplay(const std::string &track_ident,
setNumLaps(num_laps);
setMajorMode(RaceManager::MAJOR_MODE_SINGLE);
setCoinTarget(0);
m_num_karts = ReplayPlay::get()->getNumGhostKart();
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));

View File

@ -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)

View File

@ -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")
{

View File

@ -164,14 +164,11 @@ void TrackInfoScreen::init()
m_ai_kart_spinner->setVisible(has_AI);
getWidget<LabelWidget>("ai-text")->setVisible(has_AI);
std::map<int , int> 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