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 MADE_DATABASE_H
23 #define MADE_DATABASE_H
24 
25 #include "common/hashmap.h"
26 
27 namespace Common {
28 class SeekableReadStream;
29 class WriteStream;
30 class String;
31 }
32 
33 namespace Made {
34 
35 class MadeEngine;
36 
37 
38 /* Object */
39 
40 class Object {
41 public:
42 
43  Object();
44  virtual ~Object();
45 
46  virtual int load(Common::SeekableReadStream &source) = 0;
47  virtual int load(byte *source) = 0;
48  virtual int save(Common::WriteStream &dest) = 0;
49  virtual uint16 getFlags() = 0;
50  virtual uint16 getClass() = 0;
51  virtual uint16 getSize() = 0;
52  virtual byte getCount1() = 0;
53  virtual byte getCount2() = 0;
54  virtual byte *getData() = 0;
55  virtual bool isConstant() = 0;
56 
57  const char *getString();
58  void setString(const char *str);
59 
60  bool isObject();
61 
62  int16 getVectorSize();
63  int16 getVectorItem(int16 index);
64  void setVectorItem(int16 index, int16 value);
65 
66  void dump(const Common::String &filename);
67 
68 protected:
69  bool _freeData;
70  uint16 _objSize;
71  byte *_objData;
72 };
73 
74 class ObjectV2 : public Object {
75 public:
76  int load(Common::SeekableReadStream &source) override;
77  int load(byte *source) override;
78  int save(Common::WriteStream &dest) override;
79  uint16 getFlags() override;
80  uint16 getClass() override;
81  uint16 getSize() override;
82  byte getCount1() override;
83  byte getCount2() override;
84  byte *getData() override;
85 
86  bool isConstant() override {
87  return false;
88  }
89 };
90 
91 class ObjectV1 : public ObjectV2 {
92 public:
93  int load(Common::SeekableReadStream &source) override;
94 };
95 
96 class ObjectV3 : public Object {
97 public:
98  virtual int load(Common::SeekableReadStream &source) override;
99  virtual int load(byte *source) override;
100  int save(Common::WriteStream &dest) override;
101  uint16 getFlags() override;
102  uint16 getClass() override;
103  uint16 getSize() override;
104  byte getCount1() override;
105  byte getCount2() override;
106  byte *getData() override;
107 
108  bool isConstant() override {
109  return !(getFlags() & 1);
110  }
111 
112 };
113 
114 class ObjectV3_1 : public ObjectV3 {
115 public:
116  int load(Common::SeekableReadStream &source) override;
117  int load(byte *source) override;
118 };
119 
120 
121 /* GameDatabase */
122 
124 public:
125 
127  virtual ~GameDatabase();
128 
129  void open(const char *filename);
130  void openFromRed(const char *redFilename, const char *filename);
131 
132  void reload();
133 
134  Object *getObject(int16 index) const {
135  if (index >= 1)
136  return _objects[index - 1];
137  else
138  return NULL;
139  }
140 
141  uint getObjectCount() const { return _objects.size(); }
142 
143  int16 getMainCodeObjectIndex() const { return _mainCodeObjectIndex; }
144 
145  int16 getVar(int16 index);
146  void setVar(int16 index, int16 value);
147 
148  const char *getObjectString(int16 index);
149  void setObjectString(int16 index, const char *str);
150 
151  virtual int16 *findObjectProperty(int16 objectIndex, int16 propertyId, int16 &propertyFlag) = 0;
152  int16 *findObjectPropertyCached(int16 objectIndex, int16 propertyId, int16 &propertyFlag);
153  virtual const char *getString(uint16 offset) = 0;
154  virtual bool getSavegameDescription(const char *filename, Common::String &description, int16 version) = 0;
155  virtual int16 savegame(const char *filename, const char *description, int16 version) = 0;
156  virtual int16 loadgame(const char *filename, int16 version) = 0;
157 
158  int16 getObjectProperty(int16 objectIndex, int16 propertyId);
159  int16 setObjectProperty(int16 objectIndex, int16 propertyId, int16 value);
160 
161  void dumpObject(int16 index);
162 
163 protected:
165  MadeEngine *_vm;
166  Common::Array<Object *> _objects;
167  ObjectPropertyCacheMap _objectPropertyCache;
168  byte *_gameState;
169  uint32 _gameStateSize;
170  int16 _mainCodeObjectIndex;
171  bool _isRedSource;
172  Common::String _filename, _redFilename;
173  virtual void load(Common::SeekableReadStream &sourceS) = 0;
174  virtual void reloadFromStream(Common::SeekableReadStream &sourceS) = 0;
175 };
176 
177 class GameDatabaseV2 : public GameDatabase {
178 public:
180  ~GameDatabaseV2() override;
181  int16 *findObjectProperty(int16 objectIndex, int16 propertyId, int16 &propertyFlag) override;
182  const char *getString(uint16 offset) override;
183  bool getSavegameDescription(const char *filename, Common::String &description, int16 version) override;
184  int16 savegame(const char *filename, const char *description, int16 version) override;
185  int16 loadgame(const char *filename, int16 version) override;
186 protected:
187  char *_gameText;
188  void load(Common::SeekableReadStream &sourceS) override;
189  void reloadFromStream(Common::SeekableReadStream &sourceS) override;
190 };
191 
192 class GameDatabaseV3 : public GameDatabase {
193 public:
195  virtual int16 *findObjectProperty(int16 objectIndex, int16 propertyId, int16 &propertyFlag) override;
196  const char *getString(uint16 offset) override;
197  bool getSavegameDescription(const char *filename, Common::String &description, int16 version) override;
198  int16 savegame(const char *filename, const char *description, int16 version) override;
199  int16 loadgame(const char *filename, int16 version) override;
200 protected:
201  char *_gameText;
202  uint32 _gameStateOffs;
203  void load(Common::SeekableReadStream &sourceS) override;
204  void reloadFromStream(Common::SeekableReadStream &sourceS) override;
205 };
206 
208 public:
210  int16 *findObjectProperty(int16 objectIndex, int16 propertyId, int16 &propertyFlag) override;
211 };
212 
213 } // End of namespace Made
214 
215 #endif /* MADE_H */
Definition: database.h:207
Definition: str.h:59
Definition: stream.h:77
Definition: database.h:91
Definition: made.h:69
Definition: database.h:192
Definition: stream.h:745
Definition: database.h:114
Definition: database.h:123
Definition: database.h:74
Definition: database.h:40
Definition: algorithm.h:29
Definition: console.h:27
Definition: database.h:177
Definition: database.h:96