supertux
worldmap_sector.hpp
1 // SuperTux
2 // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmail.com>
3 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 // 2023 Vankata453
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef HEADER_SUPERTUX_WORLDMAP_WORLDMAP_SECTOR_HPP
20 #define HEADER_SUPERTUX_WORLDMAP_WORLDMAP_SECTOR_HPP
21 
22 #include "supertux/sector_base.hpp"
23 
24 #include "worldmap/tux.hpp"
25 
26 namespace worldmap {
27 
28 class Camera;
29 class SpawnPoint;
30 class WorldMap;
31 
39 class WorldMapSector final : public Base::Sector
40 {
41  friend class WorldMapSectorParser;
42  friend class WorldMapState;
43 
44 public:
45  static void register_class(ssq::VM& vm);
46 
47 public:
48  static WorldMapSector* current();
49 
50 public:
51  WorldMapSector(WorldMap& parent);
52  ~WorldMapSector() override;
53 
54  void finish_construction(bool editable) override;
55 
56  std::string get_exposed_class_name() const override { return "WorldMapSector"; }
57 
58  void setup();
59  void leave();
60 
61  void draw(DrawingContext& context) override;
62  void update(float dt_sec) override;
63 
64  Vector get_next_tile(const Vector& pos, const Direction& direction) const;
65 
69  int available_directions_at(const Vector& pos) const;
70 
74  int tile_data_at(const Vector& pos) const;
75 
76  size_t level_count() const;
77  size_t solved_level_count() const;
78 
81  void finished_level(Level* level);
82 
85  SpawnPoint* get_spawnpoint_by_name(const std::string& spawnpoint_name) const;
86 
87  template<class T>
88  T* at_object() const
89  {
90  return at_object<T>(m_tux->get_tile_pos());
91  }
92  template<class T>
93  T* at_object(const Vector& pos) const
94  {
95  for (auto& obj : get_objects_by_type<T>())
96  if (obj.get_tile_pos() == pos)
97  return &obj;
98 
99  return nullptr;
100  }
101 
104  bool path_ok(const Direction& direction, const Vector& old_pos, Vector* new_pos) const;
105 
107  void set_initial_fade_tilemap(const std::string& tilemap_name, int direction);
108 
109  bool in_worldmap() const override { return true; }
110 
115  float get_tux_x() const;
120  float get_tux_y() const;
121 
127  void set_sector(const std::string& sector);
135  void spawn(const std::string& sector, const std::string& spawnpoint);
141  void move_to_spawnpoint(const std::string& spawnpoint);
142  void move_to_spawnpoint(const std::string& spawnpoint, bool pan);
143 
148  std::string get_filename() const;
155  void set_title_level(const std::string& filename);
156 
157  TileSet* get_tileset() const override;
158  WorldMap& get_worldmap() const { return m_parent; }
159  Camera& get_camera() const { return *m_camera; }
160  Tux& get_tux() const { return *m_tux; }
161  Vector get_tux_pos() const;
162 
163 protected:
164  MovingObject& add_object_scripting(const std::string& class_name, const std::string& name,
165  const Vector& pos, const std::string& direction,
166  const std::string& data) override;
167 
168  void draw_status(DrawingContext& context);
169 
170 private:
171  WorldMap& m_parent;
172 
173  std::unique_ptr<Camera> m_camera;
174  Tux* m_tux;
175  std::vector<std::unique_ptr<SpawnPoint> > m_spawnpoints;
176 
177  std::string m_initial_fade_tilemap;
178  int m_fade_direction;
179 
180 private:
181  WorldMapSector(const WorldMapSector&) = delete;
182  WorldMapSector& operator=(const WorldMapSector&) = delete;
183 };
184 
185 } // namespace worldmap
186 
187 #endif
188 
189 /* EOF */
int available_directions_at(const Vector &pos) const
gets a bitfield of Tile::WORLDMAP_NORTH | Tile::WORLDMAP_WEST | ...
Definition: worldmap_sector.cpp:421
Definition: worldmap_sector_parser.hpp:27
bool path_ok(const Direction &direction, const Vector &old_pos, Vector *new_pos) const
Check if it is possible to walk from pos into direction, if possible, write the new position to new_p...
Definition: worldmap_sector.cpp:534
Definition: spawn_point.hpp:30
MovingObject & add_object_scripting(const std::string &class_name, const std::string &name, const Vector &pos, const std::string &direction, const std::string &data) override
Add a MovingObject from scripting.
Definition: worldmap_sector.cpp:380
int tile_data_at(const Vector &pos) const
returns a bitfield representing the union of all Tile::WORLDMAP_XXX values of all solid tiles at the ...
Definition: worldmap_sector.cpp:427
Definition: worldmap_state.hpp:30
SpawnPoint * get_spawnpoint_by_name(const std::string &spawnpoint_name) const
Get a spawnpoint by its name.
Definition: worldmap_sector.cpp:524
float get_tux_x() const
Returns Tux&#39;s X position on the worldmap.
Definition: worldmap_sector.cpp:632
float get_tux_y() const
Returns Tux&#39;s Y position on the worldmap.
Definition: worldmap_sector.cpp:638
void move_to_spawnpoint(const std::string &spawnpoint)
Moves Tux to the specified spawnpoint.
Definition: worldmap_sector.cpp:586
void set_title_level(const std::string &filename)
Overrides the "Title Screen Level" property for the world with ""filename"".
Definition: worldmap_sector.cpp:650
std::string get_filename() const
Gets the path to the worldmap file.
Definition: worldmap_sector.cpp:644
Represents one of (potentially) multiple, separate parts of a WorldMap.
Definition: worldmap_sector.hpp:39
Definition: camera.hpp:27
Definition: object_settings.hpp:32
void finished_level(Level *level)
gets called from the GameSession when a level has been successfully finished
Definition: worldmap_sector.cpp:462
A base for sector classes.
Definition: sector_base.hpp:30
Represents a collection of Sectors running in a single GameSession.
Definition: level.hpp:30
void set_sector(const std::string &sector)
Changes the current sector of the worldmap to a specified new sector.
Definition: worldmap_sector.cpp:574
void finish_construction(bool editable) override
Needs to be called after parsing to finish the construction of the Sector before using it...
Definition: worldmap_sector.cpp:87
Definition: tux.hpp:34
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
void set_initial_fade_tilemap(const std::string &tilemap_name, int direction)
Sets the name of the tilemap that should fade when worldmap is set up.
Definition: worldmap_sector.cpp:612
void setup()
Definition: worldmap_sector.cpp:107
A ""Camera"" that was given a name can be manipulated by scripts.
Definition: camera.hpp:40
Definition: tile_set.hpp:44
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void spawn(const std::string &sector, const std::string &spawnpoint)
Changes the current sector of the worldmap to a specified new sector, moving Tux to the specified spa...
Definition: worldmap_sector.cpp:580
Definition: worldmap.hpp:33