e8f651aed3c516736578573b15238c831c7b5723
[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 #include "../level.hpp"
37
38 class Sprite;
39 class Menu;
40 class SpawnPoint;
41 class GameObject;
42 class TileMap;
43
44 namespace WorldMapNS {
45
46 class Tux;
47 class LevelTile;
48 class SpecialTile;
49 class SpriteChange;
50
51 // For one way tiles
52 enum {
53   BOTH_WAYS,
54   NORTH_SOUTH_WAY,
55   SOUTH_NORTH_WAY,
56   EAST_WEST_WAY,
57   WEST_EAST_WAY
58 };
59
60 enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH };
61
62 std::string direction_to_string(Direction d);
63 Direction   string_to_direction(const std::string& d);
64 Direction reverse_dir(Direction d);
65
66 /**
67  * Screen that displays a worldmap
68  */
69 class WorldMap : public Screen
70 {
71 private:
72   Tux* tux;
73
74   static WorldMap* current_;
75
76   std::auto_ptr<Menu> worldmap_menu;
77
78   Vector camera_offset;
79
80   std::string name;
81   std::string music;
82
83   typedef std::vector<GameObject*> GameObjects;
84   GameObjects game_objects;
85   TileMap* solids;
86   
87   std::auto_ptr<TileManager> tile_manager;
88   
89 public:
90   /** Variables to deal with the passive map messages */
91   Timer passive_message_timer;
92   std::string passive_message;
93
94 private:
95   std::string map_filename;
96   std::string levels_path;
97
98   typedef std::vector<SpecialTile*> SpecialTiles;
99   SpecialTiles special_tiles;
100   typedef std::vector<LevelTile*> LevelTiles;
101   LevelTiles levels;
102   typedef std::vector<SpriteChange*> SpriteChanges;
103   SpriteChanges sprite_changes;
104   typedef std::vector<SpawnPoint*> SpawnPoints;
105   SpawnPoints spawn_points;
106
107   Statistics total_stats;
108
109 public:
110   WorldMap(const std::string& filename);
111   ~WorldMap();
112
113   void add_object(GameObject* object);
114
115   static WorldMap* current()
116   { return current_; }
117
118   virtual void setup();
119
120   /** Update worldmap state */
121   virtual void update(float delta);
122   /** Draw worldmap */
123   virtual void draw(DrawingContext& context);
124
125   Vector get_next_tile(Vector pos, Direction direction);
126   const Tile* at(Vector pos);
127
128   size_t level_count();
129   size_t solved_level_count();
130
131   /**
132    * gets called from the GameSession when a level has been successfully
133    * finished
134    */
135   void finished_level(Level* level);
136
137   LevelTile* at_level();
138   SpecialTile* at_special_tile();
139   SpriteChange* at_sprite_change(const Vector& pos);
140
141   /** Check if it is possible to walk from \a pos into \a direction,
142       if possible, write the new position to \a new_pos */
143   bool path_ok(Direction direction, const Vector& pos, Vector* new_pos);
144
145   /**
146    * Save worldmap state to squirrel state table
147    */
148   void save_state();
149
150   /**
151    * Load worldmap state from squirrel state table
152    */
153   void load_state();
154
155   const std::string& get_title() const
156   { return name; }
157     
158 private:
159   void get_level_title(LevelTile& level);
160   void draw_status(DrawingContext& context);
161   void calculate_total_stats();
162
163   void load(const std::string& filename);  
164   void on_escape_press();
165   void parse_special_tile(const lisp::Lisp* lisp);
166   void parse_sprite_change(const lisp::Lisp* lisp);
167 };
168
169 } // namespace WorldMapNS
170
171 #endif