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