ScummVM API documentation
shveik_portret.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_MINIGAMES_SHVEIK_PORTRET_H
23#define QDENGINE_MINIGAMES_SHVEIK_PORTRET_H
24
25#include "common/debug.h"
26
27#include "qdengine/qd_fwd.h"
28#include "qdengine/qdcore/qd_minigame_interface.h"
29
30namespace QDEngine {
31
33public:
36
37 bool init(const qdEngineInterface *engine_interface) {
38 debugC(1, kDebugMinigames, "ShveikPortret::init()");
39
40 _engine = engine_interface;
41 _scene = engine_interface->current_scene_interface();
42 if (!_scene)
43 return false;
44
45 _objArray[1].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31"); // "объект1"
46 _objArray[1].x = -1;
47 _objArray[1].y = -1;
48 _objArray[2].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x32"); // "объект2"
49 _objArray[2].x = -1;
50 _objArray[2].y = -1;
51 _objArray[3].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x33"); // "объект3"
52 _objArray[3].x = -1;
53 _objArray[3].y = -1;
54 _objArray[4].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x34"); // "объект4"
55 _objArray[4].x = -1;
56 _objArray[4].y = -1;
57 _objArray[5].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x35"); // "объект5"
58 _objArray[5].x = -1;
59 _objArray[5].y = -1;
60 _objArray[6].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x36"); // "объект6"
61 _objArray[6].x = -1;
62 _objArray[6].y = -1;
63 _objArray[7].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x37"); // "объект7"
64 _objArray[7].x = -1;
65 _objArray[7].y = -1;
66 _objArray[8].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x38"); // "объект8"
67 _objArray[8].x = -1;
68 _objArray[8].y = -1;
69 _objArray[9].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x39"); // "объект9"
70 _objArray[9].x = -1;
71 _objArray[9].y = -1;
72 _objArray[10].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x30"); // "объект10"
73 _objArray[10].x = -1;
74 _objArray[10].y = -1;
75 _objArray[11].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x31"); // "объект11"
76 _objArray[11].x = -1;
77 _objArray[11].y = -1;
78 _objArray[12].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x32"); // "объект12"
79 _objArray[12].x = -1;
80 _objArray[12].y = -1;
81 _objArray[13].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x33"); // "объект13"
82 _objArray[13].x = -1;
83 _objArray[13].y = -1;
84 _objArray[14].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x34"); // "объект14"
85 _objArray[14].x = -1;
86 _objArray[14].y = -1;
87 _objArray[15].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x35"); // "объект15"
88 _objArray[15].x = -1;
89 _objArray[15].y = -1;
90 _objArray[16].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x36"); // "объект16"
91 _objArray[16].x = -1;
92 _objArray[16].y = -1;
93 _objArray[17].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x37"); // "объект17"
94 _objArray[17].x = -1;
95 _objArray[17].y = -1;
96 _objArray[18].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x38"); // "объект18"
97 _objArray[18].x = -1;
98 _objArray[18].y = -1;
99 _objArray[19].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x31\x39"); // "объект19"
100 _objArray[19].x = -1;
101 _objArray[19].y = -1;
102 _objArray[20].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x32\x30"); // "объект20"
103 _objArray[20].x = -1;
104 _objArray[20].y = -1;
105 _objArray[21].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x32\x31"); // "объект21"
106 _objArray[21].x = -1;
107 _objArray[21].y = -1;
108 _objArray[22].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x32\x32"); // "объект22"
109 _objArray[22].x = -1;
110 _objArray[22].y = -1;
111 _objArray[23].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x32\x33"); // "объект23"
112 _objArray[23].x = -1;
113 _objArray[23].y = -1;
114 _objArray[24].obj = _scene->object_interface("\xee\xe1\xfa\xe5\xea\xf2\x32\x34"); // "объект24"
115 _objArray[24].x = -1;
116 _objArray[24].y = -1;
117
118 _clickObj = _scene->object_interface("\x24\xea\xeb\xe8\xea\xe8\x20\xee\xe1\xfa\xe5\xea\xf2\xee\xec"); // "$клики объектом"
119 _maskOutsideObj = _scene->object_interface("\x5f\xcc\xc0\xd1\xca\xc0\x20\xec\xe5\xf1\xf2\xee\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec"); // "_МАСКА место за полем"
120 _objectClickObj = _scene->object_interface("\x24\xea\xeb\xe8\xea\xe8\x20\xef\xee\x20\xee\xe1\xfa\xe5\xea\xf2\xf3"); // "$клики по объекту"
121 _doneObj = _scene->object_interface("$done");
122 _wasStartedObj = _scene->object_interface("\x24\xe7\xe0\xef\xf3\xf1\xea\x5f\xe1\xfb\xeb"); // "$запуск_был"
123 _oneAbsentObj = _scene->object_interface("$one_absent");
124 _exitClickObj = _scene->object_interface("\x24\xea\xeb\xe8\xea\x20\xef\xee\x20\xe2\xfb\xf5\xee\xe4\xf3"); // "$клик по выходу"
125 _completePicObj = _scene->object_interface("\xe3\xee\xf2\xee\xe2\xe0\xff\x20\xea\xe0\xf0\xf2\xe8\xed\xea\xe0"); // "готовая картинка"
126
127 _currentPieceRow = -1;
128 _currentPieceCol = -1;
129
130 if (_wasStartedObj->is_state_active("\xed\xe5\xf2")) { // "нет"
131 // srand(time(0))
132
133 for (int i = 1; i <= 24; i++) {
134 switch (qd_rnd(3)) {
135 case 0:
136 _objArray[i].obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec 0"); // "лежит за полем 0")
137 break;
138 case 1:
139 _objArray[i].obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec 90"); // "лежит за полем 90")
140 break;
141 case 2:
142 _objArray[i].obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec 180"); // "лежит за полем 180")
143 break;
144 case 3:
145 _objArray[i].obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec 270"); // "лежит за полем 270")
146 break;
147 default:
148 break;
149 }
150 }
151
152 _wasStartedObj->set_state("\xe4\xe0"); // "да"
153
154 for (int i = 0; i < 7; i++)
155 for (int j = 0; j < 6; j++) {
156 _fieldState[i][j].angle = -1;
157 _fieldState[i][j].pieceNum = -1;
158 }
159
160 } else {
161 for (int i = 0; i < 7; i++)
162 for (int j = 0; j < 6; j++) {
163 _fieldState[i][j].angle = -1;
164 _fieldState[i][j].pieceNum = -1;
165 }
166
167 if (!_doneObj->is_state_active("\xe4\xe0")) // "да"
168 processState();
169 }
170
171 _exitClickObj->set_state("\xed\xe5\xf2"); // "нет"
172 _draggedInvObjectState = 0;
173 _draggedObjectState = 0;
174
175 setPiecesDepth();
176 setPiecesPos();
177
178 if (_oneAbsentObj->is_state_active("\xed\xe5\xf2")) { // "нет"
179 _objArray[2].obj->set_R(_scene->screen2world_coords(mgVect2i(700, 500), 0.0));
180 _oneAbsentObj->set_state("\xf4\xeb\xe0\xe3\x20\xee\xf2\xf0\xe0\xe1\xee\xf2\xe0\xed"); // "флаг отработан"
181 }
182
183 return true;
184 }
185
186 bool quant(float dt) {
187 debugC(3, kDebugMinigames, "ShveikPortret::quant(%f)", dt);
188
189 if (_engine->is_key_pressed(VK_F1)) {
190 for (int j = 0; j < 7; j++) {
191 for (int i = 0; i < 6; i++) {
192 debugN("%02d ", _fieldState[j][i].pieceNum);
193 }
194
195 debugN(" ");
196
197 for (int i = 0; i < 6; i++) {
198 debugN("%3d ", _fieldState[j][i].angle);
199 }
200
201 debugN("\n");
202 }
203
204 debug("\n");
205 }
206
207 if (!_doneObj->is_state_active("\xe4\xe0")) { // "да"
208 if (checkSolution()) {
209 _doneObj->set_state("\xe4\xe0"); // "да"
210 _completePicObj->set_state("\xeb\xe8\xf6\xe5\xe2\xe0\xff\x20\xf1\xf2\xee\xf0\xee\xed\xe0"); // "лицевая сторона"
211
212 for (int i = 1; i <= 24; i++)
213 _objArray[i].obj->set_R(mgVect3f(-1000.0, -1000.0, -100.0));
214
215 _scene->activate_personage("\xd8\xe2\xe5\xe9\xea"); // "Швейк"
216
217 return true;
218 }
219 }
220
221 if (_exitClickObj->is_state_active("\xe4\xe0")) // "да"
222 _exitClickObj->set_state("\xe2\xfb\xf5\xee\xe4\x20\xf0\xe0\xe7\xf0\xe5\xf8\xe5\xed"); // "выход разрешен"
223
224 mgVect2i curPos = _engine->mouse_cursor_position();
225
226 if (_scene->mouse_object_interface()) {
227 if (_draggedObjectState) {
228 _objArray[_draggedObjectState].obj->set_state(_draggedInvObjectState);
229 _draggedInvObjectState = 0;
230 _draggedObjectState = 0;
231 }
232 }
233
234 int state = _clickObj->current_state_index();
236
237 if (state > 24) {
238 obj = _objArray[state - 24].obj;
239
240 if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 0")) { // "inv на мыши 0"
241 obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec 0"); // "лежит за полем 0"
242 } else if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 90")) { // "inv на мыши 90"
243 obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec 90"); // "лежит за полем 90"
244 } else if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 180")) { // "inv на мыши 180"
245 obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec 180"); // "лежит за полем 180"
246 } else if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 270")) { // "inv на мыши 270"
247 obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec 270"); // "лежит за полем 270"
248 }
249
250 if (_engine->mouse_cursor_position().x > 205
251 || _engine->mouse_cursor_position().x <= 155) {
252 if (_engine->mouse_cursor_position().x < 600
253 || _engine->mouse_cursor_position().x >= 649) {
254 obj->set_R(_scene->screen2world_coords(_engine->mouse_cursor_position(), 0.0));
255 } else {
256 mgVect2i pos = _engine->mouse_cursor_position();
257 pos.x = 649;
258 obj->set_R(_scene->screen2world_coords(pos, 0.0));
259 }
260 } else {
261 mgVect2i pos = _engine->mouse_cursor_position();
262 pos.x = 155;
263 obj->set_R(_scene->screen2world_coords(pos, 0.0));
264 }
265
266 obj->update_screen_R();
267 _objArray[state - 24].depth = 25.0f;
268
269 setPiecesPos();
270
271 _clickObj->set_state("\xed\xe5\xf2"); // "нет"
272 _maskOutsideObj->set_state("\x21\xec\xe0\xf1\xea\xe0"); // "!маска"
273 } else if (state > 0) {
274 _currentPieceRow = getPieceNumber(curPos.x, 204, 4, 99);
275 _currentPieceCol = getPieceNumber(curPos.y, 4, 6, 99);
276
277 obj = _objArray[state].obj;
278
279 if (_fieldState[_currentPieceRow][_currentPieceCol].pieceNum == -1) {
280 if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 0")) { // "inv на мыши 0"
281 obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 0"); // "лежит на поле 0"
282 _fieldState[_currentPieceRow][_currentPieceCol].angle = 0;
283 } else if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 90")) { // "inv на мыши 90"
284 obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 90"); // "лежит на поле 90"
285 _fieldState[_currentPieceRow][_currentPieceCol].angle = 90;
286 } else if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 180")) { // "inv на мыши 180"
287 obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 180"); // "лежит на поле 180"
288 _fieldState[_currentPieceRow][_currentPieceCol].angle = 180;
289 } else if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 270")) { // "inv на мыши 270"
290 obj->set_state("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 270"); // "лежит на поле 270"
291 _fieldState[_currentPieceRow][_currentPieceCol].angle = 270;
292 }
293
294 mgVect2i pos;
295
296 pos.x = 99 * _currentPieceRow + 154;
297 pos.y = 99 * _currentPieceCol - 46;
298
299 obj->set_R(_scene->screen2world_coords(pos, 0.0));
300
301 _objArray[state].x = _currentPieceRow;
302 _objArray[state].y = _currentPieceCol;
303 _fieldState[_currentPieceRow][_currentPieceCol].pieceNum = state;
304 }
305
306 _clickObj->set_state("\xed\xe5\xf2"); // "нет"
307 _maskOutsideObj->set_state("\x21\xec\xe0\xf1\xea\xe0"); // "!маска"
308 }
309
310 state = _objectClickObj->current_state_index();
311
312 if (state > 0) {
313 obj = _objArray[state].obj;
314
315 if (obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 0") // "лежит на поле 0"
316 || obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 90") // "лежит на поле 90"
317 || obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 180") // "лежит на поле 180"
318 || obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 270")) { // "лежит на поле 270"
319 _fieldState[_objArray[state].x][_objArray[state].y].pieceNum = -1;
320 _fieldState[_objArray[state].x][_objArray[state].y].angle = -1;
321
322 _objArray[state].x = -1;
323 _objArray[state].y = -1;
324 }
325
326 if (obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 0") // "лежит на поле 0"
327 || obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec\x20\x30")) { // "лежит за полем 0"
328 _draggedInvObjectState = obj->state_index("inv \xed\xe0\x20\xec\xfb\xf8\xe8 0"); // "inv на мыши 0"
329 }
330 if (obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 90") // "лежит на поле 90"
331 || obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec\x20\x39\x30")) { // "лежит за полем 90"
332 _draggedInvObjectState = obj->state_index("inv \xed\xe0\x20\xec\xfb\xf8\xe8 90"); // "inv на мыши 90"
333 }
334 if (obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 180") // "лежит на поле 180"
335 || obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec\x20\x31\x38\x30")) { // "лежит за полем 180"
336 _draggedInvObjectState = obj->state_index("inv \xed\xe0\x20\xec\xfb\xf8\xe8 180"); // "inv на мыши 180"
337 }
338 if (obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5 270") // "лежит на поле 270"
339 || obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xe7\xe0\x20\xef\xee\xeb\xe5\xec\x20\x32\x37\x30")) { // "лежит за полем 270"
340 _draggedInvObjectState = obj->state_index("inv \xed\xe0\x20\xec\xfb\xf8\xe8 270"); // "inv на мыши 270"
341 }
342
343 _draggedObjectState = state;
344
345 obj->set_state("to_inv");
346
347 _objectClickObj->set_state("\xed\xe5\xf2"); // "нет"
348 _maskOutsideObj->set_state("\xd4\xee\xed\x20\x2d\x20\xec\xe0\xf1\xea\xe0"); // Фон - маска"
349 }
350
353 obj =_scene->mouse_object_interface();
354
355 if (obj) {
356 if (obj->has_state("\xf3\xe4\xe0\xeb\xe8\xf2\xfc")) { // "удалить"
357 if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 0")) { // "inv на мыши 0"
358 obj->set_state("inv \xed\xe0\x20\xec\xfb\xf8\xe8 90"); // "inv на мыши 90"
359 return true;
360 }
361 if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 90")) { // "inv на мыши 90"
362 obj->set_state("inv \xed\xe0\x20\xec\xfb\xf8\xe8 180"); // "inv на мыши 180"
363 return true;
364 }
365 if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 180")) { // "inv на мыши 180"
366 obj->set_state("inv \xed\xe0\x20\xec\xfb\xf8\xe8 270"); // "inv на мыши 270"
367 return true;
368 }
369 if (obj->is_state_active("inv \xed\xe0\x20\xec\xfb\xf8\xe8 270")) { // "inv на мыши 270"
370 obj->set_state("inv \xed\xe0\x20\xec\xfb\xf8\xe8 0"); // "inv на мыши 0"
371 return true;
372 }
373 }
374 }
375 }
376
377 return true;
378 }
379
380 bool finit() {
381 debugC(1, kDebugMinigames, "ShveikPortret::finit()");
382
383 if (_scene) {
384 _engine->release_scene_interface(_scene);
385 _scene = 0;
386 }
387
388 return true;
389 }
390
391 bool new_game(const qdEngineInterface *engine_interface) {
392 return true;
393 }
394
395 int save_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, char *buffer, int buffer_size) {
396 return 0;
397 }
398
399 int load_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, const char *buffer, int buffer_size) {
400 return 0;
401 }
402
403 enum { INTERFACE_VERSION = 112 };
404 int version() const {
405 return INTERFACE_VERSION;
406 }
407
408private:
409 void processState() {
410 for (int i = 1; i <= 24; i++) {
411 if (_objArray[i].obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5\x20\x30") // "лежит на поле 0"
412 || _objArray[i].obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5\x20\x39\x30") // "лежит на поле 90"
413 || _objArray[i].obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5\x20\x31\x38\x30") // "лежит на поле 180"
414 || _objArray[i].obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5\x20\x32\x37\x30")) { // "лежит на поле 270"
415 mgVect2i pos = _objArray[i].obj->screen_R();
416
417 _objArray[i].x = (pos.x - 204) / 99 + 1;
418 _objArray[i].y = (pos.y - 4) / 99 + 1;
419 _fieldState[_objArray[i].x][_objArray[i].y].pieceNum = i;
420
421 if (_objArray[i].obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5\x20\x30")) { // "лежит на поле 0"
422 _fieldState[_objArray[i].x][_objArray[i].y].angle = 0;
423 } else if (_objArray[i].obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5\x20\x39\x30")) { // "лежит на поле 90"
424 _fieldState[_objArray[i].x][_objArray[i].y].angle = 90;
425 } else if (_objArray[i].obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5\x20\x31\x38\x30")) { // "лежит на поле 180"
426 _fieldState[_objArray[i].x][_objArray[i].y].angle = 180;
427 } else if (_objArray[i].obj->is_state_active("\xeb\xe5\xe6\xe8\xf2\x20\xed\xe0\x20\xef\xee\xeb\xe5\x20\x32\x37\x30")) { // "лежит на поле 270"
428 _fieldState[_objArray[i].x][_objArray[i].y].angle = 270;
429 }
430 } else {
431 _objArray[i].x = -1;
432 _objArray[i].y = -1;
433 }
434 }
435 }
436
437 void setPiecesDepth() {
438 for (int i = 1; i <= 24; i++) {
439 _objArray[i].depth = i;
440 _objArray[i].obj->set_R(_scene->screen2world_coords(_objArray[i].obj->screen_R(), 0.0));
441 }
442 }
443
444 void setPiecesPos() {
445 int target = -1;
446
447 for (int j = 1; j <= 24; j++) {
448 int i;
449 for (i = 1; i <= 24; ++i) {
450 if (j == _objArray[i].depth)
451 i = 26;
452 }
453
454 if (i == 25) {
455 target = j;
456 break;
457 }
458 }
459
460 if (target != -1) {
461 for (int i = 1; i <= 24; i++) {
462 if (target < _objArray[i].depth)
463 _objArray[i].depth -= 1.0;
464 }
465
466 for (int i = 1; i <= 24; i++) {
467 _objArray[i].obj->set_R(_scene->screen2world_coords(_objArray[i].obj->screen_R(), 100.0 - _objArray[i].depth * 100.0));
468 }
469 }
470 }
471
472 bool checkSolution() {
473 int n = 1;
474
475 // The original was comparing with the static array
476 for (int j = 1; j < 6; j++)
477 for (int i = 0; i < 6; i++) {
478 if ((j == 1 && i == 0) || (j == 5 && i > 0))
479 continue;
480
481 if (_fieldState[j][i].pieceNum != n || _fieldState[j][i].angle != 0)
482 return false;
483
484 n++;
485 }
486
487 return true;
488 }
489
490 int getPieceNumber(int left, int right, int dimSize, int step) {
491 if (dimSize < 1)
492 return dimSize;
493
494 int res = dimSize;
495 int curPos = step + 204;
496
497 for (int i = 1; i <= dimSize; i++) {
498 if (right <= left && curPos > left)
499 res = i;
500
501 right += step;
502 curPos += step;
503 }
504
505 return res;
506 }
507
508private:
509 const qdEngineInterface *_engine = nullptr;
510 qdMinigameSceneInterface *_scene = nullptr;
511
512 struct PieceState {
513 int pieceNum = -1;
514 int angle = -1;
515 };
516
517 struct ObjectStruct {
518 qdMinigameObjectInterface *obj = nullptr;
519 int x = 0;
520 int y = 0;
521 float depth = 0.0;
522 };
523
524 ObjectStruct _objArray[25];
525
526 int _draggedObjectState = 0;
527 int _draggedInvObjectState = 0;
528
529 qdMinigameObjectInterface *_clickObj = nullptr;
530 qdMinigameObjectInterface *_objectClickObj = nullptr;
531 qdMinigameObjectInterface *_maskOutsideObj = nullptr;
532 qdMinigameObjectInterface *_wasStartedObj = nullptr;
533 qdMinigameObjectInterface *_oneAbsentObj = nullptr;
534 qdMinigameObjectInterface *_exitClickObj = nullptr;
535 qdMinigameObjectInterface *_completePicObj = nullptr;
536 qdMinigameObjectInterface *_doneObj = nullptr;
537
538 int _currentPieceRow = 0;
539 int _currentPieceCol = 0;
540
541 PieceState _fieldState[7][6];
542};
543
544} // namespace QDEngine
545
546#endif // QDENGINE_MINIGAMES_SHVEIK_PORTRET_H
Definition: qd_minigame_interface.h:365
virtual mgVect2i mouse_cursor_position() const =0
Возвращает текущие координаты мышиного курсора.
virtual bool is_mouse_event_active(qdMinigameMouseEvent event_id) const =0
Возвращает true, если в данный момент произошло событие event_id.
@ MOUSE_EV_RIGHT_DOWN
Нажатие правой кнопки.
Definition: qd_minigame_interface.h:374
@ MOUSE_EV_RIGHT_DBLCLICK
Двойное нажатие правой кнопки.
Definition: qd_minigame_interface.h:378
virtual bool is_key_pressed(int vkey) const =0
Возвращает true, если на клавиатуре нажата кнопка vkey.
Definition: qd_minigame_interface.h:78
Интерфейс к динамическому объекту.
Definition: qd_minigame_interface.h:230
virtual int current_state_index() const =0
Возвращает номер включенного в данный момент состояния.
virtual int state_index(const char *state_name) const =0
Возвращает номер состояния с именем state_name.
virtual bool update_screen_R()=0
Обновляет координаты объекта в экранной системе координат.
virtual bool set_state(const char *state_name)=0
Включает состояние с именем state_name.
virtual void set_R(const mgVect3f &r)=0
Устанавливает координаты объекта в мировой системе координат.
virtual bool is_state_active(const char *state_name) const =0
Возвращает true, если состояние с именем state_name включено в данный момент.
virtual bool has_state(const char *state_name) const =0
Возвращает true, если у объекта есть состояние с именем state_name.
Интерфейс к сцене.
Definition: qd_minigame_interface.h:315
virtual qdMinigameObjectInterface * mouse_object_interface() const =0
Создаёт интерфейс к объекту, который взят мышью в данный момент.
virtual mgVect3f screen2world_coords(const mgVect2i &screen_pos, float screen_depth=0) const =0
Преобразование из экранных координат в мировые.
virtual qdMinigameObjectInterface * object_interface(const char *object_name, bool test=false)=0
Создаёт интерфейс к объекту с именем object_name.
virtual bool activate_personage(const char *personage_name)=0
Активация персонажа с именем personage_name.
Definition: shveik_portret.h:32
bool finit()
Деинициализация игры.
Definition: shveik_portret.h:380
bool new_game(const qdEngineInterface *engine_interface)
Инициализация миниигры, вызывается при старте и перезапуске игры.
Definition: shveik_portret.h:391
int load_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, const char *buffer, int buffer_size)
Загрузка данных, вызывается при загрузке сцены, на которую повешена миниигра.
Definition: shveik_portret.h:399
int save_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, char *buffer, int buffer_size)
Сохранение данных, вызывается при сохранении сцены, на которую повешена миниигра.
Definition: shveik_portret.h:395
bool quant(float dt)
Обсчёт логики игры, параметр - время, которое должно пройти в игре (в секундах).
Definition: shveik_portret.h:186
bool init(const qdEngineInterface *engine_interface)
Инициализация игры.
Definition: shveik_portret.h:37
void void void void void debugC(int level, uint32 debugChannel, MSVC_PRINTF const char *s,...) GCC_PRINTF(3
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
void void void debugN(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Базовый класс для игровых ресурсов.
Definition: console.h:28
uint32 qd_rnd(uint32 m)
Возвращает случайное значение в интервале [0, m-1].
Definition: qd_rnd.h:30