22160a39b733bea4be0ce32b6742ec422030613c
[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 PlayerStatus;
33 class DrawingContext;
34 class CodeController;
35 class Menu;
36
37 /**
38  * Screen that runs a Level, where Players run and jump through Sectors.
39  */
40 class GameSession : public Screen,
41                     public Currenton<GameSession>
42 {
43 public:
44   GameSession(const std::string& levelfile, PlayerStatus* player_status, Statistics* statistics = NULL);
45   ~GameSession();
46
47   void record_demo(const std::string& filename);
48   int get_demo_random_seed(const std::string& filename);
49   void play_demo(const std::string& filename);
50
51   void draw(DrawingContext& context);
52   void update(float frame_ratio);
53   void setup();
54
55   /// ends the current level
56   void finish(bool win = true);
57   void respawn(const std::string& sectorname, const std::string& spawnpointname);
58   void set_reset_point(const std::string& sectorname, const Vector& pos);
59   std::string get_reset_point_sectorname()
60   { return reset_sector; }
61
62   Vector get_reset_point_pos()
63   { return reset_pos; }
64
65   Sector* get_current_sector()
66   { return currentsector; }
67
68   Level* get_current_level()
69   { return level.get(); }
70
71   PlayerStatus* get_player_status()
72   { return player_status; }
73
74   void start_sequence(const std::string& sequencename);
75
76   /**
77    * returns the "working directory" usually this is the directory where the
78    * currently played level resides. This is used when locating additional
79    * resources for the current level/world
80    */
81   std::string get_working_directory();
82   void restart_level();
83
84   void toggle_pause();
85
86   /**
87    * Enters or leaves level editor mode
88    */
89   void set_editmode(bool edit_mode = true);
90
91   /**
92    * Forces all Players to enter ghost mode
93    */
94   void force_ghost_mode();
95
96 private:
97   void check_end_conditions();
98   void process_events();
99   void capture_demo_step();
100
101   void drawstatus(DrawingContext& context);
102   void draw_pause(DrawingContext& context);
103
104   HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
105   void on_escape_press();
106   void process_menu();
107
108   std::auto_ptr<Level> level;
109   SurfacePtr statistics_backdrop;
110
111   // scripts
112   typedef std::vector<HSQOBJECT> ScriptList;
113   ScriptList scripts;
114
115   Sector* currentsector;
116
117   int levelnb;
118   int pause_menu_frame;
119
120   EndSequence* end_sequence;
121
122   bool  game_pause;
123   float speed_before_pause;
124
125   std::string levelfile;
126
127   // reset point (the point where tux respawns if he dies)
128   std::string reset_sector;
129   Vector reset_pos;
130
131   // the sector and spawnpoint we should spawn after this frame
132   std::string newsector;
133   std::string newspawnpoint;
134
135   Statistics* best_level_statistics;
136   PlayerStatus* player_status;
137
138   std::ostream* capture_demo_stream;
139   std::string capture_file;
140   std::istream* playback_demo_stream;
141   CodeController* demo_controller;
142
143   std::auto_ptr<Menu> game_menu;
144
145   float play_time; /**< total time in seconds that this session ran interactively */
146
147   bool edit_mode; /**< true if GameSession runs in level editor mode */
148   bool levelintro_shown; /**< true if the LevelIntro screen was already shown */
149
150 private:
151   GameSession(const GameSession&);
152   GameSession& operator=(const GameSession&);
153 };
154
155 #endif /*SUPERTUX_GAMELOOP_H*/
156
157 /* EOF */