SuperTuxKart
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
RaceManager Class Reference

The race manager has two functions: 1) it stores information about the race the user selected (e.g. More...

#include <race_manager.hpp>

Classes

struct  KartStatus
 This data structure accumulates kart data and race result data from each race. More...
 

Public Types

enum  MajorRaceModeType { MAJOR_MODE_GRAND_PRIX = 0 , MAJOR_MODE_SINGLE }
 The major types or races supported in STK.
 
enum  MinorRaceModeType {
  MINOR_MODE_NONE = -1 , MINOR_MODE_NORMAL_RACE = LINEAR_RACE(0, true) , MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1, true) , MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false) ,
  MINOR_MODE_3_STRIKES = BATTLE_ARENA(0) , MINOR_MODE_FREE_FOR_ALL = BATTLE_ARENA(1) , MINOR_MODE_CAPTURE_THE_FLAG = BATTLE_ARENA(2) , MINOR_MODE_SOCCER = BATTLE_ARENA(3) ,
  MINOR_MODE_EASTER_EGG = EASTER_EGG(0) , MINOR_MODE_OVERWORLD = MISC(0) , MINOR_MODE_TUTORIAL = MISC(1) , MINOR_MODE_CUTSCENE = MISC(2) ,
  MINOR_MODE_LAP_TRIAL = MISC(3)
}
 Minor variants to the major types of race. More...
 
enum  AISuperPower { SUPERPOWER_NONE = 0 , SUPERPOWER_NOLOK_BOSS = 1 }
 True if the AI should have additional abbilities, e.g. More...
 
enum  Difficulty {
  DIFFICULTY_EASY = 0 , DIFFICULTY_FIRST = DIFFICULTY_EASY , DIFFICULTY_MEDIUM , DIFFICULTY_HARD ,
  DIFFICULTY_BEST , DIFFICULTY_LAST = DIFFICULTY_BEST , DIFFICULTY_COUNT , DIFFICULTY_NONE
}
 Game difficulty.
 
enum  KartType {
  KT_PLAYER , KT_NETWORK_PLAYER , KT_AI , KT_LEADER ,
  KT_GHOST , KT_SPARE_TIRE
}
 Different kart types: A local player, a player connected via network, an AI kart, the leader kart (currently not used), a ghost kart and spare tire karts which allow gain life in battle mode.
 

Public Member Functions

bool hasAI ()
 Returns if the currently set minor game mode can be used by the AI.
 
 RaceManager ()
 Constructs the race manager.
 
 ~RaceManager ()
 Destructor for the race manager.
 
void reset ()
 Resets the race manager in preparation for a new race.
 
void setPlayerKart (unsigned int player_id, const std::string &kart_name)
 
void setPlayerKart (unsigned int player_id, const RemoteKartInfo &ki)
 Sets a player kart (local and non-local).
 
void setKartTeam (unsigned int player_id, KartTeam team)
 Sets additional information for a player to indicate which team it belong to.
 
void setPlayerHandicap (unsigned int player_id, HandicapLevel handicap)
 Sets the handicap for a player.
 
void setTrack (const std::string &track)
 In case of non GP mode set the track to use.
 
const AbstractKartgetKartWithGPRank (unsigned int n)
 Returns the kart with a given GP rank (or NULL if no such kart exists).
 
int getLocalPlayerGPRank (const int playerID) const
 Returns the GP rank (between 1 and number of karts) of a local player.
 
void computeGPRanks ()
 Sort karts and update the m_gp_rank KartStatus member, in preparation for future calls to RaceManager::getKartGPRank or RaceManager::getKartWithGPRank.
 
void setDifficulty (Difficulty diff)
 Sets the difficulty.
 
void startNew (bool from_overworld)
 Starts a new race or GP (or other mode).
 
void next ()
 Start the next race or go back to the start screen If there are more races to do, starts the next race, otherwise calls exitRace to finish the race.
 
void rerunRace ()
 Rerun the same race again This is called after a race is finished, and it will adjust the number of points and the overall time before restarting the race.
 
void exitRace (bool delete_world=true)
 Exit a race (and don't start the next one)
 
void startGP (const GrandPrixData &gp, bool from_overworld, bool continue_saved_gp)
 Higher-level method to start a GP without having to care about the exact startup sequence.
 
void saveGP ()
 Saves the current GP to the config.
 
void startSingleRace (const std::string &track_ident, const int num_laps, bool from_overworld)
 Higher-level method to start a GP without having to care about the exact startup sequence.
 
void startWatchingReplay (const std::string &track_ident, const int num_laps)
 Function to start the race with only ghost kart(s) and watch.
 
void setupPlayerKartInfo ()
 Fills up the remaining kart slots with AI karts.
 
void kartFinishedRace (const AbstractKart *kart, float time)
 A kart has finished the race at the specified time (which can be different from World::getWorld()->getClock() in case of setting extrapolated arrival times).
 
void setNumPlayers (int players, int local_players=-1)
 Sets the number of players and optional the number of local players.
 
void setDefaultAIKartList (const std::vector< std::string > &ai_list)
 Sets the default list of AI karts to use.
 
void computeRandomKartList ()
 Computes the list of random karts to be used for the AI.
 
bool hasTimeTarget () const
 
void setMaxGoal (int max_goal)
 
int getMaxGoal ()
 
void setCoinTarget (int num)
 
void setGrandPrix (const GrandPrixData &gp)
 
void setAIKartOverride (const std::string &kart)
 
void setAISuperPower (AISuperPower superpower)
 
AISuperPower getAISuperPower () const
 
void setNumLaps (int num)
 
void setReverseTrack (bool r_t)
 
void setMajorMode (MajorRaceModeType mode)
 
void setMinorMode (MinorRaceModeType mode)
 
void setNumKarts (int num)
 
void setNumRedAI (unsigned int num)
 
void setNumBlueAI (unsigned int num)
 
void setTimeTarget (float time)
 
RemoteKartInfogetKartInfo (unsigned int n)
 
unsigned int getNumLocalPlayers () const
 
bool getIfEmptyScreenSpaceExists () const
 Returns true if the split screen display leaves an empty space that can be used to display the minimap.
 
unsigned int getNumberOfKarts () const
 Returns the selected number of karts (selected number of players and AI karts.
 
unsigned int getNumberOfAIKarts () const
 
unsigned int getNumberOfRedAIKarts () const
 
unsigned int getNumberOfBlueAIKarts () const
 
unsigned int getNumNonGhostKarts () const
 
MajorRaceModeType getMajorMode () const
 
MinorRaceModeType getMinorMode () const
 
std::string getMinorModeName () const
 
unsigned int getNumPlayers () const
 
int getNumLaps () const
 Returns the number lf laps.
 
bool getReverseTrack () const
 
Difficulty getDifficulty () const
 Returns the difficulty.
 
std::string getDifficultyAsString (Difficulty diff) const
 Returns the specified difficulty as a string.
 
core::stringw getDifficultyName (Difficulty diff) const
 Returns the specified difficulty as a string.
 
const std::string getTrackName () const
 
const GrandPrixDatagetGrandPrix () const
 
unsigned int getFinishedKarts () const
 
unsigned int getFinishedPlayers () const
 
int getKartGPRank (const int kart_id) const
 
const std::string & getKartIdent (int kart) const
 
int getKartScore (int krt) const
 
int getKartPrevScore (int krt) const
 
int getKartLocalPlayerId (int k) const
 
int getKartGlobalPlayerId (int k) const
 
float getOverallTime (int kart) const
 
float getKartRaceTime (int kart) const
 
KartType getKartType (int kart) const
 
HandicapLevel getPlayerHandicap (int kart) const
 
bool hasBoostedAI (int kart) const
 
void setKartColor (int kart, float color)
 
float getKartColor (int kart) const
 
int getCoinTarget () const
 
float getTimeTarget () const
 
int getTrackNumber () const
 
int getNumOfTracks () const
 
const std::vector< std::string > & getAIKartList () const
 Returns the list of AI karts to use.
 
bool isLinearRaceMode () const
 get information about current mode (returns true if 'mode' is of linear races type)
 
bool isLinearRaceMode (const MinorRaceModeType mode) const
 get information about given mode (returns true if 'mode' is of linear races type)
 
bool isBattleMode () const
 Returns true if the current mode is a battle mode.
 
bool isSoccerMode () const
 Returns true if the current mode is a soccer mode.
 
bool isTutorialMode () const
 
bool isFollowMode () const
 
bool isCTFMode () const
 
bool isEggHuntMode () const
 
bool isTimeTrialMode () const
 
bool isLapTrialMode () const
 
int currentModeTimePrecision () const
 Returns the number of second's decimals to display.
 
bool modeHasLaps () const
 Returns true if the current mode has laps.
 
bool modeHasHighscores ()
 Returns true if the currently selected minor mode has highscores.
 
bool raceWasStartedFromOverworld () const
 
Callbacks from the race classes

These methods are to be used by the classes that manage the various races, to let the race manager know about current status

bool allPlayerFinished () const
 
void setAIKartList (const std::vector< std::string > &rkl)
 Sets the AI to use.
 
bool haveKartLastPositionOnOverworld ()
 
void setKartLastPositionOnOverworld (const Vec3 &pos)
 
void clearKartLastPositionOnOverworld ()
 
Vec3 getKartLastPositionOnOverworld ()
 
void setRecordRace (bool record)
 
void setRaceGhostKarts (bool ghost)
 
void setWatchingReplay (bool watch)
 
bool isRecordingRace () const
 
bool hasGhostKarts () const
 
bool isWatchingReplay () const
 
void addSpareTireKart (const std::string &name)
 
void setSpareTireKartNum (unsigned int i)
 
unsigned int getNumSpareTireKarts () const
 
void configGrandPrixResultFromNetwork (NetworkString &ns)
 
void clearNetworkGrandPrixResult ()
 
void setHitCaptureTime (int hc, float time)
 
int getHitCaptureLimit () const
 
bool teamEnabled () const
 
void setFlagReturnTicks (unsigned ticks)
 
unsigned getFlagReturnTicks () const
 
void setFlagDeactivatedTicks (unsigned ticks)
 
unsigned getFlagDeactivatedTicks () const
 
int getSkippedTracksInGP () const
 
void addSkippedTrackInGP ()
 
void setGPTimeTarget (float time_target)
 
int getGPTotalLaps () const
 
void addGPTotalLaps (int laps)
 
bool supportsLiveJoining () const
 Whether the current game mode allow live joining even the current game
 

Static Public Member Functions

static const std::string & getIdentOf (const MinorRaceModeType mode)
 Returns a string identifier for each minor race mode.
 
static const char * getIconOf (const MinorRaceModeType mode)
 Returns the icon for a minor race mode.
 
static const core::stringw getNameOf (const MinorRaceModeType mode)
 Returns a (translated) name of a minor race mode.
 
static const MinorRaceModeType getModeIDFromInternalName (const std::string &name)
 Returns the minor mode id from a string identifier.
 
static RaceManagerget ()
 
static void create ()
 
static void destroy ()
 
static void clear ()
 
static Difficulty convertDifficulty (const std::string &difficulty)
 Converst the difficulty given as a string into a Difficult enum.
 

Private Member Functions

void startNextRace ()
 Starts the next (or first) race.
 

Private Attributes

bool m_started_from_overworld
 
std::vector< KartStatusm_kart_status
 The kart status data for each kart.
 
Difficulty m_difficulty
 The selected difficulty.
 
MajorRaceModeType m_major_mode
 The major mode (single race, GP).
 
MinorRaceModeType m_minor_mode
 The minor mode (race, time trial, ftl, battle mode).
 
std::vector< RemoteKartInfom_player_karts
 Stores remote kart information about all player karts.
 
std::vector< std::string > m_tracks
 
unsigned int m_num_local_players
 Number of local players.
 
std::vector< int > m_num_laps
 The number of laps for each track of a GP (only one element is used if only a single track is used.
 
std::vector< bool > m_reverse_track
 Whether a track should be reversed.
 
std::vector< std::string > m_default_ai_list
 The list of default AI karts to use.
 
std::string m_ai_kart_override
 If set, specifies which kart to use for AI(s)
 
AISuperPower m_ai_superpower
 
std::vector< std::string > m_ai_kart_list
 The list of AI karts to use.
 
int m_track_number
 
GrandPrixData m_grand_prix
 
SavedGrandPrixm_saved_gp
 
int m_num_karts
 
unsigned int m_num_red_ai
 
unsigned int m_num_blue_ai
 
unsigned int m_num_ghost_karts
 
unsigned int m_num_spare_tire_karts
 
unsigned int m_num_finished_karts
 
unsigned int m_num_finished_players
 
unsigned m_flag_return_ticks
 
unsigned m_flag_deactivated_ticks
 
int m_coin_target
 
float m_time_target
 
int m_goal_target
 
int m_hit_capture_limit
 
int m_skipped_tracks_in_gp
 
float m_gp_time_target
 Time target for GP, used in Lap Trial mode.
 
int m_gp_total_laps
 Total laps from every track, used in Lap Trial mode.
 
bool m_have_kart_last_position_on_overworld
 
Vec3 m_kart_last_position_on_overworld
 
bool m_continue_saved_gp
 Determines if saved GP should be continued or not.
 
bool m_is_recording_race
 
bool m_has_ghost_karts
 
bool m_watching_replay
 

Friends

bool operator< (const KartStatus &left, const KartStatus &right)
 

Detailed Description

The race manager has two functions: 1) it stores information about the race the user selected (e.g.

number of karts, track, race mode etc.). Most of the values are just stored from the menus, and just read back, except for GP mode (the race manager stores the GP information, but World queries only track and number of laps, so in case of GP this information is taken from the GrandPrix object), and local player information (number of local players, and selected karts). Information about player karts (which player selected which kart, player ids) is stored in a RemoteKartInfo structure and used later to initialise the KartStatus array (startNew()). The KartStatus array stores information about all karts (player and AI), and is used to determine the order in which karts are started (see startNextRace()). 2) when a race is started, it creates the world, and keeps track of score during the race. When a race is finished, it deletes the world, and (depending on race mode) starts the next race by creating a new world. Information in the RaceManager is considered to be 'more static', sometimes the world has similar functions showing the current state. E.g.: the race manager keeps track of the number of karts with which the race was started, while world keeps track of the number of karts currently in the race (consider a race mode like follow the leader where karts can get eliminated, but still the RaceManager has to accumulate points for those karts). The race manager handles all race types as a kind of grand prix. E.g.: a quick race is basically a GP with only one track (so the race manager keeps track of scores even though no scores are used in a quick race).

Member Enumeration Documentation

◆ AISuperPower

True if the AI should have additional abbilities, e.g.

nolok will get special bubble gums in the final challenge.

◆ MinorRaceModeType

Minor variants to the major types of race.

Make sure to use the 'LINEAR_RACE/BATTLE_ARENA' macros.

Member Function Documentation

◆ computeRandomKartList()

void RaceManager::computeRandomKartList ( )

Computes the list of random karts to be used for the AI.

If a command line option specifies karts, they will be used first

◆ convertDifficulty()

RaceManager::Difficulty RaceManager::convertDifficulty ( const std::string &  difficulty)
static

Converst the difficulty given as a string into a Difficult enum.

Defaults to HARD.

Parameters
difficultyThe difficulty as string.

◆ exitRace()

void RaceManager::exitRace ( bool  delete_world = true)

Exit a race (and don't start the next one)

Note
In GP, displays the GP result screen first
Parameters
delete_worldIf set deletes the world.

◆ getAIKartList()

const std::vector< std::string > & RaceManager::getAIKartList ( ) const
inline

Returns the list of AI karts to use.

Used for networking, and for the –ai= command line option.

◆ getIconOf()

static const char * RaceManager::getIconOf ( const MinorRaceModeType  mode)
inlinestatic

Returns the icon for a minor race mode.

Parameters
modeMinor race mode.

◆ getIdentOf()

static const std::string & RaceManager::getIdentOf ( const MinorRaceModeType  mode)
inlinestatic

Returns a string identifier for each minor race mode.

Parameters
modeMinor race mode.

◆ getKartWithGPRank()

const AbstractKart * RaceManager::getKartWithGPRank ( unsigned int  n)

Returns the kart with a given GP rank (or NULL if no such kart exists).

Returns a pointer to the kart which has a given GP rank.

Parameters
nRank (0<=n<num_karts) to look for.
nThe rank (1 to number of karts) to look for.

◆ getLocalPlayerGPRank()

int RaceManager::getLocalPlayerGPRank ( const int  player_id) const

Returns the GP rank (between 1 and number of karts) of a local player.

Returns
the GP rank of a local player, or -1 if the given player ID doesn't exist
Parameters
player_idLocal id of the player.

◆ getModeIDFromInternalName()

static const MinorRaceModeType RaceManager::getModeIDFromInternalName ( const std::string &  name)
inlinestatic

Returns the minor mode id from a string identifier.

This function is used from challenge_data, which reads the mode from a challenge file.

Parameters
nameThe name of the minor mode.

◆ getNameOf()

const core::stringw RaceManager::getNameOf ( const MinorRaceModeType  mode)
static

Returns a (translated) name of a minor race mode.

Parameters
modeMinor race mode.

◆ getNumLaps()

int RaceManager::getNumLaps ( ) const
inline

Returns the number lf laps.

In case of FTL or battle mode always return 9999, since they don't have laps. This avoids problems in FTL GP, since in this case no laps would be set (otherwise we would need many more tests in calls to getNumLaps).

◆ getReverseTrack()

bool RaceManager::getReverseTrack ( ) const
inline
Returns
whether the track should be reversed

◆ kartFinishedRace()

void RaceManager::kartFinishedRace ( const AbstractKart kart,
float  time 
)

A kart has finished the race at the specified time (which can be different from World::getWorld()->getClock() in case of setting extrapolated arrival times).

This function is only called from kart::finishedRace()

Parameters
kartThe kart that finished the race.
timeTime at which the kart finished the race.

◆ reset()

void RaceManager::reset ( )

Resets the race manager in preparation for a new race.

It sets the counter of finished karts to zero. It is called by world when restarting a race.

◆ setAIKartList()

void RaceManager::setAIKartList ( const std::vector< std::string > &  rkl)
inline

Sets the AI to use.

This is used in networking mode to set the karts that will be used by the server to the client. It will take precedence over the random selection.

◆ setDefaultAIKartList()

void RaceManager::setDefaultAIKartList ( const std::vector< std::string > &  ai_list)

Sets the default list of AI karts to use.

Parameters
ai_kart_listList of the identifier of the karts to use.

◆ setDifficulty()

void RaceManager::setDifficulty ( Difficulty  diff)

Sets the difficulty.

Sets the difficulty to use.

Parameters
diffDifficulty.
diffThe difficulty to use.

◆ setKartTeam()

void RaceManager::setKartTeam ( unsigned int  player_id,
KartTeam  team 
)

Sets additional information for a player to indicate which team it belong to.

Sets additional information for a player to indicate which soccer team it belongs to.

◆ setNumPlayers()

void RaceManager::setNumPlayers ( int  players,
int  local_players = -1 
)

Sets the number of players and optional the number of local players.

Parameters
numNumber of players.
local_playersNumber of local players, only used from networking.

◆ setPlayerKart()

void RaceManager::setPlayerKart ( unsigned int  player_id,
const RemoteKartInfo ki 
)

Sets a player kart (local and non-local).

Parameters
player_idId of the player.
kiKart info structure for this player.

◆ setTrack()

void RaceManager::setTrack ( const std::string &  track)

In case of non GP mode set the track to use.

Sets a single track to be used in the next race.

Parameters
trackPointer to the track to use.
trackThe identifier of the track to use.

◆ startNew()

void RaceManager::startNew ( bool  from_overworld)

Starts a new race or GP (or other mode).

It sets up the list of player karts, AI karts, GP tracks if relevant etc.

Precondition
The list of AI karts to use must be set up first. This is usually being done by a call to computeRandomKartList() from NetworkManager::setupPlayerKartInfo, but could be done differently (e.g. depending on user command line options to test certain AIs)
Parameters
from_overworldTrue if the race/GP is started from overworld (used to return to overworld at end of race/GP).

◆ startNextRace()

void RaceManager::startNextRace ( )
private

Starts the next (or first) race.

It sorts the kart status data structure according to the number of points, and then creates the world().

◆ startSingleRace()

void RaceManager::startSingleRace ( const std::string &  track_ident,
const int  num_laps,
bool  from_overworld 
)

Higher-level method to start a GP without having to care about the exact startup sequence.

Parameters
trackIdentInternal name of the track to race on
num_lapsNumber of laps to race, or -1 if number of laps is not relevant in current mode

◆ startWatchingReplay()

void RaceManager::startWatchingReplay ( const std::string &  track_ident,
const int  num_laps 
)

Function to start the race with only ghost kart(s) and watch.

Parameters
trackIdentInternal name of the track to race on
num_lapsNumber of laps to race, or -1 if number of laps is not relevant in current mode

◆ supportsLiveJoining()

bool RaceManager::supportsLiveJoining ( ) const
inline

Whether the current game mode allow live joining even the current game

started in network

Member Data Documentation

◆ m_ai_kart_list

std::vector<std::string> RaceManager::m_ai_kart_list
private

The list of AI karts to use.

This is stored here so that the same list of AIs is used for all tracks of a GP.

◆ m_default_ai_list

std::vector<std::string> RaceManager::m_default_ai_list
private

The list of default AI karts to use.

This is from the command line.


The documentation for this class was generated from the following files: