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 ULTIMA4_MAP_MAP_H
23 #define ULTIMA4_MAP_MAP_H
24 
25 #include "ultima/ultima4/core/coords.h"
26 #include "ultima/ultima4/map/direction.h"
27 #include "ultima/ultima4/sound/music.h"
28 #include "ultima/ultima4/game/object.h"
29 #include "ultima/ultima4/filesys/savegame.h"
30 #include "ultima/ultima4/core/types.h"
31 
32 namespace Ultima {
33 namespace Ultima4 {
34 
35 #define MAP_IS_OOB(mapptr, c) (((c).x) < 0 || ((c).x) >= (static_cast<int>((mapptr)->_width)) || ((c).y) < 0 || ((c).y) >= (static_cast<int>((mapptr)->_height)) || ((c).z) < 0 || ((c).z) >= (static_cast<int>((mapptr)->_levels)))
36 
37 class AnnotationMgr;
38 class Map;
39 class Object;
40 class Person;
41 class Creature;
42 class TileMap;
43 class Tileset;
44 struct Portal;
45 struct _Dungeon;
46 
47 typedef Std::vector<Portal *> PortalList;
48 typedef Common::List<int> CompressedChunkList;
49 typedef Std::vector<MapTile> MapData;
50 
51 /* flags */
52 #define SHOW_AVATAR (1 << 0)
53 #define NO_LINE_OF_SIGHT (1 << 1)
54 #define FIRST_PERSON (1 << 2)
55 
56 /* mapTileAt flags */
57 #define WITHOUT_OBJECTS 0
58 #define WITH_GROUND_OBJECTS 1
59 #define WITH_OBJECTS 2
60 
64 class MapCoords : public Coords {
65 public:
66  MapCoords(int initx = 0, int inity = 0, int initz = 0) : Coords(initx, inity, initz) {}
67  MapCoords(const Coords &a) : Coords(a.x, a.y, a.z) {}
68 
69  MapCoords &operator=(const Coords &a) {
70  x = a.x;
71  y = a.y;
72  z = a.z;
73  return *this;
74  }
75  bool operator==(const MapCoords &a) const;
76  bool operator!=(const MapCoords &a) const;
77  bool operator<(const MapCoords &a) const;
78 
79  MapCoords &wrap(const class Map *map);
80  MapCoords &putInBounds(const class Map *map);
81  MapCoords &move(Direction d, const class Map *map = nullptr);
82  MapCoords &move(int dx, int dy, const class Map *map = nullptr);
83 
93  int getRelativeDirection(const MapCoords &c, const class Map *map = nullptr) const;
94 
102  Direction pathTo(const MapCoords &c, int valid_dirs = MASK_DIR_ALL, bool towards = true, const class Map *map = nullptr) const;
103 
107  Direction pathAway(const MapCoords &c, int valid_dirs = MASK_DIR_ALL) const;
108 
114  int movementDistance(const MapCoords &c, const class Map *map = nullptr) const;
115 
121  int distance(const MapCoords &c, const class Map *map = nullptr) const;
122 
126  static MapCoords nowhere() {
127  return MapCoords(-1, -1, -1);
128  }
129 };
130 
134 class Map {
135 public:
136  enum Type {
137  WORLD,
138  CITY,
139  SHRINE,
140  COMBAT,
141  DUNGEON,
142  XML
143  };
144 
145  enum BorderBehavior {
146  BORDER_WRAP,
147  BORDER_EXIT2PARENT,
148  BORDER_FIXED
149  };
150 
151 
152  class Source {
153  public:
154  Source() : _type(WORLD) {}
155  Source(const Common::String &f, Type t) : _fname(f), _type(t) {}
156 
157  Common::String _fname;
158  Type _type;
159  };
160 
161  Map();
162  virtual ~Map();
163 
164  // Member functions
165  virtual Common::String getName();
166 
171  Object *objectAt(const Coords &coords);
172 
178  const Portal *portalAt(const Coords &coords, int actionFlags);
179 
183  MapTile *getTileFromData(const Coords &coords);
184 
190  MapTile *tileAt(const Coords &coords, int withObjects);
191  const Tile *tileTypeAt(const Coords &coords, int withObjects);
192 
196  bool isWorldMap();
197 
201  bool isEnclosed(const Coords &party);
202 
206  Creature *addCreature(const class Creature *m, Coords coords);
207  Object *addObject(MapTile tile, MapTile prevTile, Coords coords);
208 
212  Object *addObject(Object *obj, Coords coords);
213 
221  void removeObject(const class Object *rem, bool deleteObject = true);
222  ObjectDeque::iterator removeObject(ObjectDeque::iterator rem, bool deleteObject = true);
223 
227  void clearObjects();
228 
234  Creature *moveObjects(MapCoords avatar);
235 
240  void resetObjectAnimations();
241 
245  int getNumberOfCreatures();
246 
250  int getValidMoves(MapCoords from, MapTile transport);
251  bool move(Object *obj, Direction d);
252 
256  void alertGuards();
257  MapCoords getLabel(const Common::String &name) const;
258 
259  // u4dos compatibility
260  bool fillMonsterTable();
261  MapTile translateFromRawTileIndex(int c) const;
262  uint translateToRawTileIndex(MapTile &tile) const;
263 
264 public:
265  MapId _id;
266  Common::Path _fname;
267  Type _type;
268  uint _width, _height, _levels;
269  uint _chunkWidth, _chunkHeight;
270  uint _offset;
271 
272  Source _baseSource;
273  Common::List<Source> _extraSources;
274 
275  CompressedChunkList _compressedChunks;
276  BorderBehavior _borderBehavior;
277 
278  PortalList _portals;
279  AnnotationMgr *_annotations;
280  int _flags;
281  Music::Type _music;
282  MapData _data;
283  ObjectDeque _objects;
285  Tileset *_tileSet;
286  TileMap *_tileMap;
287  MapTile _blank;
288 
289 
290  // u4dos compatibility
291  SaveGameMonsterRecord _monsterTable[MONSTERTABLE_SIZE];
292 
293 private:
294  // disallow map copying: all maps should be created and accessed
295  // through the MapMgr
296  Map(const Map &map);
297  Map &operator=(const Map &map);
298 
299  void findWalkability(Coords coords, int *path_data);
300 };
301 
302 } // End of namespace Ultima4
303 } // End of namespace Ultima
304 
305 #endif
Definition: portal.h:53
Definition: str.h:59
Definition: containers.h:186
Definition: map.h:134
Definition: coords.h:31
int getRelativeDirection(const MapCoords &c, const class Map *map=nullptr) const
Definition: path.h:52
Definition: detection.h:27
Direction pathTo(const MapCoords &c, int valid_dirs=MASK_DIR_ALL, bool towards=true, const class Map *map=nullptr) const
Definition: hashmap.h:85
Definition: map_tile.h:34
Definition: creature.h:159
Definition: savegame.h:214
int distance(const MapCoords &c, const class Map *map=nullptr) const
Definition: object.h:42
static MapCoords nowhere()
Definition: map.h:126
Definition: tileset.h:59
int movementDistance(const MapCoords &c, const class Map *map=nullptr) const
Definition: tilemap.h:38
Definition: list_intern.h:51
Definition: tile.h:65
Definition: annotation.h:135
Direction pathAway(const MapCoords &c, int valid_dirs=MASK_DIR_ALL) const
Definition: map.h:152
Definition: map.h:64