ScummVM API documentation
map_base.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 ULTIMA_SHARED_MAPS_MAP_BASE_H
23 #define ULTIMA_SHARED_MAPS_MAP_BASE_H
24 
25 #include "common/array.h"
26 #include "common/serializer.h"
27 #include "ultima/shared/core/base_object.h"
28 #include "ultima/shared/core/rect.h"
29 #include "ultima/shared/maps/map_widget.h"
30 
31 namespace Ultima {
32 namespace Shared {
33 
34 class Game;
35 
36 namespace Maps {
37 
38 typedef int MapId;
39 typedef byte MapCell;
40 
41 class Map;
42 class MapTile;
43 
47 class MapBase {
51  class WidgetsArray : public Common::Array<MapWidgetPtr> {
52  public:
56  MapWidget *findByClass(const ClassDef &classDef) const;
57  };
58 
62  struct MapCellsRow {
63  private:
65  public:
66  byte &operator[](int idx) { return _data[idx]; }
67  byte operator[](int idx) const { return _data[idx]; }
68 
72  void resize(size_t newSize) { _data.resize(newSize); }
73  };
74 
79  struct ViewportPosition {
80  Point _topLeft; // Top, left tile position for viewport
81  Point _size; // Size of the viewport. Just in case we ever allow it to change
82  MapId _mapId; // Maze the viewport is for. Used to detect when the map changes
83 
87  ViewportPosition() : _topLeft(-1, -1), _mapId(-1) {}
88 
92  bool isValid() const { return _mapId != -1; }
93 
98  s.syncAsUint16LE(_topLeft.x);
99  s.syncAsUint16LE(_topLeft.y);
100  }
101 
105  void reset() { _mapId = -1; }
106  };
107 
108 private:
109 // Map *_map; // Map manager reference
110  Game *_game; // Game reference
111  bool _mapModified; // Tiles have been dynamically changed
112 protected:
113  MapId _mapId; // The map Id
114  uint _mapIndex; // Index of map within the group of same maps
115  uint _mapStyle; // Map style category for towns & castles
116  ViewportPosition _viewportPos; // Viewport position
117  Common::Array<MapCellsRow> _data; // Data for the map
118 protected:
122  void setDimensions(const Point &size);
123 
130  void addInfoMsg(const Common::String &text, bool newLine = true, bool replaceLine = false);
131 public:
132  Point _size; // X, Y size of the map
133  Point _tilesPerOrigTile; // For enhanced modes, number of tiles per original game tile
134  Common::String _name; // Name of map, if applicable
135  MapWidget *_playerWidget; // Current means of transport, even if on foot
136  WidgetsArray _widgets; // Party, monsteres, transports, etc.
137 public:
141  MapBase(Game *game, Map *) : _game(game),_playerWidget(nullptr),
142  _mapModified(false), _mapId(0), _mapIndex(0), _mapStyle(0) {}
143 
147  virtual ~MapBase() {}
148 
152  virtual void synchronize(Common::Serializer &s);
153 
157  void addWidget(MapWidget *widget);
158 
162  void removeWidget(MapWidget *widget);
163 
167  virtual void clear();
168 
172  virtual void getTileAt(const Point &pt, MapTile *tile, bool includePlayer = true);
173 
177  virtual void setTileAt(const Point &pt, uint tileId);
178 
182  void resetViewport();
183 
187  virtual Point getViewportPosition(const Point &viewportSize);
188 
192  virtual void load(MapId mapId);
193 
199  virtual bool changeLevel(int delta) { return true; }
200 
204  virtual uint getLevel() const { return 0; }
205 
209  virtual bool isMapWrapped() const { return false; }
210 
214  virtual MapWidget *createWidget(const Common::String &name) = 0;
215 
219  size_t width() const { return _size.x; }
220 
224  size_t height() const { return _size.y; }
225 
229  Point getPosition() const;
230 
234  void setPosition(const Point &pt);
235 
239  Direction getDirection() const;
240 
244  void setDirection(Direction dir);
245 
249  Point getDirectionDelta() const;
250 
254  virtual Point getDeltaPosition(const Point &delta);
255 
259  MapId getMapId() const { return _mapId; }
260 
264  uint getMapIndex() const { return _mapIndex; }
265 
269  uint getMapStyle() const { return _mapStyle; }
270 
274  virtual void shiftViewport(const Point &delta);
275 
279  virtual void update();
280 
284  virtual void castSpell(uint spell) = 0;
285 };
286 
287 } // End of namespace Maps
288 } // End of namespace Shared
289 } // End of namespace Ultima
290 
291 #endif
virtual void shiftViewport(const Point &delta)
Definition: map.h:46
Definition: map_tile.h:36
virtual void setTileAt(const Point &pt, uint tileId)
Definition: str.h:59
Definition: game.h:42
Definition: array.h:52
size_t height() const
Definition: map_base.h:224
virtual bool changeLevel(int delta)
Definition: map_base.h:199
void setDirection(Direction dir)
virtual void load(MapId mapId)
MapId getMapId() const
Definition: map_base.h:259
void removeWidget(MapWidget *widget)
Definition: serializer.h:79
void addInfoMsg(const Common::String &text, bool newLine=true, bool replaceLine=false)
Definition: detection.h:27
virtual ~MapBase()
Definition: map_base.h:147
void setPosition(const Point &pt)
void setDimensions(const Point &size)
virtual void synchronize(Common::Serializer &s)
virtual void castSpell(uint spell)=0
Direction getDirection() const
Definition: rect.h:45
uint getMapStyle() const
Definition: map_base.h:269
Definition: map_widget.h:50
virtual uint getLevel() const
Definition: map_base.h:204
int16 x
Definition: rect.h:46
void resize(size_type newSize)
Definition: array.h:411
Definition: map_base.h:47
virtual bool isMapWrapped() const
Definition: map_base.h:209
int16 y
Definition: rect.h:47
virtual MapWidget * createWidget(const Common::String &name)=0
MapBase(Game *game, Map *)
Definition: map_base.h:141
virtual void getTileAt(const Point &pt, MapTile *tile, bool includePlayer=true)
virtual Point getViewportPosition(const Point &viewportSize)
Definition: base_object.h:43
virtual Point getDeltaPosition(const Point &delta)
size_t width() const
Definition: map_base.h:219
void addWidget(MapWidget *widget)
uint getMapIndex() const
Definition: map_base.h:264