aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/myst_scripts_selenitic.cpp
blob: c2b42f844ef78c75f6dc4926d13ff210eab791bc (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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/* 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.
 *
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/engines/mohawk/myst_scripts.cpp $
 * $Id: myst_scripts.cpp 54107 2010-11-07 01:03:29Z fingolfin $
 *
 */

#include "mohawk/myst.h"
#include "mohawk/graphics.h"
#include "mohawk/myst_scripts_selenitic.h"
#include "mohawk/sound.h"
#include "mohawk/video.h"

#include "gui/message.h"

namespace Mohawk {

#define OPCODE(op, x) { op, &MystScriptParser::x, #x }
#define SPECIFIC_OPCODE(op, x) { op, (OpcodeProcMyst) &MystScriptParser_Selenitic::x, #x }

MystScriptParser_Selenitic::MystScriptParser_Selenitic(MohawkEngine_Myst *vm) : MystScriptParser(vm) {
	setupOpcodes();
	_invokingResource = NULL;
}

MystScriptParser_Selenitic::~MystScriptParser_Selenitic() {
}

void MystScriptParser_Selenitic::setupOpcodes() {
	// "invalid" opcodes do not exist or have not been observed
	// "unknown" opcodes exist, but their meaning is unknown

	static const MystOpcode myst_opcodes[] = {
		// "Standard" Opcodes
		{ 0, &MystScriptParser::toggleBoolean, "toggleBoolean" },
		//OPCODE(0, toggleBoolean),
		OPCODE(1, setVar),
		OPCODE(2, altDest),
		OPCODE(3, takePage),
		OPCODE(4, opcode_4),
		// TODO: Opcode 5 Not Present
		OPCODE(6, opcode_6),
		OPCODE(7, opcode_7),
		OPCODE(8, opcode_8),
		OPCODE(9, opcode_9),
		// TODO: Opcode 10 to 11 Not Present
		OPCODE(12, altDest),
		OPCODE(13, altDest),
		OPCODE(14, opcode_14),
		OPCODE(15, dropPage),
		OPCODE(16, opcode_16),
		OPCODE(17, opcode_17),
		OPCODE(18, opcode_18),
		OPCODE(19, enableHotspots),
		OPCODE(20, disableHotspots),
		OPCODE(21, opcode_21),
		OPCODE(22, opcode_22),
		OPCODE(23, opcode_23),
		OPCODE(24, playSound),
		// TODO: Opcode 25 Not Present
		OPCODE(26, opcode_26),
		OPCODE(27, playSoundBlocking),
		OPCODE(28, opcode_28),
		OPCODE(29, opcode_29_33),
		OPCODE(30, opcode_30),
		OPCODE(31, opcode_31),
		OPCODE(32, opcode_32),
		OPCODE(33, opcode_29_33),
		OPCODE(34, opcode_34),
		OPCODE(35, opcode_35),
		OPCODE(36, changeCursor),
		OPCODE(37, hideCursor),
		OPCODE(38, showCursor),
		OPCODE(39, opcode_39),
		OPCODE(40, changeStack),
		OPCODE(41, opcode_41),
		OPCODE(42, opcode_42),
		OPCODE(43, opcode_43),
		OPCODE(44, opcode_44),
		// TODO: Opcode 45 Not Present
		OPCODE(46, opcode_46),
		// TODO: Opcodes 47 to 99 Not Present

		// "Stack-Specific" Opcodes
		SPECIFIC_OPCODE(101, opcode_101),
		SPECIFIC_OPCODE(105, opcode_105),
		SPECIFIC_OPCODE(106, opcode_106),
		SPECIFIC_OPCODE(107, opcode_107),
		SPECIFIC_OPCODE(108, opcode_108),
		SPECIFIC_OPCODE(109, opcode_109),
		SPECIFIC_OPCODE(110, opcode_110),
		SPECIFIC_OPCODE(111, opcode_111),
		SPECIFIC_OPCODE(115, opcode_115),

		// "Init" Opcodes
		SPECIFIC_OPCODE(200, opcode_200),
		SPECIFIC_OPCODE(201, opcode_201),
		SPECIFIC_OPCODE(202, opcode_202),
		SPECIFIC_OPCODE(203, opcode_203),
		SPECIFIC_OPCODE(204, opcode_204),
		SPECIFIC_OPCODE(205, opcode_205),
		SPECIFIC_OPCODE(206, opcode_206),

		OPCODE(0xFFFF, NOP)
	};

	_opcodes = myst_opcodes;
	_opcodeCount = ARRAYSIZE(myst_opcodes);
}

void MystScriptParser_Selenitic::disableInitOpcodes() {
	opcode_200_disable();
	opcode_201_disable();
	opcode_202_disable();
	opcode_203_disable();
	opcode_204_disable();
	opcode_205_disable();
	opcode_206_disable();
}

void MystScriptParser_Selenitic::runPersistentOpcodes() {
	opcode_200_run();
	opcode_201_run();
	opcode_202_run();
	opcode_203_run();
	opcode_204_run();
	opcode_205_run();
	opcode_206_run();
}

void MystScriptParser_Selenitic::opcode_101(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 0) {
		// Used on Card 1191 (Maze Runner)
		// Called when Red Warning Button is pushed

		debugC(kDebugScript, "Opcode %d: Repeat Buzzer Sound?", op);

		// TODO: Fill in logic...
		// Repeat buzzer sound
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Selenitic::opcode_105(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	if (argc == 1) {
		uint16 soundId = argv[0];

		debugC(kDebugScript, "Opcode %d: Sound Receiver Water Button", op);
		debugC(kDebugScript, "\tvar: %d", var);

		// TODO: Complete Function including Var Change?
		_vm->_sound->playSound(soundId);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Selenitic::opcode_106(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	if (argc == 1) {
		uint16 soundId = argv[0];

		debugC(kDebugScript, "Opcode %d: Sound Receiver Volcanic Crack Button", op);
		debugC(kDebugScript, "\tvar: %d", var);

		// TODO: Complete Function including Var Change?
		_vm->_sound->playSound(soundId);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Selenitic::opcode_107(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	if (argc == 1) {
		uint16 soundId = argv[0];

		debugC(kDebugScript, "Opcode %d: Sound Receiver Clock Button", op);
		debugC(kDebugScript, "\tvar: %d", var);

		// TODO: Complete Function including Var Change?
		_vm->_sound->playSound(soundId);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Selenitic::opcode_108(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	if (argc == 1) {
		uint16 soundId = argv[0];

		debugC(kDebugScript, "Opcode %d: Sound Receiver Crystal Rocks Button", op);
		debugC(kDebugScript, "\tvar: %d", var);

		// TODO: Complete Function including Var Change?
		_vm->_sound->playSound(soundId);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Selenitic::opcode_109(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	if (argc == 1) {
		uint16 soundId = argv[0];

		debugC(kDebugScript, "Opcode %d: Sound Receiver Wind Button", op);
		debugC(kDebugScript, "\tvar: %d", var);

		// TODO: Complete Function including Var Change?
		_vm->_sound->playSound(soundId);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Selenitic::opcode_110(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 15) {
		// Used for Selenitic Maze Runner Exit Logic
		uint16 CardIdEntry = argv[0];
		uint16 CardIdExit = argv[1];
		uint16 u0 = argv[2];
		Common::Rect rect1 = Common::Rect(argv[3], argv[4], argv[5], argv[6]);
		uint16 rect1UpdateDirection = argv[7];
		uint16 u1 = argv[8];
		Common::Rect rect2 = Common::Rect(argv[9], argv[10], argv[11], argv[12]);
		uint16 rect2UpdateDirection = argv[13];
		uint16 u2 = argv[14];

		debugC(kDebugScript, "Opcode %d: Maze Runner Exit Logic and Door Open Animation", op);
		debugC(kDebugScript, "\tExit Card: %d", CardIdEntry);
		debugC(kDebugScript, "\tEntry Card: %d", CardIdExit);
		debugC(kDebugScript, "\tu0 (Exit Var?): %d", u0);

		debugC(kDebugScript, "\trect1.left: %d", rect1.left);
		debugC(kDebugScript, "\trect1.top: %d", rect1.top);
		debugC(kDebugScript, "\trect1.right: %d", rect1.right);
		debugC(kDebugScript, "\trect1.bottom: %d", rect1.bottom);
		debugC(kDebugScript, "\trect1 updateDirection: %d", rect1UpdateDirection);
		debugC(kDebugScript, "\tu1: %d", u1);

		debugC(kDebugScript, "\trect2.left: %d", rect2.left);
		debugC(kDebugScript, "\trect2.top: %d", rect2.top);
		debugC(kDebugScript, "\trect2.right: %d", rect2.right);
		debugC(kDebugScript, "\trect2.bottom: %d", rect2.bottom);
		debugC(kDebugScript, "\trect2 updateDirection: %d", rect2UpdateDirection);
		debugC(kDebugScript, "\tu2: %d", u2);

		// TODO: Finish Implementing Logic...
		// HACK: Bypass Higher Logic for now...
		_vm->changeToCard(argv[1]);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Selenitic::opcode_111(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 0) {
		// Used on Card 1245 (Sound Receiver)
		// Used by Source Selection Buttons...

		debugC(kDebugScript, "Opcode %d: Unknown", op);
		// TODO: Fill in Function...
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Selenitic::opcode_115(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	if (argc == 11) {
		// Used for Selenitic Card 1147 (Musical Door Lock Button)
		uint16 imageIdClose = argv[0]; // TODO: Sound Id?
		uint16 imageIdOpen = argv[1]; // TODO: Sound Id?

		uint16 cardIdOpen = argv[2];

		uint16 u0 = argv[3];
		uint16 u1 = argv[4];

		Common::Rect rect = Common::Rect(argv[5], argv[6], argv[7], argv[8]);

		uint16 updateDirection = argv[9];
		uint16 u2 = argv[10];

		debugC(kDebugScript, "Music Door Lock Logic...");
		debugC(kDebugScript, "\timageId (Close): %d", imageIdClose);
		debugC(kDebugScript, "\timageId (Open): %d", imageIdOpen);
		debugC(kDebugScript, "\tcardId (Open): %d", cardIdOpen);
		debugC(kDebugScript, "\tu0: %d", u0);
		debugC(kDebugScript, "\tu1: %d", u1);

		debugC(kDebugScript, "\trect.left: %d", rect.left);
		debugC(kDebugScript, "\trect.top: %d", rect.top);
		debugC(kDebugScript, "\trect.right: %d", rect.right);
		debugC(kDebugScript, "\trect.bottom: %d", rect.bottom);
		debugC(kDebugScript, "\trect updateDirection: %d", updateDirection);
		debugC(kDebugScript, "\tu2: %d", u2);

		// TODO: Fix Logic...
		// HACK: Bypass Door Lock For Now
		_vm->changeToCard(cardIdOpen);
	} else
		unknown(op, var, argc, argv);
}

// Selenitic Stack Movies For Maze Runner (Card 1191)
static const char* kHCMovPathSelenitic[36] = {
	"backa1",
	"backe1",
	"backf0",
	"backf1",
	"backl0",
	"backl1",
	"backo0",
	"backo1",
	"backp0",
	"backp1",
	"backr0",
	"backr1",
	"backs0",
	"backs1",
	"forwa1",
	"forwe0",
	"forwf0",
	"forwf1",
	"forwl0",
	"forwl1",
	"forwo0",
	"forwo1",
	"forwp0",
	"forwp1",
	"forwr0",
	"forwr1",
	"forws0",
	"forws1",
	"left00",
	"left01",
	"left10",
	"left11",
	"right00",
	"right01",
	"right10",
	"right11"
};

static struct {
	bool enabled;
} g_opcode200Parameters;

void MystScriptParser_Selenitic::opcode_200_run() {
	if (g_opcode200Parameters.enabled) {
		// Used on Card 1191 (Maze Runner)

		// TODO: Implementation Movie Function..
		if (false) {
			_vm->_video->playMovie(_vm->wrapMovieFilename(kHCMovPathSelenitic[0], kSeleniticStack), 201, 26);
		}
	}
}

void MystScriptParser_Selenitic::opcode_200_disable() {
	g_opcode200Parameters.enabled = false;
}

void MystScriptParser_Selenitic::opcode_200(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used for Card 1191 (Maze Runner)
	if (argc == 0) {
		g_opcode200Parameters.enabled = true;
	} else
		unknown(op, var, argc, argv);
}

static struct {
	bool enabled;
} g_opcode201Parameters;

void MystScriptParser_Selenitic::opcode_201_run() {

	if (g_opcode201Parameters.enabled) {
		// Used for Card 1191 (Maze Runner)

		// TODO: Fill in Function...
	}
}

void MystScriptParser_Selenitic::opcode_201_disable() {
	g_opcode201Parameters.enabled = false;
}

void MystScriptParser_Selenitic::opcode_201(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used for Card 1191 (Maze Runner)

	if (argc == 0) {
		g_opcode201Parameters.enabled = true;
	} else
		unknown(op, var, argc, argv);
}

static struct {
	bool enabled;
} g_opcode202Parameters;

void MystScriptParser_Selenitic::opcode_202_run(void) {
	if (g_opcode202Parameters.enabled) {
		// Used for Card 1191 (Maze Runner)

		// TODO: Fill in function...
	}
}

void MystScriptParser_Selenitic::opcode_202_disable(void) {
	g_opcode202Parameters.enabled = false;
}

void MystScriptParser_Selenitic::opcode_202(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used for Card 1191 (Maze Runner)
	if (argc == 0) {
		g_opcode202Parameters.enabled = true;
	} else
		unknown(op, var, argc, argv);
}

static struct {
	bool enabled;
} g_opcode203Parameters;

void MystScriptParser_Selenitic::opcode_203_run(void) {
	if (g_opcode203Parameters.enabled) {
		// Used for Card 1245 (Sound Receiver)
		// TODO: Fill in Logic to Change Viewer Display etc.?
	}
}

void MystScriptParser_Selenitic::opcode_203_disable(void) {
	g_opcode203Parameters.enabled = false;
}

void MystScriptParser_Selenitic::opcode_203(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used for Card 1245 (Sound Receiver)
	if (argc == 0) {
		g_opcode203Parameters.enabled = true;
	} else
		unknown(op, var, argc, argv);
}

static struct {
	bool enabled;
} g_opcode204Parameters;

void MystScriptParser_Selenitic::opcode_204_run(void) {
	if (g_opcode204Parameters.enabled) {
		// Used for Card 1147 (Sound Code Lock)
		// TODO: Fill in code for Sound Lock...
	}
}

void MystScriptParser_Selenitic::opcode_204_disable(void) {
	g_opcode204Parameters.enabled = false;
}

void MystScriptParser_Selenitic::opcode_204(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used for Card 1147 (Sound Code Lock)
	if (argc == 0) {
		g_opcode204Parameters.enabled = true;
	} else
		unknown(op, var, argc, argv);
}

static struct {
	bool enabled;
} g_opcode205Parameters;

void MystScriptParser_Selenitic::opcode_205_run(void) {
	if (g_opcode205Parameters.enabled) {
		// Used for Card 1191 (Maze Runner)
		// TODO: Fill in function...
	}
}

void MystScriptParser_Selenitic::opcode_205_disable(void) {
	g_opcode205Parameters.enabled = false;
}

void MystScriptParser_Selenitic::opcode_205(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used for Card 1191 (Maze Runner)
	if (argc == 0) {
		g_opcode205Parameters.enabled = true;
	} else
		unknown(op, var, argc, argv);
}

static struct {
	bool enabled;
} g_opcode206Parameters;

void MystScriptParser_Selenitic::opcode_206_run(void) {
	if (g_opcode206Parameters.enabled) {
		// Used for Card 1191 (Maze Runner)
		// TODO: Fill in function...
	}
}

void MystScriptParser_Selenitic::opcode_206_disable(void) {
	g_opcode206Parameters.enabled = false;
}

void MystScriptParser_Selenitic::opcode_206(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used for Card 1191 (Maze Runner)

	if (argc == 0) {
		g_opcode206Parameters.enabled = true;
	} else
		unknown(op, var, argc, argv);
}

} // End of namespace Mohawk