ScummVM API documentation
map.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MM1_MAPS_MAP_H
23 #define MM1_MAPS_MAP_H
24 
25 #include "common/array.h"
26 #include "common/str.h"
27 #include "mm/mm1/events.h"
28 #include "mm/mm1/game/game_logic.h"
29 
30 namespace MM {
31 namespace MM1 {
32 namespace Maps {
33 
34 #define MAP_W 16
35 #define MAP_H 16
36 #define MAP_SIZE (MAP_W * MAP_H)
37 
38 class Maps;
39 
40 enum DataOffset {
41  MAP_ID = 0,
42  MAP_1 = 1,
43  MAP_2 = 2,
44  MAP_4 = 4,
45  MAP_6 = 6,
46  MAP_NORTH_EXIT_ID = 8,
47  MAP_NORTH_EXIT_SECTION = 10,
48  MAP_EAST_EXIT_ID = 11,
49  MAP_EAST_EXIT_SECTION = 13,
50  MAP_SOUTH_EXIT_ID = 14,
51  MAP_SOUTH_EXIT_SECTION = 16,
52  MAP_WEST_EXIT_ID = 17,
53  MAP_WEST_EXIT_SECTION = 19,
54  MAP_20 = 20,
55  MAP_21 = 21,
56  MAP_FLEE_THRESHOLD = 22,
57  MAP_FLEE_X = 23,
58  MAP_FLEE_Y = 24,
59  MAP_SURRENDER_THRESHOLD = 25,
60  MAP_SURRENDER_X = 26,
61  MAP_SURRENDER_Y = 27,
62  MAP_BRIBE_THRESHOLD = 28,
63  MAP_29 = 29,
64  MAP_30 = 30,
65  MAP_31 = 31,
66  MAP_32 = 32,
67  MAP_33 = 33,
68  MAP_MAX_MONSTERS = 34,
69  MAP_SECTOR1 = 35,
70  MAP_SECTOR2 = 36,
71  MAP_TYPE = 37,
72  MAP_DISPEL_THRESHOLD = 38,
73  MAP_SURFACE_ID = 39,
74  MAP_SURFACE_SECTION = 41,
75  MAP_SURFACE_X = 42,
76  MAP_SURFACE_Y = 43,
77  MAP_44 = 44,
78  MAP_45 = 45,
79  MAP_FLAGS = 46,
80  MAP_47 = 47,
81  MAP_TRAP_THRESHOLD = 48,
82  MAP_49 = 49,
83  MAP_SPECIAL_COUNT = 50
84 };
85 
86 enum WallType {
87  WALL_NONE = 0, WALL_NORMAL = 1, WALL_DOOR = 2,
88  WALL_TORCH = 3
89 };
90 
91 enum CellState {
92  CELL_SPECIAL = 0x80, CELL_DARK = 0x20
93 };
94 
95 class Maps;
96 
97 class Map : public Game::GameLogic {
98 protected:
99  Common::String _name;
100  Common::String _description;
101  uint16 _id;
102  uint _mapIndex;
103  byte _defaultSection;
104  Common::Array<byte> _data;
105 private:
109  void loadMazeData();
110 
114  void loadOverlay();
115 public:
119  static void reduceHP();
120 
127  static void none160() {}
128 
132  void encounter(const byte *id1, const byte *id2);
133 
134 public:
135  byte _walls[MAP_SIZE];
136  byte _states[MAP_SIZE];
137  uint8 _visited[MAP_SIZE];
138 public:
139  Map(uint index, const Common::String &name, uint16 id,
140  byte defaultSection, const char *desc = nullptr);
141  virtual ~Map() {}
142 
146  virtual void load();
147 
151  virtual void special() = 0;
152 
158  virtual bool mappingAllowed() const {
159  return true;
160  }
161 
165  Common::String getName() const { return _name; }
166 
170  Common::String getDescription() const { return _description; }
171 
172 
176  uint16 getId() const { return _id; }
177 
181  byte getDefaultSection() const {
182  return _defaultSection;
183  }
184 
188  const byte &operator[](uint ofs) const {
189  return _data[ofs];
190  }
191  byte &operator[](uint ofs) {
192  return _data[ofs];
193  }
194  byte dataByte(uint ofs) const {
195  return _data[ofs];
196  }
197  uint16 dataWord(uint16 ofs) const;
198  void dataWord(uint16 ofs, uint16 val);
199 
204  bool checkPartyDead();
205 
209  template<class T>
210  bool send(const T &msg) {
211  return g_events->send(msg);
212  }
213  template<class T>
214  bool send(const Common::String &name, const T &msg) {
215  return g_events->send(name, msg);
216  }
217 
221  uint getMapIndex() const {
222  return _mapIndex;
223  }
224 
228  static void updateGame();
229 
233  static void redrawGame();
234 
238  void unlockDoor();
239 
243  void visitedSpecial();
244 
248  void visitedExit();
249 
253  void visitedBusiness();
254 };
255 
256 } // namespace Maps
257 } // namespace MM1
258 } // namespace MM
259 
260 #endif
static void redrawGame()
static void reduceHP()
Definition: str.h:59
virtual bool mappingAllowed() const
Definition: map.h:158
Common::String getDescription() const
Definition: map.h:170
static void updateGame()
static void none160()
Definition: map.h:127
byte getDefaultSection() const
Definition: map.h:181
Definition: map.h:97
const byte & operator[](uint ofs) const
Definition: map.h:188
uint16 getId() const
Definition: map.h:176
Definition: detection.h:27
Definition: game_logic.h:29
Common::String getName() const
Definition: map.h:165
virtual void load()
uint getMapIndex() const
Definition: map.h:221
void encounter(const byte *id1, const byte *id2)
virtual void special()=0
bool send(const T &msg)
Definition: map.h:210