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
|
/* 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 "titanic/star_control/star_field.h"
#include "titanic/star_control/surface_area.h"
#include "titanic/star_control/star_control_sub12.h"
#include "titanic/titanic.h"
namespace Titanic {
CStarField::CStarField() : _points1On(false), _points2On(false), _mode(MODE_STARFIELD),
_val4(true), _val5(0), _isSolved(false) {
}
void CStarField::load(SimpleFile *file) {
_sub7.load(file);
_sub8.load(file);
_points1On = file->readNumber();
_points2On = file->readNumber();
_mode = (StarMode)file->readNumber();
_val4 = file->readNumber();
_isSolved = file->readNumber();
}
void CStarField::save(SimpleFile *file, int indent) {
_sub7.save(file, indent);
_sub8.save(file, indent);
file->writeNumberLine(_points1On, indent);
file->writeNumberLine(_points2On, indent);
file->writeNumberLine(_mode, indent);
file->writeNumberLine(_val4, indent);
file->writeNumberLine(_isSolved, indent);
}
bool CStarField::initDocument() {
bool valid = setup() && _points1.initialize();
if (valid)
valid = _sub5.setup();
if (valid)
valid = _points1.initialize();
if (valid)
valid = _points2.initialize();
return valid;
}
void CStarField::render(CVideoSurface *surface, CStarControlSub12 *sub12) {
CSurfaceArea surfaceArea(surface);
draw(&surfaceArea, sub12, &_sub5);
if (_val4)
fn3(&surfaceArea);
_sub7.draw(&surfaceArea, sub12, nullptr);
_sub8.draw(&surfaceArea);
if (_points2On)
_points2.draw(&surfaceArea, sub12);
if (_points1On)
_points1.draw(&surfaceArea, sub12);
fn4(&surfaceArea, sub12);
}
int CStarField::get1() const {
return _points1On;
}
void CStarField::set1(int val) {
_points1On = val;
}
int CStarField::get2() const {
return _points2On;
}
void CStarField::set2(int val) {
_points2On = val;
}
int CStarField::get54() const {
return _sub5.get4();
}
void CStarField::set54(int val) {
_sub5.set4(val);
}
StarMode CStarField::getMode() const {
return _mode;
}
void CStarField::setMode(StarMode mode) {
_mode = mode;
}
void CStarField::toggle4() {
_val4 = !_val4;
}
bool CStarField::set4(bool val) {
bool oldVal = _val4;
_val4 = val;
return oldVal;
}
int CStarField::get88() const {
return _sub8._field8;
}
int CStarField::get5() const {
return _val5;
}
void CStarField::setSolved() {
_isSolved = _sub8._field8 == 2;
}
bool CStarField::isSolved() const {
return _isSolved;
}
void CStarField::fn1(CErrorCode *errorCode) {
_sub5.proc3(errorCode);
}
void CStarField::fn3(CSurfaceArea *surfaceArea) {
uint oldPixel = surfaceArea->_pixel;
surfaceArea->_pixel = 0x323232;
surfaceArea->setColorFromPixel();
surfaceArea->fn1(FRect(202.60417, 63.75, 397.39584, 63.75));
surfaceArea->fn1(FRect(202.60417, 276.25, 397.39584, 276.25));
surfaceArea->fn1(FRect(193.75, 72.604164, 193.75, 267.39584));
surfaceArea->fn1(FRect(406.25, 72.604164, 406.25, 267.39584));
surfaceArea->fn1(FRect(202.60417, 63.75, 202.60417, 68.177086));
surfaceArea->fn1(FRect(397.39584, 63.75, 397.39584, 68.177086));
surfaceArea->fn1(FRect(202.60417, 276.25, 202.60417, 271.82291));
surfaceArea->fn1(FRect(397.39584, 276.25, 397.39584, 271.82291));
surfaceArea->fn1(FRect(193.75, 72.604164, 198.17708, 72.604164));
surfaceArea->fn1(FRect(193.75, 267.39584, 198.17708, 267.39584));
surfaceArea->fn1(FRect(406.25, 72.604164, 401.82291, 72.604164));
surfaceArea->fn1(FRect(406.25, 267.39584, 401.82291, 267.39584));
surfaceArea->fn1(FRect(300.0, 63.75, 300.0, 54.895832));
surfaceArea->fn1(FRect(300.0, 276.25, 300.0, 285.10416));
surfaceArea->fn1(FRect(193.75, 170.0, 184.89583, 170.0));
surfaceArea->fn1(FRect(406.25, 170.0, 415.10416, 170.0));
surfaceArea->_pixel = oldPixel;
surfaceArea->setColorFromPixel();
}
void CStarField::fn4(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12) {
FVector v1, v2, v3;
_val5 = 0;
if (_mode == MODE_STARFIELD) {
if (fn5(surfaceArea, sub12, v1, v2, v3) > -1.0) {
surfaceArea->_pixel = 0xA0A0;
surfaceArea->setColorFromPixel();
surfaceArea->fn1(FRect(v1._x, v1._y, v3._x, v3._y));
}
}
}
double CStarField::fn5(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12,
FVector &v1, FVector &v2, FVector &v3) {
if (_sub8._fieldC < 0)
return -1.0;
const CBaseStarEntry *dataP = _sub7.getDataPtr(_sub8._fieldC);
v2 = dataP->_position;
FVector tv;
sub12->proc29(2, v2, tv);
if (sub12->proc25() >= tv._z)
return -1.0;
sub12->proc28(2, tv, tv);
v1 = FVector(tv._x + surfaceArea->_centroid._x,
tv._y + surfaceArea->_centroid._y, tv._z);
FPoint pt = _sub8.getPosition();
v3 = FVector(pt._x, pt._y, 1.0);
double incr = (v1._x - pt._x) * (v1._x - pt._x);
if (incr > 3600.0)
return -1.0;
if ((v1._y - pt._y) * (v1._y - pt._y) + incr > 3600.0)
return -1.0;
_val5 = 1;
return v1._y - pt._y;
}
void CStarField::fn6(CVideoSurface *surface, CStarControlSub12 *sub12) {
CSurfaceArea surfaceArea(surface);
_sub8.fn1(this, &surfaceArea, sub12);
}
void CStarField::fn7() {
_sub8.fn3();
setSolved();
}
void CStarField::fn8(CVideoSurface *surface) {
_sub8.fn2(surface, this, &_sub7);
setSolved();
}
bool CStarField::mouseButtonDown(CVideoSurface *surface, CStarControlSub12 *sub12,
int flags, const Common::Point &pt) {
if (_mode == MODE_STARFIELD) {
CSurfaceArea surfaceArea(surface);
return selectStar(&surfaceArea, sub12, pt);
} else {
int starNum = _sub8.findStar(pt);
if (starNum >= 0) {
_sub8.selectStar(starNum, surface, this, &_sub7);
return true;
}
return false;
}
}
const CBaseStarEntry *CStarField::getRandomStar() const {
if (_data.empty())
return nullptr;
return getDataPtr(g_vm->getRandomNumber(_data.size() - 1));
}
const CBaseStarEntry *CStarField::getStar(int index) const {
return (index < 0 || index >= (int)_data.size()) ? nullptr : getDataPtr(index);
}
} // End of namespace Titanic
|