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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_MAP_H
29 #define GOB_MAP_H
30 
31 #include "gob/mult.h"
32 
33 namespace Gob {
34 
35 enum RelativeDirection {
36  kRelDirNone = 0 ,
37 
38  kRelDirLeft = (1 << 0),
39  kRelDirUp = (1 << 1),
40  kRelDirRight = (1 << 2),
41  kRelDirDown = (1 << 3),
42 
43  kRelDirLeftUp = kRelDirLeft | kRelDirUp,
44  kRelDirLeftDown = kRelDirLeft | kRelDirDown,
45  kRelDirRightUp = kRelDirRight | kRelDirUp,
46  kRelDirRightDown = kRelDirRight | kRelDirDown
47 };
48 
49 // The same numeric values are also used for the arrow keys.
50 enum Direction {
51  kDirNone = 0x0000,
52  kDirNW = 0x4700,
53  kDirN = 0x4800,
54  kDirNE = 0x4900,
55  kDirW = 0x4B00,
56  kDirE = 0x4D00,
57  kDirSW = 0x4F00,
58  kDirS = 0x5000,
59  kDirSE = 0x5100
60 };
61 
62 struct WayPoint {
63  int16 x;
64  int16 y;
65  int16 notWalkable;
66 };
67 
68 struct ItemPos {
69  int8 x;
70  int8 y;
71  int8 orient;
72 };
73 
74 
75 class Map {
76 public:
77  int16 _nearestWayPoint;
78  int16 _nearestDest;
79 
80  int16 _curGoblinX;
81  int16 _curGoblinY;
82  int16 _destX;
83  int16 _destY;
84 
85  bool _usesObliqueCoordinates;
86 
87  ItemPos _itemPoses[40];
88  char _sourceFile[15];
89 
90  Map(GobEngine *vm);
91  virtual ~Map();
92 
93  uint8 getVersion() const;
94 
95  int16 getMapWidth() const;
96  int16 getMapHeight() const;
97 
98  int16 getScreenWidth() const;
99  int16 getScreenHeight() const;
100 
101  int16 getTilesWidth() const;
102  int16 getTilesHeight() const;
103 
104  bool hasBigTiles() const;
105 
106  int8 getPass(int x, int y, int width = -1) const;
107  void setPass(int x, int y, int8 pass, int width = -1);
108 
109  const WayPoint &getWayPoint(int n) const;
110 
111  void findNearestWalkable(int16 &gobDestX, int16 &gobDestY,
112  int16 mouseX, int16 mouseY);
113 
114  int16 getItem(int x, int y) const;
115  void setItem(int x, int y, int16 item);
116  void placeItem(int16 x, int16 y, int16 id);
117 
118  Direction getDirection(int16 x0, int16 y0, int16 x1, int16 y1);
119 
120  int16 checkDirectPath(Mult::Mult_Object *obj, int16 x0,
121  int16 y0, int16 x1, int16 y1);
122  int16 checkLongPath(int16 x0, int16 y0,
123  int16 x1, int16 y1, int16 i0, int16 i1);
124 
125  void loadMapsInitGobs();
126 
127  virtual void loadMapObjects(const char *avjFile) = 0;
128  virtual void findNearestToGob(Mult::Mult_Object *obj) = 0;
129  virtual void findNearestToDest(Mult::Mult_Object *obj) = 0;
130  virtual void optimizePoints(Mult::Mult_Object *obj, int16 x, int16 y) = 0;
131 
132 protected:
133  GobEngine *_vm;
134 
135  bool _loadFromAvo;
136 
137  uint8 _mapVersion;
138 
139  int16 _mapWidth;
140  int16 _mapHeight;
141 
142  int16 _screenWidth;
143  int16 _screenHeight;
144 
145  int16 _tilesWidth;
146  int16 _tilesHeight;
147 
148  bool _bigTiles;
149 
150  int16 _passWidth;
151  int8 *_passMap; // [y * _mapWidth + x], getPass(x, y);
152 
153  int16 _wayPointCount;
154  WayPoint *_wayPoints;
155 
156  int16 **_itemsMap; // [y][x]
157 
158  int16 findNearestWayPoint(int16 x, int16 y);
159 
160 private:
161  // Move the x and y values according to the direction
162  void moveDirection(Direction dir, int16 &x, int16 &y);
163 };
164 
165 class Map_v1 : public Map {
166 public:
167  void loadMapObjects(const char *avjFile) override;
168  void findNearestToGob(Mult::Mult_Object *obj) override;
169  void findNearestToDest(Mult::Mult_Object *obj) override;
170  void optimizePoints(Mult::Mult_Object *obj, int16 x, int16 y) override;
171 
172  Map_v1(GobEngine *vm);
173  ~Map_v1() override;
174 
175 protected:
176  void init();
177  void loadSounds(Common::SeekableReadStream &data);
178  void loadGoblins(Common::SeekableReadStream &data, uint32 gobsPos);
179  void loadObjects(Common::SeekableReadStream &data, uint32 objsPos);
180  void loadItemToObject(Common::SeekableReadStream &data);
181 };
182 
183 class Map_v2 : public Map_v1 {
184 public:
185  void loadMapObjects(const char *avjFile) override;
186  void findNearestToGob(Mult::Mult_Object *obj) override;
187  void findNearestToDest(Mult::Mult_Object *obj) override;
188  void optimizePoints(Mult::Mult_Object *obj, int16 x, int16 y) override;
189 
190  Map_v2(GobEngine *vm);
191  ~Map_v2() override;
192 
193 protected:
194  void loadGoblinStates(Common::SeekableReadStream &data, int index);
195 };
196 
197 } // End of namespace Gob
198 
199 #endif // GOB_MAP_H
Definition: gob.h:156
Definition: mult.h:91
Definition: stream.h:745
Definition: anifile.h:40
Definition: map.h:68
Definition: map.h:75
Definition: map.h:62
Definition: map.h:165
Definition: map.h:183