Coding style improvements

This commit is contained in:
Alayan 2018-11-23 22:08:51 +01:00
parent 313ca1d902
commit 3ce1867e74
5 changed files with 40 additions and 48 deletions

View File

@ -515,17 +515,17 @@ void PowerupManager::computeWeightsForRace(int num_karts)
std::string class_name=""; std::string class_name="";
switch (race_manager->getMinorMode()) switch (race_manager->getMinorMode())
{ {
case RaceManager::MINOR_MODE_TIME_TRIAL: /* fall through */ case RaceManager::MINOR_MODE_TIME_TRIAL: /* fall through */
case RaceManager::MINOR_MODE_NORMAL_RACE: class_name="race"; break; case RaceManager::MINOR_MODE_NORMAL_RACE: class_name="race"; break;
case RaceManager::MINOR_MODE_FOLLOW_LEADER: class_name="ftl"; break; case RaceManager::MINOR_MODE_FOLLOW_LEADER: class_name="ftl"; break;
case RaceManager::MINOR_MODE_3_STRIKES: class_name="battle"; break; case RaceManager::MINOR_MODE_3_STRIKES: class_name="battle"; break;
case RaceManager::MINOR_MODE_FREE_FOR_ALL: class_name="battle"; break; case RaceManager::MINOR_MODE_FREE_FOR_ALL: class_name="battle"; break;
case RaceManager::MINOR_MODE_CAPTURE_THE_FLAG: class_name="battle"; break; case RaceManager::MINOR_MODE_CAPTURE_THE_FLAG: class_name="battle"; break;
case RaceManager::MINOR_MODE_TUTORIAL: class_name="tutorial"; break; case RaceManager::MINOR_MODE_TUTORIAL: class_name="tutorial"; break;
case RaceManager::MINOR_MODE_EASTER_EGG: /* fall through */ case RaceManager::MINOR_MODE_EASTER_EGG: /* fall through */
case RaceManager::MINOR_MODE_OVERWORLD: case RaceManager::MINOR_MODE_OVERWORLD:
case RaceManager::MINOR_MODE_CUTSCENE: case RaceManager::MINOR_MODE_CUTSCENE:
case RaceManager::MINOR_MODE_SOCCER: class_name="soccer"; break; case RaceManager::MINOR_MODE_SOCCER: class_name="soccer"; break;
default: default:
Log::fatal("PowerupManager", "Invalid minor mode %d - aborting.", Log::fatal("PowerupManager", "Invalid minor mode %d - aborting.",
race_manager->getMinorMode()); race_manager->getMinorMode());

View File

@ -1002,12 +1002,8 @@ void Kart::finishedRace(float time, bool from_server)
} }
} }
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_NORMAL_RACE || if (race_manager->isLinearRaceMode() || race_manager->isBattleMode() ||
race_manager->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL || race_manager->isSoccerMode() || race_manager->isEggHuntMode())
race_manager->getMinorMode() == RaceManager::MINOR_MODE_FOLLOW_LEADER ||
race_manager->isBattleMode() ||
race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER ||
race_manager->getMinorMode() == RaceManager::MINOR_MODE_EASTER_EGG)
{ {
// Save for music handling in race result gui // Save for music handling in race result gui
setRaceResult(); setRaceResult();

View File

@ -146,7 +146,7 @@ void GameSetup::loadWorld()
if (PlayerManager::getCurrentPlayer()) if (PlayerManager::getCurrentPlayer())
PlayerManager::getCurrentPlayer()->setCurrentChallenge(""); PlayerManager::getCurrentPlayer()->setCurrentChallenge("");
race_manager->setTimeTarget(0.0f); race_manager->setTimeTarget(0.0f);
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER || if (race_manager->isSoccerMode() ||
race_manager->isBattleMode()) race_manager->isBattleMode())
{ {
const bool is_ctf = race_manager->getMinorMode() == const bool is_ctf = race_manager->getMinorMode() ==
@ -158,7 +158,7 @@ void GameSetup::loadWorld()
UserConfigParams::m_random_arena_item = m_reverse; UserConfigParams::m_random_arena_item = m_reverse;
race_manager->setReverseTrack(false); race_manager->setReverseTrack(false);
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER) if (race_manager->isSoccerMode())
{ {
if (isSoccerGoalTarget()) if (isSoccerGoalTarget())
race_manager->setMaxGoal(m_laps); race_manager->setMaxGoal(m_laps);

View File

@ -466,21 +466,19 @@ void ClientLobby::displayPlayerVote(Event* event)
core::stringw yes = _("Yes"); core::stringw yes = _("Yes");
core::stringw no = _("No"); core::stringw no = _("No");
core::stringw vote_msg; core::stringw vote_msg;
if (race_manager->isBattleMode() && if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_FREE_FOR_ALL)
race_manager->getMinorMode() == RaceManager::MINOR_MODE_FREE_FOR_ALL)
{ {
//I18N: Vote message in network game from a player //I18N: Vote message in network game from a player
vote_msg = _("Track: %s,\nrandom item location: %s", vote_msg = _("Track: %s,\nrandom item location: %s",
track_readable, rev == 1 ? yes : no); track_readable, rev == 1 ? yes : no);
} }
else if (race_manager->isBattleMode() && else if (race_manager->getMinorMode() ==
race_manager->getMinorMode() == RaceManager::MINOR_MODE_CAPTURE_THE_FLAG)
RaceManager::MINOR_MODE_CAPTURE_THE_FLAG)
{ {
//I18N: Vote message in network game from a player //I18N: Vote message in network game from a player
vote_msg = _("Track: %s", track_readable); vote_msg = _("Track: %s", track_readable);
} }
else if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER) else if (race_manager->isSoccerMode())
{ {
if (m_game_setup->isSoccerGoalTarget()) if (m_game_setup->isSoccerGoalTarget())
{ {

View File

@ -107,22 +107,22 @@ public:
* Make sure to use the 'LINEAR_RACE/BATTLE_ARENA' macros. */ * Make sure to use the 'LINEAR_RACE/BATTLE_ARENA' macros. */
enum MinorRaceModeType enum MinorRaceModeType
{ {
MINOR_MODE_NONE = -1, MINOR_MODE_NONE = -1,
MINOR_MODE_NORMAL_RACE = LINEAR_RACE(0, true), MINOR_MODE_NORMAL_RACE = LINEAR_RACE(0, true),
MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1, true), MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1, true),
MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false), MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false),
MINOR_MODE_3_STRIKES = BATTLE_ARENA(0), MINOR_MODE_3_STRIKES = BATTLE_ARENA(0),
MINOR_MODE_FREE_FOR_ALL = BATTLE_ARENA(1), MINOR_MODE_FREE_FOR_ALL = BATTLE_ARENA(1),
MINOR_MODE_CAPTURE_THE_FLAG = BATTLE_ARENA(2), MINOR_MODE_CAPTURE_THE_FLAG = BATTLE_ARENA(2),
MINOR_MODE_SOCCER = BATTLE_ARENA(3), MINOR_MODE_SOCCER = BATTLE_ARENA(3),
MINOR_MODE_EASTER_EGG = EASTER_EGG(0), MINOR_MODE_EASTER_EGG = EASTER_EGG(0),
MINOR_MODE_OVERWORLD = MISC(0), MINOR_MODE_OVERWORLD = MISC(0),
MINOR_MODE_TUTORIAL = MISC(1), MINOR_MODE_TUTORIAL = MISC(1),
MINOR_MODE_CUTSCENE = MISC(2) MINOR_MODE_CUTSCENE = MISC(2)
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -571,12 +571,10 @@ public:
*/ */
int getNumLaps() const int getNumLaps() const
{ {
if(isBattleMode() || if(modeHasLaps())
m_minor_mode==MINOR_MODE_FOLLOW_LEADER || return m_num_laps[m_track_number];
m_minor_mode==MINOR_MODE_SOCCER || // else
m_minor_mode==MINOR_MODE_EASTER_EGG ) return 9999;
return 9999;
return m_num_laps[m_track_number];
} // getNumLaps } // getNumLaps
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** \return whether the track should be reversed */ /** \return whether the track should be reversed */
@ -691,7 +689,7 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** \brief get information about current mode (returns true if 'mode' is of /** \brief get information about current mode (returns true if 'mode' is of
* linear races type) */ * linear races type) */
bool isLinearRaceMode() bool isLinearRaceMode() const
{ {
const int id = (int)m_minor_mode; const int id = (int)m_minor_mode;
// info is stored in its ID for conveniance, see the macros LINEAR_RACE // info is stored in its ID for conveniance, see the macros LINEAR_RACE
@ -703,7 +701,7 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** \brief get information about given mode (returns true if 'mode' is of /** \brief get information about given mode (returns true if 'mode' is of
* linear races type) */ * linear races type) */
bool isLinearRaceMode(const MinorRaceModeType mode) bool isLinearRaceMode(const MinorRaceModeType mode) const
{ {
const int id = (int)mode; const int id = (int)mode;
// info is stored in its ID for conveniance, see the macros LINEAR_RACE // info is stored in its ID for conveniance, see the macros LINEAR_RACE
@ -735,31 +733,31 @@ public:
} // isSoccerMode } // isSoccerMode
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool isTutorialMode() bool isTutorialMode() const
{ {
return m_minor_mode == MINOR_MODE_TUTORIAL; return m_minor_mode == MINOR_MODE_TUTORIAL;
} // isTutorialMode } // isTutorialMode
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool isFollowMode() bool isFollowMode() const
{ {
return m_minor_mode == MINOR_MODE_FOLLOW_LEADER; return m_minor_mode == MINOR_MODE_FOLLOW_LEADER;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool isEggHuntMode() bool isEggHuntMode() const
{ {
return m_minor_mode == MINOR_MODE_EASTER_EGG; return m_minor_mode == MINOR_MODE_EASTER_EGG;
} // isEggHuntMode } // isEggHuntMode
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool isTimeTrialMode() bool isTimeTrialMode() const
{ {
return m_minor_mode == MINOR_MODE_TIME_TRIAL; return m_minor_mode == MINOR_MODE_TIME_TRIAL;
} // isTimeTrialMode } // isTimeTrialMode
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** \brief Returns the number of second's decimals to display */ /** \brief Returns the number of second's decimals to display */
int currentModeTimePrecision() int currentModeTimePrecision() const
{ {
if (isEggHuntMode() || isTimeTrialMode()) if (isEggHuntMode() || isTimeTrialMode())
return 3;//display milliseconds return 3;//display milliseconds
@ -768,9 +766,9 @@ public:
} // currentModeTimePrecision } // currentModeTimePrecision
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** \brief Returns true if the current mode has laps. */ /** \brief Returns true if the current mode has laps. */
bool modeHasLaps() bool modeHasLaps() const
{ {
if (isBattleMode() || isSoccerMode() || isEggHuntMode()) return false; if (!isLinearRaceMode()) return false;
const int id = (int)m_minor_mode; const int id = (int)m_minor_mode;
// See meaning of IDs above // See meaning of IDs above
const int answer = (id-1000)/100; const int answer = (id-1000)/100;