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