aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/myst_stacks/preview.cpp
blob: eaa311b75b90b202bc1ace406105b71794a1598d (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
/* 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 "mohawk/cursors.h"
#include "mohawk/myst.h"
#include "mohawk/myst_areas.h"
#include "mohawk/myst_graphics.h"
#include "mohawk/myst_sound.h"
#include "mohawk/video.h"
#include "mohawk/myst_stacks/preview.h"

#include "common/system.h"
#include "gui/message.h"

namespace Mohawk {
namespace MystStacks {

Preview::Preview(MohawkEngine_Myst *vm) :
		Myst(vm, kDemoPreviewStack) {
	setupOpcodes();
	_vm->_cursor->hideCursor();

	_libraryState = 0;
	_library = nullptr;

	_speechRunning = false;
	_speechStep = 0;
	_currentCue = 0;
	_speechNextTime = 0;
}

Preview::~Preview() {
}

void Preview::setupOpcodes() {
	// "Stack-Specific" Opcodes
	OVERRIDE_OPCODE(196, Preview, o_fadeToBlack);
	OVERRIDE_OPCODE(197, Preview, o_fadeFromBlack);
	OVERRIDE_OPCODE(198, Preview, o_stayHere);
	OVERRIDE_OPCODE(199, Preview, o_speechStop);

	// "Init" Opcodes
	OVERRIDE_OPCODE(209, Preview, o_libraryBookcaseTransformDemo_init);
	REGISTER_OPCODE(298, Preview, o_speech_init);
	REGISTER_OPCODE(299, Preview, o_library_init);
}

void Preview::disablePersistentScripts() {
	Myst::disablePersistentScripts();
}

void Preview::runPersistentScripts() {
	Myst::runPersistentScripts();

	if (_speechRunning)
		speech_run();
}

void Preview::o_fadeToBlack(uint16 var, const ArgumentsArray &args) {
	_vm->_gfx->fadeToBlack();
}

void Preview::o_fadeFromBlack(uint16 var, const ArgumentsArray &args) {

	_vm->_gfx->fadeFromBlack();
}

void Preview::o_stayHere(uint16 var, const ArgumentsArray &args) {
	// Nuh-uh! No leaving the library in the demo!
	GUI::MessageDialog dialog("You can't leave the library in the demo.");
	dialog.runModal();
}

void Preview::o_speechStop(uint16 var, const ArgumentsArray &args) {
	_vm->_sound->stopSpeech();
	_speechRunning = false;
	_globals.currentAge = kMystLibrary;
}

void Preview::speechUpdateCue() {
	// This is a callback in the original, handling audio events.
	if (!_vm->_sound->isSpeechPlaying()) {
		return;
	}

	uint samples = _vm->_sound->getSpeechNumSamplesPlayed();
	for (int16 i = 0; i < _cueList.pointCount; i++) {
		if (_cueList.points[i].sampleFrame > samples)
			return;
		if (i > _currentCue - 1) {
			_currentCue++;
			debugC(kDebugScript, "Sneak speech advanced to cue %d", _currentCue);
		}
	}
}

void Preview::speech_run() {
	uint32 time = _vm->getTotalPlayTime();

	// Update current speech sound cue
	speechUpdateCue();

	switch (_speechStep) {
	case 0: // Start Voice Over... which controls book opening
		_currentCue = 0;
			_vm->_sound->playSpeech(3001, &_cueList);

		_speechStep++;
		break;
	case 1: // Open book
		if (_currentCue >= 1) {
			_vm->changeToCard(3001, kTransitionDissolve);

			_speechStep++;
		}
		break;
	case 2: // Go to Myst
		if (_currentCue >= 2) {
			_vm->_gfx->fadeToBlack();
			_vm->changeToCard(3002, kNoTransition);
			_vm->_gfx->fadeFromBlack();

			_speechStep++;
		}
		break;
	case 3: // Start blinking the library
		if (_currentCue >= 3) {
			_libraryState = 1;
			_speechNextTime = 0;
			_speechStep++;
		}
		break;
	case 4: // Library blinking, zoom in library
		if (_currentCue >= 4) {
			_library->drawConditionalDataToScreen(0);

			_vm->changeToCard(3003, kTransitionDissolve);

			_speechNextTime = time + 2000;
			_speechStep++;
		} else {
			if (time < _speechNextTime)
				break;

			_library->drawConditionalDataToScreen(_libraryState);
			_libraryState = (_libraryState + 1) % 2;
			_speechNextTime = time + 500;
		}
		break;
	case 5: // Go to library near view
		if (time < _speechNextTime)
			break;

		_vm->changeToCard(3004, kTransitionDissolve);
		_speechNextTime = time + 2000;
		_speechStep++;
		break;
	case 6: // Fade to courtyard
		if (time < _speechNextTime)
			break;

		_vm->_gfx->fadeToBlack();
		_vm->changeToCard(3005, kNoTransition);
		_vm->_gfx->fadeFromBlack();
		_speechNextTime = time + 1000;
		_speechStep++;
		break;
	case 7: // Walk to library
	case 8:
	case 9:
	case 10:
	case 11:
	case 12:
	case 13:
		if (time < _speechNextTime)
			break;

		_vm->changeToCard(3006 + _speechStep - 7, kTransitionDissolve);
		_speechNextTime = time + 2000;
		_speechStep++;
		break;
	case 14: // Go to playable library card
		if (time < _speechNextTime)
			break;

		_vm->changeToCard(4329, kTransitionDissolve);

		_speechRunning = false;
		_globals.currentAge = kMystLibrary;

		_vm->_cursor->showCursor();
		break;
	default:
		warning("Unknown speech step");
		break;
	}
}

void Preview::o_speech_init(uint16 var, const ArgumentsArray &args) {
	// Used for Card 3000 (Closed Myst Book)
	_speechStep = 0;
	_speechRunning = true;
}

void Preview::o_library_init(uint16 var, const ArgumentsArray &args) {
	// Used for Card 3002 (Myst Island Overview)
	_library = getInvokingResource<MystAreaImageSwitch>();
}

void Preview::o_libraryBookcaseTransformDemo_init(uint16 var, const ArgumentsArray &args) {
	if (_libraryBookcaseChanged) {
		MystAreaActionSwitch *resource = getInvokingResource<MystAreaActionSwitch>();
		_libraryBookcaseMovie = static_cast<MystAreaVideo *>(resource->getSubResource(getVar(303)));
		_libraryBookcaseSoundId = args[0];
		_libraryBookcaseMoving = true;
	}
}

void Preview::libraryBookcaseTransform_run() {
	if (_libraryBookcaseChanged)
		_state.libraryBookcaseDoor = !_state.libraryBookcaseDoor;

	Myst::libraryBookcaseTransform_run();
}


} // End of namespace MystStacks
} // End of namespace Mohawk