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/crimes_database.h"
24 
25 #include "bladerunner/bladerunner.h"
26 
27 #include "bladerunner/savefile.h"
28 #include "bladerunner/text_resource.h"
29 #include "bladerunner/game_constants.h"
30 
31 namespace BladeRunner {
32 
CrimesDatabase(BladeRunnerEngine * vm,const Common::String & cluesResource,int crimeCount)33 CrimesDatabase::CrimesDatabase(BladeRunnerEngine *vm, const Common::String &cluesResource, int crimeCount) {
34 	_crimeCount = crimeCount;
35 
36 	_crimes.resize(_crimeCount);
37 	_assetTypes.resize(_crimeCount);
38 
39 	_cluesText = new TextResource(vm);
40 	if (!_cluesText->open(cluesResource)) {
41 		delete _cluesText;
42 		return;
43 	}
44 
45 	for (int i = 0; i != _crimeCount; ++i) {
46 		_crimes[i]     = -1;
47 		_assetTypes[i] = kClueTypeIntangible;
48 	}
49 }
50 
~CrimesDatabase()51 CrimesDatabase::~CrimesDatabase() {
52 	delete _cluesText;
53 }
54 
setCrime(int clueId,int crimeId)55 void CrimesDatabase::setCrime(int clueId, int crimeId) {
56 	_crimes[clueId] = crimeId;
57 }
58 
getCrime(int clueId) const59 int CrimesDatabase::getCrime(int clueId) const {
60 	return _crimes[clueId];
61 }
62 
setAssetType(int clueId,int assetType)63 void CrimesDatabase::setAssetType(int clueId, int assetType) {
64 	_assetTypes[clueId] = assetType;
65 }
66 
getAssetType(int clueId) const67 int CrimesDatabase::getAssetType(int clueId) const {
68 	return _assetTypes[clueId];
69 }
70 
getClueText(int clueId) const71 const char *CrimesDatabase::getClueText(int clueId) const {
72 	return _cluesText->getText(clueId);
73 }
74 
save(SaveFileWriteStream & f)75 void CrimesDatabase::save(SaveFileWriteStream &f) {
76 	for (int i = 0; i < _crimeCount; ++i) {
77 		int8 c = _crimes[i];
78 		f.writeSByte(c);
79 	}
80 }
81 
load(SaveFileReadStream & f)82 void CrimesDatabase::load(SaveFileReadStream &f) {
83 	for (int i = 0; i < _crimeCount; ++i) {
84 		_crimes[i] = f.readSByte();
85 	}
86 }
87 
88 } // End of namespace BladeRunner
89