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