ScummVM API documentation
database.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 DATABASE_H_
23 #define DATABASE_H_
24 
25 #include "engines/myst3/hotspot.h"
26 #include "engines/myst3/detection.h"
27 
28 #include "common/scummsys.h"
29 #include "common/str.h"
30 #include "common/language.h"
31 #include "common/platform.h"
32 #include "common/ptr.h"
33 #include "common/array.h"
34 #include "common/hashmap.h"
35 #include "common/stream.h"
36 
37 namespace Myst3 {
38 
39 enum MystLanguage {
40  kEnglish = 0,
41  kOther = 1, // Dutch, Japanese or Polish
42  kDutch = 1,
43  kFrench = 2,
44  kGerman = 3,
45  kItalian = 4,
46  kSpanish = 5
47 };
48 
49 enum NodeID {
50  kNodeSharedInit = 1,
51  kNodeLogoPlay = 1,
52  kNodeMenuNewGame = 98,
53  kNodeMenuMain = 100,
54  kNodeMenuLoadGame = 200,
55  kNodeMenuSaveGame = 300
56 };
57 
58 enum RoomID {
59  kRoomShared = 101,
60  kRoomIntro = 201,
61  kRoomTomahnaStart = 301,
62  kRoomTomahnaReturn = 401,
63  kJnaninStart = 501,
64  kRoomLeos = 502,
65  kRoomLeet = 503,
66  kRoomLelt = 504,
67  kRoomLemt = 505,
68  kRoomLeof = 506,
69  kRoomEdannaStart = 601,
70  kRoomLisw = 602,
71  kRoomLifo = 603,
72  kRoomLisp = 604,
73  kRoomLine = 605,
74  kRoomVoltaicStart = 701,
75  kRoomEnpp = 703,
76  kRoomEnem = 704,
77  kRoomEnlc = 705,
78  kRoomEndd = 706,
79  kRoomEnch = 707,
80  kRoomEnli = 708,
81  kRoomNarayan = 801,
82  kRoomMenu = 901,
83  kRoomJournals = 902,
84  kRoomDemo = 903,
85  kRoomAtix = 904,
86  kRoomAmateriaStart = 1001,
87  kRoomMais = 1002,
88  kRoomMall = 1003,
89  kRoomMass = 1004,
90  kRoomMaww = 1005,
91  kRoomMato = 1006,
92  kLogo = 1101
93 };
94 
95 struct NodeData {
96  int16 id;
97  int16 zipBitIndex;
99  Common::Array<HotSpot> hotspots;
100  Common::Array<CondScript> soundScripts;
101  Common::Array<CondScript> backgroundSoundScripts;
102 };
103 
104 // Nodes are using ref counting pointers since they can be
105 // deleted by a script they own
107 
108 struct RoomData {
109  uint32 id;
110  const char *name;
111 };
112 
113 struct RoomKey {
114  uint16 ageID;
115  uint16 roomID;
116 
117  RoomKey(uint16 room, uint16 age) : roomID(room), ageID(age) {};
118 
119  bool operator==(const RoomKey &k) const {
120  return ageID == k.ageID && roomID == k.roomID;
121  }
122 };
123 
124 struct AgeData {
125  uint32 id;
126  uint32 disk;
127  uint32 roomCount;
128  const RoomData *rooms;
129  uint32 labelId;
130 };
131 
132 struct AmbientCue {
133  uint16 id;
134  uint16 minFrames;
135  uint16 maxFrames;
136  Common::Array<uint16> tracks;
137 };
138 
142 enum ScriptType {
143  kScriptTypeNode,
144  kScriptTypeAmbientSound,
145  kScriptTypeBackgroundSound,
146  kScriptTypeNodeInit,
147  kScriptTypeAmbientCue
148 };
149 
153 struct RoomScripts {
154  Common::String room;
155  ScriptType type;
156  uint offset;
157  uint size;
158 };
159 
160 class Myst3Engine;
161 
162 class Database {
163 public:
164  Database(const Common::Platform platform, const Common::Language language, const uint32 localizationType);
165  ~Database();
166 
170  void cacheRoom(uint32 roomID, uint32 ageID);
171 
177  bool isCommonRoom(uint32 roomID, uint32 ageID) const;
178 
182  NodePtr getNodeData(uint16 nodeID, uint32 roomID, uint32 ageID);
183 
187  int32 getNodeZipBitIndex(uint16 nodeID, uint32 roomID, uint32 ageID);
188 
192  const Common::Array<Opcode>& getNodeInitScript() { return _nodeInitScript; }
193 
197  Common::String getRoomName(uint32 roomID, uint32 ageID) const;
198 
202  RoomKey getRoomKey(const char *name);
203 
207  Common::Array<uint16> listRoomNodes(uint32 roomID, uint32 ageID);
208 
212  uint32 getAgeLabelId(uint32 ageID);
213 
217  Common::String getSoundName(uint32 id);
218 
220  uint32 getSoundIdMin() const { return _soundIdMin; }
221  uint32 getSoundIdMax() const { return _soundIdMax; }
222 
226  const AmbientCue &getAmbientCue(uint16 id);
227 
228  int16 getGameLanguageCode() const;
229 
231  bool areRoomsScriptsEqual(uint32 roomID1, uint32 ageID1, uint32 roomID2, uint32 ageID2, ScriptType scriptType);
232 
233 private:
234  struct RoomKeyHash {
235  uint operator()(const RoomKey &v) const {
236  return v.ageID + (v.roomID << 16);
237  }
238  };
239 
241 
242  const Common::Platform _platform;
243  const Common::Language _language;
244  const uint32 _localizationType;
245 
246  static const AgeData _ages[];
247 
248  NodesCache _roomNodesCache;
249 
250  Common::Array<Opcode> _nodeInitScript;
251 
252  uint32 _soundIdMin;
253  uint32 _soundIdMax;
256  Common::HashMap<uint32, int16> _roomZipBitIndex;
257 
258  // 'myst3.dat' cached data
259  static const uint kDatVersion = 3;
260  Common::SeekableReadStream *_datFile;
261  Common::Array<RoomScripts> _roomScriptsIndex;
262  int32 _roomScriptsStartOffset;
263 
264  const RoomData *findRoomData(uint32 roomID, uint32 ageID) const;
265  Common::Array<NodePtr> getRoomNodes(uint32 roomID, uint32 ageID) const;
266 
267  Common::Array<NodePtr> readRoomScripts(const RoomData *room) const;
268  void preloadCommonRooms();
269  void initializeZipBitIndexTable();
270  void patchLanguageMenu();
271  void patchNodeScripts(const RoomData *room, Common::Array<NodePtr> &nodes) const;
272 
273  // 'myst3.dat' read methods
274  void readScriptIndex(Common::SeekableReadStream *stream, bool load);
275  void readSoundNames(Common::SeekableReadStream *stream, bool load);
276  void loadAmbientCues(Common::ReadStream *s);
277  Common::SeekableReadStream *getRoomScriptStream(const char *room, ScriptType scriptType) const;
278 };
279 
280 } // End of namespace Myst3
281 
282 #endif // DATABASE_H_
Definition: str.h:59
Definition: database.h:153
Definition: array.h:52
Definition: database.h:108
Definition: ambient.h:27
Definition: stream.h:745
const Common::Array< Opcode > & getNodeInitScript()
Definition: database.h:192
Definition: hashmap.h:85
Definition: database.h:132
uint32 getSoundIdMin() const
Definition: database.h:220
Definition: database.h:162
Definition: stream.h:385
Definition: ptr.h:159
Definition: myst3.h:87
Definition: database.h:124
Definition: database.h:95
Platform
Definition: platform.h:46
Language
Definition: language.h:45
Definition: database.h:113