5 * my own version of the emerald mine engine
11 #define SPRING_ROLL /* spring rolling off round things continues to roll */
12 #define ACID_ROLL /* rolling objects go into acid rather than remove it */
13 #define ACID_PLAYER /* player gets killed by acid, but without explosion */
15 #define RANDOM(x) ((seed = seed << 31 | seed >> 1) % x)
17 static short **cave, **next, **boom;
18 static unsigned int seed;
21 static const byte is_blank[GAME_TILE_MAX] =
36 static const byte is_blank_or_acid[GAME_TILE_MAX] =
59 static const byte is_fake_acid[GAME_TILE_MAX] =
71 static const byte is_amoeba[GAME_TILE_MAX] =
85 static byte is_android_blank[GAME_TILE_MAX] =
100 static const byte is_android_walkable[GAME_TILE_MAX] =
116 static void Lboom_generic(int x, int y, int element, int element_middle)
118 boom[x-1][y-1] = element;
119 boom[x][y-1] = element;
120 boom[x+1][y-1] = element;
121 boom[x-1][y] = element;
122 boom[x][y] = element_middle;
123 boom[x+1][y] = element;
124 boom[x-1][y+1] = element;
125 boom[x][y+1] = element;
126 boom[x+1][y+1] = element;
129 static void Lboom_bug(int x, int y)
131 if (game_em.use_old_explosions)
134 Lboom_generic(x, y, Xemerald, Xdiamond);
136 #if PLAY_ELEMENT_SOUND
137 play_element_sound(x, y, SOUND_boom, Xbug_1_n);
141 static void Lboom_tank(int x, int y)
143 if (game_em.use_old_explosions)
146 Lboom_generic(x, y, Xblank, Xblank);
148 #if PLAY_ELEMENT_SOUND
149 play_element_sound(x, y, SOUND_boom, Xtank_1_n);
153 static void Lboom_eater(int x, int y)
155 if (game_em.use_old_explosions)
158 boom[x-1][y-1] = lev.eater_array[lev.eater_pos][0];
159 boom[x][y-1] = lev.eater_array[lev.eater_pos][1];
160 boom[x+1][y-1] = lev.eater_array[lev.eater_pos][2];
161 boom[x-1][y] = lev.eater_array[lev.eater_pos][3];
162 boom[x][y] = lev.eater_array[lev.eater_pos][4];
163 boom[x+1][y] = lev.eater_array[lev.eater_pos][5];
164 boom[x-1][y+1] = lev.eater_array[lev.eater_pos][6];
165 boom[x][y+1] = lev.eater_array[lev.eater_pos][7];
166 boom[x+1][y+1] = lev.eater_array[lev.eater_pos][8];
168 lev.eater_pos = (lev.eater_pos + 1) % lev.num_eater_arrays;
170 #if PLAY_ELEMENT_SOUND
171 play_element_sound(x, y, SOUND_boom, Xeater_n);
175 static void Lboom_bug_old(int x, int y)
177 if (!game_em.use_old_explosions)
183 static void Lboom_tank_old(int x, int y)
185 if (!game_em.use_old_explosions)
191 static void Lboom_eater_old(int x, int y)
193 if (!game_em.use_old_explosions)
199 static void Lboom_bug_new(int x, int y, boolean chain_explosion)
201 if (game_em.use_old_explosions)
210 static void Lboom_tank_new(int x, int y, boolean chain_explosion)
212 if (game_em.use_old_explosions)
221 static void Lboom_eater_new(int x, int y, boolean chain_explosion)
223 if (game_em.use_old_explosions)
232 static void Lboom_cave_new(int x, int y, int element)
234 if (game_em.use_old_explosions)
237 cave[x][y] = element;
240 static void Lboom_next_new(int x, int y, int element)
242 if (game_em.use_old_explosions)
245 next[x][y] = element;
248 static void Lpush_element_old(int x, int y, int element)
250 if (!game_em.use_old_push_elements)
253 cave[x][y] = element;
254 next[x][y] = element;
257 static boolean player_killed(struct PLAYER *ply)
265 if (lev.killed_out_of_time && setup.time_limit)
268 switch (cave[x][y-1])
289 switch (cave[x+1][y])
310 switch (cave[x][y+1])
331 switch (cave[x-1][y])
376 static void kill_player(struct PLAYER *ply)
383 switch (cave[x][y-1])
393 cave[x][y-1] = Xboom_bug;
394 Lboom_bug_new(x, y-1, TRUE);
405 cave[x][y-1] = Xboom_tank;
406 Lboom_tank_new(x, y-1, TRUE);
410 switch (cave[x+1][y])
420 cave[x+1][y] = Xboom_bug;
421 Lboom_bug_new(x+1, y, TRUE);
432 cave[x+1][y] = Xboom_tank;
433 Lboom_tank_new(x+1, y, TRUE);
437 switch (cave[x][y+1])
447 cave[x][y+1] = Xboom_bug;
448 Lboom_bug_new(x, y+1, TRUE);
459 cave[x][y+1] = Xboom_tank;
460 Lboom_tank_new(x, y+1, TRUE);
464 switch (cave[x-1][y])
474 cave[x-1][y] = Xboom_bug;
475 Lboom_bug_new(x-1, y, TRUE);
486 cave[x-1][y] = Xboom_tank;
487 Lboom_tank_new(x-1, y, TRUE);
498 play_element_sound(x, y, SOUND_exit_leave, Xexit_1);
502 play_element_sound(x, y, SOUND_die, Zplayer);
521 cave[x][y] = Xboom_1;
527 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
529 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
534 boolean result = TRUE;
536 if (!dx && !dy) /* no direction specified */
539 if (dx && dy && ply->joy_snap) /* more than one direction specified */
542 if (!ply->joy_snap) /* player wants to move */
544 int element = cave[x][y];
548 /* fire is released */
552 cave[x][y] = Zplayer;
553 next[x][y] = Zplayer;
564 play_element_sound(x, y, SOUND_blank, Xblank);
565 ply->anim = PLY_walk_n + anim;
579 if (cave[x+1][y-1] == Xblank)
580 cave[x+1][y-1] = Xsplash_e;
581 if (cave[x-1][y-1] == Xblank)
582 cave[x-1][y-1] = Xsplash_w;
583 play_element_sound(x, y, SOUND_acid, Xacid_1);
604 ply->anim = PLY_walk_n + anim;
610 cave[x][y] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
611 (dx > 0 ? Ygrass_eB : Ygrass_wB));
612 next[x][y] = Zplayer;
613 play_element_sound(x, y, SOUND_dirt, Xgrass);
614 ply->anim = PLY_walk_n + anim;
620 cave[x][y] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
621 (dx > 0 ? Ydirt_eB : Ydirt_wB));
622 next[x][y] = Zplayer;
623 play_element_sound(x, y, SOUND_dirt, Xdirt);
624 ply->anim = PLY_walk_n + anim;
631 cave[x][y] = Ydiamond_blank;
632 next[x][y] = Zplayer;
633 play_element_sound(x, y, SOUND_collect, element);
634 lev.score += lev.diamond_score;
635 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
636 game.snapshot.collected_item = TRUE;
637 ply->anim = PLY_walk_n + anim;
644 cave[x][y] = Yemerald_blank;
645 next[x][y] = Zplayer;
646 play_element_sound(x, y, SOUND_collect, element);
647 lev.score += lev.emerald_score;
648 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
649 game.snapshot.collected_item = TRUE;
650 ply->anim = PLY_walk_n + anim;
656 cave[x][y] = Ydynamite_blank;
657 next[x][y] = Zplayer;
658 play_element_sound(x, y, SOUND_collect, element);
659 lev.score += lev.dynamite_score;
660 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
661 ply->anim = PLY_walk_n + anim;
668 cave[x][y] = Ykey_1_blank;
673 cave[x][y] = Ykey_2_blank;
678 cave[x][y] = Ykey_3_blank;
683 cave[x][y] = Ykey_4_blank;
688 cave[x][y] = Ykey_5_blank;
693 cave[x][y] = Ykey_6_blank;
698 cave[x][y] = Ykey_7_blank;
703 cave[x][y] = Ykey_8_blank;
708 next[x][y] = Zplayer;
709 play_element_sound(x, y, SOUND_collect, element);
710 lev.score += lev.key_score;
711 ply->anim = PLY_walk_n + anim;
717 cave[x][y] = Ylenses_blank;
718 next[x][y] = Zplayer;
719 play_element_sound(x, y, SOUND_collect, element);
720 lev.score += lev.lenses_score;
721 lev.lenses_cnt = lev.lenses_time;
722 ply->anim = PLY_walk_n + anim;
728 cave[x][y] = Ymagnify_blank;
729 next[x][y] = Zplayer;
730 play_element_sound(x, y, SOUND_collect, element);
731 lev.score += lev.magnify_score;
732 lev.magnify_cnt = lev.magnify_time;
733 ply->anim = PLY_walk_n + anim;
742 switch (cave[x+dx][y])
755 cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
756 next[x+dx][y] = Xstone_pause;
767 if (cave[x+dx+1][y-1] == Xblank)
768 cave[x+dx+1][y-1] = Xsplash_e;
769 if (cave[x+dx-1][y-1] == Xblank)
770 cave[x+dx-1][y-1] = Xsplash_w;
771 play_element_sound(x, y, SOUND_acid, Xacid_1);
775 cave[x][y] = dx > 0 ? Ystone_eB : Ystone_wB;
776 next[x][y] = Zplayer;
777 play_element_sound(x, y, SOUND_roll, Xstone);
782 ply->anim = PLY_push_n + anim;
789 switch (cave[x+dx][y])
802 cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
803 next[x+dx][y] = Xbomb_pause;
814 if (cave[x+dx+1][y-1] == Xblank)
815 cave[x+dx+1][y-1] = Xsplash_e;
816 if (cave[x+dx-1][y-1] == Xblank)
817 cave[x+dx-1][y-1] = Xsplash_w;
818 play_element_sound(x, y, SOUND_acid, Xacid_1);
822 cave[x][y] = dx > 0 ? Ybomb_eB : Ybomb_wB;
823 next[x][y] = Zplayer;
824 play_element_sound(x, y, SOUND_roll, Xbomb);
829 ply->anim = PLY_push_n + anim;
836 switch (cave[x+dx][y])
849 cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
850 next[x+dx][y] = Xnut_pause;
861 if (cave[x+dx+1][y-1] == Xblank)
862 cave[x+dx+1][y-1] = Xsplash_e;
863 if (cave[x+dx-1][y-1] == Xblank)
864 cave[x+dx-1][y-1] = Xsplash_w;
865 play_element_sound(x, y, SOUND_acid, Xacid_1);
869 cave[x][y] = dx > 0 ? Ynut_eB : Ynut_wB;
870 next[x][y] = Zplayer;
871 play_element_sound(x, y, SOUND_roll, Xnut);
876 ply->anim = PLY_push_n + anim;
883 switch (cave[x+dx][y])
896 cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
897 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
908 if (cave[x+dx+1][y-1] == Xblank)
909 cave[x+dx+1][y-1] = Xsplash_e;
910 if (cave[x+dx-1][y-1] == Xblank)
911 cave[x+dx-1][y-1] = Xsplash_w;
912 play_element_sound(x, y, SOUND_acid, Xacid_1);
916 cave[x][y] = dx > 0 ? Yspring_eB : Yspring_wB;
917 next[x][y] = Zplayer;
918 play_element_sound(x, y, SOUND_roll, Xspring);
924 cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
925 cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
926 next[x][y] = Zplayer;
927 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
928 play_element_sound(x, y, SOUND_slurp, Xalien);
929 lev.score += lev.slurp_score;
934 ply->anim = PLY_push_n + anim;
941 case Xsand_stonein_1:
942 case Xsand_stonein_2:
943 case Xsand_stonein_3:
944 case Xsand_stonein_4:
948 ply->anim = PLY_push_n + anim;
952 switch (cave[x+dx][y+dy])
965 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
966 (dx > 0 ? Yballoon_e : Yballoon_w));
967 next[x+dx][y+dy] = Xballoon;
978 if (cave[x+dx+1][y+dy-1] == Xblank)
979 cave[x+dx+1][y+dy-1] = Xsplash_e;
980 if (cave[x+dx-1][y+dy-1] == Xblank)
981 cave[x+dx-1][y+dy-1] = Xsplash_w;
982 play_element_sound(x, y, SOUND_acid, Xacid_1);
986 cave[x][y] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
987 (dx > 0 ? Yballoon_eB : Yballoon_wB));
988 next[x][y] = Zplayer;
989 play_element_sound(x, y, SOUND_push, Xballoon);
995 ply->anim = PLY_push_n + anim;
1007 switch (cave[x+dx][y+dy])
1020 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
1021 (dx > 0 ? Yandroid_e : Yandroid_w));
1022 next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
1023 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
1034 if (cave[x+dx+1][y+dy-1] == Xblank)
1035 cave[x+dx+1][y+dy-1] = Xsplash_e;
1036 if (cave[x+dx-1][y+dy-1] == Xblank)
1037 cave[x+dx-1][y+dy-1] = Xsplash_w;
1038 play_element_sound(x, y, SOUND_acid, Xacid_1);
1042 cave[x][y] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
1043 (dx > 0 ? Yandroid_eB : Yandroid_wB));
1044 next[x][y] = Zplayer;
1045 play_element_sound(x, y, SOUND_push, Xandroid);
1051 ply->anim = PLY_push_n + anim;
1056 if (ply->keys & 0x01)
1063 if (ply->keys & 0x02)
1070 if (ply->keys & 0x04)
1077 if (ply->keys & 0x08)
1084 if (ply->keys & 0x10)
1091 if (ply->keys & 0x20)
1098 if (ply->keys & 0x40)
1105 if (ply->keys & 0x80)
1112 if (!is_blank[cave[x+dx][y+dy]])
1115 if (!is_fake_acid[cave[x+dx][y+dy]])
1117 cave[x+dx][y+dy] = Zplayer;
1118 next[x+dx][y+dy] = Zplayer;
1121 play_element_sound(x, y, SOUND_door, element);
1122 ply->anim = PLY_walk_n + anim;
1128 play_element_sound(x, y, SOUND_press, element);
1129 lev.wheel_cnt = lev.wheel_time;
1135 lev.wind_direction = 0;
1139 lev.wind_direction = 1;
1143 lev.wind_direction = 2;
1147 lev.wind_direction = 3;
1151 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1156 play_element_sound(x, y, SOUND_press, element);
1157 lev.wind_cnt = lev.wind_time;
1161 play_element_sound(x, y, SOUND_press, element);
1166 play_element_sound(x, y, SOUND_press, element);
1167 lev.ball_cnt = lev.ball_time;
1168 lev.ball_active = !lev.ball_active;
1172 cave[x][y] = Yplant;
1173 next[x][y] = Xplant;
1174 play_element_sound(x, y, SOUND_blank, Xplant);
1175 ply->anim = PLY_walk_n + anim;
1186 game_em.level_solved = TRUE;
1188 ply->anim = PLY_walk_n + anim;
1195 if (ply->x == oldx && ply->y == oldy) /* no movement */
1198 else /* player wants to snap */
1200 int element = cave[x][y];
1204 /* fire is pressed */
1207 cave[x][y] = Ygrass_blank;
1208 next[x][y] = Xblank;
1209 play_element_sound(x, y, SOUND_dirt, element);
1210 ply->anim = PLY_shoot_n + anim;
1214 cave[x][y] = Ydirt_blank;
1215 next[x][y] = Xblank;
1216 play_element_sound(x, y, SOUND_dirt, element);
1217 ply->anim = PLY_shoot_n + anim;
1221 case Xdiamond_pause:
1222 cave[x][y] = Ydiamond_blank;
1223 next[x][y] = Xblank;
1224 play_element_sound(x, y, SOUND_collect, element);
1225 lev.score += lev.diamond_score;
1226 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
1227 game.snapshot.collected_item = TRUE;
1228 ply->anim = PLY_walk_n + anim;
1232 case Xemerald_pause:
1233 cave[x][y] = Yemerald_blank;
1234 next[x][y] = Xblank;
1235 play_element_sound(x, y, SOUND_collect, element);
1236 lev.score += lev.emerald_score;
1237 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
1238 game.snapshot.collected_item = TRUE;
1239 ply->anim = PLY_walk_n + anim;
1243 cave[x][y] = Ydynamite_blank;
1244 next[x][y] = Xblank;
1245 play_element_sound(x, y, SOUND_collect, element);
1246 lev.score += lev.dynamite_score;
1247 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1248 ply->anim = PLY_walk_n + anim;
1253 cave[x][y] = Ykey_1_blank;
1258 cave[x][y] = Ykey_2_blank;
1263 cave[x][y] = Ykey_3_blank;
1268 cave[x][y] = Ykey_4_blank;
1273 cave[x][y] = Ykey_5_blank;
1278 cave[x][y] = Ykey_6_blank;
1283 cave[x][y] = Ykey_7_blank;
1288 cave[x][y] = Ykey_8_blank;
1293 next[x][y] = Xblank;
1294 play_element_sound(x, y, SOUND_collect, element);
1295 lev.score += lev.key_score;
1296 ply->anim = PLY_walk_n + anim;
1300 cave[x][y] = Ylenses_blank;
1301 next[x][y] = Xblank;
1302 play_element_sound(x, y, SOUND_collect, element);
1303 lev.score += lev.lenses_score;
1304 lev.lenses_cnt = lev.lenses_time;
1305 ply->anim = PLY_walk_n + anim;
1309 cave[x][y] = Ymagnify_blank;
1310 next[x][y] = Xblank;
1311 play_element_sound(x, y, SOUND_collect, element);
1312 lev.score += lev.magnify_score;
1313 lev.magnify_cnt = lev.magnify_time;
1314 ply->anim = PLY_walk_n + anim;
1322 /* check for wrap-around movement */
1323 if (ply->x < lev.left ||
1324 ply->x > lev.right - 1)
1325 play_element_sound(oldx, oldy, SOUND_door, Xdoor_1);
1330 static void check_player(struct PLAYER *ply)
1338 game_em.last_player_direction[ply->num] = MV_NONE;
1340 if (ply->joy_w) /* west */
1345 else if (ply->joy_e) /* east */
1351 if (ply->joy_n) /* north */
1356 else if (ply->joy_s) /* south */
1368 boolean players_visible_before_move;
1369 boolean players_visible_after_move;
1372 players_visible_before_move = checkIfAllPlayersFitToScreen();
1377 players_visible_after_move = checkIfAllPlayersFitToScreen();
1380 player is allowed to move only in the following cases:
1381 - it is not needed to display all players (not focussed to all players)
1382 - all players are (still or again) visible after the move
1383 - some players were already outside visible screen area before the move
1385 can_move = (game.centered_player_nr != -1 ||
1386 players_visible_after_move ||
1387 !players_visible_before_move);
1403 if (dx == 0 && dy == 0)
1405 ply->joy_stick = FALSE;
1409 if (++ply->dynamite_cnt == 5 && ply->dynamite)
1411 cave[x][y] = Xdynamite_1;
1412 play_element_sound(x, y, SOUND_dynamite, Xdynamite_1);
1418 ply->dynamite_cnt = 0;
1421 /* be a bit more random if the player doesn't move */
1422 game_em.random += 7;
1427 ply->joy_stick = TRUE;
1433 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
1435 if (!ply->joy_snap) /* player wants to move */
1437 boolean moved = FALSE;
1439 if (ply->last_move_dir & MV_HORIZONTAL)
1441 if (!(moved = player_digfield(ply, 0, dy)))
1442 moved = player_digfield(ply, dx, 0);
1446 if (!(moved = player_digfield(ply, dx, 0)))
1447 moved = player_digfield(ply, 0, dy);
1453 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
1454 else if (oldy != ply->y)
1455 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
1457 game_em.any_player_moving = TRUE;
1458 game_em.last_moving_player = ply->num;
1459 game_em.last_player_direction[ply->num] = ply->last_move_dir;
1462 else /* player wants to snap */
1464 game_em.any_player_snapping = player_digfield(ply, dx, dy);
1468 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
1470 int distance, distance_shortest = CAVE_WIDTH + CAVE_HEIGHT;
1473 /* default values if no players are alive anymore */
1477 for (i = 0; i < MAX_PLAYERS; i++)
1482 distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
1484 if (distance < distance_shortest)
1489 distance_shortest = distance;
1494 static void Lacid_1(int x, int y)
1496 next[x][y] = Xacid_2;
1499 static void Lacid_2(int x, int y)
1501 next[x][y] = Xacid_3;
1504 static void Lacid_3(int x, int y)
1506 next[x][y] = Xacid_4;
1509 static void Lacid_4(int x, int y)
1511 next[x][y] = Xacid_5;
1514 static void Lacid_5(int x, int y)
1516 next[x][y] = Xacid_6;
1519 static void Lacid_6(int x, int y)
1521 next[x][y] = Xacid_7;
1524 static void Lacid_7(int x, int y)
1526 next[x][y] = Xacid_8;
1529 static void Lacid_8(int x, int y)
1531 next[x][y] = Xacid_1;
1534 static void Lfake_acid_1(int x, int y)
1536 next[x][y] = Xfake_acid_2;
1539 static void Lfake_acid_2(int x, int y)
1541 next[x][y] = Xfake_acid_3;
1544 static void Lfake_acid_3(int x, int y)
1546 next[x][y] = Xfake_acid_4;
1549 static void Lfake_acid_4(int x, int y)
1551 next[x][y] = Xfake_acid_5;
1554 static void Lfake_acid_5(int x, int y)
1556 next[x][y] = Xfake_acid_6;
1559 static void Lfake_acid_6(int x, int y)
1561 next[x][y] = Xfake_acid_7;
1564 static void Lfake_acid_7(int x, int y)
1566 next[x][y] = Xfake_acid_8;
1569 static void Lfake_acid_8(int x, int y)
1571 next[x][y] = Xfake_acid_1;
1574 static void Landroid(int x, int y)
1578 if (lev.android_clone_cnt == 0)
1580 if (!is_android_blank[cave[x-1][y-1]] &&
1581 !is_android_blank[cave[x][y-1]] &&
1582 !is_android_blank[cave[x+1][y-1]] &&
1583 !is_android_blank[cave[x-1][y]] &&
1584 !is_android_blank[cave[x+1][y]] &&
1585 !is_android_blank[cave[x-1][y+1]] &&
1586 !is_android_blank[cave[x][y+1]] &&
1587 !is_android_blank[cave[x+1][y+1]])
1592 /* randomly find an object to clone */
1594 case 0: /* S,NE,W,NW,SE,E,SW,N */
1595 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1596 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1597 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1598 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1599 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1600 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1601 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1602 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1605 case 1: /* NW,SE,N,S,NE,SW,E,W */
1606 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1607 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1608 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1609 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1610 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1611 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1612 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1613 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1616 case 2: /* SW,E,S,W,N,NW,SE,NE */
1617 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1618 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1619 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1620 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1621 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1622 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1623 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1624 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1627 case 3: /* N,SE,NE,E,W,S,NW,SW */
1628 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1629 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1630 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1631 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1632 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1633 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1634 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1635 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1638 case 4: /* SE,NW,E,NE,SW,W,N,S */
1639 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1640 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1641 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1642 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1643 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1644 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1645 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1646 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1649 case 5: /* NE,W,SE,SW,S,N,E,NW */
1650 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1651 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1652 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1653 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1654 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1655 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1656 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1657 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1660 case 6: /* E,N,SW,S,NW,NE,SE,W */
1661 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1662 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1663 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1664 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1665 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1666 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1667 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1668 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1671 case 7: /* W,SW,NW,N,E,SE,NE,S */
1672 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1673 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1674 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1675 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1676 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1677 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1678 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1679 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1683 next[x][y] = temp; /* the item we chose to clone */
1684 play_element_sound(x, y, SOUND_android_clone, temp);
1688 /* randomly find a direction to move */
1690 case 0: /* S,NE,W,NW,SE,E,SW,N */
1691 if (is_android_blank[cave[x][y+1]]) goto android_s;
1692 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1693 if (is_android_blank[cave[x-1][y]]) goto android_w;
1694 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1695 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1696 if (is_android_blank[cave[x+1][y]]) goto android_e;
1697 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1698 if (is_android_blank[cave[x][y-1]]) goto android_n;
1701 case 1: /* NW,SE,N,S,NE,SW,E,W */
1702 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1703 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1704 if (is_android_blank[cave[x][y-1]]) goto android_n;
1705 if (is_android_blank[cave[x][y+1]]) goto android_s;
1706 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1707 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1708 if (is_android_blank[cave[x+1][y]]) goto android_e;
1709 if (is_android_blank[cave[x-1][y]]) goto android_w;
1712 case 2: /* SW,E,S,W,N,NW,SE,NE */
1713 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1714 if (is_android_blank[cave[x+1][y]]) goto android_e;
1715 if (is_android_blank[cave[x][y+1]]) goto android_s;
1716 if (is_android_blank[cave[x-1][y]]) goto android_w;
1717 if (is_android_blank[cave[x][y-1]]) goto android_n;
1718 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1719 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1720 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1723 case 3: /* N,SE,NE,E,W,S,NW,SW */
1724 if (is_android_blank[cave[x][y-1]]) goto android_n;
1725 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1726 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1727 if (is_android_blank[cave[x+1][y]]) goto android_e;
1728 if (is_android_blank[cave[x-1][y]]) goto android_w;
1729 if (is_android_blank[cave[x][y+1]]) goto android_s;
1730 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1731 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1734 case 4: /* SE,NW,E,NE,SW,W,N,S */
1735 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1736 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1737 if (is_android_blank[cave[x+1][y]]) goto android_e;
1738 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1739 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1740 if (is_android_blank[cave[x-1][y]]) goto android_w;
1741 if (is_android_blank[cave[x][y-1]]) goto android_n;
1742 if (is_android_blank[cave[x][y+1]]) goto android_s;
1745 case 5: /* NE,W,SE,SW,S,N,E,NW */
1746 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1747 if (is_android_blank[cave[x-1][y]]) goto android_w;
1748 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1749 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1750 if (is_android_blank[cave[x][y+1]]) goto android_s;
1751 if (is_android_blank[cave[x][y-1]]) goto android_n;
1752 if (is_android_blank[cave[x+1][y]]) goto android_e;
1753 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1756 case 6: /* E,N,SW,S,NW,NE,SE,W */
1757 if (is_android_blank[cave[x+1][y]]) goto android_e;
1758 if (is_android_blank[cave[x][y-1]]) goto android_n;
1759 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1760 if (is_android_blank[cave[x][y+1]]) goto android_s;
1761 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1762 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1763 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1764 if (is_android_blank[cave[x-1][y]]) goto android_w;
1767 case 7: /* W,SW,NW,N,E,SE,NE,S */
1768 if (is_android_blank[cave[x-1][y]]) goto android_w;
1769 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1770 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1771 if (is_android_blank[cave[x][y-1]]) goto android_n;
1772 if (is_android_blank[cave[x+1][y]]) goto android_e;
1773 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1774 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1775 if (is_android_blank[cave[x][y+1]]) goto android_s;
1781 if (lev.android_move_cnt == 0)
1783 if (cave[x-1][y-1] == Zplayer ||
1784 cave[x][y-1] == Zplayer ||
1785 cave[x+1][y-1] == Zplayer ||
1786 cave[x-1][y] == Zplayer ||
1787 cave[x+1][y] == Zplayer ||
1788 cave[x-1][y+1] == Zplayer ||
1789 cave[x][y+1] == Zplayer ||
1790 cave[x+1][y+1] == Zplayer)
1793 set_nearest_player_xy(x, y, &dx, &dy);
1795 next[x][y] = Xblank; /* assume we will move */
1796 temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
1802 /* attempt clockwise move first if direct path is blocked */
1804 case 0: /* north west */
1805 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1806 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1807 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1811 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1812 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1813 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1816 case 2: /* north east */
1817 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1818 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1819 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1823 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1824 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1825 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1828 case 4: /* nowhere */
1832 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1833 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1834 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1837 case 6: /* south west */
1838 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1839 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1840 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1844 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1845 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1846 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1849 case 8: /* south east */
1850 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1851 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1852 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1860 /* attempt counterclockwise move first if direct path is blocked */
1862 case 0: /* north west */
1863 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1864 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1865 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1869 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1870 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1871 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1874 case 2: /* north east */
1875 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1876 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1877 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1881 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1882 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1883 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1886 case 4: /* nowhere */
1890 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1891 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1892 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1895 case 6: /* south west */
1896 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1897 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1898 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1902 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1903 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1904 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1907 case 8: /* south east */
1908 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1909 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1910 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1917 next[x][y] = Xandroid;
1921 cave[x][y] = Yandroid_nB;
1922 cave[x][y-1] = Yandroid_n;
1923 next[x][y-1] = Xandroid;
1924 play_element_sound(x, y, SOUND_android_move, Xandroid);
1928 cave[x][y] = Yandroid_neB;
1929 cave[x+1][y-1] = Yandroid_ne;
1930 next[x+1][y-1] = Xandroid;
1931 play_element_sound(x, y, SOUND_android_move, Xandroid);
1935 cave[x][y] = Yandroid_eB;
1936 cave[x+1][y] = Yandroid_e;
1937 next[x+1][y] = Xandroid;
1938 play_element_sound(x, y, SOUND_android_move, Xandroid);
1942 cave[x][y] = Yandroid_seB;
1943 cave[x+1][y+1] = Yandroid_se;
1944 next[x+1][y+1] = Xandroid;
1945 play_element_sound(x, y, SOUND_android_move, Xandroid);
1949 cave[x][y] = Yandroid_sB;
1950 cave[x][y+1] = Yandroid_s;
1951 next[x][y+1] = Xandroid;
1952 play_element_sound(x, y, SOUND_android_move, Xandroid);
1956 cave[x][y] = Yandroid_swB;
1957 cave[x-1][y+1] = Yandroid_sw;
1958 next[x-1][y+1] = Xandroid;
1959 play_element_sound(x, y, SOUND_android_move, Xandroid);
1963 cave[x][y] = Yandroid_wB;
1964 cave[x-1][y] = Yandroid_w;
1965 next[x-1][y] = Xandroid;
1966 play_element_sound(x, y, SOUND_android_move, Xandroid);
1970 cave[x][y] = Yandroid_nwB;
1971 cave[x-1][y-1] = Yandroid_nw;
1972 next[x-1][y-1] = Xandroid;
1973 play_element_sound(x, y, SOUND_android_move, Xandroid);
1977 static void Landroid_1_n(int x, int y)
1979 switch (cave[x][y-1])
1992 cave[x][y] = Yandroid_nB;
1993 next[x][y] = Xblank;
1994 cave[x][y-1] = Yandroid_n;
1995 next[x][y-1] = Xandroid;
1996 play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
2007 cave[x][y] = Yandroid_nB;
2008 next[x][y] = Xblank;
2009 if (cave[x+1][y-2] == Xblank)
2010 cave[x+1][y-2] = Xsplash_e;
2011 if (cave[x-1][y-2] == Xblank)
2012 cave[x-1][y-2] = Xsplash_w;
2013 play_element_sound(x, y, SOUND_acid, Xacid_1);
2022 static void Landroid_2_n(int x, int y)
2024 switch (cave[x][y-1])
2037 cave[x][y] = Yandroid_nB;
2038 next[x][y] = Xblank;
2039 cave[x][y-1] = Yandroid_n;
2040 next[x][y-1] = Xandroid_1_n;
2041 play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
2052 cave[x][y] = Yandroid_nB;
2053 next[x][y] = Xblank;
2054 if (cave[x+1][y-2] == Xblank)
2055 cave[x+1][y-2] = Xsplash_e;
2056 if (cave[x-1][y-2] == Xblank)
2057 cave[x-1][y-2] = Xsplash_w;
2058 play_element_sound(x, y, SOUND_acid, Xacid_1);
2067 static void Landroid_1_e(int x, int y)
2069 switch (cave[x+1][y])
2082 cave[x][y] = Yandroid_eB;
2083 next[x][y] = Xblank;
2084 cave[x+1][y] = Yandroid_e;
2085 next[x+1][y] = Xandroid;
2086 play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
2097 cave[x][y] = Yandroid_eB;
2098 next[x][y] = Xblank;
2099 if (cave[x+2][y-1] == Xblank)
2100 cave[x+2][y-1] = Xsplash_e;
2101 if (cave[x][y-1] == Xblank)
2102 cave[x][y-1] = Xsplash_w;
2103 play_element_sound(x, y, SOUND_acid, Xacid_1);
2112 static void Landroid_2_e(int x, int y)
2114 switch (cave[x+1][y])
2127 cave[x][y] = Yandroid_eB;
2128 next[x][y] = Xblank;
2129 cave[x+1][y] = Yandroid_e;
2130 next[x+1][y] = Xandroid_1_e;
2131 play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
2142 cave[x][y] = Yandroid_eB;
2143 next[x][y] = Xblank;
2144 if (cave[x+2][y-1] == Xblank)
2145 cave[x+2][y-1] = Xsplash_e;
2146 if (cave[x][y-1] == Xblank)
2147 cave[x][y-1] = Xsplash_w;
2148 play_element_sound(x, y, SOUND_acid, Xacid_1);
2157 static void Landroid_1_s(int x, int y)
2159 switch (cave[x][y+1])
2172 cave[x][y] = Yandroid_sB;
2173 next[x][y] = Xblank;
2174 cave[x][y+1] = Yandroid_s;
2175 next[x][y+1] = Xandroid;
2176 play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
2187 cave[x][y] = Yandroid_sB;
2188 next[x][y] = Xblank;
2189 if (cave[x+1][y] == Xblank)
2190 cave[x+1][y] = Xsplash_e;
2191 if (cave[x-1][y] == Xblank)
2192 cave[x-1][y] = Xsplash_w;
2193 play_element_sound(x, y, SOUND_acid, Xacid_1);
2202 static void Landroid_2_s(int x, int y)
2204 switch (cave[x][y+1])
2217 cave[x][y] = Yandroid_sB;
2218 next[x][y] = Xblank;
2219 cave[x][y+1] = Yandroid_s;
2220 next[x][y+1] = Xandroid_1_s;
2221 play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
2232 cave[x][y] = Yandroid_sB;
2233 next[x][y] = Xblank;
2234 if (cave[x+1][y] == Xblank)
2235 cave[x+1][y] = Xsplash_e;
2236 if (cave[x-1][y] == Xblank)
2237 cave[x-1][y] = Xsplash_w;
2238 play_element_sound(x, y, SOUND_acid, Xacid_1);
2247 static void Landroid_1_w(int x, int y)
2249 switch (cave[x-1][y])
2262 cave[x][y] = Yandroid_wB;
2263 next[x][y] = Xblank;
2264 cave[x-1][y] = Yandroid_w;
2265 next[x-1][y] = Xandroid;
2266 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2277 cave[x][y] = Yandroid_wB;
2278 next[x][y] = Xblank;
2279 if (cave[x][y-1] == Xblank)
2280 cave[x][y-1] = Xsplash_e;
2281 if (cave[x-2][y-1] == Xblank)
2282 cave[x-2][y-1] = Xsplash_w;
2283 play_element_sound(x, y, SOUND_acid, Xacid_1);
2292 static void Landroid_2_w(int x, int y)
2294 switch (cave[x-1][y])
2307 cave[x][y] = Yandroid_wB;
2308 next[x][y] = Xblank;
2309 cave[x-1][y] = Yandroid_w;
2310 next[x-1][y] = Xandroid_1_w;
2311 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2322 cave[x][y] = Yandroid_wB;
2323 next[x][y] = Xblank;
2324 if (cave[x][y-1] == Xblank)
2325 cave[x][y-1] = Xsplash_e;
2326 if (cave[x-2][y-1] == Xblank)
2327 cave[x-2][y-1] = Xsplash_w;
2328 play_element_sound(x, y, SOUND_acid, Xacid_1);
2337 static void Leater_n(int x, int y)
2339 if (cave[x+1][y] == Xdiamond)
2341 cave[x+1][y] = Ydiamond_blank;
2342 next[x+1][y] = Xblank;
2343 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2347 if (cave[x][y+1] == Xdiamond)
2349 cave[x][y+1] = Ydiamond_blank;
2350 next[x][y+1] = Xblank;
2351 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2355 if (cave[x-1][y] == Xdiamond)
2357 cave[x-1][y] = Ydiamond_blank;
2358 next[x-1][y] = Xblank;
2359 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2363 if (cave[x][y-1] == Xdiamond)
2365 cave[x][y-1] = Ydiamond_blank;
2366 next[x][y-1] = Xblank;
2367 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2371 switch (cave[x][y-1])
2387 cave[x][y] = Yeater_nB;
2388 next[x][y] = Xblank;
2389 cave[x][y-1] = Yeater_n;
2390 next[x][y-1] = Xeater_n;
2401 cave[x][y] = Yeater_nB;
2402 next[x][y] = Xblank;
2403 if (cave[x+1][y-2] == Xblank)
2404 cave[x+1][y-2] = Xsplash_e;
2405 if (cave[x-1][y-2] == Xblank)
2406 cave[x-1][y-2] = Xsplash_w;
2407 play_element_sound(x, y, SOUND_acid, Xacid_1);
2411 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2412 play_element_sound(x, y, SOUND_eater, Xeater_n);
2417 static void Leater_e(int x, int y)
2419 if (cave[x][y+1] == Xdiamond)
2421 cave[x][y+1] = Ydiamond_blank;
2422 next[x][y+1] = Xblank;
2423 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2427 if (cave[x-1][y] == Xdiamond)
2429 cave[x-1][y] = Ydiamond_blank;
2430 next[x-1][y] = Xblank;
2431 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2435 if (cave[x][y-1] == Xdiamond)
2437 cave[x][y-1] = Ydiamond_blank;
2438 next[x][y-1] = Xblank;
2439 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2443 if (cave[x+1][y] == Xdiamond)
2445 cave[x+1][y] = Ydiamond_blank;
2446 next[x+1][y] = Xblank;
2447 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2451 switch (cave[x+1][y])
2467 cave[x][y] = Yeater_eB;
2468 next[x][y] = Xblank;
2469 cave[x+1][y] = Yeater_e;
2470 next[x+1][y] = Xeater_e;
2481 cave[x][y] = Yeater_eB;
2482 next[x][y] = Xblank;
2483 if (cave[x+2][y-1] == Xblank)
2484 cave[x+2][y-1] = Xsplash_e;
2485 if (cave[x][y-1] == Xblank)
2486 cave[x][y-1] = Xsplash_w;
2487 play_element_sound(x, y, SOUND_acid, Xacid_1);
2491 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2492 play_element_sound(x, y, SOUND_eater, Xeater_e);
2497 static void Leater_s(int x, int y)
2499 if (cave[x-1][y] == Xdiamond)
2501 cave[x-1][y] = Ydiamond_blank;
2502 next[x-1][y] = Xblank;
2503 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2507 if (cave[x][y-1] == Xdiamond)
2509 cave[x][y-1] = Ydiamond_blank;
2510 next[x][y-1] = Xblank;
2511 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2515 if (cave[x+1][y] == Xdiamond)
2517 cave[x+1][y] = Ydiamond_blank;
2518 next[x+1][y] = Xblank;
2519 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2523 if (cave[x][y+1] == Xdiamond)
2525 cave[x][y+1] = Ydiamond_blank;
2526 next[x][y+1] = Xblank;
2527 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2531 switch (cave[x][y+1])
2547 cave[x][y] = Yeater_sB;
2548 next[x][y] = Xblank;
2549 cave[x][y+1] = Yeater_s;
2550 next[x][y+1] = Xeater_s;
2561 cave[x][y] = Yeater_sB;
2562 next[x][y] = Xblank;
2563 if (cave[x+1][y] == Xblank)
2564 cave[x+1][y] = Xsplash_e;
2565 if (cave[x-1][y] == Xblank)
2566 cave[x-1][y] = Xsplash_w;
2567 play_element_sound(x, y, SOUND_acid, Xacid_1);
2571 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2572 play_element_sound(x, y, SOUND_eater, Xeater_s);
2577 static void Leater_w(int x, int y)
2579 if (cave[x][y-1] == Xdiamond)
2581 cave[x][y-1] = Ydiamond_blank;
2582 next[x][y-1] = Xblank;
2583 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2587 if (cave[x+1][y] == Xdiamond)
2589 cave[x+1][y] = Ydiamond_blank;
2590 next[x+1][y] = Xblank;
2591 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2595 if (cave[x][y+1] == Xdiamond)
2597 cave[x][y+1] = Ydiamond_blank;
2598 next[x][y+1] = Xblank;
2599 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2603 if (cave[x-1][y] == Xdiamond)
2605 cave[x-1][y] = Ydiamond_blank;
2606 next[x-1][y] = Xblank;
2607 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2611 switch (cave[x-1][y])
2627 cave[x][y] = Yeater_wB;
2628 next[x][y] = Xblank;
2629 cave[x-1][y] = Yeater_w;
2630 next[x-1][y] = Xeater_w;
2641 cave[x][y] = Yeater_wB;
2642 next[x][y] = Xblank;
2643 if (cave[x][y-1] == Xblank)
2644 cave[x][y-1] = Xsplash_e;
2645 if (cave[x-2][y-1] == Xblank)
2646 cave[x-2][y-1] = Xsplash_w;
2647 play_element_sound(x, y, SOUND_acid, Xacid_1);
2651 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2652 play_element_sound(x, y, SOUND_eater, Xeater_w);
2657 static void Lalien(int x, int y)
2668 set_nearest_player_xy(x, y, &dx, &dy);
2675 switch (cave[x][y-1])
2691 cave[x][y] = Yalien_nB;
2692 next[x][y] = Xblank;
2693 cave[x][y-1] = Yalien_n;
2694 next[x][y-1] = Xalien_pause;
2695 play_element_sound(x, y, SOUND_alien, Xalien);
2706 cave[x][y] = Yalien_nB;
2707 next[x][y] = Xblank;
2708 if (cave[x+1][y-2] == Xblank)
2709 cave[x+1][y-2] = Xsplash_e;
2710 if (cave[x-1][y-2] == Xblank)
2711 cave[x-1][y-2] = Xsplash_w;
2712 play_element_sound(x, y, SOUND_acid, Xacid_1);
2718 switch (cave[x][y+1])
2734 cave[x][y] = Yalien_sB;
2735 next[x][y] = Xblank;
2736 cave[x][y+1] = Yalien_s;
2737 next[x][y+1] = Xalien_pause;
2738 play_element_sound(x, y, SOUND_alien, Xalien);
2749 cave[x][y] = Yalien_sB;
2750 next[x][y] = Xblank;
2751 if (cave[x+1][y] == Xblank)
2752 cave[x+1][y] = Xsplash_e;
2753 if (cave[x-1][y] == Xblank)
2754 cave[x-1][y] = Xsplash_w;
2755 play_element_sound(x, y, SOUND_acid, Xacid_1);
2764 switch (cave[x+1][y])
2780 cave[x][y] = Yalien_eB;
2781 next[x][y] = Xblank;
2782 cave[x+1][y] = Yalien_e;
2783 next[x+1][y] = Xalien_pause;
2784 play_element_sound(x, y, SOUND_alien, Xalien);
2795 cave[x][y] = Yalien_eB;
2796 next[x][y] = Xblank;
2797 if (cave[x+2][y-1] == Xblank)
2798 cave[x+2][y-1] = Xsplash_e;
2799 if (cave[x][y-1] == Xblank)
2800 cave[x][y-1] = Xsplash_w;
2801 play_element_sound(x, y, SOUND_acid, Xacid_1);
2807 switch (cave[x-1][y])
2823 cave[x][y] = Yalien_wB;
2824 next[x][y] = Xblank;
2825 cave[x-1][y] = Yalien_w;
2826 next[x-1][y] = Xalien_pause;
2827 play_element_sound(x, y, SOUND_alien, Xalien);
2838 cave[x][y] = Yalien_wB;
2839 next[x][y] = Xblank;
2840 if (cave[x][y-1] == Xblank)
2841 cave[x][y-1] = Xsplash_e;
2842 if (cave[x-2][y-1] == Xblank)
2843 cave[x-2][y-1] = Xsplash_w;
2844 play_element_sound(x, y, SOUND_acid, Xacid_1);
2851 static void Lalien_pause(int x, int y)
2853 next[x][y] = Xalien;
2856 static void Lbug_n(int x, int y)
2858 switch (cave[x][y-1])
2874 cave[x][y] = Ybug_nB;
2875 next[x][y] = Xblank;
2876 cave[x][y-1] = Ybug_n;
2877 next[x][y-1] = Xbug_1_n;
2878 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2889 cave[x][y] = Ybug_nB;
2890 next[x][y] = Xblank;
2891 if (cave[x+1][y-2] == Xblank)
2892 cave[x+1][y-2] = Xsplash_e;
2893 if (cave[x-1][y-2] == Xblank)
2894 cave[x-1][y-2] = Xsplash_w;
2895 play_element_sound(x, y, SOUND_acid, Xacid_1);
2899 cave[x][y] = Ybug_n_w;
2900 next[x][y] = Xbug_2_w;
2901 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2906 static void Lbug_1_n(int x, int y)
2908 if (is_amoeba[cave[x][y-1]] ||
2909 is_amoeba[cave[x+1][y]] ||
2910 is_amoeba[cave[x][y+1]] ||
2911 is_amoeba[cave[x-1][y]])
2919 switch (cave[x+1][y])
2943 cave[x][y] = Ybug_n_e;
2944 next[x][y] = Xbug_2_e;
2945 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2954 static void Lbug_2_n(int x, int y)
2956 if (is_amoeba[cave[x][y-1]] ||
2957 is_amoeba[cave[x+1][y]] ||
2958 is_amoeba[cave[x][y+1]] ||
2959 is_amoeba[cave[x-1][y]])
2970 static void Lbug_e(int x, int y)
2972 switch (cave[x+1][y])
2988 cave[x][y] = Ybug_eB;
2989 next[x][y] = Xblank;
2990 cave[x+1][y] = Ybug_e;
2991 next[x+1][y] = Xbug_1_e;
2992 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
3003 cave[x][y] = Ybug_eB;
3004 next[x][y] = Xblank;
3005 if (cave[x+2][y-1] == Xblank)
3006 cave[x+2][y-1] = Xsplash_e;
3007 if (cave[x][y-1] == Xblank)
3008 cave[x][y-1] = Xsplash_w;
3009 play_element_sound(x, y, SOUND_acid, Xacid_1);
3013 cave[x][y] = Ybug_e_n;
3014 next[x][y] = Xbug_2_n;
3015 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
3020 static void Lbug_1_e(int x, int y)
3022 if (is_amoeba[cave[x][y-1]] ||
3023 is_amoeba[cave[x+1][y]] ||
3024 is_amoeba[cave[x][y+1]] ||
3025 is_amoeba[cave[x-1][y]])
3033 switch (cave[x][y+1])
3057 cave[x][y] = Ybug_e_s;
3058 next[x][y] = Xbug_2_s;
3059 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
3068 static void Lbug_2_e(int x, int y)
3070 if (is_amoeba[cave[x][y-1]] ||
3071 is_amoeba[cave[x+1][y]] ||
3072 is_amoeba[cave[x][y+1]] ||
3073 is_amoeba[cave[x-1][y]])
3084 static void Lbug_s(int x, int y)
3086 switch (cave[x][y+1])
3102 cave[x][y] = Ybug_sB;
3103 next[x][y] = Xblank;
3104 cave[x][y+1] = Ybug_s;
3105 next[x][y+1] = Xbug_1_s;
3106 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3117 cave[x][y] = Ybug_sB;
3118 next[x][y] = Xblank;
3119 if (cave[x+1][y] == Xblank)
3120 cave[x+1][y] = Xsplash_e;
3121 if (cave[x-1][y] == Xblank)
3122 cave[x-1][y] = Xsplash_w;
3123 play_element_sound(x, y, SOUND_acid, Xacid_1);
3127 cave[x][y] = Ybug_s_e;
3128 next[x][y] = Xbug_2_e;
3129 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3134 static void Lbug_1_s(int x, int y)
3136 if (is_amoeba[cave[x][y-1]] ||
3137 is_amoeba[cave[x+1][y]] ||
3138 is_amoeba[cave[x][y+1]] ||
3139 is_amoeba[cave[x-1][y]])
3147 switch (cave[x-1][y])
3171 cave[x][y] = Ybug_s_w;
3172 next[x][y] = Xbug_2_w;
3173 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3182 static void Lbug_2_s(int x, int y)
3184 if (is_amoeba[cave[x][y-1]] ||
3185 is_amoeba[cave[x+1][y]] ||
3186 is_amoeba[cave[x][y+1]] ||
3187 is_amoeba[cave[x-1][y]])
3198 static void Lbug_w(int x, int y)
3200 switch (cave[x-1][y])
3216 cave[x][y] = Ybug_wB;
3217 next[x][y] = Xblank;
3218 cave[x-1][y] = Ybug_w;
3219 next[x-1][y] = Xbug_1_w;
3220 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3231 cave[x][y] = Ybug_wB;
3232 next[x][y] = Xblank;
3233 if (cave[x][y-1] == Xblank)
3234 cave[x][y-1] = Xsplash_e;
3235 if (cave[x-2][y-1] == Xblank)
3236 cave[x-2][y-1] = Xsplash_w;
3237 play_element_sound(x, y, SOUND_acid, Xacid_1);
3241 cave[x][y] = Ybug_w_s;
3242 next[x][y] = Xbug_2_s;
3243 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3248 static void Lbug_1_w(int x, int y)
3250 if (is_amoeba[cave[x][y-1]] ||
3251 is_amoeba[cave[x+1][y]] ||
3252 is_amoeba[cave[x][y+1]] ||
3253 is_amoeba[cave[x-1][y]])
3261 switch (cave[x][y-1])
3285 cave[x][y] = Ybug_w_n;
3286 next[x][y] = Xbug_2_n;
3287 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3296 static void Lbug_2_w(int x, int y)
3298 if (is_amoeba[cave[x][y-1]] ||
3299 is_amoeba[cave[x+1][y]] ||
3300 is_amoeba[cave[x][y+1]] ||
3301 is_amoeba[cave[x-1][y]])
3312 static void Ltank_n(int x, int y)
3314 switch (cave[x][y-1])
3330 cave[x][y] = Ytank_nB;
3331 next[x][y] = Xblank;
3332 cave[x][y-1] = Ytank_n;
3333 next[x][y-1] = Xtank_1_n;
3334 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3345 cave[x][y] = Ytank_nB;
3346 next[x][y] = Xblank;
3347 if (cave[x+1][y-2] == Xblank)
3348 cave[x+1][y-2] = Xsplash_e;
3349 if (cave[x-1][y-2] == Xblank)
3350 cave[x-1][y-2] = Xsplash_w;
3351 play_element_sound(x, y, SOUND_acid, Xacid_1);
3355 cave[x][y] = Ytank_n_e;
3356 next[x][y] = Xtank_2_e;
3357 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3362 static void Ltank_1_n(int x, int y)
3364 if (is_amoeba[cave[x][y-1]] ||
3365 is_amoeba[cave[x+1][y]] ||
3366 is_amoeba[cave[x][y+1]] ||
3367 is_amoeba[cave[x-1][y]])
3375 switch (cave[x-1][y])
3399 cave[x][y] = Ytank_n_w;
3400 next[x][y] = Xtank_2_w;
3401 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3410 static void Ltank_2_n(int x, int y)
3412 if (is_amoeba[cave[x][y-1]] ||
3413 is_amoeba[cave[x+1][y]] ||
3414 is_amoeba[cave[x][y+1]] ||
3415 is_amoeba[cave[x-1][y]])
3426 static void Ltank_e(int x, int y)
3428 switch (cave[x+1][y])
3444 cave[x][y] = Ytank_eB;
3445 next[x][y] = Xblank;
3446 cave[x+1][y] = Ytank_e;
3447 next[x+1][y] = Xtank_1_e;
3448 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3459 cave[x][y] = Ytank_eB;
3460 next[x][y] = Xblank;
3461 if (cave[x+2][y-1] == Xblank)
3462 cave[x+2][y-1] = Xsplash_e;
3463 if (cave[x][y-1] == Xblank)
3464 cave[x][y-1] = Xsplash_w;
3465 play_element_sound(x, y, SOUND_acid, Xacid_1);
3469 cave[x][y] = Ytank_e_s;
3470 next[x][y] = Xtank_2_s;
3471 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3476 static void Ltank_1_e(int x, int y)
3478 if (is_amoeba[cave[x][y-1]] ||
3479 is_amoeba[cave[x+1][y]] ||
3480 is_amoeba[cave[x][y+1]] ||
3481 is_amoeba[cave[x-1][y]])
3489 switch (cave[x][y-1])
3513 cave[x][y] = Ytank_e_n;
3514 next[x][y] = Xtank_2_n;
3515 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3524 static void Ltank_2_e(int x, int y)
3526 if (is_amoeba[cave[x][y-1]] ||
3527 is_amoeba[cave[x+1][y]] ||
3528 is_amoeba[cave[x][y+1]] ||
3529 is_amoeba[cave[x-1][y]])
3540 static void Ltank_s(int x, int y)
3542 switch (cave[x][y+1])
3558 cave[x][y] = Ytank_sB;
3559 next[x][y] = Xblank;
3560 cave[x][y+1] = Ytank_s;
3561 next[x][y+1] = Xtank_1_s;
3562 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3573 cave[x][y] = Ytank_sB;
3574 next[x][y] = Xblank;
3575 if (cave[x+1][y] == Xblank)
3576 cave[x+1][y] = Xsplash_e;
3577 if (cave[x-1][y] == Xblank)
3578 cave[x-1][y] = Xsplash_w;
3579 play_element_sound(x, y, SOUND_acid, Xacid_1);
3583 cave[x][y] = Ytank_s_w;
3584 next[x][y] = Xtank_2_w;
3585 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3590 static void Ltank_1_s(int x, int y)
3592 if (is_amoeba[cave[x][y-1]] ||
3593 is_amoeba[cave[x+1][y]] ||
3594 is_amoeba[cave[x][y+1]] ||
3595 is_amoeba[cave[x-1][y]])
3603 switch (cave[x+1][y])
3627 cave[x][y] = Ytank_s_e;
3628 next[x][y] = Xtank_2_e;
3629 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3638 static void Ltank_2_s(int x, int y)
3640 if (is_amoeba[cave[x][y-1]] ||
3641 is_amoeba[cave[x+1][y]] ||
3642 is_amoeba[cave[x][y+1]] ||
3643 is_amoeba[cave[x-1][y]])
3654 static void Ltank_w(int x, int y)
3656 switch (cave[x-1][y])
3672 cave[x][y] = Ytank_wB;
3673 next[x][y] = Xblank;
3674 cave[x-1][y] = Ytank_w;
3675 next[x-1][y] = Xtank_1_w;
3676 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3687 cave[x][y] = Ytank_wB;
3688 next[x][y] = Xblank;
3689 if (cave[x][y-1] == Xblank)
3690 cave[x][y-1] = Xsplash_e;
3691 if (cave[x-2][y-1] == Xblank)
3692 cave[x-2][y-1] = Xsplash_w;
3693 play_element_sound(x, y, SOUND_acid, Xacid_1);
3697 cave[x][y] = Ytank_w_n;
3698 next[x][y] = Xtank_2_n;
3699 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3704 static void Ltank_1_w(int x, int y)
3706 if (is_amoeba[cave[x][y-1]] ||
3707 is_amoeba[cave[x+1][y]] ||
3708 is_amoeba[cave[x][y+1]] ||
3709 is_amoeba[cave[x-1][y]])
3717 switch (cave[x][y+1])
3741 cave[x][y] = Ytank_w_s;
3742 next[x][y] = Xtank_2_s;
3743 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3752 static void Ltank_2_w(int x, int y)
3754 if (is_amoeba[cave[x][y-1]] ||
3755 is_amoeba[cave[x+1][y]] ||
3756 is_amoeba[cave[x][y+1]] ||
3757 is_amoeba[cave[x-1][y]])
3768 static void Lemerald(int x, int y)
3770 switch (cave[x][y+1])
3783 cave[x][y] = Yemerald_sB;
3784 next[x][y] = Xblank;
3785 cave[x][y+1] = Yemerald_s;
3786 next[x][y+1] = Xemerald_fall;
3797 cave[x][y] = Yemerald_sB;
3798 next[x][y] = Xblank;
3799 if (cave[x+1][y] == Xblank)
3800 cave[x+1][y] = Xsplash_e;
3801 if (cave[x-1][y] == Xblank)
3802 cave[x-1][y] = Xsplash_w;
3803 play_element_sound(x, y, SOUND_acid, Xacid_1);
3816 case Xemerald_pause:
3818 case Xdiamond_pause:
3862 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3864 cave[x][y] = Yemerald_eB;
3865 next[x][y] = Xblank;
3866 cave[x+1][y] = Yemerald_e;
3867 next[x+1][y] = Xemerald_pause;
3868 if (cave[x][y+1] == Xbumper)
3869 cave[x][y+1] = Ybumper;
3873 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3875 cave[x][y] = Yemerald_wB;
3876 next[x][y] = Xblank;
3877 cave[x-1][y] = Yemerald_w;
3878 next[x-1][y] = Xemerald_pause;
3879 if (cave[x][y+1] == Xbumper)
3880 cave[x][y+1] = Ybumper;
3886 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3888 cave[x][y] = Yemerald_wB;
3889 next[x][y] = Xblank;
3890 cave[x-1][y] = Yemerald_w;
3891 next[x-1][y] = Xemerald_pause;
3892 if (cave[x][y+1] == Xbumper)
3893 cave[x][y+1] = Ybumper;
3897 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3899 cave[x][y] = Yemerald_eB;
3900 next[x][y] = Xblank;
3901 cave[x+1][y] = Yemerald_e;
3902 next[x+1][y] = Xemerald_pause;
3903 if (cave[x][y+1] == Xbumper)
3904 cave[x][y+1] = Ybumper;
3910 if (++lev.shine_cnt > 50)
3912 lev.shine_cnt = RANDOM(8);
3913 cave[x][y] = Xemerald_shine;
3920 static void Lemerald_pause(int x, int y)
3922 switch (cave[x][y+1])
3935 cave[x][y] = Yemerald_sB;
3936 next[x][y] = Xblank;
3937 cave[x][y+1] = Yemerald_s;
3938 next[x][y+1] = Xemerald_fall;
3949 cave[x][y] = Yemerald_sB;
3950 next[x][y] = Xblank;
3951 if (cave[x+1][y] == Xblank)
3952 cave[x+1][y] = Xsplash_e;
3953 if (cave[x-1][y] == Xblank)
3954 cave[x-1][y] = Xsplash_w;
3955 play_element_sound(x, y, SOUND_acid, Xacid_1);
3959 cave[x][y] = Xemerald;
3960 next[x][y] = Xemerald;
3965 static void Lemerald_fall(int x, int y)
3967 switch (cave[x][y+1])
3981 cave[x][y] = Yemerald_sB;
3982 next[x][y] = Xblank;
3983 cave[x][y+1] = Yemerald_s;
3984 next[x][y+1] = Xemerald_fall;
3995 cave[x][y] = Yemerald_sB;
3996 next[x][y] = Xblank;
3997 if (cave[x+1][y] == Xblank)
3998 cave[x+1][y] = Xsplash_e;
3999 if (cave[x-1][y] == Xblank)
4000 cave[x-1][y] = Xsplash_w;
4001 play_element_sound(x, y, SOUND_acid, Xacid_1);
4005 if (lev.wonderwall_time > 0)
4007 lev.wonderwall_active = TRUE;
4008 cave[x][y] = Yemerald_sB;
4009 next[x][y] = Xblank;
4010 if (is_blank[cave[x][y+2]])
4012 cave[x][y+2] = Ydiamond_s;
4013 next[x][y+2] = Xdiamond_fall;
4015 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4020 cave[x][y] = Xemerald;
4021 next[x][y] = Xemerald;
4022 play_element_sound(x, y, SOUND_diamond, Xemerald);
4027 static void Ldiamond(int x, int y)
4029 switch (cave[x][y+1])
4042 cave[x][y] = Ydiamond_sB;
4043 next[x][y] = Xblank;
4044 cave[x][y+1] = Ydiamond_s;
4045 next[x][y+1] = Xdiamond_fall;
4056 cave[x][y] = Ydiamond_sB;
4057 next[x][y] = Xblank;
4058 if (cave[x+1][y] == Xblank)
4059 cave[x+1][y] = Xsplash_e;
4060 if (cave[x-1][y] == Xblank)
4061 cave[x-1][y] = Xsplash_w;
4062 play_element_sound(x, y, SOUND_acid, Xacid_1);
4075 case Xemerald_pause:
4077 case Xdiamond_pause:
4121 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4123 cave[x][y] = Ydiamond_eB;
4124 next[x][y] = Xblank;
4125 cave[x+1][y] = Ydiamond_e;
4126 next[x+1][y] = Xdiamond_pause;
4127 if (cave[x][y+1] == Xbumper)
4128 cave[x][y+1] = Ybumper;
4132 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4134 cave[x][y] = Ydiamond_wB;
4135 next[x][y] = Xblank;
4136 cave[x-1][y] = Ydiamond_w;
4137 next[x-1][y] = Xdiamond_pause;
4138 if (cave[x][y+1] == Xbumper)
4139 cave[x][y+1] = Ybumper;
4145 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4147 cave[x][y] = Ydiamond_wB;
4148 next[x][y] = Xblank;
4149 cave[x-1][y] = Ydiamond_w;
4150 next[x-1][y] = Xdiamond_pause;
4151 if (cave[x][y+1] == Xbumper)
4152 cave[x][y+1] = Ybumper;
4156 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4158 cave[x][y] = Ydiamond_eB;
4159 next[x][y] = Xblank;
4160 cave[x+1][y] = Ydiamond_e;
4161 next[x+1][y] = Xdiamond_pause;
4162 if (cave[x][y+1] == Xbumper)
4163 cave[x][y+1] = Ybumper;
4169 if (++lev.shine_cnt > 50)
4171 lev.shine_cnt = RANDOM(8);
4172 cave[x][y] = Xdiamond_shine;
4179 static void Ldiamond_pause(int x, int y)
4181 switch (cave[x][y+1])
4194 cave[x][y] = Ydiamond_sB;
4195 next[x][y] = Xblank;
4196 cave[x][y+1] = Ydiamond_s;
4197 next[x][y+1] = Xdiamond_fall;
4208 cave[x][y] = Ydiamond_sB;
4209 next[x][y] = Xblank;
4210 if (cave[x+1][y] == Xblank)
4211 cave[x+1][y] = Xsplash_e;
4212 if (cave[x-1][y] == Xblank)
4213 cave[x-1][y] = Xsplash_w;
4214 play_element_sound(x, y, SOUND_acid, Xacid_1);
4218 cave[x][y] = Xdiamond;
4219 next[x][y] = Xdiamond;
4224 static void Ldiamond_fall(int x, int y)
4226 switch (cave[x][y+1])
4240 cave[x][y] = Ydiamond_sB;
4241 next[x][y] = Xblank;
4242 cave[x][y+1] = Ydiamond_s;
4243 next[x][y+1] = Xdiamond_fall;
4254 cave[x][y] = Ydiamond_sB;
4255 next[x][y] = Xblank;
4256 if (cave[x+1][y] == Xblank)
4257 cave[x+1][y] = Xsplash_e;
4258 if (cave[x-1][y] == Xblank)
4259 cave[x-1][y] = Xsplash_w;
4260 play_element_sound(x, y, SOUND_acid, Xacid_1);
4264 if (lev.wonderwall_time > 0)
4266 lev.wonderwall_active = TRUE;
4267 cave[x][y] = Ydiamond_sB;
4268 next[x][y] = Xblank;
4269 if (is_blank[cave[x][y+2]])
4271 cave[x][y+2] = Ystone_s;
4272 next[x][y+2] = Xstone_fall;
4274 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4279 cave[x][y] = Xdiamond;
4280 next[x][y] = Xdiamond;
4281 play_element_sound(x, y, SOUND_diamond, Xdiamond);
4286 static void Lstone(int x, int y)
4288 switch (cave[x][y+1])
4303 cave[x][y] = Ystone_sB;
4304 next[x][y] = Xblank;
4305 cave[x][y+1] = Ystone_s;
4306 next[x][y+1] = Xstone_fall;
4317 cave[x][y] = Ystone_sB;
4318 next[x][y] = Xblank;
4319 if (cave[x+1][y] == Xblank)
4320 cave[x+1][y] = Xsplash_e;
4321 if (cave[x-1][y] == Xblank)
4322 cave[x-1][y] = Xsplash_w;
4323 play_element_sound(x, y, SOUND_acid, Xacid_1);
4327 cave[x][y] = Xsand_stonein_1;
4328 next[x][y] = Xsand_stonein_2;
4329 cave[x][y+1] = Xsand_sandstone_1;
4330 next[x][y+1] = Xsand_sandstone_2;
4343 case Xemerald_pause:
4345 case Xdiamond_pause:
4382 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4384 cave[x][y] = Ystone_eB;
4385 next[x][y] = Xblank;
4386 cave[x+1][y] = Ystone_e;
4387 next[x+1][y] = Xstone_pause;
4388 if (cave[x][y+1] == Xbumper)
4389 cave[x][y+1] = Ybumper;
4393 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4395 cave[x][y] = Ystone_wB;
4396 next[x][y] = Xblank;
4397 cave[x-1][y] = Ystone_w;
4398 next[x-1][y] = Xstone_pause;
4399 if (cave[x][y+1] == Xbumper)
4400 cave[x][y+1] = Ybumper;
4406 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4408 cave[x][y] = Ystone_wB;
4409 next[x][y] = Xblank;
4410 cave[x-1][y] = Ystone_w;
4411 next[x-1][y] = Xstone_pause;
4412 if (cave[x][y+1] == Xbumper)
4413 cave[x][y+1] = Ybumper;
4417 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4419 cave[x][y] = Ystone_eB;
4420 next[x][y] = Xblank;
4421 cave[x+1][y] = Ystone_e;
4422 next[x+1][y] = Xstone_pause;
4423 if (cave[x][y+1] == Xbumper)
4424 cave[x][y+1] = Ybumper;
4431 static void Lstone_pause(int x, int y)
4433 switch (cave[x][y+1])
4446 cave[x][y] = Ystone_sB;
4447 next[x][y] = Xblank;
4448 cave[x][y+1] = Ystone_s;
4449 next[x][y+1] = Xstone_fall;
4460 cave[x][y] = Ystone_sB;
4461 next[x][y] = Xblank;
4462 if (cave[x+1][y] == Xblank)
4463 cave[x+1][y] = Xsplash_e;
4464 if (cave[x-1][y] == Xblank)
4465 cave[x-1][y] = Xsplash_w;
4466 play_element_sound(x, y, SOUND_acid, Xacid_1);
4470 cave[x][y] = Xstone;
4471 next[x][y] = Xstone;
4476 static void Lstone_fall(int x, int y)
4478 switch (cave[x][y+1])
4492 cave[x][y] = Ystone_sB;
4493 next[x][y] = Xblank;
4494 cave[x][y+1] = Ystone_s;
4495 next[x][y+1] = Xstone_fall;
4506 cave[x][y] = Ystone_sB;
4507 next[x][y] = Xblank;
4508 if (cave[x+1][y] == Xblank)
4509 cave[x+1][y] = Xsplash_e;
4510 if (cave[x-1][y] == Xblank)
4511 cave[x-1][y] = Xsplash_w;
4512 play_element_sound(x, y, SOUND_acid, Xacid_1);
4519 cave[x][y] = Ystone_sB;
4520 Lboom_next_new(x, y, Xblank);
4521 cave[x][y+1] = Yeater_stone;
4522 next[x][y+1] = Zeater;
4523 Lboom_eater_old(x, y+1);
4524 score += lev.eater_score;
4529 cave[x][y] = Ystone_sB;
4530 Lboom_next_new(x, y, Xblank);
4531 cave[x][y+1] = Yalien_stone;
4532 next[x][y+1] = Ztank;
4533 Lboom_tank_old(x, y+1);
4534 score += lev.alien_score;
4545 cave[x][y] = Ystone_sB;
4546 Lboom_next_new(x, y, Xblank);
4547 cave[x][y+1] = Ybug_stone;
4548 next[x][y+1] = Zbug;
4549 Lboom_bug_old(x, y+1);
4550 score += lev.bug_score;
4561 cave[x][y] = Ystone_sB;
4562 Lboom_next_new(x, y, Xblank);
4563 cave[x][y+1] = Ytank_stone;
4564 next[x][y+1] = Ztank;
4565 Lboom_tank_old(x, y+1);
4566 score += lev.tank_score;
4570 case Xdiamond_pause:
4571 switch (cave[x][y+2])
4627 next[x][y] = Xstone;
4628 play_element_sound(x, y, SOUND_stone, Xstone);
4632 cave[x][y] = Ystone_sB;
4633 next[x][y] = Xblank;
4634 cave[x][y+1] = Ydiamond_stone;
4635 next[x][y+1] = Xstone_pause;
4636 play_element_sound(x, y, SOUND_squash, Xdiamond);
4641 Lboom_cave_new(x, y, Xstone);
4642 Lboom_next_new(x, y, Xstone);
4643 cave[x][y+1] = Ybomb_blank;
4644 next[x][y+1] = Ztank;
4645 Lboom_tank_old(x, y+1);
4650 next[x][y] = Xstone;
4651 cave[x][y+1] = Ynut_stone;
4652 next[x][y+1] = Xemerald;
4653 play_element_sound(x, y, SOUND_crack, Xnut);
4654 score += lev.nut_score;
4660 switch (cave[x+1][y+1])
4675 cave[x][y+1] = Xspring_e;
4679 cave[x][y+1] = Xspring_w;
4685 switch (cave[x-1][y+1])
4700 cave[x][y+1] = Xspring_w;
4703 cave[x][y+1] = Xspring_e;
4708 next[x][y] = Xstone;
4712 if (lev.wonderwall_time > 0)
4714 lev.wonderwall_active = TRUE;
4715 cave[x][y] = Ystone_sB;
4716 next[x][y] = Xblank;
4717 if (is_blank[cave[x][y+2]])
4719 cave[x][y+2] = Yemerald_s;
4720 next[x][y+2] = Xemerald_fall;
4722 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4727 cave[x][y] = Xstone;
4728 next[x][y] = Xstone;
4729 play_element_sound(x, y, SOUND_stone, Xstone);
4734 static void Lbomb(int x, int y)
4736 switch (cave[x][y+1])
4749 cave[x][y] = Ybomb_sB;
4750 next[x][y] = Xblank;
4751 cave[x][y+1] = Ybomb_s;
4752 next[x][y+1] = Xbomb_fall;
4763 cave[x][y] = Ybomb_sB;
4764 next[x][y] = Xblank;
4765 if (cave[x+1][y] == Xblank)
4766 cave[x+1][y] = Xsplash_e;
4767 if (cave[x-1][y] == Xblank)
4768 cave[x-1][y] = Xsplash_w;
4769 play_element_sound(x, y, SOUND_acid, Xacid_1);
4782 case Xemerald_pause:
4784 case Xdiamond_pause:
4819 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4821 cave[x][y] = Ybomb_eB;
4822 next[x][y] = Xblank;
4823 cave[x+1][y] = Ybomb_e;
4824 next[x+1][y] = Xbomb_pause;
4825 if (cave[x][y+1] == Xbumper)
4826 cave[x][y+1] = Ybumper;
4830 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4832 cave[x][y] = Ybomb_wB;
4833 next[x][y] = Xblank;
4834 cave[x-1][y] = Ybomb_w;
4835 next[x-1][y] = Xbomb_pause;
4836 if (cave[x][y+1] == Xbumper)
4837 cave[x][y+1] = Ybumper;
4843 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4845 cave[x][y] = Ybomb_wB;
4846 next[x][y] = Xblank;
4847 cave[x-1][y] = Ybomb_w;
4848 next[x-1][y] = Xbomb_pause;
4849 if (cave[x][y+1] == Xbumper)
4850 cave[x][y+1] = Ybumper;
4854 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4856 cave[x][y] = Ybomb_eB;
4857 next[x][y] = Xblank;
4858 cave[x+1][y] = Ybomb_e;
4859 next[x+1][y] = Xbomb_pause;
4860 if (cave[x][y+1] == Xbumper)
4861 cave[x][y+1] = Ybumper;
4868 static void Lbomb_pause(int x, int y)
4870 switch (cave[x][y+1])
4883 cave[x][y] = Ybomb_sB;
4884 next[x][y] = Xblank;
4885 cave[x][y+1] = Ybomb_s;
4886 next[x][y+1] = Xbomb_fall;
4897 cave[x][y] = Ybomb_sB;
4898 next[x][y] = Xblank;
4899 if (cave[x+1][y] == Xblank)
4900 cave[x+1][y] = Xsplash_e;
4901 if (cave[x-1][y] == Xblank)
4902 cave[x-1][y] = Xsplash_w;
4903 play_element_sound(x, y, SOUND_acid, Xacid_1);
4913 static void Lbomb_fall(int x, int y)
4915 switch (cave[x][y+1])
4928 cave[x][y] = Ybomb_sB;
4929 next[x][y] = Xblank;
4930 cave[x][y+1] = Ybomb_s;
4931 next[x][y+1] = Xbomb_fall;
4942 cave[x][y] = Ybomb_sB;
4943 next[x][y] = Xblank;
4944 if (cave[x+1][y] == Xblank)
4945 cave[x+1][y] = Xsplash_e;
4946 if (cave[x-1][y] == Xblank)
4947 cave[x-1][y] = Xsplash_w;
4948 play_element_sound(x, y, SOUND_acid, Xacid_1);
4952 cave[x][y] = Ybomb_blank;
4954 Lboom_tank_old(x, y);
4959 static void Lnut(int x, int y)
4961 switch (cave[x][y+1])
4974 cave[x][y] = Ynut_sB;
4975 next[x][y] = Xblank;
4976 cave[x][y+1] = Ynut_s;
4977 next[x][y+1] = Xnut_fall;
4988 cave[x][y] = Ynut_sB;
4989 next[x][y] = Xblank;
4990 if (cave[x+1][y] == Xblank)
4991 cave[x+1][y] = Xsplash_e;
4992 if (cave[x-1][y] == Xblank)
4993 cave[x-1][y] = Xsplash_w;
4994 play_element_sound(x, y, SOUND_acid, Xacid_1);
5007 case Xemerald_pause:
5009 case Xdiamond_pause:
5044 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5046 cave[x][y] = Ynut_eB;
5047 next[x][y] = Xblank;
5048 cave[x+1][y] = Ynut_e;
5049 next[x+1][y] = Xnut_pause;
5050 if (cave[x][y+1] == Xbumper)
5051 cave[x][y+1] = Ybumper;
5055 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5057 cave[x][y] = Ynut_wB;
5058 next[x][y] = Xblank;
5059 cave[x-1][y] = Ynut_w;
5060 next[x-1][y] = Xnut_pause;
5061 if (cave[x][y+1] == Xbumper)
5062 cave[x][y+1] = Ybumper;
5068 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5070 cave[x][y] = Ynut_wB;
5071 next[x][y] = Xblank;
5072 cave[x-1][y] = Ynut_w;
5073 next[x-1][y] = Xnut_pause;
5074 if (cave[x][y+1] == Xbumper)
5075 cave[x][y+1] = Ybumper;
5079 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5081 cave[x][y] = Ynut_eB;
5082 next[x][y] = Xblank;
5083 cave[x+1][y] = Ynut_e;
5084 next[x+1][y] = Xnut_pause;
5085 if (cave[x][y+1] == Xbumper)
5086 cave[x][y+1] = Ybumper;
5093 static void Lnut_pause(int x, int y)
5095 switch (cave[x][y+1])
5108 cave[x][y] = Ynut_sB;
5109 next[x][y] = Xblank;
5110 cave[x][y+1] = Ynut_s;
5111 next[x][y+1] = Xnut_fall;
5122 cave[x][y] = Ynut_sB;
5123 next[x][y] = Xblank;
5124 if (cave[x+1][y] == Xblank)
5125 cave[x+1][y] = Xsplash_e;
5126 if (cave[x-1][y] == Xblank)
5127 cave[x-1][y] = Xsplash_w;
5128 play_element_sound(x, y, SOUND_acid, Xacid_1);
5138 static void Lnut_fall(int x, int y)
5140 switch (cave[x][y+1])
5154 cave[x][y] = Ynut_sB;
5155 next[x][y] = Xblank;
5156 cave[x][y+1] = Ynut_s;
5157 next[x][y+1] = Xnut_fall;
5168 cave[x][y] = Ynut_sB;
5169 next[x][y] = Xblank;
5170 if (cave[x+1][y] == Xblank)
5171 cave[x+1][y] = Xsplash_e;
5172 if (cave[x-1][y] == Xblank)
5173 cave[x-1][y] = Xsplash_w;
5174 play_element_sound(x, y, SOUND_acid, Xacid_1);
5180 play_element_sound(x, y, SOUND_nut, Xnut);
5185 static void Lspring(int x, int y)
5187 switch (cave[x][y+1])
5202 cave[x][y] = Yspring_sB;
5203 next[x][y] = Xblank;
5204 cave[x][y+1] = Yspring_s;
5205 next[x][y+1] = Xspring_fall;
5216 cave[x][y] = Yspring_sB;
5217 next[x][y] = Xblank;
5218 if (cave[x+1][y] == Xblank)
5219 cave[x+1][y] = Xsplash_e;
5220 if (cave[x-1][y] == Xblank)
5221 cave[x-1][y] = Xsplash_w;
5222 play_element_sound(x, y, SOUND_acid, Xacid_1);
5235 case Xemerald_pause:
5237 case Xdiamond_pause:
5272 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5274 cave[x][y] = Yspring_eB;
5275 next[x][y] = Xblank;
5276 cave[x+1][y] = Yspring_e;
5278 next[x+1][y] = Xspring_e;
5280 next[x+1][y] = Xspring_pause;
5282 if (cave[x][y+1] == Xbumper)
5283 cave[x][y+1] = Ybumper;
5287 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5289 cave[x][y] = Yspring_wB;
5290 next[x][y] = Xblank;
5291 cave[x-1][y] = Yspring_w;
5293 next[x-1][y] = Xspring_w;
5295 next[x-1][y] = Xspring_pause;
5297 if (cave[x][y+1] == Xbumper)
5298 cave[x][y+1] = Ybumper;
5304 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5306 cave[x][y] = Yspring_wB;
5307 next[x][y] = Xblank;
5308 cave[x-1][y] = Yspring_w;
5310 next[x-1][y] = Xspring_w;
5312 next[x-1][y] = Xspring_pause;
5314 if (cave[x][y+1] == Xbumper)
5315 cave[x][y+1] = Ybumper;
5319 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5321 cave[x][y] = Yspring_eB;
5322 next[x][y] = Xblank;
5323 cave[x+1][y] = Yspring_e;
5325 next[x+1][y] = Xspring_e;
5327 next[x+1][y] = Xspring_pause;
5329 if (cave[x][y+1] == Xbumper)
5330 cave[x][y+1] = Ybumper;
5337 static void Lspring_pause(int x, int y)
5339 switch (cave[x][y+1])
5352 cave[x][y] = Yspring_sB;
5353 next[x][y] = Xblank;
5354 cave[x][y+1] = Yspring_s;
5355 next[x][y+1] = Xspring_fall;
5366 cave[x][y] = Yspring_sB;
5367 next[x][y] = Xblank;
5368 if (cave[x+1][y] == Xblank)
5369 cave[x+1][y] = Xsplash_e;
5370 if (cave[x-1][y] == Xblank)
5371 cave[x-1][y] = Xsplash_w;
5372 play_element_sound(x, y, SOUND_acid, Xacid_1);
5376 cave[x][y] = Xspring;
5377 next[x][y] = Xspring;
5382 static void Lspring_e(int x, int y)
5384 switch (cave[x][y+1])
5397 cave[x][y] = Yspring_sB;
5398 next[x][y] = Xblank;
5399 cave[x][y+1] = Yspring_s;
5400 next[x][y+1] = Xspring_fall;
5411 cave[x][y] = Yspring_sB;
5412 next[x][y] = Xblank;
5413 if (cave[x+1][y] == Xblank)
5414 cave[x+1][y] = Xsplash_e;
5415 if (cave[x-1][y] == Xblank)
5416 cave[x-1][y] = Xsplash_w;
5417 play_element_sound(x, y, SOUND_acid, Xacid_1);
5421 cave[x][y+1] = Ybumper;
5424 switch (cave[x+1][y])
5441 cave[x][y] = Yspring_eB;
5442 next[x][y] = Xblank;
5443 cave[x+1][y] = Yspring_e;
5444 next[x+1][y] = Xspring_e;
5455 cave[x][y] = Yspring_eB;
5456 next[x][y] = Xblank;
5457 if (cave[x+2][y-1] == Xblank)
5458 cave[x+2][y-1] = Xsplash_e;
5459 if (cave[x][y-1] == Xblank)
5460 cave[x][y-1] = Xsplash_w;
5461 play_element_sound(x, y, SOUND_acid, Xacid_1);
5470 cave[x][y] = Yspring_alien_eB;
5471 next[x][y] = Xblank;
5472 cave[x+1][y] = Yspring_alien_e;
5473 next[x+1][y] = Xspring_e;
5474 play_element_sound(x, y, SOUND_slurp, Xalien);
5475 score += lev.slurp_score;
5480 cave[x+1][y] = Ybumper;
5481 next[x][y] = Xspring_w;
5482 play_element_sound(x, y, SOUND_spring, Xspring);
5486 cave[x][y] = Xspring;
5487 next[x][y] = Xspring;
5488 play_element_sound(x, y, SOUND_spring, Xspring);
5493 static void Lspring_w(int x, int y)
5495 switch (cave[x][y+1])
5508 cave[x][y] = Yspring_sB;
5509 next[x][y] = Xblank;
5510 cave[x][y+1] = Yspring_s;
5511 next[x][y+1] = Xspring_fall;
5522 cave[x][y] = Yspring_sB;
5523 next[x][y] = Xblank;
5524 if (cave[x+1][y] == Xblank)
5525 cave[x+1][y] = Xsplash_e;
5526 if (cave[x-1][y] == Xblank)
5527 cave[x-1][y] = Xsplash_w;
5528 play_element_sound(x, y, SOUND_acid, Xacid_1);
5532 cave[x][y+1] = Ybumper;
5535 switch (cave[x-1][y])
5552 cave[x][y] = Yspring_wB;
5553 next[x][y] = Xblank;
5554 cave[x-1][y] = Yspring_w;
5555 next[x-1][y] = Xspring_w;
5566 cave[x][y] = Yspring_wB;
5567 next[x][y] = Xblank;
5568 if (cave[x][y-1] == Xblank)
5569 cave[x][y-1] = Xsplash_e;
5570 if (cave[x-2][y-1] == Xblank)
5571 cave[x-2][y-1] = Xsplash_w;
5572 play_element_sound(x, y, SOUND_acid, Xacid_1);
5581 cave[x][y] = Yspring_alien_wB;
5582 next[x][y] = Xblank;
5583 cave[x-1][y] = Yspring_alien_w;
5584 next[x-1][y] = Xspring_w;
5585 play_element_sound(x, y, SOUND_slurp, Xalien);
5586 score += lev.slurp_score;
5591 cave[x-1][y] = Ybumper;
5592 next[x][y] = Xspring_e;
5593 play_element_sound(x, y, SOUND_spring, Xspring);
5597 cave[x][y] = Xspring;
5598 next[x][y] = Xspring;
5599 play_element_sound(x, y, SOUND_spring, Xspring);
5604 static void Lspring_fall(int x, int y)
5606 switch (cave[x][y+1])
5620 cave[x][y] = Yspring_sB;
5621 next[x][y] = Xblank;
5622 cave[x][y+1] = Yspring_s;
5623 next[x][y+1] = Xspring_fall;
5634 cave[x][y] = Yspring_sB;
5635 next[x][y] = Xblank;
5636 if (cave[x+1][y] == Xblank)
5637 cave[x+1][y] = Xsplash_e;
5638 if (cave[x-1][y] == Xblank)
5639 cave[x-1][y] = Xsplash_w;
5640 play_element_sound(x, y, SOUND_acid, Xacid_1);
5647 cave[x][y] = Yspring_sB;
5648 next[x][y] = Xblank;
5649 cave[x][y+1] = Yeater_spring;
5650 next[x][y+1] = Zeater;
5651 Lboom_eater_old(x, y+1);
5652 score += lev.eater_score;
5657 cave[x][y] = Yspring_sB;
5658 next[x][y] = Xblank;
5659 cave[x][y+1] = Yalien_spring;
5660 next[x][y+1] = Ztank;
5661 Lboom_tank_old(x, y+1);
5662 score += lev.alien_score;
5673 cave[x][y] = Yspring_sB;
5674 next[x][y] = Xblank;
5675 cave[x][y+1] = Ybug_spring;
5676 next[x][y+1] = Zbug;
5677 Lboom_bug_old(x, y+1);
5678 score += lev.bug_score;
5689 cave[x][y] = Yspring_sB;
5690 next[x][y] = Xblank;
5691 cave[x][y+1] = Ytank_spring;
5692 next[x][y+1] = Ztank;
5693 Lboom_tank_old(x, y+1);
5694 score += lev.tank_score;
5699 cave[x][y] = Xspring;
5700 next[x][y] = Xspring;
5701 cave[x][y+1] = Ybomb_blank;
5702 next[x][y+1] = Ztank;
5703 Lboom_tank_old(x, y+1);
5707 cave[x][y] = Xspring;
5708 next[x][y] = Xspring;
5709 play_element_sound(x, y, SOUND_spring, Xspring);
5714 static void Lpush_emerald_e(int x, int y)
5716 cave[x][y] = Yemerald_eB;
5717 next[x][y] = Xblank;
5719 switch (cave[x+1][y])
5722 if (!game_em.use_old_push_elements)
5735 Lpush_element_old(x, y, Xemerald);
5747 if (game_em.use_old_push_into_acid)
5749 if (cave[x+2][y-1] == Xblank)
5750 cave[x+2][y-1] = Xsplash_e;
5751 if (cave[x][y-1] == Xblank)
5752 cave[x][y-1] = Xsplash_w;
5753 play_element_sound(x, y, SOUND_acid, Xacid_1);
5758 cave[x+1][y] = Yemerald_e;
5759 next[x+1][y] = Xemerald_pause;
5762 static void Lpush_emerald_w(int x, int y)
5764 cave[x][y] = Yemerald_wB;
5765 next[x][y] = Xblank;
5767 switch (cave[x-1][y])
5770 if (!game_em.use_old_push_elements)
5783 Lpush_element_old(x, y, Xemerald);
5795 if (game_em.use_old_push_into_acid)
5797 if (cave[x][y-1] == Xblank)
5798 cave[x][y-1] = Xsplash_e;
5799 if (cave[x-2][y-1] == Xblank)
5800 cave[x-2][y-1] = Xsplash_w;
5801 play_element_sound(x, y, SOUND_acid, Xacid_1);
5806 cave[x-1][y] = Yemerald_w;
5807 next[x-1][y] = Xemerald_pause;
5810 static void Lpush_diamond_e(int x, int y)
5812 cave[x][y] = Ydiamond_eB;
5813 next[x][y] = Xblank;
5815 switch (cave[x+1][y])
5818 if (!game_em.use_old_push_elements)
5831 Lpush_element_old(x, y, Xdiamond);
5843 if (game_em.use_old_push_into_acid)
5845 if (cave[x+2][y-1] == Xblank)
5846 cave[x+2][y-1] = Xsplash_e;
5847 if (cave[x][y-1] == Xblank)
5848 cave[x][y-1] = Xsplash_w;
5849 play_element_sound(x, y, SOUND_acid, Xacid_1);
5854 cave[x+1][y] = Ydiamond_e;
5855 next[x+1][y] = Xdiamond_pause;
5858 static void Lpush_diamond_w(int x, int y)
5860 cave[x][y] = Ydiamond_wB;
5861 next[x][y] = Xblank;
5863 switch (cave[x-1][y])
5866 if (!game_em.use_old_push_elements)
5879 Lpush_element_old(x, y, Xdiamond);
5891 if (game_em.use_old_push_into_acid)
5893 if (cave[x][y-1] == Xblank)
5894 cave[x][y-1] = Xsplash_e;
5895 if (cave[x-2][y-1] == Xblank)
5896 cave[x-2][y-1] = Xsplash_w;
5897 play_element_sound(x, y, SOUND_acid, Xacid_1);
5902 cave[x-1][y] = Ydiamond_w;
5903 next[x-1][y] = Xdiamond_pause;
5906 static void Lpush_stone_e(int x, int y)
5908 cave[x][y] = Ystone_eB;
5909 next[x][y] = Xblank;
5911 switch (cave[x+1][y])
5914 if (!game_em.use_old_push_elements)
5927 Lpush_element_old(x, y, Xstone);
5939 if (game_em.use_old_push_into_acid)
5941 if (cave[x+2][y-1] == Xblank)
5942 cave[x+2][y-1] = Xsplash_e;
5943 if (cave[x][y-1] == Xblank)
5944 cave[x][y-1] = Xsplash_w;
5945 play_element_sound(x, y, SOUND_acid, Xacid_1);
5950 cave[x+1][y] = Ystone_e;
5951 next[x+1][y] = Xstone_pause;
5954 static void Lpush_stone_w(int x, int y)
5956 cave[x][y] = Ystone_wB;
5957 next[x][y] = Xblank;
5959 switch (cave[x-1][y])
5962 if (!game_em.use_old_push_elements)
5975 Lpush_element_old(x, y, Xstone);
5987 if (game_em.use_old_push_into_acid)
5989 if (cave[x][y-1] == Xblank)
5990 cave[x][y-1] = Xsplash_e;
5991 if (cave[x-2][y-1] == Xblank)
5992 cave[x-2][y-1] = Xsplash_w;
5993 play_element_sound(x, y, SOUND_acid, Xacid_1);
5998 cave[x-1][y] = Ystone_w;
5999 next[x-1][y] = Xstone_pause;
6002 static void Lpush_bomb_e(int x, int y)
6004 cave[x][y] = Ybomb_eB;
6005 next[x][y] = Xblank;
6007 switch (cave[x+1][y])
6010 if (!game_em.use_old_push_elements)
6023 Lpush_element_old(x, y, Xbomb);
6035 if (game_em.use_old_push_into_acid)
6037 if (cave[x+2][y-1] == Xblank)
6038 cave[x+2][y-1] = Xsplash_e;
6039 if (cave[x][y-1] == Xblank)
6040 cave[x][y-1] = Xsplash_w;
6041 play_element_sound(x, y, SOUND_acid, Xacid_1);
6046 cave[x+1][y] = Ybomb_e;
6047 next[x+1][y] = Xbomb_pause;
6050 static void Lpush_bomb_w(int x, int y)
6052 cave[x][y] = Ybomb_wB;
6053 next[x][y] = Xblank;
6055 switch (cave[x-1][y])
6058 if (!game_em.use_old_push_elements)
6071 Lpush_element_old(x, y, Xbomb);
6083 if (game_em.use_old_push_into_acid)
6085 if (cave[x][y-1] == Xblank)
6086 cave[x][y-1] = Xsplash_e;
6087 if (cave[x-2][y-1] == Xblank)
6088 cave[x-2][y-1] = Xsplash_w;
6089 play_element_sound(x, y, SOUND_acid, Xacid_1);
6094 cave[x-1][y] = Ybomb_w;
6095 next[x-1][y] = Xbomb_pause;
6098 static void Lpush_nut_e(int x, int y)
6100 cave[x][y] = Ynut_eB;
6101 next[x][y] = Xblank;
6103 switch (cave[x+1][y])
6106 if (!game_em.use_old_push_elements)
6119 Lpush_element_old(x, y, Xnut);
6131 if (game_em.use_old_push_into_acid)
6133 if (cave[x+2][y-1] == Xblank)
6134 cave[x+2][y-1] = Xsplash_e;
6135 if (cave[x][y-1] == Xblank)
6136 cave[x][y-1] = Xsplash_w;
6137 play_element_sound(x, y, SOUND_acid, Xacid_1);
6142 cave[x+1][y] = Ynut_e;
6143 next[x+1][y] = Xnut_pause;
6146 static void Lpush_nut_w(int x, int y)
6148 cave[x][y] = Ynut_wB;
6149 next[x][y] = Xblank;
6151 switch (cave[x-1][y])
6154 if (!game_em.use_old_push_elements)
6167 Lpush_element_old(x, y, Xnut);
6179 if (game_em.use_old_push_into_acid)
6181 if (cave[x][y-1] == Xblank)
6182 cave[x][y-1] = Xsplash_e;
6183 if (cave[x-2][y-1] == Xblank)
6184 cave[x-2][y-1] = Xsplash_w;
6185 play_element_sound(x, y, SOUND_acid, Xacid_1);
6190 cave[x-1][y] = Ynut_w;
6191 next[x-1][y] = Xnut_pause;
6194 static void Lpush_spring_e(int x, int y)
6196 cave[x][y] = Yspring_eB;
6197 next[x][y] = Xblank;
6199 switch (cave[x+1][y])
6202 if (!game_em.use_old_push_elements)
6215 Lpush_element_old(x, y, Xspring);
6227 if (game_em.use_old_push_into_acid)
6229 if (cave[x+2][y-1] == Xblank)
6230 cave[x+2][y-1] = Xsplash_e;
6231 if (cave[x][y-1] == Xblank)
6232 cave[x][y-1] = Xsplash_w;
6233 play_element_sound(x, y, SOUND_acid, Xacid_1);
6238 cave[x+1][y] = Yspring_e;
6239 next[x+1][y] = Xspring_e;
6242 static void Lpush_spring_w(int x, int y)
6244 cave[x][y] = Yspring_wB;
6245 next[x][y] = Xblank;
6247 switch (cave[x-1][y])
6250 if (!game_em.use_old_push_elements)
6263 Lpush_element_old(x, y, Xspring);
6275 if (game_em.use_old_push_into_acid)
6277 if (cave[x][y-1] == Xblank)
6278 cave[x][y-1] = Xsplash_e;
6279 if (cave[x-2][y-1] == Xblank)
6280 cave[x-2][y-1] = Xsplash_w;
6281 play_element_sound(x, y, SOUND_acid, Xacid_1);
6286 cave[x-1][y] = Yspring_w;
6287 next[x-1][y] = Xspring_w;
6290 static void Ldynamite_1(int x, int y)
6292 play_element_sound(x, y, SOUND_tick, Xdynamite_1);
6293 next[x][y] = Xdynamite_2;
6296 static void Ldynamite_2(int x, int y)
6298 play_element_sound(x, y, SOUND_tick, Xdynamite_2);
6299 next[x][y] = Xdynamite_3;
6302 static void Ldynamite_3(int x, int y)
6304 play_element_sound(x, y, SOUND_tick, Xdynamite_3);
6305 next[x][y] = Xdynamite_4;
6308 static void Ldynamite_4(int x, int y)
6310 play_element_sound(x, y, SOUND_tick, Xdynamite_4);
6311 next[x][y] = Zdynamite;
6313 Lboom_generic(x, y, Xblank, Xblank);
6316 static void Lfake_door_1(int x, int y)
6318 if (lev.magnify_cnt)
6319 cave[x][y] = Xdoor_1;
6322 static void Lfake_door_2(int x, int y)
6324 if (lev.magnify_cnt)
6325 cave[x][y] = Xdoor_2;
6328 static void Lfake_door_3(int x, int y)
6330 if (lev.magnify_cnt)
6331 cave[x][y] = Xdoor_3;
6334 static void Lfake_door_4(int x, int y)
6336 if (lev.magnify_cnt)
6337 cave[x][y] = Xdoor_4;
6340 static void Lfake_door_5(int x, int y)
6342 if (lev.magnify_cnt)
6343 cave[x][y] = Xdoor_5;
6346 static void Lfake_door_6(int x, int y)
6348 if (lev.magnify_cnt)
6349 cave[x][y] = Xdoor_6;
6352 static void Lfake_door_7(int x, int y)
6354 if (lev.magnify_cnt)
6355 cave[x][y] = Xdoor_7;
6358 static void Lfake_door_8(int x, int y)
6360 if (lev.magnify_cnt)
6361 cave[x][y] = Xdoor_8;
6364 static void Lballoon(int x, int y)
6366 if (lev.wind_cnt == 0)
6369 switch (lev.wind_direction)
6372 switch (cave[x][y-1])
6385 cave[x][y] = Yballoon_nB;
6386 next[x][y] = Xblank;
6387 cave[x][y-1] = Yballoon_n;
6388 next[x][y-1] = Xballoon;
6399 cave[x][y] = Yballoon_nB;
6400 next[x][y] = Xblank;
6401 if (cave[x+1][y-2] == Xblank)
6402 cave[x+1][y-2] = Xsplash_e;
6403 if (cave[x-1][y-2] == Xblank)
6404 cave[x-1][y-2] = Xsplash_w;
6405 play_element_sound(x, y, SOUND_acid, Xacid_1);
6411 switch (cave[x+1][y])
6424 cave[x][y] = Yballoon_eB;
6425 next[x][y] = Xblank;
6426 cave[x+1][y] = Yballoon_e;
6427 next[x+1][y] = Xballoon;
6438 cave[x][y] = Yballoon_eB;
6439 next[x][y] = Xblank;
6440 if (cave[x+2][y-1] == Xblank)
6441 cave[x+2][y-1] = Xsplash_e;
6442 if (cave[x][y-1] == Xblank)
6443 cave[x][y-1] = Xsplash_w;
6444 play_element_sound(x, y, SOUND_acid, Xacid_1);
6450 switch (cave[x][y+1])
6463 cave[x][y] = Yballoon_sB;
6464 next[x][y] = Xblank;
6465 cave[x][y+1] = Yballoon_s;
6466 next[x][y+1] = Xballoon;
6477 cave[x][y] = Yballoon_sB;
6478 next[x][y] = Xblank;
6479 if (cave[x+1][y] == Xblank)
6480 cave[x+1][y] = Xsplash_e;
6481 if (cave[x-1][y] == Xblank)
6482 cave[x-1][y] = Xsplash_w;
6483 play_element_sound(x, y, SOUND_acid, Xacid_1);
6489 switch (cave[x-1][y])
6502 cave[x][y] = Yballoon_wB;
6503 next[x][y] = Xblank;
6504 cave[x-1][y] = Yballoon_w;
6505 next[x-1][y] = Xballoon;
6516 cave[x][y] = Yballoon_wB;
6517 next[x][y] = Xblank;
6518 if (cave[x][y-1] == Xblank)
6519 cave[x][y-1] = Xsplash_e;
6520 if (cave[x-2][y-1] == Xblank)
6521 cave[x-2][y-1] = Xsplash_w;
6522 play_element_sound(x, y, SOUND_acid, Xacid_1);
6529 static void Lball_common(int x, int y)
6531 play_element_sound(x, y, SOUND_ball, Xball_1);
6533 if (lev.ball_random)
6538 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6539 is_blank[cave[x-1][y-1]])
6541 cave[x-1][y-1] = Yball_blank;
6542 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6547 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6548 is_blank[cave[x][y-1]])
6550 cave[x][y-1] = Yball_blank;
6551 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6556 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6557 is_blank[cave[x+1][y-1]])
6559 cave[x+1][y-1] = Yball_blank;
6560 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6565 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6566 is_blank[cave[x-1][y]])
6568 cave[x-1][y] = Yball_blank;
6569 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6574 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6575 is_blank[cave[x+1][y]])
6577 cave[x+1][y] = Yball_blank;
6578 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6583 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6584 is_blank[cave[x-1][y+1]])
6586 cave[x-1][y+1] = Yball_blank;
6587 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6592 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6593 is_blank[cave[x][y+1]])
6595 cave[x][y+1] = Yball_blank;
6596 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6601 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6602 is_blank[cave[x+1][y+1]])
6604 cave[x+1][y+1] = Yball_blank;
6605 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6612 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6613 is_blank[cave[x-1][y-1]])
6615 cave[x-1][y-1] = Yball_blank;
6616 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6619 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6620 is_blank[cave[x][y-1]])
6622 cave[x][y-1] = Yball_blank;
6623 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6626 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6627 is_blank[cave[x+1][y-1]])
6629 cave[x+1][y-1] = Yball_blank;
6630 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6633 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6634 is_blank[cave[x-1][y]])
6636 cave[x-1][y] = Yball_blank;
6637 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6640 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6641 is_blank[cave[x+1][y]])
6643 cave[x+1][y] = Yball_blank;
6644 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6647 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6648 is_blank[cave[x-1][y+1]])
6650 cave[x-1][y+1] = Yball_blank;
6651 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6654 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6655 is_blank[cave[x][y+1]])
6657 cave[x][y+1] = Yball_blank;
6658 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6661 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6662 is_blank[cave[x+1][y+1]])
6664 cave[x+1][y+1] = Yball_blank;
6665 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6669 lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
6672 static void Lball_1(int x, int y)
6674 if (!lev.ball_active)
6677 cave[x][y] = Yball_1;
6678 next[x][y] = Xball_2;
6685 static void Lball_2(int x, int y)
6687 if (!lev.ball_active)
6690 cave[x][y] = Yball_2;
6691 next[x][y] = Xball_1;
6698 static void Ldrip(int x, int y)
6700 next[x][y] = Xdrip_fall;
6703 static void Ldrip_fall(int x, int y)
6707 switch (cave[x][y+1])
6723 cave[x][y] = Ydrip_1_sB;
6724 next[x][y] = Xdrip_stretchB;
6725 cave[x][y+1] = Ydrip_1_s;
6726 next[x][y+1] = Xdrip_stretch;
6737 cave[x][y] = Ydrip_1_sB;
6738 next[x][y] = Xdrip_stretchB;
6739 if (cave[x+1][y] == Xblank)
6740 cave[x+1][y] = Xsplash_e;
6741 if (cave[x-1][y] == Xblank)
6742 cave[x-1][y] = Xsplash_w;
6743 play_element_sound(x, y, SOUND_acid, Xacid_1);
6749 case 0: temp = Xamoeba_1; break;
6750 case 1: temp = Xamoeba_2; break;
6751 case 2: temp = Xamoeba_3; break;
6752 case 3: temp = Xamoeba_4; break;
6753 case 4: temp = Xamoeba_5; break;
6754 case 5: temp = Xamoeba_6; break;
6755 case 6: temp = Xamoeba_7; break;
6756 case 7: temp = Xamoeba_8; break;
6761 play_element_sound(x, y, SOUND_drip, Xdrip_fall);
6766 static void Ldrip_stretch(int x, int y)
6768 cave[x][y] = Ydrip_2_s;
6769 next[x][y] = Xdrip_fall;
6772 static void Ldrip_stretchB(int x, int y)
6774 cave[x][y] = Ydrip_2_sB;
6775 next[x][y] = Xblank;
6778 static void Lwonderwall(int x, int y)
6780 if (lev.wonderwall_time > 0 && lev.wonderwall_active)
6782 cave[x][y] = Ywonderwall;
6783 play_element_sound(x, y, SOUND_wonder, Xwonderwall);
6787 static void Lwheel(int x, int y)
6789 if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
6790 cave[x][y] = Ywheel;
6793 static void Lswitch(int x, int y)
6795 if (lev.ball_active)
6796 cave[x][y] = Yswitch;
6799 static void Lfake_blank(int x, int y)
6802 cave[x][y] = Yfake_blank;
6805 static void Lfake_grass(int x, int y)
6807 if (lev.magnify_cnt)
6808 cave[x][y] = Yfake_grass;
6811 static void Lfake_amoeba(int x, int y)
6814 cave[x][y] = Yfake_amoeba;
6817 static void Lsand_stone(int x, int y)
6819 switch (cave[x][y+1])
6832 cave[x][y] = Xsand_stonesand_quickout_1;
6833 next[x][y] = Xsand_stonesand_quickout_2;
6834 cave[x][y+1] = Xsand_stoneout_1;
6835 next[x][y+1] = Xsand_stoneout_2;
6846 cave[x][y] = Xsand_stonesand_quickout_1;
6847 next[x][y] = Xsand_stonesand_quickout_2;
6848 if (cave[x+1][y] == Xblank)
6849 cave[x+1][y] = Xsplash_e;
6850 if (cave[x-1][y] == Xblank)
6851 cave[x-1][y] = Xsplash_w;
6852 play_element_sound(x, y, SOUND_acid, Xacid_1);
6856 cave[x][y] = Xsand_stonesand_1;
6857 next[x][y] = Xsand_stonesand_2;
6858 cave[x][y+1] = Xsand_sandstone_1;
6859 next[x][y+1] = Xsand_sandstone_2;
6864 static void Lsand_stonein_1(int x, int y)
6866 next[x][y] = Xsand_stonein_2;
6869 static void Lsand_stonein_2(int x, int y)
6871 next[x][y] = Xsand_stonein_3;
6874 static void Lsand_stonein_3(int x, int y)
6876 next[x][y] = Xsand_stonein_4;
6879 static void Lsand_stonein_4(int x, int y)
6881 next[x][y] = Xblank;
6884 static void Lsand_sandstone_1(int x, int y)
6886 next[x][y] = Xsand_sandstone_2;
6889 static void Lsand_sandstone_2(int x, int y)
6891 next[x][y] = Xsand_sandstone_3;
6894 static void Lsand_sandstone_3(int x, int y)
6896 next[x][y] = Xsand_sandstone_4;
6899 static void Lsand_sandstone_4(int x, int y)
6901 next[x][y] = Xsand_stone;
6904 static void Lsand_stonesand_1(int x, int y)
6906 next[x][y] = Xsand_stonesand_2;
6909 static void Lsand_stonesand_2(int x, int y)
6911 next[x][y] = Xsand_stonesand_3;
6914 static void Lsand_stonesand_3(int x, int y)
6916 next[x][y] = Xsand_stonesand_4;
6919 static void Lsand_stonesand_4(int x, int y)
6924 static void Lsand_stoneout_1(int x, int y)
6926 next[x][y] = Xsand_stoneout_2;
6929 static void Lsand_stoneout_2(int x, int y)
6931 next[x][y] = Xstone_fall;
6934 static void Lsand_stonesand_quickout_1(int x, int y)
6936 next[x][y] = Xsand_stonesand_quickout_2;
6939 static void Lsand_stonesand_quickout_2(int x, int y)
6944 static void Lslide_ns(int x, int y)
6946 if (is_blank[cave[x][y-1]])
6948 cave[x][y-1] = Yslide_ns_blank;
6949 next[x][y-1] = Xslide_ns;
6950 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6953 if (is_blank[cave[x][y+1]])
6955 cave[x][y+1] = Yslide_ns_blank;
6956 next[x][y+1] = Xslide_ns;
6957 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6961 static void Lslide_ew(int x, int y)
6963 if (is_blank[cave[x+1][y]])
6965 cave[x+1][y] = Yslide_ew_blank;
6966 next[x+1][y] = Xslide_ew;
6967 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6970 if (is_blank[cave[x-1][y]])
6972 cave[x-1][y] = Yslide_ew_blank;
6973 next[x-1][y] = Xslide_ew;
6974 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6978 static void Lexit(int x, int y)
6980 if (lev.gems_needed > 0)
6983 switch (RANDOM(64) / 21)
6986 cave[x][y] = Xexit_1;
6987 next[x][y] = Xexit_2;
6991 cave[x][y] = Xexit_2;
6992 next[x][y] = Xexit_3;
6996 cave[x][y] = Xexit_3;
6997 next[x][y] = Xexit_1;
7001 play_element_sound(x, y, SOUND_exit_open, Xexit);
7004 static void Lexit_1(int x, int y)
7006 next[x][y] = Xexit_2;
7009 static void Lexit_2(int x, int y)
7011 next[x][y] = Xexit_3;
7014 static void Lexit_3(int x, int y)
7016 next[x][y] = Xexit_1;
7019 static void Lpause(int x, int y)
7021 next[x][y] = Xblank;
7024 static void Lamoeba(int x, int y)
7044 if (is_amoeba[cave[x][y-1]] ||
7045 is_amoeba[cave[x+1][y]] ||
7046 is_amoeba[cave[x][y+1]] ||
7047 is_amoeba[cave[x-1][y]])
7052 static void Lboom_one(int x, int y, boolean by_dynamite)
7113 cave[x][y] = Xboom_android;
7124 cave[x][y] = Xboom_bug;
7125 Lboom_bug_new(x, y, TRUE);
7131 cave[x][y] = Xboom_tank;
7132 Lboom_tank_new(x, y, TRUE);
7136 cave[x][y] = Xboom_1;
7141 static void Lboom_nine(int x, int y, boolean by_dynamite)
7143 Lboom_one(x, y-1, by_dynamite);
7144 Lboom_one(x-1, y, by_dynamite);
7145 Lboom_one(x+1, y, by_dynamite);
7146 Lboom_one(x, y+1, by_dynamite);
7147 Lboom_one(x-1, y-1, by_dynamite);
7148 Lboom_one(x+1, y-1, by_dynamite);
7149 Lboom_one(x-1, y+1, by_dynamite);
7150 Lboom_one(x+1, y+1, by_dynamite);
7152 cave[x][y] = Xboom_1;
7155 static void Lexplode(int x, int y)
7160 Lboom_bug_new(x, y, FALSE);
7161 Lboom_nine(x, y, FALSE);
7165 Lboom_tank_new(x, y, FALSE);
7166 Lboom_nine(x, y, FALSE);
7170 Lboom_eater_new(x, y, FALSE);
7171 Lboom_nine(x, y, FALSE);
7175 Lboom_nine(x, y, TRUE);
7179 Lboom_nine(x, y, FALSE);
7184 static void Lboom_1(int x, int y)
7186 next[x][y] = Xboom_2;
7187 #if !PLAY_ELEMENT_SOUND
7188 if (x != lev.exit_x && y != lev.exit_y)
7189 play_sound(x, y, SOUND_boom);
7191 lev.exit_x = lev.exit_y = -1;
7195 static void Lboom_2(int x, int y)
7197 next[x][y] = boom[x][y];
7200 static void Lboom_android(int x, int y)
7202 #if PLAY_ELEMENT_SOUND
7203 play_element_sound(x, y, SOUND_boom, Xandroid);
7209 static void Lchain(int x, int y)
7214 static void handle_tile(int x, int y)
7218 case Xacid_1: Lacid_1(x, y); break;
7219 case Xacid_2: Lacid_2(x, y); break;
7220 case Xacid_3: Lacid_3(x, y); break;
7221 case Xacid_4: Lacid_4(x, y); break;
7222 case Xacid_5: Lacid_5(x, y); break;
7223 case Xacid_6: Lacid_6(x, y); break;
7224 case Xacid_7: Lacid_7(x, y); break;
7225 case Xacid_8: Lacid_8(x, y); break;
7227 case Xfake_acid_1: Lfake_acid_1(x, y); break;
7228 case Xfake_acid_2: Lfake_acid_2(x, y); break;
7229 case Xfake_acid_3: Lfake_acid_3(x, y); break;
7230 case Xfake_acid_4: Lfake_acid_4(x, y); break;
7231 case Xfake_acid_5: Lfake_acid_5(x, y); break;
7232 case Xfake_acid_6: Lfake_acid_6(x, y); break;
7233 case Xfake_acid_7: Lfake_acid_7(x, y); break;
7234 case Xfake_acid_8: Lfake_acid_8(x, y); break;
7236 case Xandroid: Landroid(x, y); break;
7237 case Xandroid_1_n: Landroid_1_n(x, y); break;
7238 case Xandroid_2_n: Landroid_2_n(x, y); break;
7239 case Xandroid_1_e: Landroid_1_e(x, y); break;
7240 case Xandroid_2_e: Landroid_2_e(x, y); break;
7241 case Xandroid_1_s: Landroid_1_s(x, y); break;
7242 case Xandroid_2_s: Landroid_2_s(x, y); break;
7243 case Xandroid_1_w: Landroid_1_w(x, y); break;
7244 case Xandroid_2_w: Landroid_2_w(x, y); break;
7246 case Xeater_n: Leater_n(x, y); break;
7247 case Xeater_e: Leater_e(x, y); break;
7248 case Xeater_s: Leater_s(x, y); break;
7249 case Xeater_w: Leater_w(x, y); break;
7251 case Xalien: Lalien(x, y); break;
7252 case Xalien_pause: Lalien_pause(x, y); break;
7254 case Xbug_1_n: Lbug_1_n(x, y); break;
7255 case Xbug_2_n: Lbug_2_n(x, y); break;
7256 case Xbug_1_e: Lbug_1_e(x, y); break;
7257 case Xbug_2_e: Lbug_2_e(x, y); break;
7258 case Xbug_1_s: Lbug_1_s(x, y); break;
7259 case Xbug_2_s: Lbug_2_s(x, y); break;
7260 case Xbug_1_w: Lbug_1_w(x, y); break;
7261 case Xbug_2_w: Lbug_2_w(x, y); break;
7263 case Xtank_1_n: Ltank_1_n(x, y); break;
7264 case Xtank_2_n: Ltank_2_n(x, y); break;
7265 case Xtank_1_e: Ltank_1_e(x, y); break;
7266 case Xtank_2_e: Ltank_2_e(x, y); break;
7267 case Xtank_1_s: Ltank_1_s(x, y); break;
7268 case Xtank_2_s: Ltank_2_s(x, y); break;
7269 case Xtank_1_w: Ltank_1_w(x, y); break;
7270 case Xtank_2_w: Ltank_2_w(x, y); break;
7272 case Xemerald: Lemerald(x, y); break;
7273 case Xemerald_pause: Lemerald_pause(x, y); break;
7274 case Xemerald_fall: Lemerald_fall(x, y); break;
7276 case Xdiamond: Ldiamond(x, y); break;
7277 case Xdiamond_pause: Ldiamond_pause(x, y); break;
7278 case Xdiamond_fall: Ldiamond_fall(x, y); break;
7280 case Xstone: Lstone(x, y); break;
7281 case Xstone_pause: Lstone_pause(x, y); break;
7282 case Xstone_fall: Lstone_fall(x, y); break;
7284 case Xbomb: Lbomb(x, y); break;
7285 case Xbomb_pause: Lbomb_pause(x, y); break;
7286 case Xbomb_fall: Lbomb_fall(x, y); break;
7288 case Xnut: Lnut(x, y); break;
7289 case Xnut_pause: Lnut_pause(x, y); break;
7290 case Xnut_fall: Lnut_fall(x, y); break;
7292 case Xspring: Lspring(x, y); break;
7293 case Xspring_pause: Lspring_pause(x, y); break;
7294 case Xspring_e: Lspring_e(x, y); break;
7295 case Xspring_w: Lspring_w(x, y); break;
7296 case Xspring_fall: Lspring_fall(x, y); break;
7298 case Xpush_emerald_e: Lpush_emerald_e(x, y); break;
7299 case Xpush_emerald_w: Lpush_emerald_w(x, y); break;
7300 case Xpush_diamond_e: Lpush_diamond_e(x, y); break;
7301 case Xpush_diamond_w: Lpush_diamond_w(x, y); break;
7302 case Xpush_stone_e: Lpush_stone_e(x, y); break;
7303 case Xpush_stone_w: Lpush_stone_w(x, y); break;
7304 case Xpush_bomb_e: Lpush_bomb_e(x, y); break;
7305 case Xpush_bomb_w: Lpush_bomb_w(x, y); break;
7306 case Xpush_nut_e: Lpush_nut_e(x, y); break;
7307 case Xpush_nut_w: Lpush_nut_w(x, y); break;
7308 case Xpush_spring_e: Lpush_spring_e(x, y); break;
7309 case Xpush_spring_w: Lpush_spring_w(x, y); break;
7311 case Xdynamite_1: Ldynamite_1(x, y); break;
7312 case Xdynamite_2: Ldynamite_2(x, y); break;
7313 case Xdynamite_3: Ldynamite_3(x, y); break;
7314 case Xdynamite_4: Ldynamite_4(x, y); break;
7316 case Xfake_door_1: Lfake_door_1(x, y); break;
7317 case Xfake_door_2: Lfake_door_2(x, y); break;
7318 case Xfake_door_3: Lfake_door_3(x, y); break;
7319 case Xfake_door_4: Lfake_door_4(x, y); break;
7320 case Xfake_door_5: Lfake_door_5(x, y); break;
7321 case Xfake_door_6: Lfake_door_6(x, y); break;
7322 case Xfake_door_7: Lfake_door_7(x, y); break;
7323 case Xfake_door_8: Lfake_door_8(x, y); break;
7325 case Xballoon: Lballoon(x, y); break;
7327 case Xball_1: Lball_1(x, y); break;
7328 case Xball_2: Lball_2(x, y); break;
7330 case Xdrip: Ldrip(x, y); break;
7331 case Xdrip_fall: Ldrip_fall(x, y); break;
7332 case Xdrip_stretch: Ldrip_stretch(x, y); break;
7333 case Xdrip_stretchB: Ldrip_stretchB(x, y); break;
7335 case Xwonderwall: Lwonderwall(x, y); break;
7337 case Xwheel: Lwheel(x, y); break;
7339 case Xswitch: Lswitch(x, y); break;
7341 case Xfake_blank: Lfake_blank(x, y); break;
7342 case Xfake_grass: Lfake_grass(x, y); break;
7343 case Xfake_amoeba: Lfake_amoeba(x, y); break;
7345 case Xsand_stone: Lsand_stone(x, y); break;
7346 case Xsand_stonein_1: Lsand_stonein_1(x, y); break;
7347 case Xsand_stonein_2: Lsand_stonein_2(x, y); break;
7348 case Xsand_stonein_3: Lsand_stonein_3(x, y); break;
7349 case Xsand_stonein_4: Lsand_stonein_4(x, y); break;
7350 case Xsand_sandstone_1: Lsand_sandstone_1(x, y); break;
7351 case Xsand_sandstone_2: Lsand_sandstone_2(x, y); break;
7352 case Xsand_sandstone_3: Lsand_sandstone_3(x, y); break;
7353 case Xsand_sandstone_4: Lsand_sandstone_4(x, y); break;
7354 case Xsand_stonesand_1: Lsand_stonesand_1(x, y); break;
7355 case Xsand_stonesand_2: Lsand_stonesand_2(x, y); break;
7356 case Xsand_stonesand_3: Lsand_stonesand_3(x, y); break;
7357 case Xsand_stonesand_4: Lsand_stonesand_4(x, y); break;
7358 case Xsand_stoneout_1: Lsand_stoneout_1(x, y); break;
7359 case Xsand_stoneout_2: Lsand_stoneout_2(x, y); break;
7360 case Xsand_stonesand_quickout_1: Lsand_stonesand_quickout_1(x, y); break;
7361 case Xsand_stonesand_quickout_2: Lsand_stonesand_quickout_2(x, y); break;
7363 case Xslide_ns: Lslide_ns(x, y); break;
7364 case Xslide_ew: Lslide_ew(x, y); break;
7366 case Xexit: Lexit(x, y); break;
7367 case Xexit_1: Lexit_1(x, y); break;
7368 case Xexit_2: Lexit_2(x, y); break;
7369 case Xexit_3: Lexit_3(x, y); break;
7371 case Xpause: Lpause(x, y); break;
7373 case Xchain: Lchain(x, y); break;
7374 case Xboom_bug: Lboom_bug(x, y); break;
7375 case Xboom_tank: Lboom_tank(x, y); break;
7376 case Xboom_android: Lboom_android(x, y); break;
7377 case Xboom_1: Lboom_1(x, y); break;
7378 case Xboom_2: Lboom_2(x, y); break;
7382 static void logic_players(void)
7391 game_em.any_player_moving = FALSE;
7392 game_em.any_player_snapping = FALSE;
7394 /* must test for death and actually kill separately */
7395 for (i = 0; i < MAX_PLAYERS; i++)
7397 boolean ply_kill = player_killed(&ply[i]);
7399 if (ply[i].alive && ply_kill)
7400 kill_player(&ply[i]);
7403 for (i = 0; i < MAX_PLAYERS; i++)
7408 /* check for wrap-around movement */
7409 if (ply[i].x < lev.left ||
7410 ply[i].x > lev.right - 1)
7412 ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
7414 game.centered_player_nr_next = i;
7415 game.set_centered_player = TRUE;
7416 game.set_centered_player_wrap = TRUE;
7419 ply[i].prev_x = ply[i].x;
7420 ply[i].prev_y = ply[i].y;
7421 ply[i].anim = PLY_still;
7424 start_check_nr = ((game_em.random & 128 ? 0 : 1) * 2 +
7425 (game_em.random & 256 ? 0 : 1));
7427 for (i = 0; i < MAX_PLAYERS; i++)
7429 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
7431 if (ply[check_nr].alive)
7432 check_player(&ply[check_nr]);
7435 for (i = 0; i < MAX_PLAYERS; i++)
7440 if (cave[ply[i].prev_x][ply[i].prev_y] == Zplayer)
7442 cave[ply[i].prev_x][ply[i].prev_y] = Xblank;
7443 next[ply[i].prev_x][ply[i].prev_y] = Xblank;
7446 if (cave[ply[i].x][ply[i].y] == Xblank)
7448 cave[ply[i].x][ply[i].y] = Zplayer;
7449 next[ply[i].x][ply[i].y] = Zplayer;
7454 static void logic_objects(void)
7462 seed = game_em.random;
7465 for (y = lev.top; y < lev.bottom; y++)
7466 for (x = lev.left; x < lev.right; x++)
7469 if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
7470 lev.score += score; /* only add a score if someone is alive */
7472 game_em.game_over = TRUE;
7474 game_em.random = seed;
7476 /* triple buffering */
7477 void *temp = lev.cave;
7478 lev.cave = lev.next;
7479 lev.next = lev.draw;
7483 static void logic_globals(void)
7488 unsigned int random;
7494 /* update variables */
7496 if (lev.score > 9999)
7499 if (lev.android_move_cnt-- == 0)
7500 lev.android_move_cnt = lev.android_move_time;
7501 if (lev.android_clone_cnt-- == 0)
7502 lev.android_clone_cnt = lev.android_clone_time;
7503 if (lev.ball_active)
7504 if (lev.ball_cnt-- == 0)
7505 lev.ball_cnt = lev.ball_time;
7508 if (lev.magnify_cnt)
7514 if (lev.wonderwall_time > 0 && lev.wonderwall_active)
7515 lev.wonderwall_time--;
7518 play_element_sound(lev.wheel_x, lev.wheel_y, SOUND_wheel, Xwheel);
7522 random = game_em.random;
7524 for (count = lev.amoeba_time; count--;)
7526 x = lev.left - 1 + (random >> 10) % (CAVE_WIDTH + 2);
7527 y = lev.top - 1 + (random >> 20) % (CAVE_HEIGHT + 2);
7529 if (x >= lev.left && x < lev.right &&
7530 y >= lev.top && y < lev.bottom)
7533 random = random * 129 + 1;
7536 game_em.random = random;
7538 /* handle explosions */
7540 for (y = lev.top; y < lev.bottom; y++)
7541 for (x = lev.left; x < lev.right; x++)
7544 /* triple buffering */
7546 for (y = lev.top; y < lev.bottom; y++)
7547 for (x = lev.left; x < lev.right; x++)
7548 next[x][y] = cave[x][y];
7551 void logic_init(void)
7553 int splash_is_blank = !game_em.use_old_android;
7555 is_android_blank[Xsplash_e] = splash_is_blank;
7556 is_android_blank[Xsplash_w] = splash_is_blank;