ScummVM API documentation
isomap.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// Isometric level module - private header
23
24#ifndef SAGA_ISOMAP_H
25#define SAGA_ISOMAP_H
26
27#include "saga/actor.h"
28
29namespace Saga {
30
31#define ITE_OBJ_MAP 14
32
33#define SAGA_ISOTILE_WIDTH 32
34#define SAGA_ISOTILE_BASEHEIGHT 15
35#define SAGA_TILE_NOMINAL_H 16
36#define SAGA_MAX_TILE_H 64
37
38#define SAGA_TILEPLATFORMDATA_LEN 136
39#define SAGA_PLATFORM_W 8
40#define SAGA_MAX_PLATFORM_H 16
41
42#define SAGA_TILEMAP_LEN 514
43#define SAGA_TILEMAP_W 16
44#define SAGA_TILEMAP_H 16
45
46#define SAGA_METATILEDATA_LEN 36
47
48#define SAGA_MULTI_TILE (1 << 15)
49
50#define SAGA_SCROLL_LIMIT_X1 32
51#define SAGA_SCROLL_LIMIT_X2 64
52#define SAGA_SCROLL_LIMIT_Y1 8
53#define SAGA_SCROLL_LIMIT_Y2 32
54
55#define SAGA_DRAGON_SEARCH_CENTER 24
56#define SAGA_DRAGON_SEARCH_DIAMETER (SAGA_DRAGON_SEARCH_CENTER * 2)
57
58#define SAGA_SEARCH_CENTER 15
59#define SAGA_SEARCH_DIAMETER (SAGA_SEARCH_CENTER * 2)
60#define SAGA_SEARCH_QUEUE_SIZE 128
61#define SAGA_IMPASSABLE ((1 << kTerrBlock) | (1 << kTerrWater))
62
63#define SAGA_STRAIGHT_NORMAL_COST 4
64#define SAGA_DIAG_NORMAL_COST 6
65
66#define SAGA_STRAIGHT_EASY_COST 2
67#define SAGA_DIAG_EASY_COST 3
68
69#define SAGA_STRAIGHT_HARD_COST 9
70#define SAGA_DIAG_HARD_COST 10
71#define SAGA_MAX_PATH_DIRECTIONS 256
72
73enum TerrainTypes {
74 kTerrNone = 0,
75 kTerrPath = 1,
76 kTerrRough = 2,
77 kTerrBlock = 3,
78 kTerrWater = 4,
79 kTerrLast = 5
80};
81
82enum TileMapEdgeType {
83 kEdgeTypeBlack = 0,
84 kEdgeTypeFill0 = 1,
85 kEdgeTypeFill1 = 2,
86 kEdgeTypeRpt = 3,
87 kEdgeTypeWrap = 4
88};
89
91 byte height;
92 size_t tileSize;
93 int8 attributes;
94 byte *tilePointer;
95 uint16 terrainMask;
96 byte FGDBGDAttr;
97 int8 getMaskRule() const {
98 return attributes & 0x0F;
99 }
100 byte getFGDAttr() const {
101 return FGDBGDAttr >> 4;
102 }
103 byte getBGDAttr() const {
104 return FGDBGDAttr & 0x0F;
105 }
106 uint16 getFGDMask() const {
107 return 1 << getFGDAttr();
108 }
109 uint16 getBGDMask() const {
110 return 1 << getBGDAttr();
111 }
112};
113
115 int16 metaTile;
116 int16 height;
117 int16 highestPixel;
118 byte vBits;
119 byte uBits;
120 int16 tiles[SAGA_PLATFORM_W][SAGA_PLATFORM_W];
121};
122
124 byte edgeType;
125 int16 tilePlatforms[SAGA_TILEMAP_W][SAGA_TILEMAP_H];
126};
127
129 uint16 highestPlatform;
130 uint16 highestPixel;
131 int16 stack[SAGA_MAX_PLATFORM_H];
132};
133
135 int16 offset;
136 byte u;
137 byte v;
138 byte h;
139 byte uSize;
140 byte vSize;
141 byte numStates;
142 byte currentState;
143};
144
145
146
147
148
149class IsoMap {
150public:
151 IsoMap(SagaEngine *vm);
152 ~IsoMap() {
153 }
154 void loadImages(const ByteArray &resourceData);
155 void loadMap(const ByteArray &resourceData);
156 void loadPlatforms(const ByteArray &resourceData);
157 void loadMetaTiles(const ByteArray &resourceData);
158 void loadMulti(const ByteArray &resourceData);
159 void clear();
160 void draw();
161 void drawSprite(SpriteList &spriteList, int spriteNumber, const Location &location, const Point &screenPosition, int scale);
162 void adjustScroll(bool jump);
163 void tileCoordsToScreenPoint(const Location &location, Point &position) {
164 position.x = location.u() - location.v() + (128 * SAGA_TILEMAP_W) - _viewScroll.x + 16;
165 position.y = -(location.uv() >> 1) + (128 * SAGA_TILEMAP_W) - _viewScroll.y - location.z;
166 }
167 void screenPointToTileCoords(const Point &position, Location &location);
168 void placeOnTileMap(const Location &start, Location &result, int16 distance, uint16 direction);
169 void findDragonTilePath(ActorData* actor, const Location &start, const Location &end, uint16 initialDirection);
170 bool findNearestChasm(int16 &u0, int16 &v0, uint16 &direction);
171 void findTilePath(ActorData* actor, const Location &start, const Location &end);
172 bool nextTileTarget(ActorData* actor);
173 void setTileDoorState(int doorNumber, int doorState);
174 Point getMapPosition() { return _mapPosition; }
175 void setMapPosition(int x, int y);
176 int16 getTileIndex(int16 u, int16 v, int16 z);
177
178private:
179 void drawTiles(const Location *location);
180 void drawMetaTile(uint16 metaTileIndex, const Point &point, int16 absU, int16 absV);
181 void drawSpriteMetaTile(uint16 metaTileIndex, const Point &point, Location &location, int16 absU, int16 absV);
182 void drawPlatform(uint16 platformIndex, const Point &point, int16 absU, int16 absV, int16 absH);
183 void drawSpritePlatform(uint16 platformIndex, const Point &point, const Location &location, int16 absU, int16 absV, int16 absH);
184 void drawTile(uint16 tileIndex, const Point &point, const Location *location);
185 int16 smoothSlide(int16 value, int16 min, int16 max) {
186 if (value < min) {
187 if (value < min - 100 || value > min - 4) {
188 value = min;
189 } else {
190 value += 4;
191 }
192 } else {
193 if (value > max) {
194 if (value > max + 100 || value < max + 4) {
195 value = max;
196 } else {
197 value -= 4;
198 }
199 }
200 }
201 return value;
202 }
203 int16 findMulti(int16 tileIndex, int16 absU, int16 absV, int16 absH);
204 void pushPoint(int16 u, int16 v, uint16 cost, uint16 direction);
205 void pushDragonPoint(int16 u, int16 v, uint16 direction);
206 bool checkDragonPoint(int16 u, int16 v, uint16 direction);
207 void testPossibleDirections(int16 u, int16 v, uint16 terraComp[8], int skipCenter);
208 IsoTileData *getTile(int16 u, int16 v, int16 z);
209
210
211 ByteArray _tileData;
212 Common::Array<IsoTileData> _tilesTable;
213
214 Common::Array<TilePlatformData> _tilePlatformList;
215 Common::Array<MetaTileData> _metaTileList;
216
218 Common::Array<int16> _multiTableData;
219
220 TileMapData _tileMap;
221
222 Point _mapPosition;
223
224// path finding stuff
225 uint16 _platformHeight;
226
227 struct DragonPathCell {
228 uint8 visited:1,direction:3;
229 };
230 struct DragonTilePoint {
231 int8 u, v;
232 uint8 direction:4;
233 };
234 struct PathCell {
235 uint16 visited:1,direction:3,cost:12;
236 };
237
238public:
239 struct TilePoint {
240 int8 u, v;
241 uint16 direction:4,cost:12;
242 };
243
244private:
245 struct DragonSearchArray {
246 DragonPathCell cell[SAGA_DRAGON_SEARCH_DIAMETER][SAGA_DRAGON_SEARCH_DIAMETER];
247 DragonTilePoint queue[SAGA_SEARCH_QUEUE_SIZE];
248 DragonTilePoint *getQueue(uint16 i) {
249 assert(i < SAGA_SEARCH_QUEUE_SIZE);
250 return &queue[i];
251 }
252 DragonPathCell *getPathCell(uint16 u, uint16 v) {
253 assert((u < SAGA_DRAGON_SEARCH_DIAMETER) && (v < SAGA_DRAGON_SEARCH_DIAMETER));
254 return &cell[u][v];
255 }
256 };
257 struct SearchArray {
258 PathCell cell[SAGA_SEARCH_DIAMETER][SAGA_SEARCH_DIAMETER];
259 TilePoint queue[SAGA_SEARCH_QUEUE_SIZE];
260 TilePoint *getQueue(uint16 i) {
261 assert(i < SAGA_SEARCH_QUEUE_SIZE);
262 return &queue[i];
263 }
264 PathCell *getPathCell(uint16 u, uint16 v) {
265 assert((u < SAGA_SEARCH_DIAMETER) && (v < SAGA_SEARCH_DIAMETER));
266 return &cell[u][v];
267 }
268 };
269
270 int16 _queueCount;
271 int16 _readCount;
272 SearchArray _searchArray;
273 DragonSearchArray _dragonSearchArray;
274 byte _pathDirections[SAGA_MAX_PATH_DIRECTIONS];
275
276
277 int _viewDiff;
278 Point _viewScroll;
279 Rect _tileClip;
280
281 SagaEngine *_vm;
282};
283
284} // End of namespace Saga
285
286#endif
Definition: actor.h:345
Definition: saga.h:464
Definition: isomap.h:149
Definition: saga.h:497
Definition: actor.h:34
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: display_client.h:58
Definition: isomap.h:239
Definition: isomap.h:90
Definition: actor.h:199
Definition: isomap.h:128
Definition: isomap.h:134
Definition: isomap.h:123
Definition: isomap.h:114