1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "mohawk/myst.h"
24 #include "mohawk/myst_areas.h"
25 #include "mohawk/myst_graphics.h"
26 #include "mohawk/myst_state.h"
27 #include "mohawk/sound.h"
28 #include "mohawk/video.h"
29 #include "mohawk/myst_stacks/intro.h"
30 
31 namespace Mohawk {
32 namespace MystStacks {
33 
Intro(MohawkEngine_Myst * vm,MystStack stackId)34 Intro::Intro(MohawkEngine_Myst *vm, MystStack stackId) :
35 		MystScriptParser(vm, stackId),
36 		_introMoviesRunning(false),
37 		_introStep(0),
38 		_linkBookRunning(false),
39 		_linkBookMovie(nullptr) {
40 	setupOpcodes();
41 }
42 
~Intro()43 Intro::~Intro() {
44 }
45 
setupOpcodes()46 void Intro::setupOpcodes() {
47 	// "Stack-Specific" Opcodes
48 	REGISTER_OPCODE(100, Intro, o_useLinkBook);
49 
50 	// "Init" Opcodes
51 	REGISTER_OPCODE(200, Intro, o_playIntroMovies);
52 	REGISTER_OPCODE(201, Intro, o_mystLinkBook_init);
53 
54 	// "Exit" Opcodes
55 	REGISTER_OPCODE(300, Intro, NOP);
56 }
57 
disablePersistentScripts()58 void Intro::disablePersistentScripts() {
59 	_introMoviesRunning = false;
60 	_linkBookRunning = false;
61 }
62 
runPersistentScripts()63 void Intro::runPersistentScripts() {
64 	if (_introMoviesRunning)
65 		introMovies_run();
66 
67 	if (_linkBookRunning)
68 		mystLinkBook_run();
69 }
70 
getVar(uint16 var)71 uint16 Intro::getVar(uint16 var) {
72 	switch(var) {
73 	case 0:
74 		if (_globals.currentAge == kSirrusEnding || _globals.currentAge == kAchenarEnding)
75 			return 2;
76 		else
77 			return _globals.currentAge;
78 	default:
79 		return MystScriptParser::getVar(var);
80 	}
81 }
82 
o_useLinkBook(uint16 var,const ArgumentsArray & args)83 void Intro::o_useLinkBook(uint16 var, const ArgumentsArray &args) {
84 	// Hard coded SoundId valid only for Intro Stack.
85 	// Other stacks use Opcode 40, which takes SoundId values as arguments.
86 	const uint16 soundIdLinkSrc = 5;
87 	const uint16 soundIdLinkDst[] = { 2282, 3029, 6396, 7122, 3137, 0, 9038, 5134, 0, 4739, 4741 };
88 
89 	// Change to dest stack
90 	_vm->changeToStack(_stackMap[_globals.currentAge], _startCard[_globals.currentAge], soundIdLinkSrc, soundIdLinkDst[_globals.currentAge]);
91 }
92 
introMovies_run()93 void Intro::introMovies_run() {
94 	// Play Intro Movies
95 	// This is all quite messy...
96 
97 	VideoEntryPtr video;
98 
99 	switch (_introStep) {
100 	case 0:
101 		_introStep = 1;
102 		video = _vm->playMovieFullscreen("broder", kIntroStack);
103 		break;
104 	case 1:
105 		if (!_vm->_video->isVideoPlaying())
106 			_introStep = 2;
107 		break;
108 	case 2:
109 		_introStep = 3;
110 		video = _vm->playMovieFullscreen("cyanlogo", kIntroStack);
111 		break;
112 	case 3:
113 		if (!_vm->_video->isVideoPlaying())
114 			_introStep = 4;
115 		break;
116 	case 4:
117 		_introStep = 5;
118 
119 		if (!(_vm->getFeatures() & GF_DEMO)) { // The demo doesn't have the intro video
120 			video = _vm->playMovieFullscreen("intro", kIntroStack);
121 		}
122 		break;
123 	case 5:
124 		if (!_vm->_video->isVideoPlaying())
125 			_introStep = 6;
126 		break;
127 	default:
128 		if (_vm->getFeatures() & GF_DEMO)
129 			_vm->changeToCard(2001, kTransitionRightToLeft);
130 		else
131 			_vm->changeToCard(2, kTransitionRightToLeft);
132 	}
133 }
134 
o_playIntroMovies(uint16 var,const ArgumentsArray & args)135 void Intro::o_playIntroMovies(uint16 var, const ArgumentsArray &args) {
136 	_introMoviesRunning = true;
137 
138 	if (_vm->getFeatures() & GF_25TH) {
139 		// In the 25th anniversary version, the Broderbund / Cyan Logo were already shown
140 		// before the main menu. No need to play them again here.
141 		_introStep = 4;
142 	} else {
143 		_introStep = 0;
144 	}
145 }
146 
mystLinkBook_run()147 void Intro::mystLinkBook_run() {
148 	if (_startTime == 1) {
149 		_startTime = 0;
150 
151 		if (!_vm->wait(5000, true)) {
152 			_linkBookMovie->playMovie();
153 			_vm->_gfx->copyImageToBackBuffer(4, Common::Rect(544, 333));
154 			_vm->_gfx->copyBackBufferToScreen(Common::Rect(544, 333));
155 		}
156 	} else if (!_linkBookMovie->isPlaying()) {
157 		_vm->changeToCard(5, kTransitionRightToLeft);
158 	}
159 }
160 
o_mystLinkBook_init(uint16 var,const ArgumentsArray & args)161 void Intro::o_mystLinkBook_init(uint16 var, const ArgumentsArray &args) {
162 	_linkBookMovie = getInvokingResource<MystAreaVideo>();
163 	_startTime = 1;
164 	_linkBookRunning = true;
165 }
166 
167 } // End of namespace MystStacks
168 } // End of namespace Mohawk
169