rnd-19980930-1
[rocksndiamonds.git] / src / screens.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  (c) 1995-98 Artsoft Entertainment                       *
5 *              Holger Schemel                              *
6 *              Oststrasse 11a                              *
7 *              33604 Bielefeld                             *
8 *              phone: ++49 +521 290471                     *
9 *              email: aeglos@valinor.owl.de                *
10 *----------------------------------------------------------*
11 *  screens.c                                               *
12 ***********************************************************/
13
14 #include "screens.h"
15 #include "events.h"
16 #include "sound.h"
17 #include "game.h"
18 #include "tools.h"
19 #include "editor.h"
20 #include "misc.h"
21 #include "files.h"
22 #include "buttons.h"
23 #include "tape.h"
24 #include "joystick.h"
25 #include "cartoons.h"
26
27 #ifdef MSDOS
28 extern unsigned char get_ascii(KeySym);
29 #endif
30
31 void DrawHeadline()
32 {
33   int x1 = SX+(SXSIZE - strlen(GAMETITLE_STRING) * FONT1_XSIZE) / 2;
34   int y1 = SY+8;
35   int x2 = SX+(SXSIZE - strlen(COPYRIGHT_STRING) * FONT2_XSIZE) / 2;
36   int y2 = SY+46;
37
38   DrawText(x1,y1, GAMETITLE_STRING, FS_BIG,FC_YELLOW);
39   DrawText(x2,y2, COPYRIGHT_STRING, FS_SMALL,FC_RED);
40 }
41
42 void DrawMainMenu()
43 {
44   int i;
45
46   FadeSounds();
47   GetPlayerConfig();
48   LoadLevel(level_nr);
49
50   ClearWindow();
51   DrawHeadline();
52   DrawText(SX+32, SY+64, "Name:",FS_BIG,FC_GREEN);
53   DrawText(SX+192,SY+64, local_player->alias_name,FS_BIG,FC_RED);
54   DrawText(SX+32, SY+96, "Level:",FS_BIG,FC_GREEN);
55   DrawText(SX+352,SY+96, int2str(level_nr,3),FS_BIG,
56            (level_nr<leveldir[leveldir_nr].levels ? FC_RED : FC_YELLOW));
57   DrawText(SX+32, SY+128,"Hall Of Fame",FS_BIG,FC_GREEN);
58   DrawText(SX+32, SY+160,"Level Creator",FS_BIG,FC_GREEN);
59   DrawText(SY+32, SY+192,"Info Screen",FS_BIG,FC_GREEN);
60   DrawText(SX+32, SY+224,"Start Game",FS_BIG,FC_GREEN);
61   DrawText(SX+32, SY+256,"Setup",FS_BIG,FC_GREEN);
62   DrawText(SX+32, SY+288,"Quit",FS_BIG,FC_GREEN);
63
64   DrawMicroLevel(MICROLEV_XPOS,MICROLEV_YPOS);
65
66   for(i=2;i<10;i++)
67     DrawGraphic(0,i,GFX_KUGEL_BLAU);
68   DrawGraphic(10,3,GFX_PFEIL_L);
69   DrawGraphic(14,3,GFX_PFEIL_R);
70
71   DrawText(SX+40+16,SY+326,"A Game by Artsoft Entertainment",FS_SMALL,FC_BLUE);
72   DrawText(SX+40+16,SY+344,"Graphics: Deluxe Paint IV Amiga",
73            FS_SMALL,FC_BLUE);
74   DrawText(SX+60+16,SY+362,"Sounds: AudioMaster IV Amiga",
75            FS_SMALL,FC_BLUE);
76
77   FadeToFront();
78   InitAnimation();
79   HandleMainMenu(0,0,0,0,MB_MENU_INITIALIZE);
80
81   TapeStop();
82   if (TAPE_IS_EMPTY(tape))
83     LoadLevelTape(level_nr);
84   DrawCompleteVideoDisplay();
85
86   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
87
88   ClearEventQueue();
89   XAutoRepeatOn(display);
90 }
91
92 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
93 {
94   static int choice = 3;
95   static int redraw = TRUE;
96   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
97
98   if (redraw || button == MB_MENU_INITIALIZE)
99   {
100     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
101     redraw = FALSE;
102   }
103
104   if (button == MB_MENU_INITIALIZE)
105     return;
106
107   if (dx || dy)
108   {
109     if (dx && choice==4)
110     {
111       x = (dx<0 ? 11 : 15);
112       y = 4;
113     }
114     else if (dy)
115     {
116       x = 1;
117       y = choice+dy;
118     }
119     else
120       x = y = 0;
121
122     if (y<3)
123       y = 3;
124     else if (y>10)
125       y = 10;
126   }
127
128   if (!mx && !my && !dx && !dy)
129   {
130     x = 1;
131     y = choice;
132   }
133
134   if (y==4 && ((x==11 && level_nr>0) ||
135                (x==15 && level_nr<leveldir[leveldir_nr].levels)) &&
136       button)
137   {
138     static long level_delay = 0;
139     int step = (button==1 ? 1 : button==2 ? 5 : 10);
140     int new_level_nr, old_level_nr = level_nr;
141
142     new_level_nr = level_nr + (x==11 ? -step : +step);
143     if (new_level_nr<0)
144       new_level_nr = 0;
145     if (new_level_nr>leveldir[leveldir_nr].levels-1)
146       new_level_nr = leveldir[leveldir_nr].levels-1;
147
148     if (old_level_nr==new_level_nr || !DelayReached(&level_delay,150))
149       goto out;
150
151     level_nr = new_level_nr;
152
153     if (level_nr > local_player->handicap)
154       level_nr = local_player->handicap;
155
156     DrawTextExt(drawto,gc,SX+352,SY+96, int2str(level_nr,3), FS_BIG,FC_RED);
157     DrawTextExt(window,gc,SX+352,SY+96, int2str(level_nr,3), FS_BIG,FC_RED);
158
159     LoadLevel(level_nr);
160     DrawMicroLevel(MICROLEV_XPOS,MICROLEV_YPOS);
161
162     TapeErase();
163     LoadLevelTape(level_nr);
164     DrawCompleteVideoDisplay();
165
166     /* needed because DrawMicroLevel() takes some time */
167     BackToFront();
168     XSync(display,FALSE);
169     DelayReached(&level_delay,0);       /* reset delay counter */
170   }
171   else if (x==1 && y>=3 && y<=10)
172   {
173     if (button)
174     {
175       if (y!=choice)
176       {
177         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
178         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
179       }
180       choice = y;
181     }
182     else
183     {
184       if (y==3)
185       {
186         game_status = TYPENAME;
187         HandleTypeName(strlen(local_player->alias_name),0);
188       }
189       else if (y==4)
190       {
191         if (num_leveldirs)
192         {
193           game_status = CHOOSELEVEL;
194           SavePlayerInfo(PLAYER_LEVEL);
195           DrawChooseLevel();
196         }
197       }
198       else if (y==5)
199       {
200         game_status = HALLOFFAME;
201         DrawHallOfFame(-1);
202       }
203       else if (y==6)
204       {
205         game_status = LEVELED;
206         if (leveldir[leveldir_nr].readonly)
207           AreYouSure("This level is read only !",AYS_CONFIRM);
208         DrawLevelEd();
209       }
210       else if (y==7)
211       {
212         game_status = HELPSCREEN;
213         DrawHelpScreen();
214       }
215       else if (y==8)
216       {
217         if (autorecord_on)
218           TapeStartRecording();
219
220         game_status = PLAYING;
221         InitGame();
222       }
223       else if (y==9)
224       {
225         game_status = SETUP;
226         DrawSetupScreen();
227       }
228       else if (y==10)
229       {
230         SavePlayerInfo(PLAYER_LEVEL);
231         if (AreYouSure("Do you really want to quit ?",AYS_ASK|AYS_STAY_CLOSED))
232           game_status = EXITGAME;
233       }
234
235       if (!button)
236         redraw = TRUE;
237     }
238   }
239   BackToFront();
240
241   out:
242
243   if (game_status==MAINMENU)
244     DoAnimation();
245 }
246
247 #define MAX_HELPSCREEN_ELS      10
248 #define HA_NEXT                 -999
249 #define HA_END                  -1000
250
251 static long helpscreen_state;
252 static int helpscreen_step[MAX_HELPSCREEN_ELS];
253 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
254 static int helpscreen_delay[MAX_HELPSCREEN_ELS];
255 static int helpscreen_action[] =
256 {
257   GFX_SPIELER1_DOWN,4,2,
258   GFX_SPIELER1_UP,4,2,
259   GFX_SPIELER1_LEFT,4,2,
260   GFX_SPIELER1_RIGHT,4,2,
261   GFX_SPIELER1_PUSH_LEFT,4,2,
262   GFX_SPIELER1_PUSH_RIGHT,4,2,                                  HA_NEXT,
263   GFX_ERDREICH,1,100,                                           HA_NEXT,
264   GFX_LEERRAUM,1,100,                                           HA_NEXT,
265   GFX_MORAST_LEER,1,100,                                        HA_NEXT,
266   GFX_BETON,1,100,                                              HA_NEXT,
267   GFX_MAUERWERK,1,100,                                          HA_NEXT,
268   GFX_MAUER_R1,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
269   GFX_MAUER_L1,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,      HA_NEXT,
270   GFX_UNSICHTBAR,1,100,                                         HA_NEXT,
271   GFX_FELSBODEN,1,100,                                          HA_NEXT,
272   GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4,                        HA_NEXT,
273   GFX_EDELSTEIN,2,5,                                            HA_NEXT,
274   GFX_DIAMANT,2,5,                                              HA_NEXT,
275   GFX_EDELSTEIN_BD,2,5,                                         HA_NEXT,
276   GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
277   GFX_EDELSTEIN_LILA,2,5,                                       HA_NEXT,
278   GFX_FELSBROCKEN,4,5,                                          HA_NEXT,
279   GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10,         HA_NEXT,
280   GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10,  HA_NEXT,
281   GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10,     HA_NEXT,
282   GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10,       HA_NEXT,
283   GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
284   GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
285   GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
286   GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
287   GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
288   GFX_EDELSTEIN_LILA,1,10,                                      HA_NEXT,
289   GFX_GEBLUBBER,4,4,                                            HA_NEXT,
290   GFX_SCHLUESSEL1,4,25,                                         HA_NEXT,
291   GFX_PFORTE1,4,25,                                             HA_NEXT,
292   GFX_PFORTE1X,4,25,                                            HA_NEXT,
293   GFX_DYNAMIT_AUS,1,100,                                        HA_NEXT,
294   GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10,        HA_NEXT,
295   GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
296   GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
297   GFX_LEERRAUM,1,10,                                            HA_NEXT,
298   GFX_DYNABOMB_NR,1,100,                                        HA_NEXT,
299   GFX_DYNABOMB_SZ,1,100,                                        HA_NEXT,
300   GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
301   GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
302   GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
303   GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3,      HA_NEXT,
304   GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
305   GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
306   GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
307   GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1,         HA_NEXT,
308   GFX_BUTTERFLY,2,2,                                            HA_NEXT,
309   GFX_FIREFLY,2,2,                                              HA_NEXT,
310   GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
311   GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
312   GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
313   GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3,         HA_NEXT,
314   GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
315   GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1,                         HA_NEXT,
316   GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
317   GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1,                       HA_NEXT,
318   GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
319   GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1,                             HA_NEXT,
320   GFX_MAULWURF_DOWN,4,2,
321   GFX_MAULWURF_UP,4,2,
322   GFX_MAULWURF_LEFT,4,2,
323   GFX_MAULWURF_RIGHT,4,2,                                       HA_NEXT,
324   GFX_PINGUIN_DOWN,4,2,
325   GFX_PINGUIN_UP,4,2,
326   GFX_PINGUIN_LEFT,4,2,
327   GFX_PINGUIN_RIGHT,4,2,                                        HA_NEXT,
328   GFX_SCHWEIN_DOWN,4,2,
329   GFX_SCHWEIN_UP,4,2,
330   GFX_SCHWEIN_LEFT,4,2,
331   GFX_SCHWEIN_RIGHT,4,2,                                        HA_NEXT,
332   GFX_DRACHE_DOWN,4,2,
333   GFX_DRACHE_UP,4,2,
334   GFX_DRACHE_LEFT,4,2,
335   GFX_DRACHE_RIGHT,4,2,                                         HA_NEXT,
336   GFX_SONDE_START,8,1,                                          HA_NEXT,
337   GFX_ABLENK,4,1,                                               HA_NEXT,
338   GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25,                       HA_NEXT,
339   GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25,                       HA_NEXT,
340   GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10,     HA_NEXT,
341   GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50,                   HA_NEXT,
342   GFX_AMOEBE_LEBT,4,40,                                         HA_NEXT,
343   GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2,                       HA_NEXT,
344   GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
345   GFX_DIAMANT,1,10,                                             HA_NEXT,
346   GFX_LIFE,1,100,                                               HA_NEXT,
347   GFX_LIFE_ASYNC,1,100,                                         HA_NEXT,
348   GFX_SIEB_LEER,4,2,                                            HA_NEXT,
349   GFX_SIEB2_LEER,4,2,                                           HA_NEXT,
350   GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
351   GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
352   GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2,                 HA_NEXT,
353   GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
354   GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2,                 HA_NEXT,
355   HA_END
356 };
357 static char *helpscreen_eltext[][2] =
358 {
359  {"THE HERO:",                          "(Is _this_ guy good old Rockford?)"},
360  {"Normal sand:",                       "You can dig through it"},
361  {"Empty field:",                       "You can walk through it"},
362  {"Quicksand: You cannot pass it,",     "but rocks can fall though it"},
363  {"Massive Wall:",                      "Nothing can go through it"},
364  {"Normal Wall: You can't go through",  "it, but you can bomb it away"},
365  {"Growing Wall: Grows to the left or", "right if there is an empty field"},
366  {"Invisible Wall: Behaves like normal","wall, but is invisible"},
367  {"Old Wall: Like normal wall, but",    "some things can fall down from it"},
368  {"Letter Wall: Looks like a letter,",  "behaves like a normal wall"},
369  {"Emerald: You must collect enough of","them to finish a level"},
370  {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
371  {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
372  {"Colorful Gems:",                     "Seem to behave like Emeralds"},
373  {"Rock: Smashes several things;",      "Can be moved by the player"},
374  {"Bomb: You can move it, but be",      "careful when dropping it"},
375  {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
376  {"Wall with an emerald inside:",       "Bomb the wall away to get it"},
377  {"Wall with a diamond inside:",        "Bomb the wall away to get it"},
378  {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
379  {"Wall with colorful gem inside:",     "Bomb the wall away to get it"},
380  {"Acid: Things that fall in are gone", "forever (including our hero)"},
381  {"Key: Opens the door that has the",   "same color (red/yellow/green/blue)"},
382  {"Door: Can be opened by the key",     "with the same color"},
383  {"Door: You have to find out the",     "right color of the key for it"},
384  {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
385  {"Dynamite: This one explodes after",  "a few seconds"},
386  {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
387  {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
388  {"Dyna Bomb: Increases the size of",   "explosion of dyna bombs"},
389  {"Spaceship: Moves at the left side",  "of walls; don't touch it!"},
390  {"Bug: Moves at the right side",       "of walls; don't touch it!"},
391  {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
392  {"Firefly: Moves at the left side",    "of walls; don't touch it!"},
393  {"Pacman: Eats the amoeba and you,",   "if you're not careful"},
394  {"Cruncher: Eats diamonds and you,",   "if you're not careful"},
395  {"Cruncher (BD style):",               "Eats almost everything"},
396  {"Robot: Tries to kill the player",    ""},
397  {"The mole: You must guide him savely","to the exit; he will follow you"},
398  {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
399  {"The Pig: Harmless, but eats all",    "gems it can get"},
400  {"The Dragon: Breathes fire,",         "especially to some monsters"},
401  {"Sonde: Follows you everywhere;",     "harmless, but may block your way"},
402  {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
403  {"Light Bulb: All of them must be",    "switched on to finish a level"},
404  {"Extra Time Orb: Adds some seconds",  "to the time available for the level"},
405  {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
406  {"Dead Amoeba: Does not grow, but",    "can still kill bugs and spaceships"},
407  {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
408  {"Dropping Amoeba: This one makes",    "drops that grow to a new amoeba"},
409  {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
410  {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
411  {"Biomaze: A bit like the 'Game Of",   "Life', but builds crazy mazes"},
412  {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
413  {"Magic Wall (BD style):",             "Changes rocks and BD style diamonds"},
414  {"Exit door: Opens if you have enough","emeralds to finish the level"},
415  {"Open exit door: Enter here to leave","the level and exit the actual game"},
416 };
417 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
418
419 static char *helpscreen_music[][3] =
420 {
421   { "Alchemy",                  "Ian Boddy",            "Drive" },
422   { "The Chase",                "Propaganda",           "A Secret Wish" },
423   { "Network 23",               "Tangerine Dream",      "Exit" },
424   { "Czardasz",                 "Robert Pieculewicz",   "Czardasz" },
425   { "21st Century Common Man",  "Tangerine Dream",      "Tyger" },
426   { "Voyager",                  "The Alan Parsons Project","Pyramid" },
427   { "Twilight Painter",         "Tangerine Dream",      "Heartbreakers" }
428 };
429 static int helpscreen_musicpos;
430
431 void DrawHelpScreenElAction(int start)
432 {
433   int i = 0, j = 0;
434   int frame, graphic;
435   int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
436
437   while(helpscreen_action[j] != HA_END)
438   {
439     if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
440       break;
441     else if (i<start || helpscreen_delay[i-start])
442     {
443       if (i>=start && helpscreen_delay[i-start])
444         helpscreen_delay[i-start]--;
445
446       while(helpscreen_action[j] != HA_NEXT)
447         j++;
448       j++;
449       i++;
450       continue;
451     }
452
453     j += 3*helpscreen_step[i-start];
454     graphic = helpscreen_action[j++];
455
456     if (helpscreen_frame[i-start])
457     {
458       frame = helpscreen_action[j++] - helpscreen_frame[i-start];
459       helpscreen_frame[i-start]--;
460     }
461     else
462     {
463       frame = 0;
464       helpscreen_frame[i-start] = helpscreen_action[j++]-1;
465     }
466
467     helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
468
469     if (helpscreen_action[j] == HA_NEXT)
470     {
471       if (!helpscreen_frame[i-start])
472         helpscreen_step[i-start] = 0;
473     }
474     else
475     {
476       if (!helpscreen_frame[i-start])
477         helpscreen_step[i-start]++;
478       while(helpscreen_action[j] != HA_NEXT)
479         j++;
480     }
481     j++;
482
483     DrawGraphicExt(drawto, gc, xstart, ystart+(i-start)*ystep, graphic+frame);
484     i++;
485   }
486
487   for(i=2;i<16;i++)
488   {
489     MarkTileDirty(0,i);
490     MarkTileDirty(1,i);
491   }
492 }
493
494 void DrawHelpScreenElText(int start)
495 {
496   int i;
497   int xstart = SX+56, ystart = SY+65+2*32, ystep = TILEY+4;
498   char text[FULL_SXSIZE/FONT2_XSIZE+10];
499
500   ClearWindow();
501   DrawHeadline();
502
503   sprintf(text,"The game elements:");
504   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
505            text,FS_SMALL,FC_GREEN);
506
507   for(i=start;i<start+MAX_HELPSCREEN_ELS && i<num_helpscreen_els;i++)
508   {
509     DrawText(xstart,ystart+(i-start)*ystep+(*helpscreen_eltext[i][1] ? 0 : 8),
510              helpscreen_eltext[i][0],FS_SMALL,FC_YELLOW);
511     DrawText(xstart,ystart+(i-start)*ystep+16,
512              helpscreen_eltext[i][1],FS_SMALL,FC_YELLOW);
513   }
514
515   sprintf(text,"Press any key or button for next page");
516   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
517            text,FS_SMALL,FC_BLUE);
518 }
519
520 void DrawHelpScreenMusicText(int num)
521 {
522   int ystart = 150, ystep = 30;
523   char text[FULL_SXSIZE/FONT2_XSIZE+10];
524
525   FadeSounds();
526   ClearWindow();
527   DrawHeadline();
528
529   sprintf(text,"The game background music loops:");
530   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
531            text,FS_SMALL,FC_GREEN);
532
533   sprintf(text,"Excerpt from");
534   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+0*ystep,
535            text,FS_SMALL,FC_YELLOW);
536   sprintf(text,"%c%s%c",'\"',helpscreen_music[num][0],'\"');
537   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+1*ystep,
538            text,FS_SMALL,FC_RED);
539   sprintf(text,"by");
540   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+2*ystep,
541            text,FS_SMALL,FC_YELLOW);
542   sprintf(text,"%s",helpscreen_music[num][1]);
543   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+3*ystep,
544            text,FS_SMALL,FC_RED);
545   sprintf(text,"from the album");
546   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep,
547            text,FS_SMALL,FC_YELLOW);
548   sprintf(text,"%c%s%c",'\"',helpscreen_music[num][2],'\"');
549   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+5*ystep,
550            text,FS_SMALL,FC_RED);
551
552   sprintf(text,"Press any key or button for next page");
553   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
554            text,FS_SMALL,FC_BLUE);
555
556   PlaySoundLoop(background_loop[num]);
557 }
558
559 void DrawHelpScreenCreditsText()
560 {
561   int ystart = 150, ystep = 30;
562   char text[FULL_SXSIZE/FONT2_XSIZE+10];
563
564   FadeSounds();
565   ClearWindow();
566   DrawHeadline();
567
568   sprintf(text,"Program information:");
569   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
570            text,FS_SMALL,FC_GREEN);
571
572   sprintf(text,"This game is Freeware!");
573   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+0*ystep,
574            text,FS_SMALL,FC_YELLOW);
575   sprintf(text,"If you like it, send e-mail to:");
576   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+1*ystep,
577            text,FS_SMALL,FC_YELLOW);
578   sprintf(text,"aeglos@valinor.owl.de");
579   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+2*ystep,
580            text,FS_SMALL,FC_RED);
581   sprintf(text,"or SnailMail to:");
582   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+3*ystep,
583            text,FS_SMALL,FC_YELLOW);
584   sprintf(text,"Holger Schemel");
585   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep,
586            text,FS_SMALL,FC_RED);
587   sprintf(text,"Sennehof 28");
588   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep+20,
589            text,FS_SMALL,FC_RED);
590   sprintf(text,"33659 Bielefeld");
591   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep+40,
592            text,FS_SMALL,FC_RED);
593   sprintf(text,"Germany");
594   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep+60,
595            text,FS_SMALL,FC_RED);
596
597   sprintf(text,"If you have created new levels,");
598   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+7*ystep,
599            text,FS_SMALL,FC_YELLOW);
600   sprintf(text,"send them to me to include them!");
601   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+8*ystep,
602            text,FS_SMALL,FC_YELLOW);
603   sprintf(text,":-)");
604   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+9*ystep,
605            text,FS_SMALL,FC_YELLOW);
606
607   sprintf(text,"Press any key or button for main menu");
608   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
609            text,FS_SMALL,FC_BLUE);
610 }
611
612 void DrawHelpScreen()
613 {
614   int i;
615
616   CloseDoor(DOOR_CLOSE_2);
617
618   for(i=0;i<MAX_HELPSCREEN_ELS;i++)
619     helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
620   helpscreen_musicpos = 0;
621   helpscreen_state = 0;
622   DrawHelpScreenElText(0);
623   DrawHelpScreenElAction(0);
624
625   FadeToFront();
626   InitAnimation();
627   PlaySoundLoop(SND_RHYTHMLOOP);
628 }
629
630 void HandleHelpScreen(int button)
631 {
632   static long hs_delay = 0;
633   int num_helpscreen_els_pages =
634     (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
635   int button_released = !button;
636   int i;
637
638   if (button_released)
639   {
640     if (helpscreen_state<num_helpscreen_els_pages-1)
641     {
642       for(i=0;i<MAX_HELPSCREEN_ELS;i++)
643         helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
644       helpscreen_state++;
645       DrawHelpScreenElText(helpscreen_state*MAX_HELPSCREEN_ELS);
646       DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
647     }
648     else if (helpscreen_state<num_helpscreen_els_pages+num_bg_loops-1)
649     {
650       helpscreen_state++;
651       DrawHelpScreenMusicText(helpscreen_state-num_helpscreen_els_pages);
652     }
653     else if (helpscreen_state==num_helpscreen_els_pages+num_bg_loops-1)
654     {
655       helpscreen_state++;
656       DrawHelpScreenCreditsText();
657     }
658     else
659     {
660       FadeSounds();
661       DrawMainMenu();
662       game_status = MAINMENU;
663     }
664   }
665   else
666   {
667     if (DelayReached(&hs_delay,GAME_FRAME_DELAY * 2))
668     {
669       if (helpscreen_state<num_helpscreen_els_pages)
670         DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
671     }
672     DoAnimation();
673   }
674
675   BackToFront();
676 }
677
678 void CheckCheat()
679 {
680   int old_handicap = local_player->handicap;
681
682   if (!strcmp(local_player->alias_name,"Artsoft"))
683     local_player->handicap = leveldir[leveldir_nr].levels-1;
684
685   if (local_player->handicap != old_handicap)
686   {
687     SavePlayerInfo(PLAYER_LEVEL);
688     level_nr = local_player->handicap;
689   }
690 }
691
692 void HandleTypeName(int newxpos, KeySym key)
693 {
694   static int xpos = 0, ypos = 2;
695   unsigned char ascii;
696
697   if (newxpos)
698   {
699     xpos = newxpos;
700     DrawText(SX+6*32, SY+ypos*32, local_player->alias_name, FS_BIG, FC_YELLOW);
701     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
702     return;
703   }
704
705 #ifndef MSDOS
706   if ((key>=XK_A && key<=XK_Z) || (key>=XK_a && key<=XK_z && 
707       xpos<MAX_NAMELEN-1))
708   {
709     if (key>=XK_A && key<=XK_Z)
710       ascii = 'A'+(char)(key-XK_A);
711     if (key>=XK_a && key<=XK_z)
712       ascii = 'a'+(char)(key-XK_a);
713 #else
714   if((ascii = get_ascii(key)) && xpos<MAX_NAMELEN-1)
715   {
716 #endif
717     local_player->alias_name[xpos] = ascii;
718     local_player->alias_name[xpos+1] = 0;
719     xpos++;
720     DrawTextExt(drawto,gc,SX+6*32,SY+ypos*32,
721                 local_player->alias_name,FS_BIG,FC_YELLOW);
722     DrawTextExt(window,gc,SX+6*32,SY+ypos*32,
723                 local_player->alias_name,FS_BIG,FC_YELLOW);
724     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
725   }
726   else if ((key==XK_Delete || key==XK_BackSpace) && xpos>0)
727   {
728     xpos--;
729     local_player->alias_name[xpos] = 0;
730     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
731     DrawGraphic(xpos+7,ypos,GFX_LEERRAUM);
732   }
733   else if (key==XK_Return && xpos>0)
734   {
735     DrawText(SX+6*32,SY+ypos*32,local_player->alias_name,FS_BIG,FC_RED);
736     DrawGraphic(xpos+6,ypos,GFX_LEERRAUM);
737     SavePlayerInfo(PLAYER_SETUP);
738     CheckCheat();
739
740     game_status = MAINMENU;
741 /*
742     DrawMainMenu();
743 */
744
745   }
746   BackToFront();
747 }
748
749 void DrawChooseLevel()
750 {
751   int i;
752
753   CloseDoor(DOOR_CLOSE_2);
754
755   ClearWindow();
756   DrawText(SX,SY,"Level Directories",FS_BIG,FC_GREEN);
757   for(i=0;i<num_leveldirs;i++)
758   {
759     DrawText(SX+32,SY+(i+2)*32,leveldir[i].name,FS_BIG,FC_YELLOW);
760     DrawGraphic(0,i+2,GFX_KUGEL_BLAU);
761   }
762
763   FadeToFront();
764   InitAnimation();
765   HandleChooseLevel(0,0,0,0,MB_MENU_INITIALIZE);
766 }
767
768 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
769 {
770   static int choice = 3;
771   static int redraw = TRUE;
772   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
773
774   if (button == MB_MENU_INITIALIZE)
775   {
776     redraw = TRUE;
777     choice = leveldir_nr + 3;
778   }
779
780   if (redraw)
781   {
782     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
783     redraw = FALSE;
784   }
785
786   if (button == MB_MENU_INITIALIZE)
787     return;
788
789   if (dx || dy)
790   {
791     if (dy)
792     {
793       x = 1;
794       y = choice+dy;
795     }
796     else
797       x = y = 0;
798
799     if (y<3)
800       y = 3;
801     else if (y>num_leveldirs+2)
802       y = num_leveldirs+2;
803   }
804
805   if (!mx && !my && !dx && !dy)
806   {
807     x = 1;
808     y = choice;
809   }
810
811   if (x==1 && y>=3 && y<=num_leveldirs+2)
812   {
813     if (button)
814     {
815       if (y!=choice)
816       {
817         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
818         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
819       }
820       choice = y;
821     }
822     else
823     {
824       local_player->leveldir_nr = leveldir_nr = y-3;
825       LoadPlayerInfo(PLAYER_LEVEL);
826       SavePlayerInfo(PLAYER_SETUP);
827       CheckCheat();
828
829       TapeErase();
830       LoadLevelTape(level_nr);
831
832       game_status = MAINMENU;
833       DrawMainMenu();
834       redraw = TRUE;
835     }
836   }
837   BackToFront();
838
839   if (game_status==CHOOSELEVEL)
840     DoAnimation();
841 }
842
843 void DrawHallOfFame(int pos)
844 {
845   int y;
846   char txt[40];
847
848   CloseDoor(DOOR_CLOSE_2);
849
850   if (pos<0) 
851     LoadScore(level_nr);
852   ClearWindow();
853   DrawText(SX+64,SY+10,"Hall Of Fame",FS_BIG,FC_YELLOW);
854   sprintf(txt,"HighScores of Level %d",level_nr);
855   DrawText(SX+256-strlen(txt)*7,SY+48,txt,FS_SMALL,FC_RED);
856   for(y=0;y<MAX_SCORE_ENTRIES;y++)
857   {
858     DrawText(SX,SY+64+y*32,".................",FS_BIG,
859              (y==pos ? FC_RED : FC_GREEN));
860     DrawText(SX,SY+64+y*32,highscore[y].Name,FS_BIG,
861              (y==pos ? FC_RED : FC_GREEN));
862     DrawText(SX+12*32,SY+64+y*32,
863              int2str(highscore[y].Score,5),FS_BIG,
864              (y==pos ? FC_RED : FC_GREEN));
865   }
866
867   FadeToFront();
868   InitAnimation();
869   PlaySound(SND_HALLOFFAME);
870 }
871
872 void HandleHallOfFame(int button)
873 {
874   int button_released = !button;
875
876   if (button_released)
877   {
878     FadeSound(SND_HALLOFFAME);
879     game_status = MAINMENU;
880     DrawMainMenu();
881     BackToFront();
882   }
883   else
884     DoAnimation();
885 }
886
887 void DrawSetupScreen()
888 {
889   int i;
890   static struct setup
891   {
892     unsigned int bit;
893     char *text, *mode[2];
894     int color[2];
895   } setup[] =
896   {
897     {SETUP_SOUND,       "Sound:",       {"on", "off"},  {FC_YELLOW,FC_BLUE}},
898     {SETUP_SOUND_LOOPS, " Sound Loops:",{"on", "off"},  {FC_YELLOW,FC_BLUE}},
899     {SETUP_SOUND_MUSIC, " Game Music:", {"on", "off"},  {FC_YELLOW,FC_BLUE}},
900     {SETUP_TOONS,       "Toons:",       {"on", "off"},  {FC_YELLOW,FC_BLUE}},
901     {SETUP_DIRECT_DRAW, "Buffered gfx:",{"off","on" },  {FC_BLUE,FC_YELLOW}},
902     {SETUP_SCROLL_DELAY,"Scroll Delay:",{"on", "off"},  {FC_YELLOW,FC_BLUE}},
903     {SETUP_SOFT_SCROLL, "Soft Scroll.:",{"on", "off"},  {FC_YELLOW,FC_BLUE}},
904     {SETUP_FADING,      "Fading:",      {"on", "off"},  {FC_YELLOW,FC_BLUE}},
905     {SETUP_QUICK_DOORS, "Quick Doors:", {"on", "off"},  {FC_YELLOW,FC_BLUE}},
906     {SETUP_AUTO_RECORD, "Auto-Record:", {"on", "off"},  {FC_YELLOW,FC_BLUE}},
907     {SETUP_2ND_JOYSTICK,"Joystick:",    {"2nd","1st"},  {FC_YELLOW,FC_YELLOW}},
908     {0,                 "Cal. Joystick",{"",   ""},     {0,0}},
909     {0,                 "",             {"",   ""},     {0,0}},
910     {0,                 "Exit",         {"",   ""},     {0,0}},
911     {0,                 "Save and exit",{"",   ""},     {0,0}}
912   };
913
914   CloseDoor(DOOR_CLOSE_2);
915   ClearWindow();
916   DrawText(SX+16, SY+16,  "SETUP",FS_BIG,FC_YELLOW);
917
918   for(i=SETUP_SCREEN_POS_START;i<=SETUP_SCREEN_POS_END;i++)
919   {
920     int base = i - SETUP_SCREEN_POS_START;
921
922     if (i != SETUP_SCREEN_POS_EMPTY)
923     {
924       DrawGraphic(0,i,GFX_KUGEL_BLAU);
925       DrawText(SX+32,SY+i*32, setup[base].text, FS_BIG,FC_GREEN);
926     }
927
928     if (i < SETUP_SCREEN_POS_EMPTY)
929     {
930       int setting_bit = setup[base].bit;
931       int setting_pos = ((local_player->setup & setting_bit) != 0 ? 0 : 1);
932       DrawText(SX+14*32, SY+i*32,setup[base].mode[setting_pos],
933                FS_BIG,setup[base].color[setting_pos]);
934     }
935   }
936
937   FadeToFront();
938   InitAnimation();
939   HandleSetupScreen(0,0,0,0,MB_MENU_INITIALIZE);
940 }
941
942 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
943 {
944   static int choice = 3;
945   static int redraw = TRUE;
946   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
947   int pos_start = SETUP_SCREEN_POS_START + 1;
948   int pos_empty = SETUP_SCREEN_POS_EMPTY + 1;
949   int pos_end   = SETUP_SCREEN_POS_END   + 1;
950
951   if (button == MB_MENU_INITIALIZE)
952     redraw = TRUE;
953
954   if (redraw)
955   {
956     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
957     redraw = FALSE;
958   }
959
960   if (button == MB_MENU_INITIALIZE)
961     return;
962
963   if (dx || dy)
964   {
965     if (dy)
966     {
967       x = 1;
968       y = choice+dy;
969     }
970     else
971       x = y = 0;
972
973     if (y == pos_empty)
974       y = (dy>0 ? pos_empty+1 : pos_empty-1);
975
976     if (y < pos_start)
977       y = pos_start;
978     else if (y > pos_end)
979       y = pos_end;
980   }
981
982   if (!mx && !my && !dx && !dy)
983   {
984     x = 1;
985     y = choice;
986   }
987
988   if (x==1 && y>=pos_start && y<=pos_end && y!=pos_empty)
989   {
990     if (button)
991     {
992       if (y!=choice)
993       {
994         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
995         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
996       }
997       choice = y;
998     }
999     else
1000     {
1001       int yy = y-1;
1002
1003       if (y==3 && sound_status==SOUND_AVAILABLE)
1004       {
1005         if (SETUP_SOUND_ON(local_player->setup))
1006         {
1007           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1008           DrawText(SX+14*32, SY+(yy+1)*32,"off",FS_BIG,FC_BLUE);
1009           DrawText(SX+14*32, SY+(yy+2)*32,"off",FS_BIG,FC_BLUE);
1010           local_player->setup &= ~SETUP_SOUND_LOOPS;
1011           local_player->setup &= ~SETUP_SOUND_MUSIC;
1012         }
1013         else
1014           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1015         local_player->setup ^= SETUP_SOUND;
1016       }
1017       else if (y==4 && sound_loops_allowed)
1018       {
1019         if (SETUP_SOUND_LOOPS_ON(local_player->setup))
1020           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1021         else
1022         {
1023           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1024           DrawText(SX+14*32, SY+(yy-1)*32,"on ",FS_BIG,FC_YELLOW);
1025           local_player->setup |= SETUP_SOUND;
1026         }
1027         local_player->setup ^= SETUP_SOUND_LOOPS;
1028       }
1029       else if (y==5 && sound_loops_allowed)
1030       {
1031         if (SETUP_SOUND_MUSIC_ON(local_player->setup))
1032           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1033         else
1034         {
1035           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1036           DrawText(SX+14*32, SY+(yy-2)*32,"on ",FS_BIG,FC_YELLOW);
1037           local_player->setup |= SETUP_SOUND;
1038         }
1039         local_player->setup ^= SETUP_SOUND_MUSIC;
1040       }
1041       else if (y==6)
1042       {
1043         if (SETUP_TOONS_ON(local_player->setup))
1044           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1045         else
1046           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1047         local_player->setup ^= SETUP_TOONS;
1048       }
1049       else if (y==7)
1050       {
1051         if (!SETUP_DIRECT_DRAW_ON(local_player->setup))
1052           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1053         else
1054           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1055         local_player->setup ^= SETUP_DIRECT_DRAW;
1056       }
1057       else if (y==8)
1058       {
1059         if (SETUP_SCROLL_DELAY_ON(local_player->setup))
1060           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1061         else
1062           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1063         local_player->setup ^= SETUP_SCROLL_DELAY;
1064       }
1065       else if (y==9)
1066       {
1067         if (SETUP_SOFT_SCROLL_ON(local_player->setup))
1068           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1069         else
1070           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1071         local_player->setup ^= SETUP_SOFT_SCROLL;
1072       }
1073       else if (y==10)
1074       {
1075         if (SETUP_FADING_ON(local_player->setup))
1076           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1077         else
1078           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1079         local_player->setup ^= SETUP_FADING;
1080       }
1081       else if (y==11)
1082       {
1083         if (SETUP_QUICK_DOORS_ON(local_player->setup))
1084           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1085         else
1086           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1087         local_player->setup ^= SETUP_QUICK_DOORS;
1088       }
1089       else if (y==12)
1090       {
1091         if (SETUP_AUTO_RECORD_ON(local_player->setup))
1092           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1093         else
1094           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1095         local_player->setup ^= SETUP_AUTO_RECORD;
1096       }
1097       else if (y==13)
1098       {
1099         if (SETUP_2ND_JOYSTICK_ON(local_player->setup))
1100           DrawText(SX+14*32, SY+yy*32,"1st",FS_BIG,FC_YELLOW);
1101         else
1102           DrawText(SX+14*32, SY+yy*32,"2nd",FS_BIG,FC_YELLOW);
1103         local_player->setup ^= SETUP_2ND_JOYSTICK;
1104       }
1105       else if (y==14)
1106       {
1107         CalibrateJoystick();
1108         redraw = TRUE;
1109       }
1110       else if (y==pos_end-1 || y==pos_end)
1111       {
1112         if (y==pos_end)
1113         {
1114           SavePlayerInfo(PLAYER_SETUP);
1115           SaveJoystickData();
1116         }
1117
1118         game_status = MAINMENU;
1119         DrawMainMenu();
1120         redraw = TRUE;
1121       }
1122     }
1123   }
1124   BackToFront();
1125
1126   if (game_status==SETUP)
1127     DoAnimation();
1128 }
1129
1130 void CalibrateJoystick()
1131 {
1132 #ifdef __FreeBSD__
1133   struct joystick joy_ctrl;
1134 #else
1135   struct joystick_control
1136   {
1137     int buttons;
1138     int x;
1139     int y;
1140   } joy_ctrl;
1141 #endif
1142
1143 #ifdef MSDOS
1144   char joy_nr[4];
1145 #endif
1146
1147   int new_joystick_xleft, new_joystick_xright, new_joystick_xmiddle;
1148   int new_joystick_yupper, new_joystick_ylower, new_joystick_ymiddle;
1149
1150   if (joystick_status==JOYSTICK_OFF)
1151     goto error_out;
1152
1153 #ifndef MSDOS
1154   ClearWindow();
1155   DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW);
1156   DrawText(SX+16, SY+8*32, " THE UPPER LEFT ",FS_BIG,FC_YELLOW);
1157   DrawText(SX+16, SY+9*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW);
1158   BackToFront();
1159
1160 #ifdef __FreeBSD__
1161   joy_ctrl.b1 = joy_ctrl.b2 = 0;
1162 #else
1163   joy_ctrl.buttons = 0;
1164 #endif
1165   while(Joystick() & JOY_BUTTON);
1166 #ifdef __FreeBSD__
1167   while(!(joy_ctrl.b1||joy_ctrl.b2))
1168 #else
1169   while(!joy_ctrl.buttons)
1170 #endif
1171   {
1172     if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
1173     {
1174       joystick_status=JOYSTICK_OFF;
1175       goto error_out;
1176     }
1177     Delay(10);
1178   }
1179
1180   new_joystick_xleft = joy_ctrl.x;
1181   new_joystick_yupper = joy_ctrl.y;
1182
1183   ClearWindow();
1184   DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW);
1185   DrawText(SX+32, SY+8*32, "THE LOWER RIGHT",FS_BIG,FC_YELLOW);
1186   DrawText(SX+16, SY+9*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW);
1187   BackToFront();
1188
1189 #ifdef __FreeBSD__
1190   joy_ctrl.b1 = joy_ctrl.b2 = 0;
1191 #else
1192   joy_ctrl.buttons = 0;
1193 #endif
1194   while(Joystick() & JOY_BUTTON);
1195 #ifdef __FreeBSD__
1196   while(!(joy_ctrl.b1||joy_ctrl.b2))
1197 #else
1198   while(!joy_ctrl.buttons)
1199 #endif
1200   {
1201     if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
1202     {
1203       joystick_status=JOYSTICK_OFF;
1204       goto error_out;
1205     }
1206     Delay(10);
1207   }
1208
1209   new_joystick_xright = joy_ctrl.x;
1210   new_joystick_ylower = joy_ctrl.y;
1211
1212   ClearWindow();
1213   DrawText(SX+32, SY+16+7*32, "CENTER JOYSTICK",FS_BIG,FC_YELLOW);
1214   DrawText(SX+16, SY+16+8*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW);
1215   BackToFront();
1216
1217 #ifdef __FreeBSD__
1218   joy_ctrl.b1 = joy_ctrl.b2 = 0;
1219 #else
1220   joy_ctrl.buttons = 0;
1221 #endif
1222   while(Joystick() & JOY_BUTTON);
1223 #ifdef __FreeBSD__
1224   while(!(joy_ctrl.b1||joy_ctrl.b2))
1225 #else
1226   while(!joy_ctrl.buttons)
1227 #endif
1228   {
1229     if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
1230     {
1231       joystick_status=JOYSTICK_OFF;
1232       goto error_out;
1233     }
1234     Delay(10);
1235   }
1236
1237   new_joystick_xmiddle = joy_ctrl.x;
1238   new_joystick_ymiddle = joy_ctrl.y;
1239
1240   joystick[joystick_nr].xleft = new_joystick_xleft;
1241   joystick[joystick_nr].yupper = new_joystick_yupper;
1242   joystick[joystick_nr].xright = new_joystick_xright;
1243   joystick[joystick_nr].ylower = new_joystick_ylower;
1244   joystick[joystick_nr].xmiddle = new_joystick_xmiddle;
1245   joystick[joystick_nr].ymiddle = new_joystick_ymiddle;
1246
1247   CheckJoystickData();
1248
1249   DrawSetupScreen();
1250   while(Joystick() & JOY_BUTTON);
1251   return;
1252
1253 #endif
1254   error_out:
1255
1256 #ifdef MSDOS
1257   joy_nr[0] = '#';
1258   joy_nr[1] = SETUP_2ND_JOYSTICK_ON(local_player->setup)+49;
1259   joy_nr[2] = '\0';
1260
1261   remove_joystick();
1262   ClearWindow();
1263   DrawText(SX+32, SY+7*32, "CENTER JOYSTICK",FS_BIG,FC_YELLOW);
1264   DrawText(SX+16+7*32, SY+8*32, joy_nr, FS_BIG,FC_YELLOW);
1265   DrawText(SX+32, SY+9*32, "AND PRESS A KEY",FS_BIG,FC_YELLOW);
1266   BackToFront();
1267
1268   for(clear_keybuf();!keypressed(););
1269   install_joystick(JOY_TYPE_2PADS);
1270
1271   ClearWindow();
1272   DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW);
1273   DrawText(SX+16, SY+8*32, " THE UPPER LEFT ",FS_BIG,FC_YELLOW);
1274   DrawText(SX+32, SY+9*32, "AND PRESS A KEY",FS_BIG,FC_YELLOW);
1275   BackToFront();
1276
1277   for(clear_keybuf();!keypressed(););
1278   calibrate_joystick(SETUP_2ND_JOYSTICK_ON(local_player->setup));
1279
1280   ClearWindow();
1281   DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW);
1282   DrawText(SX+32, SY+8*32, "THE LOWER RIGHT",FS_BIG,FC_YELLOW);
1283   DrawText(SX+32, SY+9*32, "AND PRESS A KEY",FS_BIG,FC_YELLOW);
1284   BackToFront();
1285
1286   for(clear_keybuf();!keypressed(););
1287   calibrate_joystick(SETUP_2ND_JOYSTICK_ON(local_player->setup));
1288
1289   DrawSetupScreen();
1290   return;
1291 #endif
1292
1293   ClearWindow();
1294   DrawText(SX+16, SY+16, "NO JOYSTICK",FS_BIG,FC_YELLOW);
1295   DrawText(SX+16, SY+48, " AVAILABLE ",FS_BIG,FC_YELLOW);
1296   BackToFront();
1297   Delay(3000);
1298   DrawSetupScreen();
1299 }
1300
1301 void HandleGameActions(int player_action)
1302 {
1303   if (game_status != PLAYING)
1304     return;
1305
1306   if (local_player->LevelSolved)
1307     GameWon();
1308
1309   if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
1310     TapeStop();
1311
1312   GameActions(player_action);
1313
1314   BackToFront();
1315 }
1316
1317 void HandleVideoButtons(int mx, int my, int button)
1318 {
1319   if (game_status != MAINMENU && game_status != PLAYING)
1320     return;
1321
1322   switch(CheckVideoButtons(mx,my,button))
1323   {
1324     case BUTTON_VIDEO_EJECT:
1325       TapeStop();
1326       if (TAPE_IS_EMPTY(tape))
1327       {
1328         LoadLevelTape(level_nr);
1329         if (TAPE_IS_EMPTY(tape))
1330           AreYouSure("No tape for this level !",AYS_CONFIRM);
1331       }
1332       else
1333       {
1334         if (tape.changed)
1335           SaveLevelTape(tape.level_nr);
1336         TapeErase();
1337       }
1338       DrawCompleteVideoDisplay();
1339       break;
1340     case BUTTON_VIDEO_STOP:
1341       TapeStop();
1342       break;
1343     case BUTTON_VIDEO_PAUSE:
1344       TapeTogglePause();
1345       break;
1346     case BUTTON_VIDEO_REC:
1347       if (TAPE_IS_STOPPED(tape))
1348       {
1349         TapeStartRecording();
1350         game_status = PLAYING;
1351         InitGame();
1352       }
1353       else if (tape.pausing)
1354       {
1355         if (tape.playing)       /* PLAYING -> PAUSING -> RECORDING */
1356         {
1357           tape.pos[tape.counter].delay = tape.delay_played;
1358           tape.playing = FALSE;
1359           tape.recording = TRUE;
1360           tape.changed = TRUE;
1361
1362           DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON,0);
1363         }
1364         else
1365           TapeTogglePause();
1366       }
1367       break;
1368     case BUTTON_VIDEO_PLAY:
1369       if (TAPE_IS_EMPTY(tape))
1370         break;
1371
1372       if (TAPE_IS_STOPPED(tape))
1373       {
1374         TapeStartPlaying();
1375         game_status = PLAYING;
1376         InitGame();
1377       }
1378       else if (tape.playing)
1379       {
1380         if (tape.pausing)                       /* PAUSE -> PLAY */
1381           TapeTogglePause();
1382         else if (!tape.fast_forward)            /* PLAY -> FAST FORWARD PLAY */
1383         {
1384           tape.fast_forward = TRUE;
1385           DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
1386         }
1387         else if (!tape.pause_before_death)      /* FFWD PLAY -> + AUTO PAUSE */
1388         {
1389           tape.pause_before_death = TRUE;
1390           DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, VIDEO_DISPLAY_LABEL_ONLY);
1391         }
1392         else                                    /* -> NORMAL PLAY */
1393         {
1394           tape.fast_forward = FALSE;
1395           tape.pause_before_death = FALSE;
1396           DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PAUSE_OFF, 0);
1397         }
1398       }
1399       break;
1400     default:
1401       break;
1402   }
1403
1404   BackToFront();
1405 }
1406
1407 void HandleSoundButtons(int mx, int my, int button)
1408 {
1409   if (game_status != PLAYING)
1410     return;
1411
1412   switch(CheckSoundButtons(mx,my,button))
1413   {
1414     case BUTTON_SOUND_MUSIC:
1415       if (sound_music_on)
1416       { 
1417         sound_music_on = FALSE;
1418         local_player->setup &= ~SETUP_SOUND_MUSIC;
1419         FadeSound(background_loop[level_nr % num_bg_loops]);
1420         DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF);
1421       }
1422       else if (sound_loops_allowed)
1423       { 
1424         sound_on = sound_music_on = TRUE;
1425         local_player->setup |= (SETUP_SOUND | SETUP_SOUND_MUSIC);
1426         PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
1427         DrawSoundDisplay(BUTTON_SOUND_MUSIC_ON);
1428       }
1429       else
1430         DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF);
1431       break;
1432     case BUTTON_SOUND_LOOPS:
1433       if (sound_loops_on)
1434       { 
1435         sound_loops_on = FALSE;
1436         local_player->setup &= ~SETUP_SOUND_LOOPS;
1437         DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF);
1438       }
1439       else if (sound_loops_allowed)
1440       { 
1441         sound_on = sound_loops_on = TRUE;
1442         local_player->setup |= (SETUP_SOUND | SETUP_SOUND_LOOPS);
1443         DrawSoundDisplay(BUTTON_SOUND_LOOPS_ON);
1444       }
1445       else
1446         DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF);
1447       break;
1448     case BUTTON_SOUND_SIMPLE:
1449       if (sound_simple_on)
1450       { 
1451         sound_simple_on = FALSE;
1452         local_player->setup &= ~SETUP_SOUND;
1453         DrawSoundDisplay(BUTTON_SOUND_SIMPLE_OFF);
1454       }
1455       else if (sound_status==SOUND_AVAILABLE)
1456       { 
1457         sound_on = sound_simple_on = TRUE;
1458         local_player->setup |= SETUP_SOUND;
1459         DrawSoundDisplay(BUTTON_SOUND_SIMPLE_ON);
1460       }
1461       else
1462         DrawSoundDisplay(BUTTON_SOUND_SIMPLE_OFF);
1463       break;
1464     default:
1465       break;
1466   }
1467
1468   BackToFront();
1469 }
1470
1471 void HandleGameButtons(int mx, int my, int button)
1472 {
1473   if (game_status != PLAYING)
1474     return;
1475
1476   switch(CheckGameButtons(mx,my,button))
1477   {
1478     case BUTTON_GAME_STOP:
1479       if (AllPlayersGone)
1480       {
1481         CloseDoor(DOOR_CLOSE_1);
1482         game_status = MAINMENU;
1483         DrawMainMenu();
1484         break;
1485       }
1486
1487       if (AreYouSure("Do you really want to quit the game ?",
1488                       AYS_ASK | AYS_STAY_CLOSED))
1489       { 
1490         game_status = MAINMENU;
1491         DrawMainMenu();
1492       }
1493       else
1494         OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
1495       break;
1496     case BUTTON_GAME_PAUSE:
1497       if (tape.pausing)
1498       {
1499         tape.pausing = FALSE;
1500         DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
1501       }
1502       else
1503       {
1504         tape.pausing = TRUE;
1505         DrawVideoDisplay(VIDEO_STATE_PAUSE_ON,0);
1506       }
1507       break;
1508     case BUTTON_GAME_PLAY:
1509       if (tape.pausing)
1510       {
1511         tape.pausing = FALSE;
1512         DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
1513       }
1514       break;
1515     default:
1516       break;
1517   }
1518
1519   BackToFront();
1520 }