aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/neighborhood/mars/reactor.cpp
blob: 3a7ef9d7eb4e00ae54b62a44812006737415490e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * Additional copyright for this file:
 * Copyright (C) 1995-1997 Presto Studios, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * aint32 with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "pegasus/pegasus.h"
#include "pegasus/neighborhood/mars/reactor.h"

namespace Pegasus {

static const CoordType kCurrentGuessWidth = 121;
static const CoordType kCurrentGuessHeight = 23;

static const CoordType kOneGuessWidth = 25;
static const CoordType kOneGuessHeight = 23;

static const ResIDType kReactorChoicesPICTID = 905;

static const CoordType kCurrentGuessLeft = kNavAreaLeft + 146;
static const CoordType kCurrentGuessTop = kNavAreaTop + 90;

ReactorGuess::ReactorGuess(const DisplayElementID id) : DisplayElement(id) {
	setBounds(kCurrentGuessLeft, kCurrentGuessTop, kCurrentGuessLeft + kCurrentGuessWidth,
			kCurrentGuessTop + kCurrentGuessHeight);
	setDisplayOrder(kMonitorLayer);
	_currentGuess[0] = -1;
	_currentGuess[1] = -1;
	_currentGuess[2] = -1;
}

void ReactorGuess::initReactorGuess() {
	_colors.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorChoicesPICTID);
	startDisplaying();
	show();
}

void ReactorGuess::disposeReactorGuess() {
	stopDisplaying();
	_colors.deallocateSurface();
}

void ReactorGuess::setGuess(int32 a, int32 b, int32 c) {
	_currentGuess[0] = a;
	_currentGuess[1] = b;
	_currentGuess[2] = c;
	triggerRedraw();
}

void ReactorGuess::draw(const Common::Rect &) {
	if (_colors.isSurfaceValid()) {
		Common::Rect r1(0, 0, kOneGuessWidth, kOneGuessHeight);
		Common::Rect r2 = r1;

		for (int i = 0; i < 3; i++) {
			if (_currentGuess[i] >= 0) {
				r1.moveTo(kOneGuessWidth * _currentGuess[i], 0);
				r2.moveTo(kCurrentGuessLeft + 48 * i, kCurrentGuessTop);
				_colors.copyToCurrentPortTransparent(r1, r2);
			}
		}
	}
}

static const CoordType kReactorChoiceHiliteWidth = 166;
static const CoordType kReactorChoiceHiliteHeight = 26;

static const CoordType kChoiceHiliteLefts[6] = {
	0,
	34,
	34 + 34,
	34 + 34 + 32,
	34 + 34 + 32 + 34,
	34 + 34 + 32 + 34 + 32
};

static const ResIDType kReactorChoiceHilitePICTID = 901;

static const CoordType kReactorChoiceHiliteLeft = kNavAreaLeft + 116;
static const CoordType kReactorChoiceHiliteTop = kNavAreaTop + 158;

ReactorChoiceHighlight::ReactorChoiceHighlight(const DisplayElementID id) : DisplayElement(id) {
	setBounds(kReactorChoiceHiliteLeft, kReactorChoiceHiliteTop, kReactorChoiceHiliteLeft + kReactorChoiceHiliteWidth,
			kReactorChoiceHiliteTop + kReactorChoiceHiliteHeight);
	setDisplayOrder(kMonitorLayer);
}

void ReactorChoiceHighlight::initReactorChoiceHighlight() {
	_colors.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorChoiceHilitePICTID);
	startDisplaying();
	show();
}

void ReactorChoiceHighlight::disposeReactorChoiceHighlight() {
	stopDisplaying();
	_colors.deallocateSurface();
}

void ReactorChoiceHighlight::draw(const Common::Rect &) {
	if (_colors.isSurfaceValid()) {
		for (int i = 0; i < 5; ++i) {
			if (_choices.getFlag(i)) {
				Common::Rect r1(0, 0, kChoiceHiliteLefts[i + 1] - kChoiceHiliteLefts[i], kReactorChoiceHiliteHeight);
				Common::Rect r2 = r1;
				r1.moveTo(kChoiceHiliteLefts[i], 0);
				r2.moveTo(kReactorChoiceHiliteLeft + kChoiceHiliteLefts[i], kReactorChoiceHiliteTop);
				_colors.copyToCurrentPort(r1, r2);
			}
		}
	}
}

static const CoordType kReactorHistoryWidth = 128;
static const CoordType kReactorHistoryHeight = 168;

static const CoordType kColorWidths[5] = { 24, 25, 25, 26, 27 };
static const CoordType kColorHeights[5] = { 14, 15, 17, 17, 19};

static const CoordType kHistoryLefts[5][3] = {
	{ 302 + kNavAreaLeft, 329 + kNavAreaLeft, 357 + kNavAreaLeft },
	{ 302 + kNavAreaLeft, 331 + kNavAreaLeft, 360 + kNavAreaLeft },
	{ 303 + kNavAreaLeft, 333 + kNavAreaLeft, 363 + kNavAreaLeft },
	{ 304 + kNavAreaLeft, 335 + kNavAreaLeft, 366 + kNavAreaLeft },
	{ 305 + kNavAreaLeft, 337 + kNavAreaLeft, 369 + kNavAreaLeft }
};

static const CoordType kHistoryTops[5] = {
	39 + kNavAreaTop,
	61 + kNavAreaTop,
	84 + kNavAreaTop,
	110 + kNavAreaTop,
	137 + kNavAreaTop
};

static const CoordType kOneAnswerWidth = 35;
static const CoordType kOneAnswerHeight = 27;

static const CoordType kDigitWidth = 16;
static const CoordType kDigitHeight = 12;

static const CoordType kCorrectCountLefts[5] = {
	388 + kNavAreaLeft,
	392 + kNavAreaLeft,
	398 + kNavAreaLeft,
	402 + kNavAreaLeft,
	406 + kNavAreaLeft
};

static const CoordType kCorrectCountTops[5] = {
	40 + kNavAreaTop,
	62 + kNavAreaTop,
	86 + kNavAreaTop,
	112 + kNavAreaTop,
	140 + kNavAreaTop
};

static const ResIDType kReactorDigitsPICTID = 902;
static const ResIDType kReactorHistoryPICTID = 903;
static const ResIDType kReactorAnswerPICTID = 904;

static const CoordType kReactorHistoryLeft = kNavAreaLeft + 302;
static const CoordType kReactorHistoryTop = kNavAreaTop + 39;

static const CoordType kAnswerLeft = kNavAreaLeft + 304;
static const CoordType kAnswerTop = kNavAreaTop + 180;

ReactorHistory::ReactorHistory(const DisplayElementID id) : DisplayElement(id) {
	setBounds(kReactorHistoryLeft, kReactorHistoryTop, kReactorHistoryLeft + kReactorHistoryWidth,
			kReactorHistoryTop + kReactorHistoryHeight);
	setDisplayOrder(kMonitorLayer);
	_numGuesses = 0;
	_answer[0] = -1;
	_answer[1] = -1;
	_answer[2] = -1;
	_showAnswer = false;
}

void ReactorHistory::initReactorHistory() {
	_colors.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorHistoryPICTID);
	_digits.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorDigitsPICTID);
	_answerColors.getImageFromPICTResource(((PegasusEngine *)g_engine)->_resFork, kReactorAnswerPICTID);
	startDisplaying();
	show();
}

void ReactorHistory::disposeReactorHistory() {
	stopDisplaying();
	_colors.deallocateSurface();
}

void ReactorHistory::addGuess(int32 a, int32 b, int32 c) {
	_history[_numGuesses][0] = a;
	_history[_numGuesses][1] = b;
	_history[_numGuesses][2] = c;
	_numGuesses++;
	triggerRedraw();
}

void ReactorHistory::clearHistory() {
	_numGuesses = 0;
	_showAnswer = false;
	triggerRedraw();
}

void ReactorHistory::setAnswer(int32 a, int32 b, int32 c) {
	_answer[0] = a;
	_answer[1] = b;
	_answer[2] = c;
}

void ReactorHistory::showAnswer() {
	_showAnswer = true;
	triggerRedraw();
}

bool ReactorHistory::isSolved() {
	for (int i = 0; i < _numGuesses; i++)
		if (_history[i][0] == _answer[0] && _history[i][1] == _answer[1] && _history[i][2] == _answer[2])
			return true;

	return false;
}

void ReactorHistory::draw(const Common::Rect &) {
	static const CoordType kColorTops[5] = {
		0,
		kColorHeights[0],
		(CoordType)(kColorHeights[0] + kColorHeights[1]),
		(CoordType)(kColorHeights[0] + kColorHeights[1] + kColorHeights[2]),
		(CoordType)(kColorHeights[0] + kColorHeights[1] + kColorHeights[2] + kColorHeights[3]),
	};

	if (_colors.isSurfaceValid() && _digits.isSurfaceValid()) {
		for (int i = 0; i < _numGuesses; ++i) {
			Common::Rect r1(0, 0, kColorWidths[i], kColorHeights[i]);
			Common::Rect r2 = r1;
			Common::Rect r3(0, 0, kDigitWidth, kDigitHeight);
			Common::Rect r4 = r3;
			int correct = 0;

			for (int j = 0; j < 3; ++j) {
				r1.moveTo(kColorWidths[i] * _history[i][j], kColorTops[i]);
				r2.moveTo(kHistoryLefts[i][j], kHistoryTops[i]);
				_colors.copyToCurrentPortTransparent(r1, r2);

				if (_history[i][j] == _answer[j])
					correct++;
			}

			r3.moveTo(kDigitWidth * correct, 0);
			r4.moveTo(kCorrectCountLefts[i], kCorrectCountTops[i]);
			_digits.copyToCurrentPort(r3, r4);
		}

		if (_showAnswer && _answerColors.isSurfaceValid()) {
			Common::Rect r1(0, 0, kOneAnswerWidth, kOneAnswerHeight);
			Common::Rect r2 = r1;

			for (int i = 0; i < 3; i++) {
				r1.moveTo(kOneAnswerWidth * _answer[i], 0);
				r2.moveTo(kAnswerLeft + 34 * i, kAnswerTop);
				_answerColors.copyToCurrentPortTransparent(r1, r2);
			}
		}
	}
}

int32 ReactorHistory::getCurrentNumCorrect() {
	int correct = 0;

	for (int i = 0; i < 3; i++)
		if (_history[_numGuesses - 1][i] == _answer[i])
			correct++;

	return correct;
}

} // End of namespace Pegasus