2 // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
3 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef HEADER_SUPERTUX_WORLDMAP_WORLDMAP_HPP
19 #define HEADER_SUPERTUX_WORLDMAP_WORLDMAP_HPP
24 #include "control/controller.hpp"
25 #include "lisp/lisp.hpp"
26 #include "math/vector.hpp"
27 #include "supertux/console.hpp"
28 #include "supertux/game_object.hpp"
29 #include "supertux/level.hpp"
30 #include "supertux/screen.hpp"
31 #include "supertux/statistics.hpp"
32 #include "supertux/tile_manager.hpp"
33 #include "supertux/timer.hpp"
34 #include "worldmap/direction.hpp"
35 #include "worldmap/spawn_point.hpp"
36 #include "worldmap/special_tile.hpp"
37 #include "worldmap/sprite_change.hpp"
38 #include "worldmap/teleporter.hpp"
45 namespace WorldMapNS {
61 std::string direction_to_string(Direction d);
62 Direction string_to_direction(const std::string& d);
63 Direction reverse_dir(Direction d);
66 * Screen that runs a WorldMap, which lets the player choose a Level.
68 class WorldMap : public Screen
70 static Color level_title_color;
71 static Color message_color;
72 static Color teleporter_message_color;
79 static WorldMap* current_;
81 std::auto_ptr<Menu> worldmap_menu;
87 std::string init_script;
89 typedef std::vector<GameObject*> GameObjects;
90 GameObjects game_objects;
91 std::list<TileMap*> solid_tilemaps;
94 /** Variables to deal with the passive map messages */
95 Timer passive_message_timer;
96 std::string passive_message;
99 std::string map_filename;
100 std::string levels_path;
102 typedef std::vector<SpecialTile*> SpecialTiles;
103 SpecialTiles special_tiles;
104 typedef std::vector<LevelTile*> LevelTiles;
106 typedef std::vector<SpriteChange*> SpriteChanges;
107 SpriteChanges sprite_changes;
108 typedef std::vector<SpawnPoint*> SpawnPoints;
109 SpawnPoints spawn_points;
110 std::vector<Teleporter*> teleporters;
112 Statistics total_stats;
114 HSQOBJECT worldmap_table;
115 typedef std::vector<HSQOBJECT> ScriptList;
119 std::string force_spawnpoint; /**< if set, spawnpoint will be forced to this value */
123 /* variables to track panning to a spawn point */
128 WorldMap(const std::string& filename, const std::string& force_spawnpoint = "");
131 void add_object(GameObject* object);
133 void try_expose(GameObject* object);
134 void try_unexpose(GameObject* object);
136 static WorldMap* current()
139 virtual void setup();
140 virtual void leave();
142 /** Update worldmap state */
143 virtual void update(float delta);
145 virtual void draw(DrawingContext& context);
147 Vector get_next_tile(Vector pos, Direction direction);
150 * gets a bitfield of Tile::WORLDMAP_NORTH | Tile::WORLDMAP_WEST | ... values,
151 * which indicates the directions Tux can move to when at the given position.
153 int available_directions_at(Vector pos);
156 * returns a bitfield representing the union of all Tile::WORLDMAP_XXX values
157 * of all solid tiles at the given position
159 int tile_data_at(Vector pos);
161 size_t level_count();
162 size_t solved_level_count();
165 * gets called from the GameSession when a level has been successfully
168 void finished_level(Level* level);
170 /** returns current Tux incarnation */
171 Tux* get_tux() { return tux; }
173 LevelTile* at_level();
174 SpecialTile* at_special_tile();
175 SpriteChange* at_sprite_change(const Vector& pos);
176 Teleporter* at_teleporter(const Vector& pos);
178 /** Check if it is possible to walk from \a pos into \a direction,
179 if possible, write the new position to \a new_pos */
180 bool path_ok(Direction direction, const Vector& pos, Vector* new_pos);
183 * Save worldmap state to squirrel state table
188 * Load worldmap state from squirrel state table
192 const std::string& get_title() const
196 * runs a script in the context of the worldmap (and keeps a reference to
197 * the script (so the script gets destroyed when the worldmap is destroyed)
199 HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
202 * switch to another worldmap.
203 * filename is relative to data root path
205 void change(const std::string& filename, const std::string& force_spawnpoint="");
208 * moves Tux to the given spawnpoint
210 void move_to_spawnpoint(const std::string& spawnpoint, bool pan =false);
213 * returns the width (in tiles) of a worldmap
215 float get_width() const;
218 * returns the height (in tiles) of a worldmap
220 float get_height() const;
223 void get_level_title(LevelTile& level);
224 void draw_status(DrawingContext& context);
225 void calculate_total_stats();
227 void load(const std::string& filename);
228 void on_escape_press();
230 Vector get_camera_pos_for_tux();
231 void clamp_camera_position(Vector& c);
234 WorldMap(const WorldMap&);
235 WorldMap& operator=(const WorldMap&);
238 } // namespace WorldMapNS