ScummVM API documentation
map_dungeon.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 ULTIMA2_DATA_MAP_DUNGEON_H
23#define ULTIMA2_DATA_MAP_DUNGEON_H
24
25#include "common/scummsys.h"
26#include "common/serializer.h"
27
28namespace Ultima {
29namespace Ultima2 {
30namespace Data {
31
32constexpr int DUNGEON_WIDTH = 16;
33constexpr int DUNGEON_HEIGHT = 16;
34constexpr int DUNGEON_LEVELS = 16;
35
36enum DungeonTerrain {
37 DUNGEON_FLOOR = 0x00,
38 DUNGEON_LADDER_UP = 0x10,
39 DUNGEON_LADDER_DOWN = 0x20,
40 DUNGEON_LADDER_UP_DOWN = 0x30,
41 DUNGEON_CHEST = 0x40,
42 DUNGEON_WALL = 0x80,
43 DUNGEON_DOOR = 0xC0,
44 DUNGEON_SECRET_DOOR = 0xE0
45};
46
54struct MapDungeon {
55 byte _cells[DUNGEON_LEVELS][DUNGEON_HEIGHT][DUNGEON_WIDTH] = {};
56
57 void load(int mapEra, int mapType);
58
59 void synchronize(Common::Serializer &s) {
60 s.syncBytes(&_cells[0][0][0], sizeof(_cells));
61 }
62
69 byte &cell(int level, int x, int y) {
70 byte row = (byte)y;
71 int carry = 0;
72 for (int i = 0; i < 4; ++i) {
73 carry = row >> 7;
74 row = (byte)(row << 1);
75 }
76
77 int index = (row + (byte)x + carry) & 0xFF;
78 return _cells[level & 0xF][index / DUNGEON_WIDTH][index % DUNGEON_WIDTH];
79 }
80
81 DungeonTerrain terrainAt(int level, int x, int y) const {
82 return (DungeonTerrain)(_cells[level][y][x] & 0xF0);
83 }
84 bool hasMonsterAt(int level, int x, int y) const {
85 return (_cells[level][y][x] & 7) != 0;
86 }
87};
88
89} // namespace Data
90} // namespace Ultima2
91} // namespace Ultima
92
93#endif
Definition: serializer.h:80
void syncBytes(byte *buf, uint32 size, Version minVersion=0, Version maxVersion=kLastVersion)
Definition: serializer.h:205
Definition: map_dungeon.h:54
byte & cell(int level, int x, int y)
Definition: map_dungeon.h:69