- Fixed ghostforest vs. ghostwood name
[supertux.git] / src / worldmap / worldmap.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
5 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 #ifndef SUPERTUX_WORLDMAP_H
21 #define SUPERTUX_WORLDMAP_H
22
23 #include <vector>
24 #include <string>
25
26 #include "math/vector.hpp"
27 #include "video/screen.hpp"
28 #include "lisp/lisp.hpp"
29 #include "control/controller.hpp"
30 #include "statistics.hpp"
31 #include "timer.hpp"
32 #include "screen.hpp"
33 #include "tile_manager.hpp"
34 #include "game_object.hpp"
35 #include "console.hpp"
36
37 class Sprite;
38 class Menu;
39 class SpawnPoint;
40 class GameObject;
41 class TileMap;
42
43 namespace WorldMapNS {
44
45 class Tux;
46 class Level;
47 class SpecialTile;
48 class SpriteChange;
49
50 // For one way tiles
51 enum {
52   BOTH_WAYS,
53   NORTH_SOUTH_WAY,
54   SOUTH_NORTH_WAY,
55   EAST_WEST_WAY,
56   WEST_EAST_WAY
57 };
58
59 enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH };
60
61 std::string direction_to_string(Direction d);
62 Direction   string_to_direction(const std::string& d);
63 Direction reverse_dir(Direction d);
64
65 /** */
66 class WorldMap : public Screen
67 {
68 private:
69   Tux* tux;
70
71   static WorldMap* current_;
72
73   std::auto_ptr<Menu> worldmap_menu;
74
75   Vector camera_offset;
76
77   std::string name;
78   std::string music;
79
80   typedef std::vector<GameObject*> GameObjects;
81   GameObjects game_objects;
82   TileMap* solids;
83   
84   std::auto_ptr<TileManager> tile_manager;
85   
86 public:
87   /** Variables to deal with the passive map messages */
88   Timer passive_message_timer;
89   std::string passive_message;
90
91 private:
92   std::string map_filename;
93   std::string levels_path;
94
95   typedef std::vector<SpecialTile*> SpecialTiles;
96   SpecialTiles special_tiles;
97   typedef std::vector<Level*> Levels;
98   Levels levels;
99   typedef std::vector<SpriteChange*> SpriteChanges;
100   SpriteChanges sprite_changes;
101   typedef std::vector<SpawnPoint*> SpawnPoints;
102   SpawnPoints spawn_points;
103
104   Vector offset;
105   std::string savegame_file;
106   
107   std::string intro_script;
108   bool intro_displayed;
109
110   void get_level_title(Level& level);
111
112   void draw_status(DrawingContext& context);
113
114   // to avoid calculating total stats all the time. This way only
115   // when need, it is calculated.
116   Statistics total_stats;
117   void calculate_total_stats();
118
119 public:
120   WorldMap();
121   ~WorldMap();
122
123   void load_map();
124   
125   void add_object(GameObject* object);
126   void clear_objects();
127
128   static WorldMap* current()
129   { return current_; }
130
131   void setup();
132
133   /** Update Tux position */
134   void update(float delta);
135
136   /** Draw one frame */
137   void draw(DrawingContext& context);
138
139   Vector get_next_tile(Vector pos, Direction direction);
140   const Tile* at(Vector pos);
141
142   size_t level_count();
143   size_t solved_level_count();
144
145   /**
146    * gets called from the GameSession when a level has been successfully
147    * finished
148    */
149   void finished_level(const std::string& filename);
150
151   Level* at_level();
152   SpecialTile* at_special_tile();
153   SpriteChange* at_sprite_change();
154
155   /** Check if it is possible to walk from \a pos into \a direction,
156       if possible, write the new position to \a new_pos */
157   bool path_ok(Direction direction, Vector pos, Vector* new_pos);
158
159   /**
160    * Save worldmap state to squirrel state table
161    */
162   void save_state();
163
164   /**
165    * Load worldmap state from squirrel state table
166    */
167   void load_state();
168
169   /**
170    * Load a worldmap
171    */
172   void loadmap(const std::string& filename);
173
174   const std::string& get_title() const
175   { return name; }
176     
177   void set_map_filename(std::string filename)
178   { map_filename = filename; }
179
180 private:
181   void on_escape_press();
182   void parse_special_tile(const lisp::Lisp* lisp);
183   void parse_sprite_change(const lisp::Lisp* lisp);
184 };
185
186 } // namespace WorldMapNS
187
188 #endif