aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/true_talk/maitred_script.cpp
blob: 08e8119b00042f0449a7dd4ca173a07cb3b1e89f (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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/* 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.
 *
 */

#include "common/textconsole.h"
#include "titanic/true_talk/maitred_script.h"
#include "titanic/true_talk/true_talk_manager.h"

namespace Titanic {

MaitreDScript::MaitreDScript(int val1, const char *charClass, int v2,
		const char *charName, int v3, int val2) :
		TTnpcScript(val1, charClass, v2, charName, v3, val2, -1, -1, -1, 0) {
	CTrueTalkManager::setFlags(9, 1);
	CTrueTalkManager::setFlags(10, 0);
	CTrueTalkManager::setFlags(11, 0);
	CTrueTalkManager::setFlags(12, 0);
	CTrueTalkManager::setFlags(13, 0);
	CTrueTalkManager::setFlags(14, 0);
	CTrueTalkManager::setFlags(15, 0);
	CTrueTalkManager::setFlags(16, 0);

	loadRanges("Ranges/MaitreD");
	loadResponses("Responses/MaitreD");
	setupSentences();
	_tagMappings.load("TagMap/MaitreD");
	_quotes.load("Quotes/MaitreD");
	_states.load("States/MaitreD");
}

void MaitreDScript::setupSentences() {
	_mappings.load("Mappings/MaitreD", 1);
	_entries.load("Sentences/MaitreD");
	_field68 = 0;
	_entryCount = 0;
}

int MaitreDScript::chooseResponse(TTroomScript *roomScript, TTsentence *sentence, uint tag) {
	if (tag == MKTAG('F', 'O', 'O', 'D') || tag == MKTAG('F', 'I', 'S', 'H') ||
			tag == MKTAG('C', 'H', 'S', 'E')) {
		addResponse(getDialogueId(260388));
		addResponse(getDialogueId(260659));
		applyResponse();
		return 2;
	}

	return TTnpcScript::chooseResponse(roomScript, sentence, tag);
}

int MaitreDScript::process(TTroomScript *roomScript, TTsentence *sentence) {
	// TODO
	return 0;
}

ScriptChangedResult MaitreDScript::scriptChanged(TTscriptBase *roomScript, uint id) {
	warning("TODO");
	return SCR_1;
}

int MaitreDScript::handleQuote(TTroomScript *roomScript, TTsentence *sentence,
		uint val, uint tagId, uint remainder) {
	switch (tagId) {
	case MKTAG('A', 'D', 'V', 'T'):
	case MKTAG('A', 'R', 'T', 'I'):
	case MKTAG('A', 'R', 'T', 'Y'):
	case MKTAG('B', 'R', 'N', 'D'):
	case MKTAG('C', 'O', 'M', 'D'):
	case MKTAG('D', 'N', 'C', 'E'):
	case MKTAG('H', 'B', 'B', 'Y'):
	case MKTAG('L', 'I', 'T', 'R'):
	case MKTAG('M', 'A', 'G', 'S'):
	case MKTAG('M', 'C', 'P', 'Y'):
	case MKTAG('M', 'I', 'N', 'S'):
	case MKTAG('M', 'U', 'S', 'I'):
	case MKTAG('N', 'I', 'K', 'E'):
	case MKTAG('S', 'F', 'S', 'F'):
	case MKTAG('S', 'O', 'A', 'P'):
	case MKTAG('S', 'P', 'R', 'T'):
	case MKTAG('S', 'O', 'N', 'G'):
	case MKTAG('T', 'E', 'A', 'M'):
	case MKTAG('T', 'V', 'S', 'H'):
	case MKTAG('W', 'W', 'E', 'B'):
		tagId = MKTAG('E', 'N', 'T', 'N');
		break;
	case MKTAG('A', 'C', 'T', 'R'):
	case MKTAG('A', 'C', 'T', 'S'):
	case MKTAG('A', 'U', 'T', 'H'):
	case MKTAG('B', 'A', 'R', 'K'):
	case MKTAG('B', 'A', 'R', 'U'):
	case MKTAG('B', 'L', 'F', '1'):
	case MKTAG('B', 'L', 'F', '2'):
	case MKTAG('B', 'L', 'P', '1'):
	case MKTAG('B', 'L', 'P', '2'):
	case MKTAG('B', 'L', 'P', '3'):
	case MKTAG('B', 'L', 'P', '4'):
	case MKTAG('B', 'L', 'R', '1'):
	case MKTAG('B', 'L', 'R', '2'):
	case MKTAG('B', 'L', 'T', '1'):
	case MKTAG('B', 'L', 'T', '2'):
	case MKTAG('B', 'L', 'T', '3'):
	case MKTAG('B', 'L', 'T', '4'):
	case MKTAG('B', 'L', 'T', '5'):
	case MKTAG('C', 'O', 'P', 'S'):
	case MKTAG('D', 'C', 'T', 'R'):
	case MKTAG('F', 'A', 'M', 'E'):
	case MKTAG('F', 'A', 'S', 'H'):
	case MKTAG('G', 'I', 'R', 'L'):
	case MKTAG('H', 'E', 'R', 'O'):
	case MKTAG('H', 'O', 'S', 'T'):
	case MKTAG('K', 'N', 'O', 'B'):
	case MKTAG('N', 'H', 'R', 'O'):
	case MKTAG('R', 'A', 'C', 'E'):
	case MKTAG('S', 'C', 'I', 'T'):
	case MKTAG('T', 'D', 'V', 'P'):
	case MKTAG('T', 'W', 'A', 'T'):
	case MKTAG('W', 'E', 'A', 'T'):
		tagId = MKTAG('P', 'R', 'S', 'N');
		break;
	case MKTAG('C', 'H', 'S', 'E'):
	case MKTAG('C', 'M', 'N', 'T'):
	case MKTAG('F', 'I', 'L', 'M'):
	case MKTAG('L', 'I', 'Q', 'D'):
		tagId = MKTAG('F', 'O', 'O', 'D');
		break;
	case MKTAG('C', 'R', 'I', 'M'):
	case MKTAG('C', 'S', 'P', 'Y'):
	case MKTAG('D', 'R', 'U', 'G'):
		tagId = MKTAG('V', 'B', 'A', 'D');
		break;
	case MKTAG('E', 'A', 'R', 'T'):
	case MKTAG('H', 'O', 'M', 'E'):
	case MKTAG('N', 'P', 'L', 'C'):
	case MKTAG('P', 'L', 'A', 'N'):
		tagId = MKTAG('P', 'L', 'A', 'C');
		break;
	case MKTAG('F', 'A', 'U', 'N'):
	case MKTAG('F', 'I', 'S', 'H'):
	case MKTAG('F', 'L', 'O', 'R'):
		tagId = MKTAG('N', 'A', 'T', 'R');
		break;
	case MKTAG('H', 'H', 'L', 'D'):
	case MKTAG('T', 'O', 'Y', 'S'):
	case MKTAG('W', 'E', 'A', 'P'):
		tagId = MKTAG('M', 'A', 'C', 'H');
		break;
	case MKTAG('M', 'L', 'T', 'Y'):
	case MKTAG('P', 'G', 'R', 'P'):
	case MKTAG('P', 'T', 'I', 'C'):
		tagId = MKTAG('G', 'R', 'U', 'P');
		break;
	case MKTAG('P', 'K', 'U', 'P'):
	case MKTAG('S', 'E', 'X', '1'):
	case MKTAG('S', 'W', 'E', 'R'):
		tagId = MKTAG('R', 'U', 'D', 'E');
		break;
	case MKTAG('P', 'H', 'I', 'L'):
	case MKTAG('R', 'C', 'K', 'T'):
		tagId = MKTAG('S', 'C', 'I', 'E');
		break;
	case MKTAG('T', 'R', 'A', '2'):
	case MKTAG('T', 'R', 'A', '3'):
		tagId = MKTAG('T', 'R', 'A', 'V');
		break;

	}

	return TTnpcScript::handleQuote(roomScript, sentence, val, tagId, remainder);
}

int MaitreDScript::updateState(uint oldId, uint newId, int index) {
	if (getValue(8)) {
		if (oldId == 260112)
			return getRangeValue(260654);
		if (oldId != 260655 && oldId != 260654)
			return getRangeValue(260655);
	}

	newId = getStateDialogueId(oldId, newId);

	if (newId == 260023) {
		switch (getValue(13)) {
		case 1:
			newId = 260023; break;
		case 2:
			newId = 260024; break;
		case 3:
			newId = 260025; break;
		case 4:
			newId = 260026; break;
		case 5:
			newId = 260027; break;
		default:
			newId = 260016; break;
		}
	}

	if (newId == 260034) {
		switch (getValue(13)) {
		case 1:
			newId = 260034; break;
		case 2:
			newId = 260035; break;
		case 3:
			newId = 260036; break;
		case 4:
			newId = 260037; break;
		case 5:
			newId = 260038; break;
		default:
			newId = 260045; break;
		}
	}

	if (newId == 260070) {
		switch (getValue(13)) {
		case 1:
			newId = 260070; break;
		case 2:
			newId = 260071; break;
		case 3:
			newId = 260072; break;
		case 4:
			newId = 260073; break;
		case 5:
			newId = 260074; break;
		default:
			newId = 260110; break;
		}
	}

	if (newId == 260076 || newId == 260181 || newId == 261010) {
		CTrueTalkManager::setFlags(14, 1);
		trigger12(true);
		setFlags10(newId, index);
		return newId;
	}

	if (!getValue(12)) {
		static const uint FLAG_IDS[] = {
			260080, 260066, 260067, 260062, 260050, 260087, 260090, 260171, 260173,
			260184, 260193, 260202, 260205, 260220, 260221, 260223, 260231, 260232,
			260365, 260373, 260374, 260387, 260421, 260622, 260695, 0
		};

		for (uint idx = 0; FLAG_IDS[idx]; ++idx) {
			if (FLAG_IDS[idx] == newId) {
				setFlags12();
				break;
			}
		}
	}

	if (newId == 261018) {
		if (getValue(8) == 0 && getValue(9) == 0) {
			newId = getRangeValue(260961);
			setFlags10(newId, index);
			return newId;
		}

		if (getValue(8) == 1 && getValue(9) == 1) {
			newId = getRangeValue(260655);
			setFlags10(newId, index);
			return newId;
		}

		if (getValue(9) && getValue(16)) {
			newId = getValue(16);
			setFlags10(newId, index);
			return index;
		}

		newId = 260989;
	}

	setFlags10(newId, index);
	return newId;
}

int MaitreDScript::preResponse(uint id) {
	if (id == 60911)
		return 260101;

	return 0;
}

int MaitreDScript::proc23() const {
	warning("TODO");
	return 0;
}

int MaitreDScript::doSentenceEntry(int val1, const int *srcIdP, TTroomScript *roomScript, TTsentence *sentence) {
	warning("TODO");
	return 0;
}

uint MaitreDScript::getStateDialogueId(uint oldId, uint newId) {
	if (getValue(8) || getValue(9))
		return newId;

	switch (newId) {
	case 260009:
	case 260010:
	case 260011:
	case 260012:
		return getRangeValue(260961);
	case 260052:
		return 260094;
	case 260203:
		return 260204;
	case 260211:
	case 260212:
	case 260761:
	case 260986:
	case 260987:
	case 260989:
		return getRangeValue(260961);
	case 260263:
	case 260264:
		return 260265;
	case 260411:
		return 260457;
	case 260427:
	case 260053:
	case 260054:
	case 260055:
	case 260056:
	case 260057:
	case 260058:
	case 260059:
	case 260060:
		return 260135;
	case 260698:
	case 260895:
	case 260896:
		return 260457;
	case 260799:
		return 260214;

	default:
		return newId;
	}
}


void MaitreDScript::setFlags12() {
	int val = getValue(12);
	CTrueTalkManager::setFlags(12, 1);

	if (!val) {
		CTrueTalkManager::triggerAction(8, 0);
		resetRange(260121);
		resetRange(260122);
		resetRange(260123);
		resetRange(260124);
		resetRange(260125);
		resetRange(260126);
	}
}

void MaitreDScript::setFlags10(uint newId, uint index) {
	int val = 28;
	for (uint idx = 0; idx < _states.size(); ++idx) {
		TTmapEntry &us = _states[idx];
		if (us._src == newId) {
			val = us._dest;
			break;
		}
	}

	CTrueTalkManager::setFlags(10, val);
}

void MaitreDScript::trigger12(bool flag) {
	int val = getValue(12);
	CTrueTalkManager::setFlags(12, 0);

	if (val) {
		CTrueTalkManager::triggerAction(flag ? 10 : 9, 0);
	}
}

} // End of namespace Titanic