Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / supertux / game_session.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP
19
20 #include <memory>
21 #include <vector>
22 #include <squirrel.h>
23
24 #include "object/endsequence.hpp"
25 #include "supertux/screen.hpp"
26 #include "util/currenton.hpp"
27 #include "video/surface.hpp"
28
29 class Level;
30 class Sector;
31 class Statistics;
32 class DrawingContext;
33 class CodeController;
34 class Menu;
35
36 /**
37  * Screen that runs a Level, where Players run and jump through Sectors.
38  */
39 class GameSession : public Screen,
40                     public Currenton<GameSession>
41 {
42 public:
43   GameSession(const std::string& levelfile, Statistics* statistics = NULL);
44   ~GameSession();
45
46   void record_demo(const std::string& filename);
47   int get_demo_random_seed(const std::string& filename);
48   void play_demo(const std::string& filename);
49
50   void draw(DrawingContext& context);
51   void update(float frame_ratio);
52   void setup();
53
54   /// ends the current level
55   void finish(bool win = true);
56   void respawn(const std::string& sectorname, const std::string& spawnpointname);
57   void set_reset_point(const std::string& sectorname, const Vector& pos);
58   std::string get_reset_point_sectorname()
59   { return reset_sector; }
60
61   Vector get_reset_point_pos()
62   { return reset_pos; }
63
64   Sector* get_current_sector()
65   { return currentsector; }
66
67   Level* get_current_level()
68   { return level.get(); }
69
70   void start_sequence(const std::string& sequencename);
71
72   /**
73    * returns the "working directory" usually this is the directory where the
74    * currently played level resides. This is used when locating additional
75    * resources for the current level/world
76    */
77   std::string get_working_directory();
78   void restart_level();
79
80   void toggle_pause();
81
82   /**
83    * Enters or leaves level editor mode
84    */
85   void set_editmode(bool edit_mode = true);
86
87   /**
88    * Forces all Players to enter ghost mode
89    */
90   void force_ghost_mode();
91
92 private:
93   void check_end_conditions();
94   void process_events();
95   void capture_demo_step();
96
97   void drawstatus(DrawingContext& context);
98   void draw_pause(DrawingContext& context);
99
100   HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
101   void on_escape_press();
102   void process_menu();
103
104   std::auto_ptr<Level> level;
105   std::auto_ptr<Surface> statistics_backdrop;
106
107   // scripts
108   typedef std::vector<HSQOBJECT> ScriptList;
109   ScriptList scripts;
110
111   Sector* currentsector;
112
113   int levelnb;
114   int pause_menu_frame;
115
116   EndSequence* end_sequence;
117
118   bool  game_pause;
119   float speed_before_pause;
120
121   std::string levelfile;
122
123   // reset point (the point where tux respawns if he dies)
124   std::string reset_sector;
125   Vector reset_pos;
126
127   // the sector and spawnpoint we should spawn after this frame
128   std::string newsector;
129   std::string newspawnpoint;
130
131   Statistics* best_level_statistics;
132
133   std::ostream* capture_demo_stream;
134   std::string capture_file;
135   std::istream* playback_demo_stream;
136   CodeController* demo_controller;
137
138   std::auto_ptr<Menu> game_menu;
139
140   float play_time; /**< total time in seconds that this session ran interactively */
141
142   bool edit_mode; /**< true if GameSession runs in level editor mode */
143   bool levelintro_shown; /**< true if the LevelIntro screen was already shown */
144
145 private:
146   GameSession(const GameSession&);
147   GameSession& operator=(const GameSession&);
148 };
149
150 #endif /*SUPERTUX_GAMELOOP_H*/
151
152 /* EOF */