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