1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN 0
29 #define SETUP_MODE_GAME 1
30 #define SETUP_MODE_INPUT 2
31 #define SETUP_MODE_SHORTCUT 3
32 #define SETUP_MODE_GRAPHICS 4
33 #define SETUP_MODE_SOUND 5
34 #define SETUP_MODE_ARTWORK 6
35 #define SETUP_MODE_CHOOSE_GRAPHICS 7
36 #define SETUP_MODE_CHOOSE_SOUNDS 8
37 #define SETUP_MODE_CHOOSE_MUSIC 9
39 #define MAX_SETUP_MODES 10
41 /* for input setup functions */
42 #define SETUPINPUT_SCREEN_POS_START 0
43 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
44 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
45 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
47 /* for various menu stuff */
48 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
49 #define MENU_SCREEN_START_YPOS 2
50 #define MENU_SCREEN_VALUE_XPOS 14
52 /* buttons and scrollbars identifiers */
53 #define SCREEN_CTRL_ID_SCROLL_UP 0
54 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
55 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
57 #define NUM_SCREEN_SCROLLBUTTONS 2
58 #define NUM_SCREEN_SCROLLBARS 1
59 #define NUM_SCREEN_GADGETS 3
61 /* forward declarations of internal functions */
62 static void HandleScreenGadgets(struct GadgetInfo *);
63 static void HandleSetupScreen_Generic(int, int, int, int, int);
64 static void HandleSetupScreen_Input(int, int, int, int, int);
65 static void CustomizeKeyboard(int);
66 static void CalibrateJoystick(int);
67 static void execSetupArtwork(void);
68 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
70 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
71 static int setup_mode = SETUP_MODE_MAIN;
73 static void drawCursorExt(int pos, int color, int graphic)
75 static int cursor_array[SCR_FIELDY];
78 cursor_array[pos] = graphic;
80 graphic = cursor_array[pos];
83 graphic = (graphic == GFX_ARROW_BLUE_LEFT ? GFX_ARROW_RED_LEFT :
84 graphic == GFX_ARROW_BLUE_RIGHT ? GFX_ARROW_RED_RIGHT :
87 DrawGraphic(0, MENU_SCREEN_START_YPOS + pos, graphic);
90 static void initCursor(int pos, int graphic)
92 drawCursorExt(pos, FC_BLUE, graphic);
95 static void drawCursor(int pos, int color)
97 drawCursorExt(pos, color, 0);
102 int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
104 DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
105 DrawTextFCentered(46, FC_RED, WINDOW_SUBTITLE_STRING);
108 static void ToggleFullscreenIfNeeded()
110 if (setup.fullscreen != video.fullscreen_enabled)
112 /* save old door content */
113 BlitBitmap(backbuffer, pix[PIX_DB_DOOR],
114 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
116 /* toggle fullscreen */
117 ChangeVideoModeIfNeeded(setup.fullscreen);
118 setup.fullscreen = video.fullscreen_enabled;
120 /* redraw background to newly created backbuffer */
121 BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
123 /* restore old door content */
124 BlitBitmap(pix[PIX_DB_DOOR], backbuffer,
125 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
127 redraw_mask = REDRAW_ALL;
133 static LevelDirTree *leveldir_last_valid = NULL;
135 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
139 KeyboardAutoRepeatOn();
141 SetDrawDeactivationMask(REDRAW_NONE);
142 audio.sound_deactivated = FALSE;
144 /* needed if last screen was the playing screen, invoked from level editor */
145 if (level_editor_test_game)
147 game_status = LEVELED;
152 /* needed if last screen was the editor screen */
153 UndrawSpecialEditorDoor();
155 /* needed if last screen was the setup screen and fullscreen state changed */
156 ToggleFullscreenIfNeeded();
158 /* needed if last screen (level choice) changed graphics, sounds or music */
159 ReloadCustomArtwork();
162 SetDrawtoField(DRAW_BACKBUFFER);
165 /* map gadgets for main menu screen */
168 /* leveldir_current may be invalid (level group, parent link) */
169 if (!validLevelSeries(leveldir_current))
170 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
172 /* store valid level series information */
173 leveldir_last_valid = leveldir_current;
175 /* level_nr may have been set to value over handicap with level editor */
176 if (setup.handicap && level_nr > leveldir_current->handicap_level)
177 level_nr = leveldir_current->handicap_level;
184 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
185 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
186 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
187 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
188 (leveldir_current->readonly ? FC_RED : FC_YELLOW));
189 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
190 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
191 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
192 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
193 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
194 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
196 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
198 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
199 leveldir_current->first_level,
200 leveldir_current->last_level);
202 if (leveldir_current->readonly)
204 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
205 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
209 initCursor(i, (i == 1 || i == 6 ? GFX_ARROW_BLUE_RIGHT : GFX_KUGEL_BLAU));
211 DrawGraphic(10, 3, GFX_ARROW_BLUE_LEFT);
212 DrawGraphic(14, 3, GFX_ARROW_BLUE_RIGHT);
214 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
217 if (leveldir_current->name)
219 int len = strlen(leveldir_current->name);
220 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
221 int lypos = SY + 352;
223 DrawText(lxpos, lypos, leveldir_current->name, FS_SMALL, FC_SPECIAL2);
228 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
231 if (TAPE_IS_EMPTY(tape))
233 DrawCompleteVideoDisplay();
235 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
242 static void gotoTopLevelDir()
244 /* move upwards to top level directory */
245 while (leveldir_current->node_parent)
247 /* write a "path" into level tree for easy navigation to last level */
248 if (leveldir_current->node_parent->node_group->cl_first == -1)
250 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
251 int leveldir_pos = posTreeInfo(leveldir_current);
252 int num_page_entries;
253 int cl_first, cl_cursor;
255 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
256 num_page_entries = num_leveldirs;
258 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
260 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
261 cl_cursor = leveldir_pos - cl_first;
263 leveldir_current->node_parent->node_group->cl_first = cl_first;
264 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
267 leveldir_current = leveldir_current->node_parent;
271 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
273 static int choice = 0;
277 if (button == MB_MENU_INITIALIZE)
279 drawCursor(choice, FC_RED);
283 if (mx || my) /* mouse input */
286 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
288 else if (dx || dy) /* keyboard input */
290 if (dx && choice == 1)
291 x = (dx < 0 ? 10 : 14);
296 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
297 (x == 14 && level_nr < leveldir_current->last_level)) &&
300 static unsigned long level_delay = 0;
301 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
302 int new_level_nr, old_level_nr = level_nr;
303 int font_color = (leveldir_current->readonly ? FC_RED : FC_YELLOW);
305 new_level_nr = level_nr + (x == 10 ? -step : +step);
306 if (new_level_nr < leveldir_current->first_level)
307 new_level_nr = leveldir_current->first_level;
308 if (new_level_nr > leveldir_current->last_level)
309 new_level_nr = leveldir_current->last_level;
311 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
312 new_level_nr = leveldir_current->handicap_level;
314 if (old_level_nr == new_level_nr ||
315 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
318 level_nr = new_level_nr;
320 DrawTextExt(drawto, SX + 11 * 32, SY + 3 * 32,
321 int2str(level_nr, 3), FS_BIG, font_color);
322 DrawTextExt(window, SX + 11 * 32, SY + 3 * 32,
323 int2str(level_nr, 3), FS_BIG, font_color);
326 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
330 DrawCompleteVideoDisplay();
332 /* needed because DrawMicroLevel() takes some time */
335 DelayReached(&level_delay, 0); /* reset delay counter */
337 else if (x == 0 && y >= 0 && y <= 7)
343 drawCursor(y, FC_RED);
344 drawCursor(choice, FC_BLUE);
352 game_status = TYPENAME;
353 HandleTypeName(strlen(setup.player_name), 0);
359 game_status = CHOOSELEVEL;
360 SaveLevelSetup_LastSeries();
361 SaveLevelSetup_SeriesInfo();
370 game_status = HALLOFFAME;
375 if (leveldir_current->readonly &&
376 strcmp(setup.player_name, "Artsoft") != 0)
377 Request("This level is read only !", REQ_CONFIRM);
378 game_status = LEVELED;
383 game_status = HELPSCREEN;
388 if (setup.autorecord)
389 TapeStartRecording();
391 #if defined(PLATFORM_UNIX)
393 SendToServer_StartPlaying();
397 game_status = PLAYING;
405 setup_mode = SETUP_MODE_MAIN;
410 SaveLevelSetup_LastSeries();
411 SaveLevelSetup_SeriesInfo();
412 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
413 game_status = EXITGAME;
422 if (game_status == MAINMENU)
424 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
430 #define MAX_HELPSCREEN_ELS 10
434 static long helpscreen_state;
435 static int helpscreen_step[MAX_HELPSCREEN_ELS];
436 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
437 static int helpscreen_delay[MAX_HELPSCREEN_ELS];
438 static int helpscreen_action[] =
440 GFX_SPIELER1_DOWN,4,2,
442 GFX_SPIELER1_LEFT,4,2,
443 GFX_SPIELER1_RIGHT,4,2,
444 GFX_SPIELER1_PUSH_LEFT,4,2,
445 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
446 GFX_ERDREICH,1,100, HA_NEXT,
447 GFX_LEERRAUM,1,100, HA_NEXT,
448 GFX_MORAST_LEER,1,100, HA_NEXT,
449 GFX_BETON,1,100, HA_NEXT,
450 GFX_MAUERWERK,1,100, HA_NEXT,
451 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
452 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
453 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
454 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
455 GFX_UNSICHTBAR,1,100, HA_NEXT,
456 GFX_FELSBODEN,1,100, HA_NEXT,
457 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
458 GFX_EDELSTEIN,2,5, HA_NEXT,
459 GFX_DIAMANT,2,5, HA_NEXT,
460 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
461 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
462 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
463 GFX_FELSBROCKEN,4,5, HA_NEXT,
464 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
465 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
466 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
467 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
468 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
469 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
470 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
471 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
472 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
473 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
474 GFX_GEBLUBBER,4,4, HA_NEXT,
475 GFX_SCHLUESSEL1,4,25, HA_NEXT,
476 GFX_PFORTE1,4,25, HA_NEXT,
477 GFX_PFORTE1X,4,25, HA_NEXT,
478 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
479 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
480 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
481 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
482 GFX_LEERRAUM,1,10, HA_NEXT,
483 GFX_DYNABOMB_NR,1,100, HA_NEXT,
484 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
485 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
486 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
487 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
488 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
489 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
490 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
491 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
492 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
493 GFX_BUTTERFLY,2,2, HA_NEXT,
494 GFX_FIREFLY,2,2, HA_NEXT,
495 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
496 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
497 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
498 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
499 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
500 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
501 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
502 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
503 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
504 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
508 GFX_MOLE_RIGHT,4,2, HA_NEXT,
509 GFX_PINGUIN_DOWN,4,2,
511 GFX_PINGUIN_LEFT,4,2,
512 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
513 GFX_SCHWEIN_DOWN,4,2,
515 GFX_SCHWEIN_LEFT,4,2,
516 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
520 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
521 GFX_SONDE_START,8,1, HA_NEXT,
522 GFX_ABLENK,4,1, HA_NEXT,
523 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
524 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
525 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
526 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
527 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
528 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
529 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
530 GFX_DIAMANT,1,10, HA_NEXT,
531 GFX_LIFE,1,100, HA_NEXT,
532 GFX_LIFE_ASYNC,1,100, HA_NEXT,
533 GFX_MAGIC_WALL_OFF,4,2, HA_NEXT,
534 GFX_MAGIC_WALL_BD_OFF,4,2, HA_NEXT,
535 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
536 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
537 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
538 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
539 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
540 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
541 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
542 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
543 GFX_SPEED_PILL,1,100, HA_NEXT,
546 static char *helpscreen_eltext[][2] =
548 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
549 {"Normal sand:", "You can dig through it"},
550 {"Empty field:", "You can walk through it"},
551 {"Quicksand: You cannot pass it,", "but rocks can fall though it"},
552 {"Massive Wall:", "Nothing can go through it"},
553 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
554 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
555 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
556 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
557 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
558 {"Emerald: You must collect enough of","them to finish a level"},
559 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
560 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
561 {"Colorful Gems:", "Seem to behave like Emeralds"},
562 {"Rock: Smashes several things;", "Can be moved by the player"},
563 {"Bomb: You can move it, but be", "careful when dropping it"},
564 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
565 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
566 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
567 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
568 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
569 {"Acid: Things that fall in are gone", "forever (including our hero)"},
570 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
571 {"Door: Can be opened by the key", "with the same color"},
572 {"Door: You have to find out the", "right color of the key for it"},
573 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
574 {"Dynamite: This one explodes after", "a few seconds"},
575 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
576 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
577 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
578 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
579 {"Bug: Moves at the right side", "of walls; don't touch it!"},
580 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
581 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
582 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
583 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
584 {"Cruncher (BD style):", "Eats almost everything"},
585 {"Robot: Tries to kill the player", ""},
586 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
587 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
588 {"The Pig: Harmless, but eats all", "gems it can get"},
589 {"The Dragon: Breathes fire,", "especially to some monsters"},
590 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
591 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
592 {"Light Bulb: All of them must be", "switched on to finish a level"},
593 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
594 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
595 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
596 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
597 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
598 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
599 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
600 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
601 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
602 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
603 {"Exit door: Opens if you have enough","emeralds to finish the level"},
604 {"Open exit door: Enter here to leave","the level and exit the actual game"},
605 {"Sokoban element: Object which must", "be pushed to an empty field"},
606 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
607 {"Sokoban element: Field with object", "which can be pushed away"},
608 {"Speed pill: Lets the player run", "twice as fast as normally"},
610 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
612 static char *helpscreen_music[][3] =
614 { "Alchemy", "Ian Boddy", "Drive" },
615 { "The Chase", "Propaganda", "A Secret Wish" },
616 { "Network 23", "Tangerine Dream", "Exit" },
617 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
618 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
619 { "Voyager", "The Alan Parsons Project","Pyramid" },
620 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
622 static int num_helpscreen_music = 7;
623 static int helpscreen_musicpos;
625 void DrawHelpScreenElAction(int start)
629 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
631 while(helpscreen_action[j] != HA_END)
633 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
635 else if (i<start || helpscreen_delay[i-start])
637 if (i>=start && helpscreen_delay[i-start])
638 helpscreen_delay[i-start]--;
640 while(helpscreen_action[j] != HA_NEXT)
647 j += 3*helpscreen_step[i-start];
648 graphic = helpscreen_action[j++];
650 if (helpscreen_frame[i-start])
652 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
653 helpscreen_frame[i-start]--;
658 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
661 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
663 if (helpscreen_action[j] == HA_NEXT)
665 if (!helpscreen_frame[i-start])
666 helpscreen_step[i-start] = 0;
670 if (!helpscreen_frame[i-start])
671 helpscreen_step[i-start]++;
672 while(helpscreen_action[j] != HA_NEXT)
677 DrawGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
688 void DrawHelpScreenElText(int start)
691 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
692 int ybottom = SYSIZE - 20;
697 DrawTextFCentered(100, FC_GREEN, "The game elements:");
699 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
702 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
703 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
704 DrawText(xstart, ystart + (i - start) * ystep + 16,
705 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
708 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
711 void DrawHelpScreenMusicText(int num)
713 int ystart = 150, ystep = 30;
714 int ybottom = SYSIZE - 20;
720 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
722 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
724 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
725 helpscreen_music[num][0]);
726 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
728 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
729 "%s", helpscreen_music[num][1]);
730 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
732 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
733 helpscreen_music[num][2]);
735 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
738 PlaySoundLoop(background_loop[num]);
742 void DrawHelpScreenCreditsText()
744 int ystart = 150, ystep = 30;
745 int ybottom = SYSIZE - 20;
751 DrawTextFCentered(100, FC_GREEN,
753 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
754 "DOS port of the game:");
755 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
757 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
758 "Additional toons:");
759 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
761 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
762 "...and many thanks to all contributors");
763 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
766 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
769 void DrawHelpScreenContactText()
771 int ystart = 150, ystep = 30;
772 int ybottom = SYSIZE - 20;
777 DrawTextFCentered(100, FC_GREEN, "Program information:");
779 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
780 "This game is Freeware!");
781 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
782 "If you like it, send e-mail to:");
783 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
785 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
787 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
789 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
790 "Detmolder Strasse 189");
791 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
793 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
796 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
797 "If you have created new levels,");
798 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
799 "send them to me to include them!");
800 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
803 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
806 void DrawHelpScreen()
811 CloseDoor(DOOR_CLOSE_2);
813 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
814 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
815 helpscreen_musicpos = 0;
816 helpscreen_state = 0;
817 DrawHelpScreenElText(0);
818 DrawHelpScreenElAction(0);
822 PlaySoundLoop(SND_MENU_INFO_SCREEN);
825 void HandleHelpScreen(int button)
827 static unsigned long hs_delay = 0;
828 int num_helpscreen_els_pages =
829 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
830 int button_released = !button;
835 if (helpscreen_state < num_helpscreen_els_pages - 1)
837 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
838 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
840 DrawHelpScreenElText(helpscreen_state * MAX_HELPSCREEN_ELS);
841 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
843 else if (helpscreen_state <
844 num_helpscreen_els_pages + num_helpscreen_music - 1)
847 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
849 else if (helpscreen_state ==
850 num_helpscreen_els_pages + num_helpscreen_music - 1)
853 DrawHelpScreenCreditsText();
855 else if (helpscreen_state ==
856 num_helpscreen_els_pages + num_helpscreen_music)
859 DrawHelpScreenContactText();
865 game_status = MAINMENU;
870 if (DelayReached(&hs_delay, GAME_FRAME_DELAY * 2))
872 if (helpscreen_state < num_helpscreen_els_pages)
873 DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
876 /* !!! workaround for playing "music" that is really a sound loop (and
877 must therefore periodically be reactivated with the current sound
879 PlaySoundLoop(SND_MENU_INFO_SCREEN);
887 void HandleTypeName(int newxpos, Key key)
889 static int xpos = 0, ypos = 2;
894 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
895 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
899 if (((key >= KSYM_A && key <= KSYM_Z) ||
900 (key >= KSYM_a && key <= KSYM_z)) &&
901 xpos < MAX_PLAYER_NAME_LEN)
905 if (key >= KSYM_A && key <= KSYM_Z)
906 ascii = 'A' + (char)(key - KSYM_A);
908 ascii = 'a' + (char)(key - KSYM_a);
910 setup.player_name[xpos] = ascii;
911 setup.player_name[xpos + 1] = 0;
913 DrawTextExt(drawto, SX + 6*32, SY + ypos*32,
914 setup.player_name, FS_BIG, FC_YELLOW);
915 DrawTextExt(window, SX + 6*32, SY + ypos*32,
916 setup.player_name, FS_BIG, FC_YELLOW);
917 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
919 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
922 setup.player_name[xpos] = 0;
923 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
924 DrawGraphic(xpos + 7, ypos, GFX_LEERRAUM);
926 else if (key == KSYM_Return && xpos > 0)
928 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_RED);
929 DrawGraphic(xpos + 6, ypos, GFX_LEERRAUM);
932 game_status = MAINMENU;
938 static void DrawChooseTree(TreeInfo **ti_ptr)
941 CloseDoor(DOOR_CLOSE_2);
944 HandleChooseTree(0,0, 0,0, MB_MENU_INITIALIZE, ti_ptr);
945 MapChooseTreeGadgets(*ti_ptr);
951 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
953 struct GadgetInfo *gi = screen_gadget[id];
954 int items_max, items_visible, item_position;
956 items_max = numTreeInfoInGroup(ti);
957 items_visible = MAX_MENU_ENTRIES_ON_SCREEN - 1;
958 item_position = first_entry;
960 if (item_position > items_max - items_visible)
961 item_position = items_max - items_visible;
963 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
964 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
967 static void drawChooseTreeList(int first_entry, int num_page_entries,
971 char buffer[SCR_FIELDX * 2];
972 int max_buffer_len = (SCR_FIELDX - 2) * 2;
973 int num_entries = numTreeInfoInGroup(ti);
974 char *title_string = NULL;
975 int offset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : 16);
977 ClearRectangle(backbuffer, SX, SY, SXSIZE - 32, SYSIZE);
978 redraw_mask |= REDRAW_FIELD;
981 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
982 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
983 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
984 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
986 DrawText(SX + offset, SY + offset, title_string, FS_BIG,
987 (ti->type == TREE_TYPE_LEVEL_DIR ? FC_GREEN : FC_YELLOW));
989 for(i=0; i<num_page_entries; i++)
991 TreeInfo *node, *node_first;
992 int entry_pos = first_entry + i;
993 int ypos = MENU_SCREEN_START_YPOS + i;
995 node_first = getTreeInfoFirstGroupEntry(ti);
996 node = getTreeInfoFromPos(node_first, entry_pos);
998 strncpy(buffer, node->name , max_buffer_len);
999 buffer[max_buffer_len] = '\0';
1001 DrawText(SX + 32, SY + ypos * 32, buffer, FS_MEDIUM, node->color);
1003 if (node->parent_link)
1004 initCursor(i, GFX_ARROW_BLUE_LEFT);
1005 else if (node->level_group)
1006 initCursor(i, GFX_ARROW_BLUE_RIGHT);
1008 initCursor(i, GFX_KUGEL_BLAU);
1011 if (first_entry > 0)
1012 DrawGraphic(0, 1, GFX_ARROW_BLUE_UP);
1014 if (first_entry + num_page_entries < num_entries)
1015 DrawGraphic(0, MAX_MENU_ENTRIES_ON_SCREEN + 1, GFX_ARROW_BLUE_DOWN);
1018 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1020 TreeInfo *node, *node_first;
1021 int x, last_redraw_mask = redraw_mask;
1023 if (ti->type != TREE_TYPE_LEVEL_DIR)
1026 node_first = getTreeInfoFirstGroupEntry(ti);
1027 node = getTreeInfoFromPos(node_first, entry_pos);
1029 ClearRectangle(drawto, SX + 32, SY + 32, SXSIZE - 64, 32);
1031 if (node->parent_link)
1032 DrawTextFCentered(40, FC_RED, "leave group \"%s\"", node->class_desc);
1033 else if (node->level_group)
1034 DrawTextFCentered(40, FC_RED, "enter group \"%s\"", node->class_desc);
1035 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1036 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
1037 node->levels, node->class_desc);
1039 /* let BackToFront() redraw only what is needed */
1040 redraw_mask = last_redraw_mask | REDRAW_TILES;
1041 for (x=0; x<SCR_FIELDX; x++)
1042 MarkTileDirty(x, 1);
1045 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1048 static unsigned long choose_delay = 0;
1049 TreeInfo *ti = *ti_ptr;
1051 int y = ti->cl_cursor;
1052 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1053 int num_entries = numTreeInfoInGroup(ti);
1054 int num_page_entries;
1056 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
1057 num_page_entries = num_entries;
1059 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1061 if (button == MB_MENU_INITIALIZE)
1063 int entry_pos = posTreeInfo(ti);
1065 if (ti->cl_first == -1)
1067 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1069 entry_pos - ti->cl_first;
1072 if (dx == 999) /* first entry is set by scrollbar position */
1075 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1078 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1079 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1080 drawCursor(ti->cl_cursor, FC_RED);
1083 else if (button == MB_MENU_LEAVE)
1085 if (ti->node_parent)
1087 *ti_ptr = ti->node_parent;
1088 DrawChooseTree(ti_ptr);
1090 else if (game_status == SETUP)
1096 game_status = MAINMENU;
1103 if (mx || my) /* mouse input */
1106 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1108 else if (dx || dy) /* keyboard input */
1111 y = ti->cl_cursor + dy;
1113 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1116 step = num_page_entries - 1;
1117 y = (dy < 0 ? -1 : num_page_entries);
1121 if (x == 0 && y == -1)
1123 if (ti->cl_first > 0 &&
1124 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1126 ti->cl_first -= step;
1127 if (ti->cl_first < 0)
1130 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1131 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1132 drawCursor(ti->cl_cursor, FC_RED);
1133 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1138 else if (x == 0 && y > num_page_entries - 1)
1140 if (ti->cl_first + num_page_entries < num_entries &&
1141 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
1143 ti->cl_first += step;
1144 if (ti->cl_first + num_page_entries > num_entries)
1145 ti->cl_first = MAX(0, num_entries - num_page_entries);
1147 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1148 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1149 drawCursor(ti->cl_cursor, FC_RED);
1150 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1158 TreeInfo *node_first, *node_cursor;
1159 int entry_pos = ti->cl_first + y;
1161 node_first = getTreeInfoFirstGroupEntry(ti);
1162 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1164 if (node_cursor->node_group)
1166 node_cursor->cl_first = ti->cl_first;
1167 node_cursor->cl_cursor = ti->cl_cursor;
1168 *ti_ptr = node_cursor->node_group;
1169 DrawChooseTree(ti_ptr);
1173 else if (dx == -1 && ti->node_parent)
1175 *ti_ptr = ti->node_parent;
1176 DrawChooseTree(ti_ptr);
1180 if (x == 0 && y >= 0 && y < num_page_entries)
1184 if (y != ti->cl_cursor)
1186 drawCursor(y, FC_RED);
1187 drawCursor(ti->cl_cursor, FC_BLUE);
1188 drawChooseTreeInfo(ti->cl_first + y, ti);
1194 TreeInfo *node_first, *node_cursor;
1195 int entry_pos = ti->cl_first + y;
1197 node_first = getTreeInfoFirstGroupEntry(ti);
1198 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1200 if (node_cursor->node_group)
1202 node_cursor->cl_first = ti->cl_first;
1203 node_cursor->cl_cursor = ti->cl_cursor;
1204 *ti_ptr = node_cursor->node_group;
1205 DrawChooseTree(ti_ptr);
1207 else if (node_cursor->parent_link)
1209 *ti_ptr = node_cursor->node_parent;
1210 DrawChooseTree(ti_ptr);
1214 node_cursor->cl_first = ti->cl_first;
1215 node_cursor->cl_cursor = ti->cl_cursor;
1216 *ti_ptr = node_cursor;
1218 if (ti->type == TREE_TYPE_LEVEL_DIR)
1220 LoadLevelSetup_SeriesInfo();
1222 SaveLevelSetup_LastSeries();
1223 SaveLevelSetup_SeriesInfo();
1227 if (game_status == SETUP)
1233 game_status = MAINMENU;
1242 if (game_status == CHOOSELEVEL || game_status == SETUP)
1246 void DrawChooseLevel()
1248 DrawChooseTree(&leveldir_current);
1251 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1253 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1256 void DrawHallOfFame(int highlight_position)
1260 CloseDoor(DOOR_CLOSE_2);
1262 if (highlight_position < 0)
1263 LoadScore(level_nr);
1267 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1268 PlaySound(SND_MENU_HALL_OF_FAME);
1271 static void drawHallOfFameList(int first_entry, int highlight_position)
1276 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1277 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1279 for(i=0; i<MAX_MENU_ENTRIES_ON_SCREEN; i++)
1281 int entry = first_entry + i;
1282 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1285 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1286 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1287 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1288 int2str(highscore[i].Score, 5), FS_BIG, color);
1290 DrawText(SX, SY + 64 + i * 32, "..................................",
1291 FS_MEDIUM, FC_YELLOW);
1292 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1293 FS_MEDIUM, FC_YELLOW);
1294 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1295 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1296 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1301 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1303 static int first_entry = 0;
1304 static int highlight_position = 0;
1305 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1306 int button_released = !button;
1308 if (button == MB_MENU_INITIALIZE)
1311 highlight_position = mx;
1312 drawHallOfFameList(first_entry, highlight_position);
1316 if (ABS(dy) == SCR_FIELDY) /* handle KSYM_Page_Up, KSYM_Page_Down */
1317 step = MAX_MENU_ENTRIES_ON_SCREEN - 1;
1321 if (first_entry > 0)
1323 first_entry -= step;
1324 if (first_entry < 0)
1327 drawHallOfFameList(first_entry, highlight_position);
1333 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1335 first_entry += step;
1336 if (first_entry + MAX_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1337 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_MENU_ENTRIES_ON_SCREEN);
1339 drawHallOfFameList(first_entry, highlight_position);
1344 if (button_released)
1346 FadeSound(SND_MENU_HALL_OF_FAME);
1347 game_status = MAINMENU;
1353 if (game_status == HALLOFFAME)
1358 /* ========================================================================= */
1359 /* setup screen functions */
1360 /* ========================================================================= */
1362 static struct TokenInfo *setup_info;
1363 static int num_setup_info;
1365 static void execSetupMain()
1367 setup_mode = SETUP_MODE_MAIN;
1371 static void execSetupGame()
1373 setup_mode = SETUP_MODE_GAME;
1377 static void execSetupGraphics()
1379 setup_mode = SETUP_MODE_GRAPHICS;
1383 static void execSetupSound()
1385 setup_mode = SETUP_MODE_SOUND;
1389 static void execSetupArtwork()
1391 /* needed if last screen (setup choice) changed graphics, sounds or music */
1392 ReloadCustomArtwork();
1394 setup.graphics_set = artwork.gfx_current->name;
1395 setup.sounds_set = artwork.snd_current->name;
1396 setup.music_set = artwork.mus_current->name;
1398 setup_mode = SETUP_MODE_ARTWORK;
1402 static void execSetupChooseGraphics()
1404 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1408 static void execSetupChooseSounds()
1410 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1414 static void execSetupChooseMusic()
1416 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1420 static void execSetupInput()
1422 setup_mode = SETUP_MODE_INPUT;
1426 static void execSetupShortcut()
1428 setup_mode = SETUP_MODE_SHORTCUT;
1432 static void execExitSetup()
1434 game_status = MAINMENU;
1438 static void execSaveAndExitSetup()
1444 static struct TokenInfo setup_info_main[] =
1446 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1447 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1448 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1449 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1450 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1451 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1452 { TYPE_EMPTY, NULL, "" },
1453 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1454 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and exit" },
1458 static struct TokenInfo setup_info_game[] =
1460 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1461 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1462 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1463 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1464 { TYPE_EMPTY, NULL, "" },
1465 { TYPE_LEAVE_MENU, execSetupMain, "Exit" },
1469 static struct TokenInfo setup_info_graphics[] =
1471 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1472 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1473 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1475 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1476 { TYPE_SWITCH, &setup.fading, "Fading:" },
1478 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1479 { TYPE_SWITCH, &setup.toons, "Toons:" },
1480 { TYPE_EMPTY, NULL, "" },
1481 { TYPE_LEAVE_MENU, execSetupMain, "Exit" },
1485 static struct TokenInfo setup_info_sound[] =
1487 { TYPE_SWITCH, &setup.sound, "Sound:", },
1488 { TYPE_EMPTY, NULL, "" },
1489 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1490 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1491 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1492 { TYPE_EMPTY, NULL, "" },
1493 { TYPE_LEAVE_MENU, execSetupMain, "Exit" },
1497 static struct TokenInfo setup_info_artwork[] =
1499 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1500 { TYPE_STRING, &setup.graphics_set, "" },
1501 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1502 { TYPE_STRING, &setup.sounds_set, "" },
1503 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1504 { TYPE_STRING, &setup.music_set, "" },
1505 { TYPE_EMPTY, NULL, "" },
1506 { TYPE_STRING, NULL, "Override Level Artwork:"},
1507 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1508 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1509 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1510 { TYPE_EMPTY, NULL, "" },
1511 { TYPE_LEAVE_MENU, execSetupMain, "Exit" },
1515 static struct TokenInfo setup_info_shortcut[] =
1517 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1518 { TYPE_KEY, &setup.shortcut.save_game, "" },
1519 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1520 { TYPE_KEY, &setup.shortcut.load_game, "" },
1521 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1522 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1523 { TYPE_EMPTY, NULL, "" },
1524 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1525 { TYPE_EMPTY, NULL, "" },
1526 { TYPE_LEAVE_MENU, execSetupMain, "Exit" },
1530 static Key getSetupKey()
1532 Key key = KSYM_UNDEFINED;
1533 boolean got_key_event = FALSE;
1535 while (!got_key_event)
1537 if (PendingEvent()) /* got event */
1545 case EVENT_KEYPRESS:
1547 key = GetEventKey((KeyEvent *)&event, TRUE);
1549 /* press 'Escape' or 'Enter' to keep the existing key binding */
1550 if (key == KSYM_Escape || key == KSYM_Return)
1551 key = KSYM_UNDEFINED; /* keep old value */
1553 got_key_event = TRUE;
1557 case EVENT_KEYRELEASE:
1558 key_joystick_mapping = 0;
1562 HandleOtherEvents(&event);
1570 /* don't eat all CPU time */
1577 static void drawSetupValue(int pos)
1579 int xpos = MENU_SCREEN_VALUE_XPOS;
1580 int ypos = MENU_SCREEN_START_YPOS + pos;
1581 int font_size = FS_BIG;
1582 int font_color = FC_YELLOW;
1583 char *value_string = getSetupValue(setup_info[pos].type & ~TYPE_GHOSTED,
1584 setup_info[pos].value);
1586 if (value_string == NULL)
1589 if (setup_info[pos].type & TYPE_KEY)
1593 if (setup_info[pos].type & TYPE_QUERY)
1595 value_string = "<press key>";
1596 font_color = FC_RED;
1599 else if (setup_info[pos].type & TYPE_STRING)
1601 int max_value_len = (SCR_FIELDX - 2) * 2;
1604 font_size = FS_MEDIUM;
1606 if (strlen(value_string) > max_value_len)
1607 value_string[max_value_len] = '\0';
1609 else if (setup_info[pos].type & TYPE_BOOLEAN_STYLE &&
1610 !*(boolean *)(setup_info[pos].value))
1611 font_color = FC_BLUE;
1613 DrawText(SX + xpos * 32, SY + ypos * 32,
1614 (xpos == 3 ? " " : " "), FS_BIG, FC_YELLOW);
1615 DrawText(SX + xpos * 32, SY + ypos * 32, value_string, font_size,font_color);
1618 static void changeSetupValue(int pos)
1620 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1622 *(boolean *)setup_info[pos].value ^= TRUE;
1624 else if (setup_info[pos].type & TYPE_KEY)
1628 setup_info[pos].type |= TYPE_QUERY;
1629 drawSetupValue(pos);
1630 setup_info[pos].type &= ~TYPE_QUERY;
1632 key = getSetupKey();
1633 if (key != KSYM_UNDEFINED)
1634 *(Key *)setup_info[pos].value = key;
1637 drawSetupValue(pos);
1640 static void DrawSetupScreen_Generic()
1642 char *title_string = NULL;
1646 CloseDoor(DOOR_CLOSE_2);
1649 if (setup_mode == SETUP_MODE_MAIN)
1651 setup_info = setup_info_main;
1652 title_string = "Setup";
1654 else if (setup_mode == SETUP_MODE_GAME)
1656 setup_info = setup_info_game;
1657 title_string = "Setup Game";
1659 else if (setup_mode == SETUP_MODE_GRAPHICS)
1661 setup_info = setup_info_graphics;
1662 title_string = "Setup Graphics";
1664 else if (setup_mode == SETUP_MODE_SOUND)
1666 setup_info = setup_info_sound;
1667 title_string = "Setup Sound";
1669 else if (setup_mode == SETUP_MODE_ARTWORK)
1671 setup_info = setup_info_artwork;
1672 title_string = "Custom Artwork";
1674 else if (setup_mode == SETUP_MODE_SHORTCUT)
1676 setup_info = setup_info_shortcut;
1677 title_string = "Setup Shortcuts";
1680 DrawText(SX + 16, SY + 16, title_string, FS_BIG, FC_YELLOW);
1683 for(i=0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1685 void *value_ptr = setup_info[i].value;
1686 int ypos = MENU_SCREEN_START_YPOS + i;
1687 int font_size = FS_BIG;
1689 /* set some entries to "unchangeable" according to other variables */
1690 if ((value_ptr == &setup.sound && !audio.sound_available) ||
1691 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
1692 (value_ptr == &setup.sound_music && !audio.music_available) ||
1693 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
1694 setup_info[i].type |= TYPE_GHOSTED;
1696 if (setup_info[i].type & TYPE_STRING)
1697 font_size = FS_MEDIUM;
1699 DrawText(SX + 32, SY + ypos * 32, setup_info[i].text, font_size, FC_GREEN);
1701 if (setup_info[i].type & TYPE_ENTER_MENU)
1702 initCursor(i, GFX_ARROW_BLUE_RIGHT);
1703 else if (setup_info[i].type & TYPE_LEAVE_MENU)
1704 initCursor(i, GFX_ARROW_BLUE_LEFT);
1705 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
1706 initCursor(i, GFX_KUGEL_BLAU);
1708 if (setup_info[i].type & TYPE_VALUE)
1716 HandleSetupScreen_Generic(0,0,0,0,MB_MENU_INITIALIZE);
1719 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
1721 static int choice_store[MAX_SETUP_MODES];
1722 int choice = choice_store[setup_mode];
1726 if (button == MB_MENU_INITIALIZE)
1728 drawCursor(choice, FC_RED);
1731 else if (button == MB_MENU_LEAVE)
1733 for (y=0; y<num_setup_info; y++)
1735 if (setup_info[y].type & TYPE_LEAVE_MENU)
1737 void (*menu_callback_function)(void) = setup_info[y].value;
1739 menu_callback_function();
1740 break; /* absolutely needed because function changes 'setup_info'! */
1747 if (mx || my) /* mouse input */
1750 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1752 else if (dx || dy) /* keyboard input */
1756 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
1758 if ((setup_info[choice].type & menu_navigation_type) ||
1759 (setup_info[choice].type & TYPE_BOOLEAN_STYLE))
1760 button = MB_MENU_CHOICE;
1765 /* jump to next non-empty menu entry (up or down) */
1766 while (y > 0 && y < num_setup_info - 1 &&
1767 (setup_info[y].type & TYPE_SKIP_ENTRY))
1771 if (x == 0 && y >= 0 && y < num_setup_info &&
1772 (setup_info[y].type & ~TYPE_SKIP_ENTRY))
1778 drawCursor(y, FC_RED);
1779 drawCursor(choice, FC_BLUE);
1780 choice = choice_store[setup_mode] = y;
1783 else if (!(setup_info[y].type & TYPE_GHOSTED))
1785 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
1787 void (*menu_callback_function)(void) = setup_info[choice].value;
1789 menu_callback_function();
1793 if ((setup_info[y].type & TYPE_KEYTEXT) &&
1794 (setup_info[y + 1].type & TYPE_KEY))
1797 if (setup_info[y].type & TYPE_VALUE)
1798 changeSetupValue(y);
1805 if (game_status == SETUP)
1809 void DrawSetupScreen_Input()
1812 DrawText(SX+16, SY+16, "Setup Input", FS_BIG, FC_YELLOW);
1814 initCursor(0, GFX_KUGEL_BLAU);
1815 initCursor(1, GFX_KUGEL_BLAU);
1816 initCursor(2, GFX_ARROW_BLUE_RIGHT);
1817 initCursor(13, GFX_ARROW_BLUE_LEFT);
1819 DrawGraphic(10, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_LEFT);
1820 DrawGraphic(12, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_RIGHT);
1822 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
1823 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
1824 DrawText(SX+32, SY+15*32, "Exit", FS_BIG, FC_GREEN);
1827 DeactivateJoystickForCalibration();
1828 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
1829 "Joysticks deactivated on this screen");
1832 HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
1837 static void setJoystickDeviceToNr(char *device_name, int device_nr)
1839 if (device_name == NULL)
1842 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
1845 if (strlen(device_name) > 1)
1847 char c1 = device_name[strlen(device_name) - 1];
1848 char c2 = device_name[strlen(device_name) - 2];
1850 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
1851 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
1854 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
1855 strlen(device_name));
1858 static void drawPlayerSetupInputInfo(int player_nr)
1861 static struct SetupKeyboardInfo custom_key;
1868 { &custom_key.left, "Joystick Left" },
1869 { &custom_key.right, "Joystick Right" },
1870 { &custom_key.up, "Joystick Up" },
1871 { &custom_key.down, "Joystick Down" },
1872 { &custom_key.snap, "Button 1" },
1873 { &custom_key.bomb, "Button 2" }
1875 static char *joystick_name[MAX_PLAYERS] =
1883 custom_key = setup.input[player_nr].key;
1885 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
1886 DrawGraphic(8, 2, GFX_SPIELER1 + player_nr);
1888 if (setup.input[player_nr].use_joystick)
1890 char *device_name = setup.input[player_nr].joy.device_name;
1892 DrawText(SX+8*32, SY+3*32,
1893 joystick_name[getJoystickNrFromDeviceName(device_name)],
1895 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
1899 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
1900 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
1903 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
1904 DrawGraphic(1, 6, GFX_ARROW_BLUE_LEFT);
1905 DrawGraphic(1, 7, GFX_ARROW_BLUE_RIGHT);
1906 DrawGraphic(1, 8, GFX_ARROW_BLUE_UP);
1907 DrawGraphic(1, 9, GFX_ARROW_BLUE_DOWN);
1908 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
1909 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
1910 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
1911 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
1912 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
1913 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
1917 int ypos = 6 + i + (i > 3 ? i-3 : 0);
1919 DrawText(SX + 3*32, SY + ypos*32,
1920 " ", FS_BIG, FC_YELLOW);
1921 DrawText(SX + 3*32, SY + ypos*32,
1922 (setup.input[player_nr].use_joystick ?
1924 getKeyNameFromKey(*custom[i].key)),
1929 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
1931 static int choice = 0;
1932 static int player_nr = 0;
1935 int pos_start = SETUPINPUT_SCREEN_POS_START;
1936 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
1937 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
1938 int pos_end = SETUPINPUT_SCREEN_POS_END;
1940 if (button == MB_MENU_INITIALIZE)
1942 drawPlayerSetupInputInfo(player_nr);
1943 drawCursor(choice, FC_RED);
1946 else if (button == MB_MENU_LEAVE)
1948 setup_mode = SETUP_MODE_MAIN;
1953 if (mx || my) /* mouse input */
1956 y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
1958 else if (dx || dy) /* keyboard input */
1960 if (dx && choice == 0)
1961 x = (dx < 0 ? 10 : 12);
1962 else if ((dx && choice == 1) ||
1963 (dx == +1 && choice == 2) ||
1964 (dx == -1 && choice == pos_end))
1965 button = MB_MENU_CHOICE;
1969 if (y >= pos_empty1 && y <= pos_empty2)
1970 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
1973 if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
1975 static unsigned long delay = 0;
1977 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
1980 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
1982 drawPlayerSetupInputInfo(player_nr);
1984 else if (x == 0 && y >= pos_start && y <= pos_end &&
1985 !(y >= pos_empty1 && y <= pos_empty2))
1991 drawCursor(y, FC_RED);
1992 drawCursor(choice, FC_BLUE);
2000 char *device_name = setup.input[player_nr].joy.device_name;
2002 if (!setup.input[player_nr].use_joystick)
2004 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2006 setJoystickDeviceToNr(device_name, new_device_nr);
2007 setup.input[player_nr].use_joystick = TRUE;
2011 int device_nr = getJoystickNrFromDeviceName(device_name);
2012 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2014 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2015 setup.input[player_nr].use_joystick = FALSE;
2017 setJoystickDeviceToNr(device_name, new_device_nr);
2020 drawPlayerSetupInputInfo(player_nr);
2024 if (setup.input[player_nr].use_joystick)
2027 CalibrateJoystick(player_nr);
2030 CustomizeKeyboard(player_nr);
2032 else if (y == pos_end)
2036 setup_mode = SETUP_MODE_MAIN;
2046 if (game_status == SETUP)
2050 void CustomizeKeyboard(int player_nr)
2054 boolean finished = FALSE;
2055 static struct SetupKeyboardInfo custom_key;
2060 } customize_step[] =
2062 { &custom_key.left, "Move Left" },
2063 { &custom_key.right, "Move Right" },
2064 { &custom_key.up, "Move Up" },
2065 { &custom_key.down, "Move Down" },
2066 { &custom_key.snap, "Snap Field" },
2067 { &custom_key.bomb, "Place Bomb" }
2070 /* read existing key bindings from player setup */
2071 custom_key = setup.input[player_nr].key;
2074 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
2080 DrawText(SX, SY + (2+2*step_nr)*32,
2081 customize_step[step_nr].text, FS_BIG, FC_RED);
2082 DrawText(SX, SY + (2+2*step_nr+1)*32,
2083 "Key:", FS_BIG, FC_RED);
2084 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2085 getKeyNameFromKey(*customize_step[step_nr].key),
2090 if (PendingEvent()) /* got event */
2098 case EVENT_KEYPRESS:
2100 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2102 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2108 /* all keys configured -- wait for "Escape" or "Return" key */
2112 /* press 'Enter' to keep the existing key binding */
2113 if (key == KSYM_Return)
2114 key = *customize_step[step_nr].key;
2116 /* check if key already used */
2117 for (i=0; i<step_nr; i++)
2118 if (*customize_step[i].key == key)
2123 /* got new key binding */
2124 *customize_step[step_nr].key = key;
2125 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2126 " ", FS_BIG, FC_YELLOW);
2127 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
2128 getKeyNameFromKey(key), FS_BIG, FC_YELLOW);
2131 /* un-highlight last query */
2132 DrawText(SX, SY+(2+2*(step_nr-1))*32,
2133 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
2134 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
2135 "Key:", FS_BIG, FC_GREEN);
2137 /* press 'Enter' to leave */
2140 DrawText(SX + 16, SY + 15*32+16,
2141 "Press Enter", FS_BIG, FC_YELLOW);
2145 /* query next key binding */
2146 DrawText(SX, SY+(2+2*step_nr)*32,
2147 customize_step[step_nr].text, FS_BIG, FC_RED);
2148 DrawText(SX, SY+(2+2*step_nr+1)*32,
2149 "Key:", FS_BIG, FC_RED);
2150 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
2151 getKeyNameFromKey(*customize_step[step_nr].key),
2156 case EVENT_KEYRELEASE:
2157 key_joystick_mapping = 0;
2161 HandleOtherEvents(&event);
2169 /* don't eat all CPU time */
2173 /* write new key bindings back to player setup */
2174 setup.input[player_nr].key = custom_key;
2177 DrawSetupScreen_Input();
2180 static boolean CalibrateJoystickMain(int player_nr)
2182 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2183 int new_joystick_xright = JOYSTICK_XMIDDLE;
2184 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2185 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2186 int new_joystick_xmiddle, new_joystick_ymiddle;
2188 int joystick_fd = joystick.fd[player_nr];
2189 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2190 boolean check[3][3];
2191 int check_remaining = 3 * 3;
2196 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2199 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2208 check[x][y] = FALSE;
2209 DrawGraphic(xpos + x - 1, ypos + y - 1, GFX_KUGEL_BLAU);
2213 DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
2214 DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
2215 DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
2216 DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
2217 DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
2218 DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
2219 DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
2221 joy_value = Joystick(player_nr);
2222 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2223 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2225 /* eventually uncalibrated center position (joystick could be uncentered) */
2226 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2229 new_joystick_xmiddle = joy_x;
2230 new_joystick_ymiddle = joy_y;
2232 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
2235 while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2240 if (PendingEvent()) /* got event */
2248 case EVENT_KEYPRESS:
2249 switch(GetEventKey((KeyEvent *)&event, TRUE))
2252 if (check_remaining == 0)
2265 case EVENT_KEYRELEASE:
2266 key_joystick_mapping = 0;
2270 HandleOtherEvents(&event);
2275 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2278 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2279 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2280 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2281 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2283 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2284 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2285 setup.input[player_nr].joy.xright = new_joystick_xright;
2286 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2287 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2288 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2290 CheckJoystickData();
2292 joy_value = Joystick(player_nr);
2294 if (joy_value & JOY_BUTTON && check_remaining == 0)
2297 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2298 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2300 if (x != last_x || y != last_y)
2302 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
2303 DrawGraphic(xpos + x, ypos + y, GFX_KUGEL_ROT);
2308 if (check_remaining > 0 && !check[x+1][y+1])
2310 check[x+1][y+1] = TRUE;
2316 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2317 setup.input[player_nr].joy.xleft,
2318 setup.input[player_nr].joy.xmiddle,
2319 setup.input[player_nr].joy.xright);
2320 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2321 setup.input[player_nr].joy.yupper,
2322 setup.input[player_nr].joy.ymiddle,
2323 setup.input[player_nr].joy.ylower);
2332 /* don't eat all CPU time */
2336 /* calibrated center position (joystick should now be centered) */
2337 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2340 new_joystick_xmiddle = joy_x;
2341 new_joystick_ymiddle = joy_y;
2345 DrawSetupScreen_Input();
2347 /* wait until the last pressed button was released */
2348 while (Joystick(player_nr) & JOY_BUTTON)
2350 if (PendingEvent()) /* got event */
2355 HandleOtherEvents(&event);
2364 void CalibrateJoystick(int player_nr)
2366 if (!CalibrateJoystickMain(player_nr))
2370 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2371 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2373 Delay(2000); /* show error message for two seconds */
2377 void DrawSetupScreen()
2379 DeactivateJoystick();
2381 if (setup_mode == SETUP_MODE_INPUT)
2382 DrawSetupScreen_Input();
2383 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2384 DrawChooseTree(&artwork.gfx_current);
2385 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2386 DrawChooseTree(&artwork.snd_current);
2387 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2388 DrawChooseTree(&artwork.mus_current);
2390 DrawSetupScreen_Generic();
2393 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2395 if (setup_mode == SETUP_MODE_INPUT)
2396 HandleSetupScreen_Input(mx, my, dx, dy, button);
2397 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2398 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2399 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2400 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2401 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2402 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2404 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2407 void HandleGameActions()
2409 if (game_status != PLAYING)
2412 if (local_player->LevelSolved)
2415 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2423 /* ---------- new screen button stuff -------------------------------------- */
2425 /* graphic position and size values for buttons and scrollbars */
2426 #define SC_SCROLLBUTTON_XPOS 64
2427 #define SC_SCROLLBUTTON_YPOS 0
2428 #define SC_SCROLLBAR_XPOS 0
2429 #define SC_SCROLLBAR_YPOS 64
2431 #define SC_SCROLLBUTTON_XSIZE 32
2432 #define SC_SCROLLBUTTON_YSIZE 32
2434 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2435 #define SC_SCROLL_UP_YPOS SC_SCROLLBUTTON_YSIZE
2436 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2437 #define SC_SCROLL_DOWN_YPOS (SYSIZE - SC_SCROLLBUTTON_YSIZE)
2438 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2439 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + SC_SCROLLBUTTON_YSIZE)
2440 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2441 #define SC_SCROLL_VERTICAL_YSIZE (SYSIZE - 3 * SC_SCROLLBUTTON_YSIZE)
2443 #define SC_BORDER_SIZE 14
2451 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2454 SC_SCROLLBUTTON_XPOS + 0 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
2455 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2456 SCREEN_CTRL_ID_SCROLL_UP,
2460 SC_SCROLLBUTTON_XPOS + 1 * SC_SCROLLBUTTON_XSIZE, SC_SCROLLBUTTON_YPOS,
2461 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2462 SCREEN_CTRL_ID_SCROLL_DOWN,
2475 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2478 SC_SCROLLBAR_XPOS, SC_SCROLLBAR_YPOS,
2479 SX + SC_SCROLL_VERTICAL_XPOS, SY + SC_SCROLL_VERTICAL_YPOS,
2480 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2481 GD_TYPE_SCROLLBAR_VERTICAL,
2482 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2483 "scroll level series vertically"
2487 static void CreateScreenScrollbuttons()
2489 Bitmap *gd_bitmap = pix[PIX_MORE];
2490 struct GadgetInfo *gi;
2491 unsigned long event_mask;
2494 for (i=0; i<NUM_SCREEN_SCROLLBUTTONS; i++)
2496 int id = scrollbutton_info[i].gadget_id;
2497 int x, y, width, height;
2498 int gd_x1, gd_x2, gd_y1, gd_y2;
2500 x = scrollbutton_info[i].x;
2501 y = scrollbutton_info[i].y;
2503 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2507 width = SC_SCROLLBUTTON_XSIZE;
2508 height = SC_SCROLLBUTTON_YSIZE;
2509 gd_x1 = scrollbutton_info[i].xpos;
2510 gd_y1 = scrollbutton_info[i].ypos;
2512 gd_y2 = gd_y1 + SC_SCROLLBUTTON_YSIZE;
2514 gi = CreateGadget(GDI_CUSTOM_ID, id,
2515 GDI_CUSTOM_TYPE_ID, i,
2516 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2521 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2522 GDI_STATE, GD_BUTTON_UNPRESSED,
2523 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2524 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2525 GDI_EVENT_MASK, event_mask,
2526 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2530 Error(ERR_EXIT, "cannot create gadget");
2532 screen_gadget[id] = gi;
2536 static void CreateScreenScrollbars()
2540 for (i=0; i<NUM_SCREEN_SCROLLBARS; i++)
2542 int id = scrollbar_info[i].gadget_id;
2543 Bitmap *gd_bitmap = pix[PIX_MORE];
2544 int gd_x1, gd_x2, gd_y1, gd_y2;
2545 struct GadgetInfo *gi;
2546 int items_max, items_visible, item_position;
2547 unsigned long event_mask;
2548 int num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2551 if (num_leveldirs <= MAX_MENU_ENTRIES_ON_SCREEN)
2552 num_page_entries = num_leveldirs;
2554 num_page_entries = MAX_MENU_ENTRIES_ON_SCREEN - 1;
2556 items_max = MAX(num_leveldirs, num_page_entries);
2557 items_visible = num_page_entries;
2560 items_max = num_page_entries;
2561 items_visible = num_page_entries;
2565 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2567 gd_x1 = scrollbar_info[i].xpos;
2568 gd_x2 = gd_x1 + scrollbar_info[i].width;
2569 gd_y1 = scrollbar_info[i].ypos;
2570 gd_y2 = scrollbar_info[i].ypos;
2572 gi = CreateGadget(GDI_CUSTOM_ID, id,
2573 GDI_CUSTOM_TYPE_ID, i,
2574 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2575 GDI_X, scrollbar_info[i].x,
2576 GDI_Y, scrollbar_info[i].y,
2577 GDI_WIDTH, scrollbar_info[i].width,
2578 GDI_HEIGHT, scrollbar_info[i].height,
2579 GDI_TYPE, scrollbar_info[i].type,
2580 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2581 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2582 GDI_SCROLLBAR_ITEM_POSITION, item_position,
2583 GDI_STATE, GD_BUTTON_UNPRESSED,
2584 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2585 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2586 GDI_BORDER_SIZE, SC_BORDER_SIZE,
2587 GDI_EVENT_MASK, event_mask,
2588 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2592 Error(ERR_EXIT, "cannot create gadget");
2594 screen_gadget[id] = gi;
2598 void CreateScreenGadgets()
2600 CreateScreenScrollbuttons();
2601 CreateScreenScrollbars();
2604 void MapChooseTreeGadgets(TreeInfo *ti)
2606 int num_entries = numTreeInfoInGroup(ti);
2609 if (num_entries <= MAX_MENU_ENTRIES_ON_SCREEN)
2612 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2613 MapGadget(screen_gadget[i]);
2616 void UnmapChooseTreeGadgets()
2620 for (i=0; i<NUM_SCREEN_GADGETS; i++)
2621 UnmapGadget(screen_gadget[i]);
2624 static void HandleScreenGadgets(struct GadgetInfo *gi)
2626 int id = gi->custom_id;
2628 if (game_status != CHOOSELEVEL && game_status != SETUP)
2633 case SCREEN_CTRL_ID_SCROLL_UP:
2634 if (game_status == CHOOSELEVEL)
2635 HandleChooseLevel(SX,SY + 32, 0,0, MB_MENU_MARK);
2636 else if (game_status == SETUP)
2637 HandleSetupScreen(SX,SY + 32, 0,0, MB_MENU_MARK);
2640 case SCREEN_CTRL_ID_SCROLL_DOWN:
2641 if (game_status == CHOOSELEVEL)
2642 HandleChooseLevel(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
2643 else if (game_status == SETUP)
2644 HandleSetupScreen(SX,SY + SYSIZE - 32, 0,0, MB_MENU_MARK);
2647 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
2648 if (game_status == CHOOSELEVEL)
2649 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
2650 else if (game_status == SETUP)
2651 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);