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 XEEN_MAP_H
23 #define XEEN_MAP_H
24 
25 #include "common/stream.h"
26 #include "common/array.h"
27 #include "common/rect.h"
28 #include "xeen/combat.h"
29 #include "xeen/files.h"
30 #include "xeen/party.h"
31 #include "xeen/scripts.h"
32 #include "xeen/sprites.h"
33 
34 namespace Xeen {
35 
36 #define MAP_WIDTH 16
37 #define MAP_HEIGHT 16
38 #define TOTAL_SURFACES 16
39 #define INVALID_CELL 0x8888
40 
41 class XeenEngine;
42 
43 enum MonsterType {
44  MONSTER_MONSTERS = 0, MONSTER_ANIMAL = 1, MONSTER_INSECT = 2,
45  MONSTER_HUMANOID = 3, MONSTER_UNDEAD = 4, MONSTER_GOLEM = 5,
46  MONSTER_DRAGON = 6
47 };
48 
49 enum MapId {
50  XEEN_CASTLE1 = 75, XEEN_CASTLE4 = 78
51 };
52 
54 public:
55  Common::String _name;
56  int _experience;
57  int _hp;
58  int _armorClass;
59  int _speed;
60  int _numberOfAttacks;
61  int _hatesClass;
62  int _strikes;
63  int _dmgPerStrike;
64  DamageType _attackType;
65  SpecialAttack _specialAttack;
66  int _hitChance;
67  int _rangeAttack;
68  MonsterType _monsterType;
69  int _fireResistence;
70  int _electricityResistence;
71  int _coldResistence;
72  int _poisonResistence;
73  int _energyResistence;
74  int _magicResistence;
75  int _phsyicalResistence;
76  int _field29;
77  int _gold;
78  int _gems;
79  int _itemDrop;
80  bool _flying;
81  int _imageNumber;
82  int _loopAnimation;
83  int _animationEffect;
84  int _fx;
85  Common::String _attackVoc;
86 public:
87  MonsterStruct();
88  MonsterStruct(Common::String name, int experience, int hp, int accuracy,
89  int speed, int numberOfAttacks, CharacterClass hatesClass, int strikes,
90  int dmgPerStrike, DamageType attackType, SpecialAttack specialAttack,
91  int hitChance, int rangeAttack, MonsterType monsterType,
92  int fireResistence, int electricityResistence, int coldResistence,
93  int poisonResistence, int energyResistence, int magicResistence,
94  int phsyicalResistence, int field29, int gold, int gems, int itemDrop,
95  bool flying, int imageNumber, int loopAnimation, int animationEffect,
96  int field32, Common::String attackVoc);
97 
98  void synchronize(Common::SeekableReadStream &s);
99 };
100 
101 class MonsterData : public Common::Array<MonsterStruct> {
102 private:
103  void synchronize(Common::SeekableReadStream &s);
104 public:
105  MonsterData();
106 
107  void load(const Common::String &name);
108 };
109 
111 public:
112  int _north;
113  int _east;
114  int _south;
115  int _west;
116 public:
118 
119  void clear();
120 
121  void synchronize(XeenSerializer &s);
122 
123  int &operator[](int idx);
124 };
125 
127 public:
128  int _wallNoPass;
129  int _surfaceNoPass;
130  int _unlockDoor;
131  int _unlockBox;
132  int _bashDoor;
133  int _bashGrate;
134  int _bashWall;
135  int _chance2Run;
136 public:
138 
142  void synchronize(XeenSerializer &s);
143 };
144 
145 enum MazeFlags {
146  OUTFLAG_GRATE = 0x80, OUTFLAG_DRAIN = 0x20, OUTFLAG_OBJECT_EXISTS = 0x08,
147  INFLAG_INSIDE = 0x08, FLAG_AUTOEXECUTE_EVENT = 0x10,
148  RESTRICTION_ETHERIALIZE = 0x40, RESTRICTION_80 = 0x80,
149  RESTRICTION_TOWN_PORTAL = 0x100, RESTRICTION_SUPER_SHELTER = 0x200,
150  RESTRICTION_TIME_DISTORTION = 0x400, RESTRICTION_LLOYDS_BEACON = 0x800,
151  RESTRICTION_TELPORT = 0x1000, RESTRICTION_2000 = 0x2000,
152  RESTRICTION_REST = 0x4000, RESTRICTION_SAVE = 0x8000,
153 
154  FLAG_GROUND_BITS = 7
155 };
156 
157 enum MazeFlags2 { FLAG_IS_OUTDOORS = 0x8000, FLAG_IS_DARK = 0x4000 };
158 
159 enum SurfaceType {
160  SURFTYPE_DEFAULT = 0,
161  SURFTYPE_WATER = 0, SURFTYPE_DIRT = 1, SURFTYPE_GRASS = 2,
162  SURFTYPE_SNOW = 3, SURFTYPE_SWAMP = 4, SURFTYPE_LAVA = 5,
163  SURFTYPE_DESERT = 6, SURFTYPE_ROAD = 7, SURFTYPE_DWATER = 8,
164  SURFTYPE_TFLR = 9, SURFTYPE_SKY = 10, SURFTYPE_CROAD = 11,
165  SURFTYPE_SEWER = 12, SURFTYPE_CLOUD = 13, SURFTYPE_SCORCH = 14,
166  SURFTYPE_SPACE = 15
167 };
168 
171  uint _wallNorth : 4;
172  uint _wallEast : 4;
173  uint _wallSouth : 4;
174  uint _wallWest : 4;
175  } _indoors;
177  uint _surfaceId : 4; // SurfaceType, but needs to be unsigned
178  uint _iMiddle : 4;
179  uint _iTop : 4;
180  uint _iOverlay : 4;
181  } _outdoors;
182  uint16 _data;
183 };
184 
185 struct MazeCell {
186  int _flags;
187  int _surfaceId;
188  MazeCell() : _flags(0), _surfaceId(0) {}
189 };
190 
191 class MazeData {
192 public:
193  // Resource fields
194  MazeWallLayers _wallData[MAP_HEIGHT][MAP_WIDTH];
195  MazeCell _cells[MAP_HEIGHT][MAP_WIDTH];
196  int _mazeNumber;
197  SurroundingMazes _surroundingMazes;
198  int _mazeFlags;
199  int _mazeFlags2;
200  int _wallTypes[16];
201  int _surfaceTypes[16];
202  int _floorType;
203  Common::Point _runPosition;
204  MazeDifficulties _difficulties;
205  int _trapDamage;
206  int _wallKind;
207  int _tavernTips;
208  bool _seenTiles[MAP_HEIGHT][MAP_WIDTH];
209  bool _steppedOnTiles[MAP_HEIGHT][MAP_WIDTH];
210  Common::Array<bool> _objectsPresent;
211 
212  // Misc fields
213  int _mazeId;
214 public:
215  MazeData();
216 
217  void clear();
218 
222  void synchronize(XeenSerializer &s);
223 
227  void setAllTilesStepped();
228 
229  void clearCellSurfaces();
230 };
231 
232 class MobStruct {
233 public:
234  Common::Point _pos;
235  int _id;
236  Direction _direction;
237 public:
238  MobStruct();
239 
243  bool synchronize(XeenSerializer &s);
244 
248  void endOfList();
249 };
250 
251 struct MazeObject {
252 public:
253  Common::Point _position;
254  int _id;
255  int _frame;
256  int _spriteId;
257  Direction _direction;
258  bool _flipped;
259  SpriteResource *_sprites;
260 
261  MazeObject();
262 };
263 
264 struct MazeMonster {
265  Common::Point _position;
266  int _frame;
267  int _id;
268  int _spriteId;
269  bool _isAttacking;
270  DamageType _damageType;
271  int _field9;
272  int _postAttackDelay;
273  int _hp;
274  int _effect1, _effect2;
275  int _effect3;
276  SpriteResource *_sprites;
277  SpriteResource *_attackSprites;
278  MonsterStruct *_monsterData;
279 
280  MazeMonster();
281 
286  int getTextColor() const;
287 };
288 
290 public:
291  Common::Point _position;
292  int _id;
293  int _frame;
294  int _spriteId;
295  Direction _direction;
296  SpriteResource *_sprites;
297 public:
298  MazeWallItem();
299 };
300 
301 struct WallSprites {
302  SpriteResource _surfaces[TOTAL_SURFACES];
303  SpriteResource _fwl1;
304  SpriteResource _fwl2;
305  SpriteResource _fwl3;
306  SpriteResource _fwl4;
307  SpriteResource _swl;
308 };
309 
310 class Map;
311 
313  friend class Map;
314 public:
316  int _spriteId;
317  SpriteResource _sprites;
318  SpriteResource _attackSprites;
319 
320  SpriteResourceEntry() { _spriteId = -1; }
321  SpriteResourceEntry(int spriteId): _spriteId(spriteId) { }
322 
326  bool isEmpty() const { return _spriteId == -1; }
327  };
328 private:
329  XeenEngine *_vm;
330  Common::Array<SpriteResourceEntry> _monsterSprites;
331  Common::Array<SpriteResourceEntry> _monsterAttackSprites;
332  Common::Array<SpriteResourceEntry> _wallItemSprites;
333 public:
334  Common::Array<MazeObject> _objects;
335  Common::Array<MazeMonster> _monsters;
336  Common::Array<MazeWallItem> _wallItems;
337  Common::Array<SpriteResourceEntry> _objectSprites;
338 public:
340 
344  void synchronize(XeenSerializer &s, MonsterData &monsterData);
345 
349  void clearMonsterSprites();
350 
354  void addMonsterSprites(MazeMonster &monster);
355 };
356 
357 class HeadData {
358 public:
359  struct HeadEntry {
360  int _left;
361  int _right;
362  };
363  HeadEntry _data[MAP_HEIGHT][MAP_WIDTH];
364 public:
365  HeadData();
366 
367  void synchronize(Common::SeekableReadStream &s);
368 
369  HeadEntry *operator[](int y) { return &_data[y][0]; }
370 };
371 
372 struct AnimationFrame { int _front, _left, _back, _right; };
373 struct AnimationFlipped { bool _front, _left, _back, _right; };
375  union {
376  AnimationFrame _positions;
377  int _frames[4];
378  } _frame1;
379  union {
380  AnimationFlipped _positions;
381  bool _flags[4];
382  } _flipped;
383  union {
384  AnimationFrame _positions;
385  int _frames[4];
386  } _frame2;
387 
391  void synchronize(Common::SeekableReadStream &s);
392 };
393 
394 class AnimationInfo : public Common::Array<AnimationEntry> {
395 public:
399  void synchronize(Common::SeekableReadStream &s);
400 
404  void load(const Common::String &name);
405 };
406 
407 class Map {
408 private:
409  XeenEngine *_vm;
410  MazeData _mazeData[9];
411  SpriteResource _wallPicSprites;
412  int _sidePictures;
413  int _sideObjects;
414  int _sideMonsters;
415  int _mazeDataIndex;
416 
420  void loadEvents(int mapId, int ccNum);
421 
425  void saveEvents();
426 
430  void saveMonsters();
431 
435  void saveMap();
436 
441  void findMap(int mapId = -1);
442 public:
443  Common::String _mazeName;
444  bool _isOutdoors;
445  MonsterObjectData _mobData;
446  MonsterData _monsterData;
447  MazeEvents _events;
448  HeadData _headData;
449  AnimationInfo _animationInfo;
450  SpriteResource _skySprites[2];
451  SpriteResource _groundSprites;
452  SpriteResource _tileSprites;
453  SpriteResource _surfaceSprites[TOTAL_SURFACES];
454  WallSprites _wallSprites;
455  bool _currentGrateUnlocked;
456  bool _currentCantRest;
457  bool _currentIsDrain;
458  bool _currentIsEvent;
459  int _currentSky;
460  int _currentMonsterFlags;
461  int _currentWall;
462  int _currentTile;
463  int _currentSurfaceId;
464  bool _currentSteppedOn;
465  int _loadCcNum;
466  int _sideTownPortal;
467 public:
468  Map(XeenEngine *vm);
469 
473  void load(int mapId);
474 
475  int mazeLookup(const Common::Point &pt, int layerShift, int wallMask = 0xf);
476 
477  void cellFlagLookup(const Common::Point &pt);
478 
482  void setCellSurfaceFlags(const Common::Point &pt, int bits);
483 
487  void setWall(const Common::Point &pt, Direction dir, int v);
488 
492  void saveMaze();
493 
498  void clearMaze();
499 
504  int getCell(int idx);
505 
509  MazeData &mazeData() { return _mazeData[0]; }
510 
514  const MazeData *mazeDataSurrounding() { return _mazeData; }
515 
519  MazeData &mazeDataCurrent() { return _mazeData[_mazeDataIndex]; }
520 
524  void loadSky();
525 
531  void getNewMaze();
532 
538  static Common::String getMazeName(int mapId, int ccNum = -1);
539 };
540 
541 } // End of namespace Xeen
542 
543 #endif /* XEEN_MAP_H */
Definition: map.h:232
Definition: map.h:53
Definition: str.h:59
Definition: map.h:315
Definition: map.h:289
MazeData & mazeDataCurrent()
Definition: map.h:519
Definition: array.h:52
Definition: sprites.h:48
Definition: map.h:301
Definition: map.h:101
Definition: map.h:359
Definition: map.h:126
Definition: stream.h:652
Definition: map.h:372
Definition: map.h:312
Definition: map.h:191
Definition: map.h:407
Definition: files.h:244
Definition: map.h:169
Definition: map.h:394
Definition: map.h:264
Definition: map.h:374
bool isEmpty() const
Definition: map.h:326
Definition: rect.h:45
Definition: map.h:357
Definition: map.h:373
Definition: map.h:251
Definition: map.h:110
const MazeData * mazeDataSurrounding()
Definition: map.h:514
Definition: xeen.h:100
Definition: map.h:185
Definition: scripts.h:170
MazeData & mazeData()
Definition: map.h:509
Definition: character.h:33