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 "common/scummsys.h"
24 #include "access/access.h"
25 #include "access/martian/martian_game.h"
26 #include "access/martian/martian_resources.h"
27 #include "access/martian/martian_scripts.h"
28 
29 namespace Access {
30 
31 namespace Martian {
32 
MartianScripts(AccessEngine * vm)33 MartianScripts::MartianScripts(AccessEngine *vm) : Scripts(vm) {
34 	_game = (MartianEngine *)_vm;
35 }
36 
cmdSpecial0()37 void MartianScripts::cmdSpecial0() {
38 	_vm->_sound->stopSound();
39 	_vm->_midi->stopSong();
40 
41 	_vm->_midi->loadMusic(47, 1);
42 	_vm->_midi->midiPlay();
43 	_vm->_midi->setLoop(true);
44 
45 	_vm->_events->_vbCount = 300;
46 	while (!_vm->shouldQuit() && _vm->_events->_vbCount > 0)
47 		_vm->_events->pollEventsAndWait();
48 
49 	_vm->_screen->forceFadeOut();
50 	_vm->_files->loadScreen("HOUSE.SC");
51 
52 	_vm->_video->setVideo(_vm->_screen, Common::Point(46, 30), "HVID.VID", 20);
53 
54 	do {
55 		_vm->_video->playVideo();
56 		if (_vm->_video->_videoFrame == 4) {
57 			_vm->_screen->flashPalette(16);
58 			_vm->_sound->playSound(4);
59 			do {
60 				_vm->_events->pollEvents();
61 			} while (!_vm->shouldQuit() && _vm->_sound->_playingSound);
62 			_vm->_timers[31]._timer = _vm->_timers[31]._initTm = 40;
63 		}
64 	} while (!_vm->_video->_videoEnd && !_vm->shouldQuit());
65 
66 	if (_vm->_video->_videoEnd) {
67 		_vm->_screen->flashPalette(12);
68 		_vm->_sound->playSound(4);
69 		do {
70 			_vm->_events->pollEvents();
71 		} while (!_vm->shouldQuit() && _vm->_sound->_playingSound);
72 		_vm->_midi->stopSong();
73 		_vm->_midi->freeMusic();
74 		warning("TODO: Pop Midi");
75 	}
76 }
77 
cmdSpecial1(int param1)78 void MartianScripts::cmdSpecial1(int param1) {
79 	_vm->_events->hideCursor();
80 
81 	if (param1 != -1) {
82 		_vm->_files->loadScreen(49, param1);
83 		_vm->_buffer2.copyBuffer(_vm->_screen);
84 	}
85 
86 	_vm->_screen->setIconPalette();
87 	_vm->_screen->forceFadeIn();
88 	_vm->_events->showCursor();
89 }
90 
cmdSpecial3()91 void MartianScripts::cmdSpecial3() {
92 	_vm->_screen->forceFadeOut();
93 	_vm->_events->hideCursor();
94 	_vm->_files->loadScreen(57, 3);
95 	_vm->_buffer2.copyFrom(*_vm->_screen);
96 
97 	_vm->_screen->setIconPalette();
98 	_vm->_events->showCursor();
99 	_vm->_screen->forceFadeIn();
100 }
101 
doIntro(int param1)102 void MartianScripts::doIntro(int param1) {
103 	_game->doSpecial5(param1);
104 }
105 
cmdSpecial6()106 void MartianScripts::cmdSpecial6() {
107 	_vm->_midi->stopSong();
108 	_vm->_screen->setDisplayScan();
109 	_vm->_events->clearEvents();
110 	_vm->_screen->forceFadeOut();
111 	_vm->_events->hideCursor();
112 	_vm->_files->loadScreen(49, 9);
113 	_vm->_events->showCursor();
114 	_vm->_screen->setIconPalette();
115 	_vm->_screen->forceFadeIn();
116 
117 	Resource *cellsRes = _vm->_files->loadFile("CELLS00.LZ");
118 	_vm->_objectsTable[0] = new SpriteResource(_vm, cellsRes);
119 	delete cellsRes;
120 
121 	_vm->_timers[20]._timer = _vm->_timers[20]._initTm = 30;
122 	_vm->_fonts._charSet._lo = 1;
123 	_vm->_fonts._charSet._hi = 10;
124 	_vm->_fonts._charFor._lo = 1;
125 	_vm->_fonts._charFor._hi = 255;
126 
127 	_vm->_screen->_maxChars = 50;
128 	_vm->_screen->_printOrg = _vm->_screen->_printStart = Common::Point(24, 18);
129 
130 	Resource *notesRes = _vm->_files->loadFile("ETEXT.DAT");
131 	notesRes->_stream->seek(72);
132 
133 	// Read the message
134 	Common::String msg = "";
135 	byte c;
136 	while ((c = (char)notesRes->_stream->readByte()) != '\0')
137 		msg += c;
138 
139 	//display the message
140 	_game->showDeathText(msg);
141 
142 	delete notesRes;
143 	delete _vm->_objectsTable[0];
144 	_vm->_objectsTable[0] = nullptr;
145 	_vm->_midi->stopSong();
146 }
147 
cmdSpecial7()148 void MartianScripts::cmdSpecial7() {
149 	_vm->_room->clearRoom();
150 	_vm->_midi->loadMusic(47, 8);
151 
152 	_vm->_sound->freeSounds();
153 	Resource *sound = _vm->_sound->loadSound(46, 14);
154 	_vm->_sound->_soundTable.push_back(SoundEntry(sound, 1));
155 
156 	_vm->_screen->setDisplayScan();
157 	_vm->_screen->forceFadeOut();
158 	_vm->_events->hideCursor();
159 
160 	_vm->_files->loadScreen(40, 3);
161 	_vm->_buffer1.copyBuffer(_vm->_screen);
162 	_vm->_buffer2.copyBuffer(_vm->_screen);
163 
164 	_vm->_events->showCursor();
165 	_vm->_screen->setIconPalette();
166 	_vm->_screen->forceFadeIn();
167 
168 	// Load objects specific to this special scene
169 	Resource *data = _vm->_files->loadFile(40, 2);
170 	_game->_spec7Objects = new SpriteResource(_vm, data);
171 	delete data;
172 
173 	// Load animation data
174 	_vm->_animation->freeAnimationData();
175 	Resource *animResource = _vm->_files->loadFile(40, 1);
176 	_vm->_animation->loadAnimations(animResource);
177 	delete animResource;
178 
179 	// Load script
180 	Resource *newScript = _vm->_files->loadFile(40, 0);
181 	_vm->_scripts->setScript(newScript);
182 
183 	_vm->_images.clear();
184 	_vm->_oldRects.clear();
185 	_vm->_scripts->_sequence = 0;
186 
187 	_vm->_sound->playSound(0);
188 
189 	do {
190 		charLoop();
191 	} while (_vm->_flags[134] != 1);
192 
193 	do {
194 		_vm->_events->pollEvents();
195 	} while (!_vm->shouldQuit() && _vm->_sound->_playingSound);
196 
197 	_game->_numAnimTimers = 0;
198 	_vm->_animation->freeAnimationData();
199 	_vm->_scripts->freeScriptData();
200 	_vm->_sound->freeSounds();
201 
202 	_vm->_screen->forceFadeOut();
203 	_vm->_midi->midiPlay();
204 	_vm->_midi->setLoop(true);
205 	_vm->_events->hideCursor();
206 
207 	_vm->_files->loadScreen(40, 4);
208 	_vm->_buffer1.copyBuffer(_vm->_screen);
209 	_vm->_buffer2.copyBuffer(_vm->_screen);
210 
211 	_vm->_events->showCursor();
212 	_vm->_screen->setIconPalette();
213 	_vm->_screen->forceFadeIn();
214 
215 	// Setup fonts
216 	_vm->_fonts._charSet._hi = 10;
217 	_vm->_fonts._charSet._lo = 1;
218 	_vm->_fonts._charFor._lo = 247;
219 	_vm->_fonts._charFor._hi = 255;
220 	_vm->_screen->_maxChars = 50;
221 	_vm->_screen->_printOrg = Common::Point(24, 18);
222 	_vm->_screen->_printStart = Common::Point(24, 18);
223 
224 	// Display death message
225 	_game->showDeathText(Common::String(SPEC7MESSAGE));
226 
227 	_vm->_events->showCursor();
228 	_vm->_screen->copyBuffer(&_vm->_buffer1);
229 	_vm->_events->hideCursor();
230 
231 	_vm->_video->setVideo(_vm->_screen, Common::Point(120, 16), FileIdent(40, 5), 10);
232 
233 	while (!_vm->shouldQuit() && !_vm->_video->_videoEnd) {
234 		_vm->_video->playVideo();
235 		_vm->_events->pollEventsAndWait();
236 	}
237 
238 	_vm->_sound->freeSounds();
239 	sound = _vm->_sound->loadSound(40, 8);
240 	_vm->_sound->_soundTable.push_back(SoundEntry(sound, 1));
241 	sound = _vm->_sound->loadSound(40, 9);
242 	_vm->_sound->_soundTable.push_back(SoundEntry(sound, 1));
243 	sound = _vm->_sound->loadSound(40, 10);
244 	_vm->_sound->_soundTable.push_back(SoundEntry(sound, 1));
245 
246 	_vm->_screen->forceFadeOut();
247 	_vm->_files->loadScreen(40, 7);
248 	_vm->_destIn = _vm->_screen;
249 
250 	_vm->_screen->plotImage(_game->_spec7Objects, 8, Common::Point(104, 176));
251 	_vm->_screen->plotImage(_game->_spec7Objects, 7, Common::Point(102, 160));
252 	_vm->_events->showCursor();
253 	_vm->_screen->forceFadeIn();
254 
255 	_vm->_events->_vbCount = 100;
256 	while (!_vm->shouldQuit() && _vm->_events->_vbCount > 0)
257 		_vm->_events->pollEventsAndWait();
258 
259 	_vm->_sound->playSound(0);
260 	do {
261 		_vm->_events->pollEvents();
262 	} while (!_vm->shouldQuit() && _vm->_sound->_playingSound);
263 
264 	_vm->_events->_vbCount = 80;
265 	while (!_vm->shouldQuit() && _vm->_events->_vbCount > 0)
266 		_vm->_events->pollEventsAndWait();
267 
268 	_vm->_sound->playSound(1);
269 	do {
270 		_vm->_events->pollEvents();
271 	} while (!_vm->shouldQuit() && _vm->_sound->_playingSound);
272 
273 	_vm->_events->_vbCount = 80;
274 	while (!_vm->shouldQuit() && _vm->_events->_vbCount > 0)
275 		_vm->_events->pollEventsAndWait();
276 
277 	_vm->_sound->playSound(2);
278 	do {
279 		_vm->_events->pollEvents();
280 	} while (!_vm->shouldQuit() && _vm->_sound->_playingSound);
281 
282 	_vm->_sound->freeSounds();
283 
284 	delete _game->_spec7Objects;
285 	_game->_spec7Objects = nullptr;
286 
287 	_vm->_events->hideCursor();
288 	_vm->_screen->forceFadeOut();
289 	_vm->_files->loadScreen(40, 6);
290 	_vm->_events->showCursor();
291 	_vm->_screen->forceFadeIn();
292 
293 	_vm->_events->waitKeyMouse();
294 	_vm->_midi->stopSong();
295 	_vm->_midi->freeMusic();
296 
297 	// The original was jumping to the restart label in main
298 	_vm->_restartFl = true;
299 	_vm->_events->pollEvents();
300 }
301 
executeSpecial(int commandIndex,int param1,int param2)302 void MartianScripts::executeSpecial(int commandIndex, int param1, int param2) {
303 	switch (commandIndex) {
304 	case 0:
305 		cmdSpecial0();
306 		break;
307 	case 1:
308 		cmdSpecial1(param1);
309 		break;
310 	case 2:
311 		warning("TODO: cmdSpecial2");
312 		break;
313 	case 3:
314 		cmdSpecial3();
315 		break;
316 	case 4:
317 		warning("TODO: cmdSpecial4");
318 		break;
319 	case 5:
320 		doIntro(param1);
321 		break;
322 	case 6:
323 		cmdSpecial6();
324 		break;
325 	case 7:
326 		cmdSpecial7();
327 		break;
328 	default:
329 		warning("Unexpected Special code %d - Skipped", commandIndex);
330 	}
331 }
332 
333 typedef void(MartianScripts::*MartianScriptMethodPtr)();
334 
executeCommand(int commandIndex)335 void MartianScripts::executeCommand(int commandIndex) {
336 	Scripts::executeCommand(commandIndex);
337 }
338 
339 } // End of namespace Martian
340 
341 } // End of namespace Access
342