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 "bladerunner/chapters.h"
24 
25 #include "bladerunner/bladerunner.h"
26 #include "bladerunner/slice_animations.h"
27 
28 namespace BladeRunner {
29 
enterChapter(int chapter)30 bool Chapters::enterChapter(int chapter) {
31 	int id = _resourceIds[chapter];
32 
33 	if (!_vm->_sliceAnimations->openFrames(id))
34 		return false;
35 
36 	if (!_vm->openArchive("A.TLK"))
37 		return false;
38 
39 	if (!_vm->openArchive(Common::String::format("VQA%d.MIX", MIN(id, 3))))
40 		return false;
41 
42 	if (_vm->_cutContent) {
43 		for (int chi = 1; chi < 4; ++chi) {
44 			if (!_vm->isArchiveOpen(Common::String::format("%d.TLK", chi))
45 			    && !_vm->openArchive(Common::String::format("%d.TLK", chi))
46 			) {
47 				return false;
48 			}
49 		}
50 	} else {
51 		if (!_vm->openArchive(Common::String::format("%d.TLK", MIN(id, 3))))
52 			return false;
53 	}
54 
55 	if (!_vm->openArchive(Common::String::format("OUTTAKE%d.MIX", id)))
56 		return false;
57 
58 	_chapter = chapter;
59 	_hasOpenResources = true;
60 	return true;
61 }
62 
closeResources()63 void Chapters::closeResources() {
64 	int id = _resourceIds[_chapter];
65 
66 #if BLADERUNNER_ORIGINAL_BUGS
67 	_vm->closeArchive("A.TLK");
68 #else
69 	if (_vm->isArchiveOpen("A.TLK")) {
70 		_vm->closeArchive("A.TLK");
71 	}
72 #endif // BLADERUNNER_ORIGINAL_BUGS
73 	_vm->closeArchive(Common::String::format("VQA%d.MIX", MIN(id, 3)));
74 	// It's better to try and close every TLK file here (if open), since
75 	// when switching from Restored Content version to Original (due to a save game load)
76 	// TLK files would still remain open -- and should still be closed here
77 	for (int chi = 1; chi < 4; ++chi) {
78 		if (_vm->isArchiveOpen(Common::String::format("%d.TLK", chi))) {
79 			_vm->closeArchive(Common::String::format("%d.TLK", chi));
80 		}
81 	}
82 	_vm->closeArchive(Common::String::format("OUTTAKE%d.MIX", id));
83 	_hasOpenResources = false;
84 }
85 
86 } // End of namespace BladeRunner
87