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