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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
/* 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 TITANIC_TT_NPC_SCRIPT_H
#define TITANIC_TT_NPC_SCRIPT_H
#include "titanic/support/simple_file.h"
#include "titanic/true_talk/tt_script_base.h"
namespace Titanic {
#define DIALS_ARRAY_COUNT 10
enum ScriptArrayFlag { SF_NONE = 0, SF_RANDOM = 1, SF_SEQUENTIAL = 2 };
class CGameManager;
class CPetControl;
class TTroomScript;
class TTsentence;
struct TTsentenceEntry;
struct TTnpcScriptResponse {
uint _tag;
uint _values[4];
/**
* Returns the size of the values list plus 1
*/
int size() const;
};
struct TTscriptRange {
uint _id;
Common::Array<uint> _values;
TTscriptRange *_nextP;
uint _priorIndex;
ScriptArrayFlag _mode;
TTscriptRange() : _id(0), _nextP(nullptr),
_priorIndex(0), _mode(SF_NONE) {}
TTscriptRange(uint id, const Common::Array<uint> &values, bool isRandom,
bool isSequential);
};
struct TTsentenceEntry {
int _field0;
int _field4;
CString _string8;
int _fieldC;
CString _string10;
CString _string14;
CString _string18;
CString _string1C;
int _field20;
CString _string24;
int _field28;
int _field2C;
int _field30;
TTsentenceEntry() : _field0(0), _field4(0), _fieldC(0),
_field20(0), _field28(0), _field2C(0), _field30(0) {}
/**
* Load an entry from the passed stream, and returns true
* if an entry was successfully loaded
*/
bool load(Common::SeekableReadStream *s);
};
class TTsentenceEntries : public Common::Array<TTsentenceEntry> {
public:
/**
* Load a list of entries from the specified resource
*/
void load(const CString &resName);
};
struct TTscriptMapping {
uint _id;
uint _values[8];
TTscriptMapping();
};
class TTscriptMappings : public Common::Array<TTscriptMapping> {
public:
int _valuesPerMapping;
void load(const char *name, int valuesPerMapping);
};
struct TTtagMapping {
uint _src, _dest;
TTtagMapping() : _src(0), _dest(0) {}
TTtagMapping(uint src, uint dest) : _src(src), _dest(dest) {}
};
class TTtagMappings : public Common::Array<TTtagMapping> {
public:
void load(const char *name);
};
class TTnpcScriptBase : public TTscriptBase {
protected:
int _field54;
int _val2;
public:
int _charId;
public:
TTnpcScriptBase(int charId, const char *charClass, int v2,
const char *charName, int v3, int val2, int v4,
int v5, int v6, int v7);
/**
* Chooses and adds a conversation response based on a specified tag Id.
*/
virtual int chooseResponse(TTroomScript *roomScript, TTsentence *sentence, uint tag) = 0;
/**
* Does NPC specific processing of the parsed sentence
*/
virtual int process(TTroomScript *roomScript, TTsentence *sentence) = 0;
virtual int proc8() const = 0;
virtual int proc9() const = 0;
/**
* Called when the script/id changes
*/
virtual ScriptChangedResult scriptChanged(TTscriptBase *roomScript, uint id) = 0;
virtual int proc11() const = 0;
virtual int proc12() const = 0;
int charId() const { return _charId; }
};
class TTnpcScript : public TTnpcScriptBase {
private:
int translateByArray(int id);
protected:
Common::Array<TTnpcScriptResponse> _responses;
int _valuesPerResponse;
Common::Array<TTscriptRange> _ranges;
TTscriptMappings _mappings;
TTsentenceEntries _entries;
TTtagMappings _tagMappings;
int _entryCount;
int _field68;
int _field6C;
int _rangeResetCtr;
int _field74;
int _field78;
int _field7C;
const char *_itemStringP;
int _dialValues[DIALS_ARRAY_COUNT];
int _array[136];
bool _field2CC;
protected:
/**
* Loads response data for the NPC from the given resource
*/
void loadResponses(const char *name, int valuesPerResponse = 1);
/**
* Load ranges data for the NPC from the given resource
*/
void loadRanges(const char *name);
/**
* Reset script flags
*/
void resetFlags();
/**
* Setup dials
*/
void setupDials(int dial1, int dial2, int dial3);
static int getRoom54(int roomId);
/**
* Perform test on various state values
*/
int getValue(int testNum);
/**
* Gets a random number between 1 and a given max
*/
uint getRandomNumber(int max) const;
/**
* Gets a random number of 0 or 1
*/
uint getRandomBit() const {
return getRandomNumber(2) - 1;
}
/**
* Returns a dialogue Id by script tag value Id
*/
uint getDialogueId(uint tagId);
/**
* Returns a pointer to the PET control
*/
static CPetControl *getPetControl(CGameManager *gameManager);
/**
* Adds a new item to the list of number ranges
*/
void addRange(uint id, const Common::Array<uint> &values, bool isRandom, bool isSequential);
/**
* Finds an entry in the list of prevoiusly registered number ranges
*/
TTscriptRange *findRange(uint id);
/**
* Scans through a list of sentence entries for a matching standardized response
*/
int processEntries(const TTsentenceEntries *entries, uint entryCount, TTroomScript *roomScript, TTsentence *sentence);
/**
* Scans through a list of sentence entries for a matching standardized response
*/
int processEntries(TTroomScript *roomScript, TTsentence *sentence) {
return processEntries(&_entries, _entryCount, roomScript, sentence);
}
bool defaultProcess(TTroomScript *roomScript, TTsentence *sentence);
void checkItems(TTroomScript *roomScript, TTsentence *sentence);
/**
* Adds a random conversation response
*/
bool addRandomResponse(bool flag);
public:
TTnpcScript(int charId, const char *charClass, int v2,
const char *charName, int v3, int val2, int v4,
int v5, int v6, int v7);
virtual void addResponse(int id);
/**
* Chooses and adds a conversation response based on a specified tag Id.
* This default implementation does a lookup into a list of known tags,
* and chooses a random dialogue Id from the available ones for that tag
*/
virtual int chooseResponse(TTroomScript *roomScript, TTsentence *sentence, uint tag);
/**
* Does NPC specific processing of the parsed sentence
*/
virtual int process(TTroomScript *roomScript, TTsentence *sentence);
virtual int proc8() const;
virtual int proc9() const;
/**
* Called when the script/id changes
*/
virtual ScriptChangedResult scriptChanged(TTscriptBase *roomScript, uint id) {
return SCR_2;
}
virtual int proc11() const;
virtual int proc12() const;
/**
* Translate a passed Id to a dialogue Id if necessary,
* and adds it to the response
*/
virtual void selectResponse(int id);
virtual int proc15(int id) const;
virtual bool handleQuote(TTroomScript *roomScript, TTsentence *sentence,
int val, uint tagId, uint remainder) const;
/**
* Given an Id for a previously registered set of random number values,
* picks one of the array values and returns it.. depending on flags,
* either a random value, or each value in turn
*/
virtual uint getRangeValue(uint id);
/**
* Resets the prior used index for the specified range
*/
virtual void resetRange(int id);
virtual int proc21(int v1, int v2, int v3);
virtual int proc22(int id) const;
virtual int proc23() const;
virtual const TTscriptMapping *getMapping(int index);
virtual int proc25(int val1, int val2, TTroomScript *roomScript, TTsentence *sentence) const;
virtual void proc26(int v1, const TTsentenceEntry *entry, TTroomScript *roomScript, TTsentence *sentence);
virtual void save(SimpleFile *file);
virtual void load(SimpleFile *file);
virtual void saveBody(SimpleFile *file);
virtual void loadBody(SimpleFile *file);
virtual int proc31() const;
/**
* Sets a given dial to be pointing in a specified region (0 to 2)
*/
virtual void setDialRegion(int dialNum, int region);
/**
* Sets the value for an NPC's dial
*/
virtual void setDial(int dialNum, int value);
/**
* Returns a dial's region number
*/
virtual int getDialRegion(int dialNum) const;
/**
* Gets the value for a dial
* @param dialNum Dial number
* @param randomizeFlag If set, introduces a slight random variance so that
* the displayed dial will oscillate randomly around it's real level
*/
virtual int getDialLevel(uint dialNum, bool randomizeFlag = true);
virtual int proc36(int val) const;
virtual uint translateId(uint id) const;
void preLoad();
/**
* Called with the script and id changes
*/
ScriptChangedResult notifyScript(TTscriptBase *npcScript, int id) {
return scriptChanged(npcScript, id);
}
};
} // End of namespace Titanic
#endif /* TITANIC_TT_NPC_SCRIPT_H */
|