4 // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
5 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
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.
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.
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
26 #include "math/vector.hpp"
27 #include "lisp/lisp.hpp"
28 #include "control/controller.hpp"
29 #include "statistics.hpp"
32 #include "tile_manager.hpp"
33 #include "game_object.hpp"
34 #include "console.hpp"
35 #include "../level.hpp"
36 #include "worldmap/special_tile.hpp"
37 #include "worldmap/sprite_change.hpp"
38 #include "worldmap/teleporter.hpp"
39 #include "worldmap/spawn_point.hpp"
40 #include "worldmap/direction.hpp"
47 namespace WorldMapNS {
63 std::string direction_to_string(Direction d);
64 Direction string_to_direction(const std::string& d);
65 Direction reverse_dir(Direction d);
68 * Screen that runs a WorldMap, which lets the player choose a Level.
70 class WorldMap : public Screen
78 static WorldMap* current_;
80 std::auto_ptr<Menu> worldmap_menu;
86 std::string init_script;
88 typedef std::vector<GameObject*> GameObjects;
89 GameObjects game_objects;
90 std::list<TileMap*> solid_tilemaps;
93 /** Variables to deal with the passive map messages */
94 Timer passive_message_timer;
95 std::string passive_message;
98 std::string map_filename;
99 std::string levels_path;
101 typedef std::vector<SpecialTile*> SpecialTiles;
102 SpecialTiles special_tiles;
103 typedef std::vector<LevelTile*> LevelTiles;
105 typedef std::vector<SpriteChange*> SpriteChanges;
106 SpriteChanges sprite_changes;
107 typedef std::vector<SpawnPoint*> SpawnPoints;
108 SpawnPoints spawn_points;
109 std::vector<Teleporter*> teleporters;
111 Statistics total_stats;
113 HSQOBJECT worldmap_table;
114 typedef std::vector<HSQOBJECT> ScriptList;
118 std::string force_spawnpoint; /**< if set, spawnpoint will be forced to this value */
123 WorldMap(const std::string& filename, const std::string& force_spawnpoint = "");
126 void add_object(GameObject* object);
128 void try_expose(GameObject* object);
129 void try_unexpose(GameObject* object);
131 static WorldMap* current()
134 virtual void setup();
135 virtual void leave();
137 /** Update worldmap state */
138 virtual void update(float delta);
140 virtual void draw(DrawingContext& context);
142 Vector get_next_tile(Vector pos, Direction direction);
145 * gets a bitfield of Tile::WORLDMAP_NORTH | Tile::WORLDMAP_WEST | ... values,
146 * which indicates the directions Tux can move to when at the given position.
148 int available_directions_at(Vector pos);
151 * returns a bitfield representing the union of all Tile::WORLDMAP_XXX values
152 * of all solid tiles at the given position
154 int tile_data_at(Vector pos);
156 size_t level_count();
157 size_t solved_level_count();
160 * gets called from the GameSession when a level has been successfully
163 void finished_level(Level* level);
165 LevelTile* at_level();
166 SpecialTile* at_special_tile();
167 SpriteChange* at_sprite_change(const Vector& pos);
168 Teleporter* at_teleporter(const Vector& pos);
170 /** Check if it is possible to walk from \a pos into \a direction,
171 if possible, write the new position to \a new_pos */
172 bool path_ok(Direction direction, const Vector& pos, Vector* new_pos);
175 * Save worldmap state to squirrel state table
180 * Load worldmap state from squirrel state table
184 const std::string& get_title() const
188 * runs a script in the context of the worldmap (and keeps a reference to
189 * the script (so the script gets destroyed when the worldmap is destroyed)
191 HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
194 * switch to another worldmap.
195 * filename is relative to data root path
197 void change(const std::string& filename, const std::string& force_spawnpoint="");
200 * moves Tux to the given spawnpoint
202 void move_to_spawnpoint(const std::string& spawnpoint);
205 * returns the width (in tiles) of a worldmap
207 float get_width() const;
210 * returns the height (in tiles) of a worldmap
212 float get_height() const;
215 void get_level_title(LevelTile& level);
216 void draw_status(DrawingContext& context);
217 void calculate_total_stats();
219 void load(const std::string& filename);
220 void on_escape_press();
223 } // namespace WorldMapNS