-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.h
239 lines (195 loc) · 6.07 KB
/
database.h
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* 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 KOM_DATABASE_H
#define KOM_DATABASE_H
#include <assert.h>
#include "common/scummsys.h"
#include "common/str.h"
#include "common/list.h"
#include "common/file.h"
#include "kom/character.h"
namespace Kom {
class KomEngine;
struct EventLink {
int exitBox;
int proc;
};
struct Object {
Object() : data1(0), type(0), spellType(0), proc(0),
data4(0), isCarryable(0), isContainer(0), isVisible(0), isSprite(0), isUseImmediate(0),
isPickable(0), isUsable(0), price(0), data11(0), spellCost(0), minDamage(0),
maxDamage(0), ownerType(0), ownerId(0), box(0), data16(0), data17(0),
data18(0) {}
char name[7];
int data1;
char desc[50];
int type;
int spellType;
int proc;
int data4;
int isCarryable;
int isContainer;
int isVisible;
int isSprite;
int isUseImmediate;
int isPickable;
int isUsable;
int price;
int data11;
int spellCost;
int minDamage;
int maxDamage;
int ownerType;
int ownerId;
int box;
int data16;
int data17;
int data18;
Common::List<int> contents;
};
struct Location {
char name[7];
int xtend;
int allowedTime;
char desc[50];
Common::List<EventLink> events;
Common::List<int> objects;
Common::List<int> characters;
};
struct OpCode {
int opcode;
char arg1[30];
int arg2;
int arg3;
int arg4;
int arg5;
int arg6;
OpCode() : arg2(0), arg3(0), arg4(0), arg5(0), arg6(0) { arg1[0] = '\0'; }
};
struct Command {
int cmd;
uint16 value;
Common::List<OpCode> opcodes;
Command() : value(0) {}
};
struct Process {
char name[30];
Common::List<Command> commands;
};
struct Exit {
int16 exit;
int16 exitLoc;
int16 exitBox;
};
struct Box {
Box() : enabled(false) {}
bool enabled;
int16 x1, y1, x2, y2, priority;
int32 z1, z2;
uint8 attrib;
int8 joins[6];
};
struct LocRoute {
Exit exits[6];
Box boxes[32];
};
class Database {
public:
Database(KomEngine *vm);
~Database();
void init(Common::String databasePrefix);
static void stripUndies(char *s);
int8 loc2loc(int from, int to) { return (int8)(_routes[(int8)(_routes[0]) * to + from + 1]); }
int8 box2box(int loc, int fromBox, int toBox);
Box *getBox(int locId, int boxId) const { return &(_locRoutes[locId].boxes[boxId]); }
Exit *getExits(int locId) const { return _locRoutes[locId].exits; }
int8 whatBox(int locId, int x, int y);
int8 whatBoxLinked(int locId, int8 boxId, int x, int y);
int16 getMidX(int loc, int box) { return _locRoutes[loc].boxes[box].x1 +
(_locRoutes[loc].boxes[box].x2 - _locRoutes[loc].boxes[box].x1) / 2; }
int16 getMidY(int loc, int box) { return _locRoutes[loc].boxes[box].y1 +
(_locRoutes[loc].boxes[box].y2 - _locRoutes[loc].boxes[box].y1) / 2; }
int16 getMidOverlapX(int loc, int box1, int box2);
int16 getMidOverlapY(int loc, int box1, int box2);
int16 getPriority(int loc, int box) { return _locRoutes[loc].boxes[box].priority; }
int16 getZValue(int loc, int box, int32 y);
uint16 getExitBox(int currLoc, int nextLoc);
int8 getBoxLink(int loc, int box, int join);
int8 getFirstLink(int loc, int box);
void getExitInfo(int loc, int box, int *exitLoc, int *exitBox);
int findFarthestExit(int loc, int box);
bool isInLine(int loc, int box, int x, int y);
void getClosestBox(int loc, uint16 mouseX, uint16 mouseY,
int16 screenX, int16 screenY,
int16 *collideBox, int16 *collideBoxX, int16 *collideBoxY);
void setCharPos(int charId, int loc, int box);
bool giveObject(int obj, int charId, bool noAnimation = false);
Process *getProc(uint16 procIndex) const { return procIndex < _procsNum ? &(_processes[procIndex]) : NULL; }
Character *getChar(uint16 charIndex) const { return charIndex < _charactersNum ? &(_characters[charIndex]) : NULL; }
Character *getMagicChar(uint16 charIndex) { return charIndex < sizeof(_magicCharacters) ? &(_magicCharacters[charIndex]) : NULL; }
Object *getObj(uint16 objIndex) const { return objIndex < _objectsNum ? &(_objects[objIndex]) : NULL; }
Location *getLoc(uint16 locIndex) const { return locIndex < _locationsNum ? &(_locations[locIndex]) : NULL; }
int charactersNum() { return _charactersNum; }
int16 getVar(uint16 index) { assert(index < _varSize); return _variables[index]; }
void setVar(uint16 index, int16 value) { assert(index < _varSize); _variables[index] = value; }
char *getNarratorText(const char *entry);
byte *getConvIndex(const char *entry);
Common::File *getConvData() { return _convData; }
private:
void loadConvIndex();
void loadNarratorIndex();
void initLocations();
void initCharacters();
void initObjects();
void initEvents();
void initObjectLocs();
void initCharacterLocs();
void initProcs();
void initRoutes();
void initScopes();
KomEngine *_vm;
Common::String _databasePrefix;
Common::String _pathPrefix;
Location *_locations;
int _locationsNum;
Character *_characters;
int _charactersNum;
Character _magicCharacters[10];
Object *_objects;
int _objectsNum;
Process *_processes;
int _procsNum;
int _varSize;
int16 *_variables;
uint32 _convIndexLen;
byte *_convIndex;
Common::File *_convData;
int _narrIndexSize;
byte *_narrIndex;
Common::File _narrData;
int _mapSize;
byte *_map;
int _routesSize;
byte *_routes;
static const int _locRoutesSize;
LocRoute *_locRoutes;
};
} // End of namespace Kom
#endif