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