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 ULTIMA1_DATA_MAP_H
23#define ULTIMA1_DATA_MAP_H
24
25#include "common/array.h"
26#include "common/rect.h"
27#include "common/serializer.h"
28#include "graphics/managed_surface.h"
29#include "ultima/ultima1/data/tiles.h"
30
31namespace Ultima {
32namespace Ultima1 {
33namespace Data {
34
35constexpr int OVERWORLD_WIDTH = 168;
36constexpr int OVERWORLD_HEIGHT = 156;
37constexpr int OVERWORLD_SIZE = OVERWORLD_WIDTH * OVERWORLD_HEIGHT;
38constexpr int OVERWORLD_VISIBLE_WIDTH = 19;
39constexpr int OVERWORLD_VISIBLE_HEIGHT = 9;
40constexpr int OVERWORLD_VISIBLE_CENTER_X = 9;
41constexpr int OVERWORLD_VISIBLE_CENTER_Y = 4;
42
43constexpr int CITY_WIDTH = 38;
44constexpr int CITY_HEIGHT = 18;
45constexpr int CITY_SIZE = CITY_WIDTH * CITY_HEIGHT;
46
47constexpr int MONDAIN_WIDTH = 19;
48constexpr int MONDAIN_HEIGHT = 9;
49
50// Where the gem Mondain is creating sits in his room
51constexpr int MONDAIN_GEM_X = 14;
52constexpr int MONDAIN_GEM_Y = 4;
53
54constexpr int LOCATION_COUNT = 84;
55
56enum {
57 MAP_OVERWORLD = 0,
58 MAP_SPACE = 90,
59 MAP_MONDAIN = 91
60};
61
62enum Direction {
63 DIR_LEFT = 1, DIR_RIGHT = 2, DIR_UP = 3, DIR_DOWN = 4, DIR_UNSPECIFIED = -1
64};
65
66enum MapType {
67 MAPTYPE_OVERWORLD = 0,
68 MAPTYPE_CITY = 1,
69 MAPTYPE_CASTLE = 2,
70 MAPTYPE_DUNGEON = 3,
71 MAPTYPE_SPACE = 4,
72 MAPTYPE_MONDAIN = 5
73};
74
75typedef Common::Array< Common::Array<byte> > MapTiles;
76
77extern const char *DIRECTION_NAMES[5];
78extern const char *SPACE_DIRECTION_NAMES[5];
79extern const char *LOCATION_NAMES[LOCATION_COUNT];
80extern const char *CONTINENT_NAMES[4];
81
82struct Map {
83private:
84 Common::Array<byte> _overworldMap; // Cached overworld map data
85 Common::Array<byte> _cityMap[10]; // Cached city/castle/town maps
86 byte _mondainMap[MONDAIN_HEIGHT][MONDAIN_WIDTH] = {}; // Cached Mondain encounter map
87
88 MapTiles _mapTiles; // Visible on-screen tiles
89 int _mapWidth = 0, _mapHeight = 0; // Map width/height
90 byte _outsideMapTile = 0xff; // -1 for wrapping, else tile for outside map boundaries
91
95 class Row {
96 private:
97 Map *_owner = nullptr;
98 byte *_data = nullptr;
99
100 public:
101 Row() {}
102 Row(Map *owner, byte *data) : _owner(owner), _data(data) {}
103
104 // Give access to the byte for a column within the row. Returns a
105 // mutable reference (even though the method is const - constness
106 // here is about the Row's own members, not the mapped bytes) so
107 // map[y][x] = value can be used to modify the map's contents
108 byte &operator[](int x) const {
109 // Handle when the Y is already outside the map, or X is outside map
110 if (!_data || (_owner->_outsideMapTile != 0xff && (x < 0 || x >= _owner->_mapWidth)))
111 return _owner->_outsideMapTile;
112
113 // Return cell within the row
114 if (x < 0)
115 return _data[_owner->_mapWidth + x];
116 return _data[x % _owner->_mapWidth];
117 }
118 };
119 friend class Row;
120
121 Common::Array<Row> _mapRows; // Used for array operator getting map contents
122 Graphics::ManagedSurface _overworldTiles[OVERWORLD_TILES_COUNT];
123 Graphics::ManagedSurface _cityTiles[CITY_TILES_COUNT];
124 Graphics::ManagedSurface _mondainTiles[MONDAIN_TILES_COUNT + 2];
125 Graphics::ManagedSurface _spaceShipTiles[SPACE_SHIP_TILES_COUNT];
126 Graphics::ManagedSurface _enemyFighterTiles[SPACE_ENEMY_TILES_COUNT];
127
131 void loadDungeonMap();
132
133public:
134 byte _tilePlayerCenter = 0;
135 byte _tilePlayerUp = 0, _tilePlayerDown = 0,
136 _tilePlayerLeft = 0, _tilePlayerRight = 0;
137 int _woodsCount = 0, _grassCount = 0, _waterCount = 0; // Tiles surrounding entered locations
138 bool _isLordBritishCastle = false;
139 int _mapStyle = 0;
140 int _mapType = MAPTYPE_OVERWORLD;
141 int _tavernCtr = 0;
142 int _castleNum = 0, _castleNum2 = 0;
143 Graphics::ManagedSurface *_tiles = nullptr;
144
145public:
149 void init();
150
155
160 void load(int mapNum);
161
167
175
179 int width() const {
180 return _mapWidth;
181 }
182
186 int height() const {
187 return _mapHeight;
188 }
189
194 return _tiles;
195 }
196
198 return _tiles;
199 }
200
205 return _spaceShipTiles;
206 }
207
212 return _enemyFighterTiles;
213 }
214
218 const Row &operator[](int y) const {
219 if (_outsideMapTile != 0xff && (y < 0 || y >= _mapHeight))
220 // In a row outside the map
221 return _mapRows[_mapHeight];
222
223 // Return valid row
224 if (y < 0)
225 return _mapRows[_mapHeight + y];
226 return _mapRows[y % _mapHeight];
227 }
228
235 int getMapTile(int x, int y) const;
236
240 int getTileAt(int x, int y, int creatureIndex = 1) const;
241
247 int getOverworldTileAt(int x, int y) const;
248
253 int wrapOverworldX(int x) const;
254 int wrapOverworldY(int y) const;
255
261
265 int getContinentAt(int x, int y) const;
266 int getContinentAt(const Common::Point &pt) const {
267 return getContinentAt(pt.x, pt.y);
268 }
269
273 int getLocationAt(int x, int y) const;
274 int getLocationAt(const Common::Point &pt) const {
275 return getLocationAt(pt.x, pt.y);
276 }
277
282 bool mapRangeCheckX(int xp) const;
283
288 bool mapRangeCheckY(int yp) const;
289};
290
291} // namespace Data
292} // namespace Ultima1
293} // namespace Ultima
294
295#endif
Definition: array.h:52
Definition: serializer.h:80
Definition: managed_surface.h:51
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: map.h:82
const Graphics::ManagedSurface * tiles() const
Definition: map.h:193
bool mapRangeCheckX(int xp) const
int getMapTile(int x, int y) const
int getOverworldTileAt(int x, int y) const
bool mapRangeCheckY(int yp) const
int width() const
Definition: map.h:179
int getContinentAt(int x, int y) const
const Graphics::ManagedSurface * spaceShipTiles() const
Definition: map.h:204
const Row & operator[](int y) const
Definition: map.h:218
int getTileAt(int x, int y, int creatureIndex=1) const
int getLocationAt(int x, int y) const
void synchronize(Common::Serializer &s)
const Graphics::ManagedSurface * enemyFighterTiles() const
Definition: map.h:211
int height() const
Definition: map.h:186
int wrapOverworldX(int x) const