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 */
14 #define USE_CHANGED_ACID_STUFF
16 #define RANDOM_RAW (seed = seed << 31 | seed >> 1)
17 #define RANDOM(x) (RANDOM_RAW & (x - 1))
19 static short **cave, **next, **boom;
20 static unsigned int seed;
23 static const byte is_blank[TILE_MAX] =
38 static const byte is_blank_or_acid[TILE_MAX] =
61 static const byte is_fake_acid[TILE_MAX] =
73 static const byte is_amoeba[TILE_MAX] =
87 static const byte is_android_walkable[TILE_MAX] =
103 static void Lboom_generic(int x, int y, int element, int element_middle)
105 boom[x-1][y-1] = element;
106 boom[x][y-1] = element;
107 boom[x+1][y-1] = element;
108 boom[x-1][y] = element;
109 boom[x][y] = element_middle;
110 boom[x+1][y] = element;
111 boom[x-1][y+1] = element;
112 boom[x][y+1] = element;
113 boom[x+1][y+1] = element;
116 static void Lboom_bug(int x, int y, int by_element)
120 Lboom_generic(x, y, Xemerald, Xdiamond);
122 #if PLAY_ELEMENT_SOUND
123 play_element_sound(x, y, SOUND_boom, by_element);
127 static void Lboom_tank(int x, int y, int by_element)
131 Lboom_generic(x, y, Xblank, Xblank);
133 #if PLAY_ELEMENT_SOUND
134 play_element_sound(x, y, SOUND_boom, by_element);
138 static void Lboom_eater(int x, int y, int by_element)
142 boom[x-1][y-1] = lev.eater_array[lev.eater_pos][0];
143 boom[x][y-1] = lev.eater_array[lev.eater_pos][1];
144 boom[x+1][y-1] = lev.eater_array[lev.eater_pos][2];
145 boom[x-1][y] = lev.eater_array[lev.eater_pos][3];
146 boom[x][y] = lev.eater_array[lev.eater_pos][4];
147 boom[x+1][y] = lev.eater_array[lev.eater_pos][5];
148 boom[x-1][y+1] = lev.eater_array[lev.eater_pos][6];
149 boom[x][y+1] = lev.eater_array[lev.eater_pos][7];
150 boom[x+1][y+1] = lev.eater_array[lev.eater_pos][8];
152 lev.eater_pos = (lev.eater_pos + 1) & 7;
154 #if PLAY_ELEMENT_SOUND
155 play_element_sound(x, y, SOUND_boom, by_element);
159 static boolean player_killed(struct PLAYER *ply)
167 if (lev.killed_out_of_time && setup.time_limit)
170 switch (cave[x][y-1])
191 switch (cave[x+1][y])
212 switch (cave[x][y+1])
233 switch (cave[x-1][y])
278 static void kill_player(struct PLAYER *ply)
285 switch (cave[x][y-1])
295 cave[x][y-1] = Xboom_bug;
306 cave[x][y-1] = Xboom_bomb;
310 switch (cave[x+1][y])
320 cave[x+1][y] = Xboom_bug;
331 cave[x+1][y] = Xboom_bomb;
335 switch (cave[x][y+1])
345 cave[x][y+1] = Xboom_bug;
356 cave[x][y+1] = Xboom_bomb;
360 switch (cave[x-1][y])
370 cave[x-1][y] = Xboom_bug;
381 cave[x-1][y] = Xboom_bomb;
392 play_element_sound(x, y, SOUND_exit_leave, Xexit_1);
396 play_element_sound(x, y, SOUND_die, Zplayer);
402 #ifdef USE_CHANGED_ACID_STUFF
415 cave[x][y] = Xboom_1;
421 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
423 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
428 boolean result = TRUE;
430 if (!dx && !dy) /* no direction specified */
433 if (dx && dy && ply->joy_snap) /* more than one direction specified */
436 if (ply->joy_snap == 0) /* player wants to move */
438 int element = cave[x][y];
442 /* fire is released */
446 cave[x][y] = Zplayer;
447 next[x][y] = Zplayer;
456 play_element_sound(x, y, SOUND_blank, Xblank);
457 ply->anim = PLY_walk_n + anim;
462 #ifdef USE_CHANGED_ACID_STUFF
471 if (cave[x+1][y-1] == Xblank)
472 cave[x+1][y-1] = Xsplash_e;
473 if (cave[x-1][y-1] == Xblank)
474 cave[x-1][y-1] = Xsplash_w;
475 play_element_sound(x, y, SOUND_acid, Xacid_1);
497 #ifndef USE_CHANGED_ACID_STUFF
507 ply->anim = PLY_walk_n + anim;
513 cave[x][y] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
514 (dx > 0 ? Ygrass_eB : Ygrass_wB));
515 next[x][y] = Zplayer;
516 play_element_sound(x, y, SOUND_dirt, Xgrass);
517 ply->anim = PLY_walk_n + anim;
523 cave[x][y] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
524 (dx > 0 ? Ydirt_eB : Ydirt_wB));
525 next[x][y] = Zplayer;
526 play_element_sound(x, y, SOUND_dirt, Xdirt);
527 ply->anim = PLY_walk_n + anim;
534 cave[x][y] = Ydiamond_blank;
535 next[x][y] = Zplayer;
536 play_element_sound(x, y, SOUND_collect, element);
537 lev.score += lev.diamond_score;
538 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
539 game.snapshot.collected_item = TRUE;
540 ply->anim = PLY_walk_n + anim;
547 cave[x][y] = Yemerald_blank;
548 next[x][y] = Zplayer;
549 play_element_sound(x, y, SOUND_collect, element);
550 lev.score += lev.emerald_score;
551 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
552 game.snapshot.collected_item = TRUE;
553 ply->anim = PLY_walk_n + anim;
559 cave[x][y] = Ydynamite_blank;
560 next[x][y] = Zplayer;
561 play_element_sound(x, y, SOUND_collect, element);
562 lev.score += lev.dynamite_score;
563 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
564 ply->anim = PLY_walk_n + anim;
571 cave[x][y] = Ykey_1_blank;
576 cave[x][y] = Ykey_2_blank;
581 cave[x][y] = Ykey_3_blank;
586 cave[x][y] = Ykey_4_blank;
591 cave[x][y] = Ykey_5_blank;
596 cave[x][y] = Ykey_6_blank;
601 cave[x][y] = Ykey_7_blank;
606 cave[x][y] = Ykey_8_blank;
611 next[x][y] = Zplayer;
612 play_element_sound(x, y, SOUND_collect, element);
613 lev.score += lev.key_score;
614 ply->anim = PLY_walk_n + anim;
620 cave[x][y] = Ylenses_blank;
621 next[x][y] = Zplayer;
622 play_element_sound(x, y, SOUND_collect, element);
623 lev.score += lev.lenses_score;
624 lev.lenses_cnt = lev.lenses_time;
625 ply->anim = PLY_walk_n + anim;
631 cave[x][y] = Ymagnify_blank;
632 next[x][y] = Zplayer;
633 play_element_sound(x, y, SOUND_collect, element);
634 lev.score += lev.magnify_score;
635 lev.magnify_cnt = lev.magnify_time;
636 ply->anim = PLY_walk_n + anim;
645 switch (cave[x+dx][y])
658 cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
659 next[x+dx][y] = Xstone_pause;
670 if (cave[x+dx+1][y-1] == Xblank)
671 cave[x+dx+1][y-1] = Xsplash_e;
672 if (cave[x+dx-1][y-1] == Xblank)
673 cave[x+dx-1][y-1] = Xsplash_w;
674 play_element_sound(x, y, SOUND_acid, Xacid_1);
678 cave[x][y] = dx > 0 ? Ystone_eB : Ystone_wB;
679 next[x][y] = Zplayer;
680 play_element_sound(x, y, SOUND_roll, Xstone);
685 ply->anim = PLY_push_n + anim;
692 switch (cave[x+dx][y])
705 cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
706 next[x+dx][y] = Xbomb_pause;
717 if (cave[x+dx+1][y-1] == Xblank)
718 cave[x+dx+1][y-1] = Xsplash_e;
719 if (cave[x+dx-1][y-1] == Xblank)
720 cave[x+dx-1][y-1] = Xsplash_w;
721 play_element_sound(x, y, SOUND_acid, Xacid_1);
725 cave[x][y] = dx > 0 ? Ybomb_eB : Ybomb_wB;
726 next[x][y] = Zplayer;
727 play_element_sound(x, y, SOUND_roll, Xbomb);
732 ply->anim = PLY_push_n + anim;
739 switch (cave[x+dx][y])
752 cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
753 next[x+dx][y] = Xnut_pause;
764 if (cave[x+dx+1][y-1] == Xblank)
765 cave[x+dx+1][y-1] = Xsplash_e;
766 if (cave[x+dx-1][y-1] == Xblank)
767 cave[x+dx-1][y-1] = Xsplash_w;
768 play_element_sound(x, y, SOUND_acid, Xacid_1);
772 cave[x][y] = dx > 0 ? Ynut_eB : Ynut_wB;
773 next[x][y] = Zplayer;
774 play_element_sound(x, y, SOUND_roll, Xnut);
779 ply->anim = PLY_push_n + anim;
786 switch (cave[x+dx][y])
799 cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
800 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
811 if (cave[x+dx+1][y-1] == Xblank)
812 cave[x+dx+1][y-1] = Xsplash_e;
813 if (cave[x+dx-1][y-1] == Xblank)
814 cave[x+dx-1][y-1] = Xsplash_w;
815 play_element_sound(x, y, SOUND_acid, Xacid_1);
819 cave[x][y] = dx > 0 ? Yspring_eB : Yspring_wB;
820 next[x][y] = Zplayer;
821 play_element_sound(x, y, SOUND_roll, Xspring);
827 cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
828 cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
829 next[x][y] = Zplayer;
830 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
831 play_element_sound(x, y, SOUND_slurp, Xalien);
832 lev.score += lev.slurp_score;
837 ply->anim = PLY_push_n + anim;
844 case Xsand_stonein_1:
845 case Xsand_stonein_2:
846 case Xsand_stonein_3:
847 case Xsand_stonein_4:
851 ply->anim = PLY_push_n + anim;
855 switch (cave[x+dx][y+dy])
868 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
869 (dx > 0 ? Yballoon_e : Yballoon_w));
870 next[x+dx][y+dy] = Xballoon;
881 if (cave[x+dx+1][y+dy-1] == Xblank)
882 cave[x+dx+1][y+dy-1] = Xsplash_e;
883 if (cave[x+dx-1][y+dy-1] == Xblank)
884 cave[x+dx-1][y+dy-1] = Xsplash_w;
885 play_element_sound(x, y, SOUND_acid, Xacid_1);
889 cave[x][y] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
890 (dx > 0 ? Yballoon_eB : Yballoon_wB));
891 next[x][y] = Zplayer;
892 play_element_sound(x, y, SOUND_push, Xballoon);
898 ply->anim = PLY_push_n + anim;
910 switch (cave[x+dx][y+dy])
923 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
924 (dx > 0 ? Yandroid_e : Yandroid_w));
925 next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
926 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
937 if (cave[x+dx+1][y+dy-1] == Xblank)
938 cave[x+dx+1][y+dy-1] = Xsplash_e;
939 if (cave[x+dx-1][y+dy-1] == Xblank)
940 cave[x+dx-1][y+dy-1] = Xsplash_w;
941 play_element_sound(x, y, SOUND_acid, Xacid_1);
945 cave[x][y] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
946 (dx > 0 ? Yandroid_eB : Yandroid_wB));
947 next[x][y] = Zplayer;
948 play_element_sound(x, y, SOUND_push, Xandroid);
954 ply->anim = PLY_push_n + anim;
959 if (ply->keys & 0x01)
966 if (ply->keys & 0x02)
973 if (ply->keys & 0x04)
980 if (ply->keys & 0x08)
987 if (ply->keys & 0x10)
994 if (ply->keys & 0x20)
1001 if (ply->keys & 0x40)
1008 if (ply->keys & 0x80)
1015 if (!is_blank[cave[x+dx][y+dy]])
1018 if (!is_fake_acid[cave[x+dx][y+dy]])
1020 cave[x+dx][y+dy] = Zplayer;
1021 next[x+dx][y+dy] = Zplayer;
1024 play_element_sound(x, y, SOUND_door, element);
1025 ply->anim = PLY_walk_n + anim;
1031 play_element_sound(x, y, SOUND_press, element);
1032 lev.wheel_cnt = lev.wheel_time;
1038 lev.wind_direction = 0;
1042 lev.wind_direction = 1;
1046 lev.wind_direction = 2;
1050 lev.wind_direction = 3;
1054 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1059 play_element_sound(x, y, SOUND_press, element);
1060 lev.wind_cnt = lev.wind_time;
1064 play_element_sound(x, y, SOUND_press, element);
1069 play_element_sound(x, y, SOUND_press, element);
1070 lev.ball_cnt = lev.ball_time;
1071 lev.ball_state = !lev.ball_state;
1075 cave[x][y] = Yplant;
1076 next[x][y] = Xplant;
1077 play_element_sound(x, y, SOUND_blank, Xplant);
1078 ply->anim = PLY_walk_n + anim;
1089 game_em.level_solved = TRUE;
1091 ply->anim = PLY_walk_n + anim;
1098 if (ply->x == oldx && ply->y == oldy) /* no movement */
1101 else /* player wants to snap */
1103 int element = cave[x][y];
1107 /* fire is pressed */
1110 cave[x][y] = Ygrass_blank;
1111 next[x][y] = Xblank;
1112 play_element_sound(x, y, SOUND_dirt, element);
1113 ply->anim = PLY_shoot_n + anim;
1117 cave[x][y] = Ydirt_blank;
1118 next[x][y] = Xblank;
1119 play_element_sound(x, y, SOUND_dirt, element);
1120 ply->anim = PLY_shoot_n + anim;
1124 case Xdiamond_pause:
1125 cave[x][y] = Ydiamond_blank;
1126 next[x][y] = Xblank;
1127 play_element_sound(x, y, SOUND_collect, element);
1128 lev.score += lev.diamond_score;
1129 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
1130 game.snapshot.collected_item = TRUE;
1131 ply->anim = PLY_walk_n + anim;
1135 case Xemerald_pause:
1136 cave[x][y] = Yemerald_blank;
1137 next[x][y] = Xblank;
1138 play_element_sound(x, y, SOUND_collect, element);
1139 lev.score += lev.emerald_score;
1140 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
1141 game.snapshot.collected_item = TRUE;
1142 ply->anim = PLY_walk_n + anim;
1146 cave[x][y] = Ydynamite_blank;
1147 next[x][y] = Xblank;
1148 play_element_sound(x, y, SOUND_collect, element);
1149 lev.score += lev.dynamite_score;
1150 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1151 ply->anim = PLY_walk_n + anim;
1156 cave[x][y] = Ykey_1_blank;
1161 cave[x][y] = Ykey_2_blank;
1166 cave[x][y] = Ykey_3_blank;
1171 cave[x][y] = Ykey_4_blank;
1176 cave[x][y] = Ykey_5_blank;
1181 cave[x][y] = Ykey_6_blank;
1186 cave[x][y] = Ykey_7_blank;
1191 cave[x][y] = Ykey_8_blank;
1196 next[x][y] = Xblank;
1197 play_element_sound(x, y, SOUND_collect, element);
1198 lev.score += lev.key_score;
1199 ply->anim = PLY_walk_n + anim;
1203 cave[x][y] = Ylenses_blank;
1204 next[x][y] = Xblank;
1205 play_element_sound(x, y, SOUND_collect, element);
1206 lev.score += lev.lenses_score;
1207 lev.lenses_cnt = lev.lenses_time;
1208 ply->anim = PLY_walk_n + anim;
1212 cave[x][y] = Ymagnify_blank;
1213 next[x][y] = Xblank;
1214 play_element_sound(x, y, SOUND_collect, element);
1215 lev.score += lev.magnify_score;
1216 lev.magnify_cnt = lev.magnify_time;
1217 ply->anim = PLY_walk_n + anim;
1228 static void check_player(struct PLAYER *ply)
1236 game_em.last_player_direction[ply->num] = MV_NONE;
1238 if (ply->joy_w) /* west */
1243 else if (ply->joy_e) /* east */
1249 if (ply->joy_n) /* north */
1254 else if (ply->joy_s) /* south */
1266 boolean players_visible_before_move;
1267 boolean players_visible_after_move;
1270 players_visible_before_move = checkIfAllPlayersFitToScreen();
1275 players_visible_after_move = checkIfAllPlayersFitToScreen();
1278 player is allowed to move only in the following cases:
1279 - it is not needed to display all players (not focussed to all players)
1280 - all players are (still or again) visible after the move
1281 - some players were already outside visible screen area before the move
1283 can_move = (game.centered_player_nr != -1 ||
1284 players_visible_after_move ||
1285 !players_visible_before_move);
1292 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
1298 if (dx == 0 && dy == 0)
1304 if (++ply->dynamite_cnt == 5 && ply->dynamite)
1306 cave[x][y] = Xdynamite_1;
1307 play_element_sound(x, y, SOUND_dynamite, Xdynamite_1);
1313 ply->dynamite_cnt = 0;
1316 /* be a bit more random if the player doesn't move */
1317 game_em.random += 7;
1323 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
1324 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
1325 ply->joy_spin = !ply->joy_spin;
1327 if (ply->joy_snap == 0) /* player wants to move */
1329 boolean moved = FALSE;
1331 if (ply->last_move_dir & MV_HORIZONTAL)
1333 if (!(moved = player_digfield(ply, 0, dy)))
1334 moved = player_digfield(ply, dx, 0);
1338 if (!(moved = player_digfield(ply, dx, 0)))
1339 moved = player_digfield(ply, 0, dy);
1345 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
1346 else if (oldy != ply->y)
1347 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
1349 game_em.any_player_moving = TRUE;
1350 game_em.last_moving_player = ply->num;
1351 game_em.last_player_direction[ply->num] = ply->last_move_dir;
1354 else /* player wants to snap */
1356 game_em.any_player_snapping = player_digfield(ply, dx, dy);
1360 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
1362 int distance, distance_shortest = CAVE_WIDTH + CAVE_HEIGHT;
1365 /* default values if no players are alive anymore */
1369 for (i = 0; i < MAX_PLAYERS; i++)
1374 distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
1376 if (distance < distance_shortest)
1381 distance_shortest = distance;
1386 static void Lacid_1(int x, int y)
1388 next[x][y] = Xacid_2;
1391 static void Lacid_2(int x, int y)
1393 next[x][y] = Xacid_3;
1396 static void Lacid_3(int x, int y)
1398 next[x][y] = Xacid_4;
1401 static void Lacid_4(int x, int y)
1403 next[x][y] = Xacid_5;
1406 static void Lacid_5(int x, int y)
1408 next[x][y] = Xacid_6;
1411 static void Lacid_6(int x, int y)
1413 next[x][y] = Xacid_7;
1416 static void Lacid_7(int x, int y)
1418 next[x][y] = Xacid_8;
1421 static void Lacid_8(int x, int y)
1423 next[x][y] = Xacid_1;
1426 static void Lfake_acid_1(int x, int y)
1428 next[x][y] = Xfake_acid_2;
1431 static void Lfake_acid_2(int x, int y)
1433 next[x][y] = Xfake_acid_3;
1436 static void Lfake_acid_3(int x, int y)
1438 next[x][y] = Xfake_acid_4;
1441 static void Lfake_acid_4(int x, int y)
1443 next[x][y] = Xfake_acid_5;
1446 static void Lfake_acid_5(int x, int y)
1448 next[x][y] = Xfake_acid_6;
1451 static void Lfake_acid_6(int x, int y)
1453 next[x][y] = Xfake_acid_7;
1456 static void Lfake_acid_7(int x, int y)
1458 next[x][y] = Xfake_acid_8;
1461 static void Lfake_acid_8(int x, int y)
1463 next[x][y] = Xfake_acid_1;
1466 static void Landroid(int x, int y)
1470 if (lev.android_clone_cnt == 0)
1472 if (!is_blank[cave[x-1][y-1]] &&
1473 !is_blank[cave[x][y-1]] &&
1474 !is_blank[cave[x+1][y-1]] &&
1475 !is_blank[cave[x-1][y]] &&
1476 !is_blank[cave[x+1][y]] &&
1477 !is_blank[cave[x-1][y+1]] &&
1478 !is_blank[cave[x][y+1]] &&
1479 !is_blank[cave[x+1][y+1]])
1484 /* randomly find an object to clone */
1486 case 0: /* S,NE,W,NW,SE,E,SW,N */
1487 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1488 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1489 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1490 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1491 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1492 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1493 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1494 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1497 case 1: /* NW,SE,N,S,NE,SW,E,W */
1498 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1499 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1500 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1501 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1502 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1503 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1504 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1505 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1508 case 2: /* SW,E,S,W,N,NW,SE,NE */
1509 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1510 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1511 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1512 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1513 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1514 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1515 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1516 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1519 case 3: /* N,SE,NE,E,W,S,NW,SW */
1520 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1521 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1522 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1523 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1524 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1525 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1526 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1527 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1530 case 4: /* SE,NW,E,NE,SW,W,N,S */
1531 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1532 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1533 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1534 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1535 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1536 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1537 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1538 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1541 case 5: /* NE,W,SE,SW,S,N,E,NW */
1542 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1543 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1544 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1545 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1546 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1547 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1548 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1549 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1552 case 6: /* E,N,SW,S,NW,NE,SE,W */
1553 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1554 temp = lev.android_array[cave[x][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][y+1]]; 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+1][y-1]]; if (temp != Xblank) break;
1559 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1560 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1563 case 7: /* W,SW,NW,N,E,SE,NE,S */
1564 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1565 temp = lev.android_array[cave[x-1][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][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+1]]; if (temp != Xblank) break;
1570 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1571 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1575 next[x][y] = temp; /* the item we chose to clone */
1576 play_element_sound(x, y, SOUND_android_clone, temp);
1580 /* randomly find a direction to move */
1582 case 0: /* S,NE,W,NW,SE,E,SW,N */
1583 if (is_blank[cave[x][y+1]]) goto android_s;
1584 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1585 if (is_blank[cave[x-1][y]]) goto android_w;
1586 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1587 if (is_blank[cave[x+1][y+1]]) goto android_se;
1588 if (is_blank[cave[x+1][y]]) goto android_e;
1589 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1590 if (is_blank[cave[x][y-1]]) goto android_n;
1593 case 1: /* NW,SE,N,S,NE,SW,E,W */
1594 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1595 if (is_blank[cave[x+1][y+1]]) goto android_se;
1596 if (is_blank[cave[x][y-1]]) goto android_n;
1597 if (is_blank[cave[x][y+1]]) goto android_s;
1598 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1599 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1600 if (is_blank[cave[x+1][y]]) goto android_e;
1601 if (is_blank[cave[x-1][y]]) goto android_w;
1604 case 2: /* SW,E,S,W,N,NW,SE,NE */
1605 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1606 if (is_blank[cave[x+1][y]]) goto android_e;
1607 if (is_blank[cave[x][y+1]]) goto android_s;
1608 if (is_blank[cave[x-1][y]]) goto android_w;
1609 if (is_blank[cave[x][y-1]]) goto android_n;
1610 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1611 if (is_blank[cave[x+1][y+1]]) goto android_se;
1612 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1615 case 3: /* N,SE,NE,E,W,S,NW,SW */
1616 if (is_blank[cave[x][y-1]]) goto android_n;
1617 if (is_blank[cave[x+1][y+1]]) goto android_se;
1618 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1619 if (is_blank[cave[x+1][y]]) goto android_e;
1620 if (is_blank[cave[x-1][y]]) goto android_w;
1621 if (is_blank[cave[x][y+1]]) goto android_s;
1622 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1623 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1626 case 4: /* SE,NW,E,NE,SW,W,N,S */
1627 if (is_blank[cave[x+1][y+1]]) goto android_se;
1628 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1629 if (is_blank[cave[x+1][y]]) goto android_e;
1630 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1631 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1632 if (is_blank[cave[x-1][y]]) goto android_w;
1633 if (is_blank[cave[x][y-1]]) goto android_n;
1634 if (is_blank[cave[x][y+1]]) goto android_s;
1637 case 5: /* NE,W,SE,SW,S,N,E,NW */
1638 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1639 if (is_blank[cave[x-1][y]]) goto android_w;
1640 if (is_blank[cave[x+1][y+1]]) goto android_se;
1641 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1642 if (is_blank[cave[x][y+1]]) goto android_s;
1643 if (is_blank[cave[x][y-1]]) goto android_n;
1644 if (is_blank[cave[x+1][y]]) goto android_e;
1645 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1648 case 6: /* E,N,SW,S,NW,NE,SE,W */
1649 if (is_blank[cave[x+1][y]]) goto android_e;
1650 if (is_blank[cave[x][y-1]]) goto android_n;
1651 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1652 if (is_blank[cave[x][y+1]]) goto android_s;
1653 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1654 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1655 if (is_blank[cave[x+1][y+1]]) goto android_se;
1656 if (is_blank[cave[x-1][y]]) goto android_w;
1659 case 7: /* W,SW,NW,N,E,SE,NE,S */
1660 if (is_blank[cave[x-1][y]]) goto android_w;
1661 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1662 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1663 if (is_blank[cave[x][y-1]]) goto android_n;
1664 if (is_blank[cave[x+1][y]]) goto android_e;
1665 if (is_blank[cave[x+1][y+1]]) goto android_se;
1666 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1667 if (is_blank[cave[x][y+1]]) goto android_s;
1673 if (lev.android_move_cnt == 0)
1675 if (cave[x-1][y-1] == Zplayer ||
1676 cave[x][y-1] == Zplayer ||
1677 cave[x+1][y-1] == Zplayer ||
1678 cave[x-1][y] == Zplayer ||
1679 cave[x+1][y] == Zplayer ||
1680 cave[x-1][y+1] == Zplayer ||
1681 cave[x][y+1] == Zplayer ||
1682 cave[x+1][y+1] == Zplayer)
1685 set_nearest_player_xy(x, y, &dx, &dy);
1687 next[x][y] = Xblank; /* assume we will move */
1688 temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
1694 /* attempt clockwise move first if direct path is blocked */
1696 case 0: /* north west */
1697 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1698 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1699 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1703 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1704 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1705 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1708 case 2: /* north east */
1709 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1710 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1711 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1715 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1716 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1717 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1720 case 4: /* nowhere */
1724 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1725 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1726 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1729 case 6: /* south west */
1730 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1731 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1732 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1736 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1737 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1738 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1741 case 8: /* south east */
1742 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1743 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1744 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1752 /* attempt counterclockwise move first if direct path is blocked */
1754 case 0: /* north west */
1755 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1756 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1757 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1761 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1762 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1763 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1766 case 2: /* north east */
1767 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1768 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1769 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1773 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1774 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1775 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1778 case 4: /* nowhere */
1782 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1783 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1784 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1787 case 6: /* south west */
1788 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1789 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1790 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1794 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1795 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1796 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1799 case 8: /* south east */
1800 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1801 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1802 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1809 next[x][y] = Xandroid;
1813 cave[x][y] = Yandroid_nB;
1814 cave[x][y-1] = Yandroid_n;
1815 next[x][y-1] = Xandroid;
1816 play_element_sound(x, y, SOUND_android_move, Xandroid);
1820 cave[x][y] = Yandroid_neB;
1821 cave[x+1][y-1] = Yandroid_ne;
1822 next[x+1][y-1] = Xandroid;
1823 play_element_sound(x, y, SOUND_android_move, Xandroid);
1827 cave[x][y] = Yandroid_eB;
1828 cave[x+1][y] = Yandroid_e;
1829 next[x+1][y] = Xandroid;
1830 play_element_sound(x, y, SOUND_android_move, Xandroid);
1834 cave[x][y] = Yandroid_seB;
1835 cave[x+1][y+1] = Yandroid_se;
1836 next[x+1][y+1] = Xandroid;
1837 play_element_sound(x, y, SOUND_android_move, Xandroid);
1841 cave[x][y] = Yandroid_sB;
1842 cave[x][y+1] = Yandroid_s;
1843 next[x][y+1] = Xandroid;
1844 play_element_sound(x, y, SOUND_android_move, Xandroid);
1848 cave[x][y] = Yandroid_swB;
1849 cave[x-1][y+1] = Yandroid_sw;
1850 next[x-1][y+1] = Xandroid;
1851 play_element_sound(x, y, SOUND_android_move, Xandroid);
1855 cave[x][y] = Yandroid_wB;
1856 cave[x-1][y] = Yandroid_w;
1857 next[x-1][y] = Xandroid;
1858 play_element_sound(x, y, SOUND_android_move, Xandroid);
1862 cave[x][y] = Yandroid_nwB;
1863 cave[x-1][y-1] = Yandroid_nw;
1864 next[x-1][y-1] = Xandroid;
1865 play_element_sound(x, y, SOUND_android_move, Xandroid);
1869 static void Landroid_1_n(int x, int y)
1871 switch (cave[x][y-1])
1884 cave[x][y] = Yandroid_nB;
1885 next[x][y] = Xblank;
1886 cave[x][y-1] = Yandroid_n;
1887 next[x][y-1] = Xandroid;
1888 play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
1899 cave[x][y] = Yandroid_nB;
1900 next[x][y] = Xblank;
1901 if (cave[x+1][y-2] == Xblank)
1902 cave[x+1][y-2] = Xsplash_e;
1903 if (cave[x-1][y-2] == Xblank)
1904 cave[x-1][y-2] = Xsplash_w;
1905 play_element_sound(x, y, SOUND_acid, Xacid_1);
1914 static void Landroid_2_n(int x, int y)
1916 switch (cave[x][y-1])
1929 cave[x][y] = Yandroid_nB;
1930 next[x][y] = Xblank;
1931 cave[x][y-1] = Yandroid_n;
1932 next[x][y-1] = Xandroid_1_n;
1933 play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
1944 cave[x][y] = Yandroid_nB;
1945 next[x][y] = Xblank;
1946 if (cave[x+1][y-2] == Xblank)
1947 cave[x+1][y-2] = Xsplash_e;
1948 if (cave[x-1][y-2] == Xblank)
1949 cave[x-1][y-2] = Xsplash_w;
1950 play_element_sound(x, y, SOUND_acid, Xacid_1);
1959 static void Landroid_1_e(int x, int y)
1961 switch (cave[x+1][y])
1974 cave[x][y] = Yandroid_eB;
1975 next[x][y] = Xblank;
1976 cave[x+1][y] = Yandroid_e;
1977 next[x+1][y] = Xandroid;
1978 play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
1989 cave[x][y] = Yandroid_eB;
1990 next[x][y] = Xblank;
1991 if (cave[x+2][y-1] == Xblank)
1992 cave[x+2][y-1] = Xsplash_e;
1993 if (cave[x][y-1] == Xblank)
1994 cave[x][y-1] = Xsplash_w;
1995 play_element_sound(x, y, SOUND_acid, Xacid_1);
2004 static void Landroid_2_e(int x, int y)
2006 switch (cave[x+1][y])
2019 cave[x][y] = Yandroid_eB;
2020 next[x][y] = Xblank;
2021 cave[x+1][y] = Yandroid_e;
2022 next[x+1][y] = Xandroid_1_e;
2023 play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
2034 cave[x][y] = Yandroid_eB;
2035 next[x][y] = Xblank;
2036 if (cave[x+2][y-1] == Xblank)
2037 cave[x+2][y-1] = Xsplash_e;
2038 if (cave[x][y-1] == Xblank)
2039 cave[x][y-1] = Xsplash_w;
2040 play_element_sound(x, y, SOUND_acid, Xacid_1);
2049 static void Landroid_1_s(int x, int y)
2051 switch (cave[x][y+1])
2064 cave[x][y] = Yandroid_sB;
2065 next[x][y] = Xblank;
2066 cave[x][y+1] = Yandroid_s;
2067 next[x][y+1] = Xandroid;
2068 play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
2079 cave[x][y] = Yandroid_sB;
2080 next[x][y] = Xblank;
2081 if (cave[x+1][y] == Xblank)
2082 cave[x+1][y] = Xsplash_e;
2083 if (cave[x-1][y] == Xblank)
2084 cave[x-1][y] = Xsplash_w;
2085 play_element_sound(x, y, SOUND_acid, Xacid_1);
2094 static void Landroid_2_s(int x, int y)
2096 switch (cave[x][y+1])
2109 cave[x][y] = Yandroid_sB;
2110 next[x][y] = Xblank;
2111 cave[x][y+1] = Yandroid_s;
2112 next[x][y+1] = Xandroid_1_s;
2113 play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
2124 cave[x][y] = Yandroid_sB;
2125 next[x][y] = Xblank;
2126 if (cave[x+1][y] == Xblank)
2127 cave[x+1][y] = Xsplash_e;
2128 if (cave[x-1][y] == Xblank)
2129 cave[x-1][y] = Xsplash_w;
2130 play_element_sound(x, y, SOUND_acid, Xacid_1);
2139 static void Landroid_1_w(int x, int y)
2141 switch (cave[x-1][y])
2154 cave[x][y] = Yandroid_wB;
2155 next[x][y] = Xblank;
2156 cave[x-1][y] = Yandroid_w;
2157 next[x-1][y] = Xandroid;
2158 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2169 cave[x][y] = Yandroid_wB;
2170 next[x][y] = Xblank;
2171 if (cave[x][y-1] == Xblank)
2172 cave[x][y-1] = Xsplash_e;
2173 if (cave[x-2][y-1] == Xblank)
2174 cave[x-2][y-1] = Xsplash_w;
2175 play_element_sound(x, y, SOUND_acid, Xacid_1);
2184 static void Landroid_2_w(int x, int y)
2186 switch (cave[x-1][y])
2199 cave[x][y] = Yandroid_wB;
2200 next[x][y] = Xblank;
2201 cave[x-1][y] = Yandroid_w;
2202 next[x-1][y] = Xandroid_1_w;
2203 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2214 cave[x][y] = Yandroid_wB;
2215 next[x][y] = Xblank;
2216 if (cave[x][y-1] == Xblank)
2217 cave[x][y-1] = Xsplash_e;
2218 if (cave[x-2][y-1] == Xblank)
2219 cave[x-2][y-1] = Xsplash_w;
2220 play_element_sound(x, y, SOUND_acid, Xacid_1);
2229 static void Leater_n(int x, int y)
2231 if (cave[x+1][y] == Xdiamond)
2233 cave[x+1][y] = Ydiamond_blank;
2234 next[x+1][y] = Xblank;
2235 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2239 if (cave[x][y+1] == Xdiamond)
2241 cave[x][y+1] = Ydiamond_blank;
2242 next[x][y+1] = Xblank;
2243 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2247 if (cave[x-1][y] == Xdiamond)
2249 cave[x-1][y] = Ydiamond_blank;
2250 next[x-1][y] = Xblank;
2251 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2255 if (cave[x][y-1] == Xdiamond)
2257 cave[x][y-1] = Ydiamond_blank;
2258 next[x][y-1] = Xblank;
2259 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2263 switch (cave[x][y-1])
2279 cave[x][y] = Yeater_nB;
2280 next[x][y] = Xblank;
2281 cave[x][y-1] = Yeater_n;
2282 next[x][y-1] = Xeater_n;
2293 cave[x][y] = Yeater_nB;
2294 next[x][y] = Xblank;
2295 if (cave[x+1][y-2] == Xblank)
2296 cave[x+1][y-2] = Xsplash_e;
2297 if (cave[x-1][y-2] == Xblank)
2298 cave[x-1][y-2] = Xsplash_w;
2299 play_element_sound(x, y, SOUND_acid, Xacid_1);
2303 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2304 play_element_sound(x, y, SOUND_eater, Xeater_n);
2309 static void Leater_e(int x, int y)
2311 if (cave[x][y+1] == Xdiamond)
2313 cave[x][y+1] = Ydiamond_blank;
2314 next[x][y+1] = Xblank;
2315 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2319 if (cave[x-1][y] == Xdiamond)
2321 cave[x-1][y] = Ydiamond_blank;
2322 next[x-1][y] = Xblank;
2323 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2327 if (cave[x][y-1] == Xdiamond)
2329 cave[x][y-1] = Ydiamond_blank;
2330 next[x][y-1] = Xblank;
2331 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2335 if (cave[x+1][y] == Xdiamond)
2337 cave[x+1][y] = Ydiamond_blank;
2338 next[x+1][y] = Xblank;
2339 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2343 switch (cave[x+1][y])
2359 cave[x][y] = Yeater_eB;
2360 next[x][y] = Xblank;
2361 cave[x+1][y] = Yeater_e;
2362 next[x+1][y] = Xeater_e;
2373 cave[x][y] = Yeater_eB;
2374 next[x][y] = Xblank;
2375 if (cave[x+2][y-1] == Xblank)
2376 cave[x+2][y-1] = Xsplash_e;
2377 if (cave[x][y-1] == Xblank)
2378 cave[x][y-1] = Xsplash_w;
2379 play_element_sound(x, y, SOUND_acid, Xacid_1);
2383 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2384 play_element_sound(x, y, SOUND_eater, Xeater_e);
2389 static void Leater_s(int x, int y)
2391 if (cave[x-1][y] == Xdiamond)
2393 cave[x-1][y] = Ydiamond_blank;
2394 next[x-1][y] = Xblank;
2395 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2399 if (cave[x][y-1] == Xdiamond)
2401 cave[x][y-1] = Ydiamond_blank;
2402 next[x][y-1] = Xblank;
2403 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2407 if (cave[x+1][y] == Xdiamond)
2409 cave[x+1][y] = Ydiamond_blank;
2410 next[x+1][y] = Xblank;
2411 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2415 if (cave[x][y+1] == Xdiamond)
2417 cave[x][y+1] = Ydiamond_blank;
2418 next[x][y+1] = Xblank;
2419 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2423 switch (cave[x][y+1])
2439 cave[x][y] = Yeater_sB;
2440 next[x][y] = Xblank;
2441 cave[x][y+1] = Yeater_s;
2442 next[x][y+1] = Xeater_s;
2453 cave[x][y] = Yeater_sB;
2454 next[x][y] = Xblank;
2455 if (cave[x+1][y] == Xblank)
2456 cave[x+1][y] = Xsplash_e;
2457 if (cave[x-1][y] == Xblank)
2458 cave[x-1][y] = Xsplash_w;
2459 play_element_sound(x, y, SOUND_acid, Xacid_1);
2463 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2464 play_element_sound(x, y, SOUND_eater, Xeater_s);
2469 static void Leater_w(int x, int y)
2471 if (cave[x][y-1] == Xdiamond)
2473 cave[x][y-1] = Ydiamond_blank;
2474 next[x][y-1] = Xblank;
2475 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2479 if (cave[x+1][y] == Xdiamond)
2481 cave[x+1][y] = Ydiamond_blank;
2482 next[x+1][y] = Xblank;
2483 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2487 if (cave[x][y+1] == Xdiamond)
2489 cave[x][y+1] = Ydiamond_blank;
2490 next[x][y+1] = Xblank;
2491 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2495 if (cave[x-1][y] == Xdiamond)
2497 cave[x-1][y] = Ydiamond_blank;
2498 next[x-1][y] = Xblank;
2499 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2503 switch (cave[x-1][y])
2519 cave[x][y] = Yeater_wB;
2520 next[x][y] = Xblank;
2521 cave[x-1][y] = Yeater_w;
2522 next[x-1][y] = Xeater_w;
2533 cave[x][y] = Yeater_wB;
2534 next[x][y] = Xblank;
2535 if (cave[x][y-1] == Xblank)
2536 cave[x][y-1] = Xsplash_e;
2537 if (cave[x-2][y-1] == Xblank)
2538 cave[x-2][y-1] = Xsplash_w;
2539 play_element_sound(x, y, SOUND_acid, Xacid_1);
2543 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2544 play_element_sound(x, y, SOUND_eater, Xeater_w);
2549 static void Lalien(int x, int y)
2560 set_nearest_player_xy(x, y, &dx, &dy);
2567 switch (cave[x][y-1])
2583 cave[x][y] = Yalien_nB;
2584 next[x][y] = Xblank;
2585 cave[x][y-1] = Yalien_n;
2586 next[x][y-1] = Xalien_pause;
2587 play_element_sound(x, y, SOUND_alien, Xalien);
2598 cave[x][y] = Yalien_nB;
2599 next[x][y] = Xblank;
2600 if (cave[x+1][y-2] == Xblank)
2601 cave[x+1][y-2] = Xsplash_e;
2602 if (cave[x-1][y-2] == Xblank)
2603 cave[x-1][y-2] = Xsplash_w;
2604 play_element_sound(x, y, SOUND_acid, Xacid_1);
2610 switch (cave[x][y+1])
2626 cave[x][y] = Yalien_sB;
2627 next[x][y] = Xblank;
2628 cave[x][y+1] = Yalien_s;
2629 next[x][y+1] = Xalien_pause;
2630 play_element_sound(x, y, SOUND_alien, Xalien);
2641 cave[x][y] = Yalien_sB;
2642 next[x][y] = Xblank;
2643 if (cave[x+1][y] == Xblank)
2644 cave[x+1][y] = Xsplash_e;
2645 if (cave[x-1][y] == Xblank)
2646 cave[x-1][y] = Xsplash_w;
2647 play_element_sound(x, y, SOUND_acid, Xacid_1);
2656 switch (cave[x+1][y])
2672 cave[x][y] = Yalien_eB;
2673 next[x][y] = Xblank;
2674 cave[x+1][y] = Yalien_e;
2675 next[x+1][y] = Xalien_pause;
2676 play_element_sound(x, y, SOUND_alien, Xalien);
2687 cave[x][y] = Yalien_eB;
2688 next[x][y] = Xblank;
2689 if (cave[x+2][y-1] == Xblank)
2690 cave[x+2][y-1] = Xsplash_e;
2691 if (cave[x][y-1] == Xblank)
2692 cave[x][y-1] = Xsplash_w;
2693 play_element_sound(x, y, SOUND_acid, Xacid_1);
2699 switch (cave[x-1][y])
2715 cave[x][y] = Yalien_wB;
2716 next[x][y] = Xblank;
2717 cave[x-1][y] = Yalien_w;
2718 next[x-1][y] = Xalien_pause;
2719 play_element_sound(x, y, SOUND_alien, Xalien);
2730 cave[x][y] = Yalien_wB;
2731 next[x][y] = Xblank;
2732 if (cave[x][y-1] == Xblank)
2733 cave[x][y-1] = Xsplash_e;
2734 if (cave[x-2][y-1] == Xblank)
2735 cave[x-2][y-1] = Xsplash_w;
2736 play_element_sound(x, y, SOUND_acid, Xacid_1);
2743 static void Lalien_pause(int x, int y)
2745 next[x][y] = Xalien;
2748 static void Lbug_n(int x, int y)
2750 switch (cave[x][y-1])
2766 cave[x][y] = Ybug_nB;
2767 next[x][y] = Xblank;
2768 cave[x][y-1] = Ybug_n;
2769 next[x][y-1] = Xbug_1_n;
2770 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2781 cave[x][y] = Ybug_nB;
2782 next[x][y] = Xblank;
2783 if (cave[x+1][y-2] == Xblank)
2784 cave[x+1][y-2] = Xsplash_e;
2785 if (cave[x-1][y-2] == Xblank)
2786 cave[x-1][y-2] = Xsplash_w;
2787 play_element_sound(x, y, SOUND_acid, Xacid_1);
2791 cave[x][y] = Ybug_n_w;
2792 next[x][y] = Xbug_2_w;
2793 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2798 static void Lbug_1_n(int x, int y)
2800 if (is_amoeba[cave[x][y-1]] ||
2801 is_amoeba[cave[x+1][y]] ||
2802 is_amoeba[cave[x][y+1]] ||
2803 is_amoeba[cave[x-1][y]])
2805 Lboom_bug(x, y, Xbug_1_n);
2810 switch (cave[x+1][y])
2834 cave[x][y] = Ybug_n_e;
2835 next[x][y] = Xbug_2_e;
2836 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2845 static void Lbug_2_n(int x, int y)
2847 if (is_amoeba[cave[x][y-1]] ||
2848 is_amoeba[cave[x+1][y]] ||
2849 is_amoeba[cave[x][y+1]] ||
2850 is_amoeba[cave[x-1][y]])
2852 Lboom_bug(x, y, Xbug_2_n);
2860 static void Lbug_e(int x, int y)
2862 switch (cave[x+1][y])
2878 cave[x][y] = Ybug_eB;
2879 next[x][y] = Xblank;
2880 cave[x+1][y] = Ybug_e;
2881 next[x+1][y] = Xbug_1_e;
2882 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2893 cave[x][y] = Ybug_eB;
2894 next[x][y] = Xblank;
2895 if (cave[x+2][y-1] == Xblank)
2896 cave[x+2][y-1] = Xsplash_e;
2897 if (cave[x][y-1] == Xblank)
2898 cave[x][y-1] = Xsplash_w;
2899 play_element_sound(x, y, SOUND_acid, Xacid_1);
2903 cave[x][y] = Ybug_e_n;
2904 next[x][y] = Xbug_2_n;
2905 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2910 static void Lbug_1_e(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]])
2917 Lboom_bug(x, y, Xbug_1_e);
2922 switch (cave[x][y+1])
2946 cave[x][y] = Ybug_e_s;
2947 next[x][y] = Xbug_2_s;
2948 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2957 static void Lbug_2_e(int x, int y)
2959 if (is_amoeba[cave[x][y-1]] ||
2960 is_amoeba[cave[x+1][y]] ||
2961 is_amoeba[cave[x][y+1]] ||
2962 is_amoeba[cave[x-1][y]])
2964 Lboom_bug(x, y, Xbug_2_e);
2972 static void Lbug_s(int x, int y)
2974 switch (cave[x][y+1])
2990 cave[x][y] = Ybug_sB;
2991 next[x][y] = Xblank;
2992 cave[x][y+1] = Ybug_s;
2993 next[x][y+1] = Xbug_1_s;
2994 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3005 cave[x][y] = Ybug_sB;
3006 next[x][y] = Xblank;
3007 if (cave[x+1][y] == Xblank)
3008 cave[x+1][y] = Xsplash_e;
3009 if (cave[x-1][y] == Xblank)
3010 cave[x-1][y] = Xsplash_w;
3011 play_element_sound(x, y, SOUND_acid, Xacid_1);
3015 cave[x][y] = Ybug_s_e;
3016 next[x][y] = Xbug_2_e;
3017 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3022 static void Lbug_1_s(int x, int y)
3024 if (is_amoeba[cave[x][y-1]] ||
3025 is_amoeba[cave[x+1][y]] ||
3026 is_amoeba[cave[x][y+1]] ||
3027 is_amoeba[cave[x-1][y]])
3029 Lboom_bug(x, y, Xbug_1_s);
3034 switch (cave[x-1][y])
3058 cave[x][y] = Ybug_s_w;
3059 next[x][y] = Xbug_2_w;
3060 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3069 static void Lbug_2_s(int x, int y)
3071 if (is_amoeba[cave[x][y-1]] ||
3072 is_amoeba[cave[x+1][y]] ||
3073 is_amoeba[cave[x][y+1]] ||
3074 is_amoeba[cave[x-1][y]])
3076 Lboom_bug(x, y, Xbug_2_s);
3084 static void Lbug_w(int x, int y)
3086 switch (cave[x-1][y])
3102 cave[x][y] = Ybug_wB;
3103 next[x][y] = Xblank;
3104 cave[x-1][y] = Ybug_w;
3105 next[x-1][y] = Xbug_1_w;
3106 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3117 cave[x][y] = Ybug_wB;
3118 next[x][y] = Xblank;
3119 if (cave[x][y-1] == Xblank)
3120 cave[x][y-1] = Xsplash_e;
3121 if (cave[x-2][y-1] == Xblank)
3122 cave[x-2][y-1] = Xsplash_w;
3123 play_element_sound(x, y, SOUND_acid, Xacid_1);
3127 cave[x][y] = Ybug_w_s;
3128 next[x][y] = Xbug_2_s;
3129 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3134 static void Lbug_1_w(int x, int y)
3136 if (is_amoeba[cave[x][y-1]] ||
3137 is_amoeba[cave[x+1][y]] ||
3138 is_amoeba[cave[x][y+1]] ||
3139 is_amoeba[cave[x-1][y]])
3141 Lboom_bug(x, y, Xbug_1_w);
3146 switch (cave[x][y-1])
3170 cave[x][y] = Ybug_w_n;
3171 next[x][y] = Xbug_2_n;
3172 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3181 static void Lbug_2_w(int x, int y)
3183 if (is_amoeba[cave[x][y-1]] ||
3184 is_amoeba[cave[x+1][y]] ||
3185 is_amoeba[cave[x][y+1]] ||
3186 is_amoeba[cave[x-1][y]])
3188 Lboom_bug(x, y, Xbug_2_w);
3196 static void Ltank_n(int x, int y)
3198 switch (cave[x][y-1])
3214 cave[x][y] = Ytank_nB;
3215 next[x][y] = Xblank;
3216 cave[x][y-1] = Ytank_n;
3217 next[x][y-1] = Xtank_1_n;
3218 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3229 cave[x][y] = Ytank_nB;
3230 next[x][y] = Xblank;
3231 if (cave[x+1][y-2] == Xblank)
3232 cave[x+1][y-2] = Xsplash_e;
3233 if (cave[x-1][y-2] == Xblank)
3234 cave[x-1][y-2] = Xsplash_w;
3235 play_element_sound(x, y, SOUND_acid, Xacid_1);
3239 cave[x][y] = Ytank_n_e;
3240 next[x][y] = Xtank_2_e;
3241 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3246 static void Ltank_1_n(int x, int y)
3248 if (is_amoeba[cave[x][y-1]] ||
3249 is_amoeba[cave[x+1][y]] ||
3250 is_amoeba[cave[x][y+1]] ||
3251 is_amoeba[cave[x-1][y]])
3253 Lboom_tank(x, y, Xtank_1_n);
3258 switch (cave[x-1][y])
3282 cave[x][y] = Ytank_n_w;
3283 next[x][y] = Xtank_2_w;
3284 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3293 static void Ltank_2_n(int x, int y)
3295 if (is_amoeba[cave[x][y-1]] ||
3296 is_amoeba[cave[x+1][y]] ||
3297 is_amoeba[cave[x][y+1]] ||
3298 is_amoeba[cave[x-1][y]])
3300 Lboom_tank(x, y, Xtank_2_n);
3308 static void Ltank_e(int x, int y)
3310 switch (cave[x+1][y])
3326 cave[x][y] = Ytank_eB;
3327 next[x][y] = Xblank;
3328 cave[x+1][y] = Ytank_e;
3329 next[x+1][y] = Xtank_1_e;
3330 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3341 cave[x][y] = Ytank_eB;
3342 next[x][y] = Xblank;
3343 if (cave[x+2][y-1] == Xblank)
3344 cave[x+2][y-1] = Xsplash_e;
3345 if (cave[x][y-1] == Xblank)
3346 cave[x][y-1] = Xsplash_w;
3347 play_element_sound(x, y, SOUND_acid, Xacid_1);
3351 cave[x][y] = Ytank_e_s;
3352 next[x][y] = Xtank_2_s;
3353 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3358 static void Ltank_1_e(int x, int y)
3360 if (is_amoeba[cave[x][y-1]] ||
3361 is_amoeba[cave[x+1][y]] ||
3362 is_amoeba[cave[x][y+1]] ||
3363 is_amoeba[cave[x-1][y]])
3365 Lboom_tank(x, y, Xtank_1_e);
3370 switch (cave[x][y-1])
3394 cave[x][y] = Ytank_e_n;
3395 next[x][y] = Xtank_2_n;
3396 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3405 static void Ltank_2_e(int x, int y)
3407 if (is_amoeba[cave[x][y-1]] ||
3408 is_amoeba[cave[x+1][y]] ||
3409 is_amoeba[cave[x][y+1]] ||
3410 is_amoeba[cave[x-1][y]])
3412 Lboom_tank(x, y, Xtank_2_e);
3420 static void Ltank_s(int x, int y)
3422 switch (cave[x][y+1])
3438 cave[x][y] = Ytank_sB;
3439 next[x][y] = Xblank;
3440 cave[x][y+1] = Ytank_s;
3441 next[x][y+1] = Xtank_1_s;
3442 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3453 cave[x][y] = Ytank_sB;
3454 next[x][y] = Xblank;
3455 if (cave[x+1][y] == Xblank)
3456 cave[x+1][y] = Xsplash_e;
3457 if (cave[x-1][y] == Xblank)
3458 cave[x-1][y] = Xsplash_w;
3459 play_element_sound(x, y, SOUND_acid, Xacid_1);
3463 cave[x][y] = Ytank_s_w;
3464 next[x][y] = Xtank_2_w;
3465 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3470 static void Ltank_1_s(int x, int y)
3472 if (is_amoeba[cave[x][y-1]] ||
3473 is_amoeba[cave[x+1][y]] ||
3474 is_amoeba[cave[x][y+1]] ||
3475 is_amoeba[cave[x-1][y]])
3477 Lboom_tank(x, y, Xtank_1_s);
3482 switch (cave[x+1][y])
3506 cave[x][y] = Ytank_s_e;
3507 next[x][y] = Xtank_2_e;
3508 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3517 static void Ltank_2_s(int x, int y)
3519 if (is_amoeba[cave[x][y-1]] ||
3520 is_amoeba[cave[x+1][y]] ||
3521 is_amoeba[cave[x][y+1]] ||
3522 is_amoeba[cave[x-1][y]])
3524 Lboom_tank(x, y, Xtank_2_s);
3532 static void Ltank_w(int x, int y)
3534 switch (cave[x-1][y])
3550 cave[x][y] = Ytank_wB;
3551 next[x][y] = Xblank;
3552 cave[x-1][y] = Ytank_w;
3553 next[x-1][y] = Xtank_1_w;
3554 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3565 cave[x][y] = Ytank_wB;
3566 next[x][y] = Xblank;
3567 if (cave[x][y-1] == Xblank)
3568 cave[x][y-1] = Xsplash_e;
3569 if (cave[x-2][y-1] == Xblank)
3570 cave[x-2][y-1] = Xsplash_w;
3571 play_element_sound(x, y, SOUND_acid, Xacid_1);
3575 cave[x][y] = Ytank_w_n;
3576 next[x][y] = Xtank_2_n;
3577 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3582 static void Ltank_1_w(int x, int y)
3584 if (is_amoeba[cave[x][y-1]] ||
3585 is_amoeba[cave[x+1][y]] ||
3586 is_amoeba[cave[x][y+1]] ||
3587 is_amoeba[cave[x-1][y]])
3589 Lboom_tank(x, y, Xtank_1_w);
3594 switch (cave[x][y+1])
3618 cave[x][y] = Ytank_w_s;
3619 next[x][y] = Xtank_2_s;
3620 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3629 static void Ltank_2_w(int x, int y)
3631 if (is_amoeba[cave[x][y-1]] ||
3632 is_amoeba[cave[x+1][y]] ||
3633 is_amoeba[cave[x][y+1]] ||
3634 is_amoeba[cave[x-1][y]])
3636 Lboom_tank(x, y, Xtank_2_w);
3644 static void Lemerald(int x, int y)
3646 switch (cave[x][y+1])
3659 cave[x][y] = Yemerald_sB;
3660 next[x][y] = Xblank;
3661 cave[x][y+1] = Yemerald_s;
3662 next[x][y+1] = Xemerald_fall;
3673 cave[x][y] = Yemerald_sB;
3674 next[x][y] = Xblank;
3675 if (cave[x+1][y] == Xblank)
3676 cave[x+1][y] = Xsplash_e;
3677 if (cave[x-1][y] == Xblank)
3678 cave[x-1][y] = Xsplash_w;
3679 play_element_sound(x, y, SOUND_acid, Xacid_1);
3692 case Xemerald_pause:
3694 case Xdiamond_pause:
3738 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3740 cave[x][y] = Yemerald_eB;
3741 next[x][y] = Xblank;
3742 cave[x+1][y] = Yemerald_e;
3743 next[x+1][y] = Xemerald_pause;
3744 if (cave[x][y+1] == Xbumper)
3745 cave[x][y+1] = Ybumper;
3749 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3751 cave[x][y] = Yemerald_wB;
3752 next[x][y] = Xblank;
3753 cave[x-1][y] = Yemerald_w;
3754 next[x-1][y] = Xemerald_pause;
3755 if (cave[x][y+1] == Xbumper)
3756 cave[x][y+1] = Ybumper;
3762 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3764 cave[x][y] = Yemerald_wB;
3765 next[x][y] = Xblank;
3766 cave[x-1][y] = Yemerald_w;
3767 next[x-1][y] = Xemerald_pause;
3768 if (cave[x][y+1] == Xbumper)
3769 cave[x][y+1] = Ybumper;
3773 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3775 cave[x][y] = Yemerald_eB;
3776 next[x][y] = Xblank;
3777 cave[x+1][y] = Yemerald_e;
3778 next[x+1][y] = Xemerald_pause;
3779 if (cave[x][y+1] == Xbumper)
3780 cave[x][y+1] = Ybumper;
3786 if (++lev.shine_cnt > 50)
3788 lev.shine_cnt = RANDOM(8);
3789 cave[x][y] = Xemerald_shine;
3796 static void Lemerald_pause(int x, int y)
3798 switch (cave[x][y+1])
3811 cave[x][y] = Yemerald_sB;
3812 next[x][y] = Xblank;
3813 cave[x][y+1] = Yemerald_s;
3814 next[x][y+1] = Xemerald_fall;
3825 cave[x][y] = Yemerald_sB;
3826 next[x][y] = Xblank;
3827 if (cave[x+1][y] == Xblank)
3828 cave[x+1][y] = Xsplash_e;
3829 if (cave[x-1][y] == Xblank)
3830 cave[x-1][y] = Xsplash_w;
3831 play_element_sound(x, y, SOUND_acid, Xacid_1);
3835 cave[x][y] = Xemerald;
3836 next[x][y] = Xemerald;
3841 static void Lemerald_fall(int x, int y)
3843 switch (cave[x][y+1])
3857 cave[x][y] = Yemerald_sB;
3858 next[x][y] = Xblank;
3859 cave[x][y+1] = Yemerald_s;
3860 next[x][y+1] = Xemerald_fall;
3871 cave[x][y] = Yemerald_sB;
3872 next[x][y] = Xblank;
3873 if (cave[x+1][y] == Xblank)
3874 cave[x+1][y] = Xsplash_e;
3875 if (cave[x-1][y] == Xblank)
3876 cave[x-1][y] = Xsplash_w;
3877 play_element_sound(x, y, SOUND_acid, Xacid_1);
3881 if (lev.wonderwall_time)
3883 lev.wonderwall_state = 1;
3884 cave[x][y] = Yemerald_sB;
3885 next[x][y] = Xblank;
3886 if (is_blank[cave[x][y+2]])
3888 cave[x][y+2] = Ydiamond_s;
3889 next[x][y+2] = Xdiamond_fall;
3891 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
3896 cave[x][y] = Xemerald;
3897 next[x][y] = Xemerald;
3898 play_element_sound(x, y, SOUND_diamond, Xemerald);
3903 static void Ldiamond(int x, int y)
3905 switch (cave[x][y+1])
3918 cave[x][y] = Ydiamond_sB;
3919 next[x][y] = Xblank;
3920 cave[x][y+1] = Ydiamond_s;
3921 next[x][y+1] = Xdiamond_fall;
3932 cave[x][y] = Ydiamond_sB;
3933 next[x][y] = Xblank;
3934 if (cave[x+1][y] == Xblank)
3935 cave[x+1][y] = Xsplash_e;
3936 if (cave[x-1][y] == Xblank)
3937 cave[x-1][y] = Xsplash_w;
3938 play_element_sound(x, y, SOUND_acid, Xacid_1);
3951 case Xemerald_pause:
3953 case Xdiamond_pause:
3997 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3999 cave[x][y] = Ydiamond_eB;
4000 next[x][y] = Xblank;
4001 cave[x+1][y] = Ydiamond_e;
4002 next[x+1][y] = Xdiamond_pause;
4003 if (cave[x][y+1] == Xbumper)
4004 cave[x][y+1] = Ybumper;
4008 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4010 cave[x][y] = Ydiamond_wB;
4011 next[x][y] = Xblank;
4012 cave[x-1][y] = Ydiamond_w;
4013 next[x-1][y] = Xdiamond_pause;
4014 if (cave[x][y+1] == Xbumper)
4015 cave[x][y+1] = Ybumper;
4021 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4023 cave[x][y] = Ydiamond_wB;
4024 next[x][y] = Xblank;
4025 cave[x-1][y] = Ydiamond_w;
4026 next[x-1][y] = Xdiamond_pause;
4027 if (cave[x][y+1] == Xbumper)
4028 cave[x][y+1] = Ybumper;
4032 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4034 cave[x][y] = Ydiamond_eB;
4035 next[x][y] = Xblank;
4036 cave[x+1][y] = Ydiamond_e;
4037 next[x+1][y] = Xdiamond_pause;
4038 if (cave[x][y+1] == Xbumper)
4039 cave[x][y+1] = Ybumper;
4045 if (++lev.shine_cnt > 50)
4047 lev.shine_cnt = RANDOM(8);
4048 cave[x][y] = Xdiamond_shine;
4055 static void Ldiamond_pause(int x, int y)
4057 switch (cave[x][y+1])
4070 cave[x][y] = Ydiamond_sB;
4071 next[x][y] = Xblank;
4072 cave[x][y+1] = Ydiamond_s;
4073 next[x][y+1] = Xdiamond_fall;
4084 cave[x][y] = Ydiamond_sB;
4085 next[x][y] = Xblank;
4086 if (cave[x+1][y] == Xblank)
4087 cave[x+1][y] = Xsplash_e;
4088 if (cave[x-1][y] == Xblank)
4089 cave[x-1][y] = Xsplash_w;
4090 play_element_sound(x, y, SOUND_acid, Xacid_1);
4094 cave[x][y] = Xdiamond;
4095 next[x][y] = Xdiamond;
4100 static void Ldiamond_fall(int x, int y)
4102 switch (cave[x][y+1])
4116 cave[x][y] = Ydiamond_sB;
4117 next[x][y] = Xblank;
4118 cave[x][y+1] = Ydiamond_s;
4119 next[x][y+1] = Xdiamond_fall;
4130 cave[x][y] = Ydiamond_sB;
4131 next[x][y] = Xblank;
4132 if (cave[x+1][y] == Xblank)
4133 cave[x+1][y] = Xsplash_e;
4134 if (cave[x-1][y] == Xblank)
4135 cave[x-1][y] = Xsplash_w;
4136 play_element_sound(x, y, SOUND_acid, Xacid_1);
4140 if (lev.wonderwall_time)
4142 lev.wonderwall_state = 1;
4143 cave[x][y] = Ydiamond_sB;
4144 next[x][y] = Xblank;
4145 if (is_blank[cave[x][y+2]])
4147 cave[x][y+2] = Ystone_s;
4148 next[x][y+2] = Xstone_fall;
4150 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4155 cave[x][y] = Xdiamond;
4156 next[x][y] = Xdiamond;
4157 play_element_sound(x, y, SOUND_diamond, Xdiamond);
4162 static void Lstone(int x, int y)
4164 switch (cave[x][y+1])
4179 cave[x][y] = Ystone_sB;
4180 next[x][y] = Xblank;
4181 cave[x][y+1] = Ystone_s;
4182 next[x][y+1] = Xstone_fall;
4193 cave[x][y] = Ystone_sB;
4194 next[x][y] = Xblank;
4195 if (cave[x+1][y] == Xblank)
4196 cave[x+1][y] = Xsplash_e;
4197 if (cave[x-1][y] == Xblank)
4198 cave[x-1][y] = Xsplash_w;
4199 play_element_sound(x, y, SOUND_acid, Xacid_1);
4203 cave[x][y] = Xsand_stonein_1;
4204 next[x][y] = Xsand_stonein_2;
4205 cave[x][y+1] = Xsand_sandstone_1;
4206 next[x][y+1] = Xsand_sandstone_2;
4219 case Xemerald_pause:
4221 case Xdiamond_pause:
4258 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4260 cave[x][y] = Ystone_eB;
4261 next[x][y] = Xblank;
4262 cave[x+1][y] = Ystone_e;
4263 next[x+1][y] = Xstone_pause;
4264 if (cave[x][y+1] == Xbumper)
4265 cave[x][y+1] = Ybumper;
4269 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4271 cave[x][y] = Ystone_wB;
4272 next[x][y] = Xblank;
4273 cave[x-1][y] = Ystone_w;
4274 next[x-1][y] = Xstone_pause;
4275 if (cave[x][y+1] == Xbumper)
4276 cave[x][y+1] = Ybumper;
4282 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4284 cave[x][y] = Ystone_wB;
4285 next[x][y] = Xblank;
4286 cave[x-1][y] = Ystone_w;
4287 next[x-1][y] = Xstone_pause;
4288 if (cave[x][y+1] == Xbumper)
4289 cave[x][y+1] = Ybumper;
4293 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4295 cave[x][y] = Ystone_eB;
4296 next[x][y] = Xblank;
4297 cave[x+1][y] = Ystone_e;
4298 next[x+1][y] = Xstone_pause;
4299 if (cave[x][y+1] == Xbumper)
4300 cave[x][y+1] = Ybumper;
4307 static void Lstone_pause(int x, int y)
4309 switch (cave[x][y+1])
4322 cave[x][y] = Ystone_sB;
4323 next[x][y] = Xblank;
4324 cave[x][y+1] = Ystone_s;
4325 next[x][y+1] = Xstone_fall;
4336 cave[x][y] = Ystone_sB;
4337 next[x][y] = Xblank;
4338 if (cave[x+1][y] == Xblank)
4339 cave[x+1][y] = Xsplash_e;
4340 if (cave[x-1][y] == Xblank)
4341 cave[x-1][y] = Xsplash_w;
4342 play_element_sound(x, y, SOUND_acid, Xacid_1);
4346 cave[x][y] = Xstone;
4347 next[x][y] = Xstone;
4352 static void Lstone_fall(int x, int y)
4354 switch (cave[x][y+1])
4368 cave[x][y] = Ystone_sB;
4369 next[x][y] = Xblank;
4370 cave[x][y+1] = Ystone_s;
4371 next[x][y+1] = Xstone_fall;
4382 cave[x][y] = Ystone_sB;
4383 next[x][y] = Xblank;
4384 if (cave[x+1][y] == Xblank)
4385 cave[x+1][y] = Xsplash_e;
4386 if (cave[x-1][y] == Xblank)
4387 cave[x-1][y] = Xsplash_w;
4388 play_element_sound(x, y, SOUND_acid, Xacid_1);
4395 cave[x][y] = Ystone_sB;
4396 cave[x][y+1] = Yeater_stone;
4397 Lboom_eater(x, y+1, Xstone_fall);
4398 score += lev.eater_score;
4403 cave[x][y] = Ystone_sB;
4404 cave[x][y+1] = Yalien_stone;
4405 Lboom_tank(x, y+1, Xstone_fall);
4406 score += lev.alien_score;
4417 cave[x][y] = Ystone_sB;
4418 cave[x][y+1] = Ybug_stone;
4419 Lboom_bug(x, y+1, Xstone_fall);
4420 score += lev.bug_score;
4431 cave[x][y] = Ystone_sB;
4432 cave[x][y+1] = Ytank_stone;
4433 Lboom_tank(x, y+1, Xstone_fall);
4434 score += lev.tank_score;
4438 case Xdiamond_pause:
4439 switch (cave[x][y+2])
4495 next[x][y] = Xstone;
4496 play_element_sound(x, y, SOUND_stone, Xstone);
4500 cave[x][y] = Ystone_sB;
4501 next[x][y] = Xblank;
4502 cave[x][y+1] = Ydiamond_stone;
4503 next[x][y+1] = Xstone_pause;
4504 play_element_sound(x, y, SOUND_squash, Xdiamond);
4509 cave[x][y+1] = Ybomb_blank;
4510 Lboom_tank(x, y+1, Xstone_fall);
4515 next[x][y] = Xstone;
4516 cave[x][y+1] = Ynut_stone;
4517 next[x][y+1] = Xemerald;
4518 play_element_sound(x, y, SOUND_crack, Xnut);
4519 score += lev.nut_score;
4525 switch (cave[x+1][y+1])
4540 cave[x][y+1] = Xspring_e;
4544 cave[x][y+1] = Xspring_w;
4550 switch (cave[x-1][y+1])
4565 cave[x][y+1] = Xspring_w;
4568 cave[x][y+1] = Xspring_e;
4573 next[x][y] = Xstone;
4577 if (lev.wonderwall_time)
4579 lev.wonderwall_state = 1;
4580 cave[x][y] = Ystone_sB;
4581 next[x][y] = Xblank;
4582 if (is_blank[cave[x][y+2]])
4584 cave[x][y+2] = Yemerald_s;
4585 next[x][y+2] = Xemerald_fall;
4587 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4592 cave[x][y] = Xstone;
4593 next[x][y] = Xstone;
4594 play_element_sound(x, y, SOUND_stone, Xstone);
4599 static void Lbomb(int x, int y)
4601 switch (cave[x][y+1])
4614 cave[x][y] = Ybomb_sB;
4615 next[x][y] = Xblank;
4616 cave[x][y+1] = Ybomb_s;
4617 next[x][y+1] = Xbomb_fall;
4628 cave[x][y] = Ybomb_sB;
4629 next[x][y] = Xblank;
4630 if (cave[x+1][y] == Xblank)
4631 cave[x+1][y] = Xsplash_e;
4632 if (cave[x-1][y] == Xblank)
4633 cave[x-1][y] = Xsplash_w;
4634 play_element_sound(x, y, SOUND_acid, Xacid_1);
4647 case Xemerald_pause:
4649 case Xdiamond_pause:
4684 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4686 cave[x][y] = Ybomb_eB;
4687 next[x][y] = Xblank;
4688 cave[x+1][y] = Ybomb_e;
4689 next[x+1][y] = Xbomb_pause;
4690 if (cave[x][y+1] == Xbumper)
4691 cave[x][y+1] = Ybumper;
4695 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4697 cave[x][y] = Ybomb_wB;
4698 next[x][y] = Xblank;
4699 cave[x-1][y] = Ybomb_w;
4700 next[x-1][y] = Xbomb_pause;
4701 if (cave[x][y+1] == Xbumper)
4702 cave[x][y+1] = Ybumper;
4708 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4710 cave[x][y] = Ybomb_wB;
4711 next[x][y] = Xblank;
4712 cave[x-1][y] = Ybomb_w;
4713 next[x-1][y] = Xbomb_pause;
4714 if (cave[x][y+1] == Xbumper)
4715 cave[x][y+1] = Ybumper;
4719 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4721 cave[x][y] = Ybomb_eB;
4722 next[x][y] = Xblank;
4723 cave[x+1][y] = Ybomb_e;
4724 next[x+1][y] = Xbomb_pause;
4725 if (cave[x][y+1] == Xbumper)
4726 cave[x][y+1] = Ybumper;
4733 static void Lbomb_pause(int x, int y)
4735 switch (cave[x][y+1])
4748 cave[x][y] = Ybomb_sB;
4749 next[x][y] = Xblank;
4750 cave[x][y+1] = Ybomb_s;
4751 next[x][y+1] = Xbomb_fall;
4762 cave[x][y] = Ybomb_sB;
4763 next[x][y] = Xblank;
4764 if (cave[x+1][y] == Xblank)
4765 cave[x+1][y] = Xsplash_e;
4766 if (cave[x-1][y] == Xblank)
4767 cave[x-1][y] = Xsplash_w;
4768 play_element_sound(x, y, SOUND_acid, Xacid_1);
4778 static void Lbomb_fall(int x, int y)
4780 switch (cave[x][y+1])
4793 cave[x][y] = Ybomb_sB;
4794 next[x][y] = Xblank;
4795 cave[x][y+1] = Ybomb_s;
4796 next[x][y+1] = Xbomb_fall;
4807 cave[x][y] = Ybomb_sB;
4808 next[x][y] = Xblank;
4809 if (cave[x+1][y] == Xblank)
4810 cave[x+1][y] = Xsplash_e;
4811 if (cave[x-1][y] == Xblank)
4812 cave[x-1][y] = Xsplash_w;
4813 play_element_sound(x, y, SOUND_acid, Xacid_1);
4817 cave[x][y] = Ybomb_blank;
4818 Lboom_tank(x, y, Xbomb_fall);
4823 static void Lnut(int x, int y)
4825 switch (cave[x][y+1])
4838 cave[x][y] = Ynut_sB;
4839 next[x][y] = Xblank;
4840 cave[x][y+1] = Ynut_s;
4841 next[x][y+1] = Xnut_fall;
4852 cave[x][y] = Ynut_sB;
4853 next[x][y] = Xblank;
4854 if (cave[x+1][y] == Xblank)
4855 cave[x+1][y] = Xsplash_e;
4856 if (cave[x-1][y] == Xblank)
4857 cave[x-1][y] = Xsplash_w;
4858 play_element_sound(x, y, SOUND_acid, Xacid_1);
4871 case Xemerald_pause:
4873 case Xdiamond_pause:
4908 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4910 cave[x][y] = Ynut_eB;
4911 next[x][y] = Xblank;
4912 cave[x+1][y] = Ynut_e;
4913 next[x+1][y] = Xnut_pause;
4914 if (cave[x][y+1] == Xbumper)
4915 cave[x][y+1] = Ybumper;
4919 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4921 cave[x][y] = Ynut_wB;
4922 next[x][y] = Xblank;
4923 cave[x-1][y] = Ynut_w;
4924 next[x-1][y] = Xnut_pause;
4925 if (cave[x][y+1] == Xbumper)
4926 cave[x][y+1] = Ybumper;
4932 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4934 cave[x][y] = Ynut_wB;
4935 next[x][y] = Xblank;
4936 cave[x-1][y] = Ynut_w;
4937 next[x-1][y] = Xnut_pause;
4938 if (cave[x][y+1] == Xbumper)
4939 cave[x][y+1] = Ybumper;
4943 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4945 cave[x][y] = Ynut_eB;
4946 next[x][y] = Xblank;
4947 cave[x+1][y] = Ynut_e;
4948 next[x+1][y] = Xnut_pause;
4949 if (cave[x][y+1] == Xbumper)
4950 cave[x][y+1] = Ybumper;
4957 static void Lnut_pause(int x, int y)
4959 switch (cave[x][y+1])
4972 cave[x][y] = Ynut_sB;
4973 next[x][y] = Xblank;
4974 cave[x][y+1] = Ynut_s;
4975 next[x][y+1] = Xnut_fall;
4986 cave[x][y] = Ynut_sB;
4987 next[x][y] = Xblank;
4988 if (cave[x+1][y] == Xblank)
4989 cave[x+1][y] = Xsplash_e;
4990 if (cave[x-1][y] == Xblank)
4991 cave[x-1][y] = Xsplash_w;
4992 play_element_sound(x, y, SOUND_acid, Xacid_1);
5002 static void Lnut_fall(int x, int y)
5004 switch (cave[x][y+1])
5018 cave[x][y] = Ynut_sB;
5019 next[x][y] = Xblank;
5020 cave[x][y+1] = Ynut_s;
5021 next[x][y+1] = Xnut_fall;
5032 cave[x][y] = Ynut_sB;
5033 next[x][y] = Xblank;
5034 if (cave[x+1][y] == Xblank)
5035 cave[x+1][y] = Xsplash_e;
5036 if (cave[x-1][y] == Xblank)
5037 cave[x-1][y] = Xsplash_w;
5038 play_element_sound(x, y, SOUND_acid, Xacid_1);
5044 play_element_sound(x, y, SOUND_nut, Xnut);
5049 static void Lspring(int x, int y)
5051 switch (cave[x][y+1])
5066 cave[x][y] = Yspring_sB;
5067 next[x][y] = Xblank;
5068 cave[x][y+1] = Yspring_s;
5069 next[x][y+1] = Xspring_fall;
5080 cave[x][y] = Yspring_sB;
5081 next[x][y] = Xblank;
5082 if (cave[x+1][y] == Xblank)
5083 cave[x+1][y] = Xsplash_e;
5084 if (cave[x-1][y] == Xblank)
5085 cave[x-1][y] = Xsplash_w;
5086 play_element_sound(x, y, SOUND_acid, Xacid_1);
5099 case Xemerald_pause:
5101 case Xdiamond_pause:
5136 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5138 cave[x][y] = Yspring_eB;
5139 next[x][y] = Xblank;
5140 cave[x+1][y] = Yspring_e;
5142 next[x+1][y] = Xspring_e;
5144 next[x+1][y] = Xspring_pause;
5146 if (cave[x][y+1] == Xbumper)
5147 cave[x][y+1] = Ybumper;
5151 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5153 cave[x][y] = Yspring_wB;
5154 next[x][y] = Xblank;
5155 cave[x-1][y] = Yspring_w;
5157 next[x-1][y] = Xspring_w;
5159 next[x-1][y] = Xspring_pause;
5161 if (cave[x][y+1] == Xbumper)
5162 cave[x][y+1] = Ybumper;
5168 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5170 cave[x][y] = Yspring_wB;
5171 next[x][y] = Xblank;
5172 cave[x-1][y] = Yspring_w;
5174 next[x-1][y] = Xspring_w;
5176 next[x-1][y] = Xspring_pause;
5178 if (cave[x][y+1] == Xbumper)
5179 cave[x][y+1] = Ybumper;
5183 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5185 cave[x][y] = Yspring_eB;
5186 next[x][y] = Xblank;
5187 cave[x+1][y] = Yspring_e;
5189 next[x+1][y] = Xspring_e;
5191 next[x+1][y] = Xspring_pause;
5193 if (cave[x][y+1] == Xbumper)
5194 cave[x][y+1] = Ybumper;
5201 static void Lspring_pause(int x, int y)
5203 switch (cave[x][y+1])
5216 cave[x][y] = Yspring_sB;
5217 next[x][y] = Xblank;
5218 cave[x][y+1] = Yspring_s;
5219 next[x][y+1] = Xspring_fall;
5230 cave[x][y] = Yspring_sB;
5231 next[x][y] = Xblank;
5232 if (cave[x+1][y] == Xblank)
5233 cave[x+1][y] = Xsplash_e;
5234 if (cave[x-1][y] == Xblank)
5235 cave[x-1][y] = Xsplash_w;
5236 play_element_sound(x, y, SOUND_acid, Xacid_1);
5240 cave[x][y] = Xspring;
5241 next[x][y] = Xspring;
5246 static void Lspring_e(int x, int y)
5248 switch (cave[x][y+1])
5261 cave[x][y] = Yspring_sB;
5262 next[x][y] = Xblank;
5263 cave[x][y+1] = Yspring_s;
5264 next[x][y+1] = Xspring_fall;
5275 cave[x][y] = Yspring_sB;
5276 next[x][y] = Xblank;
5277 if (cave[x+1][y] == Xblank)
5278 cave[x+1][y] = Xsplash_e;
5279 if (cave[x-1][y] == Xblank)
5280 cave[x-1][y] = Xsplash_w;
5281 play_element_sound(x, y, SOUND_acid, Xacid_1);
5285 cave[x][y+1] = Ybumper;
5288 switch (cave[x+1][y])
5305 cave[x][y] = Yspring_eB;
5306 next[x][y] = Xblank;
5307 cave[x+1][y] = Yspring_e;
5308 next[x+1][y] = Xspring_e;
5319 cave[x][y] = Yspring_eB;
5320 next[x][y] = Xblank;
5321 if (cave[x+2][y-1] == Xblank)
5322 cave[x+2][y-1] = Xsplash_e;
5323 if (cave[x][y-1] == Xblank)
5324 cave[x][y-1] = Xsplash_w;
5325 play_element_sound(x, y, SOUND_acid, Xacid_1);
5334 cave[x][y] = Yspring_alien_eB;
5335 next[x][y] = Xblank;
5336 cave[x+1][y] = Yspring_alien_e;
5337 next[x+1][y] = Xspring_e;
5338 play_element_sound(x, y, SOUND_slurp, Xalien);
5339 score += lev.slurp_score;
5344 cave[x+1][y] = Ybumper;
5345 next[x][y] = Xspring_w;
5346 play_element_sound(x, y, SOUND_spring, Xspring);
5350 cave[x][y] = Xspring;
5351 next[x][y] = Xspring;
5352 play_element_sound(x, y, SOUND_spring, Xspring);
5357 static void Lspring_w(int x, int y)
5359 switch (cave[x][y+1])
5372 cave[x][y] = Yspring_sB;
5373 next[x][y] = Xblank;
5374 cave[x][y+1] = Yspring_s;
5375 next[x][y+1] = Xspring_fall;
5386 cave[x][y] = Yspring_sB;
5387 next[x][y] = Xblank;
5388 if (cave[x+1][y] == Xblank)
5389 cave[x+1][y] = Xsplash_e;
5390 if (cave[x-1][y] == Xblank)
5391 cave[x-1][y] = Xsplash_w;
5392 play_element_sound(x, y, SOUND_acid, Xacid_1);
5396 cave[x][y+1] = Ybumper;
5399 switch (cave[x-1][y])
5416 cave[x][y] = Yspring_wB;
5417 next[x][y] = Xblank;
5418 cave[x-1][y] = Yspring_w;
5419 next[x-1][y] = Xspring_w;
5430 cave[x][y] = Yspring_wB;
5431 next[x][y] = Xblank;
5432 if (cave[x][y-1] == Xblank)
5433 cave[x][y-1] = Xsplash_e;
5434 if (cave[x-2][y-1] == Xblank)
5435 cave[x-2][y-1] = Xsplash_w;
5436 play_element_sound(x, y, SOUND_acid, Xacid_1);
5445 cave[x][y] = Yspring_alien_wB;
5446 next[x][y] = Xblank;
5447 cave[x-1][y] = Yspring_alien_w;
5448 next[x-1][y] = Xspring_w;
5449 play_element_sound(x, y, SOUND_slurp, Xalien);
5450 score += lev.slurp_score;
5455 cave[x-1][y] = Ybumper;
5456 next[x][y] = Xspring_e;
5457 play_element_sound(x, y, SOUND_spring, Xspring);
5461 cave[x][y] = Xspring;
5462 next[x][y] = Xspring;
5463 play_element_sound(x, y, SOUND_spring, Xspring);
5468 static void Lspring_fall(int x, int y)
5470 switch (cave[x][y+1])
5484 cave[x][y] = Yspring_sB;
5485 next[x][y] = Xblank;
5486 cave[x][y+1] = Yspring_s;
5487 next[x][y+1] = Xspring_fall;
5498 cave[x][y] = Yspring_sB;
5499 next[x][y] = Xblank;
5500 if (cave[x+1][y] == Xblank)
5501 cave[x+1][y] = Xsplash_e;
5502 if (cave[x-1][y] == Xblank)
5503 cave[x-1][y] = Xsplash_w;
5504 play_element_sound(x, y, SOUND_acid, Xacid_1);
5511 cave[x][y] = Yspring_sB;
5512 cave[x][y+1] = Yeater_spring;
5513 Lboom_eater(x, y+1, Xspring_fall);
5514 score += lev.eater_score;
5519 cave[x][y] = Yspring_sB;
5520 cave[x][y+1] = Yalien_spring;
5521 Lboom_tank(x, y+1, Xspring_fall);
5522 score += lev.alien_score;
5533 cave[x][y] = Yspring_sB;
5534 cave[x][y+1] = Ybug_spring;
5535 Lboom_bug(x, y+1, Xspring_fall);
5536 score += lev.bug_score;
5547 cave[x][y] = Yspring_sB;
5548 cave[x][y+1] = Ytank_spring;
5549 Lboom_tank(x, y+1, Xspring_fall);
5550 score += lev.tank_score;
5555 cave[x][y+1] = Ybomb_blank;
5556 Lboom_tank(x, y+1, Xspring_fall);
5560 cave[x][y] = Xspring;
5561 next[x][y] = Xspring;
5562 play_element_sound(x, y, SOUND_spring, Xspring);
5567 static void Lpush_emerald_e(int x, int y)
5569 cave[x][y] = Yemerald_eB;
5570 next[x][y] = Xblank;
5572 switch (cave[x+1][y])
5594 if (cave[x+2][y-1] == Xblank)
5595 cave[x+2][y-1] = Xsplash_e;
5596 if (cave[x][y-1] == Xblank)
5597 cave[x][y-1] = Xsplash_w;
5598 play_element_sound(x, y, SOUND_acid, Xacid_1);
5603 cave[x+1][y] = Yemerald_e;
5604 next[x+1][y] = Xemerald_pause;
5607 static void Lpush_emerald_w(int x, int y)
5609 cave[x][y] = Yemerald_wB;
5610 next[x][y] = Xblank;
5612 switch (cave[x-1][y])
5634 if (cave[x][y-1] == Xblank)
5635 cave[x][y-1] = Xsplash_e;
5636 if (cave[x-2][y-1] == Xblank)
5637 cave[x-2][y-1] = Xsplash_w;
5638 play_element_sound(x, y, SOUND_acid, Xacid_1);
5643 cave[x-1][y] = Yemerald_w;
5644 next[x-1][y] = Xemerald_pause;
5647 static void Lpush_diamond_e(int x, int y)
5649 cave[x][y] = Ydiamond_eB;
5650 next[x][y] = Xblank;
5652 switch (cave[x+1][y])
5674 if (cave[x+2][y-1] == Xblank)
5675 cave[x+2][y-1] = Xsplash_e;
5676 if (cave[x][y-1] == Xblank)
5677 cave[x][y-1] = Xsplash_w;
5678 play_element_sound(x, y, SOUND_acid, Xacid_1);
5683 cave[x+1][y] = Ydiamond_e;
5684 next[x+1][y] = Xdiamond_pause;
5687 static void Lpush_diamond_w(int x, int y)
5689 cave[x][y] = Ydiamond_wB;
5690 next[x][y] = Xblank;
5692 switch (cave[x-1][y])
5714 if (cave[x][y-1] == Xblank)
5715 cave[x][y-1] = Xsplash_e;
5716 if (cave[x-2][y-1] == Xblank)
5717 cave[x-2][y-1] = Xsplash_w;
5718 play_element_sound(x, y, SOUND_acid, Xacid_1);
5723 cave[x-1][y] = Ydiamond_w;
5724 next[x-1][y] = Xdiamond_pause;
5727 static void Lpush_stone_e(int x, int y)
5729 cave[x][y] = Ystone_eB;
5730 next[x][y] = Xblank;
5732 switch (cave[x+1][y])
5754 if (cave[x+2][y-1] == Xblank)
5755 cave[x+2][y-1] = Xsplash_e;
5756 if (cave[x][y-1] == Xblank)
5757 cave[x][y-1] = Xsplash_w;
5758 play_element_sound(x, y, SOUND_acid, Xacid_1);
5763 cave[x+1][y] = Ystone_e;
5764 next[x+1][y] = Xstone_pause;
5767 static void Lpush_stone_w(int x, int y)
5769 cave[x][y] = Ystone_wB;
5770 next[x][y] = Xblank;
5772 switch (cave[x-1][y])
5794 if (cave[x][y-1] == Xblank)
5795 cave[x][y-1] = Xsplash_e;
5796 if (cave[x-2][y-1] == Xblank)
5797 cave[x-2][y-1] = Xsplash_w;
5798 play_element_sound(x, y, SOUND_acid, Xacid_1);
5803 cave[x-1][y] = Ystone_w;
5804 next[x-1][y] = Xstone_pause;
5807 static void Lpush_bomb_e(int x, int y)
5809 cave[x][y] = Ybomb_eB;
5810 next[x][y] = Xblank;
5812 switch (cave[x+1][y])
5834 if (cave[x+2][y-1] == Xblank)
5835 cave[x+2][y-1] = Xsplash_e;
5836 if (cave[x][y-1] == Xblank)
5837 cave[x][y-1] = Xsplash_w;
5838 play_element_sound(x, y, SOUND_acid, Xacid_1);
5843 cave[x+1][y] = Ybomb_e;
5844 next[x+1][y] = Xbomb_pause;
5847 static void Lpush_bomb_w(int x, int y)
5849 cave[x][y] = Ybomb_wB;
5850 next[x][y] = Xblank;
5852 switch (cave[x-1][y])
5874 if (cave[x][y-1] == Xblank)
5875 cave[x][y-1] = Xsplash_e;
5876 if (cave[x-2][y-1] == Xblank)
5877 cave[x-2][y-1] = Xsplash_w;
5878 play_element_sound(x, y, SOUND_acid, Xacid_1);
5883 cave[x-1][y] = Ybomb_w;
5884 next[x-1][y] = Xbomb_pause;
5887 static void Lpush_nut_e(int x, int y)
5889 cave[x][y] = Ynut_eB;
5890 next[x][y] = Xblank;
5892 switch (cave[x+1][y])
5914 if (cave[x+2][y-1] == Xblank)
5915 cave[x+2][y-1] = Xsplash_e;
5916 if (cave[x][y-1] == Xblank)
5917 cave[x][y-1] = Xsplash_w;
5918 play_element_sound(x, y, SOUND_acid, Xacid_1);
5923 cave[x+1][y] = Ynut_e;
5924 next[x+1][y] = Xnut_pause;
5927 static void Lpush_nut_w(int x, int y)
5929 cave[x][y] = Ynut_wB;
5930 next[x][y] = Xblank;
5932 switch (cave[x-1][y])
5954 if (cave[x][y-1] == Xblank)
5955 cave[x][y-1] = Xsplash_e;
5956 if (cave[x-2][y-1] == Xblank)
5957 cave[x-2][y-1] = Xsplash_w;
5958 play_element_sound(x, y, SOUND_acid, Xacid_1);
5963 cave[x-1][y] = Ynut_w;
5964 next[x-1][y] = Xnut_pause;
5967 static void Lpush_spring_e(int x, int y)
5969 cave[x][y] = Yspring_eB;
5970 next[x][y] = Xblank;
5972 switch (cave[x+1][y])
5994 if (cave[x+2][y-1] == Xblank)
5995 cave[x+2][y-1] = Xsplash_e;
5996 if (cave[x][y-1] == Xblank)
5997 cave[x][y-1] = Xsplash_w;
5998 play_element_sound(x, y, SOUND_acid, Xacid_1);
6003 cave[x+1][y] = Yspring_e;
6004 next[x+1][y] = Xspring_e;
6007 static void Lpush_spring_w(int x, int y)
6009 cave[x][y] = Yspring_wB;
6010 next[x][y] = Xblank;
6012 switch (cave[x-1][y])
6034 if (cave[x][y-1] == Xblank)
6035 cave[x][y-1] = Xsplash_e;
6036 if (cave[x-2][y-1] == Xblank)
6037 cave[x-2][y-1] = Xsplash_w;
6038 play_element_sound(x, y, SOUND_acid, Xacid_1);
6043 cave[x-1][y] = Yspring_w;
6044 next[x-1][y] = Xspring_w;
6047 static void Ldynamite_1(int x, int y)
6049 play_element_sound(x, y, SOUND_tick, Xdynamite_1);
6050 next[x][y] = Xdynamite_2;
6053 static void Ldynamite_2(int x, int y)
6055 play_element_sound(x, y, SOUND_tick, Xdynamite_2);
6056 next[x][y] = Xdynamite_3;
6059 static void Ldynamite_3(int x, int y)
6061 play_element_sound(x, y, SOUND_tick, Xdynamite_3);
6062 next[x][y] = Xdynamite_4;
6065 static void Ldynamite_4(int x, int y)
6067 play_element_sound(x, y, SOUND_tick, Xdynamite_4);
6068 next[x][y] = Zdynamite;
6070 Lboom_generic(x, y, Xblank, Xblank);
6073 static void Lfake_door_1(int x, int y)
6075 if (lev.magnify_cnt)
6076 cave[x][y] = Xdoor_1;
6079 static void Lfake_door_2(int x, int y)
6081 if (lev.magnify_cnt)
6082 cave[x][y] = Xdoor_2;
6085 static void Lfake_door_3(int x, int y)
6087 if (lev.magnify_cnt)
6088 cave[x][y] = Xdoor_3;
6091 static void Lfake_door_4(int x, int y)
6093 if (lev.magnify_cnt)
6094 cave[x][y] = Xdoor_4;
6097 static void Lfake_door_5(int x, int y)
6099 if (lev.magnify_cnt)
6100 cave[x][y] = Xdoor_5;
6103 static void Lfake_door_6(int x, int y)
6105 if (lev.magnify_cnt)
6106 cave[x][y] = Xdoor_6;
6109 static void Lfake_door_7(int x, int y)
6111 if (lev.magnify_cnt)
6112 cave[x][y] = Xdoor_7;
6115 static void Lfake_door_8(int x, int y)
6117 if (lev.magnify_cnt)
6118 cave[x][y] = Xdoor_8;
6121 static void Lballoon(int x, int y)
6123 if (lev.wind_cnt == 0)
6126 switch (lev.wind_direction)
6129 switch (cave[x][y-1])
6142 cave[x][y] = Yballoon_nB;
6143 next[x][y] = Xblank;
6144 cave[x][y-1] = Yballoon_n;
6145 next[x][y-1] = Xballoon;
6156 cave[x][y] = Yballoon_nB;
6157 next[x][y] = Xblank;
6158 if (cave[x+1][y-2] == Xblank)
6159 cave[x+1][y-2] = Xsplash_e;
6160 if (cave[x-1][y-2] == Xblank)
6161 cave[x-1][y-2] = Xsplash_w;
6162 play_element_sound(x, y, SOUND_acid, Xacid_1);
6168 switch (cave[x+1][y])
6181 cave[x][y] = Yballoon_eB;
6182 next[x][y] = Xblank;
6183 cave[x+1][y] = Yballoon_e;
6184 next[x+1][y] = Xballoon;
6195 cave[x][y] = Yballoon_eB;
6196 next[x][y] = Xblank;
6197 if (cave[x+2][y-1] == Xblank)
6198 cave[x+2][y-1] = Xsplash_e;
6199 if (cave[x][y-1] == Xblank)
6200 cave[x][y-1] = Xsplash_w;
6201 play_element_sound(x, y, SOUND_acid, Xacid_1);
6207 switch (cave[x][y+1])
6220 cave[x][y] = Yballoon_sB;
6221 next[x][y] = Xblank;
6222 cave[x][y+1] = Yballoon_s;
6223 next[x][y+1] = Xballoon;
6234 cave[x][y] = Yballoon_sB;
6235 next[x][y] = Xblank;
6236 if (cave[x+1][y] == Xblank)
6237 cave[x+1][y] = Xsplash_e;
6238 if (cave[x-1][y] == Xblank)
6239 cave[x-1][y] = Xsplash_w;
6240 play_element_sound(x, y, SOUND_acid, Xacid_1);
6246 switch (cave[x-1][y])
6259 cave[x][y] = Yballoon_wB;
6260 next[x][y] = Xblank;
6261 cave[x-1][y] = Yballoon_w;
6262 next[x-1][y] = Xballoon;
6273 cave[x][y] = Yballoon_wB;
6274 next[x][y] = Xblank;
6275 if (cave[x][y-1] == Xblank)
6276 cave[x][y-1] = Xsplash_e;
6277 if (cave[x-2][y-1] == Xblank)
6278 cave[x-2][y-1] = Xsplash_w;
6279 play_element_sound(x, y, SOUND_acid, Xacid_1);
6286 static void Lball_common(int x, int y)
6288 play_element_sound(x, y, SOUND_ball, Xball_1);
6290 if (lev.ball_random)
6295 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6296 is_blank[cave[x-1][y-1]])
6298 cave[x-1][y-1] = Yball_blank;
6299 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6304 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6305 is_blank[cave[x][y-1]])
6307 cave[x][y-1] = Yball_blank;
6308 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6313 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6314 is_blank[cave[x+1][y-1]])
6316 cave[x+1][y-1] = Yball_blank;
6317 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6322 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6323 is_blank[cave[x-1][y]])
6325 cave[x-1][y] = Yball_blank;
6326 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6331 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6332 is_blank[cave[x+1][y]])
6334 cave[x+1][y] = Yball_blank;
6335 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6340 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6341 is_blank[cave[x-1][y+1]])
6343 cave[x-1][y+1] = Yball_blank;
6344 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6349 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6350 is_blank[cave[x][y+1]])
6352 cave[x][y+1] = Yball_blank;
6353 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6358 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6359 is_blank[cave[x+1][y+1]])
6361 cave[x+1][y+1] = Yball_blank;
6362 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6369 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6370 is_blank[cave[x-1][y-1]])
6372 cave[x-1][y-1] = Yball_blank;
6373 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6376 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6377 is_blank[cave[x][y-1]])
6379 cave[x][y-1] = Yball_blank;
6380 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6383 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6384 is_blank[cave[x+1][y-1]])
6386 cave[x+1][y-1] = Yball_blank;
6387 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6390 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6391 is_blank[cave[x-1][y]])
6393 cave[x-1][y] = Yball_blank;
6394 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6397 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6398 is_blank[cave[x+1][y]])
6400 cave[x+1][y] = Yball_blank;
6401 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6404 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6405 is_blank[cave[x-1][y+1]])
6407 cave[x-1][y+1] = Yball_blank;
6408 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6411 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6412 is_blank[cave[x][y+1]])
6414 cave[x][y+1] = Yball_blank;
6415 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6418 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6419 is_blank[cave[x+1][y+1]])
6421 cave[x+1][y+1] = Yball_blank;
6422 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6426 lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
6429 static void Lball_1(int x, int y)
6431 if (lev.ball_state == 0)
6434 cave[x][y] = Yball_1;
6435 next[x][y] = Xball_2;
6442 static void Lball_2(int x, int y)
6444 if (lev.ball_state == 0)
6447 cave[x][y] = Yball_2;
6448 next[x][y] = Xball_1;
6455 static void Ldrip(int x, int y)
6457 next[x][y] = Xdrip_fall;
6460 static void Ldrip_fall(int x, int y)
6464 switch (cave[x][y+1])
6480 cave[x][y] = Ydrip_1_sB;
6481 next[x][y] = Xdrip_stretchB;
6482 cave[x][y+1] = Ydrip_1_s;
6483 next[x][y+1] = Xdrip_stretch;
6494 cave[x][y] = Ydrip_1_sB;
6495 next[x][y] = Xdrip_stretchB;
6496 if (cave[x+1][y] == Xblank)
6497 cave[x+1][y] = Xsplash_e;
6498 if (cave[x-1][y] == Xblank)
6499 cave[x-1][y] = Xsplash_w;
6500 play_element_sound(x, y, SOUND_acid, Xacid_1);
6506 case 0: temp = Xamoeba_1; break;
6507 case 1: temp = Xamoeba_2; break;
6508 case 2: temp = Xamoeba_3; break;
6509 case 3: temp = Xamoeba_4; break;
6510 case 4: temp = Xamoeba_5; break;
6511 case 5: temp = Xamoeba_6; break;
6512 case 6: temp = Xamoeba_7; break;
6513 case 7: temp = Xamoeba_8; break;
6518 play_element_sound(x, y, SOUND_drip, Xdrip_fall);
6523 static void Ldrip_stretch(int x, int y)
6525 cave[x][y] = Ydrip_2_s;
6526 next[x][y] = Xdrip_fall;
6529 static void Ldrip_stretchB(int x, int y)
6531 cave[x][y] = Ydrip_2_sB;
6532 next[x][y] = Xblank;
6535 static void Lwonderwall(int x, int y)
6537 if (lev.wonderwall_time && lev.wonderwall_state)
6539 cave[x][y] = Ywonderwall;
6540 play_element_sound(x, y, SOUND_wonder, Xwonderwall);
6544 static void Lwheel(int x, int y)
6546 if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
6547 cave[x][y] = Ywheel;
6550 static void Lswitch(int x, int y)
6553 cave[x][y] = Yswitch;
6556 static void Lfake_blank(int x, int y)
6559 cave[x][y] = Yfake_blank;
6562 static void Lfake_grass(int x, int y)
6564 if (lev.magnify_cnt)
6565 cave[x][y] = Yfake_grass;
6568 static void Lfake_amoeba(int x, int y)
6571 cave[x][y] = Yfake_amoeba;
6574 static void Lsand_stone(int x, int y)
6576 switch (cave[x][y+1])
6589 cave[x][y] = Xsand_stonesand_quickout_1;
6590 next[x][y] = Xsand_stonesand_quickout_2;
6591 cave[x][y+1] = Xsand_stoneout_1;
6592 next[x][y+1] = Xsand_stoneout_2;
6603 cave[x][y] = Xsand_stonesand_quickout_1;
6604 next[x][y] = Xsand_stonesand_quickout_2;
6605 if (cave[x+1][y] == Xblank)
6606 cave[x+1][y] = Xsplash_e;
6607 if (cave[x-1][y] == Xblank)
6608 cave[x-1][y] = Xsplash_w;
6609 play_element_sound(x, y, SOUND_acid, Xacid_1);
6613 cave[x][y] = Xsand_stonesand_1;
6614 next[x][y] = Xsand_stonesand_2;
6615 cave[x][y+1] = Xsand_sandstone_1;
6616 next[x][y+1] = Xsand_sandstone_2;
6621 static void Lsand_stonein_1(int x, int y)
6623 next[x][y] = Xsand_stonein_2;
6626 static void Lsand_stonein_2(int x, int y)
6628 next[x][y] = Xsand_stonein_3;
6631 static void Lsand_stonein_3(int x, int y)
6633 next[x][y] = Xsand_stonein_4;
6636 static void Lsand_stonein_4(int x, int y)
6638 next[x][y] = Xblank;
6641 static void Lsand_sandstone_1(int x, int y)
6643 next[x][y] = Xsand_sandstone_2;
6646 static void Lsand_sandstone_2(int x, int y)
6648 next[x][y] = Xsand_sandstone_3;
6651 static void Lsand_sandstone_3(int x, int y)
6653 next[x][y] = Xsand_sandstone_4;
6656 static void Lsand_sandstone_4(int x, int y)
6658 next[x][y] = Xsand_stone;
6661 static void Lsand_stonesand_1(int x, int y)
6663 next[x][y] = Xsand_stonesand_2;
6666 static void Lsand_stonesand_2(int x, int y)
6668 next[x][y] = Xsand_stonesand_3;
6671 static void Lsand_stonesand_3(int x, int y)
6673 next[x][y] = Xsand_stonesand_4;
6676 static void Lsand_stonesand_4(int x, int y)
6681 static void Lsand_stoneout_1(int x, int y)
6683 next[x][y] = Xsand_stoneout_2;
6686 static void Lsand_stoneout_2(int x, int y)
6688 next[x][y] = Xstone_fall;
6691 static void Lsand_stonesand_quickout_1(int x, int y)
6693 next[x][y] = Xsand_stonesand_quickout_2;
6696 static void Lsand_stonesand_quickout_2(int x, int y)
6701 static void Lslide_ns(int x, int y)
6703 if (is_blank[cave[x][y-1]])
6705 cave[x][y-1] = Yslide_ns_blank;
6706 next[x][y-1] = Xslide_ns;
6707 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6710 if (is_blank[cave[x][y+1]])
6712 cave[x][y+1] = Yslide_ns_blank;
6713 next[x][y+1] = Xslide_ns;
6714 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6718 static void Lslide_ew(int x, int y)
6720 if (is_blank[cave[x+1][y]])
6722 cave[x+1][y] = Yslide_ew_blank;
6723 next[x+1][y] = Xslide_ew;
6724 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6727 if (is_blank[cave[x-1][y]])
6729 cave[x-1][y] = Yslide_ew_blank;
6730 next[x-1][y] = Xslide_ew;
6731 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6735 static void Lexit(int x, int y)
6737 if (lev.gems_needed > 0)
6740 switch (RANDOM(64) / 21)
6743 cave[x][y] = Xexit_1;
6744 next[x][y] = Xexit_2;
6748 cave[x][y] = Xexit_2;
6749 next[x][y] = Xexit_3;
6753 cave[x][y] = Xexit_3;
6754 next[x][y] = Xexit_1;
6758 play_element_sound(x, y, SOUND_exit_open, Xexit);
6761 static void Lexit_1(int x, int y)
6763 next[x][y] = Xexit_2;
6766 static void Lexit_2(int x, int y)
6768 next[x][y] = Xexit_3;
6771 static void Lexit_3(int x, int y)
6773 next[x][y] = Xexit_1;
6776 static void Lpause(int x, int y)
6778 next[x][y] = Xblank;
6781 static void Lamoeba(int x, int y)
6801 if (is_amoeba[cave[x][y-1]] ||
6802 is_amoeba[cave[x+1][y]] ||
6803 is_amoeba[cave[x][y+1]] ||
6804 is_amoeba[cave[x-1][y]])
6809 static void Lboom_one(int x, int y, boolean by_dynamite)
6868 cave[x][y] = Xboom_android;
6879 cave[x][y] = Xboom_bug;
6885 cave[x][y] = Xboom_bomb;
6889 cave[x][y] = Xboom_1;
6894 static void Lboom_nine(int x, int y, boolean by_dynamite)
6896 Lboom_one(x, y-1, by_dynamite);
6897 Lboom_one(x-1, y, by_dynamite);
6898 Lboom_one(x+1, y, by_dynamite);
6899 Lboom_one(x, y+1, by_dynamite);
6900 Lboom_one(x-1, y-1, by_dynamite);
6901 Lboom_one(x+1, y-1, by_dynamite);
6902 Lboom_one(x-1, y+1, by_dynamite);
6903 Lboom_one(x+1, y+1, by_dynamite);
6905 cave[x][y] = Xboom_1;
6908 static void Lexplode(int x, int y)
6913 Lboom_nine(x, y, FALSE);
6917 Lboom_nine(x, y, FALSE);
6921 Lboom_nine(x, y, FALSE);
6925 Lboom_nine(x, y, TRUE);
6930 static void Lboom_1(int x, int y)
6932 next[x][y] = Xboom_2;
6933 #if !PLAY_ELEMENT_SOUND
6934 if (x != lev.exit_x && y != lev.exit_y)
6935 play_sound(x, y, SOUND_boom);
6937 lev.exit_x = lev.exit_y = -1;
6941 static void Lboom_2(int x, int y)
6943 next[x][y] = boom[x][y];
6946 static void Lboom_android(int x, int y)
6948 #if PLAY_ELEMENT_SOUND
6949 play_element_sound(x, y, SOUND_boom, Xandroid);
6955 static void handle_tile(int x, int y)
6959 case Xacid_1: Lacid_1(x, y); break;
6960 case Xacid_2: Lacid_2(x, y); break;
6961 case Xacid_3: Lacid_3(x, y); break;
6962 case Xacid_4: Lacid_4(x, y); break;
6963 case Xacid_5: Lacid_5(x, y); break;
6964 case Xacid_6: Lacid_6(x, y); break;
6965 case Xacid_7: Lacid_7(x, y); break;
6966 case Xacid_8: Lacid_8(x, y); break;
6968 case Xfake_acid_1: Lfake_acid_1(x, y); break;
6969 case Xfake_acid_2: Lfake_acid_2(x, y); break;
6970 case Xfake_acid_3: Lfake_acid_3(x, y); break;
6971 case Xfake_acid_4: Lfake_acid_4(x, y); break;
6972 case Xfake_acid_5: Lfake_acid_5(x, y); break;
6973 case Xfake_acid_6: Lfake_acid_6(x, y); break;
6974 case Xfake_acid_7: Lfake_acid_7(x, y); break;
6975 case Xfake_acid_8: Lfake_acid_8(x, y); break;
6977 case Xandroid: Landroid(x, y); break;
6978 case Xandroid_1_n: Landroid_1_n(x, y); break;
6979 case Xandroid_2_n: Landroid_2_n(x, y); break;
6980 case Xandroid_1_e: Landroid_1_e(x, y); break;
6981 case Xandroid_2_e: Landroid_2_e(x, y); break;
6982 case Xandroid_1_s: Landroid_1_s(x, y); break;
6983 case Xandroid_2_s: Landroid_2_s(x, y); break;
6984 case Xandroid_1_w: Landroid_1_w(x, y); break;
6985 case Xandroid_2_w: Landroid_2_w(x, y); break;
6987 case Xeater_n: Leater_n(x, y); break;
6988 case Xeater_e: Leater_e(x, y); break;
6989 case Xeater_s: Leater_s(x, y); break;
6990 case Xeater_w: Leater_w(x, y); break;
6992 case Xalien: Lalien(x, y); break;
6993 case Xalien_pause: Lalien_pause(x, y); break;
6995 case Xbug_1_n: Lbug_1_n(x, y); break;
6996 case Xbug_2_n: Lbug_2_n(x, y); break;
6997 case Xbug_1_e: Lbug_1_e(x, y); break;
6998 case Xbug_2_e: Lbug_2_e(x, y); break;
6999 case Xbug_1_s: Lbug_1_s(x, y); break;
7000 case Xbug_2_s: Lbug_2_s(x, y); break;
7001 case Xbug_1_w: Lbug_1_w(x, y); break;
7002 case Xbug_2_w: Lbug_2_w(x, y); break;
7004 case Xtank_1_n: Ltank_1_n(x, y); break;
7005 case Xtank_2_n: Ltank_2_n(x, y); break;
7006 case Xtank_1_e: Ltank_1_e(x, y); break;
7007 case Xtank_2_e: Ltank_2_e(x, y); break;
7008 case Xtank_1_s: Ltank_1_s(x, y); break;
7009 case Xtank_2_s: Ltank_2_s(x, y); break;
7010 case Xtank_1_w: Ltank_1_w(x, y); break;
7011 case Xtank_2_w: Ltank_2_w(x, y); break;
7013 case Xemerald: Lemerald(x, y); break;
7014 case Xemerald_pause: Lemerald_pause(x, y); break;
7015 case Xemerald_fall: Lemerald_fall(x, y); break;
7017 case Xdiamond: Ldiamond(x, y); break;
7018 case Xdiamond_pause: Ldiamond_pause(x, y); break;
7019 case Xdiamond_fall: Ldiamond_fall(x, y); break;
7021 case Xstone: Lstone(x, y); break;
7022 case Xstone_pause: Lstone_pause(x, y); break;
7023 case Xstone_fall: Lstone_fall(x, y); break;
7025 case Xbomb: Lbomb(x, y); break;
7026 case Xbomb_pause: Lbomb_pause(x, y); break;
7027 case Xbomb_fall: Lbomb_fall(x, y); break;
7029 case Xnut: Lnut(x, y); break;
7030 case Xnut_pause: Lnut_pause(x, y); break;
7031 case Xnut_fall: Lnut_fall(x, y); break;
7033 case Xspring: Lspring(x, y); break;
7034 case Xspring_pause: Lspring_pause(x, y); break;
7035 case Xspring_e: Lspring_e(x, y); break;
7036 case Xspring_w: Lspring_w(x, y); break;
7037 case Xspring_fall: Lspring_fall(x, y); break;
7039 case Xpush_emerald_e: Lpush_emerald_e(x, y); break;
7040 case Xpush_emerald_w: Lpush_emerald_w(x, y); break;
7041 case Xpush_diamond_e: Lpush_diamond_e(x, y); break;
7042 case Xpush_diamond_w: Lpush_diamond_w(x, y); break;
7043 case Xpush_stone_e: Lpush_stone_e(x, y); break;
7044 case Xpush_stone_w: Lpush_stone_w(x, y); break;
7045 case Xpush_bomb_e: Lpush_bomb_e(x, y); break;
7046 case Xpush_bomb_w: Lpush_bomb_w(x, y); break;
7047 case Xpush_nut_e: Lpush_nut_e(x, y); break;
7048 case Xpush_nut_w: Lpush_nut_w(x, y); break;
7049 case Xpush_spring_e: Lpush_spring_e(x, y); break;
7050 case Xpush_spring_w: Lpush_spring_w(x, y); break;
7052 case Xdynamite_1: Ldynamite_1(x, y); break;
7053 case Xdynamite_2: Ldynamite_2(x, y); break;
7054 case Xdynamite_3: Ldynamite_3(x, y); break;
7055 case Xdynamite_4: Ldynamite_4(x, y); break;
7057 case Xfake_door_1: Lfake_door_1(x, y); break;
7058 case Xfake_door_2: Lfake_door_2(x, y); break;
7059 case Xfake_door_3: Lfake_door_3(x, y); break;
7060 case Xfake_door_4: Lfake_door_4(x, y); break;
7061 case Xfake_door_5: Lfake_door_5(x, y); break;
7062 case Xfake_door_6: Lfake_door_6(x, y); break;
7063 case Xfake_door_7: Lfake_door_7(x, y); break;
7064 case Xfake_door_8: Lfake_door_8(x, y); break;
7066 case Xballoon: Lballoon(x, y); break;
7068 case Xball_1: Lball_1(x, y); break;
7069 case Xball_2: Lball_2(x, y); break;
7071 case Xdrip: Ldrip(x, y); break;
7072 case Xdrip_fall: Ldrip_fall(x, y); break;
7073 case Xdrip_stretch: Ldrip_stretch(x, y); break;
7074 case Xdrip_stretchB: Ldrip_stretchB(x, y); break;
7076 case Xwonderwall: Lwonderwall(x, y); break;
7078 case Xwheel: Lwheel(x, y); break;
7080 case Xswitch: Lswitch(x, y); break;
7082 case Xfake_blank: Lfake_blank(x, y); break;
7083 case Xfake_grass: Lfake_grass(x, y); break;
7084 case Xfake_amoeba: Lfake_amoeba(x, y); break;
7086 case Xsand_stone: Lsand_stone(x, y); break;
7087 case Xsand_stonein_1: Lsand_stonein_1(x, y); break;
7088 case Xsand_stonein_2: Lsand_stonein_2(x, y); break;
7089 case Xsand_stonein_3: Lsand_stonein_3(x, y); break;
7090 case Xsand_stonein_4: Lsand_stonein_4(x, y); break;
7091 case Xsand_sandstone_1: Lsand_sandstone_1(x, y); break;
7092 case Xsand_sandstone_2: Lsand_sandstone_2(x, y); break;
7093 case Xsand_sandstone_3: Lsand_sandstone_3(x, y); break;
7094 case Xsand_sandstone_4: Lsand_sandstone_4(x, y); break;
7095 case Xsand_stonesand_1: Lsand_stonesand_1(x, y); break;
7096 case Xsand_stonesand_2: Lsand_stonesand_2(x, y); break;
7097 case Xsand_stonesand_3: Lsand_stonesand_3(x, y); break;
7098 case Xsand_stonesand_4: Lsand_stonesand_4(x, y); break;
7099 case Xsand_stoneout_1: Lsand_stoneout_1(x, y); break;
7100 case Xsand_stoneout_2: Lsand_stoneout_2(x, y); break;
7101 case Xsand_stonesand_quickout_1: Lsand_stonesand_quickout_1(x, y); break;
7102 case Xsand_stonesand_quickout_2: Lsand_stonesand_quickout_2(x, y); break;
7104 case Xslide_ns: Lslide_ns(x, y); break;
7105 case Xslide_ew: Lslide_ew(x, y); break;
7107 case Xexit: Lexit(x, y); break;
7108 case Xexit_1: Lexit_1(x, y); break;
7109 case Xexit_2: Lexit_2(x, y); break;
7110 case Xexit_3: Lexit_3(x, y); break;
7112 case Xpause: Lpause(x, y); break;
7114 case Xboom_bug: Lboom_bug(x, y, Xboom_bug); break;
7115 case Xboom_bomb: Lboom_tank(x, y, Xboom_bomb); break;
7116 case Xboom_android: Lboom_android(x, y); break;
7117 case Xboom_1: Lboom_1(x, y); break;
7118 case Xboom_2: Lboom_2(x, y); break;
7122 void logic_players(void)
7131 game_em.any_player_moving = FALSE;
7132 game_em.any_player_snapping = FALSE;
7134 /* must test for death and actually kill separately */
7135 for (i = 0; i < MAX_PLAYERS; i++)
7137 boolean ply_kill = player_killed(&ply[i]);
7139 if (ply[i].alive && ply_kill)
7140 kill_player(&ply[i]);
7143 for (i = 0; i < MAX_PLAYERS; i++)
7145 /* check for wrap-around movement */
7146 if (ply[i].x < lev.left ||
7147 ply[i].x > lev.right - 1)
7149 ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
7151 game.centered_player_nr_next = i;
7152 game.set_centered_player = TRUE;
7153 game.set_centered_player_fast = TRUE;
7156 ply[i].oldx = ply[i].x;
7157 ply[i].oldy = ply[i].y;
7158 ply[i].anim = PLY_still;
7161 start_check_nr = ((game_em.random & 128 ? 0 : 1) * 2 +
7162 (game_em.random & 256 ? 0 : 1));
7164 for (i = 0; i < MAX_PLAYERS; i++)
7166 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
7168 if (ply[check_nr].alive)
7169 check_player(&ply[check_nr]);
7172 for (i = 0; i < MAX_PLAYERS; i++)
7177 if (cave[ply[i].oldx][ply[i].oldy] == Zplayer)
7179 cave[ply[i].oldx][ply[i].oldy] = Xblank;
7180 next[ply[i].oldx][ply[i].oldy] = Xblank;
7183 if (cave[ply[i].x][ply[i].y] == Xblank)
7185 cave[ply[i].x][ply[i].y] = Zplayer;
7186 next[ply[i].x][ply[i].y] = Zplayer;
7191 void logic_objects(void)
7199 seed = game_em.random;
7202 for (y = lev.top; y < lev.bottom; y++)
7203 for (x = lev.left; x < lev.right; x++)
7206 if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
7207 lev.score += score; /* only add a score if someone is alive */
7209 game_em.game_over = TRUE;
7211 game_em.random = seed;
7213 /* triple buffering */
7214 void *temp = lev.cave;
7215 lev.cave = lev.next;
7216 lev.next = lev.draw;
7220 void logic_globals(void)
7225 unsigned int random;
7231 /* update variables */
7233 if (lev.score > 9999)
7236 if (lev.android_move_cnt-- == 0)
7237 lev.android_move_cnt = lev.android_move_time;
7238 if (lev.android_clone_cnt-- == 0)
7239 lev.android_clone_cnt = lev.android_clone_time;
7241 if (lev.ball_cnt-- == 0)
7242 lev.ball_cnt = lev.ball_time;
7245 if (lev.magnify_cnt)
7251 if (lev.wonderwall_time && lev.wonderwall_state)
7252 lev.wonderwall_time--;
7255 play_element_sound(lev.wheel_x, lev.wheel_y, SOUND_wheel, Xwheel);
7259 random = game_em.random;
7261 for (count = lev.amoeba_time; count--;)
7263 x = lev.left - 1 + (random >> 10) % (CAVE_WIDTH + 2);
7264 y = lev.top - 1 + (random >> 20) % (CAVE_HEIGHT + 2);
7266 if (x >= lev.left && x < lev.right &&
7267 y >= lev.top && y < lev.bottom)
7270 random = random * 129 + 1;
7273 game_em.random = random;
7275 /* handle explosions */
7277 for (y = lev.top; y < lev.bottom; y++)
7278 for (x = lev.left; x < lev.right; x++)
7281 /* triple buffering */
7283 for (y = lev.top; y < lev.bottom; y++)
7284 for (x = lev.left; x < lev.right; x++)
7285 next[x][y] = cave[x][y];