- remove pointless leveltime from world1 levels
[supertux.git] / src / game_session.hpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Bill Kendrick <bill@newbreedsoftware.com>
5 //                     Tobias Glaesser <tobi.web@gmx.de>
6 //                     Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 #ifndef SUPERTUX_GAMELOOP_H
22 #define SUPERTUX_GAMELOOP_H
23
24 #include <string>
25 #include <SDL.h>
26 #include "screen.hpp"
27 #include "timer.hpp"
28 #include "statistics.hpp"
29 #include "math/vector.hpp"
30 #include "console.hpp"
31 #include "video/surface.hpp"
32
33 /* GameLoop modes */
34 enum GameSessionMode {
35   ST_GL_PLAY,
36   ST_GL_TEST,
37   ST_GL_LOAD_GAME,
38   ST_GL_LOAD_LEVEL_FILE,
39   ST_GL_DEMO_GAME
40 };
41
42 enum GameMenuIDs {
43   MNID_CONTINUE,
44   MNID_ABORTLEVEL
45 };
46
47 extern int game_started;
48
49 class Level;
50 class Sector;
51 class Statistics;
52 class DrawingContext;
53 class CodeController;
54
55 /**
56  * The GameSession class controlls the controll flow of the Game (the part
57  * where you actually play a level)
58  */
59 class GameSession : public Screen, public ConsoleCommandReceiver
60 {
61 public:
62   GameSession(const std::string& levelfile, GameSessionMode mode,
63               Statistics* statistics = NULL);
64   ~GameSession();
65
66   void record_demo(const std::string& filename);
67   void play_demo(const std::string& filename);
68
69   void draw(DrawingContext& context);
70   void update(float frame_ratio);
71   void setup();
72
73   void set_current()
74   { current_ = this; }
75   static GameSession* current()
76   { return current_; }
77
78   /// ends the current level
79   void finish(bool win = true);
80   void respawn(const std::string& sectorname,
81       const std::string& spawnpointname);
82   void set_reset_point(const std::string& sectorname,
83       const Vector& pos);
84   void display_info_box(const std::string& text);
85   
86   Sector* get_current_sector()
87   { return currentsector; }
88
89   Level* get_current_level()
90   { return level.get(); }
91
92   void start_sequence(const std::string& sequencename);
93
94   /** returns the "working directory" usually this is the directory where the
95    * currently played level resides. This is used when locating additional
96    * resources for the current level/world
97    */
98   std::string get_working_directory();
99   bool consoleCommand(std::string command, std::vector<std::string> arguments); /**< callback from Console; return false if command was unknown, true otherwise */
100
101 private:
102   void restart_level(bool fromBeginning = true);
103
104   void check_end_conditions();
105   void process_events();
106   void capture_demo_step();
107
108   void levelintro();
109   void drawstatus(DrawingContext& context);
110   void draw_pause(DrawingContext& context);
111
112   void on_escape_press();
113   void process_menu();
114
115   Timer endsequence_timer;
116   std::auto_ptr<Level> level;
117   std::auto_ptr<Surface> statistics_backdrop;
118
119   Sector* currentsector;
120
121   GameSessionMode mode;
122   int levelnb;
123   float fps_fps;
124   int pause_menu_frame;
125
126   /** If true the end_sequence will be played, user input will be
127       ignored while doing that */
128   enum EndSequenceState {
129     NO_ENDSEQUENCE,
130     ENDSEQUENCE_RUNNING, // tux is running right
131     ENDSEQUENCE_WAITING  // waiting for the end of the music
132   };
133   EndSequenceState end_sequence;
134   float last_x_pos;
135   CodeController* end_sequence_controller;
136
137   bool game_pause;
138
139   std::string levelfile;
140
141   // reset point (the point where tux respawns if he dies)
142   std::string reset_sector;
143   Vector reset_pos;
144
145   // the sector and spawnpoint we should spawn after this frame
146   std::string newsector;
147   std::string newspawnpoint;
148
149   static GameSession* current_;
150
151   Statistics* best_level_statistics;
152
153   std::ostream* capture_demo_stream;
154   std::string capture_file;
155   std::istream* playback_demo_stream;
156   CodeController* demo_controller;
157 };
158
159 #endif /*SUPERTUX_GAMELOOP_H*/
160