supertux
sector.hpp
1 // SuperTux - A Jump'n Run
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_SUPERTUX_SECTOR_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_SECTOR_HPP
19 
20 #include <vector>
21 #include <stdint.h>
22 
23 #include "math/anchor_point.hpp"
24 #include "squirrel/squirrel_environment.hpp"
25 #include "supertux/d_scope.hpp"
26 #include "supertux/game_object_manager.hpp"
27 #include "video/color.hpp"
28 
29 namespace collision {
30 class Constraints;
31 }
32 
33 class Camera;
34 class CollisionSystem;
35 class DisplayEffect;
36 class DrawingContext;
37 class Level;
38 class MovingObject;
39 class Player;
40 class ReaderMapping;
41 class Rectf;
42 class Size;
43 class TileMap;
44 class Vector;
45 class Writer;
46 
49 class Sector final : public GameObjectManager
50 {
51 public:
52  friend class CollisionSystem;
53  friend class EditorSectorMenu;
54 
55 private:
56  static Sector* s_current;
57 
58 public:
60  static Sector& get() { assert(s_current != nullptr); return *s_current; }
61  static Sector* current() { return s_current; }
62 
63 public:
64  Sector(Level& parent);
65  ~Sector();
66 
69  void finish_construction(bool editable);
70 
71  Level& get_level() const;
72 
74  void activate(const std::string& spawnpoint);
75  void activate(const Vector& player_pos);
76  void deactivate();
77 
78  void update(float dt_sec);
79 
80  void draw(DrawingContext& context);
81 
82  void save(Writer &writer);
83 
85  void stop_looping_sounds();
86 
88  void play_looping_sounds();
89 
90  void set_name(const std::string& name_) { m_name = name_; }
91  const std::string& get_name() const { return m_name; }
92 
95  bool inside(const Rectf& rectangle) const;
96 
99  bool is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid = false) const;
100 
105  bool is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object = nullptr, const bool ignoreUnisolid = false) const;
106 
111  bool is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object = nullptr) const;
112 
113  bool free_line_of_sight(const Vector& line_start, const Vector& line_end, const MovingObject* ignore_object = nullptr) const;
114  bool can_see_player(const Vector& eye) const;
115 
116  Player* get_nearest_player (const Vector& pos) const;
117  Player* get_nearest_player (const Rectf& pos) const {
118  return (get_nearest_player (get_anchor_pos (pos, ANCHOR_MIDDLE)));
119  }
120 
121  std::vector<MovingObject*> get_nearby_objects (const Vector& center, float max_distance) const;
122 
123  Rectf get_active_region() const;
124 
125  int get_foremost_layer() const;
126 
128  Size get_editor_size() const;
129 
131  void resize_sector(const Size& old_size, const Size& new_size, const Size& resize_offset);
132 
134  void change_solid_tiles(uint32_t old_tile_id, uint32_t new_tile_id);
135 
137  void set_gravity(float gravity);
138  float get_gravity() const;
139 
140  void set_init_script(const std::string& init_script) {
141  m_init_script = init_script;
142  }
143 
144  void run_script(const std::string& script, const std::string& sourcename);
145 
146  Camera& get_camera() const;
147  Player& get_player() const;
148  DisplayEffect& get_effect() const;
149 
150 private:
151  uint32_t collision_tile_attributes(const Rectf& dest, const Vector& mov) const;
152 
153  virtual bool before_object_add(GameObject& object) override;
154  virtual void before_object_remove(GameObject& object) override;
155 
156  int calculate_foremost_layer() const;
157 
160  void convert_tiles2gameobject();
161 
162 private:
164  Level& m_level;
165 
166  std::string m_name;
167 
168  bool m_fully_constructed;
169 
170  std::string m_init_script;
171 
172  int m_foremost_layer;
173 
174  std::unique_ptr<SquirrelEnvironment> m_squirrel_environment;
175  std::unique_ptr<CollisionSystem> m_collision_system;
176 
177  float m_gravity;
178 
179 private:
180  Sector(const Sector&) = delete;
181  Sector& operator=(const Sector&) = delete;
182 };
183 
184 #endif
185 
186 /* EOF */
Definition: writer.hpp:27
Simple two dimensional vector.
Definition: vector.hpp:24
Definition: game_object_manager.hpp:34
Definition: collision_system.hpp:32
Represents one of (potentially) multiple, separate parts of a Level.
Definition: sector.hpp:49
Definition: size.hpp:24
Definition: collision.cpp:24
Definition: rectf.hpp:29
Definition: display_effect.hpp:24
Represents a collection of Sectors running in a single GameSession.
Definition: level.hpp:29
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:31
Definition: editor_sector_menu.hpp:25
This class is responsible for drawing the level tiles.
Definition: tilemap.hpp:39
Definition: camera.hpp:36
Definition: reader_mapping.hpp:31
Definition: player.hpp:39
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42