Back to index

supertuxkart  0.5+dfsg1
world.hpp
Go to the documentation of this file.
00001 //  $Id: world.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2004 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_WORLD_H
00021 #define HEADER_WORLD_H
00022 
00023 #include <vector>
00024 #include <plib/ssg.h>
00025 #include "track.hpp"
00026 #include "player_kart.hpp"
00027 #include "physics.hpp"
00028 #include "kart.hpp"
00029 #include "highscores.hpp"
00030 #ifdef HAVE_GHOST_REPLAY
00031 #  include "replay_recorder.hpp"
00032    class ReplayPlayer;
00033 #endif
00034 
00037 class World
00038 {
00039 public:
00040     typedef std::vector<Kart*> Karts;
00041 
00046     enum Phase {
00047         // Game setup, e.g. track loading
00048         SETUP_PHASE,
00049         // 'Ready' is displayed
00050         READY_PHASE,
00051         // 'Set' is displayed
00052         SET_PHASE,
00053         // 'Go' is displayed, but this is already race phase
00054         GO_PHASE,
00055         // the actual race has started, no ready/set/go is displayed anymore
00056         RACE_PHASE,
00057         // All players have finished, now wait a certain amount of time for AI
00058         // karts to finish. If they do not finish in that time, finish the race
00059         DELAY_FINISH_PHASE,
00060         // The player crossed the finishing line and his and the time of
00061         // the other players is displayed, controll is automatic
00062         FINISH_PHASE,
00063         // The state after finish where no calculations are done.
00064         LIMBO_PHASE,
00065     };
00066 
00067     Track* m_track;
00068     
00070     std::string m_debug_text[10];
00071 
00072                 World();
00073     virtual    ~World();
00074     void        update(float delta);
00075     // Note: GO_PHASE is both: start phase and race phase
00076     bool        isStartPhase() const  {return m_phase<GO_PHASE;}
00077     bool        isRacePhase() const   {return m_phase>=GO_PHASE && m_phase<LIMBO_PHASE;}
00078     void        restartRace();
00079     void        disableRace(); // Put race into limbo phase
00080 
00081     PlayerKart* getPlayerKart(int player) const
00082     {
00083         return m_player_karts[player];
00084     }
00085     
00086     
00087     Kart* getKart(int kartId) const
00088     {
00089         assert(kartId >= 0 &&
00090                kartId < int(m_kart.size()));
00091         return m_kart[kartId];
00092     }
00093     unsigned int getCurrentNumKarts()  const  { return (int)m_kart.size()-
00094                                                           m_eliminated_karts;      }
00095     unsigned int getCurrentNumPlayers() const { return (int)m_player_karts.size()-
00096                                                         m_eliminated_players;      }
00097 
00099     Phase getPhase() const                    { return m_phase;                    }
00100     Physics *getPhysics() const               { return m_physics;                  }
00101     Track *getTrack() const                   { return m_track;                    }
00102     Kart* getFastestKart() const              { return m_fastest_kart;             }
00103     float getFastestLapTime() const           { return m_fastest_lap;              }
00104     void  setFastestLap(Kart *k, float time)  {m_fastest_kart=k;m_fastest_lap=time;}
00105     const Highscores* getHighscores() const   { return m_highscores;               }
00106     float getTime() const                     { return m_clock;                    }
00107 
00108     void  pause();
00109     void  unpause();
00110 
00111 private:
00112     Karts       m_kart;
00113     std::vector<PlayerKart*>  m_player_karts;
00114     Physics*    m_physics;
00115     float       m_fastest_lap;
00116     Kart*       m_fastest_kart;
00117     Highscores* m_highscores;
00118     Phase       m_phase;
00119     Phase       m_previous_phase;      // used during the race popup menu
00120     float       m_clock;
00121     float       m_finish_delay_start_time;
00122     int         m_eliminated_karts;    // number of eliminated karts
00123     int         m_eliminated_players;  // number of eliminated players
00124     std::vector<float>
00125                 m_leader_intervals;    // time till elimination in follow leader
00126     bool        m_faster_music_active; // true if faster music was activated
00127 
00128     void  updateRacePosition(int k);
00129     void  updateHighscores  ();
00130     void  loadTrack         ();
00131     void  updateRaceStatus  (float dt);
00132     void  resetAllKarts     ();
00133     void  removeKart        (int kart_number);
00134     Kart* loadRobot         (const std::string& kart_name, int position,
00135                              sgCoord init_pos);
00136     void  updateLeaderMode  (float dt);
00137     void  printProfileResultAndExit();
00138     void  estimateFinishTimes();
00139 #ifdef HAVE_GHOST_REPLAY
00140 private:
00141     bool    saveReplayHumanReadable( std::string const &filename ) const;
00142     bool    loadReplayHumanReadable( std::string const &filename );
00143 
00144     ReplayRecorder  m_replay_recorder;
00145     ReplayPlayer    *m_p_replay_player;
00146 #endif
00147 
00148 };
00149 
00150 extern World* world;
00151 
00152 #endif
00153 
00154 /* EOF */