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/settings.h"
24 
25 #include "bladerunner/actor.h"
26 #include "bladerunner/ambient_sounds.h"
27 #include "bladerunner/bladerunner.h"
28 #include "bladerunner/chapters.h"
29 #include "bladerunner/game_constants.h"
30 #include "bladerunner/game_info.h"
31 #include "bladerunner/music.h"
32 #include "bladerunner/savefile.h"
33 #include "bladerunner/scene.h"
34 
35 #include "common/debug.h"
36 
37 namespace BladeRunner {
38 
Settings(BladeRunnerEngine * vm)39 Settings::Settings(BladeRunnerEngine *vm) {
40 	_vm = vm;
41 
42 	_difficulty = kGameDifficultyMedium;
43 	_playerAgenda = kPlayerAgendaNormal;
44 
45 	_chapter = 1;
46 	_scene = -1;
47 	_set = -1;
48 	_unk0 = 0;
49 	_gamma = 1.0f;
50 
51 	_ammoType = 0;
52 	_ammoAmounts[0] = 1;
53 	_ammoAmounts[1] = 0;
54 	_ammoAmounts[2] = 0;
55 
56 	// The remaining fields are not reset in BLADE.EXE
57 	_chapterChanged = false;
58 	_newChapter = -1;
59 	_newScene = -1;
60 	_newSet = -1;
61 
62 	_startingGame = false;
63 	_loadingGame = false;
64 
65 	_fullHDFrames = true;
66 	_mst3k = false;
67 
68 #if BLADERUNNER_ORIGINAL_BUGS
69 	// Probably a bug. Assigning these here again, overrides the initialization above.
70 	//       Also note: the reset() method assigns "_ammoAmounts[0] = 1" like above!
71 	_ammoType = 0;
72 	_ammoAmounts[0] = 0;
73 	_ammoAmounts[1] = 0;
74 	_ammoAmounts[2] = 0;
75 #endif // BLADERUNNER_ORIGINAL_BUGS
76 
77 	_learyMode = false;
78 }
79 
reset()80 void Settings::reset() {
81 	_ammoType = 0;
82 	_ammoAmounts[0] = 1;
83 	_ammoAmounts[1] = 0;
84 	_ammoAmounts[2] = 0;
85 }
86 
openNewScene()87 bool Settings::openNewScene() {
88 	if (_newSet == -1) {
89 		assert(_newScene == -1);
90 		return true;
91 	}
92 	assert(_newScene != -1);
93 
94 	if (_startingGame) {
95 		_vm->_ambientSounds->removeAllNonLoopingSounds(true);
96 		_vm->_ambientSounds->removeAllLoopingSounds(1u);
97 		_vm->_music->stop(2u);
98 	}
99 
100 	int currentSet = _vm->_scene->getSetId();
101 	int newSet     = _newSet;
102 	int newScene   = _newScene;
103 
104 	_newSet = -1;
105 	_newScene = -1;
106 	if (currentSet != -1) {
107 		_vm->_scene->close(!_loadingGame && !_startingGame);
108 	}
109 	if (_chapterChanged) {
110 		if (_vm->_chapters->hasOpenResources()) {
111 			_vm->_chapters->closeResources();
112 		}
113 
114 		int newChapter = _newChapter;
115 		_chapterChanged = false;
116 		_newChapter = 0;
117 		if (!_vm->_chapters->enterChapter(newChapter)) {
118 			_vm->_gameIsRunning = false;
119 			return false;
120 		}
121 		_chapter = newChapter;
122 		if (_startingGame) {
123 			_startingGame = false;
124 		}
125 	}
126 
127 	if (!_vm->_scene->open(newSet, newScene, _loadingGame)) {
128 		_vm->_gameIsRunning = false;
129 		return false;
130 	}
131 
132 	_set = newSet;
133 	_scene = newScene;
134 
135 	if (!_loadingGame && currentSet != newSet) {
136 		for (int i = 0; i < (int)_vm->_gameInfo->getActorCount(); ++i) {
137 			Actor *actor = _vm->_actors[i];
138 			if (i != kActorMcCoy && actor->getSetId() == currentSet) {
139 				if (!actor->isRetired()) {
140 					actor->stopWalking(false);
141 					actor->movementTrackWaypointReached();
142 				}
143 				if (actor->inCombat()) {
144 					actor->setSetId(kSetFreeSlotG);
145 					actor->combatModeOff();
146 				}
147 			}
148 		}
149 	}
150 
151 	_loadingGame = false;
152 	return true;
153 }
154 
getAmmoTypesCount()155 int Settings::getAmmoTypesCount() {
156 	return kAmmoTypesCount;
157 }
158 
getAmmoType() const159 int Settings::getAmmoType() const {
160 	return _ammoType;
161 }
162 
setAmmoType(int ammoType)163 void Settings::setAmmoType(int ammoType) {
164 	if (_ammoAmounts[ammoType] > 0) {
165 		_ammoType = ammoType;
166 	}
167 }
168 
getAmmo(int ammoType) const169 int Settings::getAmmo(int ammoType) const {
170 	return _ammoAmounts[ammoType];
171 }
172 
addAmmo(int ammoType,int ammo)173 void Settings::addAmmo(int ammoType, int ammo) {
174 	if (ammoType > _ammoType || _ammoAmounts[_ammoType] == 0) {
175 		_ammoType = ammoType;
176 	}
177 	_ammoAmounts[ammoType] += ammo;
178 }
179 
decreaseAmmo()180 void Settings::decreaseAmmo() {
181 	if (_difficulty == kGameDifficultyEasy || _ammoType == 0) {
182 		return;
183 	}
184 
185 	if (_ammoAmounts[_ammoType] > 0) {
186 		--_ammoAmounts[_ammoType];
187 	}
188 
189 	if (_ammoAmounts[_ammoType] == 0) {
190 		for (int i = 2; i >= 0; --i) {
191 			if (_ammoAmounts[i] > 0) {
192 				_ammoType = i;
193 				return;
194 			}
195 		}
196 	}
197 }
198 
getDifficulty() const199 int Settings::getDifficulty() const {
200 	return _difficulty;
201 }
202 
setDifficulty(int difficulty)203 void Settings::setDifficulty(int difficulty) {
204 	_difficulty = difficulty;
205 }
206 
getPlayerAgenda() const207 int Settings::getPlayerAgenda() const {
208 	return _playerAgenda;
209 }
210 
setPlayerAgenda(int agenda)211 void Settings::setPlayerAgenda(int agenda) {
212 	_playerAgenda = agenda;
213 }
214 
getLearyMode() const215 bool Settings::getLearyMode() const {
216 	return _learyMode;
217 }
218 
setLearyMode(bool learyMode)219 void Settings::setLearyMode(bool learyMode) {
220 	_learyMode = learyMode;
221 }
222 
save(SaveFileWriteStream & f)223 void Settings::save(SaveFileWriteStream &f) {
224 	f.writeInt(_scene);
225 	f.writeInt(_set);
226 	f.writeInt(_chapter);
227 	f.writeInt(_playerAgenda);
228 	f.writeInt(_unk0);
229 	f.writeInt(_difficulty);
230 	f.writeInt(_ammoType);
231 	for (int i = 0; i != kAmmoTypesCount; ++i) {
232 		f.writeInt(_ammoAmounts[i]);
233 	}
234 }
235 
load(SaveFileReadStream & f)236 void Settings::load(SaveFileReadStream &f) {
237 	_scene = f.readInt();
238 	_set = f.readInt();
239 	_chapter = f.readInt();
240 	_playerAgenda = f.readInt();
241 	_unk0 = f.readInt();
242 	_difficulty = f.readInt();
243 	_ammoType = f.readInt();
244 	for (int i = 0; i != kAmmoTypesCount; ++i) {
245 		_ammoAmounts[i] = f.readInt();
246 	}
247 }
248 
249 } // End of namespace BladeRunner
250