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 * Additional copyright for this file:
8 * Copyright (C) 1995-1997 Presto Studios, Inc.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * aint32 with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 *
24 */
25
26 #include "pegasus/pegasus.h"
27 #include "pegasus/neighborhood/mars/reactor.h"
28
29 namespace Pegasus {
30
31 static const CoordType kCurrentGuessWidth = 121;
32 static const CoordType kCurrentGuessHeight = 23;
33
34 static const CoordType kOneGuessWidth = 25;
35 static const CoordType kOneGuessHeight = 23;
36
37 static const ResIDType kReactorChoicesPICTID = 905;
38
39 static const CoordType kCurrentGuessLeft = kNavAreaLeft + 146;
40 static const CoordType kCurrentGuessTop = kNavAreaTop + 90;
41
ReactorGuess(const DisplayElementID id)42 ReactorGuess::ReactorGuess(const DisplayElementID id) : DisplayElement(id) {
43 setBounds(kCurrentGuessLeft, kCurrentGuessTop, kCurrentGuessLeft + kCurrentGuessWidth,
44 kCurrentGuessTop + kCurrentGuessHeight);
45 setDisplayOrder(kMonitorLayer);
46 _currentGuess[0] = -1;
47 _currentGuess[1] = -1;
48 _currentGuess[2] = -1;
49 }
50
initReactorGuess()51 void ReactorGuess::initReactorGuess() {
52 _colors.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorChoicesPICTID);
53 startDisplaying();
54 show();
55 }
56
disposeReactorGuess()57 void ReactorGuess::disposeReactorGuess() {
58 stopDisplaying();
59 _colors.deallocateSurface();
60 }
61
setGuess(int32 a,int32 b,int32 c)62 void ReactorGuess::setGuess(int32 a, int32 b, int32 c) {
63 _currentGuess[0] = a;
64 _currentGuess[1] = b;
65 _currentGuess[2] = c;
66 triggerRedraw();
67 }
68
draw(const Common::Rect &)69 void ReactorGuess::draw(const Common::Rect &) {
70 if (_colors.isSurfaceValid()) {
71 Common::Rect r1(0, 0, kOneGuessWidth, kOneGuessHeight);
72 Common::Rect r2 = r1;
73
74 for (int i = 0; i < 3; i++) {
75 if (_currentGuess[i] >= 0) {
76 r1.moveTo(kOneGuessWidth * _currentGuess[i], 0);
77 r2.moveTo(kCurrentGuessLeft + 48 * i, kCurrentGuessTop);
78 _colors.copyToCurrentPortTransparent(r1, r2);
79 }
80 }
81 }
82 }
83
84 static const CoordType kReactorChoiceHiliteWidth = 166;
85 static const CoordType kReactorChoiceHiliteHeight = 26;
86
87 static const CoordType kChoiceHiliteLefts[6] = {
88 0,
89 34,
90 34 + 34,
91 34 + 34 + 32,
92 34 + 34 + 32 + 34,
93 34 + 34 + 32 + 34 + 32
94 };
95
96 static const ResIDType kReactorChoiceHilitePICTID = 901;
97
98 static const CoordType kReactorChoiceHiliteLeft = kNavAreaLeft + 116;
99 static const CoordType kReactorChoiceHiliteTop = kNavAreaTop + 158;
100
ReactorChoiceHighlight(const DisplayElementID id)101 ReactorChoiceHighlight::ReactorChoiceHighlight(const DisplayElementID id) : DisplayElement(id) {
102 setBounds(kReactorChoiceHiliteLeft, kReactorChoiceHiliteTop, kReactorChoiceHiliteLeft + kReactorChoiceHiliteWidth,
103 kReactorChoiceHiliteTop + kReactorChoiceHiliteHeight);
104 setDisplayOrder(kMonitorLayer);
105 }
106
initReactorChoiceHighlight()107 void ReactorChoiceHighlight::initReactorChoiceHighlight() {
108 _colors.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorChoiceHilitePICTID);
109 startDisplaying();
110 show();
111 }
112
disposeReactorChoiceHighlight()113 void ReactorChoiceHighlight::disposeReactorChoiceHighlight() {
114 stopDisplaying();
115 _colors.deallocateSurface();
116 }
117
draw(const Common::Rect &)118 void ReactorChoiceHighlight::draw(const Common::Rect &) {
119 if (_colors.isSurfaceValid()) {
120 for (int i = 0; i < 5; ++i) {
121 if (_choices.getFlag(i)) {
122 Common::Rect r1(0, 0, kChoiceHiliteLefts[i + 1] - kChoiceHiliteLefts[i], kReactorChoiceHiliteHeight);
123 Common::Rect r2 = r1;
124 r1.moveTo(kChoiceHiliteLefts[i], 0);
125 r2.moveTo(kReactorChoiceHiliteLeft + kChoiceHiliteLefts[i], kReactorChoiceHiliteTop);
126 _colors.copyToCurrentPort(r1, r2);
127 }
128 }
129 }
130 }
131
132 static const CoordType kReactorHistoryWidth = 128;
133 static const CoordType kReactorHistoryHeight = 168;
134
135 static const CoordType kColorWidths[5] = { 24, 25, 25, 26, 27 };
136 static const CoordType kColorHeights[5] = { 14, 15, 17, 17, 19};
137
138 static const CoordType kHistoryLefts[5][3] = {
139 { 302 + kNavAreaLeft, 329 + kNavAreaLeft, 357 + kNavAreaLeft },
140 { 302 + kNavAreaLeft, 331 + kNavAreaLeft, 360 + kNavAreaLeft },
141 { 303 + kNavAreaLeft, 333 + kNavAreaLeft, 363 + kNavAreaLeft },
142 { 304 + kNavAreaLeft, 335 + kNavAreaLeft, 366 + kNavAreaLeft },
143 { 305 + kNavAreaLeft, 337 + kNavAreaLeft, 369 + kNavAreaLeft }
144 };
145
146 static const CoordType kHistoryTops[5] = {
147 39 + kNavAreaTop,
148 61 + kNavAreaTop,
149 84 + kNavAreaTop,
150 110 + kNavAreaTop,
151 137 + kNavAreaTop
152 };
153
154 static const CoordType kOneAnswerWidth = 35;
155 static const CoordType kOneAnswerHeight = 27;
156
157 static const CoordType kDigitWidth = 16;
158 static const CoordType kDigitHeight = 12;
159
160 static const CoordType kCorrectCountLefts[5] = {
161 388 + kNavAreaLeft,
162 392 + kNavAreaLeft,
163 398 + kNavAreaLeft,
164 402 + kNavAreaLeft,
165 406 + kNavAreaLeft
166 };
167
168 static const CoordType kCorrectCountTops[5] = {
169 40 + kNavAreaTop,
170 62 + kNavAreaTop,
171 86 + kNavAreaTop,
172 112 + kNavAreaTop,
173 140 + kNavAreaTop
174 };
175
176 static const ResIDType kReactorDigitsPICTID = 902;
177 static const ResIDType kReactorHistoryPICTID = 903;
178 static const ResIDType kReactorAnswerPICTID = 904;
179
180 static const CoordType kReactorHistoryLeft = kNavAreaLeft + 302;
181 static const CoordType kReactorHistoryTop = kNavAreaTop + 39;
182
183 static const CoordType kAnswerLeft = kNavAreaLeft + 304;
184 static const CoordType kAnswerTop = kNavAreaTop + 180;
185
ReactorHistory(const DisplayElementID id)186 ReactorHistory::ReactorHistory(const DisplayElementID id) : DisplayElement(id) {
187 setBounds(kReactorHistoryLeft, kReactorHistoryTop, kReactorHistoryLeft + kReactorHistoryWidth,
188 kReactorHistoryTop + kReactorHistoryHeight);
189 setDisplayOrder(kMonitorLayer);
190 _numGuesses = 0;
191 _answer[0] = -1;
192 _answer[1] = -1;
193 _answer[2] = -1;
194 _showAnswer = false;
195 }
196
initReactorHistory()197 void ReactorHistory::initReactorHistory() {
198 _colors.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorHistoryPICTID);
199 _digits.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorDigitsPICTID);
200 _answerColors.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorAnswerPICTID);
201 startDisplaying();
202 show();
203 }
204
disposeReactorHistory()205 void ReactorHistory::disposeReactorHistory() {
206 stopDisplaying();
207 _colors.deallocateSurface();
208 }
209
addGuess(int32 a,int32 b,int32 c)210 void ReactorHistory::addGuess(int32 a, int32 b, int32 c) {
211 _history[_numGuesses][0] = a;
212 _history[_numGuesses][1] = b;
213 _history[_numGuesses][2] = c;
214 _numGuesses++;
215 triggerRedraw();
216 }
217
clearHistory()218 void ReactorHistory::clearHistory() {
219 _numGuesses = 0;
220 _showAnswer = false;
221 triggerRedraw();
222 }
223
setAnswer(int32 a,int32 b,int32 c)224 void ReactorHistory::setAnswer(int32 a, int32 b, int32 c) {
225 _answer[0] = a;
226 _answer[1] = b;
227 _answer[2] = c;
228 }
229
showAnswer()230 void ReactorHistory::showAnswer() {
231 _showAnswer = true;
232 triggerRedraw();
233 }
234
isSolved()235 bool ReactorHistory::isSolved() {
236 for (int i = 0; i < _numGuesses; i++)
237 if (_history[i][0] == _answer[0] && _history[i][1] == _answer[1] && _history[i][2] == _answer[2])
238 return true;
239
240 return false;
241 }
242
draw(const Common::Rect &)243 void ReactorHistory::draw(const Common::Rect &) {
244 static const CoordType kColorTops[5] = {
245 0,
246 kColorHeights[0],
247 (CoordType)(kColorHeights[0] + kColorHeights[1]),
248 (CoordType)(kColorHeights[0] + kColorHeights[1] + kColorHeights[2]),
249 (CoordType)(kColorHeights[0] + kColorHeights[1] + kColorHeights[2] + kColorHeights[3]),
250 };
251
252 if (_colors.isSurfaceValid() && _digits.isSurfaceValid()) {
253 for (int i = 0; i < _numGuesses; ++i) {
254 Common::Rect r1(0, 0, kColorWidths[i], kColorHeights[i]);
255 Common::Rect r2 = r1;
256 Common::Rect r3(0, 0, kDigitWidth, kDigitHeight);
257 Common::Rect r4 = r3;
258 int correct = 0;
259
260 for (int j = 0; j < 3; ++j) {
261 r1.moveTo(kColorWidths[i] * _history[i][j], kColorTops[i]);
262 r2.moveTo(kHistoryLefts[i][j], kHistoryTops[i]);
263 _colors.copyToCurrentPortTransparent(r1, r2);
264
265 if (_history[i][j] == _answer[j])
266 correct++;
267 }
268
269 r3.moveTo(kDigitWidth * correct, 0);
270 r4.moveTo(kCorrectCountLefts[i], kCorrectCountTops[i]);
271 _digits.copyToCurrentPort(r3, r4);
272 }
273
274 if (_showAnswer && _answerColors.isSurfaceValid()) {
275 Common::Rect r1(0, 0, kOneAnswerWidth, kOneAnswerHeight);
276 Common::Rect r2 = r1;
277
278 for (int i = 0; i < 3; i++) {
279 r1.moveTo(kOneAnswerWidth * _answer[i], 0);
280 r2.moveTo(kAnswerLeft + 34 * i, kAnswerTop);
281 _answerColors.copyToCurrentPortTransparent(r1, r2);
282 }
283 }
284 }
285 }
286
getCurrentNumCorrect()287 int32 ReactorHistory::getCurrentNumCorrect() {
288 int correct = 0;
289
290 for (int i = 0; i < 3; i++)
291 if (_history[_numGuesses - 1][i] == _answer[i])
292 correct++;
293
294 return correct;
295 }
296
297 } // End of namespace Pegasus
298