New plugin: FFT, A frequency analyzer plugin
[kugel-rb.git] / apps / plugins / sokoban.c
blobb9e0aa1d2e660cd67fcdb519c1b0b487a23f9510
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Eric Linenberg
11 * February 2003: Robert Hak performs a cleanup/rewrite/feature addition.
12 * Eric smiles. Bjorn cries. Linus say 'huh?'.
13 * March 2007: Sean Morrisey performs a major rewrite/feature addition.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
24 #include "plugin.h"
25 #include "lib/playback_control.h"
27 PLUGIN_HEADER
29 #define SOKOBAN_TITLE "Sokoban"
31 #define SOKOBAN_LEVELS_FILE PLUGIN_GAMES_DIR "/sokoban.levels"
32 #define SOKOBAN_SAVE_FILE PLUGIN_GAMES_DIR "/sokoban.save"
33 #define SOKOBAN_SAVE_FOLDER "/games"
35 #include "pluginbitmaps/sokoban_tiles.h"
36 #define SOKOBAN_TILESIZE BMPWIDTH_sokoban_tiles
38 /* If tilesize is 0 (which it is during dependency generation) gcc will abort
39 (div by 0) and this plugin won't get any dependencies
41 #if SOKOBAN_TILESIZE < 1
42 #define SOKOBAN_TILESIZE 10
43 #endif
45 /* SOKOBAN_TILESIZE is the number of pixels for each block.
46 * Set dynamically so all targets can support levels
47 * that fill their entire screen, less the stat box.
48 * 16 rows & 20 cols minimum */
49 #if LCD_WIDTH > LCD_HEIGHT /* horizontal layout*/
50 #define ROWS (LCD_HEIGHT/SOKOBAN_TILESIZE)
51 #if (LCD_WIDTH+4) >= (20*SOKOBAN_TILESIZE+40) /* wide or narrow stats box */
52 #define COLS ((LCD_WIDTH-40)/SOKOBAN_TILESIZE)
53 #else
54 #define COLS ((LCD_WIDTH-32)/SOKOBAN_TILESIZE)
55 #endif
56 #else /* vertical layout*/
57 #define ROWS ((LCD_HEIGHT-25)/SOKOBAN_TILESIZE)
58 #define COLS (LCD_WIDTH/SOKOBAN_TILESIZE)
59 #endif
61 /* Use either all but 16k of the plugin buffer for level data
62 * or 128k, which ever is less */
63 #if PLUGIN_BUFFER_SIZE - 0x4000 < 0x20000
64 #define MAX_LEVEL_DATA (PLUGIN_BUFFER_SIZE - 0x4000)
65 #else
66 #define MAX_LEVEL_DATA 0x20000
67 #endif
69 /* Number of levels for which to allocate buffer indexes */
70 #define MAX_LEVELS MAX_LEVEL_DATA/70
72 /* Use 4k plus remaining plugin buffer (-12k for prog) for undo, up to 64k */
73 #if PLUGIN_BUFFER_SIZE - MAX_LEVEL_DATA - 0x3000 > 0x10000
74 #define MAX_UNDOS 0x10000
75 #else
76 #define MAX_UNDOS (PLUGIN_BUFFER_SIZE - MAX_LEVEL_DATA - 0x3000)
77 #endif
79 /* Move/push definitions for undo */
80 #define SOKOBAN_PUSH_LEFT 'L'
81 #define SOKOBAN_PUSH_RIGHT 'R'
82 #define SOKOBAN_PUSH_UP 'U'
83 #define SOKOBAN_PUSH_DOWN 'D'
84 #define SOKOBAN_MOVE_LEFT 'l'
85 #define SOKOBAN_MOVE_RIGHT 'r'
86 #define SOKOBAN_MOVE_UP 'u'
87 #define SOKOBAN_MOVE_DOWN 'd'
89 #define SOKOBAN_MOVE_DIFF (SOKOBAN_MOVE_LEFT-SOKOBAN_PUSH_LEFT)
90 #define SOKOBAN_MOVE_MIN SOKOBAN_MOVE_DOWN
92 /* variable button definitions */
93 #if (CONFIG_KEYPAD == RECORDER_PAD) || \
94 (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
95 #define SOKOBAN_LEFT BUTTON_LEFT
96 #define SOKOBAN_RIGHT BUTTON_RIGHT
97 #define SOKOBAN_UP BUTTON_UP
98 #define SOKOBAN_DOWN BUTTON_DOWN
99 #define SOKOBAN_MENU BUTTON_OFF
100 #define SOKOBAN_UNDO BUTTON_ON
101 #define SOKOBAN_REDO BUTTON_PLAY
102 #define SOKOBAN_LEVEL_DOWN BUTTON_F1
103 #define SOKOBAN_LEVEL_REPEAT BUTTON_F2
104 #define SOKOBAN_LEVEL_UP BUTTON_F3
105 #define SOKOBAN_PAUSE BUTTON_PLAY
106 #define BUTTON_SAVE BUTTON_ON
107 #define BUTTON_SAVE_NAME "ON"
109 #elif CONFIG_KEYPAD == ONDIO_PAD
110 #define SOKOBAN_LEFT BUTTON_LEFT
111 #define SOKOBAN_RIGHT BUTTON_RIGHT
112 #define SOKOBAN_UP BUTTON_UP
113 #define SOKOBAN_DOWN BUTTON_DOWN
114 #define SOKOBAN_MENU BUTTON_OFF
115 #define SOKOBAN_UNDO_PRE BUTTON_MENU
116 #define SOKOBAN_UNDO (BUTTON_MENU | BUTTON_REL)
117 #define SOKOBAN_REDO (BUTTON_MENU | BUTTON_DOWN)
118 #define SOKOBAN_LEVEL_DOWN (BUTTON_MENU | BUTTON_LEFT)
119 #define SOKOBAN_LEVEL_REPEAT (BUTTON_MENU | BUTTON_UP)
120 #define SOKOBAN_LEVEL_UP (BUTTON_MENU | BUTTON_RIGHT)
121 #define SOKOBAN_PAUSE BUTTON_MENU
122 #define BUTTON_SAVE BUTTON_MENU
123 #define BUTTON_SAVE_NAME "MENU"
125 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
126 (CONFIG_KEYPAD == IRIVER_H300_PAD)
127 #define SOKOBAN_LEFT BUTTON_LEFT
128 #define SOKOBAN_RIGHT BUTTON_RIGHT
129 #define SOKOBAN_UP BUTTON_UP
130 #define SOKOBAN_DOWN BUTTON_DOWN
131 #define SOKOBAN_MENU BUTTON_OFF
132 #define SOKOBAN_UNDO BUTTON_REC
133 #define SOKOBAN_REDO BUTTON_MODE
134 #define SOKOBAN_LEVEL_DOWN (BUTTON_ON | BUTTON_DOWN)
135 #define SOKOBAN_LEVEL_REPEAT BUTTON_ON
136 #define SOKOBAN_LEVEL_UP (BUTTON_ON | BUTTON_UP)
137 #define SOKOBAN_PAUSE BUTTON_ON
138 #define BUTTON_SAVE BUTTON_MODE
139 #define BUTTON_SAVE_NAME "MODE"
141 #define SOKOBAN_RC_MENU BUTTON_RC_STOP
143 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
144 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
145 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
146 #define SOKOBAN_LEFT BUTTON_LEFT
147 #define SOKOBAN_RIGHT BUTTON_RIGHT
148 #define SOKOBAN_UP BUTTON_MENU
149 #define SOKOBAN_DOWN BUTTON_PLAY
150 #define SOKOBAN_MENU (BUTTON_SELECT | BUTTON_MENU)
151 #define SOKOBAN_UNDO_PRE BUTTON_SELECT
152 #define SOKOBAN_UNDO (BUTTON_SELECT | BUTTON_REL)
153 #define SOKOBAN_REDO (BUTTON_SELECT | BUTTON_PLAY)
154 #define SOKOBAN_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT)
155 #define SOKOBAN_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT)
156 #define SOKOBAN_PAUSE BUTTON_SELECT
157 #define BUTTON_SAVE BUTTON_SELECT
158 #define BUTTON_SAVE_NAME "SELECT"
160 /* FIXME: if/when simultaneous button presses work for X5/M5,
161 * add level up/down */
162 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
163 #define SOKOBAN_LEFT BUTTON_LEFT
164 #define SOKOBAN_RIGHT BUTTON_RIGHT
165 #define SOKOBAN_UP BUTTON_UP
166 #define SOKOBAN_DOWN BUTTON_DOWN
167 #define SOKOBAN_MENU BUTTON_POWER
168 #define SOKOBAN_UNDO_PRE BUTTON_SELECT
169 #define SOKOBAN_UNDO (BUTTON_SELECT | BUTTON_REL)
170 #define SOKOBAN_LEVEL_REPEAT BUTTON_REC
171 #define SOKOBAN_REDO BUTTON_PLAY
172 #define SOKOBAN_PAUSE BUTTON_PLAY
173 #define BUTTON_SAVE BUTTON_SELECT
174 #define BUTTON_SAVE_NAME "SELECT"
176 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
177 #define SOKOBAN_LEFT BUTTON_LEFT
178 #define SOKOBAN_RIGHT BUTTON_RIGHT
179 #define SOKOBAN_UP BUTTON_SCROLL_UP
180 #define SOKOBAN_DOWN BUTTON_SCROLL_DOWN
181 #define SOKOBAN_MENU BUTTON_POWER
182 #define SOKOBAN_UNDO_PRE BUTTON_REW
183 #define SOKOBAN_UNDO (BUTTON_REW | BUTTON_REL)
184 #define SOKOBAN_REDO BUTTON_FF
185 #define SOKOBAN_LEVEL_DOWN (BUTTON_PLAY | BUTTON_SCROLL_DOWN)
186 #define SOKOBAN_LEVEL_REPEAT (BUTTON_PLAY | BUTTON_RIGHT)
187 #define SOKOBAN_LEVEL_UP (BUTTON_PLAY | BUTTON_SCROLL_UP)
188 #define SOKOBAN_PAUSE BUTTON_PLAY
189 #define BUTTON_SAVE BUTTON_PLAY
190 #define BUTTON_SAVE_NAME "PLAY"
192 #elif CONFIG_KEYPAD == GIGABEAT_PAD
193 #define SOKOBAN_LEFT BUTTON_LEFT
194 #define SOKOBAN_RIGHT BUTTON_RIGHT
195 #define SOKOBAN_UP BUTTON_UP
196 #define SOKOBAN_DOWN BUTTON_DOWN
197 #define SOKOBAN_MENU BUTTON_POWER
198 #define SOKOBAN_UNDO BUTTON_SELECT
199 #define SOKOBAN_REDO BUTTON_A
200 #define SOKOBAN_LEVEL_DOWN BUTTON_VOL_DOWN
201 #define SOKOBAN_LEVEL_REPEAT BUTTON_MENU
202 #define SOKOBAN_LEVEL_UP BUTTON_VOL_UP
203 #define SOKOBAN_PAUSE BUTTON_SELECT
204 #define BUTTON_SAVE BUTTON_SELECT
205 #define BUTTON_SAVE_NAME "SELECT"
207 #elif CONFIG_KEYPAD == SANSA_E200_PAD
208 #define SOKOBAN_LEFT BUTTON_LEFT
209 #define SOKOBAN_RIGHT BUTTON_RIGHT
210 #define SOKOBAN_UP BUTTON_UP
211 #define SOKOBAN_DOWN BUTTON_DOWN
212 #define SOKOBAN_MENU BUTTON_POWER
213 #define SOKOBAN_UNDO_PRE BUTTON_SELECT
214 #define SOKOBAN_UNDO (BUTTON_SELECT | BUTTON_REL)
215 #define SOKOBAN_REDO BUTTON_REC
216 #define SOKOBAN_LEVEL_DOWN (BUTTON_SELECT | BUTTON_DOWN)
217 #define SOKOBAN_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_RIGHT)
218 #define SOKOBAN_LEVEL_UP (BUTTON_SELECT | BUTTON_UP)
219 #define SOKOBAN_PAUSE BUTTON_SELECT
220 #define BUTTON_SAVE BUTTON_SELECT
221 #define BUTTON_SAVE_NAME "SELECT"
223 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
224 #define SOKOBAN_LEFT BUTTON_LEFT
225 #define SOKOBAN_RIGHT BUTTON_RIGHT
226 #define SOKOBAN_UP BUTTON_UP
227 #define SOKOBAN_DOWN BUTTON_DOWN
228 #define SOKOBAN_MENU (BUTTON_HOME|BUTTON_REPEAT)
229 #define SOKOBAN_UNDO_PRE BUTTON_SELECT
230 #define SOKOBAN_UNDO (BUTTON_SELECT | BUTTON_REL)
231 #define SOKOBAN_REDO (BUTTON_SELECT | BUTTON_LEFT)
232 #define SOKOBAN_LEVEL_DOWN (BUTTON_SELECT | BUTTON_DOWN)
233 #define SOKOBAN_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_RIGHT)
234 #define SOKOBAN_LEVEL_UP (BUTTON_SELECT | BUTTON_UP)
235 #define SOKOBAN_PAUSE BUTTON_SELECT
236 #define BUTTON_SAVE BUTTON_SELECT
237 #define BUTTON_SAVE_NAME "SELECT"
239 #elif CONFIG_KEYPAD == SANSA_C200_PAD
240 #define SOKOBAN_LEFT BUTTON_LEFT
241 #define SOKOBAN_RIGHT BUTTON_RIGHT
242 #define SOKOBAN_UP BUTTON_UP
243 #define SOKOBAN_DOWN BUTTON_DOWN
244 #define SOKOBAN_MENU BUTTON_POWER
245 #define SOKOBAN_UNDO_PRE BUTTON_SELECT
246 #define SOKOBAN_UNDO (BUTTON_SELECT | BUTTON_REL)
247 #define SOKOBAN_REDO BUTTON_REC
248 #define SOKOBAN_LEVEL_DOWN BUTTON_VOL_DOWN
249 #define SOKOBAN_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_RIGHT)
250 #define SOKOBAN_LEVEL_UP BUTTON_VOL_UP
251 #define SOKOBAN_PAUSE BUTTON_SELECT
252 #define BUTTON_SAVE BUTTON_SELECT
253 #define BUTTON_SAVE_NAME "SELECT"
255 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
256 #define SOKOBAN_LEFT BUTTON_LEFT
257 #define SOKOBAN_RIGHT BUTTON_RIGHT
258 #define SOKOBAN_UP BUTTON_UP
259 #define SOKOBAN_DOWN BUTTON_DOWN
260 #define SOKOBAN_MENU BUTTON_POWER
261 #define SOKOBAN_UNDO_PRE BUTTON_SELECT
262 #define SOKOBAN_UNDO (BUTTON_SELECT | BUTTON_REL)
263 #define SOKOBAN_REDO BUTTON_HOME
264 #define SOKOBAN_LEVEL_DOWN BUTTON_VOL_DOWN
265 #define SOKOBAN_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_RIGHT)
266 #define SOKOBAN_LEVEL_UP BUTTON_VOL_UP
267 #define SOKOBAN_PAUSE BUTTON_SELECT
268 #define BUTTON_SAVE BUTTON_SELECT
269 #define BUTTON_SAVE_NAME "SELECT"
271 #elif CONFIG_KEYPAD == SANSA_M200_PAD
272 #define SOKOBAN_LEFT BUTTON_LEFT
273 #define SOKOBAN_RIGHT BUTTON_RIGHT
274 #define SOKOBAN_UP BUTTON_UP
275 #define SOKOBAN_DOWN BUTTON_DOWN
276 #define SOKOBAN_MENU BUTTON_POWER
277 #define SOKOBAN_UNDO_PRE BUTTON_SELECT
278 #define SOKOBAN_UNDO (BUTTON_SELECT | BUTTON_REL)
279 #define SOKOBAN_REDO (BUTTON_SELECT | BUTTON_UP)
280 #define SOKOBAN_LEVEL_DOWN BUTTON_VOL_DOWN
281 #define SOKOBAN_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_RIGHT)
282 #define SOKOBAN_LEVEL_UP BUTTON_VOL_UP
283 #define SOKOBAN_PAUSE BUTTON_SELECT
284 #define BUTTON_SAVE BUTTON_SELECT
285 #define BUTTON_SAVE_NAME "SELECT"
287 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
288 #define SOKOBAN_LEFT BUTTON_LEFT
289 #define SOKOBAN_RIGHT BUTTON_RIGHT
290 #define SOKOBAN_UP BUTTON_UP
291 #define SOKOBAN_DOWN BUTTON_DOWN
292 #define SOKOBAN_MENU BUTTON_MENU
293 #define SOKOBAN_UNDO BUTTON_VOL_UP
294 #define SOKOBAN_REDO BUTTON_VOL_DOWN
295 #define SOKOBAN_LEVEL_DOWN BUTTON_PREV
296 #define SOKOBAN_LEVEL_REPEAT BUTTON_PLAY
297 #define SOKOBAN_LEVEL_UP BUTTON_NEXT
298 #define SOKOBAN_PAUSE BUTTON_SELECT
299 #define BUTTON_SAVE BUTTON_SELECT
300 #define BUTTON_SAVE_NAME "SELECT"
302 #elif CONFIG_KEYPAD == MROBE100_PAD
303 #define SOKOBAN_LEFT BUTTON_LEFT
304 #define SOKOBAN_RIGHT BUTTON_RIGHT
305 #define SOKOBAN_UP BUTTON_UP
306 #define SOKOBAN_DOWN BUTTON_DOWN
307 #define SOKOBAN_MENU BUTTON_POWER
308 #define SOKOBAN_UNDO BUTTON_SELECT
309 #define SOKOBAN_REDO BUTTON_MENU
310 #define SOKOBAN_LEVEL_DOWN (BUTTON_DISPLAY | BUTTON_DOWN)
311 #define SOKOBAN_LEVEL_REPEAT (BUTTON_DISPLAY | BUTTON_RIGHT)
312 #define SOKOBAN_LEVEL_UP (BUTTON_DISPLAY | BUTTON_UP)
313 #define SOKOBAN_PAUSE BUTTON_SELECT
314 #define BUTTON_SAVE BUTTON_SELECT
315 #define BUTTON_SAVE_NAME "SELECT"
317 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
318 #define SOKOBAN_LEFT BUTTON_RC_REW
319 #define SOKOBAN_RIGHT BUTTON_RC_FF
320 #define SOKOBAN_UP BUTTON_RC_VOL_UP
321 #define SOKOBAN_DOWN BUTTON_RC_VOL_DOWN
322 #define SOKOBAN_MENU BUTTON_RC_REC
323 #define SOKOBAN_UNDO BUTTON_RC_MODE
324 #define SOKOBAN_REDO BUTTON_RC_MENU
325 #define SOKOBAN_PAUSE BUTTON_RC_PLAY
326 #define BUTTON_SAVE BUTTON_RC_PLAY
327 #define BUTTON_SAVE_NAME "PLAY"
329 #define SOKOBAN_RC_MENU BUTTON_REC
331 #elif CONFIG_KEYPAD == COWON_D2_PAD
332 #define SOKOBAN_MENU BUTTON_MENU
333 #define SOKOBAN_LEVEL_DOWN BUTTON_MINUS
334 #define SOKOBAN_LEVEL_UP BUTTON_PLUS
335 #define SOKOBAN_MENU_NAME "[MENU]"
337 #elif CONFIG_KEYPAD == IAUDIO67_PAD
338 #define SOKOBAN_LEFT BUTTON_LEFT
339 #define SOKOBAN_RIGHT BUTTON_RIGHT
340 #define SOKOBAN_UP BUTTON_STOP
341 #define SOKOBAN_DOWN BUTTON_PLAY
342 #define SOKOBAN_MENU BUTTON_MENU
343 #define SOKOBAN_UNDO BUTTON_VOLDOWN
344 #define SOKOBAN_REDO BUTTON_VOLUP
345 #define SOKOBAN_PAUSE (BUTTON_MENU|BUTTON_LEFT)
346 #define BUTTON_SAVE (BUTTON_MENU|BUTTON_PLAY)
347 #define BUTTON_SAVE_NAME "MENU+PLAY"
349 #define SOKOBAN_RC_MENU (BUTTON_MENU|BUTTON_STOP)
351 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
352 #define SOKOBAN_LEFT BUTTON_LEFT
353 #define SOKOBAN_RIGHT BUTTON_RIGHT
354 #define SOKOBAN_UP BUTTON_UP
355 #define SOKOBAN_DOWN BUTTON_DOWN
356 #define SOKOBAN_MENU BUTTON_MENU
357 #define SOKOBAN_UNDO BUTTON_BACK
358 #define SOKOBAN_REDO (BUTTON_BACK | BUTTON_PLAY)
359 #define SOKOBAN_LEVEL_DOWN (BUTTON_SELECT | BUTTON_DOWN)
360 #define SOKOBAN_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_RIGHT)
361 #define SOKOBAN_LEVEL_UP (BUTTON_SELECT | BUTTON_UP)
362 #define SOKOBAN_PAUSE BUTTON_PLAY
363 #define BUTTON_SAVE BUTTON_CUSTOM
364 #define BUTTON_SAVE_NAME "CUSTOM"
366 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
367 #define SOKOBAN_LEFT BUTTON_LEFT
368 #define SOKOBAN_RIGHT BUTTON_RIGHT
369 #define SOKOBAN_UP BUTTON_UP
370 #define SOKOBAN_DOWN BUTTON_DOWN
371 #define SOKOBAN_MENU BUTTON_MENU
372 #define SOKOBAN_UNDO BUTTON_VIEW
373 #define SOKOBAN_REDO (BUTTON_SELECT | BUTTON_VIEW)
374 #define SOKOBAN_LEVEL_DOWN BUTTON_VOL_DOWN
375 #define SOKOBAN_LEVEL_REPEAT BUTTON_POWER
376 #define SOKOBAN_LEVEL_UP BUTTON_VOL_UP
377 #define SOKOBAN_PAUSE BUTTON_SELECT
378 #define BUTTON_SAVE BUTTON_PLAYLIST
379 #define BUTTON_SAVE_NAME "PLAYLIST"
381 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
382 #define SOKOBAN_LEFT BUTTON_PREV
383 #define SOKOBAN_RIGHT BUTTON_NEXT
384 #define SOKOBAN_UP BUTTON_UP
385 #define SOKOBAN_DOWN BUTTON_DOWN
386 #define SOKOBAN_MENU BUTTON_MENU
387 #define SOKOBAN_UNDO BUTTON_LEFT
388 #define SOKOBAN_REDO (BUTTON_LEFT | BUTTON_PLAY)
389 #define SOKOBAN_LEVEL_DOWN BUTTON_VOL_DOWN
390 #define SOKOBAN_LEVEL_REPEAT BUTTON_POWER
391 #define SOKOBAN_LEVEL_UP BUTTON_VOL_UP
392 #define SOKOBAN_PAUSE BUTTON_PLAY
393 #define BUTTON_SAVE BUTTON_RIGHT
394 #define BUTTON_SAVE_NAME "RIGHT"
396 #elif CONFIG_KEYPAD == ONDAVX747_PAD
397 #define SOKOBAN_MENU BUTTON_MENU
398 #define SOKOBAN_MENU_NAME "[MENU]"
400 #elif CONFIG_KEYPAD == ONDAVX777_PAD
401 #define SOKOBAN_MENU BUTTON_POWER
402 #define SOKOBAN_MENU_NAME "[POWER]"
404 #elif CONFIG_KEYPAD == MROBE500_PAD
406 #define SOKOBAN_MENU BUTTON_POWER
407 #define SOKOBAN_MENU_NAME "[POWER]"
409 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
410 #define SOKOBAN_LEFT BUTTON_LEFT
411 #define SOKOBAN_RIGHT BUTTON_RIGHT
412 #define SOKOBAN_UP BUTTON_UP
413 #define SOKOBAN_DOWN BUTTON_DOWN
414 #define SOKOBAN_MENU BUTTON_REC
415 #define SOKOBAN_UNDO_PRE BUTTON_REW
416 #define SOKOBAN_UNDO (BUTTON_REW | BUTTON_LEFT)
417 #define SOKOBAN_REDO BUTTON_FFWD
418 #define SOKOBAN_LEVEL_DOWN (BUTTON_PLAY | BUTTON_DOWN)
419 #define SOKOBAN_LEVEL_REPEAT (BUTTON_PLAY | BUTTON_RIGHT)
420 #define SOKOBAN_LEVEL_UP (BUTTON_PLAY | BUTTON_UP)
421 #define SOKOBAN_PAUSE BUTTON_PLAY
422 #define BUTTON_SAVE BUTTON_PLAY
423 #define BUTTON_SAVE_NAME "PLAY"
425 #else
426 #error No keymap defined!
427 #endif
429 #ifdef HAVE_TOUCHSCREEN
430 #ifndef SOKOBAN_LEFT
431 #define SOKOBAN_LEFT BUTTON_MIDLEFT
432 #endif
433 #ifndef SOKOBAN_RIGHT
434 #define SOKOBAN_RIGHT BUTTON_MIDRIGHT
435 #endif
436 #ifndef SOKOBAN_UP
437 #define SOKOBAN_UP BUTTON_TOPMIDDLE
438 #endif
439 #ifndef SOKOBAN_DOWN
440 #define SOKOBAN_DOWN BUTTON_BOTTOMMIDDLE
441 #endif
442 #ifndef SOKOBAN_MENU
443 #define SOKOBAN_MENU BUTTON_TOPLEFT
444 #define SOKOBAN_MENU_NAME "[TOPLEFT]"
445 #endif
446 #ifndef SOKOBAN_UNDO
447 #define SOKOBAN_UNDO BUTTON_BOTTOMRIGHT
448 #define SOKOBAN_UNDO_NAME "[BOTTOMRIGHT]"
449 #endif
450 #ifndef SOKOBAN_REDO
451 #define SOKOBAN_REDO BUTTON_BOTTOMLEFT
452 #define SOKOBAN_REDO_NAME "[BOTTOMLEFT]"
453 #endif
454 #ifndef SOKOBAN_PAUSE
455 #define SOKOBAN_PAUSE BUTTON_CENTER
456 #define SOKOBAN_PAUSE_NAME "[CENTER]"
457 #endif
458 #ifndef SOKOBAN_LEVEL_REPEAT
459 #define SOKOBAN_LEVEL_REPEAT BUTTON_TOPRIGHT
460 #define SOKOBAN_LEVEL_REPEAT_NAME "[TOPRIGHT]"
461 #endif
462 #ifndef BUTTON_SAVE
463 #define BUTTON_SAVE BUTTON_CENTER
464 #define BUTTON_SAVE_NAME "CENTER"
465 #endif
466 #endif
468 #define SOKOBAN_FONT FONT_SYSFIXED
471 /* The Location, Undo and LevelInfo structs are OO-flavored.
472 * (oooh!-flavored as Schnueff puts it.) It makes more you have to know,
473 * but the overall data layout becomes more manageable. */
475 /* Level data & stats */
476 struct LevelInfo {
477 int index; /* Level index (level number - 1) */
478 int moves; /* Moves & pushes for the stats */
479 int pushes;
480 short boxes_to_go; /* Number of unplaced boxes remaining in level */
481 short height; /* Height & width for centering level display */
482 short width;
485 struct Location {
486 short row;
487 short col;
490 /* Our full undo history */
491 static struct UndoInfo {
492 int count; /* How many undos have been done */
493 int current; /* Which history is the current undo */
494 int max; /* Which history is the max redoable */
495 char history[MAX_UNDOS];
496 } undo_info;
498 /* Our playing board */
499 static struct BoardInfo {
500 char board[ROWS][COLS]; /* The current board data */
501 struct LevelInfo level; /* Level data & stats */
502 struct Location player; /* Where the player is */
503 int max_level; /* The number of levels we have */
504 } current_info;
506 static struct BufferedBoards {
507 char filename[MAX_PATH]; /* Filename of the levelset we're using */
508 char data[MAX_LEVEL_DATA]; /* Buffered level data */
509 int index[MAX_LEVELS + 1]; /* Where each buffered board begins & ends */
510 int start; /* Index of first buffered board */
511 int end; /* Index of last buffered board */
512 short prebuffered_boards; /* Number of boards before current to store */
513 } buffered_boards;
516 static char buf[ROWS*(COLS + 1)]; /* Enough for a whole board or a filename */
519 static void init_undo(void)
521 undo_info.count = 0;
522 undo_info.current = 0;
523 undo_info.max = 0;
526 static void get_delta(char direction, short *d_r, short *d_c)
528 switch (direction) {
529 case SOKOBAN_PUSH_LEFT:
530 case SOKOBAN_MOVE_LEFT:
531 *d_r = 0;
532 *d_c = -1;
533 break;
534 case SOKOBAN_PUSH_RIGHT:
535 case SOKOBAN_MOVE_RIGHT:
536 *d_r = 0;
537 *d_c = 1;
538 break;
539 case SOKOBAN_PUSH_UP:
540 case SOKOBAN_MOVE_UP:
541 *d_r = -1;
542 *d_c = 0;
543 break;
544 case SOKOBAN_PUSH_DOWN:
545 case SOKOBAN_MOVE_DOWN:
546 *d_r = 1;
547 *d_c = 0;
551 static bool undo(void)
553 char undo;
554 short r, c;
555 short d_r = 0, d_c = 0; /* delta row & delta col */
556 char *space_cur, *space_next, *space_prev;
557 bool undo_push = false;
559 /* If no more undos or we've wrapped all the way around, quit */
560 if (undo_info.count == 0 || undo_info.current - 1 == undo_info.max)
561 return false;
563 /* Move to previous undo in the list */
564 if (undo_info.current == 0 && undo_info.count > 1)
565 undo_info.current = MAX_UNDOS - 1;
566 else
567 undo_info.current--;
569 undo_info.count--;
571 undo = undo_info.history[undo_info.current];
573 if (undo < SOKOBAN_MOVE_MIN)
574 undo_push = true;
576 get_delta(undo, &d_r, &d_c);
578 r = current_info.player.row;
579 c = current_info.player.col;
581 /* Give the 3 spaces we're going to use better names */
582 space_cur = &current_info.board[r][c];
583 space_next = &current_info.board[r + d_r][c + d_c];
584 space_prev = &current_info.board[r - d_r][c - d_c];
586 /* Update board info */
587 if (undo_push) {
588 /* Moving box from goal to floor */
589 if (*space_next == '*' && *space_cur == '@')
590 current_info.level.boxes_to_go++;
591 /* Moving box from floor to goal */
592 else if (*space_next == '$' && *space_cur == '+')
593 current_info.level.boxes_to_go--;
595 /* Move box off of next space... */
596 *space_next = (*space_next == '*' ? '.' : ' ');
597 /* ...and on to current space */
598 *space_cur = (*space_cur == '+' ? '*' : '$');
600 current_info.level.pushes--;
601 } else
602 /* Just move player off of current space */
603 *space_cur = (*space_cur == '+' ? '.' : ' ');
604 /* Move player back to previous space */
605 *space_prev = (*space_prev == '.' ? '+' : '@');
607 /* Update position */
608 current_info.player.row -= d_r;
609 current_info.player.col -= d_c;
611 current_info.level.moves--;
613 return true;
616 static void add_undo(char undo)
618 undo_info.history[undo_info.current] = undo;
620 /* Wrap around if MAX_UNDOS exceeded */
621 if (undo_info.current < (MAX_UNDOS - 1))
622 undo_info.current++;
623 else
624 undo_info.current = 0;
626 if (undo_info.count < MAX_UNDOS)
627 undo_info.count++;
630 static bool move(char direction, bool redo)
632 short r, c;
633 short d_r = 0, d_c = 0; /* delta row & delta col */
634 char *space_cur, *space_next, *space_beyond;
635 bool push = false;
637 get_delta(direction, &d_r, &d_c);
639 r = current_info.player.row;
640 c = current_info.player.col;
642 /* Check for out-of-bounds */
643 if (r + 2*d_r < 0 || r + 2*d_r >= ROWS ||
644 c + 2*d_c < 0 || c + 2*d_c >= COLS)
645 return false;
647 /* Give the 3 spaces we're going to use better names */
648 space_cur = &current_info.board[r][c];
649 space_next = &current_info.board[r + d_r][c + d_c];
650 space_beyond = &current_info.board[r + 2*d_r][c + 2*d_c];
652 if (*space_next == '$' || *space_next == '*') {
653 /* Change direction from move to push for undo */
654 if (direction >= SOKOBAN_MOVE_MIN)
655 direction -= SOKOBAN_MOVE_DIFF;
656 push = true;
658 else if (direction < SOKOBAN_MOVE_MIN)
659 /* Change back to move if redo/solution playback push is invalid */
660 direction += SOKOBAN_MOVE_DIFF;
662 /* Update board info */
663 if (push) {
664 /* Moving box from goal to floor */
665 if (*space_next == '*' && *space_beyond == ' ')
666 current_info.level.boxes_to_go++;
667 /* Moving box from floor to goal */
668 else if (*space_next == '$' && *space_beyond == '.')
669 current_info.level.boxes_to_go--;
670 /* Check for invalid move */
671 else if (*space_beyond != '.' && *space_beyond != ' ')
672 return false;
674 /* Move player onto next space */
675 *space_next = (*space_next == '*' ? '+' : '@');
676 /* Move box onto space beyond next */
677 *space_beyond = (*space_beyond == '.' ? '*' : '$');
679 current_info.level.pushes++;
680 } else {
681 /* Check for invalid move */
682 if (*space_next != '.' && *space_next != ' ')
683 return false;
685 /* Move player onto next space */
686 *space_next = (*space_next == '.' ? '+' : '@');
688 /* Move player off of current space */
689 *space_cur = (*space_cur == '+' ? '.' : ' ');
691 /* Update position */
692 current_info.player.row += d_r;
693 current_info.player.col += d_c;
695 current_info.level.moves++;
697 /* Update undo_info.max to current on every normal move,
698 * except if it's the same as a redo. */
699 /* normal move and either */
700 if (!redo &&
701 /* moves have been undone... */
702 ((undo_info.max != undo_info.current &&
703 /* ...and the current move is NOT the same as the one in history */
704 undo_info.history[undo_info.current] != direction) ||
705 /* or moves have not been undone */
706 undo_info.max == undo_info.current)) {
707 add_undo(direction);
708 undo_info.max = undo_info.current;
709 } else /* redo move or move was same as redo */
710 add_undo(direction); /* add_undo to update current */
712 return true;
715 #ifdef SOKOBAN_REDO
716 static bool redo(void)
718 /* If no moves have been undone, quit */
719 if (undo_info.current == undo_info.max)
720 return false;
722 return move(undo_info.history[(undo_info.current < MAX_UNDOS ?
723 undo_info.current : 0)], true);
725 #endif
727 static void init_boards(void)
729 rb->strlcpy(buffered_boards.filename, SOKOBAN_LEVELS_FILE,
730 sizeof(buffered_boards.filename));
732 current_info.level.index = 0;
733 current_info.player.row = 0;
734 current_info.player.col = 0;
735 current_info.max_level = 0;
737 buffered_boards.start = 0;
738 buffered_boards.end = 0;
739 buffered_boards.prebuffered_boards = 0;
741 init_undo();
744 static bool read_levels(bool initialize)
746 int fd = 0;
747 short len;
748 short lastlen = 0;
749 short row = 0;
750 int level_count = 0;
752 int i = 0;
753 int level_len = 0;
754 bool index_set = false;
756 /* Get the index of the first level to buffer */
757 if (current_info.level.index > buffered_boards.prebuffered_boards &&
758 !initialize)
759 buffered_boards.start = current_info.level.index -
760 buffered_boards.prebuffered_boards;
761 else
762 buffered_boards.start = 0;
764 if ((fd = rb->open(buffered_boards.filename, O_RDONLY)) < 0) {
765 rb->splashf(HZ*2, "Unable to open %s", buffered_boards.filename);
766 return false;
769 do {
770 len = rb->read_line(fd, buf, sizeof(buf));
772 /* Correct len when trailing \r's or \n's are counted */
773 if (len > 2 && buf[len - 2] == '\0')
774 len -= 2;
775 else if (len > 1 && buf[len - 1] == '\0')
776 len--;
778 /* Skip short lines & lines with non-level data */
779 if (len >= 3 && ((buf[0] >= '1' && buf[0] <= '9') || buf[0] == '#' ||
780 buf[0] == ' ' || buf[0] == '-' || buf[0] == '_')) {
781 if (level_count >= buffered_boards.start) {
782 /* Set the index of this level */
783 if (!index_set &&
784 level_count - buffered_boards.start < MAX_LEVELS) {
785 buffered_boards.index[level_count - buffered_boards.start]
786 = i;
787 index_set = true;
789 /* Copy buffer to board data */
790 if (i + level_len + len < MAX_LEVEL_DATA) {
791 rb->memcpy(&buffered_boards.data[i + level_len], buf, len);
792 buffered_boards.data[i + level_len + len] = '\n';
795 level_len += len + 1;
796 row++;
798 /* If newline & level is tall enough or is RLE */
799 } else if (buf[0] == '\0' && (row > 2 || lastlen > 22)) {
800 level_count++;
801 if (level_count >= buffered_boards.start) {
802 i += level_len;
803 if (i < MAX_LEVEL_DATA)
804 buffered_boards.end = level_count;
805 else if (!initialize)
806 break;
808 row = 0;
809 level_len = 0;
810 index_set = false;
812 } else if (len > 22)
813 len = 1;
815 } while ((lastlen = len));
817 /* Set the index of the end of the last level */
818 if (level_count - buffered_boards.start < MAX_LEVELS)
819 buffered_boards.index[level_count - buffered_boards.start] = i;
821 if (initialize) {
822 current_info.max_level = level_count;
823 buffered_boards.prebuffered_boards = buffered_boards.end/2;
826 rb->close(fd);
828 return true;
831 static void load_level(void)
833 int c, r;
834 int i, n;
835 int level_size;
836 int index = current_info.level.index - buffered_boards.start;
837 char *level;
839 /* Get the buffered board index of the current level */
840 if (current_info.level.index < buffered_boards.start ||
841 current_info.level.index >= buffered_boards.end) {
842 read_levels(false);
843 if (current_info.level.index > buffered_boards.prebuffered_boards)
844 index = buffered_boards.prebuffered_boards;
845 else
846 index = current_info.level.index;
848 level = &buffered_boards.data[buffered_boards.index[index]];
850 /* Reset level info */
851 current_info.level.moves = 0;
852 current_info.level.pushes = 0;
853 current_info.level.boxes_to_go = 0;
854 current_info.level.width = 0;
856 /* Clear board */
857 for (r = 0; r < ROWS; r++)
858 for (c = 0; c < COLS; c++)
859 current_info.board[r][c] = 'X';
861 level_size = buffered_boards.index[index + 1] -
862 buffered_boards.index[index];
864 for (r = 0, c = 0, n = 1, i = 0; i < level_size; i++) {
865 if (level[i] == '\n' || level[i] == '|') {
866 if (c > 3) {
867 /* Update max width of level & go to next row */
868 if (c > current_info.level.width)
869 current_info.level.width = c;
870 c = 0;
871 r++;
872 if (r >= ROWS)
873 break;
875 } else if (c < COLS) {
876 /* Read RLE character's length into n */
877 if (level[i] >= '0' && level[i] <= '9') {
878 n = level[i++] - '0';
879 if (level[i] >= '0' && level[i] <= '9')
880 n = n*10 + level[i++] - '0';
883 /* Cleanup & replace */
884 if (level[i] == '%')
885 level[i] = '*';
886 else if (level[i] == '-' || level[i] == '_')
887 level[i] = ' ';
889 if (n > 1) {
890 if (c + n >= COLS)
891 n = COLS - c;
893 if (level[i] == '.')
894 current_info.level.boxes_to_go += n;
896 /* Put RLE character n times */
897 while (n--)
898 current_info.board[r][c++] = level[i];
899 n = 1;
901 } else {
902 if (level[i] == '.' || level[i] == '+')
903 current_info.level.boxes_to_go++;
905 if (level[i] == '@' ||level[i] == '+') {
906 current_info.player.row = r;
907 current_info.player.col = c;
910 current_info.board[r][c++] = level[i];
915 current_info.level.height = r;
917 #if LCD_DEPTH > 2
918 /* Fill in blank space outside level on color targets */
919 for (r = 0; r < ROWS; r++)
920 for (c = 0; current_info.board[r][c] == ' ' && c < COLS; c++)
921 current_info.board[r][c] = 'X';
923 for (c = 0; c < COLS; c++) {
924 for (r = 0; (current_info.board[r][c] == ' ' ||
925 current_info.board[r][c] == 'X') && r < ROWS; r++)
926 current_info.board[r][c] = 'X';
927 for (r = ROWS - 1; (current_info.board[r][c] == ' ' ||
928 current_info.board[r][c] == 'X') && r >= 0; r--)
929 current_info.board[r][c] = 'X';
931 #endif
934 static void update_screen(void)
936 int c, r;
937 int rows, cols;
939 #if LCD_WIDTH - (COLS*SOKOBAN_TILESIZE) < 32
940 #define STAT_HEIGHT 25
941 #define STAT_X (LCD_WIDTH - 120)/2
942 #define STAT_Y (LCD_HEIGHT - STAT_HEIGHT)
943 #define BOARD_WIDTH LCD_WIDTH
944 #define BOARD_HEIGHT (LCD_HEIGHT - STAT_HEIGHT)
945 rb->lcd_putsxy(STAT_X + 4, STAT_Y + 4, "Level");
946 rb->snprintf(buf, sizeof(buf), "%d", current_info.level.index + 1);
947 rb->lcd_putsxy(STAT_X + 7, STAT_Y + 14, buf);
948 rb->lcd_putsxy(STAT_X + 41, STAT_Y + 4, "Moves");
949 rb->snprintf(buf, sizeof(buf), "%d", current_info.level.moves);
950 rb->lcd_putsxy(STAT_X + 44, STAT_Y + 14, buf);
951 rb->lcd_putsxy(STAT_X + 79, STAT_Y + 4, "Pushes");
952 rb->snprintf(buf, sizeof(buf), "%d", current_info.level.pushes);
953 rb->lcd_putsxy(STAT_X + 82, STAT_Y + 14, buf);
955 rb->lcd_drawrect(STAT_X, STAT_Y, 38, STAT_HEIGHT);
956 rb->lcd_drawrect(STAT_X + 37, STAT_Y, 39, STAT_HEIGHT);
957 rb->lcd_drawrect(STAT_X + 75, STAT_Y, 45, STAT_HEIGHT);
958 #else
959 #if LCD_WIDTH - (COLS*SOKOBAN_TILESIZE) > 40
960 #define STAT_X (LCD_WIDTH - 40)
961 #else
962 #define STAT_X COLS*SOKOBAN_TILESIZE
963 #endif
964 #define STAT_Y (LCD_HEIGHT - 64)/2
965 #define STAT_WIDTH (LCD_WIDTH - STAT_X)
966 #define BOARD_WIDTH (LCD_WIDTH - STAT_WIDTH)
967 #define BOARD_HEIGHT LCD_HEIGHT
968 rb->lcd_putsxy(STAT_X + 1, STAT_Y + 2, "Level");
969 rb->snprintf(buf, sizeof(buf), "%d", current_info.level.index + 1);
970 rb->lcd_putsxy(STAT_X + 4, STAT_Y + 12, buf);
971 rb->lcd_putsxy(STAT_X + 1, STAT_Y + 23, "Moves");
972 rb->snprintf(buf, sizeof(buf), "%d", current_info.level.moves);
973 rb->lcd_putsxy(STAT_X + 4, STAT_Y + 33, buf);
974 #if STAT_WIDTH < 38
975 rb->lcd_putsxy(STAT_X + 1, STAT_Y + 44, "Push");
976 #else
977 rb->lcd_putsxy(STAT_X + 1, STAT_Y + 44, "Pushes");
978 #endif
979 rb->snprintf(buf, sizeof(buf), "%d", current_info.level.pushes);
980 rb->lcd_putsxy(STAT_X + 4, STAT_Y + 54, buf);
982 rb->lcd_drawrect(STAT_X, STAT_Y + 0, STAT_WIDTH, 64);
983 rb->lcd_hline(STAT_X, LCD_WIDTH - 1, STAT_Y + 21);
984 rb->lcd_hline(STAT_X, LCD_WIDTH - 1, STAT_Y + 42);
986 #endif
988 /* load the board to the screen */
989 for (rows = 0; rows < ROWS; rows++) {
990 for (cols = 0; cols < COLS; cols++) {
991 c = cols*SOKOBAN_TILESIZE +
992 (BOARD_WIDTH - current_info.level.width*SOKOBAN_TILESIZE)/2;
993 r = rows*SOKOBAN_TILESIZE +
994 (BOARD_HEIGHT - current_info.level.height*SOKOBAN_TILESIZE)/2;
996 switch(current_info.board[rows][cols]) {
997 case 'X': /* blank space outside of level */
998 break;
1000 case ' ': /* floor */
1001 rb->lcd_bitmap_part(sokoban_tiles, 0, 0*SOKOBAN_TILESIZE,
1002 STRIDE( SCREEN_MAIN,
1003 BMPWIDTH_sokoban_tiles,
1004 BMPHEIGHT_sokoban_tiles),
1005 c, r, SOKOBAN_TILESIZE, SOKOBAN_TILESIZE);
1006 break;
1008 case '#': /* wall */
1009 rb->lcd_bitmap_part(sokoban_tiles, 0, 1*SOKOBAN_TILESIZE,
1010 STRIDE( SCREEN_MAIN,
1011 BMPWIDTH_sokoban_tiles,
1012 BMPHEIGHT_sokoban_tiles),
1013 c, r, SOKOBAN_TILESIZE, SOKOBAN_TILESIZE);
1014 break;
1016 case '$': /* box */
1017 rb->lcd_bitmap_part(sokoban_tiles, 0, 2*SOKOBAN_TILESIZE,
1018 STRIDE( SCREEN_MAIN,
1019 BMPWIDTH_sokoban_tiles,
1020 BMPHEIGHT_sokoban_tiles),
1021 c, r, SOKOBAN_TILESIZE,SOKOBAN_TILESIZE);
1022 break;
1024 case '*': /* box on goal */
1025 rb->lcd_bitmap_part(sokoban_tiles, 0, 3*SOKOBAN_TILESIZE,
1026 STRIDE( SCREEN_MAIN,
1027 BMPWIDTH_sokoban_tiles,
1028 BMPHEIGHT_sokoban_tiles),
1029 c, r, SOKOBAN_TILESIZE, SOKOBAN_TILESIZE);
1030 break;
1032 case '.': /* goal */
1033 rb->lcd_bitmap_part(sokoban_tiles, 0, 4*SOKOBAN_TILESIZE,
1034 STRIDE( SCREEN_MAIN,
1035 BMPWIDTH_sokoban_tiles,
1036 BMPHEIGHT_sokoban_tiles),
1037 c, r, SOKOBAN_TILESIZE, SOKOBAN_TILESIZE);
1038 break;
1040 case '@': /* player */
1041 rb->lcd_bitmap_part(sokoban_tiles, 0, 5*SOKOBAN_TILESIZE,
1042 STRIDE( SCREEN_MAIN,
1043 BMPWIDTH_sokoban_tiles,
1044 BMPHEIGHT_sokoban_tiles),
1045 c, r, SOKOBAN_TILESIZE, SOKOBAN_TILESIZE);
1046 break;
1048 case '+': /* player on goal */
1049 rb->lcd_bitmap_part(sokoban_tiles, 0, 6*SOKOBAN_TILESIZE,
1050 STRIDE( SCREEN_MAIN,
1051 BMPWIDTH_sokoban_tiles,
1052 BMPHEIGHT_sokoban_tiles),
1053 c, r, SOKOBAN_TILESIZE, SOKOBAN_TILESIZE);
1054 break;
1059 /* print out the screen */
1060 rb->lcd_update();
1063 static void draw_level(void)
1065 load_level();
1066 rb->lcd_clear_display();
1067 update_screen();
1070 static bool save(char *filename, bool solution)
1072 int fd;
1073 char *loc;
1074 DIR *dir;
1075 char dirname[MAX_PATH];
1077 rb->splash(0, "Saving...");
1079 /* Create dir if it doesn't exist */
1080 if ((loc = rb->strrchr(filename, '/')) != NULL) {
1081 rb->strlcpy(dirname, filename, loc - filename + 1);
1083 if(!(dir = rb->opendir(dirname)))
1084 rb->mkdir(dirname);
1085 else
1086 rb->closedir(dir);
1089 if (filename[0] == '\0' ||
1090 (fd = rb->open(filename, O_WRONLY|O_CREAT|O_TRUNC)) < 0) {
1091 rb->splashf(HZ*2, "Unable to open %s", filename);
1092 return false;
1095 /* Sokoban: S/P for solution/progress : level number : current undo */
1096 rb->snprintf(buf, sizeof(buf), "Sokoban:%c:%d:%d\n", (solution ? 'S' : 'P'),
1097 current_info.level.index + 1, undo_info.current);
1098 rb->write(fd, buf, rb->strlen(buf));
1100 /* Filename of levelset */
1101 rb->write(fd, buffered_boards.filename,
1102 rb->strlen(buffered_boards.filename));
1103 rb->write(fd, "\n", 1);
1105 /* Full undo history */
1106 rb->write(fd, undo_info.history, undo_info.max);
1108 rb->close(fd);
1110 return true;
1113 static bool load(char *filename, bool silent)
1115 int fd;
1116 int i, n;
1117 int len;
1118 int button;
1119 bool play_solution;
1120 bool paused = false;
1121 unsigned short speed = 2;
1122 int delay[] = {HZ/2, HZ/3, HZ/4, HZ/6, HZ/8, HZ/12, HZ/16, HZ/25};
1124 if (filename[0] == '\0' || (fd = rb->open(filename, O_RDONLY)) < 0) {
1125 if (!silent)
1126 rb->splashf(HZ*2, "Unable to open %s", filename);
1127 return false;
1130 /* Read header, level number, & current undo */
1131 rb->read_line(fd, buf, sizeof(buf));
1133 /* If we're opening a level file, not a solution/progress file */
1134 if (rb->strncmp(buf, "Sokoban", 7) != 0) {
1135 rb->close(fd);
1137 rb->strlcpy(buffered_boards.filename, filename,
1138 sizeof(buffered_boards.filename));
1140 if (!read_levels(true))
1141 return false;
1143 current_info.level.index = 0;
1144 load_level();
1146 /* If there aren't any boxes to go or the player position wasn't set,
1147 * the file probably wasn't a Sokoban level file */
1148 if (current_info.level.boxes_to_go == 0 ||
1149 current_info.player.row == 0 || current_info.player.col == 0) {
1150 if (!silent)
1151 rb->splash(HZ*2, "File is not a Sokoban level file");
1152 return false;
1155 } else {
1157 /* Read filename of levelset */
1158 rb->read_line(fd, buffered_boards.filename,
1159 sizeof(buffered_boards.filename));
1161 /* Read full undo history */
1162 len = rb->read_line(fd, undo_info.history, MAX_UNDOS);
1164 /* Correct len when trailing \r's or \n's are counted */
1165 if (len > 2 && undo_info.history[len - 2] == '\0')
1166 len -= 2;
1167 else if (len > 1 && undo_info.history[len - 1] == '\0')
1168 len--;
1170 rb->close(fd);
1172 /* Check to see if we're going to play a solution or resume progress */
1173 play_solution = (buf[8] == 'S');
1175 /* Get level number */
1176 for (n = 0, i = 10; buf[i] >= '0' && buf[i] <= '9' && i < 15; i++)
1177 n = n*10 + buf[i] - '0';
1178 current_info.level.index = n - 1;
1180 /* Get undo index */
1181 for (n = 0, i++; buf[i] >= '0' && buf[i] <= '9' && i < 21; i++)
1182 n = n*10 + buf[i] - '0';
1183 if (n > len)
1184 n = len;
1185 undo_info.max = len;
1187 if (current_info.level.index < 0) {
1188 if (!silent)
1189 rb->splash(HZ*2, "Error loading level");
1190 return false;
1192 if (!read_levels(true))
1193 return false;
1194 if (current_info.level.index >= current_info.max_level) {
1195 if (!silent)
1196 rb->splash(HZ*2, "Error loading level");
1197 return false;
1200 load_level();
1202 if (play_solution) {
1203 rb->lcd_clear_display();
1204 update_screen();
1205 rb->sleep(2*delay[speed]);
1207 /* Replay solution until menu button is pressed */
1208 i = 0;
1209 while (true) {
1210 if (i < len) {
1211 if (!move(undo_info.history[i], true)) {
1212 n = i;
1213 break;
1215 rb->lcd_clear_display();
1216 update_screen();
1217 i++;
1218 } else
1219 paused = true;
1221 rb->sleep(delay[speed]);
1223 while ((button = rb->button_get(false)) || paused) {
1224 switch (button) {
1225 case SOKOBAN_MENU:
1226 /* Pretend the level is complete so we'll quit */
1227 current_info.level.boxes_to_go = 0;
1228 return true;
1230 case SOKOBAN_PAUSE:
1231 /* Toggle pause state */
1232 paused = !paused;
1233 break;
1235 case SOKOBAN_LEFT:
1236 case SOKOBAN_LEFT | BUTTON_REPEAT:
1237 /* Go back one move */
1238 if (paused) {
1239 if (undo())
1240 i--;
1241 rb->lcd_clear_display();
1242 update_screen();
1244 break;
1246 case SOKOBAN_RIGHT:
1247 case SOKOBAN_RIGHT | BUTTON_REPEAT:
1248 /* Go forward one move */
1249 if (paused) {
1250 if (redo())
1251 i++;
1252 rb->lcd_clear_display();
1253 update_screen();
1255 break;
1257 case SOKOBAN_UP:
1258 case SOKOBAN_UP | BUTTON_REPEAT:
1259 /* Speed up */
1260 if (speed < sizeof(delay)/sizeof(int) - 1)
1261 speed++;
1262 break;
1264 case SOKOBAN_DOWN:
1265 case SOKOBAN_DOWN | BUTTON_REPEAT:
1266 /* Slow down */
1267 if (speed > 0)
1268 speed--;
1271 if (paused)
1272 rb->sleep(HZ/33);
1276 /* If level is complete, wait for keypress before quitting */
1277 if (current_info.level.boxes_to_go == 0)
1278 rb->button_get(true);
1280 } else {
1281 /* Advance to current undo */
1282 for (i = 0; i < n; i++) {
1283 if (!move(undo_info.history[i], true)) {
1284 n = i;
1285 break;
1289 rb->button_clear_queue();
1290 rb->lcd_clear_display();
1293 undo_info.current = n;
1296 return true;
1299 static int sokoban_menu(void)
1301 int button;
1302 int selection = 0;
1303 int i;
1304 bool menu_quit;
1305 int start_selected = 0;
1306 int prev_level = current_info.level.index;
1308 MENUITEM_STRINGLIST(menu, "Sokoban Menu", NULL,
1309 "Resume", "Select Level", "Audio Playback", "Keys",
1310 "Load Default Level Set", "Quit Without Saving",
1311 "Save Progress & Quit");
1313 do {
1314 menu_quit = true;
1315 selection = rb->do_menu(&menu, &start_selected, NULL, false);
1317 switch (selection) {
1318 case 0: /* Resume */
1319 break;
1321 case 1: /* Select level */
1322 current_info.level.index++;
1323 rb->set_int("Select Level", "", UNIT_INT,
1324 &current_info.level.index, NULL, 1, 1,
1325 current_info.max_level, NULL);
1326 current_info.level.index--;
1327 if (prev_level != current_info.level.index) {
1328 init_undo();
1329 draw_level();
1330 } else
1331 menu_quit = false;
1332 break;
1334 case 2: /* Audio playback control */
1335 playback_control(NULL);
1336 menu_quit = false;
1337 break;
1339 case 3: /* Keys */
1340 FOR_NB_SCREENS(i)
1341 rb->screens[i]->clear_display();
1342 rb->lcd_setfont(SOKOBAN_FONT);
1344 #if (CONFIG_KEYPAD == RECORDER_PAD) || \
1345 (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
1346 rb->lcd_putsxy(3, 6, "[OFF] Menu");
1347 rb->lcd_putsxy(3, 16, "[ON] Undo");
1348 rb->lcd_putsxy(3, 26, "[PLAY] Redo");
1349 rb->lcd_putsxy(3, 36, "[F1] Down a Level");
1350 rb->lcd_putsxy(3, 46, "[F2] Restart Level");
1351 rb->lcd_putsxy(3, 56, "[F3] Up a Level");
1352 #elif CONFIG_KEYPAD == ONDIO_PAD
1353 rb->lcd_putsxy(3, 6, "[OFF] Menu");
1354 rb->lcd_putsxy(3, 16, "[MODE] Undo");
1355 rb->lcd_putsxy(3, 26, "[MODE+DOWN] Redo");
1356 rb->lcd_putsxy(3, 36, "[MODE+LEFT] Previous Level");
1357 rb->lcd_putsxy(3, 46, "[MODE+UP] Restart Level");
1358 rb->lcd_putsxy(3, 56, "[MODE+RIGHT] Up Level");
1359 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
1360 (CONFIG_KEYPAD == IRIVER_H300_PAD)
1361 rb->lcd_putsxy(3, 6, "[STOP] Menu");
1362 rb->lcd_putsxy(3, 16, "[REC] Undo");
1363 rb->lcd_putsxy(3, 26, "[MODE] Redo");
1364 rb->lcd_putsxy(3, 36, "[PLAY+DOWN] Previous Level");
1365 rb->lcd_putsxy(3, 46, "[PLAY] Restart Level");
1366 rb->lcd_putsxy(3, 56, "[PLAY+UP] Next Level");
1367 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
1368 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1369 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
1370 rb->lcd_putsxy(3, 6, "[SELECT+MENU] Menu");
1371 rb->lcd_putsxy(3, 16, "[SELECT] Undo");
1372 rb->lcd_putsxy(3, 26, "[SELECT+PLAY] Redo");
1373 rb->lcd_putsxy(3, 36, "[SELECT+LEFT] Previous Level");
1374 rb->lcd_putsxy(3, 46, "[SELECT+RIGHT] Next Level");
1375 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1376 rb->lcd_putsxy(3, 6, "[POWER] Menu");
1377 rb->lcd_putsxy(3, 16, "[SELECT] Undo");
1378 rb->lcd_putsxy(3, 26, "[PLAY] Redo");
1379 rb->lcd_putsxy(3, 36, "[REC] Restart Level");
1380 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
1381 rb->lcd_putsxy(3, 6, "[POWER] Menu");
1382 rb->lcd_putsxy(3, 16, "[REW] Undo");
1383 rb->lcd_putsxy(3, 26, "[FF] Redo");
1384 rb->lcd_putsxy(3, 36, "[PLAY+DOWN] Previous Level");
1385 rb->lcd_putsxy(3, 46, "[PLAY+RIGHT] Restart Level");
1386 rb->lcd_putsxy(3, 56, "[PLAY+UP] Next Level");
1387 #elif CONFIG_KEYPAD == GIGABEAT_PAD
1388 rb->lcd_putsxy(3, 6, "[POWER] Menu");
1389 rb->lcd_putsxy(3, 16, "[SELECT] Undo");
1390 rb->lcd_putsxy(3, 26, "[A] Redo");
1391 rb->lcd_putsxy(3, 36, "[VOL-] Previous Level");
1392 rb->lcd_putsxy(3, 46, "[MENU] Restart Level");
1393 rb->lcd_putsxy(3, 56, "[VOL+] Next Level");
1394 #elif CONFIG_KEYPAD == SANSA_E200_PAD
1395 rb->lcd_putsxy(3, 6, "[POWER] Menu");
1396 rb->lcd_putsxy(3, 16, "[SELECT] Undo");
1397 rb->lcd_putsxy(3, 26, "[REC] Redo");
1398 rb->lcd_putsxy(3, 36, "[SELECT+DOWN] Previous Level");
1399 rb->lcd_putsxy(3, 46, "[SELECT+RIGHT] Restart Level");
1400 rb->lcd_putsxy(3, 56, "[SELECT+UP] Next Level");
1401 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
1402 rb->lcd_putsxy(3, 6, "[MENU] Menu");
1403 rb->lcd_putsxy(3, 16, "[VOL+] Undo");
1404 rb->lcd_putsxy(3, 26, "[VOL-] Redo");
1405 rb->lcd_putsxy(3, 36, "[PREV] Previous Level");
1406 rb->lcd_putsxy(3, 46, "[PLAY] Restart Level");
1407 rb->lcd_putsxy(3, 56, "[NEXT] Next Level");
1408 #endif
1410 #ifdef HAVE_TOUCHSCREEN
1411 rb->lcd_putsxy(3, 6, SOKOBAN_MENU_NAME " Menu");
1412 rb->lcd_putsxy(3, 16, SOKOBAN_UNDO_NAME " Undo");
1413 rb->lcd_putsxy(3, 26, SOKOBAN_REDO_NAME " Redo");
1414 rb->lcd_putsxy(3, 36, SOKOBAN_PAUSE_NAME " Pause");
1415 rb->lcd_putsxy(3, 46, SOKOBAN_LEVEL_REPEAT_NAME " Restart Level");
1416 #endif
1418 FOR_NB_SCREENS(i)
1419 rb->screens[i]->update();
1421 /* Display until keypress */
1422 do {
1423 rb->sleep(HZ/20);
1424 button = rb->button_get(false);
1425 } while (!button || button & BUTTON_REL ||
1426 button & BUTTON_REPEAT);
1428 menu_quit = false;
1429 break;
1431 case 4: /* Load default levelset */
1432 init_boards();
1433 if (!read_levels(true))
1434 return 5; /* Quit */
1435 load_level();
1436 break;
1438 case 5: /* Quit */
1439 break;
1441 case 6: /* Save & quit */
1442 save(SOKOBAN_SAVE_FILE, false);
1443 rb->reload_directory();
1446 } while (!menu_quit);
1448 /* Restore font */
1449 rb->lcd_setfont(SOKOBAN_FONT);
1451 FOR_NB_SCREENS(i) {
1452 rb->screens[i]->clear_display();
1453 rb->screens[i]->update();
1456 return selection;
1459 static bool sokoban_loop(void)
1461 bool moved;
1462 int i = 0, button = 0, lastbutton = 0;
1463 short r = 0, c = 0;
1464 int w, h;
1465 char *loc;
1467 while (true) {
1468 moved = false;
1470 r = current_info.player.row;
1471 c = current_info.player.col;
1473 button = rb->button_get(true);
1475 switch(button)
1477 #ifdef SOKOBAN_RC_MENU
1478 case SOKOBAN_RC_MENU:
1479 #endif
1480 case SOKOBAN_MENU:
1481 switch (sokoban_menu()) {
1482 case 5: /* Quit */
1483 case 6: /* Save & quit */
1484 return PLUGIN_OK;
1486 update_screen();
1487 break;
1489 case SOKOBAN_UNDO:
1490 #ifdef SOKOBAN_UNDO_PRE
1491 if (lastbutton != SOKOBAN_UNDO_PRE)
1492 break;
1493 #else /* repeat can't work here for Ondio, iPod, et al */
1494 case SOKOBAN_UNDO | BUTTON_REPEAT:
1495 #endif
1496 undo();
1497 rb->lcd_clear_display();
1498 update_screen();
1499 break;
1501 #ifdef SOKOBAN_REDO
1502 case SOKOBAN_REDO:
1503 case SOKOBAN_REDO | BUTTON_REPEAT:
1504 moved = redo();
1505 rb->lcd_clear_display();
1506 update_screen();
1507 break;
1508 #endif
1510 #ifdef SOKOBAN_LEVEL_UP
1511 case SOKOBAN_LEVEL_UP:
1512 case SOKOBAN_LEVEL_UP | BUTTON_REPEAT:
1513 /* next level */
1514 init_undo();
1515 if (current_info.level.index + 1 < current_info.max_level)
1516 current_info.level.index++;
1518 draw_level();
1519 break;
1520 #endif
1522 #ifdef SOKOBAN_LEVEL_DOWN
1523 case SOKOBAN_LEVEL_DOWN:
1524 case SOKOBAN_LEVEL_DOWN | BUTTON_REPEAT:
1525 /* previous level */
1526 init_undo();
1527 if (current_info.level.index > 0)
1528 current_info.level.index--;
1530 draw_level();
1531 break;
1532 #endif
1534 #ifdef SOKOBAN_LEVEL_REPEAT
1535 case SOKOBAN_LEVEL_REPEAT:
1536 case SOKOBAN_LEVEL_REPEAT | BUTTON_REPEAT:
1537 /* same level */
1538 init_undo();
1539 draw_level();
1540 break;
1541 #endif
1543 case SOKOBAN_LEFT:
1544 case SOKOBAN_LEFT | BUTTON_REPEAT:
1545 moved = move(SOKOBAN_MOVE_LEFT, false);
1546 break;
1548 case SOKOBAN_RIGHT:
1549 case SOKOBAN_RIGHT | BUTTON_REPEAT:
1550 moved = move(SOKOBAN_MOVE_RIGHT, false);
1551 break;
1553 case SOKOBAN_UP:
1554 case SOKOBAN_UP | BUTTON_REPEAT:
1555 moved = move(SOKOBAN_MOVE_UP, false);
1556 break;
1558 case SOKOBAN_DOWN:
1559 case SOKOBAN_DOWN | BUTTON_REPEAT:
1560 moved = move(SOKOBAN_MOVE_DOWN, false);
1561 break;
1563 default:
1564 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
1565 return PLUGIN_USB_CONNECTED;
1566 break;
1569 lastbutton = button;
1571 if (moved) {
1572 rb->lcd_clear_display();
1573 update_screen();
1576 /* We have completed this level */
1577 if (current_info.level.boxes_to_go == 0) {
1579 if (moved) {
1580 rb->lcd_clear_display();
1582 /* Show level complete message & stats */
1583 rb->snprintf(buf, sizeof(buf), "Level %d Complete!",
1584 current_info.level.index + 1);
1585 rb->lcd_getstringsize(buf, &w, &h);
1586 rb->lcd_putsxy(LCD_WIDTH/2 - w/2, LCD_HEIGHT/2 - h*3, buf);
1588 rb->snprintf(buf, sizeof(buf), "%4d Moves ",
1589 current_info.level.moves);
1590 rb->lcd_getstringsize(buf, &w, &h);
1591 rb->lcd_putsxy(LCD_WIDTH/2 - w/2, LCD_HEIGHT/2 - h, buf);
1593 rb->snprintf(buf, sizeof(buf), "%4d Pushes",
1594 current_info.level.pushes);
1595 rb->lcd_getstringsize(buf, &w, &h);
1596 rb->lcd_putsxy(LCD_WIDTH/2 - w/2, LCD_HEIGHT/2, buf);
1598 if (undo_info.count < MAX_UNDOS) {
1599 rb->snprintf(buf, sizeof(buf), "%s: Save solution",
1600 BUTTON_SAVE_NAME);
1601 rb->lcd_getstringsize(buf, &w, &h);
1602 rb->lcd_putsxy(LCD_WIDTH/2 - w/2, LCD_HEIGHT/2 + h*2, buf);
1605 rb->lcd_update();
1606 rb->sleep(HZ/4);
1607 rb->button_clear_queue();
1609 /* Display for 4 seconds or until new keypress */
1610 for (i = 0; i < 80; i++) {
1611 rb->sleep(HZ/20);
1612 button = rb->button_get(false);
1613 if (button && !(button & BUTTON_REL) &&
1614 !(button & BUTTON_REPEAT))
1615 break;
1618 if (button == BUTTON_SAVE) {
1619 if (undo_info.count < MAX_UNDOS) {
1620 /* Set filename to current levelset plus level number
1621 * and .sok extension. Use SAVE_FOLDER if using the
1622 * default levelset, since it's in a hidden folder. */
1623 if (rb->strcmp(buffered_boards.filename,
1624 SOKOBAN_LEVELS_FILE) == 0) {
1625 rb->snprintf(buf, sizeof(buf),
1626 "%s/sokoban.%d.sok",
1627 SOKOBAN_SAVE_FOLDER,
1628 current_info.level.index + 1);
1629 } else {
1630 if ((loc = rb->strrchr(buffered_boards.filename,
1631 '.')) != NULL)
1632 *loc = '\0';
1633 rb->snprintf(buf, sizeof(buf), "%s.%d.sok",
1634 buffered_boards.filename,
1635 current_info.level.index + 1);
1636 if (loc != NULL)
1637 *loc = '.';
1640 if (!rb->kbd_input(buf, MAX_PATH))
1641 save(buf, true);
1642 } else
1643 rb->splash(HZ*2, "Solution too long to save");
1645 rb->lcd_setfont(SOKOBAN_FONT); /* Restore font */
1649 FOR_NB_SCREENS(i) {
1650 rb->screens[i]->clear_display();
1651 rb->screens[i]->update();
1654 current_info.level.index++;
1656 /* clear undo stats */
1657 init_undo();
1659 if (current_info.level.index >= current_info.max_level) {
1660 /* Show levelset complete message */
1661 rb->snprintf(buf, sizeof(buf), "You WIN!!");
1662 rb->lcd_getstringsize(buf, &w, &h);
1663 rb->lcd_putsxy(LCD_WIDTH/2 - w/2, LCD_HEIGHT/2 - h/2, buf);
1665 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
1666 /* Display for 4 seconds or until keypress */
1667 for (i = 0; i < 80; i++) {
1668 rb->lcd_fillrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
1669 rb->lcd_update();
1670 rb->sleep(HZ/10);
1672 button = rb->button_get(false);
1673 if (button && !(button & BUTTON_REL))
1674 break;
1676 rb->lcd_set_drawmode(DRMODE_SOLID);
1678 /* Reset to first level & show quit menu */
1679 current_info.level.index = 0;
1681 switch (sokoban_menu()) {
1682 case 5: /* Quit */
1683 case 6: /* Save & quit */
1684 return PLUGIN_OK;
1688 load_level();
1689 update_screen();
1692 } /* end while */
1694 return PLUGIN_OK;
1698 enum plugin_status plugin_start(const void* parameter)
1700 int w, h;
1702 (void)(parameter);
1704 rb->lcd_setfont(SOKOBAN_FONT);
1706 rb->lcd_clear_display();
1707 rb->lcd_getstringsize(SOKOBAN_TITLE, &w, &h);
1708 rb->lcd_putsxy(LCD_WIDTH/2 - w/2, LCD_HEIGHT/2 - h/2, SOKOBAN_TITLE);
1709 rb->lcd_update();
1710 rb->sleep(HZ); /* Show title for 1 second */
1712 init_boards();
1714 if (parameter == NULL) {
1715 /* Attempt to resume saved progress, otherwise start at beginning */
1716 if (!load(SOKOBAN_SAVE_FILE, true)) {
1717 init_boards();
1718 if (!read_levels(true))
1719 return PLUGIN_OK;
1720 load_level();
1723 } else {
1724 /* The plugin is being used to open a file */
1725 if (load((char*) parameter, false)) {
1726 /* If we loaded & played a solution, quit */
1727 if (current_info.level.boxes_to_go == 0)
1728 return PLUGIN_OK;
1729 } else
1730 return PLUGIN_OK;
1733 rb->lcd_clear_display();
1734 update_screen();
1736 return sokoban_loop();