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_RAW (seed = seed << 31 | seed >> 1)
16 #define RANDOM(x) (RANDOM_RAW & (x - 1))
18 static short **cave, **next, **boom;
19 static unsigned int seed;
22 static const byte is_blank[GAME_TILE_MAX] =
37 static const byte is_blank_or_acid[GAME_TILE_MAX] =
60 static const byte is_fake_acid[GAME_TILE_MAX] =
72 static const byte is_amoeba[GAME_TILE_MAX] =
86 static const byte is_android_walkable[GAME_TILE_MAX] =
102 static void Lboom_generic(int x, int y, int element, int element_middle)
104 boom[x-1][y-1] = element;
105 boom[x][y-1] = element;
106 boom[x+1][y-1] = element;
107 boom[x-1][y] = element;
108 boom[x][y] = element_middle;
109 boom[x+1][y] = element;
110 boom[x-1][y+1] = element;
111 boom[x][y+1] = element;
112 boom[x+1][y+1] = element;
115 static void Lboom_bug(int x, int y)
117 if (game_em.use_old_explosions)
120 Lboom_generic(x, y, Xemerald, Xdiamond);
122 #if PLAY_ELEMENT_SOUND
123 play_element_sound(x, y, SOUND_boom, Xbug_1_n);
127 static void Lboom_tank(int x, int y)
129 if (game_em.use_old_explosions)
132 Lboom_generic(x, y, Xblank, Xblank);
134 #if PLAY_ELEMENT_SOUND
135 play_element_sound(x, y, SOUND_boom, Xtank_1_n);
139 static void Lboom_eater(int x, int y)
141 if (game_em.use_old_explosions)
144 boom[x-1][y-1] = lev.eater_array[lev.eater_pos][0];
145 boom[x][y-1] = lev.eater_array[lev.eater_pos][1];
146 boom[x+1][y-1] = lev.eater_array[lev.eater_pos][2];
147 boom[x-1][y] = lev.eater_array[lev.eater_pos][3];
148 boom[x][y] = lev.eater_array[lev.eater_pos][4];
149 boom[x+1][y] = lev.eater_array[lev.eater_pos][5];
150 boom[x-1][y+1] = lev.eater_array[lev.eater_pos][6];
151 boom[x][y+1] = lev.eater_array[lev.eater_pos][7];
152 boom[x+1][y+1] = lev.eater_array[lev.eater_pos][8];
154 lev.eater_pos = (lev.eater_pos + 1) & 7;
156 #if PLAY_ELEMENT_SOUND
157 play_element_sound(x, y, SOUND_boom, Xeater_n);
161 static void Lboom_bug_old(int x, int y)
163 if (!game_em.use_old_explosions)
169 static void Lboom_tank_old(int x, int y)
171 if (!game_em.use_old_explosions)
177 static void Lboom_eater_old(int x, int y)
179 if (!game_em.use_old_explosions)
185 static void Lboom_bug_new(int x, int y, boolean chain_explosion)
187 if (game_em.use_old_explosions)
196 static void Lboom_tank_new(int x, int y, boolean chain_explosion)
198 if (game_em.use_old_explosions)
207 static void Lboom_eater_new(int x, int y, boolean chain_explosion)
209 if (game_em.use_old_explosions)
218 static boolean player_killed(struct PLAYER *ply)
226 if (lev.killed_out_of_time && setup.time_limit)
229 switch (cave[x][y-1])
250 switch (cave[x+1][y])
271 switch (cave[x][y+1])
292 switch (cave[x-1][y])
337 static void kill_player(struct PLAYER *ply)
344 switch (cave[x][y-1])
354 cave[x][y-1] = Xboom_bug;
355 Lboom_bug_new(x, y-1, TRUE);
366 cave[x][y-1] = Xboom_tank;
367 Lboom_tank_new(x, y-1, TRUE);
371 switch (cave[x+1][y])
381 cave[x+1][y] = Xboom_bug;
382 Lboom_bug_new(x+1, y, TRUE);
393 cave[x+1][y] = Xboom_tank;
394 Lboom_tank_new(x+1, y, TRUE);
398 switch (cave[x][y+1])
408 cave[x][y+1] = Xboom_bug;
409 Lboom_bug_new(x, y+1, TRUE);
420 cave[x][y+1] = Xboom_tank;
421 Lboom_tank_new(x, y+1, TRUE);
425 switch (cave[x-1][y])
435 cave[x-1][y] = Xboom_bug;
436 Lboom_bug_new(x-1, y, TRUE);
447 cave[x-1][y] = Xboom_tank;
448 Lboom_tank_new(x-1, y, TRUE);
459 play_element_sound(x, y, SOUND_exit_leave, Xexit_1);
463 play_element_sound(x, y, SOUND_die, Zplayer);
482 cave[x][y] = Xboom_1;
488 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
490 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
495 boolean result = TRUE;
497 if (!dx && !dy) /* no direction specified */
500 if (dx && dy && ply->joy_snap) /* more than one direction specified */
503 if (!ply->joy_snap) /* player wants to move */
505 int element = cave[x][y];
509 /* fire is released */
513 cave[x][y] = Zplayer;
514 next[x][y] = Zplayer;
525 play_element_sound(x, y, SOUND_blank, Xblank);
526 ply->anim = PLY_walk_n + anim;
540 if (cave[x+1][y-1] == Xblank)
541 cave[x+1][y-1] = Xsplash_e;
542 if (cave[x-1][y-1] == Xblank)
543 cave[x-1][y-1] = Xsplash_w;
544 play_element_sound(x, y, SOUND_acid, Xacid_1);
565 ply->anim = PLY_walk_n + anim;
571 cave[x][y] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
572 (dx > 0 ? Ygrass_eB : Ygrass_wB));
573 next[x][y] = Zplayer;
574 play_element_sound(x, y, SOUND_dirt, Xgrass);
575 ply->anim = PLY_walk_n + anim;
581 cave[x][y] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
582 (dx > 0 ? Ydirt_eB : Ydirt_wB));
583 next[x][y] = Zplayer;
584 play_element_sound(x, y, SOUND_dirt, Xdirt);
585 ply->anim = PLY_walk_n + anim;
592 cave[x][y] = Ydiamond_blank;
593 next[x][y] = Zplayer;
594 play_element_sound(x, y, SOUND_collect, element);
595 lev.score += lev.diamond_score;
596 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
597 game.snapshot.collected_item = TRUE;
598 ply->anim = PLY_walk_n + anim;
605 cave[x][y] = Yemerald_blank;
606 next[x][y] = Zplayer;
607 play_element_sound(x, y, SOUND_collect, element);
608 lev.score += lev.emerald_score;
609 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
610 game.snapshot.collected_item = TRUE;
611 ply->anim = PLY_walk_n + anim;
617 cave[x][y] = Ydynamite_blank;
618 next[x][y] = Zplayer;
619 play_element_sound(x, y, SOUND_collect, element);
620 lev.score += lev.dynamite_score;
621 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
622 ply->anim = PLY_walk_n + anim;
629 cave[x][y] = Ykey_1_blank;
634 cave[x][y] = Ykey_2_blank;
639 cave[x][y] = Ykey_3_blank;
644 cave[x][y] = Ykey_4_blank;
649 cave[x][y] = Ykey_5_blank;
654 cave[x][y] = Ykey_6_blank;
659 cave[x][y] = Ykey_7_blank;
664 cave[x][y] = Ykey_8_blank;
669 next[x][y] = Zplayer;
670 play_element_sound(x, y, SOUND_collect, element);
671 lev.score += lev.key_score;
672 ply->anim = PLY_walk_n + anim;
678 cave[x][y] = Ylenses_blank;
679 next[x][y] = Zplayer;
680 play_element_sound(x, y, SOUND_collect, element);
681 lev.score += lev.lenses_score;
682 lev.lenses_cnt = lev.lenses_time;
683 ply->anim = PLY_walk_n + anim;
689 cave[x][y] = Ymagnify_blank;
690 next[x][y] = Zplayer;
691 play_element_sound(x, y, SOUND_collect, element);
692 lev.score += lev.magnify_score;
693 lev.magnify_cnt = lev.magnify_time;
694 ply->anim = PLY_walk_n + anim;
703 switch (cave[x+dx][y])
716 cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
717 next[x+dx][y] = Xstone_pause;
728 if (cave[x+dx+1][y-1] == Xblank)
729 cave[x+dx+1][y-1] = Xsplash_e;
730 if (cave[x+dx-1][y-1] == Xblank)
731 cave[x+dx-1][y-1] = Xsplash_w;
732 play_element_sound(x, y, SOUND_acid, Xacid_1);
736 cave[x][y] = dx > 0 ? Ystone_eB : Ystone_wB;
737 next[x][y] = Zplayer;
738 play_element_sound(x, y, SOUND_roll, Xstone);
743 ply->anim = PLY_push_n + anim;
750 switch (cave[x+dx][y])
763 cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
764 next[x+dx][y] = Xbomb_pause;
775 if (cave[x+dx+1][y-1] == Xblank)
776 cave[x+dx+1][y-1] = Xsplash_e;
777 if (cave[x+dx-1][y-1] == Xblank)
778 cave[x+dx-1][y-1] = Xsplash_w;
779 play_element_sound(x, y, SOUND_acid, Xacid_1);
783 cave[x][y] = dx > 0 ? Ybomb_eB : Ybomb_wB;
784 next[x][y] = Zplayer;
785 play_element_sound(x, y, SOUND_roll, Xbomb);
790 ply->anim = PLY_push_n + anim;
797 switch (cave[x+dx][y])
810 cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
811 next[x+dx][y] = Xnut_pause;
822 if (cave[x+dx+1][y-1] == Xblank)
823 cave[x+dx+1][y-1] = Xsplash_e;
824 if (cave[x+dx-1][y-1] == Xblank)
825 cave[x+dx-1][y-1] = Xsplash_w;
826 play_element_sound(x, y, SOUND_acid, Xacid_1);
830 cave[x][y] = dx > 0 ? Ynut_eB : Ynut_wB;
831 next[x][y] = Zplayer;
832 play_element_sound(x, y, SOUND_roll, Xnut);
837 ply->anim = PLY_push_n + anim;
844 switch (cave[x+dx][y])
857 cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
858 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
869 if (cave[x+dx+1][y-1] == Xblank)
870 cave[x+dx+1][y-1] = Xsplash_e;
871 if (cave[x+dx-1][y-1] == Xblank)
872 cave[x+dx-1][y-1] = Xsplash_w;
873 play_element_sound(x, y, SOUND_acid, Xacid_1);
877 cave[x][y] = dx > 0 ? Yspring_eB : Yspring_wB;
878 next[x][y] = Zplayer;
879 play_element_sound(x, y, SOUND_roll, Xspring);
885 cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
886 cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
887 next[x][y] = Zplayer;
888 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
889 play_element_sound(x, y, SOUND_slurp, Xalien);
890 lev.score += lev.slurp_score;
895 ply->anim = PLY_push_n + anim;
902 case Xsand_stonein_1:
903 case Xsand_stonein_2:
904 case Xsand_stonein_3:
905 case Xsand_stonein_4:
909 ply->anim = PLY_push_n + anim;
913 switch (cave[x+dx][y+dy])
926 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
927 (dx > 0 ? Yballoon_e : Yballoon_w));
928 next[x+dx][y+dy] = Xballoon;
939 if (cave[x+dx+1][y+dy-1] == Xblank)
940 cave[x+dx+1][y+dy-1] = Xsplash_e;
941 if (cave[x+dx-1][y+dy-1] == Xblank)
942 cave[x+dx-1][y+dy-1] = Xsplash_w;
943 play_element_sound(x, y, SOUND_acid, Xacid_1);
947 cave[x][y] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
948 (dx > 0 ? Yballoon_eB : Yballoon_wB));
949 next[x][y] = Zplayer;
950 play_element_sound(x, y, SOUND_push, Xballoon);
956 ply->anim = PLY_push_n + anim;
968 switch (cave[x+dx][y+dy])
981 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
982 (dx > 0 ? Yandroid_e : Yandroid_w));
983 next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
984 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
995 if (cave[x+dx+1][y+dy-1] == Xblank)
996 cave[x+dx+1][y+dy-1] = Xsplash_e;
997 if (cave[x+dx-1][y+dy-1] == Xblank)
998 cave[x+dx-1][y+dy-1] = Xsplash_w;
999 play_element_sound(x, y, SOUND_acid, Xacid_1);
1003 cave[x][y] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
1004 (dx > 0 ? Yandroid_eB : Yandroid_wB));
1005 next[x][y] = Zplayer;
1006 play_element_sound(x, y, SOUND_push, Xandroid);
1012 ply->anim = PLY_push_n + anim;
1017 if (ply->keys & 0x01)
1024 if (ply->keys & 0x02)
1031 if (ply->keys & 0x04)
1038 if (ply->keys & 0x08)
1045 if (ply->keys & 0x10)
1052 if (ply->keys & 0x20)
1059 if (ply->keys & 0x40)
1066 if (ply->keys & 0x80)
1073 if (!is_blank[cave[x+dx][y+dy]])
1076 if (!is_fake_acid[cave[x+dx][y+dy]])
1078 cave[x+dx][y+dy] = Zplayer;
1079 next[x+dx][y+dy] = Zplayer;
1082 play_element_sound(x, y, SOUND_door, element);
1083 ply->anim = PLY_walk_n + anim;
1089 play_element_sound(x, y, SOUND_press, element);
1090 lev.wheel_cnt = lev.wheel_time;
1096 lev.wind_direction = 0;
1100 lev.wind_direction = 1;
1104 lev.wind_direction = 2;
1108 lev.wind_direction = 3;
1112 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1117 play_element_sound(x, y, SOUND_press, element);
1118 lev.wind_cnt = lev.wind_time;
1122 play_element_sound(x, y, SOUND_press, element);
1127 play_element_sound(x, y, SOUND_press, element);
1128 lev.ball_cnt = lev.ball_time;
1129 lev.ball_active = !lev.ball_active;
1133 cave[x][y] = Yplant;
1134 next[x][y] = Xplant;
1135 play_element_sound(x, y, SOUND_blank, Xplant);
1136 ply->anim = PLY_walk_n + anim;
1147 game_em.level_solved = TRUE;
1149 ply->anim = PLY_walk_n + anim;
1156 if (ply->x == oldx && ply->y == oldy) /* no movement */
1159 else /* player wants to snap */
1161 int element = cave[x][y];
1165 /* fire is pressed */
1168 cave[x][y] = Ygrass_blank;
1169 next[x][y] = Xblank;
1170 play_element_sound(x, y, SOUND_dirt, element);
1171 ply->anim = PLY_shoot_n + anim;
1175 cave[x][y] = Ydirt_blank;
1176 next[x][y] = Xblank;
1177 play_element_sound(x, y, SOUND_dirt, element);
1178 ply->anim = PLY_shoot_n + anim;
1182 case Xdiamond_pause:
1183 cave[x][y] = Ydiamond_blank;
1184 next[x][y] = Xblank;
1185 play_element_sound(x, y, SOUND_collect, element);
1186 lev.score += lev.diamond_score;
1187 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
1188 game.snapshot.collected_item = TRUE;
1189 ply->anim = PLY_walk_n + anim;
1193 case Xemerald_pause:
1194 cave[x][y] = Yemerald_blank;
1195 next[x][y] = Xblank;
1196 play_element_sound(x, y, SOUND_collect, element);
1197 lev.score += lev.emerald_score;
1198 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
1199 game.snapshot.collected_item = TRUE;
1200 ply->anim = PLY_walk_n + anim;
1204 cave[x][y] = Ydynamite_blank;
1205 next[x][y] = Xblank;
1206 play_element_sound(x, y, SOUND_collect, element);
1207 lev.score += lev.dynamite_score;
1208 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1209 ply->anim = PLY_walk_n + anim;
1214 cave[x][y] = Ykey_1_blank;
1219 cave[x][y] = Ykey_2_blank;
1224 cave[x][y] = Ykey_3_blank;
1229 cave[x][y] = Ykey_4_blank;
1234 cave[x][y] = Ykey_5_blank;
1239 cave[x][y] = Ykey_6_blank;
1244 cave[x][y] = Ykey_7_blank;
1249 cave[x][y] = Ykey_8_blank;
1254 next[x][y] = Xblank;
1255 play_element_sound(x, y, SOUND_collect, element);
1256 lev.score += lev.key_score;
1257 ply->anim = PLY_walk_n + anim;
1261 cave[x][y] = Ylenses_blank;
1262 next[x][y] = Xblank;
1263 play_element_sound(x, y, SOUND_collect, element);
1264 lev.score += lev.lenses_score;
1265 lev.lenses_cnt = lev.lenses_time;
1266 ply->anim = PLY_walk_n + anim;
1270 cave[x][y] = Ymagnify_blank;
1271 next[x][y] = Xblank;
1272 play_element_sound(x, y, SOUND_collect, element);
1273 lev.score += lev.magnify_score;
1274 lev.magnify_cnt = lev.magnify_time;
1275 ply->anim = PLY_walk_n + anim;
1286 static void check_player(struct PLAYER *ply)
1294 game_em.last_player_direction[ply->num] = MV_NONE;
1296 if (ply->joy_w) /* west */
1301 else if (ply->joy_e) /* east */
1307 if (ply->joy_n) /* north */
1312 else if (ply->joy_s) /* south */
1324 boolean players_visible_before_move;
1325 boolean players_visible_after_move;
1328 players_visible_before_move = checkIfAllPlayersFitToScreen();
1333 players_visible_after_move = checkIfAllPlayersFitToScreen();
1336 player is allowed to move only in the following cases:
1337 - it is not needed to display all players (not focussed to all players)
1338 - all players are (still or again) visible after the move
1339 - some players were already outside visible screen area before the move
1341 can_move = (game.centered_player_nr != -1 ||
1342 players_visible_after_move ||
1343 !players_visible_before_move);
1359 if (dx == 0 && dy == 0)
1361 ply->joy_stick = FALSE;
1365 if (++ply->dynamite_cnt == 5 && ply->dynamite)
1367 cave[x][y] = Xdynamite_1;
1368 play_element_sound(x, y, SOUND_dynamite, Xdynamite_1);
1374 ply->dynamite_cnt = 0;
1377 /* be a bit more random if the player doesn't move */
1378 game_em.random += 7;
1383 ply->joy_stick = TRUE;
1389 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
1391 if (!ply->joy_snap) /* player wants to move */
1393 boolean moved = FALSE;
1395 if (ply->last_move_dir & MV_HORIZONTAL)
1397 if (!(moved = player_digfield(ply, 0, dy)))
1398 moved = player_digfield(ply, dx, 0);
1402 if (!(moved = player_digfield(ply, dx, 0)))
1403 moved = player_digfield(ply, 0, dy);
1409 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
1410 else if (oldy != ply->y)
1411 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
1413 game_em.any_player_moving = TRUE;
1414 game_em.last_moving_player = ply->num;
1415 game_em.last_player_direction[ply->num] = ply->last_move_dir;
1418 else /* player wants to snap */
1420 game_em.any_player_snapping = player_digfield(ply, dx, dy);
1424 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
1426 int distance, distance_shortest = CAVE_WIDTH + CAVE_HEIGHT;
1429 /* default values if no players are alive anymore */
1433 for (i = 0; i < MAX_PLAYERS; i++)
1438 distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
1440 if (distance < distance_shortest)
1445 distance_shortest = distance;
1450 static void Lacid_1(int x, int y)
1452 next[x][y] = Xacid_2;
1455 static void Lacid_2(int x, int y)
1457 next[x][y] = Xacid_3;
1460 static void Lacid_3(int x, int y)
1462 next[x][y] = Xacid_4;
1465 static void Lacid_4(int x, int y)
1467 next[x][y] = Xacid_5;
1470 static void Lacid_5(int x, int y)
1472 next[x][y] = Xacid_6;
1475 static void Lacid_6(int x, int y)
1477 next[x][y] = Xacid_7;
1480 static void Lacid_7(int x, int y)
1482 next[x][y] = Xacid_8;
1485 static void Lacid_8(int x, int y)
1487 next[x][y] = Xacid_1;
1490 static void Lfake_acid_1(int x, int y)
1492 next[x][y] = Xfake_acid_2;
1495 static void Lfake_acid_2(int x, int y)
1497 next[x][y] = Xfake_acid_3;
1500 static void Lfake_acid_3(int x, int y)
1502 next[x][y] = Xfake_acid_4;
1505 static void Lfake_acid_4(int x, int y)
1507 next[x][y] = Xfake_acid_5;
1510 static void Lfake_acid_5(int x, int y)
1512 next[x][y] = Xfake_acid_6;
1515 static void Lfake_acid_6(int x, int y)
1517 next[x][y] = Xfake_acid_7;
1520 static void Lfake_acid_7(int x, int y)
1522 next[x][y] = Xfake_acid_8;
1525 static void Lfake_acid_8(int x, int y)
1527 next[x][y] = Xfake_acid_1;
1530 static void Landroid(int x, int y)
1534 if (lev.android_clone_cnt == 0)
1536 if (!is_blank[cave[x-1][y-1]] &&
1537 !is_blank[cave[x][y-1]] &&
1538 !is_blank[cave[x+1][y-1]] &&
1539 !is_blank[cave[x-1][y]] &&
1540 !is_blank[cave[x+1][y]] &&
1541 !is_blank[cave[x-1][y+1]] &&
1542 !is_blank[cave[x][y+1]] &&
1543 !is_blank[cave[x+1][y+1]])
1548 /* randomly find an object to clone */
1550 case 0: /* S,NE,W,NW,SE,E,SW,N */
1551 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1552 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1553 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1554 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1555 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1556 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1557 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1558 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1561 case 1: /* NW,SE,N,S,NE,SW,E,W */
1562 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1563 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1564 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1565 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1566 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1567 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1568 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1569 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1572 case 2: /* SW,E,S,W,N,NW,SE,NE */
1573 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1574 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1575 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1576 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1577 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1578 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1579 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1580 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1583 case 3: /* N,SE,NE,E,W,S,NW,SW */
1584 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1585 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1586 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1587 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1588 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1589 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1590 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1591 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1594 case 4: /* SE,NW,E,NE,SW,W,N,S */
1595 temp = lev.android_array[cave[x+1][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][y-1]]; if (temp != Xblank) break;
1602 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1605 case 5: /* NE,W,SE,SW,S,N,E,NW */
1606 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1607 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1608 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1609 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1610 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1611 temp = lev.android_array[cave[x][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-1]]; if (temp != Xblank) break;
1616 case 6: /* E,N,SW,S,NW,NE,SE,W */
1617 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1618 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1619 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1620 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1621 temp = lev.android_array[cave[x-1][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]]; if (temp != Xblank) break;
1627 case 7: /* W,SW,NW,N,E,SE,NE,S */
1628 temp = lev.android_array[cave[x-1][y]]; 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][y-1]]; if (temp != Xblank) break;
1632 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1633 temp = lev.android_array[cave[x+1][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][y+1]]; if (temp != Xblank) break;
1639 next[x][y] = temp; /* the item we chose to clone */
1640 play_element_sound(x, y, SOUND_android_clone, temp);
1644 /* randomly find a direction to move */
1646 case 0: /* S,NE,W,NW,SE,E,SW,N */
1647 if (is_blank[cave[x][y+1]]) goto android_s;
1648 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1649 if (is_blank[cave[x-1][y]]) goto android_w;
1650 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1651 if (is_blank[cave[x+1][y+1]]) goto android_se;
1652 if (is_blank[cave[x+1][y]]) goto android_e;
1653 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1654 if (is_blank[cave[x][y-1]]) goto android_n;
1657 case 1: /* NW,SE,N,S,NE,SW,E,W */
1658 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1659 if (is_blank[cave[x+1][y+1]]) goto android_se;
1660 if (is_blank[cave[x][y-1]]) goto android_n;
1661 if (is_blank[cave[x][y+1]]) goto android_s;
1662 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1663 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1664 if (is_blank[cave[x+1][y]]) goto android_e;
1665 if (is_blank[cave[x-1][y]]) goto android_w;
1668 case 2: /* SW,E,S,W,N,NW,SE,NE */
1669 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1670 if (is_blank[cave[x+1][y]]) goto android_e;
1671 if (is_blank[cave[x][y+1]]) goto android_s;
1672 if (is_blank[cave[x-1][y]]) goto android_w;
1673 if (is_blank[cave[x][y-1]]) goto android_n;
1674 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1675 if (is_blank[cave[x+1][y+1]]) goto android_se;
1676 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1679 case 3: /* N,SE,NE,E,W,S,NW,SW */
1680 if (is_blank[cave[x][y-1]]) goto android_n;
1681 if (is_blank[cave[x+1][y+1]]) goto android_se;
1682 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1683 if (is_blank[cave[x+1][y]]) goto android_e;
1684 if (is_blank[cave[x-1][y]]) goto android_w;
1685 if (is_blank[cave[x][y+1]]) goto android_s;
1686 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1687 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1690 case 4: /* SE,NW,E,NE,SW,W,N,S */
1691 if (is_blank[cave[x+1][y+1]]) goto android_se;
1692 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1693 if (is_blank[cave[x+1][y]]) goto android_e;
1694 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1695 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1696 if (is_blank[cave[x-1][y]]) goto android_w;
1697 if (is_blank[cave[x][y-1]]) goto android_n;
1698 if (is_blank[cave[x][y+1]]) goto android_s;
1701 case 5: /* NE,W,SE,SW,S,N,E,NW */
1702 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1703 if (is_blank[cave[x-1][y]]) goto android_w;
1704 if (is_blank[cave[x+1][y+1]]) goto android_se;
1705 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1706 if (is_blank[cave[x][y+1]]) goto android_s;
1707 if (is_blank[cave[x][y-1]]) goto android_n;
1708 if (is_blank[cave[x+1][y]]) goto android_e;
1709 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1712 case 6: /* E,N,SW,S,NW,NE,SE,W */
1713 if (is_blank[cave[x+1][y]]) goto android_e;
1714 if (is_blank[cave[x][y-1]]) goto android_n;
1715 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1716 if (is_blank[cave[x][y+1]]) goto android_s;
1717 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1718 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1719 if (is_blank[cave[x+1][y+1]]) goto android_se;
1720 if (is_blank[cave[x-1][y]]) goto android_w;
1723 case 7: /* W,SW,NW,N,E,SE,NE,S */
1724 if (is_blank[cave[x-1][y]]) goto android_w;
1725 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1726 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1727 if (is_blank[cave[x][y-1]]) goto android_n;
1728 if (is_blank[cave[x+1][y]]) goto android_e;
1729 if (is_blank[cave[x+1][y+1]]) goto android_se;
1730 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1731 if (is_blank[cave[x][y+1]]) goto android_s;
1737 if (lev.android_move_cnt == 0)
1739 if (cave[x-1][y-1] == Zplayer ||
1740 cave[x][y-1] == Zplayer ||
1741 cave[x+1][y-1] == Zplayer ||
1742 cave[x-1][y] == Zplayer ||
1743 cave[x+1][y] == Zplayer ||
1744 cave[x-1][y+1] == Zplayer ||
1745 cave[x][y+1] == Zplayer ||
1746 cave[x+1][y+1] == Zplayer)
1749 set_nearest_player_xy(x, y, &dx, &dy);
1751 next[x][y] = Xblank; /* assume we will move */
1752 temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
1758 /* attempt clockwise move first if direct path is blocked */
1760 case 0: /* north west */
1761 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1762 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1763 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1767 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1768 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1769 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1772 case 2: /* north east */
1773 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1774 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1775 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1779 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1780 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1781 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1784 case 4: /* nowhere */
1788 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1789 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1790 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1793 case 6: /* south west */
1794 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1795 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1796 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1800 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1801 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1802 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1805 case 8: /* south east */
1806 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1807 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1808 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1816 /* attempt counterclockwise move first if direct path is blocked */
1818 case 0: /* north west */
1819 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1820 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1821 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1825 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1826 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1827 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1830 case 2: /* north east */
1831 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1832 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1833 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1837 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1838 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1839 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1842 case 4: /* nowhere */
1846 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1847 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1848 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1851 case 6: /* south west */
1852 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1853 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1854 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1858 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1859 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1860 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1863 case 8: /* south east */
1864 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1865 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1866 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1873 next[x][y] = Xandroid;
1877 cave[x][y] = Yandroid_nB;
1878 cave[x][y-1] = Yandroid_n;
1879 next[x][y-1] = Xandroid;
1880 play_element_sound(x, y, SOUND_android_move, Xandroid);
1884 cave[x][y] = Yandroid_neB;
1885 cave[x+1][y-1] = Yandroid_ne;
1886 next[x+1][y-1] = Xandroid;
1887 play_element_sound(x, y, SOUND_android_move, Xandroid);
1891 cave[x][y] = Yandroid_eB;
1892 cave[x+1][y] = Yandroid_e;
1893 next[x+1][y] = Xandroid;
1894 play_element_sound(x, y, SOUND_android_move, Xandroid);
1898 cave[x][y] = Yandroid_seB;
1899 cave[x+1][y+1] = Yandroid_se;
1900 next[x+1][y+1] = Xandroid;
1901 play_element_sound(x, y, SOUND_android_move, Xandroid);
1905 cave[x][y] = Yandroid_sB;
1906 cave[x][y+1] = Yandroid_s;
1907 next[x][y+1] = Xandroid;
1908 play_element_sound(x, y, SOUND_android_move, Xandroid);
1912 cave[x][y] = Yandroid_swB;
1913 cave[x-1][y+1] = Yandroid_sw;
1914 next[x-1][y+1] = Xandroid;
1915 play_element_sound(x, y, SOUND_android_move, Xandroid);
1919 cave[x][y] = Yandroid_wB;
1920 cave[x-1][y] = Yandroid_w;
1921 next[x-1][y] = Xandroid;
1922 play_element_sound(x, y, SOUND_android_move, Xandroid);
1926 cave[x][y] = Yandroid_nwB;
1927 cave[x-1][y-1] = Yandroid_nw;
1928 next[x-1][y-1] = Xandroid;
1929 play_element_sound(x, y, SOUND_android_move, Xandroid);
1933 static void Landroid_1_n(int x, int y)
1935 switch (cave[x][y-1])
1948 cave[x][y] = Yandroid_nB;
1949 next[x][y] = Xblank;
1950 cave[x][y-1] = Yandroid_n;
1951 next[x][y-1] = Xandroid;
1952 play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
1963 cave[x][y] = Yandroid_nB;
1964 next[x][y] = Xblank;
1965 if (cave[x+1][y-2] == Xblank)
1966 cave[x+1][y-2] = Xsplash_e;
1967 if (cave[x-1][y-2] == Xblank)
1968 cave[x-1][y-2] = Xsplash_w;
1969 play_element_sound(x, y, SOUND_acid, Xacid_1);
1978 static void Landroid_2_n(int x, int y)
1980 switch (cave[x][y-1])
1993 cave[x][y] = Yandroid_nB;
1994 next[x][y] = Xblank;
1995 cave[x][y-1] = Yandroid_n;
1996 next[x][y-1] = Xandroid_1_n;
1997 play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
2008 cave[x][y] = Yandroid_nB;
2009 next[x][y] = Xblank;
2010 if (cave[x+1][y-2] == Xblank)
2011 cave[x+1][y-2] = Xsplash_e;
2012 if (cave[x-1][y-2] == Xblank)
2013 cave[x-1][y-2] = Xsplash_w;
2014 play_element_sound(x, y, SOUND_acid, Xacid_1);
2023 static void Landroid_1_e(int x, int y)
2025 switch (cave[x+1][y])
2038 cave[x][y] = Yandroid_eB;
2039 next[x][y] = Xblank;
2040 cave[x+1][y] = Yandroid_e;
2041 next[x+1][y] = Xandroid;
2042 play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
2053 cave[x][y] = Yandroid_eB;
2054 next[x][y] = Xblank;
2055 if (cave[x+2][y-1] == Xblank)
2056 cave[x+2][y-1] = Xsplash_e;
2057 if (cave[x][y-1] == Xblank)
2058 cave[x][y-1] = Xsplash_w;
2059 play_element_sound(x, y, SOUND_acid, Xacid_1);
2068 static void Landroid_2_e(int x, int y)
2070 switch (cave[x+1][y])
2083 cave[x][y] = Yandroid_eB;
2084 next[x][y] = Xblank;
2085 cave[x+1][y] = Yandroid_e;
2086 next[x+1][y] = Xandroid_1_e;
2087 play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
2098 cave[x][y] = Yandroid_eB;
2099 next[x][y] = Xblank;
2100 if (cave[x+2][y-1] == Xblank)
2101 cave[x+2][y-1] = Xsplash_e;
2102 if (cave[x][y-1] == Xblank)
2103 cave[x][y-1] = Xsplash_w;
2104 play_element_sound(x, y, SOUND_acid, Xacid_1);
2113 static void Landroid_1_s(int x, int y)
2115 switch (cave[x][y+1])
2128 cave[x][y] = Yandroid_sB;
2129 next[x][y] = Xblank;
2130 cave[x][y+1] = Yandroid_s;
2131 next[x][y+1] = Xandroid;
2132 play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
2143 cave[x][y] = Yandroid_sB;
2144 next[x][y] = Xblank;
2145 if (cave[x+1][y] == Xblank)
2146 cave[x+1][y] = Xsplash_e;
2147 if (cave[x-1][y] == Xblank)
2148 cave[x-1][y] = Xsplash_w;
2149 play_element_sound(x, y, SOUND_acid, Xacid_1);
2158 static void Landroid_2_s(int x, int y)
2160 switch (cave[x][y+1])
2173 cave[x][y] = Yandroid_sB;
2174 next[x][y] = Xblank;
2175 cave[x][y+1] = Yandroid_s;
2176 next[x][y+1] = Xandroid_1_s;
2177 play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
2188 cave[x][y] = Yandroid_sB;
2189 next[x][y] = Xblank;
2190 if (cave[x+1][y] == Xblank)
2191 cave[x+1][y] = Xsplash_e;
2192 if (cave[x-1][y] == Xblank)
2193 cave[x-1][y] = Xsplash_w;
2194 play_element_sound(x, y, SOUND_acid, Xacid_1);
2203 static void Landroid_1_w(int x, int y)
2205 switch (cave[x-1][y])
2218 cave[x][y] = Yandroid_wB;
2219 next[x][y] = Xblank;
2220 cave[x-1][y] = Yandroid_w;
2221 next[x-1][y] = Xandroid;
2222 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2233 cave[x][y] = Yandroid_wB;
2234 next[x][y] = Xblank;
2235 if (cave[x][y-1] == Xblank)
2236 cave[x][y-1] = Xsplash_e;
2237 if (cave[x-2][y-1] == Xblank)
2238 cave[x-2][y-1] = Xsplash_w;
2239 play_element_sound(x, y, SOUND_acid, Xacid_1);
2248 static void Landroid_2_w(int x, int y)
2250 switch (cave[x-1][y])
2263 cave[x][y] = Yandroid_wB;
2264 next[x][y] = Xblank;
2265 cave[x-1][y] = Yandroid_w;
2266 next[x-1][y] = Xandroid_1_w;
2267 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2278 cave[x][y] = Yandroid_wB;
2279 next[x][y] = Xblank;
2280 if (cave[x][y-1] == Xblank)
2281 cave[x][y-1] = Xsplash_e;
2282 if (cave[x-2][y-1] == Xblank)
2283 cave[x-2][y-1] = Xsplash_w;
2284 play_element_sound(x, y, SOUND_acid, Xacid_1);
2293 static void Leater_n(int x, int y)
2295 if (cave[x+1][y] == Xdiamond)
2297 cave[x+1][y] = Ydiamond_blank;
2298 next[x+1][y] = Xblank;
2299 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2303 if (cave[x][y+1] == Xdiamond)
2305 cave[x][y+1] = Ydiamond_blank;
2306 next[x][y+1] = Xblank;
2307 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2311 if (cave[x-1][y] == Xdiamond)
2313 cave[x-1][y] = Ydiamond_blank;
2314 next[x-1][y] = Xblank;
2315 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2319 if (cave[x][y-1] == Xdiamond)
2321 cave[x][y-1] = Ydiamond_blank;
2322 next[x][y-1] = Xblank;
2323 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2327 switch (cave[x][y-1])
2343 cave[x][y] = Yeater_nB;
2344 next[x][y] = Xblank;
2345 cave[x][y-1] = Yeater_n;
2346 next[x][y-1] = Xeater_n;
2357 cave[x][y] = Yeater_nB;
2358 next[x][y] = Xblank;
2359 if (cave[x+1][y-2] == Xblank)
2360 cave[x+1][y-2] = Xsplash_e;
2361 if (cave[x-1][y-2] == Xblank)
2362 cave[x-1][y-2] = Xsplash_w;
2363 play_element_sound(x, y, SOUND_acid, Xacid_1);
2367 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2368 play_element_sound(x, y, SOUND_eater, Xeater_n);
2373 static void Leater_e(int x, int y)
2375 if (cave[x][y+1] == Xdiamond)
2377 cave[x][y+1] = Ydiamond_blank;
2378 next[x][y+1] = Xblank;
2379 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2383 if (cave[x-1][y] == Xdiamond)
2385 cave[x-1][y] = Ydiamond_blank;
2386 next[x-1][y] = Xblank;
2387 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2391 if (cave[x][y-1] == Xdiamond)
2393 cave[x][y-1] = Ydiamond_blank;
2394 next[x][y-1] = Xblank;
2395 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2399 if (cave[x+1][y] == Xdiamond)
2401 cave[x+1][y] = Ydiamond_blank;
2402 next[x+1][y] = Xblank;
2403 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2407 switch (cave[x+1][y])
2423 cave[x][y] = Yeater_eB;
2424 next[x][y] = Xblank;
2425 cave[x+1][y] = Yeater_e;
2426 next[x+1][y] = Xeater_e;
2437 cave[x][y] = Yeater_eB;
2438 next[x][y] = Xblank;
2439 if (cave[x+2][y-1] == Xblank)
2440 cave[x+2][y-1] = Xsplash_e;
2441 if (cave[x][y-1] == Xblank)
2442 cave[x][y-1] = Xsplash_w;
2443 play_element_sound(x, y, SOUND_acid, Xacid_1);
2447 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2448 play_element_sound(x, y, SOUND_eater, Xeater_e);
2453 static void Leater_s(int x, int y)
2455 if (cave[x-1][y] == Xdiamond)
2457 cave[x-1][y] = Ydiamond_blank;
2458 next[x-1][y] = Xblank;
2459 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2463 if (cave[x][y-1] == Xdiamond)
2465 cave[x][y-1] = Ydiamond_blank;
2466 next[x][y-1] = Xblank;
2467 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2471 if (cave[x+1][y] == Xdiamond)
2473 cave[x+1][y] = Ydiamond_blank;
2474 next[x+1][y] = Xblank;
2475 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2479 if (cave[x][y+1] == Xdiamond)
2481 cave[x][y+1] = Ydiamond_blank;
2482 next[x][y+1] = Xblank;
2483 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2487 switch (cave[x][y+1])
2503 cave[x][y] = Yeater_sB;
2504 next[x][y] = Xblank;
2505 cave[x][y+1] = Yeater_s;
2506 next[x][y+1] = Xeater_s;
2517 cave[x][y] = Yeater_sB;
2518 next[x][y] = Xblank;
2519 if (cave[x+1][y] == Xblank)
2520 cave[x+1][y] = Xsplash_e;
2521 if (cave[x-1][y] == Xblank)
2522 cave[x-1][y] = Xsplash_w;
2523 play_element_sound(x, y, SOUND_acid, Xacid_1);
2527 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2528 play_element_sound(x, y, SOUND_eater, Xeater_s);
2533 static void Leater_w(int x, int y)
2535 if (cave[x][y-1] == Xdiamond)
2537 cave[x][y-1] = Ydiamond_blank;
2538 next[x][y-1] = Xblank;
2539 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2543 if (cave[x+1][y] == Xdiamond)
2545 cave[x+1][y] = Ydiamond_blank;
2546 next[x+1][y] = Xblank;
2547 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2551 if (cave[x][y+1] == Xdiamond)
2553 cave[x][y+1] = Ydiamond_blank;
2554 next[x][y+1] = Xblank;
2555 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2559 if (cave[x-1][y] == Xdiamond)
2561 cave[x-1][y] = Ydiamond_blank;
2562 next[x-1][y] = Xblank;
2563 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2567 switch (cave[x-1][y])
2583 cave[x][y] = Yeater_wB;
2584 next[x][y] = Xblank;
2585 cave[x-1][y] = Yeater_w;
2586 next[x-1][y] = Xeater_w;
2597 cave[x][y] = Yeater_wB;
2598 next[x][y] = Xblank;
2599 if (cave[x][y-1] == Xblank)
2600 cave[x][y-1] = Xsplash_e;
2601 if (cave[x-2][y-1] == Xblank)
2602 cave[x-2][y-1] = Xsplash_w;
2603 play_element_sound(x, y, SOUND_acid, Xacid_1);
2607 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2608 play_element_sound(x, y, SOUND_eater, Xeater_w);
2613 static void Lalien(int x, int y)
2624 set_nearest_player_xy(x, y, &dx, &dy);
2631 switch (cave[x][y-1])
2647 cave[x][y] = Yalien_nB;
2648 next[x][y] = Xblank;
2649 cave[x][y-1] = Yalien_n;
2650 next[x][y-1] = Xalien_pause;
2651 play_element_sound(x, y, SOUND_alien, Xalien);
2662 cave[x][y] = Yalien_nB;
2663 next[x][y] = Xblank;
2664 if (cave[x+1][y-2] == Xblank)
2665 cave[x+1][y-2] = Xsplash_e;
2666 if (cave[x-1][y-2] == Xblank)
2667 cave[x-1][y-2] = Xsplash_w;
2668 play_element_sound(x, y, SOUND_acid, Xacid_1);
2674 switch (cave[x][y+1])
2690 cave[x][y] = Yalien_sB;
2691 next[x][y] = Xblank;
2692 cave[x][y+1] = Yalien_s;
2693 next[x][y+1] = Xalien_pause;
2694 play_element_sound(x, y, SOUND_alien, Xalien);
2705 cave[x][y] = Yalien_sB;
2706 next[x][y] = Xblank;
2707 if (cave[x+1][y] == Xblank)
2708 cave[x+1][y] = Xsplash_e;
2709 if (cave[x-1][y] == Xblank)
2710 cave[x-1][y] = Xsplash_w;
2711 play_element_sound(x, y, SOUND_acid, Xacid_1);
2720 switch (cave[x+1][y])
2736 cave[x][y] = Yalien_eB;
2737 next[x][y] = Xblank;
2738 cave[x+1][y] = Yalien_e;
2739 next[x+1][y] = Xalien_pause;
2740 play_element_sound(x, y, SOUND_alien, Xalien);
2751 cave[x][y] = Yalien_eB;
2752 next[x][y] = Xblank;
2753 if (cave[x+2][y-1] == Xblank)
2754 cave[x+2][y-1] = Xsplash_e;
2755 if (cave[x][y-1] == Xblank)
2756 cave[x][y-1] = Xsplash_w;
2757 play_element_sound(x, y, SOUND_acid, Xacid_1);
2763 switch (cave[x-1][y])
2779 cave[x][y] = Yalien_wB;
2780 next[x][y] = Xblank;
2781 cave[x-1][y] = Yalien_w;
2782 next[x-1][y] = Xalien_pause;
2783 play_element_sound(x, y, SOUND_alien, Xalien);
2794 cave[x][y] = Yalien_wB;
2795 next[x][y] = Xblank;
2796 if (cave[x][y-1] == Xblank)
2797 cave[x][y-1] = Xsplash_e;
2798 if (cave[x-2][y-1] == Xblank)
2799 cave[x-2][y-1] = Xsplash_w;
2800 play_element_sound(x, y, SOUND_acid, Xacid_1);
2807 static void Lalien_pause(int x, int y)
2809 next[x][y] = Xalien;
2812 static void Lbug_n(int x, int y)
2814 switch (cave[x][y-1])
2830 cave[x][y] = Ybug_nB;
2831 next[x][y] = Xblank;
2832 cave[x][y-1] = Ybug_n;
2833 next[x][y-1] = Xbug_1_n;
2834 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2845 cave[x][y] = Ybug_nB;
2846 next[x][y] = Xblank;
2847 if (cave[x+1][y-2] == Xblank)
2848 cave[x+1][y-2] = Xsplash_e;
2849 if (cave[x-1][y-2] == Xblank)
2850 cave[x-1][y-2] = Xsplash_w;
2851 play_element_sound(x, y, SOUND_acid, Xacid_1);
2855 cave[x][y] = Ybug_n_w;
2856 next[x][y] = Xbug_2_w;
2857 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2862 static void Lbug_1_n(int x, int y)
2864 if (is_amoeba[cave[x][y-1]] ||
2865 is_amoeba[cave[x+1][y]] ||
2866 is_amoeba[cave[x][y+1]] ||
2867 is_amoeba[cave[x-1][y]])
2875 switch (cave[x+1][y])
2899 cave[x][y] = Ybug_n_e;
2900 next[x][y] = Xbug_2_e;
2901 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2910 static void Lbug_2_n(int x, int y)
2912 if (is_amoeba[cave[x][y-1]] ||
2913 is_amoeba[cave[x+1][y]] ||
2914 is_amoeba[cave[x][y+1]] ||
2915 is_amoeba[cave[x-1][y]])
2926 static void Lbug_e(int x, int y)
2928 switch (cave[x+1][y])
2944 cave[x][y] = Ybug_eB;
2945 next[x][y] = Xblank;
2946 cave[x+1][y] = Ybug_e;
2947 next[x+1][y] = Xbug_1_e;
2948 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2959 cave[x][y] = Ybug_eB;
2960 next[x][y] = Xblank;
2961 if (cave[x+2][y-1] == Xblank)
2962 cave[x+2][y-1] = Xsplash_e;
2963 if (cave[x][y-1] == Xblank)
2964 cave[x][y-1] = Xsplash_w;
2965 play_element_sound(x, y, SOUND_acid, Xacid_1);
2969 cave[x][y] = Ybug_e_n;
2970 next[x][y] = Xbug_2_n;
2971 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2976 static void Lbug_1_e(int x, int y)
2978 if (is_amoeba[cave[x][y-1]] ||
2979 is_amoeba[cave[x+1][y]] ||
2980 is_amoeba[cave[x][y+1]] ||
2981 is_amoeba[cave[x-1][y]])
2989 switch (cave[x][y+1])
3013 cave[x][y] = Ybug_e_s;
3014 next[x][y] = Xbug_2_s;
3015 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
3024 static void Lbug_2_e(int x, int y)
3026 if (is_amoeba[cave[x][y-1]] ||
3027 is_amoeba[cave[x+1][y]] ||
3028 is_amoeba[cave[x][y+1]] ||
3029 is_amoeba[cave[x-1][y]])
3040 static void Lbug_s(int x, int y)
3042 switch (cave[x][y+1])
3058 cave[x][y] = Ybug_sB;
3059 next[x][y] = Xblank;
3060 cave[x][y+1] = Ybug_s;
3061 next[x][y+1] = Xbug_1_s;
3062 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3073 cave[x][y] = Ybug_sB;
3074 next[x][y] = Xblank;
3075 if (cave[x+1][y] == Xblank)
3076 cave[x+1][y] = Xsplash_e;
3077 if (cave[x-1][y] == Xblank)
3078 cave[x-1][y] = Xsplash_w;
3079 play_element_sound(x, y, SOUND_acid, Xacid_1);
3083 cave[x][y] = Ybug_s_e;
3084 next[x][y] = Xbug_2_e;
3085 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3090 static void Lbug_1_s(int x, int y)
3092 if (is_amoeba[cave[x][y-1]] ||
3093 is_amoeba[cave[x+1][y]] ||
3094 is_amoeba[cave[x][y+1]] ||
3095 is_amoeba[cave[x-1][y]])
3103 switch (cave[x-1][y])
3127 cave[x][y] = Ybug_s_w;
3128 next[x][y] = Xbug_2_w;
3129 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3138 static void Lbug_2_s(int x, int y)
3140 if (is_amoeba[cave[x][y-1]] ||
3141 is_amoeba[cave[x+1][y]] ||
3142 is_amoeba[cave[x][y+1]] ||
3143 is_amoeba[cave[x-1][y]])
3154 static void Lbug_w(int x, int y)
3156 switch (cave[x-1][y])
3172 cave[x][y] = Ybug_wB;
3173 next[x][y] = Xblank;
3174 cave[x-1][y] = Ybug_w;
3175 next[x-1][y] = Xbug_1_w;
3176 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3187 cave[x][y] = Ybug_wB;
3188 next[x][y] = Xblank;
3189 if (cave[x][y-1] == Xblank)
3190 cave[x][y-1] = Xsplash_e;
3191 if (cave[x-2][y-1] == Xblank)
3192 cave[x-2][y-1] = Xsplash_w;
3193 play_element_sound(x, y, SOUND_acid, Xacid_1);
3197 cave[x][y] = Ybug_w_s;
3198 next[x][y] = Xbug_2_s;
3199 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3204 static void Lbug_1_w(int x, int y)
3206 if (is_amoeba[cave[x][y-1]] ||
3207 is_amoeba[cave[x+1][y]] ||
3208 is_amoeba[cave[x][y+1]] ||
3209 is_amoeba[cave[x-1][y]])
3217 switch (cave[x][y-1])
3241 cave[x][y] = Ybug_w_n;
3242 next[x][y] = Xbug_2_n;
3243 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3252 static void Lbug_2_w(int x, int y)
3254 if (is_amoeba[cave[x][y-1]] ||
3255 is_amoeba[cave[x+1][y]] ||
3256 is_amoeba[cave[x][y+1]] ||
3257 is_amoeba[cave[x-1][y]])
3268 static void Ltank_n(int x, int y)
3270 switch (cave[x][y-1])
3286 cave[x][y] = Ytank_nB;
3287 next[x][y] = Xblank;
3288 cave[x][y-1] = Ytank_n;
3289 next[x][y-1] = Xtank_1_n;
3290 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3301 cave[x][y] = Ytank_nB;
3302 next[x][y] = Xblank;
3303 if (cave[x+1][y-2] == Xblank)
3304 cave[x+1][y-2] = Xsplash_e;
3305 if (cave[x-1][y-2] == Xblank)
3306 cave[x-1][y-2] = Xsplash_w;
3307 play_element_sound(x, y, SOUND_acid, Xacid_1);
3311 cave[x][y] = Ytank_n_e;
3312 next[x][y] = Xtank_2_e;
3313 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3318 static void Ltank_1_n(int x, int y)
3320 if (is_amoeba[cave[x][y-1]] ||
3321 is_amoeba[cave[x+1][y]] ||
3322 is_amoeba[cave[x][y+1]] ||
3323 is_amoeba[cave[x-1][y]])
3331 switch (cave[x-1][y])
3355 cave[x][y] = Ytank_n_w;
3356 next[x][y] = Xtank_2_w;
3357 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3366 static void Ltank_2_n(int x, int y)
3368 if (is_amoeba[cave[x][y-1]] ||
3369 is_amoeba[cave[x+1][y]] ||
3370 is_amoeba[cave[x][y+1]] ||
3371 is_amoeba[cave[x-1][y]])
3382 static void Ltank_e(int x, int y)
3384 switch (cave[x+1][y])
3400 cave[x][y] = Ytank_eB;
3401 next[x][y] = Xblank;
3402 cave[x+1][y] = Ytank_e;
3403 next[x+1][y] = Xtank_1_e;
3404 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3415 cave[x][y] = Ytank_eB;
3416 next[x][y] = Xblank;
3417 if (cave[x+2][y-1] == Xblank)
3418 cave[x+2][y-1] = Xsplash_e;
3419 if (cave[x][y-1] == Xblank)
3420 cave[x][y-1] = Xsplash_w;
3421 play_element_sound(x, y, SOUND_acid, Xacid_1);
3425 cave[x][y] = Ytank_e_s;
3426 next[x][y] = Xtank_2_s;
3427 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3432 static void Ltank_1_e(int x, int y)
3434 if (is_amoeba[cave[x][y-1]] ||
3435 is_amoeba[cave[x+1][y]] ||
3436 is_amoeba[cave[x][y+1]] ||
3437 is_amoeba[cave[x-1][y]])
3445 switch (cave[x][y-1])
3469 cave[x][y] = Ytank_e_n;
3470 next[x][y] = Xtank_2_n;
3471 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3480 static void Ltank_2_e(int x, int y)
3482 if (is_amoeba[cave[x][y-1]] ||
3483 is_amoeba[cave[x+1][y]] ||
3484 is_amoeba[cave[x][y+1]] ||
3485 is_amoeba[cave[x-1][y]])
3496 static void Ltank_s(int x, int y)
3498 switch (cave[x][y+1])
3514 cave[x][y] = Ytank_sB;
3515 next[x][y] = Xblank;
3516 cave[x][y+1] = Ytank_s;
3517 next[x][y+1] = Xtank_1_s;
3518 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3529 cave[x][y] = Ytank_sB;
3530 next[x][y] = Xblank;
3531 if (cave[x+1][y] == Xblank)
3532 cave[x+1][y] = Xsplash_e;
3533 if (cave[x-1][y] == Xblank)
3534 cave[x-1][y] = Xsplash_w;
3535 play_element_sound(x, y, SOUND_acid, Xacid_1);
3539 cave[x][y] = Ytank_s_w;
3540 next[x][y] = Xtank_2_w;
3541 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3546 static void Ltank_1_s(int x, int y)
3548 if (is_amoeba[cave[x][y-1]] ||
3549 is_amoeba[cave[x+1][y]] ||
3550 is_amoeba[cave[x][y+1]] ||
3551 is_amoeba[cave[x-1][y]])
3559 switch (cave[x+1][y])
3583 cave[x][y] = Ytank_s_e;
3584 next[x][y] = Xtank_2_e;
3585 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3594 static void Ltank_2_s(int x, int y)
3596 if (is_amoeba[cave[x][y-1]] ||
3597 is_amoeba[cave[x+1][y]] ||
3598 is_amoeba[cave[x][y+1]] ||
3599 is_amoeba[cave[x-1][y]])
3610 static void Ltank_w(int x, int y)
3612 switch (cave[x-1][y])
3628 cave[x][y] = Ytank_wB;
3629 next[x][y] = Xblank;
3630 cave[x-1][y] = Ytank_w;
3631 next[x-1][y] = Xtank_1_w;
3632 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3643 cave[x][y] = Ytank_wB;
3644 next[x][y] = Xblank;
3645 if (cave[x][y-1] == Xblank)
3646 cave[x][y-1] = Xsplash_e;
3647 if (cave[x-2][y-1] == Xblank)
3648 cave[x-2][y-1] = Xsplash_w;
3649 play_element_sound(x, y, SOUND_acid, Xacid_1);
3653 cave[x][y] = Ytank_w_n;
3654 next[x][y] = Xtank_2_n;
3655 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3660 static void Ltank_1_w(int x, int y)
3662 if (is_amoeba[cave[x][y-1]] ||
3663 is_amoeba[cave[x+1][y]] ||
3664 is_amoeba[cave[x][y+1]] ||
3665 is_amoeba[cave[x-1][y]])
3673 switch (cave[x][y+1])
3697 cave[x][y] = Ytank_w_s;
3698 next[x][y] = Xtank_2_s;
3699 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3708 static void Ltank_2_w(int x, int y)
3710 if (is_amoeba[cave[x][y-1]] ||
3711 is_amoeba[cave[x+1][y]] ||
3712 is_amoeba[cave[x][y+1]] ||
3713 is_amoeba[cave[x-1][y]])
3724 static void Lemerald(int x, int y)
3726 switch (cave[x][y+1])
3739 cave[x][y] = Yemerald_sB;
3740 next[x][y] = Xblank;
3741 cave[x][y+1] = Yemerald_s;
3742 next[x][y+1] = Xemerald_fall;
3753 cave[x][y] = Yemerald_sB;
3754 next[x][y] = Xblank;
3755 if (cave[x+1][y] == Xblank)
3756 cave[x+1][y] = Xsplash_e;
3757 if (cave[x-1][y] == Xblank)
3758 cave[x-1][y] = Xsplash_w;
3759 play_element_sound(x, y, SOUND_acid, Xacid_1);
3772 case Xemerald_pause:
3774 case Xdiamond_pause:
3818 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3820 cave[x][y] = Yemerald_eB;
3821 next[x][y] = Xblank;
3822 cave[x+1][y] = Yemerald_e;
3823 next[x+1][y] = Xemerald_pause;
3824 if (cave[x][y+1] == Xbumper)
3825 cave[x][y+1] = Ybumper;
3829 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3831 cave[x][y] = Yemerald_wB;
3832 next[x][y] = Xblank;
3833 cave[x-1][y] = Yemerald_w;
3834 next[x-1][y] = Xemerald_pause;
3835 if (cave[x][y+1] == Xbumper)
3836 cave[x][y+1] = Ybumper;
3842 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3844 cave[x][y] = Yemerald_wB;
3845 next[x][y] = Xblank;
3846 cave[x-1][y] = Yemerald_w;
3847 next[x-1][y] = Xemerald_pause;
3848 if (cave[x][y+1] == Xbumper)
3849 cave[x][y+1] = Ybumper;
3853 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3855 cave[x][y] = Yemerald_eB;
3856 next[x][y] = Xblank;
3857 cave[x+1][y] = Yemerald_e;
3858 next[x+1][y] = Xemerald_pause;
3859 if (cave[x][y+1] == Xbumper)
3860 cave[x][y+1] = Ybumper;
3866 if (++lev.shine_cnt > 50)
3868 lev.shine_cnt = RANDOM(8);
3869 cave[x][y] = Xemerald_shine;
3876 static void Lemerald_pause(int x, int y)
3878 switch (cave[x][y+1])
3891 cave[x][y] = Yemerald_sB;
3892 next[x][y] = Xblank;
3893 cave[x][y+1] = Yemerald_s;
3894 next[x][y+1] = Xemerald_fall;
3905 cave[x][y] = Yemerald_sB;
3906 next[x][y] = Xblank;
3907 if (cave[x+1][y] == Xblank)
3908 cave[x+1][y] = Xsplash_e;
3909 if (cave[x-1][y] == Xblank)
3910 cave[x-1][y] = Xsplash_w;
3911 play_element_sound(x, y, SOUND_acid, Xacid_1);
3915 cave[x][y] = Xemerald;
3916 next[x][y] = Xemerald;
3921 static void Lemerald_fall(int x, int y)
3923 switch (cave[x][y+1])
3937 cave[x][y] = Yemerald_sB;
3938 next[x][y] = Xblank;
3939 cave[x][y+1] = Yemerald_s;
3940 next[x][y+1] = Xemerald_fall;
3951 cave[x][y] = Yemerald_sB;
3952 next[x][y] = Xblank;
3953 if (cave[x+1][y] == Xblank)
3954 cave[x+1][y] = Xsplash_e;
3955 if (cave[x-1][y] == Xblank)
3956 cave[x-1][y] = Xsplash_w;
3957 play_element_sound(x, y, SOUND_acid, Xacid_1);
3961 if (lev.wonderwall_time > 0)
3963 lev.wonderwall_active = TRUE;
3964 cave[x][y] = Yemerald_sB;
3965 next[x][y] = Xblank;
3966 if (is_blank[cave[x][y+2]])
3968 cave[x][y+2] = Ydiamond_s;
3969 next[x][y+2] = Xdiamond_fall;
3971 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
3976 cave[x][y] = Xemerald;
3977 next[x][y] = Xemerald;
3978 play_element_sound(x, y, SOUND_diamond, Xemerald);
3983 static void Ldiamond(int x, int y)
3985 switch (cave[x][y+1])
3998 cave[x][y] = Ydiamond_sB;
3999 next[x][y] = Xblank;
4000 cave[x][y+1] = Ydiamond_s;
4001 next[x][y+1] = Xdiamond_fall;
4012 cave[x][y] = Ydiamond_sB;
4013 next[x][y] = Xblank;
4014 if (cave[x+1][y] == Xblank)
4015 cave[x+1][y] = Xsplash_e;
4016 if (cave[x-1][y] == Xblank)
4017 cave[x-1][y] = Xsplash_w;
4018 play_element_sound(x, y, SOUND_acid, Xacid_1);
4031 case Xemerald_pause:
4033 case Xdiamond_pause:
4077 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4079 cave[x][y] = Ydiamond_eB;
4080 next[x][y] = Xblank;
4081 cave[x+1][y] = Ydiamond_e;
4082 next[x+1][y] = Xdiamond_pause;
4083 if (cave[x][y+1] == Xbumper)
4084 cave[x][y+1] = Ybumper;
4088 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4090 cave[x][y] = Ydiamond_wB;
4091 next[x][y] = Xblank;
4092 cave[x-1][y] = Ydiamond_w;
4093 next[x-1][y] = Xdiamond_pause;
4094 if (cave[x][y+1] == Xbumper)
4095 cave[x][y+1] = Ybumper;
4101 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4103 cave[x][y] = Ydiamond_wB;
4104 next[x][y] = Xblank;
4105 cave[x-1][y] = Ydiamond_w;
4106 next[x-1][y] = Xdiamond_pause;
4107 if (cave[x][y+1] == Xbumper)
4108 cave[x][y+1] = Ybumper;
4112 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4114 cave[x][y] = Ydiamond_eB;
4115 next[x][y] = Xblank;
4116 cave[x+1][y] = Ydiamond_e;
4117 next[x+1][y] = Xdiamond_pause;
4118 if (cave[x][y+1] == Xbumper)
4119 cave[x][y+1] = Ybumper;
4125 if (++lev.shine_cnt > 50)
4127 lev.shine_cnt = RANDOM(8);
4128 cave[x][y] = Xdiamond_shine;
4135 static void Ldiamond_pause(int x, int y)
4137 switch (cave[x][y+1])
4150 cave[x][y] = Ydiamond_sB;
4151 next[x][y] = Xblank;
4152 cave[x][y+1] = Ydiamond_s;
4153 next[x][y+1] = Xdiamond_fall;
4164 cave[x][y] = Ydiamond_sB;
4165 next[x][y] = Xblank;
4166 if (cave[x+1][y] == Xblank)
4167 cave[x+1][y] = Xsplash_e;
4168 if (cave[x-1][y] == Xblank)
4169 cave[x-1][y] = Xsplash_w;
4170 play_element_sound(x, y, SOUND_acid, Xacid_1);
4174 cave[x][y] = Xdiamond;
4175 next[x][y] = Xdiamond;
4180 static void Ldiamond_fall(int x, int y)
4182 switch (cave[x][y+1])
4196 cave[x][y] = Ydiamond_sB;
4197 next[x][y] = Xblank;
4198 cave[x][y+1] = Ydiamond_s;
4199 next[x][y+1] = Xdiamond_fall;
4210 cave[x][y] = Ydiamond_sB;
4211 next[x][y] = Xblank;
4212 if (cave[x+1][y] == Xblank)
4213 cave[x+1][y] = Xsplash_e;
4214 if (cave[x-1][y] == Xblank)
4215 cave[x-1][y] = Xsplash_w;
4216 play_element_sound(x, y, SOUND_acid, Xacid_1);
4220 if (lev.wonderwall_time > 0)
4222 lev.wonderwall_active = TRUE;
4223 cave[x][y] = Ydiamond_sB;
4224 next[x][y] = Xblank;
4225 if (is_blank[cave[x][y+2]])
4227 cave[x][y+2] = Ystone_s;
4228 next[x][y+2] = Xstone_fall;
4230 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4235 cave[x][y] = Xdiamond;
4236 next[x][y] = Xdiamond;
4237 play_element_sound(x, y, SOUND_diamond, Xdiamond);
4242 static void Lstone(int x, int y)
4244 switch (cave[x][y+1])
4259 cave[x][y] = Ystone_sB;
4260 next[x][y] = Xblank;
4261 cave[x][y+1] = Ystone_s;
4262 next[x][y+1] = Xstone_fall;
4273 cave[x][y] = Ystone_sB;
4274 next[x][y] = Xblank;
4275 if (cave[x+1][y] == Xblank)
4276 cave[x+1][y] = Xsplash_e;
4277 if (cave[x-1][y] == Xblank)
4278 cave[x-1][y] = Xsplash_w;
4279 play_element_sound(x, y, SOUND_acid, Xacid_1);
4283 cave[x][y] = Xsand_stonein_1;
4284 next[x][y] = Xsand_stonein_2;
4285 cave[x][y+1] = Xsand_sandstone_1;
4286 next[x][y+1] = Xsand_sandstone_2;
4299 case Xemerald_pause:
4301 case Xdiamond_pause:
4338 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4340 cave[x][y] = Ystone_eB;
4341 next[x][y] = Xblank;
4342 cave[x+1][y] = Ystone_e;
4343 next[x+1][y] = Xstone_pause;
4344 if (cave[x][y+1] == Xbumper)
4345 cave[x][y+1] = Ybumper;
4349 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4351 cave[x][y] = Ystone_wB;
4352 next[x][y] = Xblank;
4353 cave[x-1][y] = Ystone_w;
4354 next[x-1][y] = Xstone_pause;
4355 if (cave[x][y+1] == Xbumper)
4356 cave[x][y+1] = Ybumper;
4362 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4364 cave[x][y] = Ystone_wB;
4365 next[x][y] = Xblank;
4366 cave[x-1][y] = Ystone_w;
4367 next[x-1][y] = Xstone_pause;
4368 if (cave[x][y+1] == Xbumper)
4369 cave[x][y+1] = Ybumper;
4373 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4375 cave[x][y] = Ystone_eB;
4376 next[x][y] = Xblank;
4377 cave[x+1][y] = Ystone_e;
4378 next[x+1][y] = Xstone_pause;
4379 if (cave[x][y+1] == Xbumper)
4380 cave[x][y+1] = Ybumper;
4387 static void Lstone_pause(int x, int y)
4389 switch (cave[x][y+1])
4402 cave[x][y] = Ystone_sB;
4403 next[x][y] = Xblank;
4404 cave[x][y+1] = Ystone_s;
4405 next[x][y+1] = Xstone_fall;
4416 cave[x][y] = Ystone_sB;
4417 next[x][y] = Xblank;
4418 if (cave[x+1][y] == Xblank)
4419 cave[x+1][y] = Xsplash_e;
4420 if (cave[x-1][y] == Xblank)
4421 cave[x-1][y] = Xsplash_w;
4422 play_element_sound(x, y, SOUND_acid, Xacid_1);
4426 cave[x][y] = Xstone;
4427 next[x][y] = Xstone;
4432 static void Lstone_fall(int x, int y)
4434 switch (cave[x][y+1])
4448 cave[x][y] = Ystone_sB;
4449 next[x][y] = Xblank;
4450 cave[x][y+1] = Ystone_s;
4451 next[x][y+1] = Xstone_fall;
4462 cave[x][y] = Ystone_sB;
4463 next[x][y] = Xblank;
4464 if (cave[x+1][y] == Xblank)
4465 cave[x+1][y] = Xsplash_e;
4466 if (cave[x-1][y] == Xblank)
4467 cave[x-1][y] = Xsplash_w;
4468 play_element_sound(x, y, SOUND_acid, Xacid_1);
4475 cave[x][y] = Ystone_sB;
4476 next[x][y] = Xblank;
4477 cave[x][y+1] = Yeater_stone;
4478 next[x][y+1] = Zeater;
4479 Lboom_eater_old(x, y+1);
4480 score += lev.eater_score;
4485 cave[x][y] = Ystone_sB;
4486 next[x][y] = Xblank;
4487 cave[x][y+1] = Yalien_stone;
4488 next[x][y+1] = Ztank;
4489 Lboom_tank_old(x, y+1);
4490 score += lev.alien_score;
4501 cave[x][y] = Ystone_sB;
4502 next[x][y] = Xblank;
4503 cave[x][y+1] = Ybug_stone;
4504 next[x][y+1] = Zbug;
4505 Lboom_bug_old(x, y+1);
4506 score += lev.bug_score;
4517 cave[x][y] = Ystone_sB;
4518 next[x][y] = Xblank;
4519 cave[x][y+1] = Ytank_stone;
4520 next[x][y+1] = Ztank;
4521 Lboom_tank_old(x, y+1);
4522 score += lev.tank_score;
4526 case Xdiamond_pause:
4527 switch (cave[x][y+2])
4583 next[x][y] = Xstone;
4584 play_element_sound(x, y, SOUND_stone, Xstone);
4588 cave[x][y] = Ystone_sB;
4589 next[x][y] = Xblank;
4590 cave[x][y+1] = Ydiamond_stone;
4591 next[x][y+1] = Xstone_pause;
4592 play_element_sound(x, y, SOUND_squash, Xdiamond);
4597 cave[x][y] = Xstone;
4598 next[x][y] = Xstone;
4599 cave[x][y+1] = Ybomb_blank;
4600 next[x][y+1] = Ztank;
4601 Lboom_tank_old(x, y+1);
4606 next[x][y] = Xstone;
4607 cave[x][y+1] = Ynut_stone;
4608 next[x][y+1] = Xemerald;
4609 play_element_sound(x, y, SOUND_crack, Xnut);
4610 score += lev.nut_score;
4616 switch (cave[x+1][y+1])
4631 cave[x][y+1] = Xspring_e;
4635 cave[x][y+1] = Xspring_w;
4641 switch (cave[x-1][y+1])
4656 cave[x][y+1] = Xspring_w;
4659 cave[x][y+1] = Xspring_e;
4664 next[x][y] = Xstone;
4668 if (lev.wonderwall_time > 0)
4670 lev.wonderwall_active = TRUE;
4671 cave[x][y] = Ystone_sB;
4672 next[x][y] = Xblank;
4673 if (is_blank[cave[x][y+2]])
4675 cave[x][y+2] = Yemerald_s;
4676 next[x][y+2] = Xemerald_fall;
4678 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4683 cave[x][y] = Xstone;
4684 next[x][y] = Xstone;
4685 play_element_sound(x, y, SOUND_stone, Xstone);
4690 static void Lbomb(int x, int y)
4692 switch (cave[x][y+1])
4705 cave[x][y] = Ybomb_sB;
4706 next[x][y] = Xblank;
4707 cave[x][y+1] = Ybomb_s;
4708 next[x][y+1] = Xbomb_fall;
4719 cave[x][y] = Ybomb_sB;
4720 next[x][y] = Xblank;
4721 if (cave[x+1][y] == Xblank)
4722 cave[x+1][y] = Xsplash_e;
4723 if (cave[x-1][y] == Xblank)
4724 cave[x-1][y] = Xsplash_w;
4725 play_element_sound(x, y, SOUND_acid, Xacid_1);
4738 case Xemerald_pause:
4740 case Xdiamond_pause:
4775 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4777 cave[x][y] = Ybomb_eB;
4778 next[x][y] = Xblank;
4779 cave[x+1][y] = Ybomb_e;
4780 next[x+1][y] = Xbomb_pause;
4781 if (cave[x][y+1] == Xbumper)
4782 cave[x][y+1] = Ybumper;
4786 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4788 cave[x][y] = Ybomb_wB;
4789 next[x][y] = Xblank;
4790 cave[x-1][y] = Ybomb_w;
4791 next[x-1][y] = Xbomb_pause;
4792 if (cave[x][y+1] == Xbumper)
4793 cave[x][y+1] = Ybumper;
4799 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4801 cave[x][y] = Ybomb_wB;
4802 next[x][y] = Xblank;
4803 cave[x-1][y] = Ybomb_w;
4804 next[x-1][y] = Xbomb_pause;
4805 if (cave[x][y+1] == Xbumper)
4806 cave[x][y+1] = Ybumper;
4810 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4812 cave[x][y] = Ybomb_eB;
4813 next[x][y] = Xblank;
4814 cave[x+1][y] = Ybomb_e;
4815 next[x+1][y] = Xbomb_pause;
4816 if (cave[x][y+1] == Xbumper)
4817 cave[x][y+1] = Ybumper;
4824 static void Lbomb_pause(int x, int y)
4826 switch (cave[x][y+1])
4839 cave[x][y] = Ybomb_sB;
4840 next[x][y] = Xblank;
4841 cave[x][y+1] = Ybomb_s;
4842 next[x][y+1] = Xbomb_fall;
4853 cave[x][y] = Ybomb_sB;
4854 next[x][y] = Xblank;
4855 if (cave[x+1][y] == Xblank)
4856 cave[x+1][y] = Xsplash_e;
4857 if (cave[x-1][y] == Xblank)
4858 cave[x-1][y] = Xsplash_w;
4859 play_element_sound(x, y, SOUND_acid, Xacid_1);
4869 static void Lbomb_fall(int x, int y)
4871 switch (cave[x][y+1])
4884 cave[x][y] = Ybomb_sB;
4885 next[x][y] = Xblank;
4886 cave[x][y+1] = Ybomb_s;
4887 next[x][y+1] = Xbomb_fall;
4898 cave[x][y] = Ybomb_sB;
4899 next[x][y] = Xblank;
4900 if (cave[x+1][y] == Xblank)
4901 cave[x+1][y] = Xsplash_e;
4902 if (cave[x-1][y] == Xblank)
4903 cave[x-1][y] = Xsplash_w;
4904 play_element_sound(x, y, SOUND_acid, Xacid_1);
4908 cave[x][y] = Ybomb_blank;
4910 Lboom_tank_old(x, y);
4915 static void Lnut(int x, int y)
4917 switch (cave[x][y+1])
4930 cave[x][y] = Ynut_sB;
4931 next[x][y] = Xblank;
4932 cave[x][y+1] = Ynut_s;
4933 next[x][y+1] = Xnut_fall;
4944 cave[x][y] = Ynut_sB;
4945 next[x][y] = Xblank;
4946 if (cave[x+1][y] == Xblank)
4947 cave[x+1][y] = Xsplash_e;
4948 if (cave[x-1][y] == Xblank)
4949 cave[x-1][y] = Xsplash_w;
4950 play_element_sound(x, y, SOUND_acid, Xacid_1);
4963 case Xemerald_pause:
4965 case Xdiamond_pause:
5000 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5002 cave[x][y] = Ynut_eB;
5003 next[x][y] = Xblank;
5004 cave[x+1][y] = Ynut_e;
5005 next[x+1][y] = Xnut_pause;
5006 if (cave[x][y+1] == Xbumper)
5007 cave[x][y+1] = Ybumper;
5011 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5013 cave[x][y] = Ynut_wB;
5014 next[x][y] = Xblank;
5015 cave[x-1][y] = Ynut_w;
5016 next[x-1][y] = Xnut_pause;
5017 if (cave[x][y+1] == Xbumper)
5018 cave[x][y+1] = Ybumper;
5024 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5026 cave[x][y] = Ynut_wB;
5027 next[x][y] = Xblank;
5028 cave[x-1][y] = Ynut_w;
5029 next[x-1][y] = Xnut_pause;
5030 if (cave[x][y+1] == Xbumper)
5031 cave[x][y+1] = Ybumper;
5035 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5037 cave[x][y] = Ynut_eB;
5038 next[x][y] = Xblank;
5039 cave[x+1][y] = Ynut_e;
5040 next[x+1][y] = Xnut_pause;
5041 if (cave[x][y+1] == Xbumper)
5042 cave[x][y+1] = Ybumper;
5049 static void Lnut_pause(int x, int y)
5051 switch (cave[x][y+1])
5064 cave[x][y] = Ynut_sB;
5065 next[x][y] = Xblank;
5066 cave[x][y+1] = Ynut_s;
5067 next[x][y+1] = Xnut_fall;
5078 cave[x][y] = Ynut_sB;
5079 next[x][y] = Xblank;
5080 if (cave[x+1][y] == Xblank)
5081 cave[x+1][y] = Xsplash_e;
5082 if (cave[x-1][y] == Xblank)
5083 cave[x-1][y] = Xsplash_w;
5084 play_element_sound(x, y, SOUND_acid, Xacid_1);
5094 static void Lnut_fall(int x, int y)
5096 switch (cave[x][y+1])
5110 cave[x][y] = Ynut_sB;
5111 next[x][y] = Xblank;
5112 cave[x][y+1] = Ynut_s;
5113 next[x][y+1] = Xnut_fall;
5124 cave[x][y] = Ynut_sB;
5125 next[x][y] = Xblank;
5126 if (cave[x+1][y] == Xblank)
5127 cave[x+1][y] = Xsplash_e;
5128 if (cave[x-1][y] == Xblank)
5129 cave[x-1][y] = Xsplash_w;
5130 play_element_sound(x, y, SOUND_acid, Xacid_1);
5136 play_element_sound(x, y, SOUND_nut, Xnut);
5141 static void Lspring(int x, int y)
5143 switch (cave[x][y+1])
5158 cave[x][y] = Yspring_sB;
5159 next[x][y] = Xblank;
5160 cave[x][y+1] = Yspring_s;
5161 next[x][y+1] = Xspring_fall;
5172 cave[x][y] = Yspring_sB;
5173 next[x][y] = Xblank;
5174 if (cave[x+1][y] == Xblank)
5175 cave[x+1][y] = Xsplash_e;
5176 if (cave[x-1][y] == Xblank)
5177 cave[x-1][y] = Xsplash_w;
5178 play_element_sound(x, y, SOUND_acid, Xacid_1);
5191 case Xemerald_pause:
5193 case Xdiamond_pause:
5228 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5230 cave[x][y] = Yspring_eB;
5231 next[x][y] = Xblank;
5232 cave[x+1][y] = Yspring_e;
5234 next[x+1][y] = Xspring_e;
5236 next[x+1][y] = Xspring_pause;
5238 if (cave[x][y+1] == Xbumper)
5239 cave[x][y+1] = Ybumper;
5243 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5245 cave[x][y] = Yspring_wB;
5246 next[x][y] = Xblank;
5247 cave[x-1][y] = Yspring_w;
5249 next[x-1][y] = Xspring_w;
5251 next[x-1][y] = Xspring_pause;
5253 if (cave[x][y+1] == Xbumper)
5254 cave[x][y+1] = Ybumper;
5260 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5262 cave[x][y] = Yspring_wB;
5263 next[x][y] = Xblank;
5264 cave[x-1][y] = Yspring_w;
5266 next[x-1][y] = Xspring_w;
5268 next[x-1][y] = Xspring_pause;
5270 if (cave[x][y+1] == Xbumper)
5271 cave[x][y+1] = Ybumper;
5275 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5277 cave[x][y] = Yspring_eB;
5278 next[x][y] = Xblank;
5279 cave[x+1][y] = Yspring_e;
5281 next[x+1][y] = Xspring_e;
5283 next[x+1][y] = Xspring_pause;
5285 if (cave[x][y+1] == Xbumper)
5286 cave[x][y+1] = Ybumper;
5293 static void Lspring_pause(int x, int y)
5295 switch (cave[x][y+1])
5308 cave[x][y] = Yspring_sB;
5309 next[x][y] = Xblank;
5310 cave[x][y+1] = Yspring_s;
5311 next[x][y+1] = Xspring_fall;
5322 cave[x][y] = Yspring_sB;
5323 next[x][y] = Xblank;
5324 if (cave[x+1][y] == Xblank)
5325 cave[x+1][y] = Xsplash_e;
5326 if (cave[x-1][y] == Xblank)
5327 cave[x-1][y] = Xsplash_w;
5328 play_element_sound(x, y, SOUND_acid, Xacid_1);
5332 cave[x][y] = Xspring;
5333 next[x][y] = Xspring;
5338 static void Lspring_e(int x, int y)
5340 switch (cave[x][y+1])
5353 cave[x][y] = Yspring_sB;
5354 next[x][y] = Xblank;
5355 cave[x][y+1] = Yspring_s;
5356 next[x][y+1] = Xspring_fall;
5367 cave[x][y] = Yspring_sB;
5368 next[x][y] = Xblank;
5369 if (cave[x+1][y] == Xblank)
5370 cave[x+1][y] = Xsplash_e;
5371 if (cave[x-1][y] == Xblank)
5372 cave[x-1][y] = Xsplash_w;
5373 play_element_sound(x, y, SOUND_acid, Xacid_1);
5377 cave[x][y+1] = Ybumper;
5380 switch (cave[x+1][y])
5397 cave[x][y] = Yspring_eB;
5398 next[x][y] = Xblank;
5399 cave[x+1][y] = Yspring_e;
5400 next[x+1][y] = Xspring_e;
5411 cave[x][y] = Yspring_eB;
5412 next[x][y] = Xblank;
5413 if (cave[x+2][y-1] == Xblank)
5414 cave[x+2][y-1] = Xsplash_e;
5415 if (cave[x][y-1] == Xblank)
5416 cave[x][y-1] = Xsplash_w;
5417 play_element_sound(x, y, SOUND_acid, Xacid_1);
5426 cave[x][y] = Yspring_alien_eB;
5427 next[x][y] = Xblank;
5428 cave[x+1][y] = Yspring_alien_e;
5429 next[x+1][y] = Xspring_e;
5430 play_element_sound(x, y, SOUND_slurp, Xalien);
5431 score += lev.slurp_score;
5436 cave[x+1][y] = Ybumper;
5437 next[x][y] = Xspring_w;
5438 play_element_sound(x, y, SOUND_spring, Xspring);
5442 cave[x][y] = Xspring;
5443 next[x][y] = Xspring;
5444 play_element_sound(x, y, SOUND_spring, Xspring);
5449 static void Lspring_w(int x, int y)
5451 switch (cave[x][y+1])
5464 cave[x][y] = Yspring_sB;
5465 next[x][y] = Xblank;
5466 cave[x][y+1] = Yspring_s;
5467 next[x][y+1] = Xspring_fall;
5478 cave[x][y] = Yspring_sB;
5479 next[x][y] = Xblank;
5480 if (cave[x+1][y] == Xblank)
5481 cave[x+1][y] = Xsplash_e;
5482 if (cave[x-1][y] == Xblank)
5483 cave[x-1][y] = Xsplash_w;
5484 play_element_sound(x, y, SOUND_acid, Xacid_1);
5488 cave[x][y+1] = Ybumper;
5491 switch (cave[x-1][y])
5508 cave[x][y] = Yspring_wB;
5509 next[x][y] = Xblank;
5510 cave[x-1][y] = Yspring_w;
5511 next[x-1][y] = Xspring_w;
5522 cave[x][y] = Yspring_wB;
5523 next[x][y] = Xblank;
5524 if (cave[x][y-1] == Xblank)
5525 cave[x][y-1] = Xsplash_e;
5526 if (cave[x-2][y-1] == Xblank)
5527 cave[x-2][y-1] = Xsplash_w;
5528 play_element_sound(x, y, SOUND_acid, Xacid_1);
5537 cave[x][y] = Yspring_alien_wB;
5538 next[x][y] = Xblank;
5539 cave[x-1][y] = Yspring_alien_w;
5540 next[x-1][y] = Xspring_w;
5541 play_element_sound(x, y, SOUND_slurp, Xalien);
5542 score += lev.slurp_score;
5547 cave[x-1][y] = Ybumper;
5548 next[x][y] = Xspring_e;
5549 play_element_sound(x, y, SOUND_spring, Xspring);
5553 cave[x][y] = Xspring;
5554 next[x][y] = Xspring;
5555 play_element_sound(x, y, SOUND_spring, Xspring);
5560 static void Lspring_fall(int x, int y)
5562 switch (cave[x][y+1])
5576 cave[x][y] = Yspring_sB;
5577 next[x][y] = Xblank;
5578 cave[x][y+1] = Yspring_s;
5579 next[x][y+1] = Xspring_fall;
5590 cave[x][y] = Yspring_sB;
5591 next[x][y] = Xblank;
5592 if (cave[x+1][y] == Xblank)
5593 cave[x+1][y] = Xsplash_e;
5594 if (cave[x-1][y] == Xblank)
5595 cave[x-1][y] = Xsplash_w;
5596 play_element_sound(x, y, SOUND_acid, Xacid_1);
5603 cave[x][y] = Yspring_sB;
5604 next[x][y] = Xblank;
5605 cave[x][y+1] = Yeater_spring;
5606 next[x][y+1] = Zeater;
5607 Lboom_eater_old(x, y+1);
5608 score += lev.eater_score;
5613 cave[x][y] = Yspring_sB;
5614 next[x][y] = Xblank;
5615 cave[x][y+1] = Yalien_spring;
5616 next[x][y+1] = Ztank;
5617 Lboom_tank_old(x, y+1);
5618 score += lev.alien_score;
5629 cave[x][y] = Yspring_sB;
5630 next[x][y] = Xblank;
5631 cave[x][y+1] = Ybug_spring;
5632 next[x][y+1] = Zbug;
5633 Lboom_bug_old(x, y+1);
5634 score += lev.bug_score;
5645 cave[x][y] = Yspring_sB;
5646 next[x][y] = Xblank;
5647 cave[x][y+1] = Ytank_spring;
5648 next[x][y+1] = Ztank;
5649 Lboom_tank_old(x, y+1);
5650 score += lev.tank_score;
5655 cave[x][y] = Xspring;
5656 next[x][y] = Xspring;
5657 cave[x][y+1] = Ybomb_blank;
5658 next[x][y+1] = Ztank;
5659 Lboom_tank_old(x, y+1);
5663 cave[x][y] = Xspring;
5664 next[x][y] = Xspring;
5665 play_element_sound(x, y, SOUND_spring, Xspring);
5670 static void Lpush_emerald_e(int x, int y)
5672 cave[x][y] = Yemerald_eB;
5673 next[x][y] = Xblank;
5675 switch (cave[x+1][y])
5699 if (cave[x+2][y-1] == Xblank)
5700 cave[x+2][y-1] = Xsplash_e;
5701 if (cave[x][y-1] == Xblank)
5702 cave[x][y-1] = Xsplash_w;
5703 play_element_sound(x, y, SOUND_acid, Xacid_1);
5708 cave[x+1][y] = Yemerald_e;
5709 next[x+1][y] = Xemerald_pause;
5712 static void Lpush_emerald_w(int x, int y)
5714 cave[x][y] = Yemerald_wB;
5715 next[x][y] = Xblank;
5717 switch (cave[x-1][y])
5741 if (cave[x][y-1] == Xblank)
5742 cave[x][y-1] = Xsplash_e;
5743 if (cave[x-2][y-1] == Xblank)
5744 cave[x-2][y-1] = Xsplash_w;
5745 play_element_sound(x, y, SOUND_acid, Xacid_1);
5750 cave[x-1][y] = Yemerald_w;
5751 next[x-1][y] = Xemerald_pause;
5754 static void Lpush_diamond_e(int x, int y)
5756 cave[x][y] = Ydiamond_eB;
5757 next[x][y] = Xblank;
5759 switch (cave[x+1][y])
5783 if (cave[x+2][y-1] == Xblank)
5784 cave[x+2][y-1] = Xsplash_e;
5785 if (cave[x][y-1] == Xblank)
5786 cave[x][y-1] = Xsplash_w;
5787 play_element_sound(x, y, SOUND_acid, Xacid_1);
5792 cave[x+1][y] = Ydiamond_e;
5793 next[x+1][y] = Xdiamond_pause;
5796 static void Lpush_diamond_w(int x, int y)
5798 cave[x][y] = Ydiamond_wB;
5799 next[x][y] = Xblank;
5801 switch (cave[x-1][y])
5825 if (cave[x][y-1] == Xblank)
5826 cave[x][y-1] = Xsplash_e;
5827 if (cave[x-2][y-1] == Xblank)
5828 cave[x-2][y-1] = Xsplash_w;
5829 play_element_sound(x, y, SOUND_acid, Xacid_1);
5834 cave[x-1][y] = Ydiamond_w;
5835 next[x-1][y] = Xdiamond_pause;
5838 static void Lpush_stone_e(int x, int y)
5840 cave[x][y] = Ystone_eB;
5841 next[x][y] = Xblank;
5843 switch (cave[x+1][y])
5867 if (cave[x+2][y-1] == Xblank)
5868 cave[x+2][y-1] = Xsplash_e;
5869 if (cave[x][y-1] == Xblank)
5870 cave[x][y-1] = Xsplash_w;
5871 play_element_sound(x, y, SOUND_acid, Xacid_1);
5876 cave[x+1][y] = Ystone_e;
5877 next[x+1][y] = Xstone_pause;
5880 static void Lpush_stone_w(int x, int y)
5882 cave[x][y] = Ystone_wB;
5883 next[x][y] = Xblank;
5885 switch (cave[x-1][y])
5909 if (cave[x][y-1] == Xblank)
5910 cave[x][y-1] = Xsplash_e;
5911 if (cave[x-2][y-1] == Xblank)
5912 cave[x-2][y-1] = Xsplash_w;
5913 play_element_sound(x, y, SOUND_acid, Xacid_1);
5918 cave[x-1][y] = Ystone_w;
5919 next[x-1][y] = Xstone_pause;
5922 static void Lpush_bomb_e(int x, int y)
5924 cave[x][y] = Ybomb_eB;
5925 next[x][y] = Xblank;
5927 switch (cave[x+1][y])
5951 if (cave[x+2][y-1] == Xblank)
5952 cave[x+2][y-1] = Xsplash_e;
5953 if (cave[x][y-1] == Xblank)
5954 cave[x][y-1] = Xsplash_w;
5955 play_element_sound(x, y, SOUND_acid, Xacid_1);
5960 cave[x+1][y] = Ybomb_e;
5961 next[x+1][y] = Xbomb_pause;
5964 static void Lpush_bomb_w(int x, int y)
5966 cave[x][y] = Ybomb_wB;
5967 next[x][y] = Xblank;
5969 switch (cave[x-1][y])
5993 if (cave[x][y-1] == Xblank)
5994 cave[x][y-1] = Xsplash_e;
5995 if (cave[x-2][y-1] == Xblank)
5996 cave[x-2][y-1] = Xsplash_w;
5997 play_element_sound(x, y, SOUND_acid, Xacid_1);
6002 cave[x-1][y] = Ybomb_w;
6003 next[x-1][y] = Xbomb_pause;
6006 static void Lpush_nut_e(int x, int y)
6008 cave[x][y] = Ynut_eB;
6009 next[x][y] = Xblank;
6011 switch (cave[x+1][y])
6035 if (cave[x+2][y-1] == Xblank)
6036 cave[x+2][y-1] = Xsplash_e;
6037 if (cave[x][y-1] == Xblank)
6038 cave[x][y-1] = Xsplash_w;
6039 play_element_sound(x, y, SOUND_acid, Xacid_1);
6044 cave[x+1][y] = Ynut_e;
6045 next[x+1][y] = Xnut_pause;
6048 static void Lpush_nut_w(int x, int y)
6050 cave[x][y] = Ynut_wB;
6051 next[x][y] = Xblank;
6053 switch (cave[x-1][y])
6077 if (cave[x][y-1] == Xblank)
6078 cave[x][y-1] = Xsplash_e;
6079 if (cave[x-2][y-1] == Xblank)
6080 cave[x-2][y-1] = Xsplash_w;
6081 play_element_sound(x, y, SOUND_acid, Xacid_1);
6086 cave[x-1][y] = Ynut_w;
6087 next[x-1][y] = Xnut_pause;
6090 static void Lpush_spring_e(int x, int y)
6092 cave[x][y] = Yspring_eB;
6093 next[x][y] = Xblank;
6095 switch (cave[x+1][y])
6119 if (cave[x+2][y-1] == Xblank)
6120 cave[x+2][y-1] = Xsplash_e;
6121 if (cave[x][y-1] == Xblank)
6122 cave[x][y-1] = Xsplash_w;
6123 play_element_sound(x, y, SOUND_acid, Xacid_1);
6128 cave[x+1][y] = Yspring_e;
6129 next[x+1][y] = Xspring_e;
6132 static void Lpush_spring_w(int x, int y)
6134 cave[x][y] = Yspring_wB;
6135 next[x][y] = Xblank;
6137 switch (cave[x-1][y])
6161 if (cave[x][y-1] == Xblank)
6162 cave[x][y-1] = Xsplash_e;
6163 if (cave[x-2][y-1] == Xblank)
6164 cave[x-2][y-1] = Xsplash_w;
6165 play_element_sound(x, y, SOUND_acid, Xacid_1);
6170 cave[x-1][y] = Yspring_w;
6171 next[x-1][y] = Xspring_w;
6174 static void Ldynamite_1(int x, int y)
6176 play_element_sound(x, y, SOUND_tick, Xdynamite_1);
6177 next[x][y] = Xdynamite_2;
6180 static void Ldynamite_2(int x, int y)
6182 play_element_sound(x, y, SOUND_tick, Xdynamite_2);
6183 next[x][y] = Xdynamite_3;
6186 static void Ldynamite_3(int x, int y)
6188 play_element_sound(x, y, SOUND_tick, Xdynamite_3);
6189 next[x][y] = Xdynamite_4;
6192 static void Ldynamite_4(int x, int y)
6194 play_element_sound(x, y, SOUND_tick, Xdynamite_4);
6195 next[x][y] = Zdynamite;
6197 Lboom_generic(x, y, Xblank, Xblank);
6200 static void Lfake_door_1(int x, int y)
6202 if (lev.magnify_cnt)
6203 cave[x][y] = Xdoor_1;
6206 static void Lfake_door_2(int x, int y)
6208 if (lev.magnify_cnt)
6209 cave[x][y] = Xdoor_2;
6212 static void Lfake_door_3(int x, int y)
6214 if (lev.magnify_cnt)
6215 cave[x][y] = Xdoor_3;
6218 static void Lfake_door_4(int x, int y)
6220 if (lev.magnify_cnt)
6221 cave[x][y] = Xdoor_4;
6224 static void Lfake_door_5(int x, int y)
6226 if (lev.magnify_cnt)
6227 cave[x][y] = Xdoor_5;
6230 static void Lfake_door_6(int x, int y)
6232 if (lev.magnify_cnt)
6233 cave[x][y] = Xdoor_6;
6236 static void Lfake_door_7(int x, int y)
6238 if (lev.magnify_cnt)
6239 cave[x][y] = Xdoor_7;
6242 static void Lfake_door_8(int x, int y)
6244 if (lev.magnify_cnt)
6245 cave[x][y] = Xdoor_8;
6248 static void Lballoon(int x, int y)
6250 if (lev.wind_cnt == 0)
6253 switch (lev.wind_direction)
6256 switch (cave[x][y-1])
6269 cave[x][y] = Yballoon_nB;
6270 next[x][y] = Xblank;
6271 cave[x][y-1] = Yballoon_n;
6272 next[x][y-1] = Xballoon;
6283 cave[x][y] = Yballoon_nB;
6284 next[x][y] = Xblank;
6285 if (cave[x+1][y-2] == Xblank)
6286 cave[x+1][y-2] = Xsplash_e;
6287 if (cave[x-1][y-2] == Xblank)
6288 cave[x-1][y-2] = Xsplash_w;
6289 play_element_sound(x, y, SOUND_acid, Xacid_1);
6295 switch (cave[x+1][y])
6308 cave[x][y] = Yballoon_eB;
6309 next[x][y] = Xblank;
6310 cave[x+1][y] = Yballoon_e;
6311 next[x+1][y] = Xballoon;
6322 cave[x][y] = Yballoon_eB;
6323 next[x][y] = Xblank;
6324 if (cave[x+2][y-1] == Xblank)
6325 cave[x+2][y-1] = Xsplash_e;
6326 if (cave[x][y-1] == Xblank)
6327 cave[x][y-1] = Xsplash_w;
6328 play_element_sound(x, y, SOUND_acid, Xacid_1);
6334 switch (cave[x][y+1])
6347 cave[x][y] = Yballoon_sB;
6348 next[x][y] = Xblank;
6349 cave[x][y+1] = Yballoon_s;
6350 next[x][y+1] = Xballoon;
6361 cave[x][y] = Yballoon_sB;
6362 next[x][y] = Xblank;
6363 if (cave[x+1][y] == Xblank)
6364 cave[x+1][y] = Xsplash_e;
6365 if (cave[x-1][y] == Xblank)
6366 cave[x-1][y] = Xsplash_w;
6367 play_element_sound(x, y, SOUND_acid, Xacid_1);
6373 switch (cave[x-1][y])
6386 cave[x][y] = Yballoon_wB;
6387 next[x][y] = Xblank;
6388 cave[x-1][y] = Yballoon_w;
6389 next[x-1][y] = Xballoon;
6400 cave[x][y] = Yballoon_wB;
6401 next[x][y] = Xblank;
6402 if (cave[x][y-1] == Xblank)
6403 cave[x][y-1] = Xsplash_e;
6404 if (cave[x-2][y-1] == Xblank)
6405 cave[x-2][y-1] = Xsplash_w;
6406 play_element_sound(x, y, SOUND_acid, Xacid_1);
6413 static void Lball_common(int x, int y)
6415 play_element_sound(x, y, SOUND_ball, Xball_1);
6417 if (lev.ball_random)
6422 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6423 is_blank[cave[x-1][y-1]])
6425 cave[x-1][y-1] = Yball_blank;
6426 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6431 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6432 is_blank[cave[x][y-1]])
6434 cave[x][y-1] = Yball_blank;
6435 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6440 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6441 is_blank[cave[x+1][y-1]])
6443 cave[x+1][y-1] = Yball_blank;
6444 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6449 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6450 is_blank[cave[x-1][y]])
6452 cave[x-1][y] = Yball_blank;
6453 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6458 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6459 is_blank[cave[x+1][y]])
6461 cave[x+1][y] = Yball_blank;
6462 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6467 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6468 is_blank[cave[x-1][y+1]])
6470 cave[x-1][y+1] = Yball_blank;
6471 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6476 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6477 is_blank[cave[x][y+1]])
6479 cave[x][y+1] = Yball_blank;
6480 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6485 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6486 is_blank[cave[x+1][y+1]])
6488 cave[x+1][y+1] = Yball_blank;
6489 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6496 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6497 is_blank[cave[x-1][y-1]])
6499 cave[x-1][y-1] = Yball_blank;
6500 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6503 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6504 is_blank[cave[x][y-1]])
6506 cave[x][y-1] = Yball_blank;
6507 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6510 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6511 is_blank[cave[x+1][y-1]])
6513 cave[x+1][y-1] = Yball_blank;
6514 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6517 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6518 is_blank[cave[x-1][y]])
6520 cave[x-1][y] = Yball_blank;
6521 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6524 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6525 is_blank[cave[x+1][y]])
6527 cave[x+1][y] = Yball_blank;
6528 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6531 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6532 is_blank[cave[x-1][y+1]])
6534 cave[x-1][y+1] = Yball_blank;
6535 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6538 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6539 is_blank[cave[x][y+1]])
6541 cave[x][y+1] = Yball_blank;
6542 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6545 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6546 is_blank[cave[x+1][y+1]])
6548 cave[x+1][y+1] = Yball_blank;
6549 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6553 lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
6556 static void Lball_1(int x, int y)
6558 if (!lev.ball_active)
6561 cave[x][y] = Yball_1;
6562 next[x][y] = Xball_2;
6569 static void Lball_2(int x, int y)
6571 if (!lev.ball_active)
6574 cave[x][y] = Yball_2;
6575 next[x][y] = Xball_1;
6582 static void Ldrip(int x, int y)
6584 next[x][y] = Xdrip_fall;
6587 static void Ldrip_fall(int x, int y)
6591 switch (cave[x][y+1])
6607 cave[x][y] = Ydrip_1_sB;
6608 next[x][y] = Xdrip_stretchB;
6609 cave[x][y+1] = Ydrip_1_s;
6610 next[x][y+1] = Xdrip_stretch;
6621 cave[x][y] = Ydrip_1_sB;
6622 next[x][y] = Xdrip_stretchB;
6623 if (cave[x+1][y] == Xblank)
6624 cave[x+1][y] = Xsplash_e;
6625 if (cave[x-1][y] == Xblank)
6626 cave[x-1][y] = Xsplash_w;
6627 play_element_sound(x, y, SOUND_acid, Xacid_1);
6633 case 0: temp = Xamoeba_1; break;
6634 case 1: temp = Xamoeba_2; break;
6635 case 2: temp = Xamoeba_3; break;
6636 case 3: temp = Xamoeba_4; break;
6637 case 4: temp = Xamoeba_5; break;
6638 case 5: temp = Xamoeba_6; break;
6639 case 6: temp = Xamoeba_7; break;
6640 case 7: temp = Xamoeba_8; break;
6645 play_element_sound(x, y, SOUND_drip, Xdrip_fall);
6650 static void Ldrip_stretch(int x, int y)
6652 cave[x][y] = Ydrip_2_s;
6653 next[x][y] = Xdrip_fall;
6656 static void Ldrip_stretchB(int x, int y)
6658 cave[x][y] = Ydrip_2_sB;
6659 next[x][y] = Xblank;
6662 static void Lwonderwall(int x, int y)
6664 if (lev.wonderwall_time > 0 && lev.wonderwall_active)
6666 cave[x][y] = Ywonderwall;
6667 play_element_sound(x, y, SOUND_wonder, Xwonderwall);
6671 static void Lwheel(int x, int y)
6673 if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
6674 cave[x][y] = Ywheel;
6677 static void Lswitch(int x, int y)
6679 if (lev.ball_active)
6680 cave[x][y] = Yswitch;
6683 static void Lfake_blank(int x, int y)
6686 cave[x][y] = Yfake_blank;
6689 static void Lfake_grass(int x, int y)
6691 if (lev.magnify_cnt)
6692 cave[x][y] = Yfake_grass;
6695 static void Lfake_amoeba(int x, int y)
6698 cave[x][y] = Yfake_amoeba;
6701 static void Lsand_stone(int x, int y)
6703 switch (cave[x][y+1])
6716 cave[x][y] = Xsand_stonesand_quickout_1;
6717 next[x][y] = Xsand_stonesand_quickout_2;
6718 cave[x][y+1] = Xsand_stoneout_1;
6719 next[x][y+1] = Xsand_stoneout_2;
6730 cave[x][y] = Xsand_stonesand_quickout_1;
6731 next[x][y] = Xsand_stonesand_quickout_2;
6732 if (cave[x+1][y] == Xblank)
6733 cave[x+1][y] = Xsplash_e;
6734 if (cave[x-1][y] == Xblank)
6735 cave[x-1][y] = Xsplash_w;
6736 play_element_sound(x, y, SOUND_acid, Xacid_1);
6740 cave[x][y] = Xsand_stonesand_1;
6741 next[x][y] = Xsand_stonesand_2;
6742 cave[x][y+1] = Xsand_sandstone_1;
6743 next[x][y+1] = Xsand_sandstone_2;
6748 static void Lsand_stonein_1(int x, int y)
6750 next[x][y] = Xsand_stonein_2;
6753 static void Lsand_stonein_2(int x, int y)
6755 next[x][y] = Xsand_stonein_3;
6758 static void Lsand_stonein_3(int x, int y)
6760 next[x][y] = Xsand_stonein_4;
6763 static void Lsand_stonein_4(int x, int y)
6765 next[x][y] = Xblank;
6768 static void Lsand_sandstone_1(int x, int y)
6770 next[x][y] = Xsand_sandstone_2;
6773 static void Lsand_sandstone_2(int x, int y)
6775 next[x][y] = Xsand_sandstone_3;
6778 static void Lsand_sandstone_3(int x, int y)
6780 next[x][y] = Xsand_sandstone_4;
6783 static void Lsand_sandstone_4(int x, int y)
6785 next[x][y] = Xsand_stone;
6788 static void Lsand_stonesand_1(int x, int y)
6790 next[x][y] = Xsand_stonesand_2;
6793 static void Lsand_stonesand_2(int x, int y)
6795 next[x][y] = Xsand_stonesand_3;
6798 static void Lsand_stonesand_3(int x, int y)
6800 next[x][y] = Xsand_stonesand_4;
6803 static void Lsand_stonesand_4(int x, int y)
6808 static void Lsand_stoneout_1(int x, int y)
6810 next[x][y] = Xsand_stoneout_2;
6813 static void Lsand_stoneout_2(int x, int y)
6815 next[x][y] = Xstone_fall;
6818 static void Lsand_stonesand_quickout_1(int x, int y)
6820 next[x][y] = Xsand_stonesand_quickout_2;
6823 static void Lsand_stonesand_quickout_2(int x, int y)
6828 static void Lslide_ns(int x, int y)
6830 if (is_blank[cave[x][y-1]])
6832 cave[x][y-1] = Yslide_ns_blank;
6833 next[x][y-1] = Xslide_ns;
6834 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6837 if (is_blank[cave[x][y+1]])
6839 cave[x][y+1] = Yslide_ns_blank;
6840 next[x][y+1] = Xslide_ns;
6841 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6845 static void Lslide_ew(int x, int y)
6847 if (is_blank[cave[x+1][y]])
6849 cave[x+1][y] = Yslide_ew_blank;
6850 next[x+1][y] = Xslide_ew;
6851 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6854 if (is_blank[cave[x-1][y]])
6856 cave[x-1][y] = Yslide_ew_blank;
6857 next[x-1][y] = Xslide_ew;
6858 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6862 static void Lexit(int x, int y)
6864 if (lev.gems_needed > 0)
6867 switch (RANDOM(64) / 21)
6870 cave[x][y] = Xexit_1;
6871 next[x][y] = Xexit_2;
6875 cave[x][y] = Xexit_2;
6876 next[x][y] = Xexit_3;
6880 cave[x][y] = Xexit_3;
6881 next[x][y] = Xexit_1;
6885 play_element_sound(x, y, SOUND_exit_open, Xexit);
6888 static void Lexit_1(int x, int y)
6890 next[x][y] = Xexit_2;
6893 static void Lexit_2(int x, int y)
6895 next[x][y] = Xexit_3;
6898 static void Lexit_3(int x, int y)
6900 next[x][y] = Xexit_1;
6903 static void Lpause(int x, int y)
6905 next[x][y] = Xblank;
6908 static void Lamoeba(int x, int y)
6928 if (is_amoeba[cave[x][y-1]] ||
6929 is_amoeba[cave[x+1][y]] ||
6930 is_amoeba[cave[x][y+1]] ||
6931 is_amoeba[cave[x-1][y]])
6936 static void Lboom_one(int x, int y, boolean by_dynamite)
6997 cave[x][y] = Xboom_android;
7008 cave[x][y] = Xboom_bug;
7009 Lboom_bug_new(x, y, TRUE);
7015 cave[x][y] = Xboom_tank;
7016 Lboom_tank_new(x, y, TRUE);
7020 cave[x][y] = Xboom_1;
7025 static void Lboom_nine(int x, int y, boolean by_dynamite)
7027 Lboom_one(x, y-1, by_dynamite);
7028 Lboom_one(x-1, y, by_dynamite);
7029 Lboom_one(x+1, y, by_dynamite);
7030 Lboom_one(x, y+1, by_dynamite);
7031 Lboom_one(x-1, y-1, by_dynamite);
7032 Lboom_one(x+1, y-1, by_dynamite);
7033 Lboom_one(x-1, y+1, by_dynamite);
7034 Lboom_one(x+1, y+1, by_dynamite);
7036 cave[x][y] = Xboom_1;
7039 static void Lexplode(int x, int y)
7044 Lboom_bug_new(x, y, FALSE);
7045 Lboom_nine(x, y, FALSE);
7049 Lboom_tank_new(x, y, FALSE);
7050 Lboom_nine(x, y, FALSE);
7054 Lboom_eater_new(x, y, FALSE);
7055 Lboom_nine(x, y, FALSE);
7059 Lboom_nine(x, y, TRUE);
7063 Lboom_nine(x, y, FALSE);
7068 static void Lboom_1(int x, int y)
7070 next[x][y] = Xboom_2;
7071 #if !PLAY_ELEMENT_SOUND
7072 if (x != lev.exit_x && y != lev.exit_y)
7073 play_sound(x, y, SOUND_boom);
7075 lev.exit_x = lev.exit_y = -1;
7079 static void Lboom_2(int x, int y)
7081 next[x][y] = boom[x][y];
7084 static void Lboom_android(int x, int y)
7086 #if PLAY_ELEMENT_SOUND
7087 play_element_sound(x, y, SOUND_boom, Xandroid);
7093 static void Lchain(int x, int y)
7098 static void handle_tile(int x, int y)
7102 case Xacid_1: Lacid_1(x, y); break;
7103 case Xacid_2: Lacid_2(x, y); break;
7104 case Xacid_3: Lacid_3(x, y); break;
7105 case Xacid_4: Lacid_4(x, y); break;
7106 case Xacid_5: Lacid_5(x, y); break;
7107 case Xacid_6: Lacid_6(x, y); break;
7108 case Xacid_7: Lacid_7(x, y); break;
7109 case Xacid_8: Lacid_8(x, y); break;
7111 case Xfake_acid_1: Lfake_acid_1(x, y); break;
7112 case Xfake_acid_2: Lfake_acid_2(x, y); break;
7113 case Xfake_acid_3: Lfake_acid_3(x, y); break;
7114 case Xfake_acid_4: Lfake_acid_4(x, y); break;
7115 case Xfake_acid_5: Lfake_acid_5(x, y); break;
7116 case Xfake_acid_6: Lfake_acid_6(x, y); break;
7117 case Xfake_acid_7: Lfake_acid_7(x, y); break;
7118 case Xfake_acid_8: Lfake_acid_8(x, y); break;
7120 case Xandroid: Landroid(x, y); break;
7121 case Xandroid_1_n: Landroid_1_n(x, y); break;
7122 case Xandroid_2_n: Landroid_2_n(x, y); break;
7123 case Xandroid_1_e: Landroid_1_e(x, y); break;
7124 case Xandroid_2_e: Landroid_2_e(x, y); break;
7125 case Xandroid_1_s: Landroid_1_s(x, y); break;
7126 case Xandroid_2_s: Landroid_2_s(x, y); break;
7127 case Xandroid_1_w: Landroid_1_w(x, y); break;
7128 case Xandroid_2_w: Landroid_2_w(x, y); break;
7130 case Xeater_n: Leater_n(x, y); break;
7131 case Xeater_e: Leater_e(x, y); break;
7132 case Xeater_s: Leater_s(x, y); break;
7133 case Xeater_w: Leater_w(x, y); break;
7135 case Xalien: Lalien(x, y); break;
7136 case Xalien_pause: Lalien_pause(x, y); break;
7138 case Xbug_1_n: Lbug_1_n(x, y); break;
7139 case Xbug_2_n: Lbug_2_n(x, y); break;
7140 case Xbug_1_e: Lbug_1_e(x, y); break;
7141 case Xbug_2_e: Lbug_2_e(x, y); break;
7142 case Xbug_1_s: Lbug_1_s(x, y); break;
7143 case Xbug_2_s: Lbug_2_s(x, y); break;
7144 case Xbug_1_w: Lbug_1_w(x, y); break;
7145 case Xbug_2_w: Lbug_2_w(x, y); break;
7147 case Xtank_1_n: Ltank_1_n(x, y); break;
7148 case Xtank_2_n: Ltank_2_n(x, y); break;
7149 case Xtank_1_e: Ltank_1_e(x, y); break;
7150 case Xtank_2_e: Ltank_2_e(x, y); break;
7151 case Xtank_1_s: Ltank_1_s(x, y); break;
7152 case Xtank_2_s: Ltank_2_s(x, y); break;
7153 case Xtank_1_w: Ltank_1_w(x, y); break;
7154 case Xtank_2_w: Ltank_2_w(x, y); break;
7156 case Xemerald: Lemerald(x, y); break;
7157 case Xemerald_pause: Lemerald_pause(x, y); break;
7158 case Xemerald_fall: Lemerald_fall(x, y); break;
7160 case Xdiamond: Ldiamond(x, y); break;
7161 case Xdiamond_pause: Ldiamond_pause(x, y); break;
7162 case Xdiamond_fall: Ldiamond_fall(x, y); break;
7164 case Xstone: Lstone(x, y); break;
7165 case Xstone_pause: Lstone_pause(x, y); break;
7166 case Xstone_fall: Lstone_fall(x, y); break;
7168 case Xbomb: Lbomb(x, y); break;
7169 case Xbomb_pause: Lbomb_pause(x, y); break;
7170 case Xbomb_fall: Lbomb_fall(x, y); break;
7172 case Xnut: Lnut(x, y); break;
7173 case Xnut_pause: Lnut_pause(x, y); break;
7174 case Xnut_fall: Lnut_fall(x, y); break;
7176 case Xspring: Lspring(x, y); break;
7177 case Xspring_pause: Lspring_pause(x, y); break;
7178 case Xspring_e: Lspring_e(x, y); break;
7179 case Xspring_w: Lspring_w(x, y); break;
7180 case Xspring_fall: Lspring_fall(x, y); break;
7182 case Xpush_emerald_e: Lpush_emerald_e(x, y); break;
7183 case Xpush_emerald_w: Lpush_emerald_w(x, y); break;
7184 case Xpush_diamond_e: Lpush_diamond_e(x, y); break;
7185 case Xpush_diamond_w: Lpush_diamond_w(x, y); break;
7186 case Xpush_stone_e: Lpush_stone_e(x, y); break;
7187 case Xpush_stone_w: Lpush_stone_w(x, y); break;
7188 case Xpush_bomb_e: Lpush_bomb_e(x, y); break;
7189 case Xpush_bomb_w: Lpush_bomb_w(x, y); break;
7190 case Xpush_nut_e: Lpush_nut_e(x, y); break;
7191 case Xpush_nut_w: Lpush_nut_w(x, y); break;
7192 case Xpush_spring_e: Lpush_spring_e(x, y); break;
7193 case Xpush_spring_w: Lpush_spring_w(x, y); break;
7195 case Xdynamite_1: Ldynamite_1(x, y); break;
7196 case Xdynamite_2: Ldynamite_2(x, y); break;
7197 case Xdynamite_3: Ldynamite_3(x, y); break;
7198 case Xdynamite_4: Ldynamite_4(x, y); break;
7200 case Xfake_door_1: Lfake_door_1(x, y); break;
7201 case Xfake_door_2: Lfake_door_2(x, y); break;
7202 case Xfake_door_3: Lfake_door_3(x, y); break;
7203 case Xfake_door_4: Lfake_door_4(x, y); break;
7204 case Xfake_door_5: Lfake_door_5(x, y); break;
7205 case Xfake_door_6: Lfake_door_6(x, y); break;
7206 case Xfake_door_7: Lfake_door_7(x, y); break;
7207 case Xfake_door_8: Lfake_door_8(x, y); break;
7209 case Xballoon: Lballoon(x, y); break;
7211 case Xball_1: Lball_1(x, y); break;
7212 case Xball_2: Lball_2(x, y); break;
7214 case Xdrip: Ldrip(x, y); break;
7215 case Xdrip_fall: Ldrip_fall(x, y); break;
7216 case Xdrip_stretch: Ldrip_stretch(x, y); break;
7217 case Xdrip_stretchB: Ldrip_stretchB(x, y); break;
7219 case Xwonderwall: Lwonderwall(x, y); break;
7221 case Xwheel: Lwheel(x, y); break;
7223 case Xswitch: Lswitch(x, y); break;
7225 case Xfake_blank: Lfake_blank(x, y); break;
7226 case Xfake_grass: Lfake_grass(x, y); break;
7227 case Xfake_amoeba: Lfake_amoeba(x, y); break;
7229 case Xsand_stone: Lsand_stone(x, y); break;
7230 case Xsand_stonein_1: Lsand_stonein_1(x, y); break;
7231 case Xsand_stonein_2: Lsand_stonein_2(x, y); break;
7232 case Xsand_stonein_3: Lsand_stonein_3(x, y); break;
7233 case Xsand_stonein_4: Lsand_stonein_4(x, y); break;
7234 case Xsand_sandstone_1: Lsand_sandstone_1(x, y); break;
7235 case Xsand_sandstone_2: Lsand_sandstone_2(x, y); break;
7236 case Xsand_sandstone_3: Lsand_sandstone_3(x, y); break;
7237 case Xsand_sandstone_4: Lsand_sandstone_4(x, y); break;
7238 case Xsand_stonesand_1: Lsand_stonesand_1(x, y); break;
7239 case Xsand_stonesand_2: Lsand_stonesand_2(x, y); break;
7240 case Xsand_stonesand_3: Lsand_stonesand_3(x, y); break;
7241 case Xsand_stonesand_4: Lsand_stonesand_4(x, y); break;
7242 case Xsand_stoneout_1: Lsand_stoneout_1(x, y); break;
7243 case Xsand_stoneout_2: Lsand_stoneout_2(x, y); break;
7244 case Xsand_stonesand_quickout_1: Lsand_stonesand_quickout_1(x, y); break;
7245 case Xsand_stonesand_quickout_2: Lsand_stonesand_quickout_2(x, y); break;
7247 case Xslide_ns: Lslide_ns(x, y); break;
7248 case Xslide_ew: Lslide_ew(x, y); break;
7250 case Xexit: Lexit(x, y); break;
7251 case Xexit_1: Lexit_1(x, y); break;
7252 case Xexit_2: Lexit_2(x, y); break;
7253 case Xexit_3: Lexit_3(x, y); break;
7255 case Xpause: Lpause(x, y); break;
7257 case Xchain: Lchain(x, y); break;
7258 case Xboom_bug: Lboom_bug(x, y); break;
7259 case Xboom_tank: Lboom_tank(x, y); break;
7260 case Xboom_android: Lboom_android(x, y); break;
7261 case Xboom_1: Lboom_1(x, y); break;
7262 case Xboom_2: Lboom_2(x, y); break;
7266 static void logic_players(void)
7275 game_em.any_player_moving = FALSE;
7276 game_em.any_player_snapping = FALSE;
7278 /* must test for death and actually kill separately */
7279 for (i = 0; i < MAX_PLAYERS; i++)
7281 boolean ply_kill = player_killed(&ply[i]);
7283 if (ply[i].alive && ply_kill)
7284 kill_player(&ply[i]);
7287 for (i = 0; i < MAX_PLAYERS; i++)
7292 /* check for wrap-around movement */
7293 if (ply[i].x < lev.left ||
7294 ply[i].x > lev.right - 1)
7296 ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
7298 game.centered_player_nr_next = i;
7299 game.set_centered_player = TRUE;
7300 game.set_centered_player_wrap = TRUE;
7303 ply[i].prev_x = ply[i].x;
7304 ply[i].prev_y = ply[i].y;
7305 ply[i].anim = PLY_still;
7308 start_check_nr = ((game_em.random & 128 ? 0 : 1) * 2 +
7309 (game_em.random & 256 ? 0 : 1));
7311 for (i = 0; i < MAX_PLAYERS; i++)
7313 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
7315 if (ply[check_nr].alive)
7316 check_player(&ply[check_nr]);
7319 for (i = 0; i < MAX_PLAYERS; i++)
7324 if (cave[ply[i].prev_x][ply[i].prev_y] == Zplayer)
7326 cave[ply[i].prev_x][ply[i].prev_y] = Xblank;
7327 next[ply[i].prev_x][ply[i].prev_y] = Xblank;
7330 if (cave[ply[i].x][ply[i].y] == Xblank)
7332 cave[ply[i].x][ply[i].y] = Zplayer;
7333 next[ply[i].x][ply[i].y] = Zplayer;
7338 static void logic_objects(void)
7346 seed = game_em.random;
7349 for (y = lev.top; y < lev.bottom; y++)
7350 for (x = lev.left; x < lev.right; x++)
7353 if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
7354 lev.score += score; /* only add a score if someone is alive */
7356 game_em.game_over = TRUE;
7358 game_em.random = seed;
7360 /* triple buffering */
7361 void *temp = lev.cave;
7362 lev.cave = lev.next;
7363 lev.next = lev.draw;
7367 static void logic_globals(void)
7372 unsigned int random;
7378 /* update variables */
7380 if (lev.score > 9999)
7383 if (lev.android_move_cnt-- == 0)
7384 lev.android_move_cnt = lev.android_move_time;
7385 if (lev.android_clone_cnt-- == 0)
7386 lev.android_clone_cnt = lev.android_clone_time;
7387 if (lev.ball_active)
7388 if (lev.ball_cnt-- == 0)
7389 lev.ball_cnt = lev.ball_time;
7392 if (lev.magnify_cnt)
7398 if (lev.wonderwall_time > 0 && lev.wonderwall_active)
7399 lev.wonderwall_time--;
7402 play_element_sound(lev.wheel_x, lev.wheel_y, SOUND_wheel, Xwheel);
7406 random = game_em.random;
7408 for (count = lev.amoeba_time; count--;)
7410 x = lev.left - 1 + (random >> 10) % (CAVE_WIDTH + 2);
7411 y = lev.top - 1 + (random >> 20) % (CAVE_HEIGHT + 2);
7413 if (x >= lev.left && x < lev.right &&
7414 y >= lev.top && y < lev.bottom)
7417 random = random * 129 + 1;
7420 game_em.random = random;
7422 /* handle explosions */
7424 for (y = lev.top; y < lev.bottom; y++)
7425 for (x = lev.left; x < lev.right; x++)
7428 /* triple buffering */
7430 for (y = lev.top; y < lev.bottom; y++)
7431 for (x = lev.left; x < lev.right; x++)
7432 next[x][y] = cave[x][y];