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
|
/* 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.
*
* 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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "bladerunner/ui/scores.h"
#include "bladerunner/bladerunner.h"
#include "bladerunner/font.h"
#include "bladerunner/savefile.h"
#include "bladerunner/scene.h"
#include "bladerunner/text_resource.h"
#include "bladerunner/vqa_player.h"
#include "common/keyboard.h"
namespace BladeRunner {
Scores::Scores(BladeRunnerEngine *vm) {
_vm = vm;
_font = nullptr;
_txtScorers = nullptr;
reset();
}
Scores::~Scores() {
}
void Scores::open() {
if (!_vm->openArchive("MODE.MIX")) {
return;
}
_vqaPlayer = new VQAPlayer(_vm, &_vm->_surfaceBack);
if (!_vqaPlayer->open("SCORE.VQA")) {
return;
}
_vqaPlayer->setLoop(1, -1, 0, nullptr, nullptr);
// TODO: Freeze game time
_txtScorers = new TextResource(_vm);
_txtScorers->open("SCORERS");
_font = new Font(_vm);
_font->open("TAHOMA24.FON", 640, 480, -1, 0, 0);
_font->setSpacing(1, 0);
fill();
_isOpen = true;
_isLoaded = false;
}
bool Scores::isOpen() const {
return _isOpen;
}
void Scores::close() {
_isOpen = false;
delete _font;
_font = nullptr;
delete _txtScorers;
_txtScorers = nullptr;
if (_vqaPlayer) {
_vqaPlayer->close();
delete _vqaPlayer;
_vqaPlayer = nullptr;
}
_vm->closeArchive("MODE.MIX");
// TODO: Unfreeze game time
_vm->_scene->resume();
}
void Scores::set(int index, int value) {
if (value > _scores[index]) {
_scores[index] = value;
}
_lastScoreId = index;
_lastScoreValue = value;
}
void Scores::handleKeyDown(const Common::KeyState &kbd) {
close();
}
int Scores::handleMouseUp(int x, int y) {
if (_isLoaded) {
close();
}
_isLoaded = false;
return false;
}
int Scores::handleMouseDown(int x, int y) {
_isLoaded = true;
return false;
}
void Scores::tick() {
if (!_vm->_gameIsRunning) {
return;
}
int frame = _vqaPlayer->update();
assert(frame >= -1);
// vqaPlayer renders to _surfaceBack
blit(_vm->_surfaceBack, _vm->_surfaceFront);
_vm->_surfaceFront.hLine(200, 139, 400, 0x3e0);
_vm->_surfaceFront.hLine(200, 347, 400, 0x1f);
_font->draw(_txtScorers->getText(7), _vm->_surfaceFront, 200, 114);
int y = 140;
for (int i = 0; i < 7; i++) {
_font->draw(_txtScorers->getText(_scorers[i]), _vm->_surfaceFront, 220, y);
_font->drawNumber(_scores[_scorers[i]], _vm->_surfaceFront, 360, y);
y += 26;
}
_font->draw(_txtScorers->getText(8), _vm->_surfaceFront, 200, 322);
_font->draw(_txtScorers->getText(_lastScoreId), _vm->_surfaceFront, 220, 348);
_font->drawNumber(_lastScoreValue, _vm->_surfaceFront, 360, 348);
_vm->blitToScreen(_vm->_surfaceFront);
}
void Scores::fill() {
for (int i = 0; i < 7; i++) {
_scorers[i] = i;
}
// Network sorting using Bose-Nelson Algorithm
const byte network[32] = { // Bose-Nelson
1,2, 3,4, 5,6,
0,2, 3,5, 4,6,
0,1, 4,5, 2,6,
0,4, 1,5,
0,3, 2,5,
1,3, 2,4,
2,3
};
for (int i = 0; i < 32; i += 2) {
int i1 = network[i], i2 = network[i + 1];
if (_scores[_scorers[i1]] < _scores[_scorers[i2]]) {
SWAP(_scorers[i1], _scorers[i2]);
}
}
}
void Scores::reset() {
_isOpen = false;
_isLoaded = false;
_vqaPlayer = nullptr;
for (int i = 0; i < 7; i++) {
_scores[i] = -80;
_scorers[i] = 0;
}
_lastScoreId = 0;
_lastScoreValue = 0;
}
void Scores::save(SaveFileWriteStream &f) {
for (int i = 0; i < 7; i++) {
f.writeInt(_scores[i]);
}
f.writeInt(_lastScoreId);
f.writeInt(_lastScoreValue);
}
void Scores::load(SaveFileReadStream &f) {
for (int i = 0; i < 7; i++) {
_scores[i] = f.readInt();
}
_lastScoreId = f.readInt();
_lastScoreValue = f.readInt();
}
} // End of namespace BladeRunner
|