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/suspects_database.h"
24 
25 #include "bladerunner/bladerunner.h"
26 
27 #include "bladerunner/text_resource.h"
28 
29 namespace BladeRunner {
30 
SuspectDatabaseEntry(BladeRunnerEngine * vm)31 SuspectDatabaseEntry::SuspectDatabaseEntry(BladeRunnerEngine *vm) {
32 	_vm = vm;
33 	reset();
34 }
35 
~SuspectDatabaseEntry()36 SuspectDatabaseEntry::~SuspectDatabaseEntry() {
37 }
38 
setActor(int actorId)39 void SuspectDatabaseEntry::setActor(int actorId) {
40 	_actorId = actorId;
41 }
42 
setSex(int sex)43 void SuspectDatabaseEntry::setSex(int sex) {
44 	_sex = sex;
45 }
46 
addMOClue(int clueId)47 bool SuspectDatabaseEntry::addMOClue(int clueId) {
48 	if (_moClueCount >= kMOClueCount) {
49 		return false;
50 	}
51 	_moClues[_moClueCount++] = clueId;
52 	return true;
53 }
54 
addWhereaboutsClue(int clueId)55 bool SuspectDatabaseEntry::addWhereaboutsClue(int clueId) {
56 	if (_whereaboutsClueCount >= kWhereaboutsClueCount) {
57 		return false;
58 	}
59 	_whereaboutsClues[_whereaboutsClueCount++] = clueId;
60 	return true;
61 }
62 
addReplicantClue(int clueId)63 bool SuspectDatabaseEntry::addReplicantClue(int clueId) {
64 	if (_replicantClueCount >= kReplicantClueCount) {
65 		return false;
66 	}
67 	_replicantClues[_replicantClueCount++] = clueId;
68 	return true;
69 }
70 
addNonReplicantClue(int clueId)71 bool SuspectDatabaseEntry::addNonReplicantClue(int clueId) {
72 	if (_nonReplicantClueCount >= kNonReplicantClueCount) {
73 		return false;
74 	}
75 	_nonReplicantClues[_nonReplicantClueCount++] = clueId;
76 	return true;
77 }
78 
addOtherClue(int clueId)79 bool SuspectDatabaseEntry::addOtherClue(int clueId) {
80 	if (_otherClueCount >= kOtherClueCount) {
81 		return false;
82 	}
83 	_otherClues[_otherClueCount++] = clueId;
84 	return true;
85 }
86 
addIdentityClue(int clueId)87 bool SuspectDatabaseEntry::addIdentityClue(int clueId) {
88 	if (_identityClueCount >= kIdentityClueCount) {
89 		return false;
90 	}
91 	_identityClues[_identityClueCount++] = clueId;
92 	return true;
93 }
94 
addPhotoClue(int shapeId,int clueId)95 bool SuspectDatabaseEntry::addPhotoClue(int shapeId, int clueId) {
96 	if (_photoClueCount >= kPhotoClueCount) {
97 		return false;
98 	}
99 	_photoClues[_photoClueCount].clueId = clueId;
100 	_photoClues[_photoClueCount].shapeId = shapeId;
101 	_photoClues[_photoClueCount].notUsed = -1;
102 
103 	++_photoClueCount;
104 	return true;
105 }
106 
getName() const107 const char *SuspectDatabaseEntry::getName() const {
108 	return _vm->_textActorNames->getText(_actorId);
109 }
110 
getSex() const111 int SuspectDatabaseEntry::getSex() const {
112 	return _sex;
113 }
114 
hasMOClue(int clueId) const115 bool SuspectDatabaseEntry::hasMOClue(int clueId) const {
116 	for (int i = 0; i < _moClueCount; ++i) {
117 		if (_moClues[i] == clueId) {
118 			return true;
119 		}
120 	}
121 	return false;
122 }
123 
hasWhereaboutsClue(int clueId) const124 bool SuspectDatabaseEntry::hasWhereaboutsClue(int clueId) const {
125 	for (int i = 0; i < _whereaboutsClueCount; ++i) {
126 		if (_whereaboutsClues[i] == clueId) {
127 			return true;
128 		}
129 	}
130 	return false;
131 }
132 
hasReplicantClue(int clueId) const133 bool SuspectDatabaseEntry::hasReplicantClue(int clueId) const {
134 	for (int i = 0; i < _replicantClueCount; ++i) {
135 		if (_replicantClues[i] == clueId) {
136 			return true;
137 		}
138 	}
139 	return false;
140 }
141 
hasNonReplicantClue(int clueId) const142 bool SuspectDatabaseEntry::hasNonReplicantClue(int clueId) const {
143 	for (int i = 0; i < _nonReplicantClueCount; ++i) {
144 		if (_nonReplicantClues[i] == clueId) {
145 			return true;
146 		}
147 	}
148 	return false;
149 }
150 
hasOtherClue(int clueId) const151 bool SuspectDatabaseEntry::hasOtherClue(int clueId) const {
152 	for (int i = 0; i < _otherClueCount; ++i) {
153 		if (_otherClues[i] == clueId) {
154 			return true;
155 		}
156 	}
157 	return false;
158 }
159 
hasIdentityClue(int clueId) const160 bool SuspectDatabaseEntry::hasIdentityClue(int clueId) const {
161 	for (int i = 0; i < _identityClueCount; ++i) {
162 		if (_identityClues[i] == clueId) {
163 			return true;
164 		}
165 	}
166 	return false;
167 }
168 
hasClue(int clueId) const169 bool SuspectDatabaseEntry::hasClue(int clueId) const {
170 	return hasMOClue(clueId)
171 		|| hasWhereaboutsClue(clueId)
172 		|| hasReplicantClue(clueId)
173 		|| hasNonReplicantClue(clueId)
174 		|| hasOtherClue(clueId);
175 }
176 
getPhotoCount() const177 int SuspectDatabaseEntry::getPhotoCount() const {
178 	return _photoClueCount;
179 }
180 
getPhotoClueId(int photoId) const181 int SuspectDatabaseEntry::getPhotoClueId(int photoId) const {
182 	return _photoClues[photoId].clueId;
183 }
184 
getPhotoShapeId(int photoId) const185 int SuspectDatabaseEntry::getPhotoShapeId(int photoId) const {
186 	return _photoClues[photoId].shapeId;
187 }
188 
getPhotoNotUsed(int photoId) const189 int SuspectDatabaseEntry::getPhotoNotUsed(int photoId) const {
190 	return _photoClues[photoId].notUsed;
191 }
192 
reset()193 void SuspectDatabaseEntry::reset() {
194 	_actorId = -1;
195 	_sex = -1;
196 	for (int i = 0; i < kMOClueCount; ++i) {
197 		_moClues[i] = -1;
198 	}
199 	for (int i = 0; i < kWhereaboutsClueCount; ++i) {
200 		_whereaboutsClues[i] = -1;
201 	}
202 	for (int i = 0; i < kIdentityClueCount; ++i) {
203 		_identityClues[i] = -1;
204 	}
205 	for (int i = 0; i < kReplicantClueCount; ++i) {
206 		_replicantClues[i] = -1;
207 	}
208 	for (int i = 0; i < kNonReplicantClueCount; ++i) {
209 		_nonReplicantClues[i] = -1;
210 	}
211 	for (int i = 0; i < kOtherClueCount; ++i) {
212 		_otherClues[i] = -1;
213 	}
214 	for (int i = 0; i < kPhotoClueCount; ++i) {
215 		_photoClues[i].clueId  = -1;
216 		_photoClues[i].shapeId = -1;
217 		_photoClues[i].notUsed = -1;
218 	}
219 
220 	// photo clues are not reseted in original game
221 
222 	_moClueCount = 0;
223 	_whereaboutsClueCount = 0;
224 	_replicantClueCount = 0;
225 	_nonReplicantClueCount = 0;
226 	_otherClueCount = 0;
227 	_identityClueCount = 0;
228 	_photoClueCount = 0;
229 }
230 
SuspectsDatabase(BladeRunnerEngine * vm,int size)231 SuspectsDatabase::SuspectsDatabase(BladeRunnerEngine *vm, int size) {
232 	_vm = vm;
233 	for (int i = 0; i < size; ++i) {
234 		_suspects.push_back(new SuspectDatabaseEntry(_vm));
235 	}
236 }
237 
~SuspectsDatabase()238 SuspectsDatabase::~SuspectsDatabase() {
239 	for (int i = _suspects.size() - 1; i >= 0; --i) {
240 		delete _suspects.remove_at(i);
241 	}
242 	_suspects.clear();
243 }
244 
get(int suspectId)245 SuspectDatabaseEntry *SuspectsDatabase::get(int suspectId) {
246 	return _suspects[suspectId];
247 }
248 
249 } // End of namespace BladeRunner
250