Back to index

supertuxkart  0.5+dfsg1
race_manager.hpp
Go to the documentation of this file.
00001 //  $Id: race_manager.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 SuperTuxKart-Team
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #ifndef HEADER_RACEMANAGER_H
00021 #define HEADER_RACEMANAGER_H
00022 
00023 #include <vector>
00024 #include <algorithm>
00025 
00026 #include <string>
00027 #include "cup_data.hpp"
00028 
00046 class RaceManager
00047 {
00048 public:
00049     enum RaceModeType   { RM_TIME_TRIAL, RM_QUICK_RACE, RM_GRAND_PRIX, 
00050                           RM_FOLLOW_LEADER };
00051     enum Difficulty     { RD_EASY, RD_MEDIUM, RD_HARD, RD_SKIDDING };
00052 
00053 private:
00054     struct KartStatus
00055     {
00056         std::string m_ident;            // The .tkkf filename without the .tkkf
00057         int         m_score;            // score for this kart
00058         int         m_last_score;       // needed for restart race
00059         double      m_overall_time;     // sum of times of all races
00060         double      m_last_time;        // needed for restart
00061         int         m_prev_finish_pos;  // previous finished position
00062         int         m_player_id;        // player controling the kart, for AI: -1
00063         bool        m_is_eliminated;    // for mini games which can eliminate karts
00064 
00065         KartStatus(const std::string& ident, const int& prev_finish_pos, 
00066                    const int& player_id) :
00067                    m_ident(ident), m_score(0), m_last_score(0), 
00068                    m_overall_time(0.0f), m_last_time(0.0f),
00069                    m_prev_finish_pos(prev_finish_pos), m_player_id(player_id),
00070                    m_is_eliminated(false)
00071                 {}
00072         
00073     };   // KartStatus
00074 
00075     std::vector<KartStatus>          m_kart_status;
00076     Difficulty                       m_difficulty;
00077     RaceModeType                     m_race_mode;
00078     typedef std::vector<std::string> PlayerKarts;
00079     PlayerKarts                      m_player_karts;
00080     std::vector<std::string>         m_tracks;
00081     std::vector<int>                 m_num_laps;
00082     std::vector<int>                 m_score_for_position;
00083     int                              m_track_number;
00084     CupData                          m_cup;
00085     int                              m_num_karts;
00086     unsigned int                     m_num_finished_karts;
00087     unsigned int                     m_num_finished_players;
00088     int                              m_coin_target;
00089 
00090     void startNextRace();    // start a next race
00091 
00092     friend bool operator< (const KartStatus& left, const KartStatus& right)
00093     {
00094         return (left.m_score < right.m_score);
00095     }
00096 
00097 public:
00098     bool                             m_active_race; //True if there is a race
00099 
00100 public:
00101     
00102     RaceManager();
00103     ~RaceManager();
00104 
00105     void setPlayerKart(unsigned int player, const std::string& kart);
00106     void setNumPlayers(int num);
00107     void reset();
00108     void setGrandPrix(const CupData &cup)    { m_cup = cup;                      }
00109     void setDifficulty(Difficulty diff);
00110     void setNumLaps(int num)                 { m_num_laps.clear();
00111                                                m_num_laps.push_back(num);        }
00112     void setTrack(const std::string& track);
00113     void setRaceMode(RaceModeType mode)      { m_race_mode = mode;               }
00114     void setNumKarts(int num)                { m_num_karts = num;                }
00115     void setCoinTarget(int num)              { m_coin_target = num;              }
00116     void addKartResult(int kart, int pos, float time);
00117     RaceModeType       getRaceMode()   const { return m_race_mode;               }
00118     unsigned int       getNumKarts()   const { return m_num_karts;               }
00119     unsigned int       getNumPlayers() const { return (int)m_player_karts.size();}
00120     int                getNumLaps()    const { return m_num_laps[m_track_number];}
00121     Difficulty         getDifficulty() const { return m_difficulty;              }
00122     const std::string& getTrackName()  const { return m_tracks[m_track_number];  }
00123     const CupData     *getGrandPrix()  const { return &m_cup;                    }
00124     unsigned int    getFinishedKarts() const { return m_num_finished_karts;      }
00125     unsigned int  getFinishedPlayers() const { return m_num_finished_players;    }
00126     const std::string&  getKartName(int kart) const
00127                                              { return m_kart_status[kart].m_ident;}
00128     const std::string& getHerringStyle() const 
00129                                              { return m_cup.getHerringStyle();   }
00130     int     getKartScore(int krt)      const { return m_kart_status[krt].m_score;}
00131     int     getPositionScore(int p)    const { return m_score_for_position[p-1]; }
00132     double  getOverallTime(int kart)   const { return m_kart_status[kart].m_overall_time;}
00133     int     getCoinTarget()            const { return m_coin_target;            }
00134     bool    isEliminated(int kart)     const { return m_kart_status[kart].m_is_eliminated;}
00135     bool    raceHasLaps()              const { return m_race_mode!=RM_FOLLOW_LEADER;}
00136     void    eliminate(int kart)              { m_kart_status[kart].m_is_eliminated=true;}
00137     void addFinishedKarts(int num)           { m_num_finished_karts += num;      }
00138     void PlayerFinishes()                    { m_num_finished_players++;         }
00139     int  allPlayerFinished() const {return m_num_finished_players==m_player_karts.size();}
00140     int  raceIsActive() const                { return m_active_race;             }
00141     bool isPlayer(int kart) const    {return m_kart_status[kart].m_player_id>-1; }
00142 
00143     void setMirror() {/*FIXME*/}
00144     void setReverse(){/*FIXME*/}
00145 
00146     void startNew();         // start new race/GP/...
00147     void next();             // start the next race or go back to the start screen
00148     void restartRace();      // restart same race again
00149     void exit_race();        // exit a race (and don't start the next one)
00150 };
00151 
00152 extern RaceManager *race_manager;
00153 #endif
00154 
00155 /* EOF */