ScummVM API documentation
3mice2_raskr_all.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_3MICE2_RASKR_ALL_H
23#define QDENGINE_MINIGAMES_3MICE2_RASKR_ALL_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
32const int zoneCountInit1[] = {
33 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
34 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 64, 89, 90, 91,
35 92, 93, 94, 96, 97, 98, 99, 129, 130, 132, 134, 135, 136, 138, 139, 140, 141,
36 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 153, 154, 155, 156, 157, 158,
37 159, 160, 161, 162, 163, 164, 166, 167, 170, 172, 173, 174, 178, 179, 180, 182,
38 184, 185, 186, 187, 190, 192, 196, 197, 198, 199, 204, 205, 211, 212, 213, 214,
39 216, 217, 218, 219, 220, 221, 222, 223, 225, 226, 227, 229, 230, 231, 232, 234,
40 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 254, 255, 260, 261, 263,
41 265, 267, 268, 271, 272, 273, 274, 280, 283, 284, 287, 288, 289, 290, 292, 294,
42 296, 308, 309, 0
43};
44
45const int colorRegions1[] = {
46 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,
47 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 89, 308, 309, 311, 0,
48 64, 65, 0,
49 90, 91, 92, 190, 207, 0,
50 93, 94, 95, 0,
51 96, 97, 98, 99, 103, 0,
52 129, 132, 133, 0,
53 130, 131, 0,
54 134, 135, 136, 137, 0,
55 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 0,
56 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 0,
57 166, 167, 194, 0,
58 170, 171, 0,
59 172, 173, 174, 175, 0,
60 178, 179, 180, 182, 184, 185, 186, 187, 229, 230, 231, 232, 233, 0,
61 192, 282, 0,
62 196, 208, 0,
63 197, 198, 199, 200, 0,
64 204, 205, 206, 0,
65 211, 212, 213, 214, 215, 0,
66 216, 217, 218, 219, 220, 221, 222, 223, 224, 0,
67 225, 226, 227, 228, 0,
68 234, 235, 0,
69 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 0,
70 254, 255, 256, 0,
71 260, 261, 262, 0,
72 263, 264, 0,
73 265, 266, 0,
74 267, 268, 269, 0,
75 271, 272, 273, 274, 275, 0,
76 280, 281, 0,
77 283, 306, 0,
78 284, 287, 288, 289, 290, 307, 0,
79 292, 293, 0,
80 294, 295, 0,
81 296, 297, 0,
82 0,
83};
84
85const int zoneCountInit2[] = {
86 1, 2, 3, 4, 5, 6, 8, 16, 17, 18, 37, 46, 48, 49, 50, 51, 52, 53, 54, 55,
87 56, 57, 58, 59, 60, 61, 66, 69, 70, 71, 72, 73, 74, 75, 76, 78, 80, 81,
88 82, 83, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
89 101, 102, 106, 107, 108, 109, 111, 113, 114, 115, 116, 117, 118, 119, 121,
90 124, 126, 128, 130, 131, 132, 143, 146, 154, 156, 157, 191, 192, 193, 194,
91 195, 205, 0,
92};
93
94int colorRegions2[] = {
95 1, 2, 3, 4, 5, 55, 56, 57, 58, 59, 60, 93, 94, 95, 96, 97, 98, 99, 100, 101, 134, 0,
96 6, 7, 0,
97 8, 9, 0,
98 16, 17, 18, 19, 0,
99 37, 38, 0,
100 46, 47, 0,
101 48, 49, 50, 51, 52, 53, 54, 102, 103, 0,
102 61, 68, 0,
103 66, 67, 0,
104 69, 70, 71, 72, 73, 74, 75, 76, 81, 152, 0,
105 78, 79, 0,
106 80, 85, 86, 87, 88, 89, 90, 91, 92, 141, 0,
107 82, 83, 84, 0,
108 106, 107, 108, 109, 110, 0,
109 111, 112, 0,
110 113, 114, 115, 116, 117, 118, 119, 120, 0,
111 121, 122, 0,
112 124, 125, 0,
113 126, 127, 0,
114 128, 129, 0,
115 130, 131, 132, 133, 0,
116 143, 144, 0,
117 146, 147, 0,
118 154, 155, 0,
119 156, 159, 0,
120 157, 158, 0,
121 191, 192, 193, 194, 195, 196, 0,
122 205, 206, 0,
123 0,
124};
125
126const int zoneCountInit3[] = {
127 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
128 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 189, 190, -1
129};
130
131const int colorRegions3[] = {
132 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,
133 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0,
134 190, 191, 192, 0,
135 0,
136};
137
138const int zoneCountInit4[] = {
139 0
140};
141
142const int colorRegions4[] = {
143 0,
144 0,
145};
146
147
149public:
150 qd3mice2RaskrAllMiniGame(int gameNum) : _gameNum(gameNum) {}
152
153 bool init(const qdEngineInterface *engine_interface) {
154 debugC(1, kDebugMinigames, "3mice2RaskrAll::init()");
155
156 _engine = engine_interface;
157 _scene = engine_interface->current_scene_interface();
158 if (!_scene)
159 return false;
160
161 const int *zoneCountInit = nullptr;
162 int zoneCountDelta = 0;
163
164 if (_gameNum == 1) {
165 _numZones = 311;
166 _colorRegions = colorRegions1;
167 _colorRegionsSize = ARRAYSIZE(colorRegions1);
168 _neededColors = 50;
169
170 zoneCountInit = zoneCountInit1;
171 zoneCountDelta = 0;
172 } else if (_gameNum == 2) {
173 _numZones = 206;
174 _colorRegions = colorRegions2;
175 _colorRegionsSize = ARRAYSIZE(colorRegions2);
176 _neededColors = 50;
177
178 zoneCountInit = zoneCountInit2;
179 zoneCountDelta = 0;
180 } else if (_gameNum == 3) {
181 _numZones = 265;
182 _colorRegions = colorRegions3;
183 _colorRegionsSize = ARRAYSIZE(colorRegions3);
184 _neededColors = 70;
185
186 zoneCountInit = zoneCountInit3;
187 zoneCountDelta = 1;
188 } else if (_gameNum == 4) {
189 _numZones = 133;
190 _colorRegions = colorRegions4;
191 _colorRegionsSize = ARRAYSIZE(colorRegions4);
192 _neededColors = 50;
193
194 zoneCountInit = zoneCountInit4;
195 zoneCountDelta = 0;
196 } else {
197 error("qd3mice2RaskrAllMiniGame::init(): Unsupported gameNumber: %d", _gameNum);
198 }
199
200 for (int i = 1; i <= _numZones; i++) {
201 _zones[i] = _scene->object_interface(Common::String::format("zone@%i#", i).c_str());
202 _zoneCount[i] = true;
203 }
204
205 for (int i = 0; zoneCountInit[i] + zoneCountDelta != 0; i++)
206 _zoneCount[zoneCountInit[i] + zoneCountDelta] = false;
207
208 _objColor = _scene->object_interface("$color");
209 _objColorSel = _scene->object_interface("$color_sel");
210 _objLoaded = _scene->object_interface("$loaded");
211 _objDone = _scene->object_interface("$done");
212
213 if (_objLoaded->is_state_active("no")) {
214 for (int i = 1; i <= _numZones; i++)
215 _zones[i]->set_shadow(0xFEFEFF, 0);
216
217 _objColorSel->set_state("!\xEC\xE0\xF1\xEA\xE0"); // "!маска"
218 _objColor->set_shadow(0xFEFEFE, 0);
219 _objLoaded->set_state("yes");
220 }
221
222 _timePassed = 0;
223
224 return true;
225 }
226
227 bool quant(float dt) {
228 debugC(3, kDebugMinigames, "3mice2RaskrAll::quant(%f)", dt);
229
230 _timePassed += dt;
231
232 if (_timePassed > 0.5) {
233 if (checkSolution())
234 _objDone->set_state("\xe4\xe0"); // "да"
235
236 _timePassed = 0.0;
237 }
238
240
241 if (!mouseObj)
242 return true;
243
244 const char *name = mouseObj->name();
245
246 if (strstr(name, "@color@")) {
247 _objColor->set_shadow(mouseObj->shadow_color(), mouseObj->shadow_alpha());
248
249 Common::String color;
250 for (int i = 8; name[i] != '#'; i++)
251 color += name[i];
252
253 _objColorSel->set_state(color.c_str());
254 } else {
255 if (strstr(name, "zone@")) {
256 int num = getObjNum(name);
257
258 int start = 0;
259 for (int i = 0; i < _colorRegionsSize; i++) {
260 if (_colorRegions[i] == 0) {
261 start = i + 1;
262 continue;
263 }
264
265 if (_colorRegions[i] == num)
266 break;
267 }
268
269 debugC(2, kDebugMinigames, "zone: %d", num);
270
271 if (start < _colorRegionsSize) {
272 for (int i = start; _colorRegions[i] != 0; i++)
273 _zones[_colorRegions[i]]->set_shadow(_objColor->shadow_color(), _objColor->shadow_alpha());
274 } else {
275 _zones[num]->set_shadow(_objColor->shadow_color(), _objColor->shadow_alpha());
276 }
277 }
278 }
279 _scene->release_object_interface(mouseObj);
280
281 return true;
282 }
283
284 bool finit() {
285 debugC(1, kDebugMinigames, "3mice2RaskrAll::finit()");
286
287 if (_scene) {
288 _engine->release_scene_interface(_scene);
289 _scene = 0;
290 }
291
292 return true;
293 }
294
295 bool new_game(const qdEngineInterface *engine_interface) {
296 return true;
297 }
298
299 int save_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, char *buffer, int buffer_size) {
300 return 0;
301 }
302
303 int load_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, const char *buffer, int buffer_size) {
304 return 0;
305 }
306
307 enum { INTERFACE_VERSION = 112 };
308 int version() const {
309 return INTERFACE_VERSION;
310 }
311
312private:
313 bool checkSolution() {
314 int count = 0;
315
316 for (int i = 1; i <= _numZones; i++) {
317 if (_zones[i]->shadow_color() != 0)
318 if (_zoneCount[i])
319 count++;
320 }
321
322 debugC(2, kDebugMinigames, "Solution count: %d zone234: %06x", count, _zones[234]->shadow_color());
323
324 return count > _neededColors;
325 }
326
327 int getObjNum(const char *name) {
328 const char *from = strstr(name, "@");
329 const char *to = strstr(name, "#");
330 char tmp[20];
331
332 Common::strlcpy(tmp, from + 1, to - from);
333
334 return atol(tmp);
335 }
336
337private:
338 const qdEngineInterface *_engine = nullptr;
339 qdMinigameSceneInterface *_scene = nullptr;
340
341 qdMinigameObjectInterface *_zones[312] = { nullptr };
342 qdMinigameObjectInterface *_objColor = nullptr;
343 qdMinigameObjectInterface *_objColorSel = nullptr;
344 qdMinigameObjectInterface *_objLoaded = nullptr;
345 qdMinigameObjectInterface *_objDone = nullptr;
346
347 bool _zoneCount[312] = { false };
348 int _numZones = 0;
349
350 float _timePassed = 0;
351
352 int _gameNum = 0;
353
354 const int *_colorRegions = nullptr;
355 int _colorRegionsSize = 0;
356 int _neededColors = 0;
357};
358
359} // namespace QDEngine
360
361#endif // QDENGINE_MINIGAMES_3MICE2_RASKR_ALL_H
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: 3mice2_raskr_all.h:148
bool new_game(const qdEngineInterface *engine_interface)
Инициализация миниигры, вызывается при старте и перезапуске игры.
Definition: 3mice2_raskr_all.h:295
int load_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, const char *buffer, int buffer_size)
Загрузка данных, вызывается при загрузке сцены, на которую повешена миниигра.
Definition: 3mice2_raskr_all.h:303
bool finit()
Деинициализация игры.
Definition: 3mice2_raskr_all.h:284
bool quant(float dt)
Обсчёт логики игры, параметр - время, которое должно пройти в игре (в секундах).
Definition: 3mice2_raskr_all.h:227
int save_game(const qdEngineInterface *engine_interface, const qdMinigameSceneInterface *scene_interface, char *buffer, int buffer_size)
Сохранение данных, вызывается при сохранении сцены, на которую повешена миниигра.
Definition: 3mice2_raskr_all.h:299
bool init(const qdEngineInterface *engine_interface)
Инициализация игры.
Definition: 3mice2_raskr_all.h:153
Definition: qd_minigame_interface.h:365
Definition: qd_minigame_interface.h:78
Интерфейс к динамическому объекту.
Definition: qd_minigame_interface.h:230
virtual int shadow_alpha() const =0
Возвращает прозрачность затенения, значения - [0, 255], если равно -1, то затенения нет.
virtual bool set_state(const char *state_name)=0
Включает состояние с именем state_name.
virtual bool set_shadow(int shadow_color, int shadow_alpha)=0
Устанавливает затенение.
virtual int shadow_color() const =0
Возвращает цвет затенения.
virtual bool is_state_active(const char *state_name) const =0
Возвращает true, если состояние с именем state_name включено в данный момент.
virtual const char * name() const =0
Имя объекта.
Интерфейс к сцене.
Definition: qd_minigame_interface.h:315
virtual qdMinigameObjectInterface * mouse_click_object_interface() const =0
Создаёт интерфейс к объекту, по которому кликнули мышью.
virtual qdMinigameObjectInterface * object_interface(const char *object_name, bool test=false)=0
Создаёт интерфейс к объекту с именем object_name.
void void void void void debugC(int level, uint32 debugChannel, MSVC_PRINTF const char *s,...) GCC_PRINTF(3
size_t strlcpy(char *dst, const char *src, size_t size)
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
#define ARRAYSIZE(x)
Definition: util.h:114
Базовый класс для игровых ресурсов.
Definition: console.h:28