aboutsummaryrefslogtreecommitdiff
path: root/engines/made/database.h
blob: 89b4b453571aec8f666493a91c46982796ddd3d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef MADE_DATABASE_H
#define MADE_DATABASE_H

#include "common/hashmap.h"

namespace Common {
class SeekableReadStream;
class WriteStream;
class String;
}

namespace Made {

class MadeEngine;

class Object {
public:

	Object();
	virtual ~Object();

	virtual int load(Common::SeekableReadStream &source) = 0;
	virtual int load(byte *source) = 0;
	virtual int save(Common::WriteStream &dest) = 0;
	virtual uint16 getFlags() = 0;
	virtual uint16 getClass() = 0;
	virtual uint16 getSize() = 0;
	virtual byte getCount1() = 0;
	virtual byte getCount2() = 0;
	virtual byte *getData() = 0;
	virtual bool isConstant() = 0;

	const char *getString();
	void setString(const char *str);

	bool isObject();
	bool isVector();

	int16 getVectorSize();
	int16 getVectorItem(int16 index);
	void setVectorItem(int16 index, int16 value);

	void dump(const Common::String &filename);

protected:
	bool _freeData;
	uint16 _objSize;
	byte *_objData;
};

class ObjectV2 : public Object {
public:
	int load(Common::SeekableReadStream &source);
	int load(byte *source);
	int save(Common::WriteStream &dest);
	uint16 getFlags();
	uint16 getClass();
	uint16 getSize();
	byte getCount1();
	byte getCount2();
	byte *getData();

	bool isConstant() {
		return false;
	}
};

class ObjectV1 : public ObjectV2 {
public:
	int load(Common::SeekableReadStream &source);
};

class ObjectV3 : public Object {
public:
	int load(Common::SeekableReadStream &source);
	int load(byte *source);
	int save(Common::WriteStream &dest);
	uint16 getFlags();
	uint16 getClass();
	uint16 getSize();
	byte getCount1();
	byte getCount2();
	byte *getData();

	bool isConstant() {
		return !(getFlags() & 1);
	}

};

class GameDatabase {
public:

	GameDatabase(MadeEngine *vm);
	virtual ~GameDatabase();

	void open(const char *filename);
	void openFromRed(const char *redFilename, const char *filename);

	void reload();

	Object *getObject(int16 index) const {
		if (index >= 1)
			return _objects[index - 1];
		else
			return NULL;
	}

	uint getObjectCount() const { return _objects.size(); }

	int16 getMainCodeObjectIndex() const { return _mainCodeObjectIndex; }

	int16 getVar(int16 index);
	void setVar(int16 index, int16 value);

	const char *getObjectString(int16 index);
	void setObjectString(int16 index, const char *str);

	virtual int16 *findObjectProperty(int16 objectIndex, int16 propertyId, int16 &propertyFlag) = 0;
	int16 *findObjectPropertyCached(int16 objectIndex, int16 propertyId, int16 &propertyFlag);
	virtual const char *getString(uint16 offset) = 0;
	virtual bool getSavegameDescription(const char *filename, Common::String &description, int16 version) = 0;
	virtual int16 savegame(const char *filename, const char *description, int16 version) = 0;
	virtual int16 loadgame(const char *filename, int16 version) = 0;

	int16 getObjectProperty(int16 objectIndex, int16 propertyId);
	int16 setObjectProperty(int16 objectIndex, int16 propertyId, int16 value);

	void dumpObject(int16 index);

protected:
	typedef Common::HashMap<uint32, int16 *> ObjectPropertyCacheMap;
	MadeEngine *_vm;
	Common::Array<Object *> _objects;
	ObjectPropertyCacheMap _objectPropertyCache;
	byte *_gameState;
	uint32 _gameStateSize;
	int16 _mainCodeObjectIndex;
	bool _isRedSource;
	Common::String _filename, _redFilename;
	virtual void load(Common::SeekableReadStream &sourceS) = 0;
	virtual void reloadFromStream(Common::SeekableReadStream &sourceS) = 0;
};

class GameDatabaseV2 : public GameDatabase {
public:
	GameDatabaseV2(MadeEngine *vm);
	~GameDatabaseV2();
	int16 *findObjectProperty(int16 objectIndex, int16 propertyId, int16 &propertyFlag);
	const char *getString(uint16 offset);
	bool getSavegameDescription(const char *filename, Common::String &description, int16 version);
	int16 savegame(const char *filename, const char *description, int16 version);
	int16 loadgame(const char *filename, int16 version);
protected:
	char *_gameText;
	void load(Common::SeekableReadStream &sourceS);
	void reloadFromStream(Common::SeekableReadStream &sourceS);
};

class GameDatabaseV3 : public GameDatabase {
public:
	GameDatabaseV3(MadeEngine *vm);
	int16 *findObjectProperty(int16 objectIndex, int16 propertyId, int16 &propertyFlag);
	const char *getString(uint16 offset);
	bool getSavegameDescription(const char *filename, Common::String &description, int16 version);
	int16 savegame(const char *filename, const char *description, int16 version);
	int16 loadgame(const char *filename, int16 version);
protected:
	char *_gameText;
	uint32 _gameStateOffs;
	void load(Common::SeekableReadStream &sourceS);
	void reloadFromStream(Common::SeekableReadStream &sourceS);
};

} // End of namespace Made

#endif /* MADE_H */