aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/myst_stacks/channelwood.cpp
blob: b710b426b4c03a359f09fbd4fdac5ee186cd8258 (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
/* 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$
 * $Id$
 *
 */

#include "mohawk/myst.h"
#include "mohawk/graphics.h"
#include "mohawk/myst_areas.h"
#include "mohawk/sound.h"
#include "mohawk/video.h"
#include "mohawk/myst_stacks/channelwood.h"

#include "gui/message.h"

namespace Mohawk {

MystScriptParser_Channelwood::MystScriptParser_Channelwood(MohawkEngine_Myst *vm) : MystScriptParser(vm) {
	setupOpcodes();
}

MystScriptParser_Channelwood::~MystScriptParser_Channelwood() {
}

#define OPCODE(op, x) _opcodes.push_back(new MystOpcode(op, (OpcodeProcMyst) &MystScriptParser_Channelwood::x, #x))

void MystScriptParser_Channelwood::setupOpcodes() {
	// "Stack-Specific" Opcodes
	OPCODE(101, opcode_101);
	OPCODE(102, opcode_102);
	OPCODE(104, opcode_104);
	OPCODE(117, opcode_117);
	OPCODE(118, opcode_118);
	OPCODE(119, opcode_119);
	OPCODE(122, opcode_122);
	OPCODE(127, opcode_127);
	OPCODE(129, opcode_129);

	// "Init" Opcodes
	OPCODE(201, opcode_201);
	OPCODE(202, opcode_202);
	OPCODE(203, opcode_203);

	// "Exit" Opcodes
	OPCODE(300, opcode_300);
}

#undef OPCODE

void MystScriptParser_Channelwood::disablePersistentScripts() {
	opcode_202_disable();
	opcode_203_disable();
}

void MystScriptParser_Channelwood::runPersistentScripts() {
	opcode_202_run();
	opcode_203_run();
}

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

	if (argc == 1) {
		debugC(kDebugScript, "Opcode %d: Play Pipe Movie and Sound", op);

		uint16 soundId = argv[0];
		debugC(kDebugScript, "\tsoundId: %d", soundId);

		_vm->_sound->playSound(soundId);

		// TODO: Get Movie Location from Invoking Resource Rect, rather than
		//       hardcoded 267, 170 ?

		// TODO: Need version of playMovie blocking which allows selection
		//       of start and finish points.
		if (!_vm->_varStore->getVar(6)) {
			// Play Pipe Extending i.e. 0 to 1/2 way through file
			_vm->_video->playMovie(_vm->wrapMovieFilename("pipebrid", kChannelwoodStack), 267, 170);
		} else {
			// Play Pipe Retracting i.e. 1/2 way to end of file
			_vm->_video->playMovie(_vm->wrapMovieFilename("pipebrid", kChannelwoodStack), 267, 170);
		}
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_102(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 2 || argc == 3) {
		debugC(kDebugScript, "Opcode %d: Draw Full Screen Image, Optional Delay and Change Card", op);

		uint16 imageId = argv[0];
		uint16 cardId = argv[1];
		uint16 delay = 0;

		if (argc == 3)
			delay = argv[2]; // TODO: Not sure about purpose of this parameter...

		debugC(kDebugScript, "\timageId: %d", imageId);
		debugC(kDebugScript, "\tcardId: %d", cardId);
		debugC(kDebugScript, "\tdelay: %d", delay);

		_vm->_gfx->copyImageToScreen(imageId, Common::Rect(0, 0, 544, 333));
		_vm->_system->delayMillis(delay / 100);
		_vm->changeToCard(cardId, true);
	} else
		unknown(op, var, argc, argv);
}


void MystScriptParser_Channelwood::opcode_104(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used on Channelwood Card 3280
	if (argc == 0) {
		debugC(kDebugScript, "Opcode %d: Do Water Tank Valve Open Animation", op);
		Common::Rect rect = _invokingResource->getRect();

		// TODO: Need to load the image ids from Script Resources structure of VIEW
		for (uint16 imageId = 3595; imageId <= 3601; imageId++) {
			_vm->_gfx->copyImageToScreen(imageId, rect);
			_vm->_system->delayMillis(50);
		}

		// TODO: Is 8 gotten from var7 of calling hotspot, rather than hardcoded?
		_vm->_varStore->setVar(8, 1);
		_vm->_varStore->setVar(19, 1);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_117(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 1) {
		// Used on Card 3012 (Temple Hologram Monitor)
		uint16 button = argv[0]; // 0 to 3
		_vm->_varStore->setVar(17, button);

		switch (button) {
		case 0:
			_vm->_video->playMovie(_vm->wrapMovieFilename("monalgh", kChannelwoodStack), 227, 71);
			break;
		case 1:
			_vm->_video->playMovie(_vm->wrapMovieFilename("monamth", kChannelwoodStack), 227, 71);
			break;
		case 2:
			_vm->_video->playMovie(_vm->wrapMovieFilename("monasirs", kChannelwoodStack), 227, 71);
			break;
		case 3:
			_vm->_video->playMovie(_vm->wrapMovieFilename("monsmsg", kChannelwoodStack), 227, 71);
			break;
		default:
			warning("Opcode %d Control Variable Out of Range", op);
			break;
		}
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_118(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 0) {
		// Used on Card 3318 (Sirrus' Room Nightstand Drawer)
		// Triggered when clicked on drawer
		// TODO: Implement function...
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_119(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 0) {
		// Used on Card 3333 (Temple Hologram)
		// TODO: Not 100% sure about movie position...
		switch (_vm->_varStore->getVar(17)) {
		case 0:
			_vm->_video->playMovie(_vm->wrapMovieFilename("holoalgh", kChannelwoodStack), 126, 74);
			break;
		case 1:
			_vm->_video->playMovie(_vm->wrapMovieFilename("holoamth", kChannelwoodStack), 126, 74);
			break;
		case 2:
			_vm->_video->playMovie(_vm->wrapMovieFilename("holoasir", kChannelwoodStack), 126, 74);
			break;
		case 3:
			_vm->_video->playMovie(_vm->wrapMovieFilename("holosmsg", kChannelwoodStack), 126, 74);
			break;
		default:
			warning("Opcode %d Control Variable Out of Range", op);
			break;
		}
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_122(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	// Used on Channelwood Card 3280
	if (argc == 0) {
		debugC(kDebugScript, "Opcode %d: Do Water Tank Valve Close Animation", op);
		Common::Rect rect = _invokingResource->getRect();

		// TODO: Need to load the image ids from Script Resources structure of VIEW
		for (uint16 imageId = 3601; imageId >= 3595; imageId--) {
			_vm->_gfx->copyImageToScreen(imageId, rect);
			_vm->_system->delayMillis(50);
		}

		// TODO: Is 8 gotten from var7 of calling hotspot, rather than hard-coded?
		_vm->_varStore->setVar(8, 0);
		_vm->_varStore->setVar(19, 0);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_127(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 2) {
		// Used by Card 3262 (Elevator)
		debugC(kDebugScript, "Opcode %d: Unknown...", op);

		uint16 u0 = argv[0];
		uint16 u1 = argv[1];

		debugC(kDebugScript, "\tu0: %d", u0);
		debugC(kDebugScript, "\tu1: %d", u1);

		// TODO: Fill in Code...
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_129(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	varUnusedCheck(op, var);

	if (argc == 1) {
		// Used by Card 3262 (Elevator)
		debugC(kDebugScript, "Opcode %d: Unknown...", op);

		uint16 cardId = argv[0];

		debugC(kDebugScript, "\tcardId: %d", cardId);

		// TODO: Fill in Code...
		_vm->changeToCard(cardId, true);
	} else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_201(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	// Used for Card 3247 (Elevator #1 Movement), 3161 (Bridge Movement), 3259 (Elevator #3 Movement) and 3252 (Elevator #2 Movement)
	if (argc == 0) {
		// TODO: Fill in Function. Video Playback? Rect from invoking hotspot resource...
		if (false) {
			// Card 3161
			_vm->_video->playMovie(_vm->wrapMovieFilename("bridge", kChannelwoodStack), 292, 204);

			// Card 3247
			_vm->_video->playMovie(_vm->wrapMovieFilename("welev1dn", kChannelwoodStack), 214, 107);
			_vm->_video->playMovie(_vm->wrapMovieFilename("welev1up", kChannelwoodStack), 214, 107);

			// Card 3252
			_vm->_video->playMovie(_vm->wrapMovieFilename("welev2dn", kChannelwoodStack), 215, 118);
			_vm->_video->playMovie(_vm->wrapMovieFilename("welev2up", kChannelwoodStack), 215, 118);

			// Card 3259
			_vm->_video->playMovie(_vm->wrapMovieFilename("welev3dn", kChannelwoodStack), 213, 99);
			_vm->_video->playMovie(_vm->wrapMovieFilename("welev3up", kChannelwoodStack), 213, 99);
		}
	} else
		unknown(op, var, argc, argv);
}

static struct {
	bool enabled;
	uint16 var;
} g_opcode202Parameters;

void MystScriptParser_Channelwood::opcode_202_run(void) {
	if (g_opcode202Parameters.enabled) {
		// Used for Cards 3328, 3691, 3731, 3809, 3846 etc. (Water Valves)

		// Code for Water Flow Logic
		// Var 8 = "Water Tank Valve State"
		// Controls
		// Var 19 = "Water Flowing to First Water Valve"
		// Code for this in Opcode 104 / 122

		// Var 19 = "Water Flowing to First Water Valve"
		// and
		// Var 9 = "First Water Valve State"
		// Controls
		// Var 20 = "Water Flowing to Second (L) Water Valve"
		// Var 3 = "Water Flowing (R) to Pump for Upper Walkway to Temple Elevator"
		uint16 var9 = _vm->_varStore->getVar(9);
		if (_vm->_varStore->getVar(19)) {
			_vm->_varStore->setVar(20, !var9);
			_vm->_varStore->setVar(3, var9);
		} else {
			// No water into Valve
			_vm->_varStore->setVar(20, 0);
			_vm->_varStore->setVar(3, 0);
		}

		// Var 20 = "Water Flowing to Second (L) Water Valve"
		// and
		// Var 10 = "Second (L) Water Valve State"
		// Controls
		// Var 24 = "Water Flowing to Third (L, L) Water Valve"
		// Var 21 = "Water Flowing to Third (L, R) Water Valve"
		uint16 var10 = _vm->_varStore->getVar(10);
		if (_vm->_varStore->getVar(20)) {
			_vm->_varStore->setVar(24, !var10);
			_vm->_varStore->setVar(21, var10);
		} else {
			// No water into Valve
			_vm->_varStore->setVar(24, 0);
			_vm->_varStore->setVar(21, 0);
		}

		// Var 21 = "Water Flowing to Third (L, R) Water Valve"
		// and
		// Var 11 = "Third (L, R) Water Valve State"
		// Controls
		// Var 23 = "Water Flowing to Fourth (L, R, L) Water Valve"
		// Var 22 = "Water Flowing to Fourth (L, R, R) Water Valve"
		uint16 var11 = _vm->_varStore->getVar(11);
		if (_vm->_varStore->getVar(21)) {
			_vm->_varStore->setVar(23, !var11);
			_vm->_varStore->setVar(22, var11);
		} else {
			// No water into Valve
			_vm->_varStore->setVar(23, 0);
			_vm->_varStore->setVar(22, 0);
		}

		// Var 24 = "Water Flowing to Third (L, L) Water Valve"
		// and
		// Var 14 = "Third (L, L) Water Valve State"
		// Controls
		// Var 29 = "Water Flowing to Pipe In Water (L, L, L)"
		// Var 28 = "Water Flowing to Join and Pump Bridge (L, L, R)"
		uint16 var14 = _vm->_varStore->getVar(14);
		if (_vm->_varStore->getVar(24)) {
			_vm->_varStore->setVar(29, !var14);
			_vm->_varStore->setVar(28, var14);
		} else {
			// No water into Valve
			_vm->_varStore->setVar(29, 0);
			_vm->_varStore->setVar(28, 0);
		}

		// Var 22 = "Water Flowing to Fourth (L, R, R) Water Valve"
		// and
		// Var 12 = "Fourth (L, R, R) Water Valve State"
		// Controls
		// Var 25 = "Water Flowing to Pipe Bridge (L, R, R, L)"
		// Var 15 = "Water Flowing (L, R, R, R) to Pump for Lower Walkway to Upper Walkway Elevator"
		uint16 var12 = _vm->_varStore->getVar(12);
		if (_vm->_varStore->getVar(22)) {
			_vm->_varStore->setVar(25, !var12);
			_vm->_varStore->setVar(15, var12);
		} else {
			// No water into Valve
			_vm->_varStore->setVar(25, 0);
			_vm->_varStore->setVar(15, 0);
		}

		// Var 23 = "Water Flowing to Fourth (L, R, L) Water Valve"
		// and
		// Var 13 = "Fourth (L, R, L) Water Valve State"
		// Controls
		// Var 27 = "Water Flowing to Join and Pump Bridge (L, R, L, L)"
		// Var 26 = "Water Flowing to Pipe At Entry Point (L, R, L, R)"
		uint16 var13 = _vm->_varStore->getVar(13);
		if (_vm->_varStore->getVar(23)) {
			_vm->_varStore->setVar(27, !var13);
			_vm->_varStore->setVar(26, var13);
		} else {
			// No water into Valve
			_vm->_varStore->setVar(27, 0);
			_vm->_varStore->setVar(26, 0);
		}

		// TODO: Not sure that original had OR logic for water flow at Join...
		// Var 27 = "Water Flowing to Join and Pump Bridge (L, R, L, L)"
		// Or
		// Var 28 = "Water Flowing to Join and Pump Bridge (L, L, R)"
		// Controls
		// Var 31 = "Water Flowing to Join (L, L, R)" // 0 to 2 = Stop Sound, Background, Background with Water Flow
		// Var 7 = "Bridge Pump Running"
		// TODO: Not sure about control of Var 31 which is tristate...
		if (_vm->_varStore->getVar(27) || _vm->_varStore->getVar(28)) {
			_vm->_varStore->setVar(31, 2); // Background with Water Flow
			_vm->_varStore->setVar(7, 1);
		} else {
			// No water into Valve
			_vm->_varStore->setVar(31, 1); // Background
			_vm->_varStore->setVar(7, 0);
		}

		// TODO: Code for this shouldn't be here...
		//       Move to Opcodes called by Pipe Extension...
		// Var 25 = "Water Flowing to Pipe Bridge (L, R, R, L)"
		// and
		// Var 6 = "Pipe Bridge Extended"
		// Controls
		// Var 32 = "Water Flowing (L, R, R, L, Pipe) State" }, // 0 to 2 = Stop Sound, Background, Background with Water Flow
		// Var 4 = "Water Flowing (L, R, R, L, Pipe Extended) to Pump for Book Room Elevator"
		// TODO: Not sure about control of Var 32 which is tristate...
		if (_vm->_varStore->getVar(25) && _vm->_varStore->getVar(6)) {
			_vm->_varStore->setVar(32, 2); // Background with Water Flow
			_vm->_varStore->setVar(4, 1);
		} else {
			// No water into Valve
			_vm->_varStore->setVar(32, 1); // Background
			_vm->_varStore->setVar(4, 0);
		}
	}
}

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

void MystScriptParser_Channelwood::opcode_202(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	// Used for Cards 3328, 3691, 3731, 3809, 3846 etc. (Water Valves)
	if (argc == 0) {
		g_opcode202Parameters.var = var;
		g_opcode202Parameters.enabled = true;
	} else
		unknown(op, var, argc, argv);
}

static struct {
	bool enabled;
} g_opcode203Parameters;

void MystScriptParser_Channelwood::opcode_203_run(void) {
	if (g_opcode203Parameters.enabled) {
		// Used for Card 3310 (Sirrus' Room Right Bed Drawer),
		// Card 3307 (Sirrus' Room Left Bed Drawer)
		// and Card 3318 (Sirrus' Room Nightstand Drawer)
		// TODO: Fill in Logic...
	}
}

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

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

	// Used for Card 3310 (Sirrus' Room Right Bed Drawer),
	// Card 3307 (Sirrus' Room Left Bed Drawer)
	// and Card 3318 (Sirrus' Room Nightstand Drawer)
	if (argc == 0)
		g_opcode203Parameters.enabled = true;
	else
		unknown(op, var, argc, argv);
}

void MystScriptParser_Channelwood::opcode_300(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	// Used in Card 3012 (Achenar's Holoprojector Control)
	varUnusedCheck(op, var);
	// TODO: Fill in Logic. Clearing Variable for View?
}

} // End of namespace Mohawk