better encapsulation of race modes. not the most elegant solution possible, but it was quick and easy, and will be easy to extend

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2334 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2008-10-11 00:32:44 +00:00
parent e93129a520
commit e6a257a7e2
3 changed files with 49 additions and 8 deletions

View File

@ -120,7 +120,7 @@ GrandPrixEnd::GrandPrixEnd()
for(unsigned int i=start; i < NUM_KARTS; ++i)
{
char sTime[20];sTime[0]=0;
if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_FOLLOW_LEADER)
if(race_manager->getWorld()->getClockMode()==CHRONO)
TimeToString(race_time[i], sTime);
sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %d %s",
i + 1-start, race_manager->getKartName(position[i]).c_str(), scores[i], sTime );
@ -131,7 +131,7 @@ GrandPrixEnd::GrandPrixEnd()
widget_manager->setWgtText(WTOK_FIRSTKART + i,
(char*)(m_score + MAX_STR_LEN * i));
widget_manager->setWgtTextSize(WTOK_FIRSTKART + i, WGT_FNT_SML);
widget_manager->breakLine();
widget_manager->breakLine();
}
const std::string KART_NAME = race_manager->getKartName(position[start]);
const KartProperties* WINNING_KART = kart_properties_manager->getKart(KART_NAME);

View File

@ -110,7 +110,7 @@ RaceOptions::RaceOptions()
// Number of laps
// ==============
if( race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX &&
race_manager->getMinorMode() != RaceManager::MINOR_MODE_FOLLOW_LEADER )
RaceManager::modeHasLaps( race_manager->getMinorMode() ) )
{
widget_manager->addTextWgt( WTOK_LAPS_TITLE, DESC_WIDTH, 7, _("Number of laps") );
widget_manager->hideWgtRect(WTOK_LAPS_TITLE);
@ -271,7 +271,7 @@ void RaceOptions::select()
race_manager->setNumKarts(m_num_karts);
if( race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX &&
race_manager->getMinorMode() != RaceManager::MINOR_MODE_FOLLOW_LEADER )
RaceManager::modeHasLaps( race_manager->getMinorMode() ) )
{
race_manager->setNumLaps( m_num_laps );
}

View File

@ -70,14 +70,25 @@ public:
MAJOR_MODE_GRAND_PRIX,
MAJOR_MODE_SINGLE
};
// quick method to tell the difference between battle modes and race modes
// think of it like a bitmask, but done in decimal to avoid endianness issues
#define LINEAR_RACE(ID, COUNT_LAPSES) (1000+ID+100*COUNT_LAPSES)
#define BATTLE_ARENA(ID) (2000+ID)
/** Minor variants to the major types of race.
*/
* Make sure to use the 'LINEAR_RACE/BATTLE_ARENA' macros
*/
enum MinorRaceModeType
{
MINOR_MODE_QUICK_RACE,
MINOR_MODE_TIME_TRIAL,
MINOR_MODE_FOLLOW_LEADER
MINOR_MODE_QUICK_RACE = LINEAR_RACE(0, true),
MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1, true),
MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false),
MINOR_MODE_LAST_ALIVE = BATTLE_ARENA(0)
};
#undef LINEAR_RACE
#undef BATTLE_ARENA
/** Difficulty. Atm skidding is implemented as a special difficulty. */
enum Difficulty { RD_EASY, RD_MEDIUM, RD_HARD, RD_SKIDDING };
@ -210,6 +221,36 @@ public:
void next(); // start the next race or go back to the start screen
void rerunRace(); // Rerun the same race again
void exit_race(); // exit a race (and don't start the next one)
/** get information about given mode (returns true if 'mode' is of linear races type)
info is stored in its ID for conveniance, see the macros above for exact meaning
*/
static bool isLinearRaceMode(const MinorRaceModeType type)
{
const int id = (int)type;
if(id > 999 && id < 2000) return true;
else return false;
}
/** get information about given mode (returns true if 'mode' is of battle type)
info is stored in its ID for conveniance, see the macros above for exact meaning
*/
static bool isBattleMode(const MinorRaceModeType type)
{
const int id = (int)type;
if(id >= 2000) return true;
else return false;
}
/** get information about given mode (returns true if 'mode' requires lap counting)
info is stored in its ID for conveniance, see the macros above for exact meaning
*/
static bool modeHasLaps(const MinorRaceModeType type)
{
if(isBattleMode(type)) return false;
const int id = (int)type;
const int answer = (id-1000)/100;
return (bool)answer;
}
};
extern RaceManager *race_manager;