Back to index

supertuxkart  0.5+dfsg1
Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | Friends
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>

Collaboration diagram for RaceManager:
Collaboration graph
[legend]

List of all members.

Classes

struct  KartStatus

Public Types

enum  RaceModeType { RM_TIME_TRIAL, RM_QUICK_RACE, RM_GRAND_PRIX, RM_FOLLOW_LEADER }
enum  Difficulty { RD_EASY, RD_MEDIUM, RD_HARD, RD_SKIDDING }

Public Member Functions

 RaceManager ()
 ~RaceManager ()
void setPlayerKart (unsigned int player, const std::string &kart)
void setNumPlayers (int num)
void reset ()
void setGrandPrix (const CupData &cup)
void setDifficulty (Difficulty diff)
void setNumLaps (int num)
void setTrack (const std::string &track)
void setRaceMode (RaceModeType mode)
void setNumKarts (int num)
void setCoinTarget (int num)
void addKartResult (int kart, int pos, float time)
RaceModeType getRaceMode () const
unsigned int getNumKarts () const
unsigned int getNumPlayers () const
int getNumLaps () const
Difficulty getDifficulty () const
const std::string & getTrackName () const
const CupDatagetGrandPrix () const
unsigned int getFinishedKarts () const
unsigned int getFinishedPlayers () const
const std::string & getKartName (int kart) const
const std::string & getHerringStyle () const
int getKartScore (int krt) const
int getPositionScore (int p) const
double getOverallTime (int kart) const
int getCoinTarget () const
bool isEliminated (int kart) const
bool raceHasLaps () const
void eliminate (int kart)
void addFinishedKarts (int num)
void PlayerFinishes ()
int allPlayerFinished () const
int raceIsActive () const
bool isPlayer (int kart) const
void setMirror ()
void setReverse ()
void startNew ()
void next ()
void restartRace ()
void exit_race ()

Public Attributes

bool m_active_race

Private Types

typedef std::vector< std::string > PlayerKarts

Private Member Functions

void startNextRace ()

Private Attributes

std::vector< KartStatusm_kart_status
Difficulty m_difficulty
RaceModeType m_race_mode
PlayerKarts m_player_karts
std::vector< std::string > m_tracks
std::vector< int > m_num_laps
std::vector< int > m_score_for_position
int m_track_number
CupData m_cup
int m_num_karts
unsigned int m_num_finished_karts
unsigned int m_num_finished_players
int m_coin_target

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.) 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 race manager 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). 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)

Definition at line 46 of file race_manager.hpp.


Member Typedef Documentation

typedef std::vector<std::string> RaceManager::PlayerKarts [private]

Definition at line 78 of file race_manager.hpp.


Member Enumeration Documentation

Enumerator:
RD_EASY 
RD_MEDIUM 
RD_HARD 
RD_SKIDDING 

Definition at line 51 of file race_manager.hpp.

Enumerator:
RM_TIME_TRIAL 
RM_QUICK_RACE 
RM_GRAND_PRIX 
RM_FOLLOW_LEADER 

Definition at line 49 of file race_manager.hpp.


Constructor & Destructor Documentation

Definition at line 37 of file race_manager.cpp.

Here is the call graph for this function:

Definition at line 51 of file race_manager.cpp.

{
}   // ~RaceManager

Member Function Documentation

void RaceManager::addFinishedKarts ( int  num) [inline]

Definition at line 137 of file race_manager.hpp.

Here is the caller graph for this function:

void RaceManager::addKartResult ( int  kart,
int  pos,
float  time 
)

Definition at line 223 of file race_manager.cpp.

{
    // In follow the leader mode, kart 0 does not get any points,
    // so the position of each kart is actually one better --> decrease pos
    if(m_race_mode==RM_FOLLOW_LEADER) 
    {
        pos--;
        // If the position is negative (i.e. follow leader and kart on 
        // position 0) set the score of this kart to the lowest possible
        // score, since the kart is ahead of the leader
        if(pos<=0) pos=stk_config->m_max_karts;
    }

    m_kart_status[kart].m_score        += m_score_for_position[pos-1];
    m_kart_status[kart].m_last_score    = m_score_for_position[pos-1];
    m_kart_status[kart].m_overall_time += time;
    m_kart_status[kart].m_last_time     = time;
}   // addKartResult

Here is the caller graph for this function:

int RaceManager::allPlayerFinished ( ) const [inline]

Definition at line 139 of file race_manager.hpp.

Here is the caller graph for this function:

void RaceManager::eliminate ( int  kart) [inline]

Definition at line 136 of file race_manager.hpp.

{ m_kart_status[kart].m_is_eliminated=true;}

Here is the caller graph for this function:

Definition at line 202 of file race_manager.cpp.

{
    // Only display the grand prix result screen if all tracks 
    // were finished, and not when a race is aborted.
    if(m_race_mode==RM_GRAND_PRIX && m_track_number==(int)m_tracks.size()) 
    {
        unlock_manager->grandPrixFinished();
        menu_manager->switchToGrandPrixEnding();
    }
    else
    {
        menu_manager->switchToMainMenu();
    }
    scene->clear();
    delete world;
    world          = 0;
    m_track_number = 0;
    m_active_race  = false;    
}   // exit_Race

Here is the call graph for this function:

Here is the caller graph for this function:

int RaceManager::getCoinTarget ( ) const [inline]

Definition at line 133 of file race_manager.hpp.

{ return m_coin_target;            }

Here is the caller graph for this function:

Definition at line 121 of file race_manager.hpp.

{ return m_difficulty;              }

Here is the caller graph for this function:

unsigned int RaceManager::getFinishedKarts ( ) const [inline]

Definition at line 124 of file race_manager.hpp.

Here is the caller graph for this function:

unsigned int RaceManager::getFinishedPlayers ( ) const [inline]

Definition at line 125 of file race_manager.hpp.

const CupData* RaceManager::getGrandPrix ( ) const [inline]

Definition at line 123 of file race_manager.hpp.

{ return &m_cup;                    }

Here is the caller graph for this function:

const std::string& RaceManager::getHerringStyle ( ) const [inline]

Definition at line 128 of file race_manager.hpp.

                                             { return m_cup.getHerringStyle();   }

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string& RaceManager::getKartName ( int  kart) const [inline]

Definition at line 126 of file race_manager.hpp.

                                             { return m_kart_status[kart].m_ident;}

Here is the caller graph for this function:

int RaceManager::getKartScore ( int  krt) const [inline]

Definition at line 130 of file race_manager.hpp.

{ return m_kart_status[krt].m_score;}

Here is the caller graph for this function:

unsigned int RaceManager::getNumKarts ( ) const [inline]

Definition at line 118 of file race_manager.hpp.

{ return m_num_karts;               }

Here is the caller graph for this function:

int RaceManager::getNumLaps ( ) const [inline]

Definition at line 120 of file race_manager.hpp.

Here is the caller graph for this function:

unsigned int RaceManager::getNumPlayers ( ) const [inline]

Definition at line 119 of file race_manager.hpp.

{ return (int)m_player_karts.size();}

Here is the caller graph for this function:

double RaceManager::getOverallTime ( int  kart) const [inline]

Definition at line 132 of file race_manager.hpp.

{ return m_kart_status[kart].m_overall_time;}

Here is the caller graph for this function:

int RaceManager::getPositionScore ( int  p) const [inline]

Definition at line 131 of file race_manager.hpp.

{ return m_score_for_position[p-1]; }

Here is the caller graph for this function:

Definition at line 117 of file race_manager.hpp.

{ return m_race_mode;               }

Here is the caller graph for this function:

const std::string& RaceManager::getTrackName ( ) const [inline]

Definition at line 122 of file race_manager.hpp.

{ return m_tracks[m_track_number];  }

Here is the caller graph for this function:

bool RaceManager::isEliminated ( int  kart) const [inline]

Definition at line 134 of file race_manager.hpp.

{ return m_kart_status[kart].m_is_eliminated;}

Here is the caller graph for this function:

bool RaceManager::isPlayer ( int  kart) const [inline]

Definition at line 141 of file race_manager.hpp.

{return m_kart_status[kart].m_player_id>-1; }

Here is the caller graph for this function:

Definition at line 185 of file race_manager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void RaceManager::PlayerFinishes ( ) [inline]

Definition at line 138 of file race_manager.hpp.

Here is the caller graph for this function:

bool RaceManager::raceHasLaps ( ) const [inline]

Definition at line 135 of file race_manager.hpp.

Here is the caller graph for this function:

int RaceManager::raceIsActive ( ) const [inline]

Definition at line 140 of file race_manager.hpp.

{ return m_active_race;             }

Here is the caller graph for this function:

Definition at line 56 of file race_manager.cpp.

Here is the caller graph for this function:

Definition at line 243 of file race_manager.cpp.

{
    // Subtract last score from all karts:
    for(int i=0; i<m_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;
    }
    world->restartRace();
}   // restartRace

Here is the call graph for this function:

Here is the caller graph for this function:

void RaceManager::setCoinTarget ( int  num) [inline]

Definition at line 115 of file race_manager.hpp.

{ m_coin_target = num;              }

Here is the caller graph for this function:

Definition at line 91 of file race_manager.cpp.

{
    if(diff==RD_SKIDDING)
    {
        m_difficulty = RD_HARD;
        user_config->m_skidding = true;
    }
    else
    {
        m_difficulty = diff;
        user_config->m_skidding = false;
    }
}   // setDifficulty

Here is the caller graph for this function:

void RaceManager::setGrandPrix ( const CupData cup) [inline]

Definition at line 108 of file race_manager.hpp.

{ m_cup = cup;                      }

Here is the caller graph for this function:

void RaceManager::setMirror ( ) [inline]

Definition at line 143 of file race_manager.hpp.

{/*FIXME*/}
void RaceManager::setNumKarts ( int  num) [inline]

Definition at line 114 of file race_manager.hpp.

{ m_num_karts = num;                }

Here is the caller graph for this function:

void RaceManager::setNumLaps ( int  num) [inline]

Definition at line 110 of file race_manager.hpp.

                                             { m_num_laps.clear();
                                               m_num_laps.push_back(num);        }

Here is the caller graph for this function:

void RaceManager::setNumPlayers ( int  num)

Definition at line 78 of file race_manager.cpp.

{
    m_player_karts.resize(num);
    for(PlayerKarts::iterator i = m_player_karts.begin(); i != m_player_karts.end(); ++i)
    {
        if (i->empty())
        {
            *i = "tuxkart";
        }
    }
}   // setNumPlayers

Here is the caller graph for this function:

void RaceManager::setPlayerKart ( unsigned int  player,
const std::string &  kart 
)

Definition at line 63 of file race_manager.cpp.

{
    if (player >= 0 && player < 4)
    {
        if (player >= getNumPlayers())
            setNumPlayers(player+1);
        m_player_karts[player] = kart;
    }
    else
    {
        fprintf(stderr, "Warning: player '%d' does not exists.\n", player);
    }
}   // setPlayerKart

Here is the call graph for this function:

Here is the caller graph for this function:

void RaceManager::setRaceMode ( RaceModeType  mode) [inline]

Definition at line 113 of file race_manager.hpp.

{ m_race_mode = mode;               }

Here is the caller graph for this function:

void RaceManager::setReverse ( ) [inline]

Definition at line 144 of file race_manager.hpp.

{/*FIXME*/}
void RaceManager::setTrack ( const std::string &  track)

Definition at line 106 of file race_manager.cpp.

{
    m_tracks.clear();
    m_tracks.push_back(track);
}   // setTrack

Here is the caller graph for this function:

Definition at line 113 of file race_manager.cpp.

{
    if(m_race_mode==RM_GRAND_PRIX)   // GP: get tracks and laps from cup object
    {
        m_tracks = m_cup.getTracks();
        m_num_laps = m_cup.getLaps();
    }
    assert(m_player_karts.size() > 0);

    // 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();

    // Create the list of all kart names to use
    // ========================================
    std::vector<std::string> kart_names;
    kart_names.resize(m_num_karts);
    for(unsigned int i = 0; i < m_player_karts.size(); i++)
    {
        /*Players position is behind the AI in the first race*/
        kart_names[m_num_karts-1 - i] = m_player_karts[m_player_karts.size() - 1 - i];
    }
    kart_properties_manager->fillWithRandomKarts(kart_names);

    // Create the kart status data structure to keep track of scores, times, ...
    // ==========================================================================
    const int num_ai_karts = m_num_karts - (int)m_player_karts.size();
    m_kart_status.clear();
    for(int i=0; i<m_num_karts; i++)
    {
        // AI karts have -1 as player 
        bool is_player = i>=num_ai_karts;   // players start at the back
        m_kart_status.push_back(KartStatus(kart_names[i], i,
                                           is_player ? i-num_ai_karts : -1 ) );
    }   // for i<m_num_karts

    // Then start the race with the first track
    // ========================================
    m_track_number = 0;
    startNextRace();
}   // startNew

Here is the call graph for this function:

Here is the caller graph for this function:

void RaceManager::startNextRace ( ) [private]

Definition at line 157 of file race_manager.cpp.

{

    m_num_finished_karts   = 0;
    m_num_finished_players = 0;

    // if subsequent race, sort kart status structure
    // ==============================================
    if (m_track_number > 0)
    {  
        std::sort(m_kart_status.begin(), m_kart_status.end());//sort karts by increasing scor        
        //reverse kart order if flagged in stk_config
        if (stk_config->m_grid_order)
        {
            std::reverse(m_kart_status.begin(), m_kart_status.end());
        } 
    }   // not first race

    // the constructor assigns this object to the global
    // variable world. Admittedly a bit ugly, but simplifies
    // handling of objects which get created in the constructor
    // and need world to be defined.
    new World();

    m_active_race = true;
}   // startNextRace

Here is the caller graph for this function:


Friends And Related Function Documentation

bool operator< ( const KartStatus left,
const KartStatus right 
) [friend]

Definition at line 92 of file race_manager.hpp.

    {
        return (left.m_score < right.m_score);
    }

Member Data Documentation

Definition at line 98 of file race_manager.hpp.

Definition at line 88 of file race_manager.hpp.

Definition at line 84 of file race_manager.hpp.

Definition at line 76 of file race_manager.hpp.

std::vector<KartStatus> RaceManager::m_kart_status [private]

Definition at line 75 of file race_manager.hpp.

unsigned int RaceManager::m_num_finished_karts [private]

Definition at line 86 of file race_manager.hpp.

unsigned int RaceManager::m_num_finished_players [private]

Definition at line 87 of file race_manager.hpp.

int RaceManager::m_num_karts [private]

Definition at line 85 of file race_manager.hpp.

std::vector<int> RaceManager::m_num_laps [private]

Definition at line 81 of file race_manager.hpp.

Definition at line 79 of file race_manager.hpp.

Definition at line 77 of file race_manager.hpp.

std::vector<int> RaceManager::m_score_for_position [private]

Definition at line 82 of file race_manager.hpp.

Definition at line 83 of file race_manager.hpp.

std::vector<std::string> RaceManager::m_tracks [private]

Definition at line 80 of file race_manager.hpp.


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