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
31namespace Ultima {
32namespace Shared {
33
34class Game;
35
36namespace Maps {
37
38typedef int MapId;
39typedef byte MapCell;
40
41class Map;
42class MapTile;
43
47class 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
108private:
109// Map *_map; // Map manager reference
110 Game *_game; // Game reference
111 bool _mapModified; // Tiles have been dynamically changed
112protected:
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
118protected:
122 void setDimensions(const Point &size);
123
130 void addInfoMsg(const Common::String &text, bool newLine = true, bool replaceLine = false);
131public:
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.
137public:
141 MapBase(Game *game, Map *) : _game(game),_playerWidget(nullptr),
142 _mapModified(false), _mapId(0), _mapIndex(0), _mapStyle(0) {}
143
147 virtual ~MapBase() {}
148
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
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
230
234 void setPosition(const Point &pt);
235
239 Direction getDirection() const;
240
244 void setDirection(Direction dir);
245
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
Definition: array.h:52
void resize(size_type newSize)
Definition: array.h:412
Definition: serializer.h:80
Definition: str.h:59
Definition: base_object.h:43
Definition: game.h:42
Definition: map_base.h:47
void addInfoMsg(const Common::String &text, bool newLine=true, bool replaceLine=false)
virtual uint getLevel() const
Definition: map_base.h:204
virtual void shiftViewport(const Point &delta)
virtual void synchronize(Common::Serializer &s)
void addWidget(MapWidget *widget)
size_t height() const
Definition: map_base.h:224
size_t width() const
Definition: map_base.h:219
void setPosition(const Point &pt)
MapBase(Game *game, Map *)
Definition: map_base.h:141
void setDimensions(const Point &size)
virtual Point getViewportPosition(const Point &viewportSize)
uint getMapIndex() const
Definition: map_base.h:264
void setDirection(Direction dir)
virtual MapWidget * createWidget(const Common::String &name)=0
virtual void setTileAt(const Point &pt, uint tileId)
void removeWidget(MapWidget *widget)
virtual void getTileAt(const Point &pt, MapTile *tile, bool includePlayer=true)
virtual Point getDeltaPosition(const Point &delta)
MapId getMapId() const
Definition: map_base.h:259
uint getMapStyle() const
Definition: map_base.h:269
Direction getDirection() const
virtual ~MapBase()
Definition: map_base.h:147
virtual void castSpell(uint spell)=0
virtual bool isMapWrapped() const
Definition: map_base.h:209
virtual void load(MapId mapId)
virtual bool changeLevel(int delta)
Definition: map_base.h:199
Definition: map.h:46
Definition: map_tile.h:36
Definition: map_widget.h:50
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144