1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef XEEN_MAP_H
#define XEEN_MAP_H
#include "common/stream.h"
#include "common/array.h"
#include "common/rect.h"
#include "xeen/combat.h"
#include "xeen/files.h"
#include "xeen/party.h"
#include "xeen/scripts.h"
#include "xeen/sprites.h"
namespace Xeen {
#define MAP_WIDTH 16
#define MAP_HEIGHT 16
#define TOTAL_SURFACES 16
#define INVALID_CELL 0x8888
class XeenEngine;
enum MonsterType {
MONSTER_0 = 0, MONSTER_ANIMAL = 1, MONSTER_INSECT = 2,
MONSTER_HUMANOID = 3, MONSTER_UNDEAD = 4, MONSTER_GOLEM = 5,
MONSTER_DRAGON = 6
};
class MonsterStruct {
public:
Common::String _name;
int _experience;
int _hp;
int _armorClass;
int _speed;
int _numberOfAttacks;
int _hatesClass;
int _strikes;
int _dmgPerStrike;
DamageType _attackType;
SpecialAttack _specialAttack;
int _hitChance;
int _rangeAttack;
MonsterType _monsterType;
int _fireResistence;
int _electricityResistence;
int _coldResistence;
int _poisonResistence;
int _energyResistence;
int _magicResistence;
int _phsyicalResistence;
int _field29;
int _gold;
int _gems;
int _itemDrop;
bool _flying;
int _imageNumber;
int _loopAnimation;
int _animationEffect;
int _fx;
Common::String _attackVoc;
public:
MonsterStruct();
MonsterStruct(Common::String name, int experience, int hp, int accuracy,
int speed, int numberOfAttacks, CharacterClass hatesClass, int strikes,
int dmgPerStrike, DamageType attackType, SpecialAttack specialAttack,
int hitChance, int rangeAttack, MonsterType monsterType,
int fireResistence, int electricityResistence, int coldResistence,
int poisonResistence, int energyResistence, int magicResistence,
int phsyicalResistence, int field29, int gold, int gems, int itemDrop,
bool flying, int imageNumber, int loopAnimation, int animationEffect,
int field32, Common::String attackVoc);
void synchronize(Common::SeekableReadStream &s);
};
class MonsterData : public Common::Array<MonsterStruct> {
private:
void synchronize(Common::SeekableReadStream &s);
public:
MonsterData();
void load(const Common::String &name);
};
class SurroundingMazes {
public:
int _north;
int _east;
int _south;
int _west;
public:
SurroundingMazes();
void clear();
void synchronize(XeenSerializer &s);
int &operator[](int idx);
};
class MazeDifficulties {
public:
int _wallNoPass;
int _surfaceNoPass;
int _unlockDoor;
int _unlockBox;
int _bashDoor;
int _bashGrate;
int _bashWall;
int _chance2Run;
public:
MazeDifficulties();
/**
* Synchronizes data for the item
*/
void synchronize(XeenSerializer &s);
};
enum MazeFlags {
OUTFLAG_GRATE = 0x80, OUTFLAG_DRAIN = 0x20, OUTFLAG_OBJECT_EXISTS = 0x08,
INFLAG_INSIDE = 0x08, FLAG_AUTOEXECUTE_EVENT = 0x10,
RESTRICTION_ETHERIALIZE = 0x40, RESTRICTION_80 = 0x80,
RESTRICTION_TOWN_PORTAL = 0x100, RESTRICTION_SUPER_SHELTER = 0x200,
RESTRICTION_TIME_DISTORTION = 0x400, RESTRICTION_LLOYDS_BEACON = 0x800,
RESTRICTION_TELPORT = 0x1000, RESTRICTION_2000 = 0x2000,
RESTRICTION_REST = 0x4000, RESTRICTION_SAVE = 0x8000,
FLAG_GROUND_BITS = 7
};
enum MazeFlags2 { FLAG_IS_OUTDOORS = 0x8000, FLAG_IS_DARK = 0x4000 };
enum SurfaceType {
SURFTYPE_DEFAULT = 0,
SURFTYPE_WATER = 0, SURFTYPE_DIRT = 1, SURFTYPE_GRASS = 2,
SURFTYPE_SNOW = 3, SURFTYPE_SWAMP = 4, SURFTYPE_LAVA = 5,
SURFTYPE_DESERT = 6, SURFTYPE_ROAD = 7, SURFTYPE_DWATER = 8,
SURFTYPE_TFLR = 9, SURFTYPE_SKY = 10, SURFTYPE_CROAD = 11,
SURFTYPE_SEWER = 12, SURFTYPE_CLOUD = 13, SURFTYPE_SCORCH = 14,
SURFTYPE_SPACE = 15
};
union MazeWallLayers {
struct MazeWallIndoors {
int _wallNorth : 4;
int _wallEast : 4;
int _wallSouth : 4;
int _wallWest : 4;
} _indoors;
struct MazeWallOutdoors {
SurfaceType _surfaceId : 4;
int _iMiddle : 4;
int _iTop : 4;
int _iOverlay : 4;
} _outdoors;
uint16 _data;
};
struct MazeCell {
int _flags;
int _surfaceId;
MazeCell() : _flags(0), _surfaceId(0) {}
};
class MazeData {
public:
// Resource fields
MazeWallLayers _wallData[MAP_HEIGHT][MAP_WIDTH];
MazeCell _cells[MAP_HEIGHT][MAP_WIDTH];
int _mazeNumber;
SurroundingMazes _surroundingMazes;
int _mazeFlags;
int _mazeFlags2;
int _wallTypes[16];
int _surfaceTypes[16];
int _floorType;
Common::Point _runPosition;
MazeDifficulties _difficulties;
int _trapDamage;
int _wallKind;
int _tavernTips;
bool _seenTiles[MAP_HEIGHT][MAP_WIDTH];
bool _steppedOnTiles[MAP_HEIGHT][MAP_WIDTH];
// Misc fields
int _mazeId;
public:
MazeData();
void clear();
/**
* Synchronize data for the maze data
*/
void synchronize(XeenSerializer &s);
/**
* Flags all tiles for the map as having been stepped on
*/
void setAllTilesStepped();
void clearCellSurfaces();
};
class MobStruct {
public:
Common::Point _pos;
int _id;
Direction _direction;
public:
MobStruct();
/**
* Synchronizes the data for the item
*/
bool synchronize(XeenSerializer &s);
/**
* Sets up the entry as an end of list marker
*/
void endOfList();
};
struct MazeObject {
public:
Common::Point _position;
int _id;
int _frame;
int _spriteId;
Direction _direction;
bool _flipped;
SpriteResource *_sprites;
MazeObject();
};
struct MazeMonster {
Common::Point _position;
int _frame;
int _id;
int _spriteId;
bool _isAttacking;
DamageType _damageType;
int _field9;
int _postAttackDelay;
int _hp;
int _effect1, _effect2;
int _effect3;
SpriteResource *_sprites;
SpriteResource *_attackSprites;
MonsterStruct *_monsterData;
MazeMonster();
/**
* Return the text color to use when displaying the monster's name in combat
* to indicate how damaged they are
*/
int getTextColor() const;
};
class MazeWallItem {
public:
Common::Point _position;
int _id;
int _frame;
int _spriteId;
Direction _direction;
SpriteResource *_sprites;
public:
MazeWallItem();
};
struct WallSprites {
SpriteResource _surfaces[TOTAL_SURFACES];
SpriteResource _fwl1;
SpriteResource _fwl2;
SpriteResource _fwl3;
SpriteResource _fwl4;
SpriteResource _swl;
};
class Map;
class MonsterObjectData {
friend class Map;
public:
struct SpriteResourceEntry {
int _spriteId;
SpriteResource _sprites;
SpriteResource _attackSprites;
SpriteResourceEntry() { _spriteId = -1; }
SpriteResourceEntry(int spriteId): _spriteId(spriteId) { }
};
private:
XeenEngine *_vm;
Common::Array<SpriteResourceEntry> _objectSprites;
Common::Array<SpriteResourceEntry> _monsterSprites;
Common::Array<SpriteResourceEntry> _monsterAttackSprites;
Common::Array<SpriteResourceEntry> _wallItemSprites;
public:
Common::Array<MazeObject> _objects;
Common::Array<MazeMonster> _monsters;
Common::Array<MazeWallItem> _wallItems;
public:
MonsterObjectData(XeenEngine *vm);
/**
* Synchronizes the data
*/
void synchronize(XeenSerializer &s, MonsterData &monsterData);
/**
* Clears the current list of monster sprites
*/
void clearMonsterSprites();
/**
* Load the normal and attack sprites for a given monster
*/
void addMonsterSprites(MazeMonster &monster);
};
class HeadData {
public:
struct HeadEntry {
int _left;
int _right;
};
HeadEntry _data[MAP_HEIGHT][MAP_WIDTH];
public:
HeadData();
void synchronize(Common::SeekableReadStream &s);
HeadEntry *operator[](int y) { return &_data[y][0]; }
};
struct AnimationFrame { int _front, _left, _back, _right; };
struct AnimationFlipped { bool _front, _left, _back, _right; };
struct AnimationEntry {
union {
AnimationFrame _positions;
int _frames[4];
} _frame1;
union {
AnimationFlipped _positions;
bool _flags[4];
} _flipped;
union {
AnimationFrame _positions;
int _frames[4];
} _frame2;
/**
* Synchronize data for an animation entry
*/
void synchronize(Common::SeekableReadStream &s);
};
class AnimationInfo : public Common::Array<AnimationEntry> {
public:
/**
* Synchronize data for object animations within the game
*/
void synchronize(Common::SeekableReadStream &s);
/**
* Load the animation info objects in the game
*/
void load(const Common::String &name);
};
class Map {
private:
XeenEngine *_vm;
MazeData _mazeData[9];
SpriteResource _wallPicSprites;
int _sidePictures;
int _sideObjects;
int _sideMonsters;
int _sideMusic;
int _mazeDataIndex;
/**
* Load the events for a new map
*/
void loadEvents(int mapId);
/**
* Save the events for a map
*/
void saveEvents();
/**
* Save the monster data for a map
*/
void saveMonsters();
/**
* Save the map data
*/
void saveMap();
/**
* Finds a map in the array that contains the currently active and the surrounding
* maps in the eight cardinal directions
*/
void findMap(int mapId = -1);
public:
Common::String _mazeName;
bool _isOutdoors;
MonsterObjectData _mobData;
MonsterData _monsterData;
MazeEvents _events;
HeadData _headData;
AnimationInfo _animationInfo;
SpriteResource _skySprites[2];
SpriteResource _groundSprites;
SpriteResource _tileSprites;
SpriteResource _surfaceSprites[TOTAL_SURFACES];
WallSprites _wallSprites;
bool _currentGrateUnlocked;
bool _currentCantRest;
bool _currentIsDrain;
bool _currentIsEvent;
int _currentSky;
int _currentMonsterFlags;
int _currentWall;
int _currentTile;
int _currentSurfaceId;
bool _currentSteppedOn;
int _loadCcNum;
int _sideTownPortal;
public:
Map(XeenEngine *vm);
/**
* Loads a specified map
*/
void load(int mapId);
int mazeLookup(const Common::Point &pt, int layerShift, int wallMask = 0xf);
void cellFlagLookup(const Common::Point &pt);
/**
* Sets the surface flags for a given position
*/
void setCellSurfaceFlags(const Common::Point &pt, int bits);
/**
* Sets the value for the wall in a given direction from a given point
*/
void setWall(const Common::Point &pt, Direction dir, int v);
/**
* Saves all changeable maze data to the in-memory save state
*/
void saveMaze();
/**
* Clears the current maze. This is used during savegame loads so that
* the previous games maze data isn't saved as the new map is loaded
*/
void clearMaze();
/**
* Gets the data for a map position at one of the relative indexes
* surrounding the current position
*/
int getCell(int idx);
/**
* Returns the data for the primary active map
*/
MazeData &mazeData() { return _mazeData[0]; }
/**
* Returns the data for the currently indexed map
*/
MazeData &mazeDataCurrent() { return _mazeData[_mazeDataIndex]; }
/**
* Loads the sprites needed for rendering the skyline
*/
void loadSky();
/**
* Tests the current position, and if it's moved beyond the valid (0,0) to (15,15)
* range for a map, loads in the correct surrounding map, and adjusts the
* position to the relative position on the new map
*/
void getNewMaze();
/**
* Return the name of a specified maze
* @param mapId Map Id
* @param ccNum Cc file number. If -1, uses the current C
*/
static Common::String getMazeName(int mapId, int ccNum = -1);
};
} // End of namespace Xeen
#endif /* XEEN_MAP_H */
|