changed order of switch cases in EM engine source file
[rocksndiamonds.git] / src / game_em / synchro_2.c
1 /* second part of synchro.
2  *
3  * game logic for monsters.
4  *
5  * one giant switch statement to process everything.
6  *
7  * this whole thing is a major bottleneck. the compiler must use registers.
8  * compilers suck.
9  */
10
11 #include "main_em.h"
12
13
14 #define SPRING_ROLL     /* spring rolling off round things continues to roll */
15
16 #define RANDOM (random_em = random_em << 31 | random_em >> 1)
17
18 static unsigned int random_em;
19 static int score;
20
21 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
22 {
23   int distance, distance_shortest = EM_MAX_CAVE_WIDTH + EM_MAX_CAVE_HEIGHT;
24   int i;
25
26   /* default values if no players are alive anymore */
27   *dx = 0;
28   *dy = 0;
29
30   for (i = 0; i < MAX_PLAYERS; i++)
31   {
32     if (!ply[i].alive)
33       continue;
34
35     distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
36
37     if (distance < distance_shortest)
38     {
39       *dx = ply[i].x;
40       *dy = ply[i].y;
41
42       distance_shortest = distance;
43     }
44   }
45 }
46
47 static void Lboom_bug(int x, int y)
48 {
49   Next[y][x] = Znormal;
50   Boom[y-1][x-1] = Xemerald;
51   Boom[y-1][x] = Xemerald;
52   Boom[y-1][x+1] = Xemerald;
53   Boom[y][x-1] = Xemerald;
54   Boom[y][x] = Xdiamond;
55   Boom[y][x+1] = Xemerald;
56   Boom[y+1][x-1] = Xemerald;
57   Boom[y+1][x] = Xemerald;
58   Boom[y+1][x+1] = Xemerald;
59
60 #if PLAY_ELEMENT_SOUND
61   play_element_sound(x, y, SOUND_boom, element);
62 #endif
63 }
64
65 static void Lboom_tank(int x, int y)
66 {
67   Next[y][x] = Znormal;
68   Boom[y-1][x-1] = Xblank;
69   Boom[y-1][x] = Xblank;
70   Boom[y-1][x+1] = Xblank;
71   Boom[y][x-1] = Xblank;
72   Boom[y][x] = Xblank;
73   Boom[y][x+1] = Xblank;
74   Boom[y+1][x-1] = Xblank;
75   Boom[y+1][x] = Xblank;
76   Boom[y+1][x+1] = Xblank;
77 #if PLAY_ELEMENT_SOUND
78   play_element_sound(x, y, SOUND_boom, element);
79 #endif
80 }
81
82 static void Landroid(int x, int y)
83 {
84   int dx, dy, temp;
85
86   if (lev.android_clone_cnt == 0)
87   {
88     if (Cave[y-1][x-1] != Xblank &&
89         Cave[y-1][x]   != Xblank &&
90         Cave[y-1][x+1] != Xblank &&
91         Cave[y][x-1]   != Xblank &&
92         Cave[y][x+1]   != Xblank &&
93         Cave[y+1][x-1] != Xblank &&
94         Cave[y+1][x]   != Xblank &&
95         Cave[y+1][x+1] != Xblank)
96       goto android_move;
97
98     switch (RANDOM & 7)
99     {
100       /* randomly find an object to clone */
101
102       case 0: /* S,NE,W,NW,SE,E,SW,N */
103         temp = lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
104         temp = lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
105         temp = lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
106         temp = lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
107         temp = lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
108         temp = lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
109         temp = lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
110         temp = lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
111         goto android_move;
112
113       case 1: /* NW,SE,N,S,NE,SW,E,W */
114         temp = lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
115         temp = lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
116         temp = lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
117         temp = lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
118         temp = lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
119         temp = lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
120         temp = lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
121         temp = lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
122         goto android_move;
123
124       case 2: /* SW,E,S,W,N,NW,SE,NE */
125         temp = lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
126         temp = lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
127         temp = lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
128         temp = lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
129         temp = lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
130         temp = lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
131         temp = lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
132         temp = lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
133         goto android_move;
134
135       case 3: /* N,SE,NE,E,W,S,NW,SW */
136         temp = lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
137         temp = lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
138         temp = lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
139         temp = lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
140         temp = lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
141         temp = lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
142         temp = lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
143         temp = lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
144         goto android_move;
145
146       case 4: /* SE,NW,E,NE,SW,W,N,S */
147         temp = lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
148         temp = lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
149         temp = lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
150         temp = lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
151         temp = lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
152         temp = lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
153         temp = lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
154         temp = lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
155         goto android_move;
156
157       case 5: /* NE,W,SE,SW,S,N,E,NW */
158         temp = lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
159         temp = lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
160         temp = lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
161         temp = lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
162         temp = lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
163         temp = lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
164         temp = lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
165         temp = lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
166         goto android_move;
167
168       case 6: /* E,N,SW,S,NW,NE,SE,W */
169         temp = lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
170         temp = lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
171         temp = lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
172         temp = lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
173         temp = lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
174         temp = lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
175         temp = lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
176         temp = lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
177         goto android_move;
178
179       case 7: /* W,SW,NW,N,E,SE,NE,S */
180         temp = lev.android_array[Cave[y][x-1]];   if (temp != Xblank) break;
181         temp = lev.android_array[Cave[y+1][x-1]]; if (temp != Xblank) break;
182         temp = lev.android_array[Cave[y-1][x-1]]; if (temp != Xblank) break;
183         temp = lev.android_array[Cave[y-1][x]];   if (temp != Xblank) break;
184         temp = lev.android_array[Cave[y][x+1]];   if (temp != Xblank) break;
185         temp = lev.android_array[Cave[y+1][x+1]]; if (temp != Xblank) break;
186         temp = lev.android_array[Cave[y-1][x+1]]; if (temp != Xblank) break;
187         temp = lev.android_array[Cave[y+1][x]];   if (temp != Xblank) break;
188         goto android_move;
189     }
190
191     Next[y][x] = temp;  /* the item we chose to clone */
192     play_element_sound(x, y, SOUND_android_clone, temp);
193
194     switch (RANDOM & 7)
195     {
196       /* randomly find a direction to move */
197
198       case 0: /* S,NE,W,NW,SE,E,SW,N */
199         if (Cave[y+1][x] == Xblank)   goto android_s;
200         if (Cave[y-1][x+1] == Xblank) goto android_ne;
201         if (Cave[y][x-1] == Xblank)   goto android_w;
202         if (Cave[y-1][x-1] == Xblank) goto android_nw;
203         if (Cave[y+1][x+1] == Xblank) goto android_se;
204         if (Cave[y][x+1] == Xblank)   goto android_e;
205         if (Cave[y+1][x-1] == Xblank) goto android_sw;
206         if (Cave[y-1][x] == Xblank)   goto android_n;
207         goto android_move;
208
209       case 1: /* NW,SE,N,S,NE,SW,E,W */
210         if (Cave[y-1][x-1] == Xblank) goto android_nw;
211         if (Cave[y+1][x+1] == Xblank) goto android_se;
212         if (Cave[y-1][x] == Xblank)   goto android_n;
213         if (Cave[y+1][x] == Xblank)   goto android_s;
214         if (Cave[y-1][x+1] == Xblank) goto android_ne;
215         if (Cave[y+1][x-1] == Xblank) goto android_sw;
216         if (Cave[y][x+1] == Xblank)   goto android_e;
217         if (Cave[y][x-1] == Xblank)   goto android_w;
218         goto android_move;
219
220       case 2: /* SW,E,S,W,N,NW,SE,NE */
221         if (Cave[y+1][x-1] == Xblank) goto android_sw;
222         if (Cave[y][x+1] == Xblank)   goto android_e;
223         if (Cave[y+1][x] == Xblank)   goto android_s;
224         if (Cave[y][x-1] == Xblank)   goto android_w;
225         if (Cave[y-1][x] == Xblank)   goto android_n;
226         if (Cave[y-1][x-1] == Xblank) goto android_nw;
227         if (Cave[y+1][x+1] == Xblank) goto android_se;
228         if (Cave[y-1][x+1] == Xblank) goto android_ne;
229         goto android_move;
230
231       case 3: /* N,SE,NE,E,W,S,NW,SW */
232         if (Cave[y-1][x] == Xblank)   goto android_n;
233         if (Cave[y+1][x+1] == Xblank) goto android_se;
234         if (Cave[y-1][x+1] == Xblank) goto android_ne;
235         if (Cave[y][x+1] == Xblank)   goto android_e;
236         if (Cave[y][x-1] == Xblank)   goto android_w;
237         if (Cave[y+1][x] == Xblank)   goto android_s;
238         if (Cave[y-1][x-1] == Xblank) goto android_nw;
239         if (Cave[y+1][x-1] == Xblank) goto android_sw;
240         goto android_move;
241
242       case 4: /* SE,NW,E,NE,SW,W,N,S */
243         if (Cave[y+1][x+1] == Xblank) goto android_se;
244         if (Cave[y-1][x-1] == Xblank) goto android_nw;
245         if (Cave[y][x+1] == Xblank)   goto android_e;
246         if (Cave[y-1][x+1] == Xblank) goto android_ne;
247         if (Cave[y+1][x-1] == Xblank) goto android_sw;
248         if (Cave[y][x-1] == Xblank)   goto android_w;
249         if (Cave[y-1][x] == Xblank)   goto android_n;
250         if (Cave[y+1][x] == Xblank)   goto android_s;
251         goto android_move;
252
253       case 5: /* NE,W,SE,SW,S,N,E,NW */
254         if (Cave[y-1][x+1] == Xblank) goto android_ne;
255         if (Cave[y][x-1] == Xblank)   goto android_w;
256         if (Cave[y+1][x+1] == Xblank) goto android_se;
257         if (Cave[y+1][x-1] == Xblank) goto android_sw;
258         if (Cave[y+1][x] == Xblank)   goto android_s;
259         if (Cave[y-1][x] == Xblank)   goto android_n;
260         if (Cave[y][x+1] == Xblank)   goto android_e;
261         if (Cave[y-1][x-1] == Xblank) goto android_nw;
262         goto android_move;
263
264       case 6: /* E,N,SW,S,NW,NE,SE,W */
265         if (Cave[y][x+1] == Xblank)   goto android_e;
266         if (Cave[y-1][x] == Xblank)   goto android_n;
267         if (Cave[y+1][x-1] == Xblank) goto android_sw;
268         if (Cave[y+1][x] == Xblank)   goto android_s;
269         if (Cave[y-1][x-1] == Xblank) goto android_nw;
270         if (Cave[y-1][x+1] == Xblank) goto android_ne;
271         if (Cave[y+1][x+1] == Xblank) goto android_se;
272         if (Cave[y][x-1] == Xblank)   goto android_w;
273         goto android_move;
274
275       case 7: /* W,SW,NW,N,E,SE,NE,S */
276         if (Cave[y][x-1] == Xblank)   goto android_w;
277         if (Cave[y+1][x-1] == Xblank) goto android_sw;
278         if (Cave[y-1][x-1] == Xblank) goto android_nw;
279         if (Cave[y-1][x] == Xblank)   goto android_n;
280         if (Cave[y][x+1] == Xblank)   goto android_e;
281         if (Cave[y+1][x+1] == Xblank) goto android_se;
282         if (Cave[y-1][x+1] == Xblank) goto android_ne;
283         if (Cave[y+1][x] == Xblank)   goto android_s;
284         goto android_move;
285     }
286   }
287
288  android_move:
289   if (lev.android_move_cnt == 0)
290   {
291     if (Cave[y-1][x-1] == Zplayer ||
292         Cave[y-1][x]   == Zplayer ||
293         Cave[y-1][x+1] == Zplayer ||
294         Cave[y][x-1]   == Zplayer ||
295         Cave[y][x+1]   == Zplayer ||
296         Cave[y+1][x-1] == Zplayer ||
297         Cave[y+1][x]   == Zplayer ||
298         Cave[y+1][x+1] == Zplayer)
299       goto android_still;
300
301     set_nearest_player_xy(x, y, &dx, &dy);
302
303     Next[y][x] = Xblank;        /* assume we will move */
304     temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
305
306     if (RANDOM & 1)
307     {
308       switch (temp)
309       {
310         /* attempt clockwise move first if direct path is blocked */
311
312         case 0: /* north west */
313           if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
314           if (tab_android_move[Cave[y-1][x]])   goto android_n;
315           if (tab_android_move[Cave[y][x-1]])   goto android_w;
316           break;
317
318         case 1: /* north */
319           if (tab_android_move[Cave[y-1][x]])   goto android_n;
320           if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
321           if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
322           break;
323
324         case 2: /* north east */
325           if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
326           if (tab_android_move[Cave[y][x+1]])   goto android_e;
327           if (tab_android_move[Cave[y-1][x]])   goto android_n;
328           break;
329
330         case 3: /* west */
331           if (tab_android_move[Cave[y][x-1]])   goto android_w;
332           if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
333           if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
334           break;
335
336         case 4: /* nowhere */
337           break;
338
339         case 5: /* east */
340           if (tab_android_move[Cave[y][x+1]])   goto android_e;
341           if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
342           if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
343           break;
344
345         case 6: /* south west */
346           if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
347           if (tab_android_move[Cave[y][x-1]])   goto android_w;
348           if (tab_android_move[Cave[y+1][x]])   goto android_s;
349           break;
350
351         case 7: /* south */
352           if (tab_android_move[Cave[y+1][x]])   goto android_s;
353           if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
354           if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
355           break;
356
357         case 8: /* south east */
358           if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
359           if (tab_android_move[Cave[y+1][x]])   goto android_s;
360           if (tab_android_move[Cave[y][x+1]])   goto android_e;
361           break;
362       }
363     }
364     else
365     {
366       switch (temp)
367       {
368         /* attempt counterclockwise move first if direct path is blocked */
369
370         case 0: /* north west */
371           if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
372           if (tab_android_move[Cave[y][x-1]])   goto android_w;
373           if (tab_android_move[Cave[y-1][x]])   goto android_n;
374           break;
375
376         case 1: /* north */
377           if (tab_android_move[Cave[y-1][x]])   goto android_n;
378           if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
379           if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
380           break;
381
382         case 2: /* north east */
383           if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
384           if (tab_android_move[Cave[y-1][x]])   goto android_n;
385           if (tab_android_move[Cave[y][x+1]])   goto android_e;
386           break;
387
388         case 3: /* west */
389           if (tab_android_move[Cave[y][x-1]])   goto android_w;
390           if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
391           if (tab_android_move[Cave[y-1][x-1]]) goto android_nw;
392           break;
393
394         case 4: /* nowhere */
395           break;
396
397         case 5: /* east */
398           if (tab_android_move[Cave[y][x+1]])   goto android_e;
399           if (tab_android_move[Cave[y-1][x+1]]) goto android_ne;
400           if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
401           break;
402
403         case 6: /* south west */
404           if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
405           if (tab_android_move[Cave[y+1][x]])   goto android_s;
406           if (tab_android_move[Cave[y][x-1]])   goto android_w;
407           break;
408
409         case 7: /* south */
410           if (tab_android_move[Cave[y+1][x]])   goto android_s;
411           if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
412           if (tab_android_move[Cave[y+1][x-1]]) goto android_sw;
413           break;
414
415         case 8: /* south east */
416           if (tab_android_move[Cave[y+1][x+1]]) goto android_se;
417           if (tab_android_move[Cave[y][x+1]])   goto android_e;
418           if (tab_android_move[Cave[y+1][x]])   goto android_s;
419           break;
420       }
421     }
422   }
423
424  android_still:
425   Next[y][x] = Xandroid;
426   return;
427
428  android_n:
429   Cave[y][x] = Yandroid_nB;
430   Cave[y-1][x] = Yandroid_n;
431   Next[y-1][x] = Xandroid;
432   play_element_sound(x, y, SOUND_android_move, Xandroid);
433   return;
434
435  android_ne:
436   Cave[y][x] = Yandroid_neB;
437   Cave[y-1][x+1] = Yandroid_ne;
438   Next[y-1][x+1] = Xandroid;
439   play_element_sound(x, y, SOUND_android_move, Xandroid);
440   return;
441
442  android_e:
443   Cave[y][x] = Yandroid_eB;
444   Cave[y][x+1] = Yandroid_e;
445   Next[y][x+1] = Xandroid;
446   play_element_sound(x, y, SOUND_android_move, Xandroid);
447   return;
448
449  android_se:
450   Cave[y][x] = Yandroid_seB;
451   Cave[y+1][x+1] = Yandroid_se;
452   Next[y+1][x+1] = Xandroid;
453   play_element_sound(x, y, SOUND_android_move, Xandroid);
454   return;
455
456  android_s:
457   Cave[y][x] = Yandroid_sB;
458   Cave[y+1][x] = Yandroid_s;
459   Next[y+1][x] = Xandroid;
460   play_element_sound(x, y, SOUND_android_move, Xandroid);
461   return;
462
463  android_sw:
464   Cave[y][x] = Yandroid_swB;
465   Cave[y+1][x-1] = Yandroid_sw;
466   Next[y+1][x-1] = Xandroid;
467   play_element_sound(x, y, SOUND_android_move, Xandroid);
468   return;
469
470  android_w:
471   Cave[y][x] = Yandroid_wB;
472   Cave[y][x-1] = Yandroid_w;
473   Next[y][x-1] = Xandroid;
474   play_element_sound(x, y, SOUND_android_move, Xandroid);
475   return;
476
477  android_nw:
478   Cave[y][x] = Yandroid_nwB;
479   Cave[y-1][x-1] = Yandroid_nw;
480   Next[y-1][x-1] = Xandroid;
481   play_element_sound(x, y, SOUND_android_move, Xandroid);
482   return;
483 }
484
485 static void Landroid_1_n(int x, int y)
486 {
487   switch (Cave[y-1][x])
488   {
489     case Xacid_1:
490     case Xacid_2:
491     case Xacid_3:
492     case Xacid_4:
493     case Xacid_5:
494     case Xacid_6:
495     case Xacid_7:
496     case Xacid_8:
497       Cave[y][x] = Yandroid_nB;
498       if (Cave[y-2][x+1] == Xblank)
499         Cave[y-2][x+1] = Xacid_splash_e;
500       if (Cave[y-2][x-1] == Xblank)
501         Cave[y-2][x-1] = Xacid_splash_w;
502       Next[y][x] = Xblank;
503       play_element_sound(x, y, SOUND_acid, Xacid_1);
504       return;
505
506     case Xblank:
507     case Xacid_splash_e:
508     case Xacid_splash_w:
509       Cave[y][x] = Yandroid_nB;
510       Cave[y-1][x] = Yandroid_n;
511       Next[y][x] = Xblank;
512       Next[y-1][x] = Xandroid;
513       play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
514       return;
515
516     default:
517       Landroid(x, y);
518       return;
519   }
520 }
521
522 static void Landroid_2_n(int x, int y)
523 {
524   switch (Cave[y-1][x])
525   {
526     case Xacid_1:
527     case Xacid_2:
528     case Xacid_3:
529     case Xacid_4:
530     case Xacid_5:
531     case Xacid_6:
532     case Xacid_7:
533     case Xacid_8:
534       Cave[y][x] = Yandroid_nB;
535       if (Cave[y-2][x+1] == Xblank)
536         Cave[y-2][x+1] = Xacid_splash_e;
537       if (Cave[y-2][x-1] == Xblank)
538         Cave[y-2][x-1] = Xacid_splash_w;
539       Next[y][x] = Xblank;
540       play_element_sound(x, y, SOUND_acid, Xacid_1);
541       return;
542
543     case Xblank:
544     case Xacid_splash_e:
545     case Xacid_splash_w:
546       Cave[y][x] = Yandroid_nB;
547       Cave[y-1][x] = Yandroid_n;
548       Next[y][x] = Xblank;
549       Next[y-1][x] = Xandroid_1_n;
550       play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
551       return;
552
553     default:
554       Landroid(x, y);
555       return;
556   }
557 }
558
559 static void Landroid_1_e(int x, int y)
560 {
561   switch (Cave[y][x+1])
562   {
563     case Xacid_1:
564     case Xacid_2:
565     case Xacid_3:
566     case Xacid_4:
567     case Xacid_5:
568     case Xacid_6:
569     case Xacid_7:
570     case Xacid_8:
571       Cave[y][x] = Yandroid_eB;
572       if (Cave[y-1][x+2] == Xblank)
573         Cave[y-1][x+2] = Xacid_splash_e;
574       if (Cave[y-1][x] == Xblank)
575         Cave[y-1][x] = Xacid_splash_w;
576       Next[y][x] = Xblank;
577       play_element_sound(x, y, SOUND_acid, Xacid_1);
578       return;
579
580     case Xblank:
581     case Xacid_splash_e:
582     case Xacid_splash_w:
583       Cave[y][x] = Yandroid_eB;
584       Cave[y][x+1] = Yandroid_e;
585       Next[y][x] = Xblank;
586       Next[y][x+1] = Xandroid;
587       play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
588       return;
589
590     default:
591       Landroid(x, y);
592       return;
593   }
594 }
595
596 static void Landroid_2_e(int x, int y)
597 {
598   switch (Cave[y][x+1])
599   {
600     case Xacid_1:
601     case Xacid_2:
602     case Xacid_3:
603     case Xacid_4:
604     case Xacid_5:
605     case Xacid_6:
606     case Xacid_7:
607     case Xacid_8:
608       Cave[y][x] = Yandroid_eB;
609       if (Cave[y-1][x+2] == Xblank)
610         Cave[y-1][x+2] = Xacid_splash_e;
611       if (Cave[y-1][x] == Xblank)
612         Cave[y-1][x] = Xacid_splash_w;
613       Next[y][x] = Xblank;
614       play_element_sound(x, y, SOUND_acid, Xacid_1);
615       return;
616
617     case Xblank:
618     case Xacid_splash_e:
619     case Xacid_splash_w:
620       Cave[y][x] = Yandroid_eB;
621       Cave[y][x+1] = Yandroid_e;
622       Next[y][x] = Xblank;
623       Next[y][x+1] = Xandroid_1_e;
624       play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
625       return;
626
627     default:
628       Landroid(x, y);
629       return;
630   }
631 }
632
633 static void Landroid_1_s(int x, int y)
634 {
635   switch (Cave[y+1][x])
636   {
637     case Xacid_1:
638     case Xacid_2:
639     case Xacid_3:
640     case Xacid_4:
641     case Xacid_5:
642     case Xacid_6:
643     case Xacid_7:
644     case Xacid_8:
645       Cave[y][x] = Yandroid_sB;
646       if (Cave[y][x+1] == Xblank)
647         Cave[y][x+1] = Xacid_splash_e;
648       if (Cave[y][x-1] == Xblank)
649         Cave[y][x-1] = Xacid_splash_w;
650       Next[y][x] = Xblank;
651       play_element_sound(x, y, SOUND_acid, Xacid_1);
652       return;
653
654     case Xblank:
655     case Xacid_splash_e:
656     case Xacid_splash_w:
657       Cave[y][x] = Yandroid_sB;
658       Cave[y+1][x] = Yandroid_s;
659       Next[y][x] = Xblank;
660       Next[y+1][x] = Xandroid;
661       play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
662       return;
663
664     default:
665       Landroid(x, y);
666       return;
667   }
668 }
669
670 static void Landroid_2_s(int x, int y)
671 {
672   switch (Cave[y+1][x])
673   {
674     case Xacid_1:
675     case Xacid_2:
676     case Xacid_3:
677     case Xacid_4:
678     case Xacid_5:
679     case Xacid_6:
680     case Xacid_7:
681     case Xacid_8:
682       Cave[y][x] = Yandroid_sB;
683       if (Cave[y][x+1] == Xblank)
684         Cave[y][x+1] = Xacid_splash_e;
685       if (Cave[y][x-1] == Xblank)
686         Cave[y][x-1] = Xacid_splash_w;
687       Next[y][x] = Xblank;
688       play_element_sound(x, y, SOUND_acid, Xacid_1);
689       return;
690
691     case Xblank:
692     case Xacid_splash_e:
693     case Xacid_splash_w:
694       Cave[y][x] = Yandroid_sB;
695       Cave[y+1][x] = Yandroid_s;
696       Next[y][x] = Xblank;
697       Next[y+1][x] = Xandroid_1_s;
698       play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
699       return;
700
701     default:
702       Landroid(x, y);
703       return;
704   }
705 }
706
707 static void Landroid_1_w(int x, int y)
708 {
709   switch (Cave[y][x-1])
710   {
711     case Xacid_1:
712     case Xacid_2:
713     case Xacid_3:
714     case Xacid_4:
715     case Xacid_5:
716     case Xacid_6:
717     case Xacid_7:
718     case Xacid_8:
719       Cave[y][x] = Yandroid_wB;
720       if (Cave[y-1][x] == Xblank)
721         Cave[y-1][x] = Xacid_splash_e;
722       if (Cave[y-1][x-2] == Xblank)
723         Cave[y-1][x-2] = Xacid_splash_w;
724       Next[y][x] = Xblank;
725       play_element_sound(x, y, SOUND_acid, Xacid_1);
726       return;
727
728     case Xblank:
729     case Xacid_splash_e:
730     case Xacid_splash_w:
731       Cave[y][x] = Yandroid_wB;
732       Cave[y][x-1] = Yandroid_w;
733       Next[y][x] = Xblank;
734       Next[y][x-1] = Xandroid;
735       play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
736       return;
737
738     default:
739       Landroid(x, y);
740       return;
741   }
742 }
743
744 static void Landroid_2_w(int x, int y)
745 {
746   switch (Cave[y][x-1])
747   {
748     case Xacid_1:
749     case Xacid_2:
750     case Xacid_3:
751     case Xacid_4:
752     case Xacid_5:
753     case Xacid_6:
754     case Xacid_7:
755     case Xacid_8:
756       Cave[y][x] = Yandroid_wB;
757       if (Cave[y-1][x] == Xblank)
758         Cave[y-1][x] = Xacid_splash_e;
759       if (Cave[y-1][x-2] == Xblank)
760         Cave[y-1][x-2] = Xacid_splash_w;
761       Next[y][x] = Xblank;
762       play_element_sound(x, y, SOUND_acid, Xacid_1);
763       return;
764
765     case Xblank:
766     case Xacid_splash_e:
767     case Xacid_splash_w:
768       Cave[y][x] = Yandroid_wB;
769       Cave[y][x-1] = Yandroid_w;
770       Next[y][x] = Xblank;
771       Next[y][x-1] = Xandroid_1_w;
772       play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
773       return;
774
775     default:
776       Landroid(x, y);
777       return;
778   }
779 }
780
781 static void Leater_n(int x, int y)
782 {
783   if (Cave[y][x+1] == Xdiamond)
784   {
785     Cave[y][x+1] = Ydiamond_blank;
786     Next[y][x+1] = Xblank;
787     play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
788     return;
789   }
790
791   if (Cave[y+1][x] == Xdiamond)
792   {
793     Cave[y+1][x] = Ydiamond_blank;
794     Next[y+1][x] = Xblank;
795     play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
796     return;
797   }
798
799   if (Cave[y][x-1] == Xdiamond)
800   {
801     Cave[y][x-1] = Ydiamond_blank;
802     Next[y][x-1] = Xblank;
803     play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
804     return;
805   }
806
807   if (Cave[y-1][x] == Xdiamond)
808   {
809     Cave[y-1][x] = Ydiamond_blank;
810     Next[y-1][x] = Xblank;
811     play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
812     return;
813   }
814
815   switch (Cave[y-1][x])
816   {
817     case Xacid_1:
818     case Xacid_2:
819     case Xacid_3:
820     case Xacid_4:
821     case Xacid_5:
822     case Xacid_6:
823     case Xacid_7:
824     case Xacid_8:
825       Cave[y][x] = Yeater_nB;
826       if (Cave[y-2][x+1] == Xblank)
827         Cave[y-2][x+1] = Xacid_splash_e;
828       if (Cave[y-2][x-1] == Xblank)
829         Cave[y-2][x-1] = Xacid_splash_w;
830       Next[y][x] = Xblank;
831       play_element_sound(x, y, SOUND_acid, Xacid_1);
832       return;
833
834     case Xblank:
835     case Xacid_splash_e:
836     case Xacid_splash_w:
837     case Xplant:
838     case Yplant:
839     case Zplayer:
840       Cave[y][x] = Yeater_nB;
841       Cave[y-1][x] = Yeater_n;
842       Next[y][x] = Xblank;
843       Next[y-1][x] = Xeater_n;
844       return;
845
846     default:
847       Next[y][x] = RANDOM & 1 ? Xeater_e : Xeater_w;
848       play_element_sound(x, y, SOUND_eater, Xeater_n);
849       return;
850   }
851 }
852
853 static void Leater_e(int x, int y)
854 {
855   if (Cave[y+1][x] == Xdiamond)
856   {
857     Cave[y+1][x] = Ydiamond_blank;
858     Next[y+1][x] = Xblank;
859     play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
860     return;
861   }
862
863   if (Cave[y][x-1] == Xdiamond)
864   {
865     Cave[y][x-1] = Ydiamond_blank;
866     Next[y][x-1] = Xblank;
867     play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
868     return;
869   }
870
871   if (Cave[y-1][x] == Xdiamond)
872   {
873     Cave[y-1][x] = Ydiamond_blank;
874     Next[y-1][x] = Xblank;
875     play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
876     return;
877   }
878
879   if (Cave[y][x+1] == Xdiamond)
880   {
881     Cave[y][x+1] = Ydiamond_blank;
882     Next[y][x+1] = Xblank;
883     play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
884     return;
885   }
886
887   switch (Cave[y][x+1])
888   {
889     case Xacid_1:
890     case Xacid_2:
891     case Xacid_3:
892     case Xacid_4:
893     case Xacid_5:
894     case Xacid_6:
895     case Xacid_7:
896     case Xacid_8:
897       Cave[y][x] = Yeater_eB;
898       if (Cave[y-1][x+2] == Xblank)
899         Cave[y-1][x+2] = Xacid_splash_e;
900       if (Cave[y-1][x] == Xblank)
901         Cave[y-1][x] = Xacid_splash_w;
902       Next[y][x] = Xblank;
903       play_element_sound(x, y, SOUND_acid, Xacid_1);
904       return;
905
906     case Xblank:
907     case Xacid_splash_e:
908     case Xacid_splash_w:
909     case Xplant:
910     case Yplant:
911     case Zplayer:
912       Cave[y][x] = Yeater_eB;
913       Cave[y][x+1] = Yeater_e;
914       Next[y][x] = Xblank;
915       Next[y][x+1] = Xeater_e;
916       return;
917
918     default:
919       Next[y][x] = RANDOM & 1 ? Xeater_n : Xeater_s;
920       play_element_sound(x, y, SOUND_eater, Xeater_e);
921       return;
922   }
923 }
924
925 static void Leater_s(int x, int y)
926 {
927   if (Cave[y][x-1] == Xdiamond)
928   {
929     Cave[y][x-1] = Ydiamond_blank;
930     Next[y][x-1] = Xblank;
931     play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
932     return;
933   }
934
935   if (Cave[y-1][x] == Xdiamond)
936   {
937     Cave[y-1][x] = Ydiamond_blank;
938     Next[y-1][x] = Xblank;
939     play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
940     return;
941   }
942
943   if (Cave[y][x+1] == Xdiamond)
944   {
945     Cave[y][x+1] = Ydiamond_blank;
946     Next[y][x+1] = Xblank;
947     play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
948     return;
949   }
950
951   if (Cave[y+1][x] == Xdiamond)
952   {
953     Cave[y+1][x] = Ydiamond_blank;
954     Next[y+1][x] = Xblank;
955     play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
956     return;
957   }
958
959   switch (Cave[y+1][x])
960   {
961     case Xacid_1:
962     case Xacid_2:
963     case Xacid_3:
964     case Xacid_4:
965     case Xacid_5:
966     case Xacid_6:
967     case Xacid_7:
968     case Xacid_8:
969       Cave[y][x] = Yeater_sB;
970       if (Cave[y][x+1] == Xblank)
971         Cave[y][x+1] = Xacid_splash_e;
972       if (Cave[y][x-1] == Xblank)
973         Cave[y][x-1] = Xacid_splash_w;
974       Next[y][x] = Xblank;
975       play_element_sound(x, y, SOUND_acid, Xacid_1);
976       return;
977
978     case Xblank:
979     case Xacid_splash_e:
980     case Xacid_splash_w:
981     case Xplant:
982     case Yplant:
983     case Zplayer:
984       Cave[y][x] = Yeater_sB;
985       Cave[y+1][x] = Yeater_s;
986       Next[y][x] = Xblank;
987       Next[y+1][x] = Xeater_s;
988       return;
989
990     default:
991       Next[y][x] = RANDOM & 1 ? Xeater_e : Xeater_w;
992       play_element_sound(x, y, SOUND_eater, Xeater_s);
993       return;
994   }
995 }
996
997 static void Leater_w(int x, int y)
998 {
999   if (Cave[y-1][x] == Xdiamond)
1000   {
1001     Cave[y-1][x] = Ydiamond_blank;
1002     Next[y-1][x] = Xblank;
1003     play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
1004     return;
1005   }
1006
1007   if (Cave[y][x+1] == Xdiamond)
1008   {
1009     Cave[y][x+1] = Ydiamond_blank;
1010     Next[y][x+1] = Xblank;
1011     play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
1012     return;
1013   }
1014
1015   if (Cave[y+1][x] == Xdiamond)
1016   {
1017     Cave[y+1][x] = Ydiamond_blank;
1018     Next[y+1][x] = Xblank;
1019     play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
1020     return;
1021   }
1022
1023   if (Cave[y][x-1] == Xdiamond)
1024   {
1025     Cave[y][x-1] = Ydiamond_blank;
1026     Next[y][x-1] = Xblank;
1027     play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
1028     return;
1029   }
1030
1031   switch (Cave[y][x-1])
1032   {
1033     case Xacid_1:
1034     case Xacid_2:
1035     case Xacid_3:
1036     case Xacid_4:
1037     case Xacid_5:
1038     case Xacid_6:
1039     case Xacid_7:
1040     case Xacid_8:
1041       Cave[y][x] = Yeater_wB;
1042       if (Cave[y-1][x] == Xblank)
1043         Cave[y-1][x] = Xacid_splash_e;
1044       if (Cave[y-1][x-2] == Xblank)
1045         Cave[y-1][x-2] = Xacid_splash_w;
1046       Next[y][x] = Xblank;
1047       play_element_sound(x, y, SOUND_acid, Xacid_1);
1048       return;
1049
1050     case Xblank:
1051     case Xacid_splash_e:
1052     case Xacid_splash_w:
1053     case Xplant:
1054     case Yplant:
1055     case Zplayer:
1056       Cave[y][x] = Yeater_wB;
1057       Cave[y][x-1] = Yeater_w;
1058       Next[y][x] = Xblank;
1059       Next[y][x-1] = Xeater_w;
1060       return;
1061
1062     default:
1063       Next[y][x] = RANDOM & 1 ? Xeater_n : Xeater_s;
1064       play_element_sound(x, y, SOUND_eater, Xeater_w);
1065       return;
1066   }
1067 }
1068
1069 static void Lalien(int x, int y)
1070 {
1071   int dx, dy;
1072
1073   if (lev.wheel_cnt)
1074   {
1075     dx = lev.wheel_x;
1076     dy = lev.wheel_y;
1077   }
1078   else
1079   {
1080     set_nearest_player_xy(x, y, &dx, &dy);
1081   }
1082
1083   if (RANDOM & 1)
1084   {
1085     if (y > dy)
1086     {
1087       switch (Cave[y-1][x])
1088       {
1089         case Xacid_1:
1090         case Xacid_2:
1091         case Xacid_3:
1092         case Xacid_4:
1093         case Xacid_5:
1094         case Xacid_6:
1095         case Xacid_7:
1096         case Xacid_8:
1097           Cave[y][x] = Yalien_nB;
1098           if (Cave[y-2][x+1] == Xblank)
1099             Cave[y-2][x+1] = Xacid_splash_e;
1100           if (Cave[y-2][x-1] == Xblank)
1101             Cave[y-2][x-1] = Xacid_splash_w;
1102           Next[y][x] = Xblank;
1103           play_element_sound(x, y, SOUND_acid, Xacid_1);
1104           return;
1105
1106         case Xblank:
1107         case Xacid_splash_e:
1108         case Xacid_splash_w:
1109         case Xplant:
1110         case Yplant:
1111         case Zplayer:
1112           Cave[y][x] = Yalien_nB;
1113           Cave[y-1][x] = Yalien_n;
1114           Next[y][x] = Xblank;
1115           Next[y-1][x] = Xalien_pause;
1116           play_element_sound(x, y, SOUND_alien, Xalien);
1117           return;
1118       }
1119     }
1120     else if (y < dy)
1121     {
1122       switch (Cave[y+1][x])
1123       {
1124         case Xacid_1:
1125         case Xacid_2:
1126         case Xacid_3:
1127         case Xacid_4:
1128         case Xacid_5:
1129         case Xacid_6:
1130         case Xacid_7:
1131         case Xacid_8:
1132           Cave[y][x] = Yalien_sB;
1133           Next[y][x] = Xblank;
1134           if (Cave[y][x+1] == Xblank)
1135             Cave[y][x+1] = Xacid_splash_e;
1136           if (Cave[y][x-1] == Xblank)
1137             Cave[y][x-1] = Xacid_splash_w;
1138           play_element_sound(x, y, SOUND_acid, Xacid_1);
1139           return;
1140
1141         case Xblank:
1142         case Xacid_splash_e:
1143         case Xacid_splash_w:
1144         case Xplant:
1145         case Yplant:
1146         case Zplayer:
1147           Cave[y][x] = Yalien_sB;
1148           Cave[y+1][x] = Yalien_s;
1149           Next[y][x] = Xblank;
1150           Next[y+1][x] = Xalien_pause;
1151           play_element_sound(x, y, SOUND_alien, Xalien);
1152           return;
1153       }
1154     }
1155   }
1156   else
1157   {
1158     if (x < dx)
1159     {
1160       switch (Cave[y][x+1])
1161       {
1162         case Xacid_1:
1163         case Xacid_2:
1164         case Xacid_3:
1165         case Xacid_4:
1166         case Xacid_5:
1167         case Xacid_6:
1168         case Xacid_7:
1169         case Xacid_8:
1170           Cave[y][x] = Yalien_eB;
1171           if (Cave[y-1][x+2] == Xblank)
1172             Cave[y-1][x+2] = Xacid_splash_e;
1173           if (Cave[y-1][x] == Xblank)
1174             Cave[y-1][x] = Xacid_splash_w;
1175           Next[y][x] = Xblank;
1176           play_element_sound(x, y, SOUND_acid, Xacid_1);
1177           return;
1178
1179         case Xblank:
1180         case Xacid_splash_e:
1181         case Xacid_splash_w:
1182         case Xplant:
1183         case Yplant:
1184         case Zplayer:
1185           Cave[y][x] = Yalien_eB;
1186           Cave[y][x+1] = Yalien_e;
1187           Next[y][x] = Xblank;
1188           Next[y][x+1] = Xalien_pause;
1189           play_element_sound(x, y, SOUND_alien, Xalien);
1190           return;
1191       }
1192     }
1193     else if (x > dx)
1194     {
1195       switch (Cave[y][x-1])
1196       {
1197         case Xacid_1:
1198         case Xacid_2:
1199         case Xacid_3:
1200         case Xacid_4:
1201         case Xacid_5:
1202         case Xacid_6:
1203         case Xacid_7:
1204         case Xacid_8:
1205           Cave[y][x] = Yalien_wB;
1206           if (Cave[y-1][x] == Xblank)
1207             Cave[y-1][x] = Xacid_splash_e;
1208           if (Cave[y-1][x-2] == Xblank)
1209             Cave[y-1][x-2] = Xacid_splash_w;
1210           Next[y][x] = Xblank;
1211           play_element_sound(x, y, SOUND_acid, Xacid_1);
1212           return;
1213
1214         case Xblank:
1215         case Xacid_splash_e:
1216         case Xacid_splash_w:
1217         case Xplant:
1218         case Yplant:
1219         case Zplayer:
1220           Cave[y][x] = Yalien_wB;
1221           Cave[y][x-1] = Yalien_w;
1222           Next[y][x] = Xblank;
1223           Next[y][x-1] = Xalien_pause;
1224           play_element_sound(x, y, SOUND_alien, Xalien);
1225           return;
1226       }
1227     }
1228   }
1229 }
1230
1231 static void Lalien_pause(int x, int y)
1232 {
1233   Next[y][x] = Xalien;
1234 }
1235
1236 static void Lbug_n(int x, int y)
1237 {
1238   switch (Cave[y-1][x])
1239   {
1240     case Xacid_1:
1241     case Xacid_2:
1242     case Xacid_3:
1243     case Xacid_4:
1244     case Xacid_5:
1245     case Xacid_6:
1246     case Xacid_7:
1247     case Xacid_8:
1248       Cave[y][x] = Ybug_nB;
1249       if (Cave[y-2][x+1] == Xblank)
1250         Cave[y-2][x+1] = Xacid_splash_e;
1251       if (Cave[y-2][x-1] == Xblank)
1252         Cave[y-2][x-1] = Xacid_splash_w;
1253       Next[y][x] = Xblank;
1254       play_element_sound(x, y, SOUND_acid, Xacid_1);
1255       return;
1256
1257     case Xblank:
1258     case Xacid_splash_e:
1259     case Xacid_splash_w:
1260     case Xplant:
1261     case Yplant:
1262     case Zplayer:
1263       Cave[y][x] = Ybug_nB;
1264       Cave[y-1][x] = Ybug_n;
1265       Next[y][x] = Xblank;
1266       Next[y-1][x] = Xbug_1_n;
1267       play_element_sound(x, y, SOUND_bug, Xbug_1_n);
1268       return;
1269
1270     default:
1271       Cave[y][x] = Ybug_n_w;
1272       Next[y][x] = Xbug_2_w;
1273       play_element_sound(x, y, SOUND_bug, Xbug_1_n);
1274       return;
1275   }
1276 }
1277
1278 static void Lbug_1_n(int x, int y)
1279 {
1280   if (tab_amoeba[Cave[y-1][x]] ||
1281       tab_amoeba[Cave[y][x+1]] ||
1282       tab_amoeba[Cave[y+1][x]] ||
1283       tab_amoeba[Cave[y][x-1]])
1284   {
1285     Lboom_bug(x, y);
1286
1287     return;
1288   }
1289
1290   switch (Cave[y][x+1])
1291   {
1292     case Xblank:
1293     case Xacid_splash_e:
1294     case Xacid_splash_w:
1295     case Xplant:
1296     case Yplant:
1297     case Xacid_1:
1298     case Xacid_2:
1299     case Xacid_3:
1300     case Xacid_4:
1301     case Xacid_5:
1302     case Xacid_6:
1303     case Xacid_7:
1304     case Xacid_8:
1305     case Zplayer:
1306       Cave[y][x] = Ybug_n_e;
1307       Next[y][x] = Xbug_2_e;
1308       play_element_sound(x, y, SOUND_bug, Xbug_1_n);
1309       return;
1310
1311     default:
1312       Lbug_n(x, y);
1313       return;
1314   }
1315 }
1316
1317 static void Lbug_2_n(int x, int y)
1318 {
1319   if (tab_amoeba[Cave[y-1][x]] ||
1320       tab_amoeba[Cave[y][x+1]] ||
1321       tab_amoeba[Cave[y+1][x]] ||
1322       tab_amoeba[Cave[y][x-1]])
1323   {
1324     Lboom_bug(x, y);
1325
1326     return;
1327   }
1328
1329   Lbug_n(x, y);
1330 }
1331
1332 static void Lbug_e(int x, int y)
1333 {
1334   switch (Cave[y][x+1])
1335   {
1336     case Xacid_1:
1337     case Xacid_2:
1338     case Xacid_3:
1339     case Xacid_4:
1340     case Xacid_5:
1341     case Xacid_6:
1342     case Xacid_7:
1343     case Xacid_8:
1344       Cave[y][x] = Ybug_eB;
1345       if (Cave[y-1][x+2] == Xblank)
1346         Cave[y-1][x+2] = Xacid_splash_e;
1347       if (Cave[y-1][x] == Xblank)
1348         Cave[y-1][x] = Xacid_splash_w;
1349       Next[y][x] = Xblank;
1350       play_element_sound(x, y, SOUND_acid, Xacid_1);
1351       return;
1352
1353     case Xblank:
1354     case Xacid_splash_e:
1355     case Xacid_splash_w:
1356     case Xplant:
1357     case Yplant:
1358     case Zplayer:
1359       Cave[y][x] = Ybug_eB;
1360       Cave[y][x+1] = Ybug_e;
1361       Next[y][x] = Xblank;
1362       Next[y][x+1] = Xbug_1_e;
1363       play_element_sound(x, y, SOUND_bug, Xbug_1_e);
1364       return;
1365
1366     default:
1367       Cave[y][x] = Ybug_e_n;
1368       Next[y][x] = Xbug_2_n;
1369       play_element_sound(x, y, SOUND_bug, Xbug_1_e);
1370       return;
1371   }
1372 }
1373
1374 static void Lbug_1_e(int x, int y)
1375 {
1376   if (tab_amoeba[Cave[y-1][x]] ||
1377       tab_amoeba[Cave[y][x+1]] ||
1378       tab_amoeba[Cave[y+1][x]] ||
1379       tab_amoeba[Cave[y][x-1]])
1380   {
1381     Lboom_bug(x, y);
1382
1383     return;
1384   }
1385
1386   switch (Cave[y+1][x])
1387   {
1388     case Xblank:
1389     case Xacid_splash_e:
1390     case Xacid_splash_w:
1391     case Xplant:
1392     case Yplant:
1393     case Xacid_1:
1394     case Xacid_2:
1395     case Xacid_3:
1396     case Xacid_4:
1397     case Xacid_5:
1398     case Xacid_6:
1399     case Xacid_7:
1400     case Xacid_8:
1401     case Zplayer:
1402       Cave[y][x] = Ybug_e_s;
1403       Next[y][x] = Xbug_2_s;
1404       play_element_sound(x, y, SOUND_bug, Xbug_1_e);
1405       return;
1406
1407     default:
1408       Lbug_e(x, y);
1409       return;
1410   }
1411 }
1412
1413 static void Lbug_2_e(int x, int y)
1414 {
1415   if (tab_amoeba[Cave[y-1][x]] ||
1416       tab_amoeba[Cave[y][x+1]] ||
1417       tab_amoeba[Cave[y+1][x]] ||
1418       tab_amoeba[Cave[y][x-1]])
1419   {
1420     Lboom_bug(x, y);
1421
1422     return;
1423   }
1424
1425   Lbug_e(x, y);
1426 }
1427
1428 static void Lbug_s(int x, int y)
1429 {
1430   switch (Cave[y+1][x])
1431   {
1432     case Xacid_1:
1433     case Xacid_2:
1434     case Xacid_3:
1435     case Xacid_4:
1436     case Xacid_5:
1437     case Xacid_6:
1438     case Xacid_7:
1439     case Xacid_8:
1440       Cave[y][x] = Ybug_sB;
1441       if (Cave[y][x+1] == Xblank)
1442         Cave[y][x+1] = Xacid_splash_e;
1443       if (Cave[y][x-1] == Xblank)
1444         Cave[y][x-1] = Xacid_splash_w;
1445       Next[y][x] = Xblank;
1446       play_element_sound(x, y, SOUND_acid, Xacid_1);
1447       return;
1448
1449     case Xblank:
1450     case Xacid_splash_e:
1451     case Xacid_splash_w:
1452     case Xplant:
1453     case Yplant:
1454     case Zplayer:
1455       Cave[y][x] = Ybug_sB;
1456       Cave[y+1][x] = Ybug_s;
1457       Next[y][x] = Xblank;
1458       Next[y+1][x] = Xbug_1_s;
1459       play_element_sound(x, y, SOUND_bug, Xbug_1_s);
1460       return;
1461
1462     default:
1463       Cave[y][x] = Ybug_s_e;
1464       Next[y][x] = Xbug_2_e;
1465       play_element_sound(x, y, SOUND_bug, Xbug_1_s);
1466       return;
1467   }
1468 }
1469
1470 static void Lbug_1_s(int x, int y)
1471 {
1472   if (tab_amoeba[Cave[y-1][x]] ||
1473       tab_amoeba[Cave[y][x+1]] ||
1474       tab_amoeba[Cave[y+1][x]] ||
1475       tab_amoeba[Cave[y][x-1]])
1476   {
1477     Lboom_bug(x, y);
1478
1479     return;
1480   }
1481
1482   switch (Cave[y][x-1])
1483   {
1484     case Xblank:
1485     case Xacid_splash_e:
1486     case Xacid_splash_w:
1487     case Xplant:
1488     case Yplant:
1489     case Xacid_1:
1490     case Xacid_2:
1491     case Xacid_3:
1492     case Xacid_4:
1493     case Xacid_5:
1494     case Xacid_6:
1495     case Xacid_7:
1496     case Xacid_8:
1497     case Zplayer:
1498       Cave[y][x] = Ybug_s_w;
1499       Next[y][x] = Xbug_2_w;
1500       play_element_sound(x, y, SOUND_bug, Xbug_1_s);
1501       return;
1502
1503     default:
1504       Lbug_s(x, y);
1505       return;
1506   }
1507 }
1508
1509 static void Lbug_2_s(int x, int y)
1510 {
1511   if (tab_amoeba[Cave[y-1][x]] ||
1512       tab_amoeba[Cave[y][x+1]] ||
1513       tab_amoeba[Cave[y+1][x]] ||
1514       tab_amoeba[Cave[y][x-1]])
1515   {
1516     Lboom_bug(x, y);
1517
1518     return;
1519   }
1520
1521   Lbug_s(x, y);
1522 }
1523
1524 static void Lbug_w(int x, int y)
1525 {
1526   switch (Cave[y][x-1])
1527   {
1528     case Xacid_1:
1529     case Xacid_2:
1530     case Xacid_3:
1531     case Xacid_4:
1532     case Xacid_5:
1533     case Xacid_6:
1534     case Xacid_7:
1535     case Xacid_8:
1536       Cave[y][x] = Ybug_wB;
1537       if (Cave[y-1][x] == Xblank)
1538         Cave[y-1][x] = Xacid_splash_e;
1539       if (Cave[y-1][x-2] == Xblank)
1540         Cave[y-1][x-2] = Xacid_splash_w;
1541       Next[y][x] = Xblank;
1542       play_element_sound(x, y, SOUND_acid, Xacid_1);
1543       return;
1544
1545     case Xblank:
1546     case Xacid_splash_e:
1547     case Xacid_splash_w:
1548     case Xplant:
1549     case Yplant:
1550     case Zplayer:
1551       Cave[y][x] = Ybug_wB;
1552       Cave[y][x-1] = Ybug_w;
1553       Next[y][x] = Xblank;
1554       Next[y][x-1] = Xbug_1_w;
1555       play_element_sound(x, y, SOUND_bug, Xbug_1_w);
1556       return;
1557
1558     default:
1559       Cave[y][x] = Ybug_w_s;
1560       Next[y][x] = Xbug_2_s;
1561       play_element_sound(x, y, SOUND_bug, Xbug_1_w);
1562       return;
1563   }
1564 }
1565
1566 static void Lbug_1_w(int x, int y)
1567 {
1568   if (tab_amoeba[Cave[y-1][x]] ||
1569       tab_amoeba[Cave[y][x+1]] ||
1570       tab_amoeba[Cave[y+1][x]] ||
1571       tab_amoeba[Cave[y][x-1]])
1572   {
1573     Lboom_bug(x, y);
1574
1575     return;
1576   }
1577
1578   switch (Cave[y-1][x])
1579   {
1580     case Xblank:
1581     case Xacid_splash_e:
1582     case Xacid_splash_w:
1583     case Xplant:
1584     case Yplant:
1585     case Xacid_1:
1586     case Xacid_2:
1587     case Xacid_3:
1588     case Xacid_4:
1589     case Xacid_5:
1590     case Xacid_6:
1591     case Xacid_7:
1592     case Xacid_8:
1593     case Zplayer:
1594       Cave[y][x] = Ybug_w_n;
1595       Next[y][x] = Xbug_2_n;
1596       play_element_sound(x, y, SOUND_bug, Xbug_1_w);
1597       return;
1598
1599     default:
1600       Lbug_w(x, y);
1601       return;
1602   }
1603 }
1604
1605 static void Lbug_2_w(int x, int y)
1606 {
1607   if (tab_amoeba[Cave[y-1][x]] ||
1608       tab_amoeba[Cave[y][x+1]] ||
1609       tab_amoeba[Cave[y+1][x]] ||
1610       tab_amoeba[Cave[y][x-1]])
1611   {
1612     Lboom_bug(x, y);
1613
1614     return;
1615   }
1616
1617   Lbug_w(x, y);
1618 }
1619
1620 static void Ltank_n(int x, int y)
1621 {
1622   switch (Cave[y-1][x])
1623   {
1624     case Xacid_1:
1625     case Xacid_2:
1626     case Xacid_3:
1627     case Xacid_4:
1628     case Xacid_5:
1629     case Xacid_6:
1630     case Xacid_7:
1631     case Xacid_8:
1632       Cave[y][x] = Ytank_nB;
1633       if (Cave[y-2][x+1] == Xblank)
1634         Cave[y-2][x+1] = Xacid_splash_e;
1635       if (Cave[y-2][x-1] == Xblank)
1636         Cave[y-2][x-1] = Xacid_splash_w;
1637       Next[y][x] = Xblank;
1638       play_element_sound(x, y, SOUND_acid, Xacid_1);
1639       return;
1640
1641     case Xblank:
1642     case Xacid_splash_e:
1643     case Xacid_splash_w:
1644     case Xplant:
1645     case Yplant:
1646     case Zplayer:
1647       Cave[y][x] = Ytank_nB;
1648       Cave[y-1][x] = Ytank_n;
1649       Next[y][x] = Xblank;
1650       Next[y-1][x] = Xtank_1_n;
1651       play_element_sound(x, y, SOUND_tank, Xtank_1_n);
1652       return;
1653
1654     default:
1655       Cave[y][x] = Ytank_n_e;
1656       Next[y][x] = Xtank_2_e;
1657       play_element_sound(x, y, SOUND_tank, Xtank_1_n);
1658       return;
1659   }
1660 }
1661
1662 static void Ltank_1_n(int x, int y)
1663 {
1664   if (tab_amoeba[Cave[y-1][x]] ||
1665       tab_amoeba[Cave[y][x+1]] ||
1666       tab_amoeba[Cave[y+1][x]] ||
1667       tab_amoeba[Cave[y][x-1]])
1668   {
1669     Lboom_tank(x, y);
1670
1671     return;
1672   }
1673
1674   switch (Cave[y][x-1])
1675   {
1676     case Xblank:
1677     case Xacid_splash_e:
1678     case Xacid_splash_w:
1679     case Xplant:
1680     case Yplant:
1681     case Xacid_1:
1682     case Xacid_2:
1683     case Xacid_3:
1684     case Xacid_4:
1685     case Xacid_5:
1686     case Xacid_6:
1687     case Xacid_7:
1688     case Xacid_8:
1689     case Zplayer:
1690       Cave[y][x] = Ytank_n_w;
1691       Next[y][x] = Xtank_2_w;
1692       play_element_sound(x, y, SOUND_tank, Xtank_1_n);
1693       return;
1694
1695     default:
1696       Ltank_n(x, y);
1697       return;
1698   }
1699 }
1700
1701 static void Ltank_2_n(int x, int y)
1702 {
1703   if (tab_amoeba[Cave[y-1][x]] ||
1704       tab_amoeba[Cave[y][x+1]] ||
1705       tab_amoeba[Cave[y+1][x]] ||
1706       tab_amoeba[Cave[y][x-1]])
1707   {
1708     Lboom_tank(x, y);
1709
1710     return;
1711   }
1712
1713   Ltank_n(x, y);
1714 }
1715
1716 static void Ltank_e(int x, int y)
1717 {
1718   switch (Cave[y][x+1])
1719   {
1720     case Xacid_1:
1721     case Xacid_2:
1722     case Xacid_3:
1723     case Xacid_4:
1724     case Xacid_5:
1725     case Xacid_6:
1726     case Xacid_7:
1727     case Xacid_8:
1728       Cave[y][x] = Ytank_eB;
1729       if (Cave[y-1][x+2] == Xblank)
1730         Cave[y-1][x+2] = Xacid_splash_e;
1731       if (Cave[y-1][x] == Xblank)
1732         Cave[y-1][x] = Xacid_splash_w;
1733       Next[y][x] = Xblank;
1734       play_element_sound(x, y, SOUND_acid, Xacid_1);
1735       return;
1736
1737     case Xblank:
1738     case Xacid_splash_e:
1739     case Xacid_splash_w:
1740     case Xplant:
1741     case Yplant:
1742     case Zplayer:
1743       Cave[y][x] = Ytank_eB;
1744       Cave[y][x+1] = Ytank_e;
1745       Next[y][x] = Xblank;
1746       Next[y][x+1] = Xtank_1_e;
1747       play_element_sound(x, y, SOUND_tank, Xtank_1_e);
1748       return;
1749
1750     default:
1751       Cave[y][x] = Ytank_e_s;
1752       Next[y][x] = Xtank_2_s;
1753       play_element_sound(x, y, SOUND_tank, Xtank_1_e);
1754       return;
1755   }
1756 }
1757
1758 static void Ltank_1_e(int x, int y)
1759 {
1760   if (tab_amoeba[Cave[y-1][x]] ||
1761       tab_amoeba[Cave[y][x+1]] ||
1762       tab_amoeba[Cave[y+1][x]] ||
1763       tab_amoeba[Cave[y][x-1]])
1764   {
1765     Lboom_tank(x, y);
1766
1767     return;
1768   }
1769
1770   switch (Cave[y-1][x])
1771   {
1772     case Xblank:
1773     case Xacid_splash_e:
1774     case Xacid_splash_w:
1775     case Xplant:
1776     case Yplant:
1777     case Xacid_1:
1778     case Xacid_2:
1779     case Xacid_3:
1780     case Xacid_4:
1781     case Xacid_5:
1782     case Xacid_6:
1783     case Xacid_7:
1784     case Xacid_8:
1785     case Zplayer:
1786       Cave[y][x] = Ytank_e_n;
1787       Next[y][x] = Xtank_2_n;
1788       play_element_sound(x, y, SOUND_tank, Xtank_1_e);
1789       return;
1790
1791     default:
1792       Ltank_e(x, y);
1793       return;
1794   }
1795 }
1796
1797 static void Ltank_2_e(int x, int y)
1798 {
1799   if (tab_amoeba[Cave[y-1][x]] ||
1800       tab_amoeba[Cave[y][x+1]] ||
1801       tab_amoeba[Cave[y+1][x]] ||
1802       tab_amoeba[Cave[y][x-1]])
1803   {
1804     Lboom_tank(x, y);
1805
1806     return;
1807   }
1808
1809   Ltank_e(x, y);
1810 }
1811
1812 static void Ltank_s(int x, int y)
1813 {
1814   switch (Cave[y+1][x])
1815   {
1816     case Xacid_1:
1817     case Xacid_2:
1818     case Xacid_3:
1819     case Xacid_4:
1820     case Xacid_5:
1821     case Xacid_6:
1822     case Xacid_7:
1823     case Xacid_8:
1824       Cave[y][x] = Ytank_sB;
1825       if (Cave[y][x+1] == Xblank)
1826         Cave[y][x+1] = Xacid_splash_e;
1827       if (Cave[y][x-1] == Xblank)
1828         Cave[y][x-1] = Xacid_splash_w;
1829       Next[y][x] = Xblank;
1830       play_element_sound(x, y, SOUND_acid, Xacid_1);
1831       return;
1832
1833     case Xblank:
1834     case Xacid_splash_e:
1835     case Xacid_splash_w:
1836     case Xplant:
1837     case Yplant:
1838     case Zplayer:
1839       Cave[y][x] = Ytank_sB;
1840       Cave[y+1][x] = Ytank_s;
1841       Next[y][x] = Xblank;
1842       Next[y+1][x] = Xtank_1_s;
1843       play_element_sound(x, y, SOUND_tank, Xtank_1_s);
1844       return;
1845
1846     default:
1847       Cave[y][x] = Ytank_s_w;
1848       Next[y][x] = Xtank_2_w;
1849       play_element_sound(x, y, SOUND_tank, Xtank_1_s);
1850       return;
1851   }
1852 }
1853
1854 static void Ltank_1_s(int x, int y)
1855 {
1856   if (tab_amoeba[Cave[y-1][x]] ||
1857       tab_amoeba[Cave[y][x+1]] ||
1858       tab_amoeba[Cave[y+1][x]] ||
1859       tab_amoeba[Cave[y][x-1]])
1860   {
1861     Lboom_tank(x, y);
1862
1863     return;
1864   }
1865
1866   switch (Cave[y][x+1])
1867   {
1868     case Xblank:
1869     case Xacid_splash_e:
1870     case Xacid_splash_w:
1871     case Xplant:
1872     case Yplant:
1873     case Xacid_1:
1874     case Xacid_2:
1875     case Xacid_3:
1876     case Xacid_4:
1877     case Xacid_5:
1878     case Xacid_6:
1879     case Xacid_7:
1880     case Xacid_8:
1881     case Zplayer:
1882       Cave[y][x] = Ytank_s_e;
1883       Next[y][x] = Xtank_2_e;
1884       play_element_sound(x, y, SOUND_tank, Xtank_1_s);
1885       return;
1886
1887     default:
1888       Ltank_s(x, y);
1889       return;
1890   }
1891 }
1892
1893 static void Ltank_2_s(int x, int y)
1894 {
1895   if (tab_amoeba[Cave[y-1][x]] ||
1896       tab_amoeba[Cave[y][x+1]] ||
1897       tab_amoeba[Cave[y+1][x]] ||
1898       tab_amoeba[Cave[y][x-1]])
1899   {
1900     Lboom_tank(x, y);
1901
1902     return;
1903   }
1904
1905   Ltank_s(x, y);
1906 }
1907
1908 static void Ltank_w(int x, int y)
1909 {
1910   switch (Cave[y][x-1])
1911   {
1912     case Xacid_1:
1913     case Xacid_2:
1914     case Xacid_3:
1915     case Xacid_4:
1916     case Xacid_5:
1917     case Xacid_6:
1918     case Xacid_7:
1919     case Xacid_8:
1920       Cave[y][x] = Ytank_wB;
1921       if (Cave[y-1][x] == Xblank)
1922         Cave[y-1][x] = Xacid_splash_e;
1923       if (Cave[y-1][x-2] == Xblank)
1924         Cave[y-1][x-2] = Xacid_splash_w;
1925       Next[y][x] = Xblank;
1926       play_element_sound(x, y, SOUND_acid, Xacid_1);
1927       return;
1928
1929     case Xblank:
1930     case Xacid_splash_e:
1931     case Xacid_splash_w:
1932     case Xplant:
1933     case Yplant:
1934     case Zplayer:
1935       Cave[y][x] = Ytank_wB;
1936       Cave[y][x-1] = Ytank_w;
1937       Next[y][x] = Xblank;
1938       Next[y][x-1] = Xtank_1_w;
1939       play_element_sound(x, y, SOUND_tank, Xtank_1_w);
1940       return;
1941
1942     default:
1943       Cave[y][x] = Ytank_w_n;
1944       Next[y][x] = Xtank_2_n;
1945       play_element_sound(x, y, SOUND_tank, Xtank_1_w);
1946       return;
1947   }
1948 }
1949
1950 static void Ltank_1_w(int x, int y)
1951 {
1952   if (tab_amoeba[Cave[y-1][x]] ||
1953       tab_amoeba[Cave[y][x+1]] ||
1954       tab_amoeba[Cave[y+1][x]] ||
1955       tab_amoeba[Cave[y][x-1]])
1956   {
1957     Lboom_tank(x, y);
1958
1959     return;
1960   }
1961
1962   switch (Cave[y+1][x])
1963   {
1964     case Xblank:
1965     case Xacid_splash_e:
1966     case Xacid_splash_w:
1967     case Xplant:
1968     case Yplant:
1969     case Xacid_1:
1970     case Xacid_2:
1971     case Xacid_3:
1972     case Xacid_4:
1973     case Xacid_5:
1974     case Xacid_6:
1975     case Xacid_7:
1976     case Xacid_8:
1977     case Zplayer:
1978       Cave[y][x] = Ytank_w_s;
1979       Next[y][x] = Xtank_2_s;
1980       play_element_sound(x, y, SOUND_tank, Xtank_1_w);
1981       return;
1982
1983     default:
1984       Ltank_w(x, y);
1985       return;
1986   }
1987 }
1988
1989 static void Ltank_2_w(int x, int y)
1990 {
1991   if (tab_amoeba[Cave[y-1][x]] ||
1992       tab_amoeba[Cave[y][x+1]] ||
1993       tab_amoeba[Cave[y+1][x]] ||
1994       tab_amoeba[Cave[y][x-1]])
1995   {
1996     Lboom_tank(x, y);
1997
1998     return;
1999   }
2000
2001   Ltank_w(x, y);
2002 }
2003
2004 static void Lemerald(int x, int y)
2005 {
2006   switch (Cave[y+1][x])
2007   {
2008     case Xacid_1:
2009     case Xacid_2:
2010     case Xacid_3:
2011     case Xacid_4:
2012     case Xacid_5:
2013     case Xacid_6:
2014     case Xacid_7:
2015     case Xacid_8:
2016       Cave[y][x] = Yemerald_sB;
2017       if (Cave[y][x+1] == Xblank)
2018         Cave[y][x+1] = Xacid_splash_e;
2019       if (Cave[y][x-1] == Xblank)
2020         Cave[y][x-1] = Xacid_splash_w;
2021       Next[y][x] = Xblank;
2022       play_element_sound(x, y, SOUND_acid, Xacid_1);
2023       return;
2024
2025     case Xblank:
2026     case Xacid_splash_e:
2027     case Xacid_splash_w:
2028       Cave[y][x] = Yemerald_sB;
2029       Cave[y+1][x] = Yemerald_s;
2030       Next[y][x] = Xblank;
2031       Next[y+1][x] = Xemerald_fall;
2032       return;
2033
2034     case Xspring:
2035     case Xspring_pause:
2036     case Xspring_e:
2037     case Xspring_w:
2038     case Xandroid:
2039     case Xandroid_1_n:
2040     case Xandroid_2_n:
2041     case Xandroid_1_e:
2042     case Xandroid_2_e:
2043     case Xandroid_1_s:
2044     case Xandroid_2_s:
2045     case Xandroid_1_w:
2046     case Xandroid_2_w:
2047     case Xstone:
2048     case Xstone_pause:
2049     case Xemerald:
2050     case Xemerald_pause:
2051     case Xdiamond:
2052     case Xdiamond_pause:
2053     case Xbomb:
2054     case Xbomb_pause:
2055     case Xballoon:
2056     case Xacid_ne:
2057     case Xacid_nw:
2058     case Xball_1:
2059     case Xball_2:
2060     case Xnut:
2061     case Xnut_pause:
2062     case Xslidewall_ns:
2063     case Xslidewall_ew:
2064     case Xwonderwall:
2065     case Xkey_1:
2066     case Xkey_2:
2067     case Xkey_3:
2068     case Xkey_4:
2069     case Xkey_5:
2070     case Xkey_6:
2071     case Xkey_7:
2072     case Xkey_8:
2073     case Xbumper:
2074     case Xswitch:
2075     case Xsteel_1:
2076     case Xsteel_2:
2077     case Xsteel_3:
2078     case Xsteel_4:
2079     case Xwall_1:
2080     case Xwall_2:
2081     case Xwall_3:
2082     case Xwall_4:
2083     case Xroundwall_1:
2084     case Xroundwall_2:
2085     case Xroundwall_3:
2086     case Xroundwall_4:
2087       if (RANDOM & 1)
2088       {
2089         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
2090         {
2091           Cave[y][x] = Yemerald_eB;
2092           Cave[y][x+1] = Yemerald_e;
2093           Next[y][x] = Xblank;
2094           Next[y][x+1] = Xemerald_pause;
2095           return;
2096         }
2097
2098         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
2099         {
2100           Cave[y][x] = Yemerald_wB;
2101           Cave[y][x-1] = Yemerald_w;
2102           Next[y][x] = Xblank;
2103           Next[y][x-1] = Xemerald_pause;
2104           return;
2105         }
2106       }
2107       else
2108       {
2109         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
2110         {
2111           Cave[y][x] = Yemerald_wB;
2112           Cave[y][x-1] = Yemerald_w;
2113           Next[y][x] = Xblank;
2114           Next[y][x-1] = Xemerald_pause;
2115           return;
2116         }
2117
2118         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
2119         {
2120           Cave[y][x] = Yemerald_eB;
2121           Cave[y][x+1] = Yemerald_e;
2122           Next[y][x] = Xblank;
2123           Next[y][x+1] = Xemerald_pause;
2124           return;
2125         }
2126       }
2127
2128     default:
2129       if (++lev.shine_cnt > 50)
2130       {
2131         lev.shine_cnt = RANDOM & 7;
2132         Cave[y][x] = Xemerald_shine;
2133       }
2134
2135       return;
2136   }
2137 }
2138
2139 static void Lemerald_pause(int x, int y)
2140 {
2141   switch (Cave[y+1][x])
2142   {
2143     case Xacid_1:
2144     case Xacid_2:
2145     case Xacid_3:
2146     case Xacid_4:
2147     case Xacid_5:
2148     case Xacid_6:
2149     case Xacid_7:
2150     case Xacid_8:
2151       Cave[y][x] = Yemerald_sB;
2152       if (Cave[y][x+1] == Xblank)
2153         Cave[y][x+1] = Xacid_splash_e;
2154       if (Cave[y][x-1] == Xblank)
2155         Cave[y][x-1] = Xacid_splash_w;
2156       Next[y][x] = Xblank;
2157       play_element_sound(x, y, SOUND_acid, Xacid_1);
2158       return;
2159
2160     case Xblank:
2161     case Xacid_splash_e:
2162     case Xacid_splash_w:
2163       Cave[y][x] = Yemerald_sB;
2164       Cave[y+1][x] = Yemerald_s;
2165       Next[y][x] = Xblank;
2166       Next[y+1][x] = Xemerald_fall;
2167       return;
2168
2169     default:
2170       Cave[y][x] = Xemerald;
2171       Next[y][x] = Xemerald;
2172       return;
2173   }
2174 }
2175
2176 static void Lemerald_fall(int x, int y)
2177 {
2178   switch (Cave[y+1][x])
2179   {
2180     case Xacid_1:
2181     case Xacid_2:
2182     case Xacid_3:
2183     case Xacid_4:
2184     case Xacid_5:
2185     case Xacid_6:
2186     case Xacid_7:
2187     case Xacid_8:
2188       Cave[y][x] = Yemerald_sB;
2189       if (Cave[y][x+1] == Xblank)
2190         Cave[y][x+1] = Xacid_splash_e;
2191       if (Cave[y][x-1] == Xblank)
2192         Cave[y][x-1] = Xacid_splash_w;
2193       Next[y][x] = Xblank;
2194       play_element_sound(x, y, SOUND_acid, Xacid_1);
2195       return;
2196
2197     case Xblank:
2198     case Xacid_splash_e:
2199     case Xacid_splash_w:
2200     case Zplayer:
2201       Cave[y][x] = Yemerald_sB;
2202       Cave[y+1][x] = Yemerald_s;
2203       Next[y][x] = Xblank;
2204       Next[y+1][x] = Xemerald_fall;
2205       return;
2206
2207     case Xwonderwall:
2208       if (lev.wonderwall_time)
2209       {
2210         lev.wonderwall_state = 1;
2211         Cave[y][x] = Yemerald_sB;
2212         if (tab_blank[Cave[y+2][x]])
2213         {
2214           Cave[y+2][x] = Ydiamond_s;
2215           Next[y+2][x] = Xdiamond_fall;
2216         }
2217
2218         Next[y][x] = Xblank;
2219         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
2220         return;
2221       }
2222
2223     default:
2224       Cave[y][x] = Xemerald;
2225       Next[y][x] = Xemerald;
2226       play_element_sound(x, y, SOUND_diamond, Xemerald);
2227       return;
2228   }
2229 }
2230
2231 static void Ldiamond(int x, int y)
2232 {
2233   switch (Cave[y+1][x])
2234   {
2235     case Xacid_1:
2236     case Xacid_2:
2237     case Xacid_3:
2238     case Xacid_4:
2239     case Xacid_5:
2240     case Xacid_6:
2241     case Xacid_7:
2242     case Xacid_8:
2243       Cave[y][x] = Ydiamond_sB;
2244       if (Cave[y][x+1] == Xblank)
2245         Cave[y][x+1] = Xacid_splash_e;
2246       if (Cave[y][x-1] == Xblank)
2247         Cave[y][x-1] = Xacid_splash_w;
2248       Next[y][x] = Xblank;
2249       play_element_sound(x, y, SOUND_acid, Xacid_1);
2250       return;
2251
2252     case Xblank:
2253     case Xacid_splash_e:
2254     case Xacid_splash_w:
2255       Cave[y][x] = Ydiamond_sB;
2256       Cave[y+1][x] = Ydiamond_s;
2257       Next[y][x] = Xblank;
2258       Next[y+1][x] = Xdiamond_fall;
2259       return;
2260
2261     case Xspring:
2262     case Xspring_pause:
2263     case Xspring_e:
2264     case Xspring_w:
2265     case Xandroid:
2266     case Xandroid_1_n:
2267     case Xandroid_2_n:
2268     case Xandroid_1_e:
2269     case Xandroid_2_e:
2270     case Xandroid_1_s:
2271     case Xandroid_2_s:
2272     case Xandroid_1_w:
2273     case Xandroid_2_w:
2274     case Xstone:
2275     case Xstone_pause:
2276     case Xemerald:
2277     case Xemerald_pause:
2278     case Xdiamond:
2279     case Xdiamond_pause:
2280     case Xbomb:
2281     case Xbomb_pause:
2282     case Xballoon:
2283     case Xacid_ne:
2284     case Xacid_nw:
2285     case Xball_1:
2286     case Xball_2:
2287     case Xnut:
2288     case Xnut_pause:
2289     case Xslidewall_ns:
2290     case Xslidewall_ew:
2291     case Xwonderwall:
2292     case Xkey_1:
2293     case Xkey_2:
2294     case Xkey_3:
2295     case Xkey_4:
2296     case Xkey_5:
2297     case Xkey_6:
2298     case Xkey_7:
2299     case Xkey_8:
2300     case Xbumper:
2301     case Xswitch:
2302     case Xsteel_1:
2303     case Xsteel_2:
2304     case Xsteel_3:
2305     case Xsteel_4:
2306     case Xwall_1:
2307     case Xwall_2:
2308     case Xwall_3:
2309     case Xwall_4:
2310     case Xroundwall_1:
2311     case Xroundwall_2:
2312     case Xroundwall_3:
2313     case Xroundwall_4:
2314       if (RANDOM & 1)
2315       {
2316         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
2317         {
2318           Cave[y][x] = Ydiamond_eB;
2319           Cave[y][x+1] = Ydiamond_e;
2320           Next[y][x] = Xblank;
2321           Next[y][x+1] = Xdiamond_pause;
2322           return;
2323         }
2324
2325         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
2326         {
2327           Cave[y][x] = Ydiamond_wB;
2328           Cave[y][x-1] = Ydiamond_w;
2329           Next[y][x] = Xblank;
2330           Next[y][x-1] = Xdiamond_pause;
2331           return;
2332         }
2333       }
2334       else
2335       {
2336         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
2337         {
2338           Cave[y][x] = Ydiamond_wB;
2339           Cave[y][x-1] = Ydiamond_w;
2340           Next[y][x] = Xblank;
2341           Next[y][x-1] = Xdiamond_pause;
2342           return;
2343         }
2344
2345         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
2346         {
2347           Cave[y][x] = Ydiamond_eB;
2348           Cave[y][x+1] = Ydiamond_e;
2349           Next[y][x] = Xblank;
2350           Next[y][x+1] = Xdiamond_pause;
2351           return;
2352         }
2353       }
2354
2355     default:
2356       if (++lev.shine_cnt > 50)
2357       {
2358         lev.shine_cnt = RANDOM & 7;
2359         Cave[y][x] = Xdiamond_shine;
2360       }
2361
2362       return;
2363   }
2364 }
2365
2366 static void Ldiamond_pause(int x, int y)
2367 {
2368   switch (Cave[y+1][x])
2369   {
2370     case Xacid_1:
2371     case Xacid_2:
2372     case Xacid_3:
2373     case Xacid_4:
2374     case Xacid_5:
2375     case Xacid_6:
2376     case Xacid_7:
2377     case Xacid_8:
2378       Cave[y][x] = Ydiamond_sB;
2379       if (Cave[y][x+1] == Xblank)
2380         Cave[y][x+1] = Xacid_splash_e;
2381       if (Cave[y][x-1] == Xblank)
2382         Cave[y][x-1] = Xacid_splash_w;
2383       Next[y][x] = Xblank;
2384       play_element_sound(x, y, SOUND_acid, Xacid_1);
2385       return;
2386
2387     case Xblank:
2388     case Xacid_splash_e:
2389     case Xacid_splash_w:
2390       Cave[y][x] = Ydiamond_sB;
2391       Cave[y+1][x] = Ydiamond_s;
2392       Next[y][x] = Xblank;
2393       Next[y+1][x] = Xdiamond_fall;
2394       return;
2395
2396     default:
2397       Cave[y][x] = Xdiamond;
2398       Next[y][x] = Xdiamond;
2399       return;
2400   }
2401 }
2402
2403 static void Ldiamond_fall(int x, int y)
2404 {
2405   switch (Cave[y+1][x])
2406   {
2407     case Xacid_1:
2408     case Xacid_2:
2409     case Xacid_3:
2410     case Xacid_4:
2411     case Xacid_5:
2412     case Xacid_6:
2413     case Xacid_7:
2414     case Xacid_8:
2415       Cave[y][x] = Ydiamond_sB;
2416       if (Cave[y][x+1] == Xblank)
2417         Cave[y][x+1] = Xacid_splash_e;
2418       if (Cave[y][x-1] == Xblank)
2419         Cave[y][x-1] = Xacid_splash_w;
2420       Next[y][x] = Xblank;
2421       play_element_sound(x, y, SOUND_acid, Xacid_1);
2422       return;
2423
2424     case Xblank:
2425     case Xacid_splash_e:
2426     case Xacid_splash_w:
2427     case Zplayer:
2428       Cave[y][x] = Ydiamond_sB;
2429       Cave[y+1][x] = Ydiamond_s;
2430       Next[y][x] = Xblank;
2431       Next[y+1][x] = Xdiamond_fall;
2432       return;
2433
2434     case Xwonderwall:
2435       if (lev.wonderwall_time)
2436       {
2437         lev.wonderwall_state = 1;
2438         Cave[y][x] = Ydiamond_sB;
2439         if (tab_blank[Cave[y+2][x]])
2440         {
2441           Cave[y+2][x] = Ystone_s;
2442           Next[y+2][x] = Xstone_fall;
2443         }
2444
2445         Next[y][x] = Xblank;
2446         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
2447         return;
2448       }
2449
2450     default:
2451       Cave[y][x] = Xdiamond;
2452       Next[y][x] = Xdiamond;
2453       play_element_sound(x, y, SOUND_diamond, Xdiamond);
2454       return;
2455   }
2456 }
2457
2458 static void Lstone(int x, int y)
2459 {
2460   switch (Cave[y+1][x])
2461   {
2462     case Xacid_1:
2463     case Xacid_2:
2464     case Xacid_3:
2465     case Xacid_4:
2466     case Xacid_5:
2467     case Xacid_6:
2468     case Xacid_7:
2469     case Xacid_8:
2470       Cave[y][x] = Ystone_sB;
2471       if (Cave[y][x+1] == Xblank)
2472         Cave[y][x+1] = Xacid_splash_e;
2473       if (Cave[y][x-1] == Xblank)
2474         Cave[y][x-1] = Xacid_splash_w;
2475       Next[y][x] = Xblank;
2476       play_element_sound(x, y, SOUND_acid, Xacid_1);
2477       return;
2478
2479     case Xblank:
2480     case Xacid_splash_e:
2481     case Xacid_splash_w:
2482     case Xplant:
2483     case Yplant:
2484 #if 1
2485     case Xfake_acid_1:
2486     case Xfake_acid_2:
2487     case Xfake_acid_3:
2488     case Xfake_acid_4:
2489     case Xfake_acid_5:
2490     case Xfake_acid_6:
2491     case Xfake_acid_7:
2492     case Xfake_acid_8:
2493 #endif
2494       Cave[y][x] = Ystone_sB;
2495       Cave[y+1][x] = Ystone_s;
2496       Next[y][x] = Xblank;
2497       Next[y+1][x] = Xstone_fall;
2498       return;
2499
2500     case Xsand:
2501       Cave[y][x] = Xsand_stonein_1;
2502       Cave[y+1][x] = Xsand_sandstone_1;
2503       Next[y][x] = Xsand_stonein_2;
2504       Next[y+1][x] = Xsand_sandstone_2;
2505       return;
2506
2507     case Xspring:
2508     case Xspring_pause:
2509     case Xspring_e:
2510     case Xspring_w:
2511     case Xandroid:
2512     case Xandroid_1_n:
2513     case Xandroid_2_n:
2514     case Xandroid_1_e:
2515     case Xandroid_2_e:
2516     case Xandroid_1_s:
2517     case Xandroid_2_s:
2518     case Xandroid_1_w:
2519     case Xandroid_2_w:
2520     case Xstone:
2521     case Xstone_pause:
2522     case Xemerald:
2523     case Xemerald_pause:
2524     case Xdiamond:
2525     case Xdiamond_pause:
2526     case Xbomb:
2527     case Xbomb_pause:
2528     case Xballoon:
2529     case Xacid_ne:
2530     case Xacid_nw:
2531     case Xball_1:
2532     case Xball_2:
2533     case Xnut:
2534     case Xnut_pause:
2535     case Xslidewall_ns:
2536     case Xslidewall_ew:
2537     case Xkey_1:
2538     case Xkey_2:
2539     case Xkey_3:
2540     case Xkey_4:
2541     case Xkey_5:
2542     case Xkey_6:
2543     case Xkey_7:
2544     case Xkey_8:
2545     case Xbumper:
2546     case Xswitch:
2547     case Xlenses:
2548     case Xmagnify:
2549     case Xroundwall_1:
2550     case Xroundwall_2:
2551     case Xroundwall_3:
2552     case Xroundwall_4:
2553       if (RANDOM & 1)
2554       {
2555         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
2556         {
2557           Cave[y][x] = Ystone_eB;
2558           Cave[y][x+1] = Ystone_e;
2559           Next[y][x] = Xblank;
2560           Next[y][x+1] = Xstone_pause;
2561           return;
2562         }
2563
2564         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
2565         {
2566           Cave[y][x] = Ystone_wB;
2567           Cave[y][x-1] = Ystone_w;
2568           Next[y][x] = Xblank;
2569           Next[y][x-1] = Xstone_pause;
2570           return;
2571         }
2572       }
2573       else
2574       {
2575         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
2576         {
2577           Cave[y][x] = Ystone_wB;
2578           Cave[y][x-1] = Ystone_w;
2579           Next[y][x] = Xblank;
2580           Next[y][x-1] = Xstone_pause;
2581           return;
2582         }
2583
2584         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
2585         {
2586           Cave[y][x] = Ystone_eB;
2587           Cave[y][x+1] = Ystone_e;
2588           Next[y][x] = Xblank;
2589           Next[y][x+1] = Xstone_pause;
2590           return;
2591         }
2592       }
2593   }
2594 }
2595
2596 static void Lstone_pause(int x, int y)
2597 {
2598   switch (Cave[y+1][x])
2599   {
2600     case Xacid_1:
2601     case Xacid_2:
2602     case Xacid_3:
2603     case Xacid_4:
2604     case Xacid_5:
2605     case Xacid_6:
2606     case Xacid_7:
2607     case Xacid_8:
2608       Cave[y][x] = Ystone_sB;
2609       if (Cave[y][x+1] == Xblank)
2610         Cave[y][x+1] = Xacid_splash_e;
2611       if (Cave[y][x-1] == Xblank)
2612         Cave[y][x-1] = Xacid_splash_w;
2613       Next[y][x] = Xblank;
2614       play_element_sound(x, y, SOUND_acid, Xacid_1);
2615       return;
2616
2617     case Xblank:
2618     case Xacid_splash_e:
2619     case Xacid_splash_w:
2620 #if 1
2621     case Xfake_acid_1:
2622     case Xfake_acid_2:
2623     case Xfake_acid_3:
2624     case Xfake_acid_4:
2625     case Xfake_acid_5:
2626     case Xfake_acid_6:
2627     case Xfake_acid_7:
2628     case Xfake_acid_8:
2629 #endif
2630       Cave[y][x] = Ystone_sB;
2631       Cave[y+1][x] = Ystone_s;
2632       Next[y][x] = Xblank;
2633       Next[y+1][x] = Xstone_fall;
2634       return;
2635
2636     default:
2637       Cave[y][x] = Xstone;
2638       Next[y][x] = Xstone;
2639       return;
2640   }
2641 }
2642
2643 static void Lstone_fall(int x, int y)
2644 {
2645   switch (Cave[y+1][x])
2646   {
2647     case Xacid_1:
2648     case Xacid_2:
2649     case Xacid_3:
2650     case Xacid_4:
2651     case Xacid_5:
2652     case Xacid_6:
2653     case Xacid_7:
2654     case Xacid_8:
2655       Cave[y][x] = Ystone_sB;
2656       if (Cave[y][x+1] == Xblank)
2657         Cave[y][x+1] = Xacid_splash_e;
2658       if (Cave[y][x-1] == Xblank)
2659         Cave[y][x-1] = Xacid_splash_w;
2660       Next[y][x] = Xblank;
2661       play_element_sound(x, y, SOUND_acid, Xacid_1);
2662       return;
2663
2664     case Xblank:
2665     case Xacid_splash_e:
2666     case Xacid_splash_w:
2667     case Zplayer:
2668 #if 1
2669     case Xfake_acid_1:
2670     case Xfake_acid_2:
2671     case Xfake_acid_3:
2672     case Xfake_acid_4:
2673     case Xfake_acid_5:
2674     case Xfake_acid_6:
2675     case Xfake_acid_7:
2676     case Xfake_acid_8:
2677 #endif
2678       Cave[y][x] = Ystone_sB;
2679       Cave[y+1][x] = Ystone_s;
2680       Next[y][x] = Xblank;
2681       Next[y+1][x] = Xstone_fall;
2682       return;
2683
2684     case Xnut:
2685     case Xnut_pause:
2686       Cave[y+1][x] = Ynut_stone;
2687       Next[y][x] = Xstone;
2688       Next[y+1][x] = Xemerald;
2689       play_element_sound(x, y, SOUND_crack, Xnut);
2690       score += lev.nut_score;
2691       return;
2692
2693     case Xbug_1_n:
2694     case Xbug_1_e:
2695     case Xbug_1_s:
2696     case Xbug_1_w:
2697     case Xbug_2_n:
2698     case Xbug_2_e:
2699     case Xbug_2_s:
2700     case Xbug_2_w:
2701       Cave[y][x] = Ystone_sB;
2702       Cave[y+1][x] = Ybug_stone;
2703       Next[y+1][x] = Znormal;
2704       Boom[y][x-1] = Xemerald;
2705       Boom[y][x] = Xemerald;
2706       Boom[y][x+1] = Xemerald;
2707       Boom[y+1][x-1] = Xemerald;
2708       Boom[y+1][x] = Xdiamond;
2709       Boom[y+1][x+1] = Xemerald;
2710       Boom[y+2][x-1] = Xemerald;
2711       Boom[y+2][x] = Xemerald;
2712       Boom[y+2][x+1] = Xemerald;
2713 #if PLAY_ELEMENT_SOUND
2714       play_element_sound(x, y, SOUND_boom, Xstone_fall);
2715 #endif
2716       score += lev.bug_score;
2717       return;
2718
2719     case Xtank_1_n:
2720     case Xtank_1_e:
2721     case Xtank_1_s:
2722     case Xtank_1_w:
2723     case Xtank_2_n:
2724     case Xtank_2_e:
2725     case Xtank_2_s:
2726     case Xtank_2_w:
2727       Cave[y][x] = Ystone_sB;
2728       Cave[y+1][x] = Ytank_stone;
2729       Next[y+1][x] = Znormal;
2730       Boom[y][x-1] = Xblank;
2731       Boom[y][x] = Xblank;
2732       Boom[y][x+1] = Xblank;
2733       Boom[y+1][x-1] = Xblank;
2734       Boom[y+1][x] = Xblank;
2735       Boom[y+1][x+1] = Xblank;
2736       Boom[y+2][x-1] = Xblank;
2737       Boom[y+2][x] = Xblank;
2738       Boom[y+2][x+1] = Xblank;
2739 #if PLAY_ELEMENT_SOUND
2740       play_element_sound(x, y, SOUND_boom, Xstone_fall);
2741 #endif
2742       score += lev.tank_score;
2743       return;
2744
2745     case Xspring:
2746       if (RANDOM & 1)
2747       {
2748         switch (Cave[y+1][x+1])
2749         {
2750           case Xblank:
2751           case Xacid_splash_e:
2752           case Xacid_splash_w:
2753           case Xalien:
2754           case Xalien_pause:
2755             Cave[y+1][x] = Xspring_e;
2756             break;
2757
2758           default:
2759             Cave[y+1][x] = Xspring_w;
2760             break;
2761         }
2762       }
2763       else
2764       {
2765         switch (Cave[y+1][x-1])
2766         {
2767           case Xblank:
2768           case Xacid_splash_e:
2769           case Xacid_splash_w:
2770           case Xalien:
2771           case Xalien_pause:
2772             Cave[y+1][x] = Xspring_w;
2773             break;
2774           default:
2775             Cave[y+1][x] = Xspring_e;
2776             break;
2777         }
2778       }
2779
2780       Next[y][x] = Xstone;
2781       return;
2782
2783     case Xeater_n:
2784     case Xeater_e:
2785     case Xeater_s:
2786     case Xeater_w:
2787       Cave[y][x] = Ystone_sB;
2788       Cave[y+1][x] = Yeater_stone;
2789       Next[y+1][x] = Znormal;
2790       Boom[y][x-1] = lev.eater_array[lev.eater_pos][0];
2791       Boom[y][x] = lev.eater_array[lev.eater_pos][1];
2792       Boom[y][x+1] = lev.eater_array[lev.eater_pos][2];
2793       Boom[y+1][x-1] = lev.eater_array[lev.eater_pos][3];
2794       Boom[y+1][x] = lev.eater_array[lev.eater_pos][4];
2795       Boom[y+1][x+1] = lev.eater_array[lev.eater_pos][5];
2796       Boom[y+2][x-1] = lev.eater_array[lev.eater_pos][6];
2797       Boom[y+2][x] = lev.eater_array[lev.eater_pos][7];
2798       Boom[y+2][x+1] = lev.eater_array[lev.eater_pos][8];
2799 #if PLAY_ELEMENT_SOUND
2800       play_element_sound(x, y, SOUND_boom, Xstone_fall);
2801 #endif
2802       lev.eater_pos = (lev.eater_pos + 1) & 7;
2803       score += lev.eater_score;
2804       return;
2805
2806     case Xalien:
2807     case Xalien_pause:
2808       Cave[y][x] = Ystone_sB;
2809       Cave[y+1][x] = Yalien_stone;
2810       Next[y+1][x] = Znormal;
2811       Boom[y][x-1] = Xblank;
2812       Boom[y][x] = Xblank;
2813       Boom[y][x+1] = Xblank;
2814       Boom[y+1][x-1] = Xblank;
2815       Boom[y+1][x] = Xblank;
2816       Boom[y+1][x+1] = Xblank;
2817       Boom[y+2][x-1] = Xblank;
2818       Boom[y+2][x] = Xblank;
2819       Boom[y+2][x+1] = Xblank;
2820 #if PLAY_ELEMENT_SOUND
2821       play_element_sound(x, y, SOUND_boom, Xstone_fall);
2822 #endif
2823       score += lev.alien_score;
2824       return;
2825
2826     case Xdiamond:
2827     case Xdiamond_pause:
2828       switch (Cave[y+2][x])
2829       {
2830         case Xblank:
2831         case Xacid_splash_e:
2832         case Xacid_splash_w:
2833         case Zplayer:
2834         case Xbug_1_n:
2835         case Xbug_1_e:
2836         case Xbug_1_s:
2837         case Xbug_1_w:
2838         case Xbug_2_n:
2839         case Xbug_2_e:
2840         case Xbug_2_s:
2841         case Xbug_2_w:
2842         case Xtank_1_n:
2843         case Xtank_1_e:
2844         case Xtank_1_s:
2845         case Xtank_1_w:
2846         case Xtank_2_n:
2847         case Xtank_2_e:
2848         case Xtank_2_s:
2849         case Xtank_2_w:
2850         case Xspring_fall:
2851         case Xandroid:
2852         case Xandroid_1_n:
2853         case Xandroid_2_n:
2854         case Xandroid_1_e:
2855         case Xandroid_2_e:
2856         case Xandroid_1_s:
2857         case Xandroid_2_s:
2858         case Xandroid_1_w:
2859         case Xandroid_2_w:
2860         case Xstone_fall:
2861         case Xemerald_fall:
2862         case Xdiamond_fall:
2863         case Xbomb_fall:
2864         case Xacid_s:
2865         case Xacid_1:
2866         case Xacid_2:
2867         case Xacid_3:
2868         case Xacid_4:
2869         case Xacid_5:
2870         case Xacid_6:
2871         case Xacid_7:
2872         case Xacid_8:
2873         case Xnut_fall:
2874         case Xplant:
2875         case Yplant:
2876           Next[y][x] = Xstone;
2877           play_element_sound(x, y, SOUND_stone, Xstone);
2878           return;
2879       }
2880
2881       Cave[y][x] = Ystone_sB;
2882       Cave[y+1][x] = Ydiamond_stone;
2883       Next[y][x] = Xblank;
2884       Next[y+1][x] = Xstone_pause;
2885       play_element_sound(x, y, SOUND_squash, Xdiamond);
2886       return;
2887
2888     case Xbomb:
2889     case Xbomb_pause:
2890       Cave[y+1][x] = Ybomb_blank;
2891       Next[y+1][x] = Znormal;
2892       Boom[y][x-1] = Xblank;
2893       Boom[y][x] = Xblank;
2894       Boom[y][x+1] = Xblank;
2895       Boom[y+1][x-1] = Xblank;
2896       Boom[y+1][x] = Xblank;
2897       Boom[y+1][x+1] = Xblank;
2898       Boom[y+2][x-1] = Xblank;
2899       Boom[y+2][x] = Xblank;
2900       Boom[y+2][x+1] = Xblank;
2901 #if PLAY_ELEMENT_SOUND
2902       play_element_sound(x, y, SOUND_boom, Xstone_fall);
2903 #endif
2904       return;
2905
2906     case Xwonderwall:
2907       if (lev.wonderwall_time)
2908       {
2909         lev.wonderwall_state = 1;
2910         Cave[y][x] = Ystone_sB;
2911
2912         if (tab_blank[Cave[y+2][x]])
2913         {
2914           Cave[y+2][x] = Yemerald_s;
2915           Next[y+2][x] = Xemerald_fall;
2916         }
2917
2918         Next[y][x] = Xblank;
2919         play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
2920         return;
2921       }
2922
2923     default:
2924       Cave[y][x] = Xstone;
2925       Next[y][x] = Xstone;
2926       play_element_sound(x, y, SOUND_stone, Xstone);
2927       return;
2928   }
2929 }
2930
2931 static void Lbomb(int x, int y)
2932 {
2933   switch (Cave[y+1][x])
2934   {
2935     case Xacid_1:
2936     case Xacid_2:
2937     case Xacid_3:
2938     case Xacid_4:
2939     case Xacid_5:
2940     case Xacid_6:
2941     case Xacid_7:
2942     case Xacid_8:
2943       Cave[y][x] = Ybomb_sB;
2944       if (Cave[y][x+1] == Xblank)
2945         Cave[y][x+1] = Xacid_splash_e;
2946       if (Cave[y][x-1] == Xblank)
2947         Cave[y][x-1] = Xacid_splash_w;
2948       Next[y][x] = Xblank;
2949       play_element_sound(x, y, SOUND_acid, Xacid_1);
2950       return;
2951
2952     case Xblank:
2953     case Xacid_splash_e:
2954     case Xacid_splash_w:
2955       Cave[y][x] = Ybomb_sB;
2956       Cave[y+1][x] = Ybomb_s;
2957       Next[y][x] = Xblank;
2958       Next[y+1][x] = Xbomb_fall;
2959       return;
2960
2961     case Xspring:
2962     case Xspring_pause:
2963     case Xspring_e:
2964     case Xspring_w:
2965     case Xandroid:
2966     case Xandroid_1_n:
2967     case Xandroid_2_n:
2968     case Xandroid_1_e:
2969     case Xandroid_2_e:
2970     case Xandroid_1_s:
2971     case Xandroid_2_s:
2972     case Xandroid_1_w:
2973     case Xandroid_2_w:
2974     case Xstone:
2975     case Xstone_pause:
2976     case Xemerald:
2977     case Xemerald_pause:
2978     case Xdiamond:
2979     case Xdiamond_pause:
2980     case Xbomb:
2981     case Xbomb_pause:
2982     case Xballoon:
2983     case Xacid_ne:
2984     case Xacid_nw:
2985     case Xball_1:
2986     case Xball_2:
2987     case Xnut:
2988     case Xnut_pause:
2989     case Xslidewall_ns:
2990     case Xslidewall_ew:
2991     case Xkey_1:
2992     case Xkey_2:
2993     case Xkey_3:
2994     case Xkey_4:
2995     case Xkey_5:
2996     case Xkey_6:
2997     case Xkey_7:
2998     case Xkey_8:
2999     case Xbumper:
3000     case Xswitch:
3001     case Xroundwall_1:
3002     case Xroundwall_2:
3003     case Xroundwall_3:
3004     case Xroundwall_4:
3005       if (RANDOM & 1)
3006       {
3007         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3008         {
3009           Cave[y][x] = Ybomb_eB;
3010           Cave[y][x+1] = Ybomb_e;
3011           Next[y][x] = Xblank;
3012           Next[y][x+1] = Xbomb_pause;
3013           return;
3014         }
3015
3016         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3017         {
3018           Cave[y][x] = Ybomb_wB;
3019           Cave[y][x-1] = Ybomb_w;
3020           Next[y][x] = Xblank;
3021           Next[y][x-1] = Xbomb_pause;
3022           return;
3023         }
3024       }
3025       else
3026       {
3027         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3028         {
3029           Cave[y][x] = Ybomb_wB;
3030           Cave[y][x-1] = Ybomb_w;
3031           Next[y][x] = Xblank;
3032           Next[y][x-1] = Xbomb_pause;
3033           return;
3034         }
3035
3036         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3037         {
3038           Cave[y][x] = Ybomb_eB;
3039           Cave[y][x+1] = Ybomb_e;
3040           Next[y][x] = Xblank;
3041           Next[y][x+1] = Xbomb_pause;
3042           return;
3043         }
3044       }
3045   }
3046 }
3047
3048 static void Lbomb_pause(int x, int y)
3049 {
3050   switch (Cave[y+1][x])
3051   {
3052     case Xacid_1:
3053     case Xacid_2:
3054     case Xacid_3:
3055     case Xacid_4:
3056     case Xacid_5:
3057     case Xacid_6:
3058     case Xacid_7:
3059     case Xacid_8:
3060       Cave[y][x] = Ybomb_sB;
3061       if (Cave[y][x+1] == Xblank)
3062         Cave[y][x+1] = Xacid_splash_e;
3063       if (Cave[y][x-1] == Xblank)
3064         Cave[y][x-1] = Xacid_splash_w;
3065       Next[y][x] = Xblank;
3066       play_element_sound(x, y, SOUND_acid, Xacid_1);
3067       return;
3068
3069     case Xblank:
3070     case Xacid_splash_e:
3071     case Xacid_splash_w:
3072       Cave[y][x] = Ybomb_sB;
3073       Cave[y+1][x] = Ybomb_s;
3074       Next[y][x] = Xblank;
3075       Next[y+1][x] = Xbomb_fall;
3076       return;
3077
3078     default:
3079       Cave[y][x] = Xbomb;
3080       Next[y][x] = Xbomb;
3081       return;
3082   }
3083 }
3084
3085 static void Lbomb_fall(int x, int y)
3086 {
3087   switch (Cave[y+1][x])
3088   {
3089     case Xacid_1:
3090     case Xacid_2:
3091     case Xacid_3:
3092     case Xacid_4:
3093     case Xacid_5:
3094     case Xacid_6:
3095     case Xacid_7:
3096     case Xacid_8:
3097       Cave[y][x] = Ybomb_sB;
3098       if (Cave[y][x+1] == Xblank)
3099         Cave[y][x+1] = Xacid_splash_e;
3100       if (Cave[y][x-1] == Xblank)
3101         Cave[y][x-1] = Xacid_splash_w;
3102       Next[y][x] = Xblank;
3103       play_element_sound(x, y, SOUND_acid, Xacid_1);
3104       return;
3105
3106     case Xblank:
3107     case Xacid_splash_e:
3108     case Xacid_splash_w:
3109       Cave[y][x] = Ybomb_sB;
3110       Cave[y+1][x] = Ybomb_s;
3111       Next[y][x] = Xblank;
3112       Next[y+1][x] = Xbomb_fall;
3113       return;
3114
3115     default:
3116       Cave[y][x] = Ybomb_blank;
3117       Next[y][x] = Znormal;
3118       Boom[y-1][x-1] = Xblank;
3119       Boom[y-1][x] = Xblank;
3120       Boom[y-1][x+1] = Xblank;
3121       Boom[y][x-1] = Xblank;
3122       Boom[y][x] = Xblank;
3123       Boom[y][x+1] = Xblank;
3124       Boom[y+1][x-1] = Xblank;
3125       Boom[y+1][x] = Xblank;
3126       Boom[y+1][x+1] = Xblank;
3127 #if PLAY_ELEMENT_SOUND
3128       play_element_sound(x, y, SOUND_boom, Xbomb_fall);
3129 #endif
3130       return;
3131   }
3132 }
3133
3134 static void Lnut(int x, int y)
3135 {
3136   switch (Cave[y+1][x])
3137   {
3138     case Xacid_1:
3139     case Xacid_2:
3140     case Xacid_3:
3141     case Xacid_4:
3142     case Xacid_5:
3143     case Xacid_6:
3144     case Xacid_7:
3145     case Xacid_8:
3146       Cave[y][x] = Ynut_sB;
3147       if (Cave[y][x+1] == Xblank)
3148         Cave[y][x+1] = Xacid_splash_e;
3149       if (Cave[y][x-1] == Xblank)
3150         Cave[y][x-1] = Xacid_splash_w;
3151       Next[y][x] = Xblank;
3152       play_element_sound(x, y, SOUND_acid, Xacid_1);
3153       return;
3154
3155     case Xblank:
3156     case Xacid_splash_e:
3157     case Xacid_splash_w:
3158       Cave[y][x] = Ynut_sB;
3159       Cave[y+1][x] = Ynut_s;
3160       Next[y][x] = Xblank;
3161       Next[y+1][x] = Xnut_fall;
3162       return;
3163
3164     case Xspring:
3165     case Xspring_pause:
3166     case Xspring_e:
3167     case Xspring_w:
3168     case Xandroid:
3169     case Xandroid_1_n:
3170     case Xandroid_2_n:
3171     case Xandroid_1_e:
3172     case Xandroid_2_e:
3173     case Xandroid_1_s:
3174     case Xandroid_2_s:
3175     case Xandroid_1_w:
3176     case Xandroid_2_w:
3177     case Xstone:
3178     case Xstone_pause:
3179     case Xemerald:
3180     case Xemerald_pause:
3181     case Xdiamond:
3182     case Xdiamond_pause:
3183     case Xbomb:
3184     case Xbomb_pause:
3185     case Xballoon:
3186     case Xacid_ne:
3187     case Xacid_nw:
3188     case Xball_1:
3189     case Xball_2:
3190     case Xnut:
3191     case Xnut_pause:
3192     case Xslidewall_ns:
3193     case Xslidewall_ew:
3194     case Xkey_1:
3195     case Xkey_2:
3196     case Xkey_3:
3197     case Xkey_4:
3198     case Xkey_5:
3199     case Xkey_6:
3200     case Xkey_7:
3201     case Xkey_8:
3202     case Xbumper:
3203     case Xswitch:
3204     case Xroundwall_1:
3205     case Xroundwall_2:
3206     case Xroundwall_3:
3207     case Xroundwall_4:
3208       if (RANDOM & 1)
3209       {
3210         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3211         {
3212           Cave[y][x] = Ynut_eB;
3213           Cave[y][x+1] = Ynut_e;
3214           Next[y][x] = Xblank;
3215           Next[y][x+1] = Xnut_pause;
3216           return;
3217         }
3218
3219         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3220         {
3221           Cave[y][x] = Ynut_wB;
3222           Cave[y][x-1] = Ynut_w;
3223           Next[y][x] = Xblank;
3224           Next[y][x-1] = Xnut_pause;
3225           return;
3226         }
3227       }
3228       else
3229       {
3230         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3231         {
3232           Cave[y][x] = Ynut_wB;
3233           Cave[y][x-1] = Ynut_w;
3234           Next[y][x] = Xblank;
3235           Next[y][x-1] = Xnut_pause;
3236           return;
3237         }
3238
3239         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3240         {
3241           Cave[y][x] = Ynut_eB;
3242           Cave[y][x+1] = Ynut_e;
3243           Next[y][x] = Xblank;
3244           Next[y][x+1] = Xnut_pause;
3245           return;
3246         }
3247       }
3248   }
3249 }
3250
3251 static void Lnut_pause(int x, int y)
3252 {
3253   switch (Cave[y+1][x])
3254   {
3255     case Xacid_1:
3256     case Xacid_2:
3257     case Xacid_3:
3258     case Xacid_4:
3259     case Xacid_5:
3260     case Xacid_6:
3261     case Xacid_7:
3262     case Xacid_8:
3263       Cave[y][x] = Ynut_sB;
3264       if (Cave[y][x+1] == Xblank)
3265         Cave[y][x+1] = Xacid_splash_e;
3266       if (Cave[y][x-1] == Xblank)
3267         Cave[y][x-1] = Xacid_splash_w;
3268       Next[y][x] = Xblank;
3269       play_element_sound(x, y, SOUND_acid, Xacid_1);
3270       return;
3271
3272     case Xblank:
3273     case Xacid_splash_e:
3274     case Xacid_splash_w:
3275       Cave[y][x] = Ynut_sB;
3276       Cave[y+1][x] = Ynut_s;
3277       Next[y][x] = Xblank;
3278       Next[y+1][x] = Xnut_fall;
3279       return;
3280
3281     default:
3282       Cave[y][x] = Xnut;
3283       Next[y][x] = Xnut;
3284       return;
3285   }
3286 }
3287
3288 static void Lnut_fall(int x, int y)
3289 {
3290   switch (Cave[y+1][x])
3291   {
3292     case Xacid_1:
3293     case Xacid_2:
3294     case Xacid_3:
3295     case Xacid_4:
3296     case Xacid_5:
3297     case Xacid_6:
3298     case Xacid_7:
3299     case Xacid_8:
3300       Cave[y][x] = Ynut_sB;
3301       if (Cave[y][x+1] == Xblank)
3302         Cave[y][x+1] = Xacid_splash_e;
3303       if (Cave[y][x-1] == Xblank)
3304         Cave[y][x-1] = Xacid_splash_w;
3305       Next[y][x] = Xblank;
3306       play_element_sound(x, y, SOUND_acid, Xacid_1);
3307       return;
3308
3309     case Xblank:
3310     case Xacid_splash_e:
3311     case Xacid_splash_w:
3312     case Zplayer:
3313       Cave[y][x] = Ynut_sB;
3314       Cave[y+1][x] = Ynut_s;
3315       Next[y][x] = Xblank;
3316       Next[y+1][x] = Xnut_fall;
3317       return;
3318
3319     default:
3320       Cave[y][x] = Xnut;
3321       Next[y][x] = Xnut;
3322       play_element_sound(x, y, SOUND_nut, Xnut);
3323       return;
3324   }
3325 }
3326
3327 static void Lspring(int x, int y)
3328 {
3329   switch (Cave[y+1][x])
3330   {
3331     case Xacid_1:
3332     case Xacid_2:
3333     case Xacid_3:
3334     case Xacid_4:
3335     case Xacid_5:
3336     case Xacid_6:
3337     case Xacid_7:
3338     case Xacid_8:
3339       Cave[y][x] = Yspring_sB;
3340       if (Cave[y][x+1] == Xblank)
3341         Cave[y][x+1] = Xacid_splash_e;
3342       if (Cave[y][x-1] == Xblank)
3343         Cave[y][x-1] = Xacid_splash_w;
3344       Next[y][x] = Xblank;
3345       play_element_sound(x, y, SOUND_acid, Xacid_1);
3346       return;
3347
3348     case Xblank:
3349     case Xacid_splash_e:
3350     case Xacid_splash_w:
3351     case Xplant:
3352     case Yplant:
3353       Cave[y][x] = Yspring_sB;
3354       Cave[y+1][x] = Yspring_s;
3355       Next[y][x] = Xblank;
3356       Next[y+1][x] = Xspring_fall;
3357       return;
3358
3359     case Xspring:
3360     case Xspring_pause:
3361     case Xspring_e:
3362     case Xspring_w:
3363     case Xandroid:
3364     case Xandroid_1_n:
3365     case Xandroid_2_n:
3366     case Xandroid_1_e:
3367     case Xandroid_2_e:
3368     case Xandroid_1_s:
3369     case Xandroid_2_s:
3370     case Xandroid_1_w:
3371     case Xandroid_2_w:
3372     case Xstone:
3373     case Xstone_pause:
3374     case Xemerald:
3375     case Xemerald_pause:
3376     case Xdiamond:
3377     case Xdiamond_pause:
3378     case Xbomb:
3379     case Xbomb_pause:
3380     case Xballoon:
3381     case Xacid_ne:
3382     case Xacid_nw:
3383     case Xball_1:
3384     case Xball_2:
3385     case Xnut:
3386     case Xnut_pause:
3387     case Xslidewall_ns:
3388     case Xslidewall_ew:
3389     case Xkey_1:
3390     case Xkey_2:
3391     case Xkey_3:
3392     case Xkey_4:
3393     case Xkey_5:
3394     case Xkey_6:
3395     case Xkey_7:
3396     case Xkey_8:
3397     case Xbumper:
3398     case Xswitch:
3399     case Xroundwall_1:
3400     case Xroundwall_2:
3401     case Xroundwall_3:
3402     case Xroundwall_4:
3403       if (RANDOM & 1)
3404       {
3405         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3406         {
3407           Cave[y][x] = Yspring_eB;
3408           Cave[y][x+1] = Yspring_e;
3409           if (Cave[y+1][x] == Xbumper)
3410             Cave[y+1][x] = XbumperB;
3411           Next[y][x] = Xblank;
3412
3413 #ifdef SPRING_ROLL
3414           Next[y][x+1] = Xspring_e;
3415 #else   
3416           Next[y][x+1] = Xspring_pause;
3417 #endif
3418           return;
3419         }
3420
3421         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3422         {
3423           Cave[y][x] = Yspring_wB;
3424           Cave[y][x-1] = Yspring_w;
3425           if (Cave[y+1][x] == Xbumper)
3426             Cave[y+1][x] = XbumperB;
3427           Next[y][x] = Xblank;
3428
3429 #ifdef SPRING_ROLL
3430           Next[y][x-1] = Xspring_w;
3431 #else
3432           Next[y][x-1] = Xspring_pause;
3433 #endif
3434           return;
3435         }
3436       }
3437       else
3438       {
3439         if (tab_blank[Cave[y][x-1]] && tab_acid[Cave[y+1][x-1]])
3440         {
3441           Cave[y][x] = Yspring_wB;
3442           Cave[y][x-1] = Yspring_w;
3443           if (Cave[y+1][x] == Xbumper)
3444             Cave[y+1][x] = XbumperB;
3445           Next[y][x] = Xblank;
3446
3447 #ifdef SPRING_ROLL
3448           Next[y][x-1] = Xspring_w;
3449 #else
3450           Next[y][x-1] = Xspring_pause;
3451 #endif
3452           return;
3453         }
3454
3455         if (tab_blank[Cave[y][x+1]] && tab_acid[Cave[y+1][x+1]])
3456         {
3457           Cave[y][x] = Yspring_eB;
3458           Cave[y][x+1] = Yspring_e;
3459           if (Cave[y+1][x] == Xbumper)
3460             Cave[y+1][x] = XbumperB;
3461           Next[y][x] = Xblank;
3462
3463 #ifdef SPRING_ROLL
3464           Next[y][x+1] = Xspring_e;
3465 #else
3466           Next[y][x+1] = Xspring_pause;
3467 #endif
3468           return;
3469         }
3470       }
3471   }
3472 }
3473
3474 static void Lspring_pause(int x, int y)
3475 {
3476   switch (Cave[y+1][x])
3477   {
3478     case Xacid_1:
3479     case Xacid_2:
3480     case Xacid_3:
3481     case Xacid_4:
3482     case Xacid_5:
3483     case Xacid_6:
3484     case Xacid_7:
3485     case Xacid_8:
3486       Cave[y][x] = Yspring_sB;
3487       if (Cave[y][x+1] == Xblank)
3488         Cave[y][x+1] = Xacid_splash_e;
3489       if (Cave[y][x-1] == Xblank)
3490         Cave[y][x-1] = Xacid_splash_w;
3491       Next[y][x] = Xblank;
3492       play_element_sound(x, y, SOUND_acid, Xacid_1);
3493       return;
3494
3495     case Xblank:
3496     case Xacid_splash_e:
3497     case Xacid_splash_w:
3498       Cave[y][x] = Yspring_sB;
3499       Cave[y+1][x] = Yspring_s;
3500       Next[y][x] = Xblank;
3501       Next[y+1][x] = Xspring_fall;
3502       return;
3503
3504     default:
3505       Cave[y][x] = Xspring;
3506       Next[y][x] = Xspring;
3507       return;
3508   }
3509 }
3510
3511 static void Lspring_e(int x, int y)
3512 {
3513   switch (Cave[y+1][x])
3514   {
3515     case Xacid_1:
3516     case Xacid_2:
3517     case Xacid_3:
3518     case Xacid_4:
3519     case Xacid_5:
3520     case Xacid_6:
3521     case Xacid_7:
3522     case Xacid_8:
3523       Cave[y][x] = Yspring_sB;
3524       if (Cave[y][x+1] == Xblank)
3525         Cave[y][x+1] = Xacid_splash_e;
3526       if (Cave[y][x-1] == Xblank)
3527         Cave[y][x-1] = Xacid_splash_w;
3528       Next[y][x] = Xblank;
3529       play_element_sound(x, y, SOUND_acid, Xacid_1);
3530       return;
3531
3532     case Xblank:
3533     case Xacid_splash_e:
3534     case Xacid_splash_w:
3535       Cave[y][x] = Yspring_sB;
3536       Cave[y+1][x] = Yspring_s;
3537       Next[y][x] = Xblank;
3538       Next[y+1][x] = Xspring_fall;
3539       return;
3540
3541     case Xbumper:
3542       Cave[y+1][x] = XbumperB;
3543   }
3544
3545   switch (Cave[y][x+1])
3546   {
3547     case Xacid_1:
3548     case Xacid_2:
3549     case Xacid_3:
3550     case Xacid_4:
3551     case Xacid_5:
3552     case Xacid_6:
3553     case Xacid_7:
3554     case Xacid_8:
3555       Cave[y][x] = Yspring_eB;
3556       if (Cave[y-1][x+2] == Xblank)
3557         Cave[y-1][x+2] = Xacid_splash_e;
3558       if (Cave[y-1][x] == Xblank)
3559         Cave[y-1][x] = Xacid_splash_w;
3560       Next[y][x] = Xblank;
3561       play_element_sound(x, y, SOUND_acid, Xacid_1);
3562       return;
3563
3564     case Xblank:
3565     case Xacid_splash_e:
3566     case Xacid_splash_w:
3567     case Yalien_nB:
3568     case Yalien_eB:
3569     case Yalien_sB:
3570     case Yalien_wB:
3571       Cave[y][x] = Yspring_eB;
3572       Cave[y][x+1] = Yspring_e;
3573       Next[y][x] = Xblank;
3574       Next[y][x+1] = Xspring_e;
3575       return;
3576
3577     case Xalien:
3578     case Xalien_pause:
3579     case Yalien_n:
3580     case Yalien_e:
3581     case Yalien_s:
3582     case Yalien_w:
3583       Cave[y][x] = Yspring_alien_eB;
3584       Cave[y][x+1] = Yspring_alien_e;
3585       Next[y][x] = Xblank;
3586       Next[y][x+1] = Xspring_e;
3587       play_element_sound(x, y, SOUND_slurp, Xalien);
3588       score += lev.slurp_score;
3589       return;
3590
3591     case Xbumper:
3592     case XbumperB:
3593       Cave[y][x+1] = XbumperB;
3594       Next[y][x] = Xspring_w;
3595       play_element_sound(x, y, SOUND_spring, Xspring);
3596       return;
3597
3598     default:
3599       Cave[y][x] = Xspring;
3600       Next[y][x] = Xspring;
3601       play_element_sound(x, y, SOUND_spring, Xspring);
3602       return;
3603   }
3604 }
3605
3606 static void Lspring_w(int x, int y)
3607 {
3608   switch (Cave[y+1][x])
3609   {
3610     case Xacid_1:
3611     case Xacid_2:
3612     case Xacid_3:
3613     case Xacid_4:
3614     case Xacid_5:
3615     case Xacid_6:
3616     case Xacid_7:
3617     case Xacid_8:
3618       Cave[y][x] = Yspring_sB;
3619       if (Cave[y][x+1] == Xblank)
3620         Cave[y][x+1] = Xacid_splash_e;
3621       if (Cave[y][x-1] == Xblank)
3622         Cave[y][x-1] = Xacid_splash_w;
3623       Next[y][x] = Xblank;
3624       play_element_sound(x, y, SOUND_acid, Xacid_1);
3625       return;
3626
3627     case Xblank:
3628     case Xacid_splash_e:
3629     case Xacid_splash_w:
3630       Cave[y][x] = Yspring_sB;
3631       Cave[y+1][x] = Yspring_s;
3632       Next[y][x] = Xblank;
3633       Next[y+1][x] = Xspring_fall;
3634       return;
3635
3636     case Xbumper:
3637       Cave[y+1][x] = XbumperB;
3638   }
3639
3640   switch (Cave[y][x-1])
3641   {
3642     case Xacid_1:
3643     case Xacid_2:
3644     case Xacid_3:
3645     case Xacid_4:
3646     case Xacid_5:
3647     case Xacid_6:
3648     case Xacid_7:
3649     case Xacid_8:
3650       Cave[y][x] = Yspring_wB;
3651       if (Cave[y-1][x] == Xblank)
3652         Cave[y-1][x] = Xacid_splash_e;
3653       if (Cave[y-1][x-2] == Xblank)
3654         Cave[y-1][x-2] = Xacid_splash_w;
3655       Next[y][x] = Xblank;
3656       play_element_sound(x, y, SOUND_acid, Xacid_1);
3657       return;
3658
3659     case Xblank:
3660     case Xacid_splash_e:
3661     case Xacid_splash_w:
3662     case Yalien_nB:
3663     case Yalien_eB:
3664     case Yalien_sB:
3665     case Yalien_wB:
3666       Cave[y][x] = Yspring_wB;
3667       Cave[y][x-1] = Yspring_w;
3668       Next[y][x] = Xblank;
3669       Next[y][x-1] = Xspring_w;
3670       return;
3671
3672     case Xalien:
3673     case Xalien_pause:
3674     case Yalien_n:
3675     case Yalien_e:
3676     case Yalien_s:
3677     case Yalien_w:
3678       Cave[y][x] = Yspring_alien_wB;
3679       Cave[y][x-1] = Yspring_alien_w;
3680       Next[y][x] = Xblank;
3681       Next[y][x-1] = Xspring_w;
3682       play_element_sound(x, y, SOUND_slurp, Xalien);
3683       score += lev.slurp_score;
3684       return;
3685
3686     case Xbumper:
3687     case XbumperB:
3688       Cave[y][x-1] = XbumperB;
3689       Next[y][x] = Xspring_e;
3690       play_element_sound(x, y, SOUND_spring, Xspring);
3691       return;
3692
3693     default:
3694       Cave[y][x] = Xspring;
3695       Next[y][x] = Xspring;
3696       play_element_sound(x, y, SOUND_spring, Xspring);
3697       return;
3698   }
3699 }
3700
3701 static void Lspring_fall(int x, int y)
3702 {
3703   switch (Cave[y+1][x])
3704   {
3705     case Xacid_1:
3706     case Xacid_2:
3707     case Xacid_3:
3708     case Xacid_4:
3709     case Xacid_5:
3710     case Xacid_6:
3711     case Xacid_7:
3712     case Xacid_8:
3713       Cave[y][x] = Yspring_sB;
3714       if (Cave[y][x+1] == Xblank)
3715         Cave[y][x+1] = Xacid_splash_e;
3716       if (Cave[y][x-1] == Xblank)
3717         Cave[y][x-1] = Xacid_splash_w;
3718       Next[y][x] = Xblank;
3719       play_element_sound(x, y, SOUND_acid, Xacid_1);
3720       return;
3721
3722     case Xblank:
3723     case Xacid_splash_e:
3724     case Xacid_splash_w:
3725     case Zplayer:
3726       Cave[y][x] = Yspring_sB;
3727       Cave[y+1][x] = Yspring_s;
3728       Next[y][x] = Xblank;
3729       Next[y+1][x] = Xspring_fall;
3730       return;
3731
3732     case Xbomb:
3733     case Xbomb_pause:
3734       Cave[y+1][x] = Ybomb_blank;
3735       Next[y+1][x] = Znormal;
3736       Boom[y][x-1] = Xblank;
3737       Boom[y][x] = Xblank;
3738       Boom[y][x+1] = Xblank;
3739       Boom[y+1][x-1] = Xblank;
3740       Boom[y+1][x] = Xblank;
3741       Boom[y+1][x+1] = Xblank;
3742       Boom[y+2][x-1] = Xblank;
3743       Boom[y+2][x] = Xblank;
3744       Boom[y+2][x+1] = Xblank;
3745 #if PLAY_ELEMENT_SOUND
3746       play_element_sound(x, y, SOUND_boom, Xspring_fall);
3747 #endif
3748       return;
3749
3750     case Xbug_1_n:
3751     case Xbug_1_e:
3752     case Xbug_1_s:
3753     case Xbug_1_w:
3754     case Xbug_2_n:
3755     case Xbug_2_e:
3756     case Xbug_2_s:
3757     case Xbug_2_w:
3758       Cave[y][x] = Yspring_sB;
3759       Cave[y+1][x] = Ybug_spring;
3760       Next[y+1][x] = Znormal;
3761       Boom[y][x-1] = Xemerald;
3762       Boom[y][x] = Xemerald;
3763       Boom[y][x+1] = Xemerald;
3764       Boom[y+1][x-1] = Xemerald;
3765       Boom[y+1][x] = Xdiamond;
3766       Boom[y+1][x+1] = Xemerald;
3767       Boom[y+2][x-1] = Xemerald;
3768       Boom[y+2][x] = Xemerald;
3769       Boom[y+2][x+1] = Xemerald;
3770 #if PLAY_ELEMENT_SOUND
3771       play_element_sound(x, y, SOUND_boom, Xspring_fall);
3772 #endif
3773       score += lev.bug_score;
3774       return;
3775
3776     case Xtank_1_n:
3777     case Xtank_1_e:
3778     case Xtank_1_s:
3779     case Xtank_1_w:
3780     case Xtank_2_n:
3781     case Xtank_2_e:
3782     case Xtank_2_s:
3783     case Xtank_2_w:
3784       Cave[y][x] = Yspring_sB;
3785       Cave[y+1][x] = Ytank_spring;
3786       Next[y+1][x] = Znormal;
3787       Boom[y][x-1] = Xblank;
3788       Boom[y][x] = Xblank;
3789       Boom[y][x+1] = Xblank;
3790       Boom[y+1][x-1] = Xblank;
3791       Boom[y+1][x] = Xblank;
3792       Boom[y+1][x+1] = Xblank;
3793       Boom[y+2][x-1] = Xblank;
3794       Boom[y+2][x] = Xblank;
3795       Boom[y+2][x+1] = Xblank;
3796 #if PLAY_ELEMENT_SOUND
3797       play_element_sound(x, y, SOUND_boom, Xspring_fall);
3798 #endif
3799       score += lev.tank_score;
3800       return;
3801
3802     case Xeater_n:
3803     case Xeater_e:
3804     case Xeater_s:
3805     case Xeater_w:
3806       Cave[y][x] = Yspring_sB;
3807       Cave[y+1][x] = Yeater_spring;
3808       Next[y+1][x] = Znormal;
3809       Boom[y][x-1] = lev.eater_array[lev.eater_pos][0];
3810       Boom[y][x] = lev.eater_array[lev.eater_pos][1];
3811       Boom[y][x+1] = lev.eater_array[lev.eater_pos][2];
3812       Boom[y+1][x-1] = lev.eater_array[lev.eater_pos][3];
3813       Boom[y+1][x] = lev.eater_array[lev.eater_pos][4];
3814       Boom[y+1][x+1] = lev.eater_array[lev.eater_pos][5];
3815       Boom[y+2][x-1] = lev.eater_array[lev.eater_pos][6];
3816       Boom[y+2][x] = lev.eater_array[lev.eater_pos][7];
3817       Boom[y+2][x+1] = lev.eater_array[lev.eater_pos][8];
3818 #if PLAY_ELEMENT_SOUND
3819       play_element_sound(x, y, SOUND_boom, Xspring_fall);
3820 #endif
3821       lev.eater_pos = (lev.eater_pos + 1) & 7;
3822       score += lev.eater_score;
3823       return;
3824
3825     case Xalien:
3826     case Xalien_pause:
3827       Cave[y][x] = Yspring_sB;
3828       Cave[y+1][x] = Yalien_spring;
3829       Next[y+1][x] = Znormal;
3830       Boom[y][x-1] = Xblank;
3831       Boom[y][x] = Xblank;
3832       Boom[y][x+1] = Xblank;
3833       Boom[y+1][x-1] = Xblank;
3834       Boom[y+1][x] = Xblank;
3835       Boom[y+1][x+1] = Xblank;
3836       Boom[y+2][x-1] = Xblank;
3837       Boom[y+2][x] = Xblank;
3838       Boom[y+2][x+1] = Xblank;
3839 #if PLAY_ELEMENT_SOUND
3840       play_element_sound(x, y, SOUND_boom, Xspring_fall);
3841 #endif
3842       score += lev.alien_score;
3843       return;
3844
3845     default:
3846       Cave[y][x] = Xspring;
3847       Next[y][x] = Xspring;
3848       play_element_sound(x, y, SOUND_spring, Xspring);
3849       return;
3850   }
3851 }
3852
3853 static void Lpush_emerald_e(int x, int y)
3854 {
3855   switch (Cave[y][x+1])
3856   {
3857     case Zborder:
3858     case Znormal:
3859     case Zdynamite:
3860     case Xboom_bug:
3861     case Xboom_bomb:
3862     case Xboom_android:
3863     case Xboom_1:
3864     case Zplayer:
3865       Cave[y][x] = Xemerald;
3866       Next[y][x] = Xemerald;
3867       return;
3868
3869     default:
3870       Cave[y][x] = Yemerald_eB;
3871       Cave[y][x+1] = Yemerald_e;
3872       Next[y][x] = Xblank;
3873       Next[y][x+1] = Xemerald_pause;
3874       return;
3875   }
3876 }
3877
3878 static void Lpush_emerald_w(int x, int y)
3879 {
3880   switch (Cave[y][x-1])
3881   {
3882     case Zborder:
3883     case Znormal:
3884     case Zdynamite:
3885     case Xboom_bug:
3886     case Xboom_bomb:
3887     case Xboom_android:
3888     case Xboom_1:
3889     case Zplayer:
3890       Cave[y][x] = Xemerald;
3891       Next[y][x] = Xemerald;
3892       return;
3893
3894     default:
3895       Cave[y][x] = Yemerald_wB;
3896       Cave[y][x-1] = Yemerald_w;
3897       Next[y][x] = Xblank;
3898       Next[y][x-1] = Xemerald_pause;
3899       return;
3900   }
3901 }
3902
3903 static void Lpush_diamond_e(int x, int y)
3904 {
3905   switch (Cave[y][x+1])
3906   {
3907     case Zborder:
3908     case Znormal:
3909     case Zdynamite:
3910     case Xboom_bug:
3911     case Xboom_bomb:
3912     case Xboom_android:
3913     case Xboom_1:
3914     case Zplayer:
3915       Cave[y][x] = Xdiamond;
3916       Next[y][x] = Xdiamond;
3917       return;
3918
3919     default:
3920       Cave[y][x] = Ydiamond_eB;
3921       Cave[y][x+1] = Ydiamond_e;
3922       Next[y][x] = Xblank;
3923       Next[y][x+1] = Xdiamond_pause;
3924       return;
3925   }
3926 }
3927
3928 static void Lpush_diamond_w(int x, int y)
3929 {
3930   switch (Cave[y][x-1])
3931   {
3932     case Zborder:
3933     case Znormal:
3934     case Zdynamite:
3935     case Xboom_bug:
3936     case Xboom_bomb:
3937     case Xboom_android:
3938     case Xboom_1:
3939     case Zplayer:
3940       Cave[y][x] = Xdiamond;
3941       Next[y][x] = Xdiamond;
3942       return;
3943
3944     default:
3945       Cave[y][x] = Ydiamond_wB;
3946       Cave[y][x-1] = Ydiamond_w;
3947       Next[y][x] = Xblank;
3948       Next[y][x-1] = Xdiamond_pause;
3949       return;
3950   }
3951 }
3952
3953 static void Lpush_stone_e(int x, int y)
3954 {
3955   switch (Cave[y][x+1])
3956   {
3957     case Zborder:
3958     case Znormal:
3959     case Zdynamite:
3960     case Xboom_bug:
3961     case Xboom_bomb:
3962     case Xboom_android:
3963     case Xboom_1:
3964     case Zplayer:
3965       Cave[y][x] = Xstone;
3966       Next[y][x] = Xstone;
3967       return;
3968
3969     default:
3970       Cave[y][x] = Ystone_eB;
3971       Cave[y][x+1] = Ystone_e;
3972       Next[y][x] = Xblank;
3973       Next[y][x+1] = Xstone_pause;
3974       return;
3975   }
3976 }
3977
3978 static void Lpush_stone_w(int x, int y)
3979 {
3980   switch (Cave[y][x-1])
3981   {
3982     case Zborder:
3983     case Znormal:
3984     case Zdynamite:
3985     case Xboom_bug:
3986     case Xboom_bomb:
3987     case Xboom_android:
3988     case Xboom_1:
3989     case Zplayer:
3990       Cave[y][x] = Xstone;
3991       Next[y][x] = Xstone;
3992       return;
3993
3994     default:
3995       Cave[y][x] = Ystone_wB;
3996       Cave[y][x-1] = Ystone_w;
3997       Next[y][x] = Xblank;
3998       Next[y][x-1] = Xstone_pause;
3999       return;
4000   }
4001 }
4002
4003 static void Lpush_bomb_e(int x, int y)
4004 {
4005   switch (Cave[y][x+1])
4006   {
4007     case Zborder:
4008     case Znormal:
4009     case Zdynamite:
4010     case Xboom_bug:
4011     case Xboom_bomb:
4012     case Xboom_android:
4013     case Xboom_1:
4014     case Zplayer:
4015       Cave[y][x] = Xbomb;
4016       Next[y][x] = Xbomb;
4017       return;
4018
4019     default:
4020       Cave[y][x] = Ybomb_eB;
4021       Cave[y][x+1] = Ybomb_e;
4022       Next[y][x] = Xblank;
4023       Next[y][x+1] = Xbomb_pause;
4024       return;
4025   }
4026 }
4027
4028 static void Lpush_bomb_w(int x, int y)
4029 {
4030   switch (Cave[y][x-1])
4031   {
4032     case Zborder:
4033     case Znormal:
4034     case Zdynamite:
4035     case Xboom_bug:
4036     case Xboom_bomb:
4037     case Xboom_android:
4038     case Xboom_1:
4039     case Zplayer:
4040       Cave[y][x] = Xbomb;
4041       Next[y][x] = Xbomb;
4042       return;
4043
4044     default:
4045       Cave[y][x] = Ybomb_wB;
4046       Cave[y][x-1] = Ybomb_w;
4047       Next[y][x] = Xblank;
4048       Next[y][x-1] = Xbomb_pause;
4049       return;
4050   }
4051 }
4052
4053 static void Lpush_nut_e(int x, int y)
4054 {
4055   switch (Cave[y][x+1])
4056   {
4057     case Zborder:
4058     case Znormal:
4059     case Zdynamite:
4060     case Xboom_bug:
4061     case Xboom_bomb:
4062     case Xboom_android:
4063     case Xboom_1:
4064     case Zplayer:
4065       Cave[y][x] = Xnut;
4066       Next[y][x] = Xnut;
4067       return;
4068
4069     default:
4070       Cave[y][x] = Ynut_eB;
4071       Cave[y][x+1] = Ynut_e;
4072       Next[y][x] = Xblank;
4073       Next[y][x+1] = Xnut_pause;
4074       return;
4075   }
4076 }
4077
4078 static void Lpush_nut_w(int x, int y)
4079 {
4080   switch (Cave[y][x-1])
4081   {
4082     case Zborder:
4083     case Znormal:
4084     case Zdynamite:
4085     case Xboom_bug:
4086     case Xboom_bomb:
4087     case Xboom_android:
4088     case Xboom_1:
4089     case Zplayer:
4090       Cave[y][x] = Xnut;
4091       Next[y][x] = Xnut;
4092       return;
4093
4094     default:
4095       Cave[y][x] = Ynut_wB;
4096       Cave[y][x-1] = Ynut_w;
4097       Next[y][x] = Xblank;
4098       Next[y][x-1] = Xnut_pause;
4099       return;
4100   }
4101 }
4102
4103 static void Lpush_spring_e(int x, int y)
4104 {
4105   switch (Cave[y][x+1])
4106   {
4107     case Zborder:
4108     case Znormal:
4109     case Zdynamite:
4110     case Xboom_bug:
4111     case Xboom_bomb:
4112     case Xboom_android:
4113     case Xboom_1:
4114     case Zplayer:
4115       Cave[y][x] = Xspring;
4116       Next[y][x] = Xspring;
4117       return;
4118
4119     default:
4120       Cave[y][x] = Yspring_eB;
4121       Cave[y][x+1] = Yspring_e;
4122       Next[y][x] = Xblank;
4123       Next[y][x+1] = Xspring_e;
4124       return;
4125   }
4126 }
4127
4128 static void Lpush_spring_w(int x, int y)
4129 {
4130   switch (Cave[y][x-1])
4131   {
4132     case Zborder:
4133     case Znormal:
4134     case Zdynamite:
4135     case Xboom_bug:
4136     case Xboom_bomb:
4137     case Xboom_android:
4138     case Xboom_1:
4139     case Zplayer:
4140       Cave[y][x] = Xspring;
4141       Next[y][x] = Xspring;
4142       return;
4143
4144     default:
4145       Cave[y][x] = Yspring_wB;
4146       Cave[y][x-1] = Yspring_w;
4147       Next[y][x] = Xblank;
4148       Next[y][x-1] = Xspring_w;
4149       return;
4150   }
4151 }
4152
4153 static void Lballoon(int x, int y)
4154 {
4155   if (lev.wind_cnt == 0)
4156     return;
4157
4158   switch (lev.wind_direction)
4159   {
4160     case 0: /* north */
4161       switch (Cave[y-1][x])
4162       {
4163         case Xacid_1:
4164         case Xacid_2:
4165         case Xacid_3:
4166         case Xacid_4:
4167         case Xacid_5:
4168         case Xacid_6:
4169         case Xacid_7:
4170         case Xacid_8:
4171           Cave[y][x] = Yballoon_nB;
4172           if (Cave[y-2][x+1] == Xblank)
4173             Cave[y-2][x+1] = Xacid_splash_e;
4174           if (Cave[y-2][x-1] == Xblank)
4175             Cave[y-2][x-1] = Xacid_splash_w;
4176           Next[y][x] = Xblank;
4177           play_element_sound(x, y, SOUND_acid, Xacid_1);
4178           return;
4179
4180         case Xblank:
4181         case Xacid_splash_e:
4182         case Xacid_splash_w:
4183           Cave[y][x] = Yballoon_nB;
4184           Cave[y-1][x] = Yballoon_n;
4185           Next[y][x] = Xblank;
4186           Next[y-1][x] = Xballoon;
4187           return;
4188       }
4189       break;
4190
4191     case 1: /* east */
4192       switch (Cave[y][x+1])
4193       {
4194         case Xacid_1:
4195         case Xacid_2:
4196         case Xacid_3:
4197         case Xacid_4:
4198         case Xacid_5:
4199         case Xacid_6:
4200         case Xacid_7:
4201         case Xacid_8:
4202           Cave[y][x] = Yballoon_eB;
4203           if (Cave[y-1][x+2] == Xblank)
4204             Cave[y-1][x+2] = Xacid_splash_e;
4205           if (Cave[y-1][x] == Xblank)
4206             Cave[y-1][x] = Xacid_splash_w;
4207           Next[y][x] = Xblank;
4208           play_element_sound(x, y, SOUND_acid, Xacid_1);
4209           return;
4210
4211         case Xblank:
4212         case Xacid_splash_e:
4213         case Xacid_splash_w:
4214           Cave[y][x] = Yballoon_eB;
4215           Cave[y][x+1] = Yballoon_e;
4216           Next[y][x] = Xblank;
4217           Next[y][x+1] = Xballoon;
4218           return;
4219       }
4220       break;
4221
4222     case 2: /* south */
4223       switch (Cave[y+1][x])
4224       {
4225         case Xacid_1:
4226         case Xacid_2:
4227         case Xacid_3:
4228         case Xacid_4:
4229         case Xacid_5:
4230         case Xacid_6:
4231         case Xacid_7:
4232         case Xacid_8:
4233           Cave[y][x] = Yballoon_sB;
4234           if (Cave[y][x+1] == Xblank)
4235             Cave[y][x+1] = Xacid_splash_e;
4236           if (Cave[y][x-1] == Xblank)
4237             Cave[y][x-1] = Xacid_splash_w;
4238           Next[y][x] = Xblank;
4239           play_element_sound(x, y, SOUND_acid, Xacid_1);
4240           return;
4241
4242         case Xblank:
4243         case Xacid_splash_e:
4244         case Xacid_splash_w:
4245           Cave[y][x] = Yballoon_sB;
4246           Cave[y+1][x] = Yballoon_s;
4247           Next[y][x] = Xblank;
4248           Next[y+1][x] = Xballoon;
4249           return;
4250       }
4251       break;
4252
4253     case 3: /* west */
4254       switch (Cave[y][x-1])
4255       {
4256         case Xacid_1:
4257         case Xacid_2:
4258         case Xacid_3:
4259         case Xacid_4:
4260         case Xacid_5:
4261         case Xacid_6:
4262         case Xacid_7:
4263         case Xacid_8:
4264           Cave[y][x] = Yballoon_wB;
4265           if (Cave[y-1][x] == Xblank)
4266             Cave[y-1][x] = Xacid_splash_e;
4267           if (Cave[y-1][x-2] == Xblank)
4268             Cave[y-1][x-2] = Xacid_splash_w;
4269           Next[y][x] = Xblank;
4270           play_element_sound(x, y, SOUND_acid, Xacid_1);
4271           return;
4272
4273         case Xblank:
4274         case Xacid_splash_e:
4275         case Xacid_splash_w:
4276           Cave[y][x] = Yballoon_wB;
4277           Cave[y][x-1] = Yballoon_w;
4278           Next[y][x] = Xblank;
4279           Next[y][x-1] = Xballoon;
4280           return;
4281       }
4282       break;
4283   }
4284 }
4285
4286 static void Lball_common(int x, int y)
4287 {
4288   play_element_sound(x, y, SOUND_ball, Xball_1);
4289
4290   if (lev.ball_random)
4291   {
4292     switch (RANDOM & 7)
4293     {
4294       case 0:
4295         if (lev.ball_array[lev.ball_pos][0] != Xblank &&
4296             tab_blank[Cave[y-1][x-1]])
4297         {
4298           Cave[y-1][x-1] = Yball_blank;
4299           Next[y-1][x-1] = lev.ball_array[lev.ball_pos][0];
4300         }
4301         break;
4302
4303       case 1:
4304         if (lev.ball_array[lev.ball_pos][1] != Xblank &&
4305             tab_blank[Cave[y-1][x]])
4306         {
4307           Cave[y-1][x] = Yball_blank;
4308           Next[y-1][x] = lev.ball_array[lev.ball_pos][1];
4309         }
4310         break;
4311
4312       case 2:
4313         if (lev.ball_array[lev.ball_pos][2] != Xblank &&
4314             tab_blank[Cave[y-1][x+1]])
4315         {
4316           Cave[y-1][x+1] = Yball_blank;
4317           Next[y-1][x+1] = lev.ball_array[lev.ball_pos][2];
4318         }
4319         break;
4320
4321       case 3:
4322         if (lev.ball_array[lev.ball_pos][3] != Xblank &&
4323             tab_blank[Cave[y][x-1]])
4324         {
4325           Cave[y][x-1] = Yball_blank;
4326           Next[y][x-1] = lev.ball_array[lev.ball_pos][3];
4327         }
4328         break;
4329
4330       case 4:
4331         if (lev.ball_array[lev.ball_pos][4] != Xblank &&
4332             tab_blank[Cave[y][x+1]])
4333         {
4334           Cave[y][x+1] = Yball_blank;
4335           Next[y][x+1] = lev.ball_array[lev.ball_pos][4];
4336         }
4337         break;
4338
4339       case 5:
4340         if (lev.ball_array[lev.ball_pos][5] != Xblank &&
4341             tab_blank[Cave[y+1][x-1]])
4342         {
4343           Cave[y+1][x-1] = Yball_blank;
4344           Next[y+1][x-1] = lev.ball_array[lev.ball_pos][5];
4345         }
4346         break;
4347
4348       case 6:
4349         if (lev.ball_array[lev.ball_pos][6] != Xblank &&
4350             tab_blank[Cave[y+1][x]])
4351         {
4352           Cave[y+1][x] = Yball_blank;
4353           Next[y+1][x] = lev.ball_array[lev.ball_pos][6];
4354         }
4355         break;
4356
4357       case 7:
4358         if (lev.ball_array[lev.ball_pos][7] != Xblank &&
4359             tab_blank[Cave[y+1][x+1]])
4360         {
4361           Cave[y+1][x+1] = Yball_blank;
4362           Next[y+1][x+1] = lev.ball_array[lev.ball_pos][7];
4363         }
4364         break;
4365     }
4366   }
4367   else
4368   {
4369     if (lev.ball_array[lev.ball_pos][0] != Xblank &&
4370         tab_blank[Cave[y-1][x-1]])
4371     {
4372       Cave[y-1][x-1] = Yball_blank;
4373       Next[y-1][x-1] = lev.ball_array[lev.ball_pos][0];
4374     }
4375
4376     if (lev.ball_array[lev.ball_pos][1] != Xblank &&
4377         tab_blank[Cave[y-1][x]])
4378     {
4379       Cave[y-1][x] = Yball_blank;
4380       Next[y-1][x] = lev.ball_array[lev.ball_pos][1];
4381     }
4382
4383     if (lev.ball_array[lev.ball_pos][2] != Xblank &&
4384         tab_blank[Cave[y-1][x+1]])
4385     {
4386       Cave[y-1][x+1] = Yball_blank;
4387       Next[y-1][x+1] = lev.ball_array[lev.ball_pos][2];
4388     }
4389
4390     if (lev.ball_array[lev.ball_pos][3] != Xblank &&
4391         tab_blank[Cave[y][x-1]])
4392     {
4393       Cave[y][x-1] = Yball_blank;
4394       Next[y][x-1] = lev.ball_array[lev.ball_pos][3];
4395     }
4396
4397     if (lev.ball_array[lev.ball_pos][4] != Xblank &&
4398         tab_blank[Cave[y][x+1]])
4399     {
4400       Cave[y][x+1] = Yball_blank;
4401       Next[y][x+1] = lev.ball_array[lev.ball_pos][4];
4402     }
4403
4404     if (lev.ball_array[lev.ball_pos][5] != Xblank &&
4405         tab_blank[Cave[y+1][x-1]])
4406     {
4407       Cave[y+1][x-1] = Yball_blank;
4408       Next[y+1][x-1] = lev.ball_array[lev.ball_pos][5];
4409     }
4410
4411     if (lev.ball_array[lev.ball_pos][6] != Xblank &&
4412         tab_blank[Cave[y+1][x]])
4413     {
4414       Cave[y+1][x] = Yball_blank;
4415       Next[y+1][x] = lev.ball_array[lev.ball_pos][6];
4416     }
4417
4418     if (lev.ball_array[lev.ball_pos][7] != Xblank &&
4419         tab_blank[Cave[y+1][x+1]])
4420     {
4421       Cave[y+1][x+1] = Yball_blank;
4422       Next[y+1][x+1] = lev.ball_array[lev.ball_pos][7];
4423     }
4424   }
4425
4426   lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
4427 }
4428
4429 static void Lball_1(int x, int y)
4430 {
4431   if (lev.ball_state == 0)
4432     return;
4433
4434   Cave[y][x] = Yball_1;
4435   Next[y][x] = Xball_2;
4436   if (lev.ball_cnt)
4437     return;
4438
4439   Lball_common(x, y);
4440 }
4441
4442 static void Lball_2(int x, int y)
4443 {
4444   if (lev.ball_state == 0)
4445     return;
4446
4447   Cave[y][x] = Yball_2;
4448   Next[y][x] = Xball_1;
4449   if (lev.ball_cnt)
4450     return;
4451
4452   Lball_common(x, y);
4453 }
4454
4455 static void Ldrip(int x, int y)
4456 {
4457   Next[y][x] = Xdrip_fall;
4458 }
4459
4460 static void Ldrip_fall(int x, int y)
4461 {
4462   int temp;
4463
4464   switch (Cave[y+1][x])
4465   {
4466     case Xacid_1:
4467     case Xacid_2:
4468     case Xacid_3:
4469     case Xacid_4:
4470     case Xacid_5:
4471     case Xacid_6:
4472     case Xacid_7:
4473     case Xacid_8:
4474       Cave[y][x] = Ydrip_1_sB;
4475       if (Cave[y][x+1] == Xblank)
4476         Cave[y][x+1] = Xacid_splash_e;
4477       if (Cave[y][x-1] == Xblank)
4478         Cave[y][x-1] = Xacid_splash_w;
4479       Next[y][x] = Xdrip_stretchB;
4480       play_element_sound(x, y, SOUND_acid, Xacid_1);
4481       return;
4482
4483     case Xblank:
4484     case Xacid_splash_e:
4485     case Xacid_splash_w:
4486     case Xplant:
4487     case Yplant:
4488     case Zplayer:
4489       Cave[y][x] = Ydrip_1_sB;
4490       Cave[y+1][x] = Ydrip_1_s;
4491       Next[y][x] = Xdrip_stretchB;
4492       Next[y+1][x] = Xdrip_stretch;
4493       return;
4494
4495     default:
4496       switch (RANDOM & 7)
4497       {
4498         case 0:
4499           temp = Xamoeba_1;
4500           break;
4501
4502         case 1:
4503           temp = Xamoeba_2;
4504           break;
4505
4506         case 2:
4507           temp = Xamoeba_3;
4508           break;
4509
4510         case 3:
4511           temp = Xamoeba_4;
4512           break;
4513
4514         case 4:
4515           temp = Xamoeba_5;
4516           break;
4517
4518         case 5:
4519           temp = Xamoeba_6;
4520           break;
4521
4522         case 6:
4523           temp = Xamoeba_7;
4524           break;
4525
4526         case 7:
4527           temp = Xamoeba_8;
4528           break;
4529       }
4530
4531       Cave[y][x] = temp;
4532       Next[y][x] = temp;
4533       play_element_sound(x, y, SOUND_drip, Xdrip_fall);
4534       return;
4535   }
4536 }
4537
4538 static void Ldrip_stretch(int x, int y)
4539 {
4540   Cave[y][x] = Ydrip_2_s;
4541   Next[y][x] = Xdrip_fall;
4542 }
4543
4544 static void Ldrip_stretchB(int x, int y)
4545 {
4546   Cave[y][x] = Ydrip_2_sB;
4547   Next[y][x] = Xblank;
4548 }
4549
4550 static void Lwonderwall(int x, int y)
4551 {
4552   if (lev.wonderwall_time && lev.wonderwall_state)
4553   {
4554     Cave[y][x] = XwonderwallB;
4555     play_element_sound(x, y, SOUND_wonder, Xwonderwall);
4556   }
4557 }
4558
4559 static void Lsand_stone(int x, int y)
4560 {
4561   switch (Cave[y+1][x])
4562   {
4563     case Xacid_1:
4564     case Xacid_2:
4565     case Xacid_3:
4566     case Xacid_4:
4567     case Xacid_5:
4568     case Xacid_6:
4569     case Xacid_7:
4570     case Xacid_8:
4571       Cave[y][x] = Xsand_stonesand_quickout_1;
4572       if (Cave[y][x+1] == Xblank)
4573         Cave[y][x+1] = Xacid_splash_e;
4574       if (Cave[y][x-1] == Xblank)
4575         Cave[y][x-1] = Xacid_splash_w;
4576       Next[y][x] = Xsand_stonesand_quickout_2;
4577       play_element_sound(x, y, SOUND_acid, Xacid_1);
4578       return;
4579
4580     case Xblank:
4581     case Xacid_splash_e:
4582     case Xacid_splash_w:
4583       Cave[y][x] = Xsand_stonesand_quickout_1;
4584       Cave[y+1][x] = Xsand_stoneout_1;
4585       Next[y][x] = Xsand_stonesand_quickout_2;
4586       Next[y+1][x] = Xsand_stoneout_2;
4587       return;
4588
4589     case Xsand:
4590       Cave[y][x] = Xsand_stonesand_1;
4591       Cave[y+1][x] = Xsand_sandstone_1;
4592       Next[y][x] = Xsand_stonesand_2;
4593       Next[y+1][x] = Xsand_sandstone_2;
4594       return;
4595   }
4596 }
4597
4598 static void Lsand_stonein_1(int x, int y)
4599 {
4600   Next[y][x] = Xsand_stonein_2;
4601 }
4602
4603 static void Lsand_stonein_2(int x, int y)
4604 {
4605   Next[y][x] = Xsand_stonein_3;
4606 }
4607
4608 static void Lsand_stonein_3(int x, int y)
4609 {
4610   Next[y][x] = Xsand_stonein_4;
4611 }
4612
4613 static void Lsand_stonein_4(int x, int y)
4614 {
4615   Next[y][x] = Xblank;
4616 }
4617
4618 static void Lsand_stonesand_1(int x, int y)
4619 {
4620   Next[y][x] = Xsand_stonesand_2;
4621 }
4622
4623 static void Lsand_stonesand_2(int x, int y)
4624 {
4625   Next[y][x] = Xsand_stonesand_3;
4626 }
4627
4628 static void Lsand_stonesand_3(int x, int y)
4629 {
4630   Next[y][x] = Xsand_stonesand_4;
4631 }
4632
4633 static void Lsand_stonesand_4(int x, int y)
4634 {
4635   Next[y][x] = Xsand;
4636 }
4637
4638 #if 1
4639 static void Lsand_stonesand_quickout_1(int x, int y)
4640 {
4641   Next[y][x] = Xsand_stonesand_quickout_2;
4642 }
4643
4644 static void Lsand_stonesand_quickout_2(int x, int y)
4645 {
4646   Next[y][x] = Xsand;
4647 }
4648 #endif
4649
4650 static void Lsand_stoneout_1(int x, int y)
4651 {
4652   Next[y][x] = Xsand_stoneout_2;
4653 }
4654
4655 static void Lsand_stoneout_2(int x, int y)
4656 {
4657   Next[y][x] = Xstone_fall;
4658 }
4659
4660 static void Lsand_sandstone_1(int x, int y)
4661 {
4662   Next[y][x] = Xsand_sandstone_2;
4663 }
4664
4665 static void Lsand_sandstone_2(int x, int y)
4666 {
4667   Next[y][x] = Xsand_sandstone_3;
4668 }
4669
4670 static void Lsand_sandstone_3(int x, int y)
4671 {
4672   Next[y][x] = Xsand_sandstone_4;
4673 }
4674
4675 static void Lsand_sandstone_4(int x, int y)
4676 {
4677   Next[y][x] = Xsand_stone;
4678 }
4679
4680 static void Lslidewall_ns(int x, int y)
4681 {
4682   if (tab_blank[Cave[y-1][x]])
4683   {
4684     Cave[y-1][x] = Yslidewall_ns_blank;
4685     Next[y-1][x] = Xslidewall_ns;
4686     play_element_sound(x, y, SOUND_slidewall, Xslidewall_ns);
4687   }
4688
4689   if (tab_blank[Cave[y+1][x]])
4690   {
4691     Cave[y+1][x] = Yslidewall_ns_blank;
4692     Next[y+1][x] = Xslidewall_ns;
4693     play_element_sound(x, y, SOUND_slidewall, Xslidewall_ns);
4694   }
4695 }
4696
4697 static void Lslidewall_ew(int x, int y)
4698 {
4699   if (tab_blank[Cave[y][x+1]])
4700   {
4701     Cave[y][x+1] = Yslidewall_ew_blank;
4702     Next[y][x+1] = Xslidewall_ew;
4703     play_element_sound(x, y, SOUND_slidewall, Xslidewall_ew);
4704   }
4705
4706   if (tab_blank[Cave[y][x-1]])
4707   {
4708     Cave[y][x-1] = Yslidewall_ew_blank;
4709     Next[y][x-1] = Xslidewall_ew;
4710     play_element_sound(x, y, SOUND_slidewall, Xslidewall_ew);
4711   }
4712 }
4713
4714 static void Lexit(int x, int y)
4715 {
4716   if (lev.required > 0)
4717     return;
4718
4719   int temp = RANDOM & 63;
4720
4721   if (temp < 21)
4722   {
4723     Cave[y][x] = Xexit_1;
4724     Next[y][x] = Xexit_2;
4725   }
4726   else if (temp < 42)
4727   {
4728     Cave[y][x] = Xexit_2;
4729     Next[y][x] = Xexit_3;
4730   }
4731   else
4732   {
4733     Cave[y][x] = Xexit_3;
4734     Next[y][x] = Xexit_1;
4735   }
4736
4737   play_element_sound(x, y, SOUND_exit_open, Xexit);
4738 }
4739
4740 static void Lexit_1(int x, int y)
4741 {
4742   Next[y][x] = Xexit_2;
4743 }
4744
4745 static void Lexit_2(int x, int y)
4746 {
4747   Next[y][x] = Xexit_3;
4748 }
4749
4750 static void Lexit_3(int x, int y)
4751 {
4752   Next[y][x] = Xexit_1;
4753 }
4754
4755 static void Lacid_1(int x, int y)
4756 {
4757   Next[y][x] = Xacid_2;
4758 }
4759
4760 static void Lacid_2(int x, int y)
4761 {
4762   Next[y][x] = Xacid_3;
4763 }
4764
4765 static void Lacid_3(int x, int y)
4766 {
4767   Next[y][x] = Xacid_4;
4768 }
4769
4770 static void Lacid_4(int x, int y)
4771 {
4772   Next[y][x] = Xacid_5;
4773 }
4774
4775 static void Lacid_5(int x, int y)
4776 {
4777   Next[y][x] = Xacid_6;
4778 }
4779
4780 static void Lacid_6(int x, int y)
4781 {
4782   Next[y][x] = Xacid_7;
4783 }
4784
4785 static void Lacid_7(int x, int y)
4786 {
4787   Next[y][x] = Xacid_8;
4788 }
4789
4790 static void Lacid_8(int x, int y)
4791 {
4792   Next[y][x] = Xacid_1;
4793 }
4794
4795 static void Lfake_acid_1(int x, int y)
4796 {
4797   Next[y][x] = Xfake_acid_2;
4798 }
4799
4800 static void Lfake_acid_2(int x, int y)
4801 {
4802   Next[y][x] = Xfake_acid_3;
4803 }
4804
4805 static void Lfake_acid_3(int x, int y)
4806 {
4807   Next[y][x] = Xfake_acid_4;
4808 }
4809
4810 static void Lfake_acid_4(int x, int y)
4811 {
4812   Next[y][x] = Xfake_acid_5;
4813 }
4814
4815 static void Lfake_acid_5(int x, int y)
4816 {
4817   Next[y][x] = Xfake_acid_6;
4818 }
4819
4820 static void Lfake_acid_6(int x, int y)
4821 {
4822   Next[y][x] = Xfake_acid_7;
4823 }
4824
4825 static void Lfake_acid_7(int x, int y)
4826 {
4827   Next[y][x] = Xfake_acid_8;
4828 }
4829
4830 static void Lfake_acid_8(int x, int y)
4831 {
4832   Next[y][x] = Xfake_acid_1;
4833 }
4834
4835 static void Lpause(int x, int y)
4836 {
4837   Next[y][x] = Xblank;
4838 }
4839
4840 static void Ldynamite_1(int x, int y)
4841 {
4842   play_element_sound(x, y, SOUND_tick, Xdynamite_1);
4843   Next[y][x] = Xdynamite_2;
4844 }
4845
4846 static void Ldynamite_2(int x, int y)
4847 {
4848   play_element_sound(x, y, SOUND_tick, Xdynamite_2);
4849   Next[y][x] = Xdynamite_3;
4850 }
4851
4852 static void Ldynamite_3(int x, int y)
4853 {
4854   play_element_sound(x, y, SOUND_tick, Xdynamite_3);
4855   Next[y][x] = Xdynamite_4;
4856 }
4857
4858 static void Ldynamite_4(int x, int y)
4859 {
4860   play_element_sound(x, y, SOUND_tick, Xdynamite_4);
4861   Next[y][x] = Zdynamite;
4862   Boom[y-1][x-1] = Xblank;
4863   Boom[y-1][x] = Xblank;
4864   Boom[y-1][x+1] = Xblank;
4865   Boom[y][x-1] = Xblank;
4866   Boom[y][x] = Xblank;
4867   Boom[y][x+1] = Xblank;
4868   Boom[y+1][x-1] = Xblank;
4869   Boom[y+1][x] = Xblank;
4870   Boom[y+1][x+1] = Xblank;
4871 }
4872
4873 static void Lwheel(int x, int y)
4874 {
4875   if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
4876     Cave[y][x] = XwheelB;
4877 }
4878
4879 static void Lswitch(int x, int y)
4880 {
4881   if (lev.ball_state)
4882     Cave[y][x] = XswitchB;
4883 }
4884
4885 static void Lfake_amoeba(int x, int y)
4886 {
4887   if (lev.lenses_cnt)
4888     Cave[y][x] = Xfake_amoebaB;
4889 }
4890
4891 static void Lfake_blank(int x, int y)
4892 {
4893   if (lev.lenses_cnt)
4894     Cave[y][x] = Xfake_blankB;
4895 }
4896
4897 static void Lfake_grass(int x, int y)
4898 {
4899   if (lev.magnify_cnt)
4900     Cave[y][x] = Xfake_grassB;
4901 }
4902
4903 static void Lfake_door_1(int x, int y)
4904 {
4905   if (lev.magnify_cnt)
4906     Cave[y][x] = Xdoor_1;
4907 }
4908
4909 static void Lfake_door_2(int x, int y)
4910 {
4911   if (lev.magnify_cnt)
4912     Cave[y][x] = Xdoor_2;
4913 }
4914
4915 static void Lfake_door_3(int x, int y)
4916 {
4917   if (lev.magnify_cnt)
4918     Cave[y][x] = Xdoor_3;
4919 }
4920
4921 static void Lfake_door_4(int x, int y)
4922 {
4923   if (lev.magnify_cnt)
4924     Cave[y][x] = Xdoor_4;
4925 }
4926
4927 static void Lfake_door_5(int x, int y)
4928 {
4929   if (lev.magnify_cnt)
4930     Cave[y][x] = Xdoor_5;
4931 }
4932
4933 static void Lfake_door_6(int x, int y)
4934 {
4935   if (lev.magnify_cnt)
4936     Cave[y][x] = Xdoor_6;
4937 }
4938
4939 static void Lfake_door_7(int x, int y)
4940 {
4941   if (lev.magnify_cnt)
4942     Cave[y][x] = Xdoor_7;
4943 }
4944
4945 static void Lfake_door_8(int x, int y)
4946 {
4947   if (lev.magnify_cnt)
4948     Cave[y][x] = Xdoor_8;
4949 }
4950
4951 static void Lboom_1(int x, int y)
4952 {
4953   Next[y][x] = Xboom_2;
4954 #if !PLAY_ELEMENT_SOUND
4955   if (x != lev.exit_x && y != lev.exit_y)
4956     play_sound(x, y, SOUND_boom);
4957   else
4958     lev.exit_x = lev.exit_y = -1;
4959 #endif
4960 }
4961
4962 static void Lboom_2(int x, int y)
4963 {
4964   Next[y][x] = Boom[y][x];
4965 }
4966
4967 static void Lboom_android(int x, int y)
4968 {
4969 #if PLAY_ELEMENT_SOUND
4970   play_element_sound(x, y, SOUND_boom, Xandroid);
4971 #endif
4972
4973   Lboom_1(x, y);
4974 }
4975
4976 void synchro_2(void)
4977 {
4978   int x = 0;
4979   int y = 1;
4980   short *cave_cache = Cave[y];  /* might be a win */
4981   int element;
4982
4983   random_em = RandomEM;
4984   score = 0;
4985
4986  loop:
4987
4988   element = cave_cache[++x];
4989
4990   switch (element)
4991   {
4992     case Xacid_1:               Lacid_1(x, y);                  goto loop;
4993     case Xacid_2:               Lacid_2(x, y);                  goto loop;
4994     case Xacid_3:               Lacid_3(x, y);                  goto loop;
4995     case Xacid_4:               Lacid_4(x, y);                  goto loop;
4996     case Xacid_5:               Lacid_5(x, y);                  goto loop;
4997     case Xacid_6:               Lacid_6(x, y);                  goto loop;
4998     case Xacid_7:               Lacid_7(x, y);                  goto loop;
4999     case Xacid_8:               Lacid_8(x, y);                  goto loop;
5000
5001     case Xfake_acid_1:          Lfake_acid_1(x, y);             goto loop;
5002     case Xfake_acid_2:          Lfake_acid_2(x, y);             goto loop;
5003     case Xfake_acid_3:          Lfake_acid_3(x, y);             goto loop;
5004     case Xfake_acid_4:          Lfake_acid_4(x, y);             goto loop;
5005     case Xfake_acid_5:          Lfake_acid_5(x, y);             goto loop;
5006     case Xfake_acid_6:          Lfake_acid_6(x, y);             goto loop;
5007     case Xfake_acid_7:          Lfake_acid_7(x, y);             goto loop;
5008     case Xfake_acid_8:          Lfake_acid_8(x, y);             goto loop;
5009
5010     case Xandroid:              Landroid(x, y);                 goto loop;
5011     case Xandroid_1_n:          Landroid_1_n(x, y);             goto loop;
5012     case Xandroid_2_n:          Landroid_2_n(x, y);             goto loop;
5013     case Xandroid_1_e:          Landroid_1_e(x, y);             goto loop;
5014     case Xandroid_2_e:          Landroid_2_e(x, y);             goto loop;
5015     case Xandroid_1_s:          Landroid_1_s(x, y);             goto loop;
5016     case Xandroid_2_s:          Landroid_2_s(x, y);             goto loop;
5017     case Xandroid_1_w:          Landroid_1_w(x, y);             goto loop;
5018     case Xandroid_2_w:          Landroid_2_w(x, y);             goto loop;
5019
5020     case Xeater_n:              Leater_n(x, y);                 goto loop;
5021     case Xeater_e:              Leater_e(x, y);                 goto loop;
5022     case Xeater_s:              Leater_s(x, y);                 goto loop;
5023     case Xeater_w:              Leater_w(x, y);                 goto loop;
5024
5025     case Xalien:                Lalien(x, y);                   goto loop;
5026     case Xalien_pause:          Lalien_pause(x, y);             goto loop;
5027
5028     case Xbug_1_n:              Lbug_1_n(x, y);                 goto loop;
5029     case Xbug_2_n:              Lbug_2_n(x, y);                 goto loop;
5030     case Xbug_1_e:              Lbug_1_e(x, y);                 goto loop;
5031     case Xbug_2_e:              Lbug_2_e(x, y);                 goto loop;
5032     case Xbug_1_s:              Lbug_1_s(x, y);                 goto loop;
5033     case Xbug_2_s:              Lbug_2_s(x, y);                 goto loop;
5034     case Xbug_1_w:              Lbug_1_w(x, y);                 goto loop;
5035     case Xbug_2_w:              Lbug_2_w(x, y);                 goto loop;
5036
5037     case Xtank_1_n:             Ltank_1_n(x, y);                goto loop;
5038     case Xtank_2_n:             Ltank_2_n(x, y);                goto loop;
5039     case Xtank_1_e:             Ltank_1_e(x, y);                goto loop;
5040     case Xtank_2_e:             Ltank_2_e(x, y);                goto loop;
5041     case Xtank_1_s:             Ltank_1_s(x, y);                goto loop;
5042     case Xtank_2_s:             Ltank_2_s(x, y);                goto loop;
5043     case Xtank_1_w:             Ltank_1_w(x, y);                goto loop;
5044     case Xtank_2_w:             Ltank_2_w(x, y);                goto loop;
5045
5046     case Xemerald:              Lemerald(x, y);                 goto loop;
5047     case Xemerald_pause:        Lemerald_pause(x, y);           goto loop;
5048     case Xemerald_fall:         Lemerald_fall(x, y);            goto loop;
5049
5050     case Xdiamond:              Ldiamond(x, y);                 goto loop;
5051     case Xdiamond_pause:        Ldiamond_pause(x, y);           goto loop;
5052     case Xdiamond_fall:         Ldiamond_fall(x, y);            goto loop;
5053
5054     case Xstone:                Lstone(x, y);                   goto loop;
5055     case Xstone_pause:          Lstone_pause(x, y);             goto loop;
5056     case Xstone_fall:           Lstone_fall(x, y);              goto loop;
5057
5058     case Xbomb:                 Lbomb(x, y);                    goto loop;
5059     case Xbomb_pause:           Lbomb_pause(x, y);              goto loop;
5060     case Xbomb_fall:            Lbomb_fall(x, y);               goto loop;
5061
5062     case Xnut:                  Lnut(x, y);                     goto loop;
5063     case Xnut_pause:            Lnut_pause(x, y);               goto loop;
5064     case Xnut_fall:             Lnut_fall(x, y);                goto loop;
5065
5066     case Xspring:               Lspring(x, y);                  goto loop;
5067     case Xspring_pause:         Lspring_pause(x, y);            goto loop;
5068     case Xspring_e:             Lspring_e(x, y);                goto loop;
5069     case Xspring_w:             Lspring_w(x, y);                goto loop;
5070     case Xspring_fall:          Lspring_fall(x, y);             goto loop;
5071
5072     case Xpush_emerald_e:       Lpush_emerald_e(x, y);          goto loop;
5073     case Xpush_emerald_w:       Lpush_emerald_w(x, y);          goto loop;
5074     case Xpush_diamond_e:       Lpush_diamond_e(x, y);          goto loop;
5075     case Xpush_diamond_w:       Lpush_diamond_w(x, y);          goto loop;
5076     case Xpush_stone_e:         Lpush_stone_e(x, y);            goto loop;
5077     case Xpush_stone_w:         Lpush_stone_w(x, y);            goto loop;
5078     case Xpush_bomb_e:          Lpush_bomb_e(x, y);             goto loop;
5079     case Xpush_bomb_w:          Lpush_bomb_w(x, y);             goto loop;
5080     case Xpush_nut_e:           Lpush_nut_e(x, y);              goto loop;
5081     case Xpush_nut_w:           Lpush_nut_w(x, y);              goto loop;
5082     case Xpush_spring_e:        Lpush_spring_e(x, y);           goto loop;
5083     case Xpush_spring_w:        Lpush_spring_w(x, y);           goto loop;
5084
5085     case Xdynamite_1:           Ldynamite_1(x, y);              goto loop;
5086     case Xdynamite_2:           Ldynamite_2(x, y);              goto loop;
5087     case Xdynamite_3:           Ldynamite_3(x, y);              goto loop;
5088     case Xdynamite_4:           Ldynamite_4(x, y);              goto loop;
5089
5090     case Xfake_door_1:          Lfake_door_1(x, y);             goto loop;
5091     case Xfake_door_2:          Lfake_door_2(x, y);             goto loop;
5092     case Xfake_door_3:          Lfake_door_3(x, y);             goto loop;
5093     case Xfake_door_4:          Lfake_door_4(x, y);             goto loop;
5094     case Xfake_door_5:          Lfake_door_5(x, y);             goto loop;
5095     case Xfake_door_6:          Lfake_door_6(x, y);             goto loop;
5096     case Xfake_door_7:          Lfake_door_7(x, y);             goto loop;
5097     case Xfake_door_8:          Lfake_door_8(x, y);             goto loop;
5098
5099     case Xballoon:              Lballoon(x, y);                 goto loop;
5100
5101     case Xball_1:               Lball_1(x, y);                  goto loop;
5102     case Xball_2:               Lball_2(x, y);                  goto loop;
5103
5104     case Xdrip:                 Ldrip(x, y);                    goto loop;
5105     case Xdrip_fall:            Ldrip_fall(x, y);               goto loop;
5106     case Xdrip_stretch:         Ldrip_stretch(x, y);            goto loop;
5107     case Xdrip_stretchB:        Ldrip_stretchB(x, y);           goto loop;
5108
5109     case Xwonderwall:           Lwonderwall(x, y);              goto loop;
5110
5111     case Xwheel:                Lwheel(x, y);                   goto loop;
5112
5113     case Xswitch:               Lswitch(x, y);                  goto loop;
5114
5115     case Xfake_blank:           Lfake_blank(x, y);              goto loop;
5116     case Xfake_grass:           Lfake_grass(x, y);              goto loop;
5117     case Xfake_amoeba:          Lfake_amoeba(x, y);             goto loop;
5118
5119     case Xsand_stone:           Lsand_stone(x, y);              goto loop;
5120     case Xsand_stonein_1:       Lsand_stonein_1(x, y);          goto loop;
5121     case Xsand_stonein_2:       Lsand_stonein_2(x, y);          goto loop;
5122     case Xsand_stonein_3:       Lsand_stonein_3(x, y);          goto loop;
5123     case Xsand_stonein_4:       Lsand_stonein_4(x, y);          goto loop;
5124     case Xsand_sandstone_1:     Lsand_sandstone_1(x, y);        goto loop;
5125     case Xsand_sandstone_2:     Lsand_sandstone_2(x, y);        goto loop;
5126     case Xsand_sandstone_3:     Lsand_sandstone_3(x, y);        goto loop;
5127     case Xsand_sandstone_4:     Lsand_sandstone_4(x, y);        goto loop;
5128     case Xsand_stonesand_1:     Lsand_stonesand_1(x, y);        goto loop;
5129     case Xsand_stonesand_2:     Lsand_stonesand_2(x, y);        goto loop;
5130     case Xsand_stonesand_3:     Lsand_stonesand_3(x, y);        goto loop;
5131     case Xsand_stonesand_4:     Lsand_stonesand_4(x, y);        goto loop;
5132     case Xsand_stoneout_1:      Lsand_stoneout_1(x, y);         goto loop;
5133     case Xsand_stoneout_2:      Lsand_stoneout_2(x, y);         goto loop;
5134 #if 1
5135     case Xsand_stonesand_quickout_1:Lsand_stonesand_quickout_1(x, y);goto loop;
5136     case Xsand_stonesand_quickout_2:Lsand_stonesand_quickout_2(x, y);goto loop;
5137 #endif
5138
5139     case Xslidewall_ns:         Lslidewall_ns(x, y);            goto loop;
5140     case Xslidewall_ew:         Lslidewall_ew(x, y);            goto loop;
5141
5142     case Xexit:                 Lexit(x, y);                    goto loop;
5143     case Xexit_1:               Lexit_1(x, y);                  goto loop;
5144     case Xexit_2:               Lexit_2(x, y);                  goto loop;
5145     case Xexit_3:               Lexit_3(x, y);                  goto loop;
5146
5147     case Xpause:                Lpause(x, y);                   goto loop;
5148
5149     case Xboom_bug:             Lboom_bug(x, y);                goto loop;
5150     case Xboom_bomb:            Lboom_tank(x, y);               goto loop;
5151     case Xboom_android:         Lboom_android(x, y);            goto loop;
5152     case Xboom_1:               Lboom_1(x, y);                  goto loop;
5153     case Xboom_2:               Lboom_2(x, y);                  goto loop;
5154
5155     case Zborder:
5156       if (++y < HEIGHT - 1)
5157       {
5158         x = 0;
5159         cave_cache = Cave[y];
5160         goto loop;
5161       }
5162
5163       goto done;
5164
5165     default:
5166       goto loop;
5167   }
5168
5169 #undef RANDOM
5170 #undef PLAY
5171 #undef PLAY_FORCE
5172
5173  done:
5174
5175   if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
5176     lev.score += score;         /* only add a score if someone is alive */
5177   else
5178     game_em.game_over = TRUE;
5179
5180   RandomEM = random_em;
5181
5182   {
5183     void *temp = Cave;
5184
5185     /* triple buffering */
5186     Cave = Next;
5187     Next = Draw;
5188     Draw = temp;
5189   }
5190 }