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)
118 if (game_em.use_old_explosions)
121 Lboom_generic(x, y, Xemerald, Xdiamond);
123 #if PLAY_ELEMENT_SOUND
124 play_element_sound(x, y, SOUND_boom, Xbug_1_n);
128 static void Lboom_tank(int x, int y)
130 if (game_em.use_old_explosions)
133 Lboom_generic(x, y, Xblank, Xblank);
135 #if PLAY_ELEMENT_SOUND
136 play_element_sound(x, y, SOUND_boom, Xtank_1_n);
140 static void Lboom_eater(int x, int y)
142 if (game_em.use_old_explosions)
145 boom[x-1][y-1] = lev.eater_array[lev.eater_pos][0];
146 boom[x][y-1] = lev.eater_array[lev.eater_pos][1];
147 boom[x+1][y-1] = lev.eater_array[lev.eater_pos][2];
148 boom[x-1][y] = lev.eater_array[lev.eater_pos][3];
149 boom[x][y] = lev.eater_array[lev.eater_pos][4];
150 boom[x+1][y] = lev.eater_array[lev.eater_pos][5];
151 boom[x-1][y+1] = lev.eater_array[lev.eater_pos][6];
152 boom[x][y+1] = lev.eater_array[lev.eater_pos][7];
153 boom[x+1][y+1] = lev.eater_array[lev.eater_pos][8];
155 lev.eater_pos = (lev.eater_pos + 1) & 7;
157 #if PLAY_ELEMENT_SOUND
158 play_element_sound(x, y, SOUND_boom, Xeater_n);
162 static void Lboom_bug_old(int x, int y)
164 if (!game_em.use_old_explosions)
170 static void Lboom_tank_old(int x, int y)
172 if (!game_em.use_old_explosions)
178 static void Lboom_eater_old(int x, int y)
180 if (!game_em.use_old_explosions)
186 static void Lboom_bug_new(int x, int y, boolean chain_explosion)
188 if (game_em.use_old_explosions)
197 static void Lboom_tank_new(int x, int y, boolean chain_explosion)
199 if (game_em.use_old_explosions)
208 static void Lboom_eater_new(int x, int y, boolean chain_explosion)
210 if (game_em.use_old_explosions)
219 static boolean player_killed(struct PLAYER *ply)
227 if (lev.killed_out_of_time && setup.time_limit)
230 switch (cave[x][y-1])
251 switch (cave[x+1][y])
272 switch (cave[x][y+1])
293 switch (cave[x-1][y])
338 static void kill_player(struct PLAYER *ply)
345 switch (cave[x][y-1])
355 cave[x][y-1] = Xboom_bug;
356 Lboom_bug_new(x, y-1, TRUE);
367 cave[x][y-1] = Xboom_tank;
368 Lboom_tank_new(x, y-1, TRUE);
372 switch (cave[x+1][y])
382 cave[x+1][y] = Xboom_bug;
383 Lboom_bug_new(x+1, y, TRUE);
394 cave[x+1][y] = Xboom_tank;
395 Lboom_tank_new(x+1, y, TRUE);
399 switch (cave[x][y+1])
409 cave[x][y+1] = Xboom_bug;
410 Lboom_bug_new(x, y+1, TRUE);
421 cave[x][y+1] = Xboom_tank;
422 Lboom_tank_new(x, y+1, TRUE);
426 switch (cave[x-1][y])
436 cave[x-1][y] = Xboom_bug;
437 Lboom_bug_new(x-1, y, TRUE);
448 cave[x-1][y] = Xboom_tank;
449 Lboom_tank_new(x-1, y, TRUE);
460 play_element_sound(x, y, SOUND_exit_leave, Xexit_1);
464 play_element_sound(x, y, SOUND_die, Zplayer);
470 #ifdef USE_CHANGED_ACID_STUFF
483 cave[x][y] = Xboom_1;
489 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
491 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
496 boolean result = TRUE;
498 if (!dx && !dy) /* no direction specified */
501 if (dx && dy && ply->joy_snap) /* more than one direction specified */
504 if (ply->joy_snap == 0) /* player wants to move */
506 int element = cave[x][y];
510 /* fire is released */
514 cave[x][y] = Zplayer;
515 next[x][y] = Zplayer;
524 play_element_sound(x, y, SOUND_blank, Xblank);
525 ply->anim = PLY_walk_n + anim;
530 #ifdef USE_CHANGED_ACID_STUFF
539 if (cave[x+1][y-1] == Xblank)
540 cave[x+1][y-1] = Xsplash_e;
541 if (cave[x-1][y-1] == Xblank)
542 cave[x-1][y-1] = Xsplash_w;
543 play_element_sound(x, y, SOUND_acid, Xacid_1);
565 #ifndef USE_CHANGED_ACID_STUFF
575 ply->anim = PLY_walk_n + anim;
581 cave[x][y] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
582 (dx > 0 ? Ygrass_eB : Ygrass_wB));
583 next[x][y] = Zplayer;
584 play_element_sound(x, y, SOUND_dirt, Xgrass);
585 ply->anim = PLY_walk_n + anim;
591 cave[x][y] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
592 (dx > 0 ? Ydirt_eB : Ydirt_wB));
593 next[x][y] = Zplayer;
594 play_element_sound(x, y, SOUND_dirt, Xdirt);
595 ply->anim = PLY_walk_n + anim;
602 cave[x][y] = Ydiamond_blank;
603 next[x][y] = Zplayer;
604 play_element_sound(x, y, SOUND_collect, element);
605 lev.score += lev.diamond_score;
606 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
607 game.snapshot.collected_item = TRUE;
608 ply->anim = PLY_walk_n + anim;
615 cave[x][y] = Yemerald_blank;
616 next[x][y] = Zplayer;
617 play_element_sound(x, y, SOUND_collect, element);
618 lev.score += lev.emerald_score;
619 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
620 game.snapshot.collected_item = TRUE;
621 ply->anim = PLY_walk_n + anim;
627 cave[x][y] = Ydynamite_blank;
628 next[x][y] = Zplayer;
629 play_element_sound(x, y, SOUND_collect, element);
630 lev.score += lev.dynamite_score;
631 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
632 ply->anim = PLY_walk_n + anim;
639 cave[x][y] = Ykey_1_blank;
644 cave[x][y] = Ykey_2_blank;
649 cave[x][y] = Ykey_3_blank;
654 cave[x][y] = Ykey_4_blank;
659 cave[x][y] = Ykey_5_blank;
664 cave[x][y] = Ykey_6_blank;
669 cave[x][y] = Ykey_7_blank;
674 cave[x][y] = Ykey_8_blank;
679 next[x][y] = Zplayer;
680 play_element_sound(x, y, SOUND_collect, element);
681 lev.score += lev.key_score;
682 ply->anim = PLY_walk_n + anim;
688 cave[x][y] = Ylenses_blank;
689 next[x][y] = Zplayer;
690 play_element_sound(x, y, SOUND_collect, element);
691 lev.score += lev.lenses_score;
692 lev.lenses_cnt = lev.lenses_time;
693 ply->anim = PLY_walk_n + anim;
699 cave[x][y] = Ymagnify_blank;
700 next[x][y] = Zplayer;
701 play_element_sound(x, y, SOUND_collect, element);
702 lev.score += lev.magnify_score;
703 lev.magnify_cnt = lev.magnify_time;
704 ply->anim = PLY_walk_n + anim;
713 switch (cave[x+dx][y])
726 cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
727 next[x+dx][y] = Xstone_pause;
738 if (cave[x+dx+1][y-1] == Xblank)
739 cave[x+dx+1][y-1] = Xsplash_e;
740 if (cave[x+dx-1][y-1] == Xblank)
741 cave[x+dx-1][y-1] = Xsplash_w;
742 play_element_sound(x, y, SOUND_acid, Xacid_1);
746 cave[x][y] = dx > 0 ? Ystone_eB : Ystone_wB;
747 next[x][y] = Zplayer;
748 play_element_sound(x, y, SOUND_roll, Xstone);
753 ply->anim = PLY_push_n + anim;
760 switch (cave[x+dx][y])
773 cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
774 next[x+dx][y] = Xbomb_pause;
785 if (cave[x+dx+1][y-1] == Xblank)
786 cave[x+dx+1][y-1] = Xsplash_e;
787 if (cave[x+dx-1][y-1] == Xblank)
788 cave[x+dx-1][y-1] = Xsplash_w;
789 play_element_sound(x, y, SOUND_acid, Xacid_1);
793 cave[x][y] = dx > 0 ? Ybomb_eB : Ybomb_wB;
794 next[x][y] = Zplayer;
795 play_element_sound(x, y, SOUND_roll, Xbomb);
800 ply->anim = PLY_push_n + anim;
807 switch (cave[x+dx][y])
820 cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
821 next[x+dx][y] = Xnut_pause;
832 if (cave[x+dx+1][y-1] == Xblank)
833 cave[x+dx+1][y-1] = Xsplash_e;
834 if (cave[x+dx-1][y-1] == Xblank)
835 cave[x+dx-1][y-1] = Xsplash_w;
836 play_element_sound(x, y, SOUND_acid, Xacid_1);
840 cave[x][y] = dx > 0 ? Ynut_eB : Ynut_wB;
841 next[x][y] = Zplayer;
842 play_element_sound(x, y, SOUND_roll, Xnut);
847 ply->anim = PLY_push_n + anim;
854 switch (cave[x+dx][y])
867 cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
868 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
879 if (cave[x+dx+1][y-1] == Xblank)
880 cave[x+dx+1][y-1] = Xsplash_e;
881 if (cave[x+dx-1][y-1] == Xblank)
882 cave[x+dx-1][y-1] = Xsplash_w;
883 play_element_sound(x, y, SOUND_acid, Xacid_1);
887 cave[x][y] = dx > 0 ? Yspring_eB : Yspring_wB;
888 next[x][y] = Zplayer;
889 play_element_sound(x, y, SOUND_roll, Xspring);
895 cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
896 cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
897 next[x][y] = Zplayer;
898 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
899 play_element_sound(x, y, SOUND_slurp, Xalien);
900 lev.score += lev.slurp_score;
905 ply->anim = PLY_push_n + anim;
912 case Xsand_stonein_1:
913 case Xsand_stonein_2:
914 case Xsand_stonein_3:
915 case Xsand_stonein_4:
919 ply->anim = PLY_push_n + anim;
923 switch (cave[x+dx][y+dy])
936 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
937 (dx > 0 ? Yballoon_e : Yballoon_w));
938 next[x+dx][y+dy] = Xballoon;
949 if (cave[x+dx+1][y+dy-1] == Xblank)
950 cave[x+dx+1][y+dy-1] = Xsplash_e;
951 if (cave[x+dx-1][y+dy-1] == Xblank)
952 cave[x+dx-1][y+dy-1] = Xsplash_w;
953 play_element_sound(x, y, SOUND_acid, Xacid_1);
957 cave[x][y] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
958 (dx > 0 ? Yballoon_eB : Yballoon_wB));
959 next[x][y] = Zplayer;
960 play_element_sound(x, y, SOUND_push, Xballoon);
966 ply->anim = PLY_push_n + anim;
978 switch (cave[x+dx][y+dy])
991 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
992 (dx > 0 ? Yandroid_e : Yandroid_w));
993 next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
994 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
1005 if (cave[x+dx+1][y+dy-1] == Xblank)
1006 cave[x+dx+1][y+dy-1] = Xsplash_e;
1007 if (cave[x+dx-1][y+dy-1] == Xblank)
1008 cave[x+dx-1][y+dy-1] = Xsplash_w;
1009 play_element_sound(x, y, SOUND_acid, Xacid_1);
1013 cave[x][y] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
1014 (dx > 0 ? Yandroid_eB : Yandroid_wB));
1015 next[x][y] = Zplayer;
1016 play_element_sound(x, y, SOUND_push, Xandroid);
1022 ply->anim = PLY_push_n + anim;
1027 if (ply->keys & 0x01)
1034 if (ply->keys & 0x02)
1041 if (ply->keys & 0x04)
1048 if (ply->keys & 0x08)
1055 if (ply->keys & 0x10)
1062 if (ply->keys & 0x20)
1069 if (ply->keys & 0x40)
1076 if (ply->keys & 0x80)
1083 if (!is_blank[cave[x+dx][y+dy]])
1086 if (!is_fake_acid[cave[x+dx][y+dy]])
1088 cave[x+dx][y+dy] = Zplayer;
1089 next[x+dx][y+dy] = Zplayer;
1092 play_element_sound(x, y, SOUND_door, element);
1093 ply->anim = PLY_walk_n + anim;
1099 play_element_sound(x, y, SOUND_press, element);
1100 lev.wheel_cnt = lev.wheel_time;
1106 lev.wind_direction = 0;
1110 lev.wind_direction = 1;
1114 lev.wind_direction = 2;
1118 lev.wind_direction = 3;
1122 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1127 play_element_sound(x, y, SOUND_press, element);
1128 lev.wind_cnt = lev.wind_time;
1132 play_element_sound(x, y, SOUND_press, element);
1137 play_element_sound(x, y, SOUND_press, element);
1138 lev.ball_cnt = lev.ball_time;
1139 lev.ball_state = !lev.ball_state;
1143 cave[x][y] = Yplant;
1144 next[x][y] = Xplant;
1145 play_element_sound(x, y, SOUND_blank, Xplant);
1146 ply->anim = PLY_walk_n + anim;
1157 game_em.level_solved = TRUE;
1159 ply->anim = PLY_walk_n + anim;
1166 if (ply->x == oldx && ply->y == oldy) /* no movement */
1169 else /* player wants to snap */
1171 int element = cave[x][y];
1175 /* fire is pressed */
1178 cave[x][y] = Ygrass_blank;
1179 next[x][y] = Xblank;
1180 play_element_sound(x, y, SOUND_dirt, element);
1181 ply->anim = PLY_shoot_n + anim;
1185 cave[x][y] = Ydirt_blank;
1186 next[x][y] = Xblank;
1187 play_element_sound(x, y, SOUND_dirt, element);
1188 ply->anim = PLY_shoot_n + anim;
1192 case Xdiamond_pause:
1193 cave[x][y] = Ydiamond_blank;
1194 next[x][y] = Xblank;
1195 play_element_sound(x, y, SOUND_collect, element);
1196 lev.score += lev.diamond_score;
1197 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
1198 game.snapshot.collected_item = TRUE;
1199 ply->anim = PLY_walk_n + anim;
1203 case Xemerald_pause:
1204 cave[x][y] = Yemerald_blank;
1205 next[x][y] = Xblank;
1206 play_element_sound(x, y, SOUND_collect, element);
1207 lev.score += lev.emerald_score;
1208 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
1209 game.snapshot.collected_item = TRUE;
1210 ply->anim = PLY_walk_n + anim;
1214 cave[x][y] = Ydynamite_blank;
1215 next[x][y] = Xblank;
1216 play_element_sound(x, y, SOUND_collect, element);
1217 lev.score += lev.dynamite_score;
1218 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1219 ply->anim = PLY_walk_n + anim;
1224 cave[x][y] = Ykey_1_blank;
1229 cave[x][y] = Ykey_2_blank;
1234 cave[x][y] = Ykey_3_blank;
1239 cave[x][y] = Ykey_4_blank;
1244 cave[x][y] = Ykey_5_blank;
1249 cave[x][y] = Ykey_6_blank;
1254 cave[x][y] = Ykey_7_blank;
1259 cave[x][y] = Ykey_8_blank;
1264 next[x][y] = Xblank;
1265 play_element_sound(x, y, SOUND_collect, element);
1266 lev.score += lev.key_score;
1267 ply->anim = PLY_walk_n + anim;
1271 cave[x][y] = Ylenses_blank;
1272 next[x][y] = Xblank;
1273 play_element_sound(x, y, SOUND_collect, element);
1274 lev.score += lev.lenses_score;
1275 lev.lenses_cnt = lev.lenses_time;
1276 ply->anim = PLY_walk_n + anim;
1280 cave[x][y] = Ymagnify_blank;
1281 next[x][y] = Xblank;
1282 play_element_sound(x, y, SOUND_collect, element);
1283 lev.score += lev.magnify_score;
1284 lev.magnify_cnt = lev.magnify_time;
1285 ply->anim = PLY_walk_n + anim;
1296 static void check_player(struct PLAYER *ply)
1304 game_em.last_player_direction[ply->num] = MV_NONE;
1306 if (ply->joy_w) /* west */
1311 else if (ply->joy_e) /* east */
1317 if (ply->joy_n) /* north */
1322 else if (ply->joy_s) /* south */
1334 boolean players_visible_before_move;
1335 boolean players_visible_after_move;
1338 players_visible_before_move = checkIfAllPlayersFitToScreen();
1343 players_visible_after_move = checkIfAllPlayersFitToScreen();
1346 player is allowed to move only in the following cases:
1347 - it is not needed to display all players (not focussed to all players)
1348 - all players are (still or again) visible after the move
1349 - some players were already outside visible screen area before the move
1351 can_move = (game.centered_player_nr != -1 ||
1352 players_visible_after_move ||
1353 !players_visible_before_move);
1360 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
1366 if (dx == 0 && dy == 0)
1372 if (++ply->dynamite_cnt == 5 && ply->dynamite)
1374 cave[x][y] = Xdynamite_1;
1375 play_element_sound(x, y, SOUND_dynamite, Xdynamite_1);
1381 ply->dynamite_cnt = 0;
1384 /* be a bit more random if the player doesn't move */
1385 game_em.random += 7;
1391 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
1392 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
1393 ply->joy_spin = !ply->joy_spin;
1395 if (ply->joy_snap == 0) /* player wants to move */
1397 boolean moved = FALSE;
1399 if (ply->last_move_dir & MV_HORIZONTAL)
1401 if (!(moved = player_digfield(ply, 0, dy)))
1402 moved = player_digfield(ply, dx, 0);
1406 if (!(moved = player_digfield(ply, dx, 0)))
1407 moved = player_digfield(ply, 0, dy);
1413 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
1414 else if (oldy != ply->y)
1415 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
1417 game_em.any_player_moving = TRUE;
1418 game_em.last_moving_player = ply->num;
1419 game_em.last_player_direction[ply->num] = ply->last_move_dir;
1422 else /* player wants to snap */
1424 game_em.any_player_snapping = player_digfield(ply, dx, dy);
1428 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
1430 int distance, distance_shortest = CAVE_WIDTH + CAVE_HEIGHT;
1433 /* default values if no players are alive anymore */
1437 for (i = 0; i < MAX_PLAYERS; i++)
1442 distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
1444 if (distance < distance_shortest)
1449 distance_shortest = distance;
1454 static void Lacid_1(int x, int y)
1456 next[x][y] = Xacid_2;
1459 static void Lacid_2(int x, int y)
1461 next[x][y] = Xacid_3;
1464 static void Lacid_3(int x, int y)
1466 next[x][y] = Xacid_4;
1469 static void Lacid_4(int x, int y)
1471 next[x][y] = Xacid_5;
1474 static void Lacid_5(int x, int y)
1476 next[x][y] = Xacid_6;
1479 static void Lacid_6(int x, int y)
1481 next[x][y] = Xacid_7;
1484 static void Lacid_7(int x, int y)
1486 next[x][y] = Xacid_8;
1489 static void Lacid_8(int x, int y)
1491 next[x][y] = Xacid_1;
1494 static void Lfake_acid_1(int x, int y)
1496 next[x][y] = Xfake_acid_2;
1499 static void Lfake_acid_2(int x, int y)
1501 next[x][y] = Xfake_acid_3;
1504 static void Lfake_acid_3(int x, int y)
1506 next[x][y] = Xfake_acid_4;
1509 static void Lfake_acid_4(int x, int y)
1511 next[x][y] = Xfake_acid_5;
1514 static void Lfake_acid_5(int x, int y)
1516 next[x][y] = Xfake_acid_6;
1519 static void Lfake_acid_6(int x, int y)
1521 next[x][y] = Xfake_acid_7;
1524 static void Lfake_acid_7(int x, int y)
1526 next[x][y] = Xfake_acid_8;
1529 static void Lfake_acid_8(int x, int y)
1531 next[x][y] = Xfake_acid_1;
1534 static void Landroid(int x, int y)
1538 if (lev.android_clone_cnt == 0)
1540 if (!is_blank[cave[x-1][y-1]] &&
1541 !is_blank[cave[x][y-1]] &&
1542 !is_blank[cave[x+1][y-1]] &&
1543 !is_blank[cave[x-1][y]] &&
1544 !is_blank[cave[x+1][y]] &&
1545 !is_blank[cave[x-1][y+1]] &&
1546 !is_blank[cave[x][y+1]] &&
1547 !is_blank[cave[x+1][y+1]])
1552 /* randomly find an object to clone */
1554 case 0: /* S,NE,W,NW,SE,E,SW,N */
1555 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1556 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1557 temp = lev.android_array[cave[x-1][y]]; 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;
1561 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1562 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1565 case 1: /* NW,SE,N,S,NE,SW,E,W */
1566 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1567 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1568 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1569 temp = lev.android_array[cave[x][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-1][y+1]]; if (temp != Xblank) break;
1572 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1573 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1576 case 2: /* SW,E,S,W,N,NW,SE,NE */
1577 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1578 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1579 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1580 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1581 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1582 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1583 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1584 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1587 case 3: /* N,SE,NE,E,W,S,NW,SW */
1588 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1589 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1590 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1591 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1592 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1593 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1594 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1595 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1598 case 4: /* SE,NW,E,NE,SW,W,N,S */
1599 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1600 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1601 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1602 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1603 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1604 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1605 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1606 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1609 case 5: /* NE,W,SE,SW,S,N,E,NW */
1610 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1611 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1612 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1613 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1614 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1615 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1616 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1617 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1620 case 6: /* E,N,SW,S,NW,NE,SE,W */
1621 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1622 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1623 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1624 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1625 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1626 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1627 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1628 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1631 case 7: /* W,SW,NW,N,E,SE,NE,S */
1632 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1633 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1634 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1635 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1636 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1637 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1638 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1639 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1643 next[x][y] = temp; /* the item we chose to clone */
1644 play_element_sound(x, y, SOUND_android_clone, temp);
1648 /* randomly find a direction to move */
1650 case 0: /* S,NE,W,NW,SE,E,SW,N */
1651 if (is_blank[cave[x][y+1]]) goto android_s;
1652 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1653 if (is_blank[cave[x-1][y]]) goto android_w;
1654 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1655 if (is_blank[cave[x+1][y+1]]) goto android_se;
1656 if (is_blank[cave[x+1][y]]) goto android_e;
1657 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1658 if (is_blank[cave[x][y-1]]) goto android_n;
1661 case 1: /* NW,SE,N,S,NE,SW,E,W */
1662 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1663 if (is_blank[cave[x+1][y+1]]) goto android_se;
1664 if (is_blank[cave[x][y-1]]) goto android_n;
1665 if (is_blank[cave[x][y+1]]) goto android_s;
1666 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1667 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1668 if (is_blank[cave[x+1][y]]) goto android_e;
1669 if (is_blank[cave[x-1][y]]) goto android_w;
1672 case 2: /* SW,E,S,W,N,NW,SE,NE */
1673 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1674 if (is_blank[cave[x+1][y]]) goto android_e;
1675 if (is_blank[cave[x][y+1]]) goto android_s;
1676 if (is_blank[cave[x-1][y]]) goto android_w;
1677 if (is_blank[cave[x][y-1]]) goto android_n;
1678 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1679 if (is_blank[cave[x+1][y+1]]) goto android_se;
1680 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1683 case 3: /* N,SE,NE,E,W,S,NW,SW */
1684 if (is_blank[cave[x][y-1]]) goto android_n;
1685 if (is_blank[cave[x+1][y+1]]) goto android_se;
1686 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1687 if (is_blank[cave[x+1][y]]) goto android_e;
1688 if (is_blank[cave[x-1][y]]) goto android_w;
1689 if (is_blank[cave[x][y+1]]) goto android_s;
1690 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1691 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1694 case 4: /* SE,NW,E,NE,SW,W,N,S */
1695 if (is_blank[cave[x+1][y+1]]) goto android_se;
1696 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1697 if (is_blank[cave[x+1][y]]) goto android_e;
1698 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1699 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1700 if (is_blank[cave[x-1][y]]) goto android_w;
1701 if (is_blank[cave[x][y-1]]) goto android_n;
1702 if (is_blank[cave[x][y+1]]) goto android_s;
1705 case 5: /* NE,W,SE,SW,S,N,E,NW */
1706 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1707 if (is_blank[cave[x-1][y]]) goto android_w;
1708 if (is_blank[cave[x+1][y+1]]) goto android_se;
1709 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1710 if (is_blank[cave[x][y+1]]) goto android_s;
1711 if (is_blank[cave[x][y-1]]) goto android_n;
1712 if (is_blank[cave[x+1][y]]) goto android_e;
1713 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1716 case 6: /* E,N,SW,S,NW,NE,SE,W */
1717 if (is_blank[cave[x+1][y]]) goto android_e;
1718 if (is_blank[cave[x][y-1]]) goto android_n;
1719 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1720 if (is_blank[cave[x][y+1]]) goto android_s;
1721 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1722 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1723 if (is_blank[cave[x+1][y+1]]) goto android_se;
1724 if (is_blank[cave[x-1][y]]) goto android_w;
1727 case 7: /* W,SW,NW,N,E,SE,NE,S */
1728 if (is_blank[cave[x-1][y]]) goto android_w;
1729 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1730 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1731 if (is_blank[cave[x][y-1]]) goto android_n;
1732 if (is_blank[cave[x+1][y]]) goto android_e;
1733 if (is_blank[cave[x+1][y+1]]) goto android_se;
1734 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1735 if (is_blank[cave[x][y+1]]) goto android_s;
1741 if (lev.android_move_cnt == 0)
1743 if (cave[x-1][y-1] == Zplayer ||
1744 cave[x][y-1] == Zplayer ||
1745 cave[x+1][y-1] == Zplayer ||
1746 cave[x-1][y] == Zplayer ||
1747 cave[x+1][y] == Zplayer ||
1748 cave[x-1][y+1] == Zplayer ||
1749 cave[x][y+1] == Zplayer ||
1750 cave[x+1][y+1] == Zplayer)
1753 set_nearest_player_xy(x, y, &dx, &dy);
1755 next[x][y] = Xblank; /* assume we will move */
1756 temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
1762 /* attempt clockwise move first if direct path is blocked */
1764 case 0: /* north west */
1765 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1766 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1767 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1771 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1772 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1773 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1776 case 2: /* north east */
1777 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1778 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1779 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1783 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1784 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1785 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1788 case 4: /* nowhere */
1792 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1793 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1794 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1797 case 6: /* south west */
1798 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1799 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1800 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1804 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1805 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1806 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1809 case 8: /* south east */
1810 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1811 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1812 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1820 /* attempt counterclockwise move first if direct path is blocked */
1822 case 0: /* north west */
1823 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1824 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1825 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1829 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1830 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1831 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1834 case 2: /* north east */
1835 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1836 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1837 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1841 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1842 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1843 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1846 case 4: /* nowhere */
1850 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1851 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1852 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1855 case 6: /* south west */
1856 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1857 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1858 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1862 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1863 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1864 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1867 case 8: /* south east */
1868 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1869 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1870 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1877 next[x][y] = Xandroid;
1881 cave[x][y] = Yandroid_nB;
1882 cave[x][y-1] = Yandroid_n;
1883 next[x][y-1] = Xandroid;
1884 play_element_sound(x, y, SOUND_android_move, Xandroid);
1888 cave[x][y] = Yandroid_neB;
1889 cave[x+1][y-1] = Yandroid_ne;
1890 next[x+1][y-1] = Xandroid;
1891 play_element_sound(x, y, SOUND_android_move, Xandroid);
1895 cave[x][y] = Yandroid_eB;
1896 cave[x+1][y] = Yandroid_e;
1897 next[x+1][y] = Xandroid;
1898 play_element_sound(x, y, SOUND_android_move, Xandroid);
1902 cave[x][y] = Yandroid_seB;
1903 cave[x+1][y+1] = Yandroid_se;
1904 next[x+1][y+1] = Xandroid;
1905 play_element_sound(x, y, SOUND_android_move, Xandroid);
1909 cave[x][y] = Yandroid_sB;
1910 cave[x][y+1] = Yandroid_s;
1911 next[x][y+1] = Xandroid;
1912 play_element_sound(x, y, SOUND_android_move, Xandroid);
1916 cave[x][y] = Yandroid_swB;
1917 cave[x-1][y+1] = Yandroid_sw;
1918 next[x-1][y+1] = Xandroid;
1919 play_element_sound(x, y, SOUND_android_move, Xandroid);
1923 cave[x][y] = Yandroid_wB;
1924 cave[x-1][y] = Yandroid_w;
1925 next[x-1][y] = Xandroid;
1926 play_element_sound(x, y, SOUND_android_move, Xandroid);
1930 cave[x][y] = Yandroid_nwB;
1931 cave[x-1][y-1] = Yandroid_nw;
1932 next[x-1][y-1] = Xandroid;
1933 play_element_sound(x, y, SOUND_android_move, Xandroid);
1937 static void Landroid_1_n(int x, int y)
1939 switch (cave[x][y-1])
1952 cave[x][y] = Yandroid_nB;
1953 next[x][y] = Xblank;
1954 cave[x][y-1] = Yandroid_n;
1955 next[x][y-1] = Xandroid;
1956 play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
1967 cave[x][y] = Yandroid_nB;
1968 next[x][y] = Xblank;
1969 if (cave[x+1][y-2] == Xblank)
1970 cave[x+1][y-2] = Xsplash_e;
1971 if (cave[x-1][y-2] == Xblank)
1972 cave[x-1][y-2] = Xsplash_w;
1973 play_element_sound(x, y, SOUND_acid, Xacid_1);
1982 static void Landroid_2_n(int x, int y)
1984 switch (cave[x][y-1])
1997 cave[x][y] = Yandroid_nB;
1998 next[x][y] = Xblank;
1999 cave[x][y-1] = Yandroid_n;
2000 next[x][y-1] = Xandroid_1_n;
2001 play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
2012 cave[x][y] = Yandroid_nB;
2013 next[x][y] = Xblank;
2014 if (cave[x+1][y-2] == Xblank)
2015 cave[x+1][y-2] = Xsplash_e;
2016 if (cave[x-1][y-2] == Xblank)
2017 cave[x-1][y-2] = Xsplash_w;
2018 play_element_sound(x, y, SOUND_acid, Xacid_1);
2027 static void Landroid_1_e(int x, int y)
2029 switch (cave[x+1][y])
2042 cave[x][y] = Yandroid_eB;
2043 next[x][y] = Xblank;
2044 cave[x+1][y] = Yandroid_e;
2045 next[x+1][y] = Xandroid;
2046 play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
2057 cave[x][y] = Yandroid_eB;
2058 next[x][y] = Xblank;
2059 if (cave[x+2][y-1] == Xblank)
2060 cave[x+2][y-1] = Xsplash_e;
2061 if (cave[x][y-1] == Xblank)
2062 cave[x][y-1] = Xsplash_w;
2063 play_element_sound(x, y, SOUND_acid, Xacid_1);
2072 static void Landroid_2_e(int x, int y)
2074 switch (cave[x+1][y])
2087 cave[x][y] = Yandroid_eB;
2088 next[x][y] = Xblank;
2089 cave[x+1][y] = Yandroid_e;
2090 next[x+1][y] = Xandroid_1_e;
2091 play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
2102 cave[x][y] = Yandroid_eB;
2103 next[x][y] = Xblank;
2104 if (cave[x+2][y-1] == Xblank)
2105 cave[x+2][y-1] = Xsplash_e;
2106 if (cave[x][y-1] == Xblank)
2107 cave[x][y-1] = Xsplash_w;
2108 play_element_sound(x, y, SOUND_acid, Xacid_1);
2117 static void Landroid_1_s(int x, int y)
2119 switch (cave[x][y+1])
2132 cave[x][y] = Yandroid_sB;
2133 next[x][y] = Xblank;
2134 cave[x][y+1] = Yandroid_s;
2135 next[x][y+1] = Xandroid;
2136 play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
2147 cave[x][y] = Yandroid_sB;
2148 next[x][y] = Xblank;
2149 if (cave[x+1][y] == Xblank)
2150 cave[x+1][y] = Xsplash_e;
2151 if (cave[x-1][y] == Xblank)
2152 cave[x-1][y] = Xsplash_w;
2153 play_element_sound(x, y, SOUND_acid, Xacid_1);
2162 static void Landroid_2_s(int x, int y)
2164 switch (cave[x][y+1])
2177 cave[x][y] = Yandroid_sB;
2178 next[x][y] = Xblank;
2179 cave[x][y+1] = Yandroid_s;
2180 next[x][y+1] = Xandroid_1_s;
2181 play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
2192 cave[x][y] = Yandroid_sB;
2193 next[x][y] = Xblank;
2194 if (cave[x+1][y] == Xblank)
2195 cave[x+1][y] = Xsplash_e;
2196 if (cave[x-1][y] == Xblank)
2197 cave[x-1][y] = Xsplash_w;
2198 play_element_sound(x, y, SOUND_acid, Xacid_1);
2207 static void Landroid_1_w(int x, int y)
2209 switch (cave[x-1][y])
2222 cave[x][y] = Yandroid_wB;
2223 next[x][y] = Xblank;
2224 cave[x-1][y] = Yandroid_w;
2225 next[x-1][y] = Xandroid;
2226 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2237 cave[x][y] = Yandroid_wB;
2238 next[x][y] = Xblank;
2239 if (cave[x][y-1] == Xblank)
2240 cave[x][y-1] = Xsplash_e;
2241 if (cave[x-2][y-1] == Xblank)
2242 cave[x-2][y-1] = Xsplash_w;
2243 play_element_sound(x, y, SOUND_acid, Xacid_1);
2252 static void Landroid_2_w(int x, int y)
2254 switch (cave[x-1][y])
2267 cave[x][y] = Yandroid_wB;
2268 next[x][y] = Xblank;
2269 cave[x-1][y] = Yandroid_w;
2270 next[x-1][y] = Xandroid_1_w;
2271 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2282 cave[x][y] = Yandroid_wB;
2283 next[x][y] = Xblank;
2284 if (cave[x][y-1] == Xblank)
2285 cave[x][y-1] = Xsplash_e;
2286 if (cave[x-2][y-1] == Xblank)
2287 cave[x-2][y-1] = Xsplash_w;
2288 play_element_sound(x, y, SOUND_acid, Xacid_1);
2297 static void Leater_n(int x, int y)
2299 if (cave[x+1][y] == Xdiamond)
2301 cave[x+1][y] = Ydiamond_blank;
2302 next[x+1][y] = Xblank;
2303 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2307 if (cave[x][y+1] == Xdiamond)
2309 cave[x][y+1] = Ydiamond_blank;
2310 next[x][y+1] = Xblank;
2311 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2315 if (cave[x-1][y] == Xdiamond)
2317 cave[x-1][y] = Ydiamond_blank;
2318 next[x-1][y] = Xblank;
2319 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2323 if (cave[x][y-1] == Xdiamond)
2325 cave[x][y-1] = Ydiamond_blank;
2326 next[x][y-1] = Xblank;
2327 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2331 switch (cave[x][y-1])
2347 cave[x][y] = Yeater_nB;
2348 next[x][y] = Xblank;
2349 cave[x][y-1] = Yeater_n;
2350 next[x][y-1] = Xeater_n;
2361 cave[x][y] = Yeater_nB;
2362 next[x][y] = Xblank;
2363 if (cave[x+1][y-2] == Xblank)
2364 cave[x+1][y-2] = Xsplash_e;
2365 if (cave[x-1][y-2] == Xblank)
2366 cave[x-1][y-2] = Xsplash_w;
2367 play_element_sound(x, y, SOUND_acid, Xacid_1);
2371 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2372 play_element_sound(x, y, SOUND_eater, Xeater_n);
2377 static void Leater_e(int x, int y)
2379 if (cave[x][y+1] == Xdiamond)
2381 cave[x][y+1] = Ydiamond_blank;
2382 next[x][y+1] = Xblank;
2383 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2387 if (cave[x-1][y] == Xdiamond)
2389 cave[x-1][y] = Ydiamond_blank;
2390 next[x-1][y] = Xblank;
2391 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2395 if (cave[x][y-1] == Xdiamond)
2397 cave[x][y-1] = Ydiamond_blank;
2398 next[x][y-1] = Xblank;
2399 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2403 if (cave[x+1][y] == Xdiamond)
2405 cave[x+1][y] = Ydiamond_blank;
2406 next[x+1][y] = Xblank;
2407 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2411 switch (cave[x+1][y])
2427 cave[x][y] = Yeater_eB;
2428 next[x][y] = Xblank;
2429 cave[x+1][y] = Yeater_e;
2430 next[x+1][y] = Xeater_e;
2441 cave[x][y] = Yeater_eB;
2442 next[x][y] = Xblank;
2443 if (cave[x+2][y-1] == Xblank)
2444 cave[x+2][y-1] = Xsplash_e;
2445 if (cave[x][y-1] == Xblank)
2446 cave[x][y-1] = Xsplash_w;
2447 play_element_sound(x, y, SOUND_acid, Xacid_1);
2451 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2452 play_element_sound(x, y, SOUND_eater, Xeater_e);
2457 static void Leater_s(int x, int y)
2459 if (cave[x-1][y] == Xdiamond)
2461 cave[x-1][y] = Ydiamond_blank;
2462 next[x-1][y] = Xblank;
2463 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2467 if (cave[x][y-1] == Xdiamond)
2469 cave[x][y-1] = Ydiamond_blank;
2470 next[x][y-1] = Xblank;
2471 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2475 if (cave[x+1][y] == Xdiamond)
2477 cave[x+1][y] = Ydiamond_blank;
2478 next[x+1][y] = Xblank;
2479 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2483 if (cave[x][y+1] == Xdiamond)
2485 cave[x][y+1] = Ydiamond_blank;
2486 next[x][y+1] = Xblank;
2487 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2491 switch (cave[x][y+1])
2507 cave[x][y] = Yeater_sB;
2508 next[x][y] = Xblank;
2509 cave[x][y+1] = Yeater_s;
2510 next[x][y+1] = Xeater_s;
2521 cave[x][y] = Yeater_sB;
2522 next[x][y] = Xblank;
2523 if (cave[x+1][y] == Xblank)
2524 cave[x+1][y] = Xsplash_e;
2525 if (cave[x-1][y] == Xblank)
2526 cave[x-1][y] = Xsplash_w;
2527 play_element_sound(x, y, SOUND_acid, Xacid_1);
2531 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2532 play_element_sound(x, y, SOUND_eater, Xeater_s);
2537 static void Leater_w(int x, int y)
2539 if (cave[x][y-1] == Xdiamond)
2541 cave[x][y-1] = Ydiamond_blank;
2542 next[x][y-1] = Xblank;
2543 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2547 if (cave[x+1][y] == Xdiamond)
2549 cave[x+1][y] = Ydiamond_blank;
2550 next[x+1][y] = Xblank;
2551 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2555 if (cave[x][y+1] == Xdiamond)
2557 cave[x][y+1] = Ydiamond_blank;
2558 next[x][y+1] = Xblank;
2559 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2563 if (cave[x-1][y] == Xdiamond)
2565 cave[x-1][y] = Ydiamond_blank;
2566 next[x-1][y] = Xblank;
2567 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2571 switch (cave[x-1][y])
2587 cave[x][y] = Yeater_wB;
2588 next[x][y] = Xblank;
2589 cave[x-1][y] = Yeater_w;
2590 next[x-1][y] = Xeater_w;
2601 cave[x][y] = Yeater_wB;
2602 next[x][y] = Xblank;
2603 if (cave[x][y-1] == Xblank)
2604 cave[x][y-1] = Xsplash_e;
2605 if (cave[x-2][y-1] == Xblank)
2606 cave[x-2][y-1] = Xsplash_w;
2607 play_element_sound(x, y, SOUND_acid, Xacid_1);
2611 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2612 play_element_sound(x, y, SOUND_eater, Xeater_w);
2617 static void Lalien(int x, int y)
2628 set_nearest_player_xy(x, y, &dx, &dy);
2635 switch (cave[x][y-1])
2651 cave[x][y] = Yalien_nB;
2652 next[x][y] = Xblank;
2653 cave[x][y-1] = Yalien_n;
2654 next[x][y-1] = Xalien_pause;
2655 play_element_sound(x, y, SOUND_alien, Xalien);
2666 cave[x][y] = Yalien_nB;
2667 next[x][y] = Xblank;
2668 if (cave[x+1][y-2] == Xblank)
2669 cave[x+1][y-2] = Xsplash_e;
2670 if (cave[x-1][y-2] == Xblank)
2671 cave[x-1][y-2] = Xsplash_w;
2672 play_element_sound(x, y, SOUND_acid, Xacid_1);
2678 switch (cave[x][y+1])
2694 cave[x][y] = Yalien_sB;
2695 next[x][y] = Xblank;
2696 cave[x][y+1] = Yalien_s;
2697 next[x][y+1] = Xalien_pause;
2698 play_element_sound(x, y, SOUND_alien, Xalien);
2709 cave[x][y] = Yalien_sB;
2710 next[x][y] = Xblank;
2711 if (cave[x+1][y] == Xblank)
2712 cave[x+1][y] = Xsplash_e;
2713 if (cave[x-1][y] == Xblank)
2714 cave[x-1][y] = Xsplash_w;
2715 play_element_sound(x, y, SOUND_acid, Xacid_1);
2724 switch (cave[x+1][y])
2740 cave[x][y] = Yalien_eB;
2741 next[x][y] = Xblank;
2742 cave[x+1][y] = Yalien_e;
2743 next[x+1][y] = Xalien_pause;
2744 play_element_sound(x, y, SOUND_alien, Xalien);
2755 cave[x][y] = Yalien_eB;
2756 next[x][y] = Xblank;
2757 if (cave[x+2][y-1] == Xblank)
2758 cave[x+2][y-1] = Xsplash_e;
2759 if (cave[x][y-1] == Xblank)
2760 cave[x][y-1] = Xsplash_w;
2761 play_element_sound(x, y, SOUND_acid, Xacid_1);
2767 switch (cave[x-1][y])
2783 cave[x][y] = Yalien_wB;
2784 next[x][y] = Xblank;
2785 cave[x-1][y] = Yalien_w;
2786 next[x-1][y] = Xalien_pause;
2787 play_element_sound(x, y, SOUND_alien, Xalien);
2798 cave[x][y] = Yalien_wB;
2799 next[x][y] = Xblank;
2800 if (cave[x][y-1] == Xblank)
2801 cave[x][y-1] = Xsplash_e;
2802 if (cave[x-2][y-1] == Xblank)
2803 cave[x-2][y-1] = Xsplash_w;
2804 play_element_sound(x, y, SOUND_acid, Xacid_1);
2811 static void Lalien_pause(int x, int y)
2813 next[x][y] = Xalien;
2816 static void Lbug_n(int x, int y)
2818 switch (cave[x][y-1])
2834 cave[x][y] = Ybug_nB;
2835 next[x][y] = Xblank;
2836 cave[x][y-1] = Ybug_n;
2837 next[x][y-1] = Xbug_1_n;
2838 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2849 cave[x][y] = Ybug_nB;
2850 next[x][y] = Xblank;
2851 if (cave[x+1][y-2] == Xblank)
2852 cave[x+1][y-2] = Xsplash_e;
2853 if (cave[x-1][y-2] == Xblank)
2854 cave[x-1][y-2] = Xsplash_w;
2855 play_element_sound(x, y, SOUND_acid, Xacid_1);
2859 cave[x][y] = Ybug_n_w;
2860 next[x][y] = Xbug_2_w;
2861 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2866 static void Lbug_1_n(int x, int y)
2868 if (is_amoeba[cave[x][y-1]] ||
2869 is_amoeba[cave[x+1][y]] ||
2870 is_amoeba[cave[x][y+1]] ||
2871 is_amoeba[cave[x-1][y]])
2879 switch (cave[x+1][y])
2903 cave[x][y] = Ybug_n_e;
2904 next[x][y] = Xbug_2_e;
2905 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2914 static void Lbug_2_n(int x, int y)
2916 if (is_amoeba[cave[x][y-1]] ||
2917 is_amoeba[cave[x+1][y]] ||
2918 is_amoeba[cave[x][y+1]] ||
2919 is_amoeba[cave[x-1][y]])
2930 static void Lbug_e(int x, int y)
2932 switch (cave[x+1][y])
2948 cave[x][y] = Ybug_eB;
2949 next[x][y] = Xblank;
2950 cave[x+1][y] = Ybug_e;
2951 next[x+1][y] = Xbug_1_e;
2952 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2963 cave[x][y] = Ybug_eB;
2964 next[x][y] = Xblank;
2965 if (cave[x+2][y-1] == Xblank)
2966 cave[x+2][y-1] = Xsplash_e;
2967 if (cave[x][y-1] == Xblank)
2968 cave[x][y-1] = Xsplash_w;
2969 play_element_sound(x, y, SOUND_acid, Xacid_1);
2973 cave[x][y] = Ybug_e_n;
2974 next[x][y] = Xbug_2_n;
2975 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2980 static void Lbug_1_e(int x, int y)
2982 if (is_amoeba[cave[x][y-1]] ||
2983 is_amoeba[cave[x+1][y]] ||
2984 is_amoeba[cave[x][y+1]] ||
2985 is_amoeba[cave[x-1][y]])
2993 switch (cave[x][y+1])
3017 cave[x][y] = Ybug_e_s;
3018 next[x][y] = Xbug_2_s;
3019 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
3028 static void Lbug_2_e(int x, int y)
3030 if (is_amoeba[cave[x][y-1]] ||
3031 is_amoeba[cave[x+1][y]] ||
3032 is_amoeba[cave[x][y+1]] ||
3033 is_amoeba[cave[x-1][y]])
3044 static void Lbug_s(int x, int y)
3046 switch (cave[x][y+1])
3062 cave[x][y] = Ybug_sB;
3063 next[x][y] = Xblank;
3064 cave[x][y+1] = Ybug_s;
3065 next[x][y+1] = Xbug_1_s;
3066 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3077 cave[x][y] = Ybug_sB;
3078 next[x][y] = Xblank;
3079 if (cave[x+1][y] == Xblank)
3080 cave[x+1][y] = Xsplash_e;
3081 if (cave[x-1][y] == Xblank)
3082 cave[x-1][y] = Xsplash_w;
3083 play_element_sound(x, y, SOUND_acid, Xacid_1);
3087 cave[x][y] = Ybug_s_e;
3088 next[x][y] = Xbug_2_e;
3089 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3094 static void Lbug_1_s(int x, int y)
3096 if (is_amoeba[cave[x][y-1]] ||
3097 is_amoeba[cave[x+1][y]] ||
3098 is_amoeba[cave[x][y+1]] ||
3099 is_amoeba[cave[x-1][y]])
3107 switch (cave[x-1][y])
3131 cave[x][y] = Ybug_s_w;
3132 next[x][y] = Xbug_2_w;
3133 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3142 static void Lbug_2_s(int x, int y)
3144 if (is_amoeba[cave[x][y-1]] ||
3145 is_amoeba[cave[x+1][y]] ||
3146 is_amoeba[cave[x][y+1]] ||
3147 is_amoeba[cave[x-1][y]])
3158 static void Lbug_w(int x, int y)
3160 switch (cave[x-1][y])
3176 cave[x][y] = Ybug_wB;
3177 next[x][y] = Xblank;
3178 cave[x-1][y] = Ybug_w;
3179 next[x-1][y] = Xbug_1_w;
3180 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3191 cave[x][y] = Ybug_wB;
3192 next[x][y] = Xblank;
3193 if (cave[x][y-1] == Xblank)
3194 cave[x][y-1] = Xsplash_e;
3195 if (cave[x-2][y-1] == Xblank)
3196 cave[x-2][y-1] = Xsplash_w;
3197 play_element_sound(x, y, SOUND_acid, Xacid_1);
3201 cave[x][y] = Ybug_w_s;
3202 next[x][y] = Xbug_2_s;
3203 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3208 static void Lbug_1_w(int x, int y)
3210 if (is_amoeba[cave[x][y-1]] ||
3211 is_amoeba[cave[x+1][y]] ||
3212 is_amoeba[cave[x][y+1]] ||
3213 is_amoeba[cave[x-1][y]])
3221 switch (cave[x][y-1])
3245 cave[x][y] = Ybug_w_n;
3246 next[x][y] = Xbug_2_n;
3247 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3256 static void Lbug_2_w(int x, int y)
3258 if (is_amoeba[cave[x][y-1]] ||
3259 is_amoeba[cave[x+1][y]] ||
3260 is_amoeba[cave[x][y+1]] ||
3261 is_amoeba[cave[x-1][y]])
3272 static void Ltank_n(int x, int y)
3274 switch (cave[x][y-1])
3290 cave[x][y] = Ytank_nB;
3291 next[x][y] = Xblank;
3292 cave[x][y-1] = Ytank_n;
3293 next[x][y-1] = Xtank_1_n;
3294 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3305 cave[x][y] = Ytank_nB;
3306 next[x][y] = Xblank;
3307 if (cave[x+1][y-2] == Xblank)
3308 cave[x+1][y-2] = Xsplash_e;
3309 if (cave[x-1][y-2] == Xblank)
3310 cave[x-1][y-2] = Xsplash_w;
3311 play_element_sound(x, y, SOUND_acid, Xacid_1);
3315 cave[x][y] = Ytank_n_e;
3316 next[x][y] = Xtank_2_e;
3317 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3322 static void Ltank_1_n(int x, int y)
3324 if (is_amoeba[cave[x][y-1]] ||
3325 is_amoeba[cave[x+1][y]] ||
3326 is_amoeba[cave[x][y+1]] ||
3327 is_amoeba[cave[x-1][y]])
3335 switch (cave[x-1][y])
3359 cave[x][y] = Ytank_n_w;
3360 next[x][y] = Xtank_2_w;
3361 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3370 static void Ltank_2_n(int x, int y)
3372 if (is_amoeba[cave[x][y-1]] ||
3373 is_amoeba[cave[x+1][y]] ||
3374 is_amoeba[cave[x][y+1]] ||
3375 is_amoeba[cave[x-1][y]])
3386 static void Ltank_e(int x, int y)
3388 switch (cave[x+1][y])
3404 cave[x][y] = Ytank_eB;
3405 next[x][y] = Xblank;
3406 cave[x+1][y] = Ytank_e;
3407 next[x+1][y] = Xtank_1_e;
3408 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3419 cave[x][y] = Ytank_eB;
3420 next[x][y] = Xblank;
3421 if (cave[x+2][y-1] == Xblank)
3422 cave[x+2][y-1] = Xsplash_e;
3423 if (cave[x][y-1] == Xblank)
3424 cave[x][y-1] = Xsplash_w;
3425 play_element_sound(x, y, SOUND_acid, Xacid_1);
3429 cave[x][y] = Ytank_e_s;
3430 next[x][y] = Xtank_2_s;
3431 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3436 static void Ltank_1_e(int x, int y)
3438 if (is_amoeba[cave[x][y-1]] ||
3439 is_amoeba[cave[x+1][y]] ||
3440 is_amoeba[cave[x][y+1]] ||
3441 is_amoeba[cave[x-1][y]])
3449 switch (cave[x][y-1])
3473 cave[x][y] = Ytank_e_n;
3474 next[x][y] = Xtank_2_n;
3475 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3484 static void Ltank_2_e(int x, int y)
3486 if (is_amoeba[cave[x][y-1]] ||
3487 is_amoeba[cave[x+1][y]] ||
3488 is_amoeba[cave[x][y+1]] ||
3489 is_amoeba[cave[x-1][y]])
3500 static void Ltank_s(int x, int y)
3502 switch (cave[x][y+1])
3518 cave[x][y] = Ytank_sB;
3519 next[x][y] = Xblank;
3520 cave[x][y+1] = Ytank_s;
3521 next[x][y+1] = Xtank_1_s;
3522 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3533 cave[x][y] = Ytank_sB;
3534 next[x][y] = Xblank;
3535 if (cave[x+1][y] == Xblank)
3536 cave[x+1][y] = Xsplash_e;
3537 if (cave[x-1][y] == Xblank)
3538 cave[x-1][y] = Xsplash_w;
3539 play_element_sound(x, y, SOUND_acid, Xacid_1);
3543 cave[x][y] = Ytank_s_w;
3544 next[x][y] = Xtank_2_w;
3545 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3550 static void Ltank_1_s(int x, int y)
3552 if (is_amoeba[cave[x][y-1]] ||
3553 is_amoeba[cave[x+1][y]] ||
3554 is_amoeba[cave[x][y+1]] ||
3555 is_amoeba[cave[x-1][y]])
3563 switch (cave[x+1][y])
3587 cave[x][y] = Ytank_s_e;
3588 next[x][y] = Xtank_2_e;
3589 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3598 static void Ltank_2_s(int x, int y)
3600 if (is_amoeba[cave[x][y-1]] ||
3601 is_amoeba[cave[x+1][y]] ||
3602 is_amoeba[cave[x][y+1]] ||
3603 is_amoeba[cave[x-1][y]])
3614 static void Ltank_w(int x, int y)
3616 switch (cave[x-1][y])
3632 cave[x][y] = Ytank_wB;
3633 next[x][y] = Xblank;
3634 cave[x-1][y] = Ytank_w;
3635 next[x-1][y] = Xtank_1_w;
3636 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3647 cave[x][y] = Ytank_wB;
3648 next[x][y] = Xblank;
3649 if (cave[x][y-1] == Xblank)
3650 cave[x][y-1] = Xsplash_e;
3651 if (cave[x-2][y-1] == Xblank)
3652 cave[x-2][y-1] = Xsplash_w;
3653 play_element_sound(x, y, SOUND_acid, Xacid_1);
3657 cave[x][y] = Ytank_w_n;
3658 next[x][y] = Xtank_2_n;
3659 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3664 static void Ltank_1_w(int x, int y)
3666 if (is_amoeba[cave[x][y-1]] ||
3667 is_amoeba[cave[x+1][y]] ||
3668 is_amoeba[cave[x][y+1]] ||
3669 is_amoeba[cave[x-1][y]])
3677 switch (cave[x][y+1])
3701 cave[x][y] = Ytank_w_s;
3702 next[x][y] = Xtank_2_s;
3703 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3712 static void Ltank_2_w(int x, int y)
3714 if (is_amoeba[cave[x][y-1]] ||
3715 is_amoeba[cave[x+1][y]] ||
3716 is_amoeba[cave[x][y+1]] ||
3717 is_amoeba[cave[x-1][y]])
3728 static void Lemerald(int x, int y)
3730 switch (cave[x][y+1])
3743 cave[x][y] = Yemerald_sB;
3744 next[x][y] = Xblank;
3745 cave[x][y+1] = Yemerald_s;
3746 next[x][y+1] = Xemerald_fall;
3757 cave[x][y] = Yemerald_sB;
3758 next[x][y] = Xblank;
3759 if (cave[x+1][y] == Xblank)
3760 cave[x+1][y] = Xsplash_e;
3761 if (cave[x-1][y] == Xblank)
3762 cave[x-1][y] = Xsplash_w;
3763 play_element_sound(x, y, SOUND_acid, Xacid_1);
3776 case Xemerald_pause:
3778 case Xdiamond_pause:
3822 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3824 cave[x][y] = Yemerald_eB;
3825 next[x][y] = Xblank;
3826 cave[x+1][y] = Yemerald_e;
3827 next[x+1][y] = Xemerald_pause;
3828 if (cave[x][y+1] == Xbumper)
3829 cave[x][y+1] = Ybumper;
3833 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3835 cave[x][y] = Yemerald_wB;
3836 next[x][y] = Xblank;
3837 cave[x-1][y] = Yemerald_w;
3838 next[x-1][y] = Xemerald_pause;
3839 if (cave[x][y+1] == Xbumper)
3840 cave[x][y+1] = Ybumper;
3846 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3848 cave[x][y] = Yemerald_wB;
3849 next[x][y] = Xblank;
3850 cave[x-1][y] = Yemerald_w;
3851 next[x-1][y] = Xemerald_pause;
3852 if (cave[x][y+1] == Xbumper)
3853 cave[x][y+1] = Ybumper;
3857 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3859 cave[x][y] = Yemerald_eB;
3860 next[x][y] = Xblank;
3861 cave[x+1][y] = Yemerald_e;
3862 next[x+1][y] = Xemerald_pause;
3863 if (cave[x][y+1] == Xbumper)
3864 cave[x][y+1] = Ybumper;
3870 if (++lev.shine_cnt > 50)
3872 lev.shine_cnt = RANDOM(8);
3873 cave[x][y] = Xemerald_shine;
3880 static void Lemerald_pause(int x, int y)
3882 switch (cave[x][y+1])
3895 cave[x][y] = Yemerald_sB;
3896 next[x][y] = Xblank;
3897 cave[x][y+1] = Yemerald_s;
3898 next[x][y+1] = Xemerald_fall;
3909 cave[x][y] = Yemerald_sB;
3910 next[x][y] = Xblank;
3911 if (cave[x+1][y] == Xblank)
3912 cave[x+1][y] = Xsplash_e;
3913 if (cave[x-1][y] == Xblank)
3914 cave[x-1][y] = Xsplash_w;
3915 play_element_sound(x, y, SOUND_acid, Xacid_1);
3919 cave[x][y] = Xemerald;
3920 next[x][y] = Xemerald;
3925 static void Lemerald_fall(int x, int y)
3927 switch (cave[x][y+1])
3941 cave[x][y] = Yemerald_sB;
3942 next[x][y] = Xblank;
3943 cave[x][y+1] = Yemerald_s;
3944 next[x][y+1] = Xemerald_fall;
3955 cave[x][y] = Yemerald_sB;
3956 next[x][y] = Xblank;
3957 if (cave[x+1][y] == Xblank)
3958 cave[x+1][y] = Xsplash_e;
3959 if (cave[x-1][y] == Xblank)
3960 cave[x-1][y] = Xsplash_w;
3961 play_element_sound(x, y, SOUND_acid, Xacid_1);
3965 if (lev.wonderwall_time)
3967 lev.wonderwall_state = 1;
3968 cave[x][y] = Yemerald_sB;
3969 next[x][y] = Xblank;
3970 if (is_blank[cave[x][y+2]])
3972 cave[x][y+2] = Ydiamond_s;
3973 next[x][y+2] = Xdiamond_fall;
3975 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
3980 cave[x][y] = Xemerald;
3981 next[x][y] = Xemerald;
3982 play_element_sound(x, y, SOUND_diamond, Xemerald);
3987 static void Ldiamond(int x, int y)
3989 switch (cave[x][y+1])
4002 cave[x][y] = Ydiamond_sB;
4003 next[x][y] = Xblank;
4004 cave[x][y+1] = Ydiamond_s;
4005 next[x][y+1] = Xdiamond_fall;
4016 cave[x][y] = Ydiamond_sB;
4017 next[x][y] = Xblank;
4018 if (cave[x+1][y] == Xblank)
4019 cave[x+1][y] = Xsplash_e;
4020 if (cave[x-1][y] == Xblank)
4021 cave[x-1][y] = Xsplash_w;
4022 play_element_sound(x, y, SOUND_acid, Xacid_1);
4035 case Xemerald_pause:
4037 case Xdiamond_pause:
4081 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4083 cave[x][y] = Ydiamond_eB;
4084 next[x][y] = Xblank;
4085 cave[x+1][y] = Ydiamond_e;
4086 next[x+1][y] = Xdiamond_pause;
4087 if (cave[x][y+1] == Xbumper)
4088 cave[x][y+1] = Ybumper;
4092 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4094 cave[x][y] = Ydiamond_wB;
4095 next[x][y] = Xblank;
4096 cave[x-1][y] = Ydiamond_w;
4097 next[x-1][y] = Xdiamond_pause;
4098 if (cave[x][y+1] == Xbumper)
4099 cave[x][y+1] = Ybumper;
4105 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4107 cave[x][y] = Ydiamond_wB;
4108 next[x][y] = Xblank;
4109 cave[x-1][y] = Ydiamond_w;
4110 next[x-1][y] = Xdiamond_pause;
4111 if (cave[x][y+1] == Xbumper)
4112 cave[x][y+1] = Ybumper;
4116 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4118 cave[x][y] = Ydiamond_eB;
4119 next[x][y] = Xblank;
4120 cave[x+1][y] = Ydiamond_e;
4121 next[x+1][y] = Xdiamond_pause;
4122 if (cave[x][y+1] == Xbumper)
4123 cave[x][y+1] = Ybumper;
4129 if (++lev.shine_cnt > 50)
4131 lev.shine_cnt = RANDOM(8);
4132 cave[x][y] = Xdiamond_shine;
4139 static void Ldiamond_pause(int x, int y)
4141 switch (cave[x][y+1])
4154 cave[x][y] = Ydiamond_sB;
4155 next[x][y] = Xblank;
4156 cave[x][y+1] = Ydiamond_s;
4157 next[x][y+1] = Xdiamond_fall;
4168 cave[x][y] = Ydiamond_sB;
4169 next[x][y] = Xblank;
4170 if (cave[x+1][y] == Xblank)
4171 cave[x+1][y] = Xsplash_e;
4172 if (cave[x-1][y] == Xblank)
4173 cave[x-1][y] = Xsplash_w;
4174 play_element_sound(x, y, SOUND_acid, Xacid_1);
4178 cave[x][y] = Xdiamond;
4179 next[x][y] = Xdiamond;
4184 static void Ldiamond_fall(int x, int y)
4186 switch (cave[x][y+1])
4200 cave[x][y] = Ydiamond_sB;
4201 next[x][y] = Xblank;
4202 cave[x][y+1] = Ydiamond_s;
4203 next[x][y+1] = Xdiamond_fall;
4214 cave[x][y] = Ydiamond_sB;
4215 next[x][y] = Xblank;
4216 if (cave[x+1][y] == Xblank)
4217 cave[x+1][y] = Xsplash_e;
4218 if (cave[x-1][y] == Xblank)
4219 cave[x-1][y] = Xsplash_w;
4220 play_element_sound(x, y, SOUND_acid, Xacid_1);
4224 if (lev.wonderwall_time)
4226 lev.wonderwall_state = 1;
4227 cave[x][y] = Ydiamond_sB;
4228 next[x][y] = Xblank;
4229 if (is_blank[cave[x][y+2]])
4231 cave[x][y+2] = Ystone_s;
4232 next[x][y+2] = Xstone_fall;
4234 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4239 cave[x][y] = Xdiamond;
4240 next[x][y] = Xdiamond;
4241 play_element_sound(x, y, SOUND_diamond, Xdiamond);
4246 static void Lstone(int x, int y)
4248 switch (cave[x][y+1])
4263 cave[x][y] = Ystone_sB;
4264 next[x][y] = Xblank;
4265 cave[x][y+1] = Ystone_s;
4266 next[x][y+1] = Xstone_fall;
4277 cave[x][y] = Ystone_sB;
4278 next[x][y] = Xblank;
4279 if (cave[x+1][y] == Xblank)
4280 cave[x+1][y] = Xsplash_e;
4281 if (cave[x-1][y] == Xblank)
4282 cave[x-1][y] = Xsplash_w;
4283 play_element_sound(x, y, SOUND_acid, Xacid_1);
4287 cave[x][y] = Xsand_stonein_1;
4288 next[x][y] = Xsand_stonein_2;
4289 cave[x][y+1] = Xsand_sandstone_1;
4290 next[x][y+1] = Xsand_sandstone_2;
4303 case Xemerald_pause:
4305 case Xdiamond_pause:
4342 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4344 cave[x][y] = Ystone_eB;
4345 next[x][y] = Xblank;
4346 cave[x+1][y] = Ystone_e;
4347 next[x+1][y] = Xstone_pause;
4348 if (cave[x][y+1] == Xbumper)
4349 cave[x][y+1] = Ybumper;
4353 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4355 cave[x][y] = Ystone_wB;
4356 next[x][y] = Xblank;
4357 cave[x-1][y] = Ystone_w;
4358 next[x-1][y] = Xstone_pause;
4359 if (cave[x][y+1] == Xbumper)
4360 cave[x][y+1] = Ybumper;
4366 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4368 cave[x][y] = Ystone_wB;
4369 next[x][y] = Xblank;
4370 cave[x-1][y] = Ystone_w;
4371 next[x-1][y] = Xstone_pause;
4372 if (cave[x][y+1] == Xbumper)
4373 cave[x][y+1] = Ybumper;
4377 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4379 cave[x][y] = Ystone_eB;
4380 next[x][y] = Xblank;
4381 cave[x+1][y] = Ystone_e;
4382 next[x+1][y] = Xstone_pause;
4383 if (cave[x][y+1] == Xbumper)
4384 cave[x][y+1] = Ybumper;
4391 static void Lstone_pause(int x, int y)
4393 switch (cave[x][y+1])
4406 cave[x][y] = Ystone_sB;
4407 next[x][y] = Xblank;
4408 cave[x][y+1] = Ystone_s;
4409 next[x][y+1] = Xstone_fall;
4420 cave[x][y] = Ystone_sB;
4421 next[x][y] = Xblank;
4422 if (cave[x+1][y] == Xblank)
4423 cave[x+1][y] = Xsplash_e;
4424 if (cave[x-1][y] == Xblank)
4425 cave[x-1][y] = Xsplash_w;
4426 play_element_sound(x, y, SOUND_acid, Xacid_1);
4430 cave[x][y] = Xstone;
4431 next[x][y] = Xstone;
4436 static void Lstone_fall(int x, int y)
4438 switch (cave[x][y+1])
4452 cave[x][y] = Ystone_sB;
4453 next[x][y] = Xblank;
4454 cave[x][y+1] = Ystone_s;
4455 next[x][y+1] = Xstone_fall;
4466 cave[x][y] = Ystone_sB;
4467 next[x][y] = Xblank;
4468 if (cave[x+1][y] == Xblank)
4469 cave[x+1][y] = Xsplash_e;
4470 if (cave[x-1][y] == Xblank)
4471 cave[x-1][y] = Xsplash_w;
4472 play_element_sound(x, y, SOUND_acid, Xacid_1);
4479 cave[x][y] = Ystone_sB;
4480 next[x][y] = Xblank;
4481 cave[x][y+1] = Yeater_stone;
4482 next[x][y+1] = Zeater;
4483 Lboom_eater_old(x, y+1);
4484 score += lev.eater_score;
4489 cave[x][y] = Ystone_sB;
4490 next[x][y] = Xblank;
4491 cave[x][y+1] = Yalien_stone;
4492 next[x][y+1] = Ztank;
4493 Lboom_tank_old(x, y+1);
4494 score += lev.alien_score;
4505 cave[x][y] = Ystone_sB;
4506 next[x][y] = Xblank;
4507 cave[x][y+1] = Ybug_stone;
4508 next[x][y+1] = Zbug;
4509 Lboom_bug_old(x, y+1);
4510 score += lev.bug_score;
4521 cave[x][y] = Ystone_sB;
4522 next[x][y] = Xblank;
4523 cave[x][y+1] = Ytank_stone;
4524 next[x][y+1] = Ztank;
4525 Lboom_tank_old(x, y+1);
4526 score += lev.tank_score;
4530 case Xdiamond_pause:
4531 switch (cave[x][y+2])
4587 next[x][y] = Xstone;
4588 play_element_sound(x, y, SOUND_stone, Xstone);
4592 cave[x][y] = Ystone_sB;
4593 next[x][y] = Xblank;
4594 cave[x][y+1] = Ydiamond_stone;
4595 next[x][y+1] = Xstone_pause;
4596 play_element_sound(x, y, SOUND_squash, Xdiamond);
4601 cave[x][y] = Xstone;
4602 next[x][y] = Xstone;
4603 cave[x][y+1] = Ybomb_blank;
4604 next[x][y+1] = Ztank;
4605 Lboom_tank_old(x, y+1);
4610 next[x][y] = Xstone;
4611 cave[x][y+1] = Ynut_stone;
4612 next[x][y+1] = Xemerald;
4613 play_element_sound(x, y, SOUND_crack, Xnut);
4614 score += lev.nut_score;
4620 switch (cave[x+1][y+1])
4635 cave[x][y+1] = Xspring_e;
4639 cave[x][y+1] = Xspring_w;
4645 switch (cave[x-1][y+1])
4660 cave[x][y+1] = Xspring_w;
4663 cave[x][y+1] = Xspring_e;
4668 next[x][y] = Xstone;
4672 if (lev.wonderwall_time)
4674 lev.wonderwall_state = 1;
4675 cave[x][y] = Ystone_sB;
4676 next[x][y] = Xblank;
4677 if (is_blank[cave[x][y+2]])
4679 cave[x][y+2] = Yemerald_s;
4680 next[x][y+2] = Xemerald_fall;
4682 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4687 cave[x][y] = Xstone;
4688 next[x][y] = Xstone;
4689 play_element_sound(x, y, SOUND_stone, Xstone);
4694 static void Lbomb(int x, int y)
4696 switch (cave[x][y+1])
4709 cave[x][y] = Ybomb_sB;
4710 next[x][y] = Xblank;
4711 cave[x][y+1] = Ybomb_s;
4712 next[x][y+1] = Xbomb_fall;
4723 cave[x][y] = Ybomb_sB;
4724 next[x][y] = Xblank;
4725 if (cave[x+1][y] == Xblank)
4726 cave[x+1][y] = Xsplash_e;
4727 if (cave[x-1][y] == Xblank)
4728 cave[x-1][y] = Xsplash_w;
4729 play_element_sound(x, y, SOUND_acid, Xacid_1);
4742 case Xemerald_pause:
4744 case Xdiamond_pause:
4779 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4781 cave[x][y] = Ybomb_eB;
4782 next[x][y] = Xblank;
4783 cave[x+1][y] = Ybomb_e;
4784 next[x+1][y] = Xbomb_pause;
4785 if (cave[x][y+1] == Xbumper)
4786 cave[x][y+1] = Ybumper;
4790 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4792 cave[x][y] = Ybomb_wB;
4793 next[x][y] = Xblank;
4794 cave[x-1][y] = Ybomb_w;
4795 next[x-1][y] = Xbomb_pause;
4796 if (cave[x][y+1] == Xbumper)
4797 cave[x][y+1] = Ybumper;
4803 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4805 cave[x][y] = Ybomb_wB;
4806 next[x][y] = Xblank;
4807 cave[x-1][y] = Ybomb_w;
4808 next[x-1][y] = Xbomb_pause;
4809 if (cave[x][y+1] == Xbumper)
4810 cave[x][y+1] = Ybumper;
4814 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4816 cave[x][y] = Ybomb_eB;
4817 next[x][y] = Xblank;
4818 cave[x+1][y] = Ybomb_e;
4819 next[x+1][y] = Xbomb_pause;
4820 if (cave[x][y+1] == Xbumper)
4821 cave[x][y+1] = Ybumper;
4828 static void Lbomb_pause(int x, int y)
4830 switch (cave[x][y+1])
4843 cave[x][y] = Ybomb_sB;
4844 next[x][y] = Xblank;
4845 cave[x][y+1] = Ybomb_s;
4846 next[x][y+1] = Xbomb_fall;
4857 cave[x][y] = Ybomb_sB;
4858 next[x][y] = Xblank;
4859 if (cave[x+1][y] == Xblank)
4860 cave[x+1][y] = Xsplash_e;
4861 if (cave[x-1][y] == Xblank)
4862 cave[x-1][y] = Xsplash_w;
4863 play_element_sound(x, y, SOUND_acid, Xacid_1);
4873 static void Lbomb_fall(int x, int y)
4875 switch (cave[x][y+1])
4888 cave[x][y] = Ybomb_sB;
4889 next[x][y] = Xblank;
4890 cave[x][y+1] = Ybomb_s;
4891 next[x][y+1] = Xbomb_fall;
4902 cave[x][y] = Ybomb_sB;
4903 next[x][y] = Xblank;
4904 if (cave[x+1][y] == Xblank)
4905 cave[x+1][y] = Xsplash_e;
4906 if (cave[x-1][y] == Xblank)
4907 cave[x-1][y] = Xsplash_w;
4908 play_element_sound(x, y, SOUND_acid, Xacid_1);
4912 cave[x][y] = Ybomb_blank;
4914 Lboom_tank_old(x, y);
4919 static void Lnut(int x, int y)
4921 switch (cave[x][y+1])
4934 cave[x][y] = Ynut_sB;
4935 next[x][y] = Xblank;
4936 cave[x][y+1] = Ynut_s;
4937 next[x][y+1] = Xnut_fall;
4948 cave[x][y] = Ynut_sB;
4949 next[x][y] = Xblank;
4950 if (cave[x+1][y] == Xblank)
4951 cave[x+1][y] = Xsplash_e;
4952 if (cave[x-1][y] == Xblank)
4953 cave[x-1][y] = Xsplash_w;
4954 play_element_sound(x, y, SOUND_acid, Xacid_1);
4967 case Xemerald_pause:
4969 case Xdiamond_pause:
5004 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5006 cave[x][y] = Ynut_eB;
5007 next[x][y] = Xblank;
5008 cave[x+1][y] = Ynut_e;
5009 next[x+1][y] = Xnut_pause;
5010 if (cave[x][y+1] == Xbumper)
5011 cave[x][y+1] = Ybumper;
5015 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5017 cave[x][y] = Ynut_wB;
5018 next[x][y] = Xblank;
5019 cave[x-1][y] = Ynut_w;
5020 next[x-1][y] = Xnut_pause;
5021 if (cave[x][y+1] == Xbumper)
5022 cave[x][y+1] = Ybumper;
5028 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5030 cave[x][y] = Ynut_wB;
5031 next[x][y] = Xblank;
5032 cave[x-1][y] = Ynut_w;
5033 next[x-1][y] = Xnut_pause;
5034 if (cave[x][y+1] == Xbumper)
5035 cave[x][y+1] = Ybumper;
5039 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5041 cave[x][y] = Ynut_eB;
5042 next[x][y] = Xblank;
5043 cave[x+1][y] = Ynut_e;
5044 next[x+1][y] = Xnut_pause;
5045 if (cave[x][y+1] == Xbumper)
5046 cave[x][y+1] = Ybumper;
5053 static void Lnut_pause(int x, int y)
5055 switch (cave[x][y+1])
5068 cave[x][y] = Ynut_sB;
5069 next[x][y] = Xblank;
5070 cave[x][y+1] = Ynut_s;
5071 next[x][y+1] = Xnut_fall;
5082 cave[x][y] = Ynut_sB;
5083 next[x][y] = Xblank;
5084 if (cave[x+1][y] == Xblank)
5085 cave[x+1][y] = Xsplash_e;
5086 if (cave[x-1][y] == Xblank)
5087 cave[x-1][y] = Xsplash_w;
5088 play_element_sound(x, y, SOUND_acid, Xacid_1);
5098 static void Lnut_fall(int x, int y)
5100 switch (cave[x][y+1])
5114 cave[x][y] = Ynut_sB;
5115 next[x][y] = Xblank;
5116 cave[x][y+1] = Ynut_s;
5117 next[x][y+1] = Xnut_fall;
5128 cave[x][y] = Ynut_sB;
5129 next[x][y] = Xblank;
5130 if (cave[x+1][y] == Xblank)
5131 cave[x+1][y] = Xsplash_e;
5132 if (cave[x-1][y] == Xblank)
5133 cave[x-1][y] = Xsplash_w;
5134 play_element_sound(x, y, SOUND_acid, Xacid_1);
5140 play_element_sound(x, y, SOUND_nut, Xnut);
5145 static void Lspring(int x, int y)
5147 switch (cave[x][y+1])
5162 cave[x][y] = Yspring_sB;
5163 next[x][y] = Xblank;
5164 cave[x][y+1] = Yspring_s;
5165 next[x][y+1] = Xspring_fall;
5176 cave[x][y] = Yspring_sB;
5177 next[x][y] = Xblank;
5178 if (cave[x+1][y] == Xblank)
5179 cave[x+1][y] = Xsplash_e;
5180 if (cave[x-1][y] == Xblank)
5181 cave[x-1][y] = Xsplash_w;
5182 play_element_sound(x, y, SOUND_acid, Xacid_1);
5195 case Xemerald_pause:
5197 case Xdiamond_pause:
5232 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5234 cave[x][y] = Yspring_eB;
5235 next[x][y] = Xblank;
5236 cave[x+1][y] = Yspring_e;
5238 next[x+1][y] = Xspring_e;
5240 next[x+1][y] = Xspring_pause;
5242 if (cave[x][y+1] == Xbumper)
5243 cave[x][y+1] = Ybumper;
5247 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5249 cave[x][y] = Yspring_wB;
5250 next[x][y] = Xblank;
5251 cave[x-1][y] = Yspring_w;
5253 next[x-1][y] = Xspring_w;
5255 next[x-1][y] = Xspring_pause;
5257 if (cave[x][y+1] == Xbumper)
5258 cave[x][y+1] = Ybumper;
5264 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5266 cave[x][y] = Yspring_wB;
5267 next[x][y] = Xblank;
5268 cave[x-1][y] = Yspring_w;
5270 next[x-1][y] = Xspring_w;
5272 next[x-1][y] = Xspring_pause;
5274 if (cave[x][y+1] == Xbumper)
5275 cave[x][y+1] = Ybumper;
5279 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5281 cave[x][y] = Yspring_eB;
5282 next[x][y] = Xblank;
5283 cave[x+1][y] = Yspring_e;
5285 next[x+1][y] = Xspring_e;
5287 next[x+1][y] = Xspring_pause;
5289 if (cave[x][y+1] == Xbumper)
5290 cave[x][y+1] = Ybumper;
5297 static void Lspring_pause(int x, int y)
5299 switch (cave[x][y+1])
5312 cave[x][y] = Yspring_sB;
5313 next[x][y] = Xblank;
5314 cave[x][y+1] = Yspring_s;
5315 next[x][y+1] = Xspring_fall;
5326 cave[x][y] = Yspring_sB;
5327 next[x][y] = Xblank;
5328 if (cave[x+1][y] == Xblank)
5329 cave[x+1][y] = Xsplash_e;
5330 if (cave[x-1][y] == Xblank)
5331 cave[x-1][y] = Xsplash_w;
5332 play_element_sound(x, y, SOUND_acid, Xacid_1);
5336 cave[x][y] = Xspring;
5337 next[x][y] = Xspring;
5342 static void Lspring_e(int x, int y)
5344 switch (cave[x][y+1])
5357 cave[x][y] = Yspring_sB;
5358 next[x][y] = Xblank;
5359 cave[x][y+1] = Yspring_s;
5360 next[x][y+1] = Xspring_fall;
5371 cave[x][y] = Yspring_sB;
5372 next[x][y] = Xblank;
5373 if (cave[x+1][y] == Xblank)
5374 cave[x+1][y] = Xsplash_e;
5375 if (cave[x-1][y] == Xblank)
5376 cave[x-1][y] = Xsplash_w;
5377 play_element_sound(x, y, SOUND_acid, Xacid_1);
5381 cave[x][y+1] = Ybumper;
5384 switch (cave[x+1][y])
5401 cave[x][y] = Yspring_eB;
5402 next[x][y] = Xblank;
5403 cave[x+1][y] = Yspring_e;
5404 next[x+1][y] = Xspring_e;
5415 cave[x][y] = Yspring_eB;
5416 next[x][y] = Xblank;
5417 if (cave[x+2][y-1] == Xblank)
5418 cave[x+2][y-1] = Xsplash_e;
5419 if (cave[x][y-1] == Xblank)
5420 cave[x][y-1] = Xsplash_w;
5421 play_element_sound(x, y, SOUND_acid, Xacid_1);
5430 cave[x][y] = Yspring_alien_eB;
5431 next[x][y] = Xblank;
5432 cave[x+1][y] = Yspring_alien_e;
5433 next[x+1][y] = Xspring_e;
5434 play_element_sound(x, y, SOUND_slurp, Xalien);
5435 score += lev.slurp_score;
5440 cave[x+1][y] = Ybumper;
5441 next[x][y] = Xspring_w;
5442 play_element_sound(x, y, SOUND_spring, Xspring);
5446 cave[x][y] = Xspring;
5447 next[x][y] = Xspring;
5448 play_element_sound(x, y, SOUND_spring, Xspring);
5453 static void Lspring_w(int x, int y)
5455 switch (cave[x][y+1])
5468 cave[x][y] = Yspring_sB;
5469 next[x][y] = Xblank;
5470 cave[x][y+1] = Yspring_s;
5471 next[x][y+1] = Xspring_fall;
5482 cave[x][y] = Yspring_sB;
5483 next[x][y] = Xblank;
5484 if (cave[x+1][y] == Xblank)
5485 cave[x+1][y] = Xsplash_e;
5486 if (cave[x-1][y] == Xblank)
5487 cave[x-1][y] = Xsplash_w;
5488 play_element_sound(x, y, SOUND_acid, Xacid_1);
5492 cave[x][y+1] = Ybumper;
5495 switch (cave[x-1][y])
5512 cave[x][y] = Yspring_wB;
5513 next[x][y] = Xblank;
5514 cave[x-1][y] = Yspring_w;
5515 next[x-1][y] = Xspring_w;
5526 cave[x][y] = Yspring_wB;
5527 next[x][y] = Xblank;
5528 if (cave[x][y-1] == Xblank)
5529 cave[x][y-1] = Xsplash_e;
5530 if (cave[x-2][y-1] == Xblank)
5531 cave[x-2][y-1] = Xsplash_w;
5532 play_element_sound(x, y, SOUND_acid, Xacid_1);
5541 cave[x][y] = Yspring_alien_wB;
5542 next[x][y] = Xblank;
5543 cave[x-1][y] = Yspring_alien_w;
5544 next[x-1][y] = Xspring_w;
5545 play_element_sound(x, y, SOUND_slurp, Xalien);
5546 score += lev.slurp_score;
5551 cave[x-1][y] = Ybumper;
5552 next[x][y] = Xspring_e;
5553 play_element_sound(x, y, SOUND_spring, Xspring);
5557 cave[x][y] = Xspring;
5558 next[x][y] = Xspring;
5559 play_element_sound(x, y, SOUND_spring, Xspring);
5564 static void Lspring_fall(int x, int y)
5566 switch (cave[x][y+1])
5580 cave[x][y] = Yspring_sB;
5581 next[x][y] = Xblank;
5582 cave[x][y+1] = Yspring_s;
5583 next[x][y+1] = Xspring_fall;
5594 cave[x][y] = Yspring_sB;
5595 next[x][y] = Xblank;
5596 if (cave[x+1][y] == Xblank)
5597 cave[x+1][y] = Xsplash_e;
5598 if (cave[x-1][y] == Xblank)
5599 cave[x-1][y] = Xsplash_w;
5600 play_element_sound(x, y, SOUND_acid, Xacid_1);
5607 cave[x][y] = Yspring_sB;
5608 next[x][y] = Xblank;
5609 cave[x][y+1] = Yeater_spring;
5610 next[x][y+1] = Zeater;
5611 Lboom_eater_old(x, y+1);
5612 score += lev.eater_score;
5617 cave[x][y] = Yspring_sB;
5618 next[x][y] = Xblank;
5619 cave[x][y+1] = Yalien_spring;
5620 next[x][y+1] = Ztank;
5621 Lboom_tank_old(x, y+1);
5622 score += lev.alien_score;
5633 cave[x][y] = Yspring_sB;
5634 next[x][y] = Xblank;
5635 cave[x][y+1] = Ybug_spring;
5636 next[x][y+1] = Zbug;
5637 Lboom_bug_old(x, y+1);
5638 score += lev.bug_score;
5649 cave[x][y] = Yspring_sB;
5650 next[x][y] = Xblank;
5651 cave[x][y+1] = Ytank_spring;
5652 next[x][y+1] = Ztank;
5653 Lboom_tank_old(x, y+1);
5654 score += lev.tank_score;
5659 cave[x][y] = Xspring;
5660 next[x][y] = Xspring;
5661 cave[x][y+1] = Ybomb_blank;
5662 next[x][y+1] = Ztank;
5663 Lboom_tank_old(x, y+1);
5667 cave[x][y] = Xspring;
5668 next[x][y] = Xspring;
5669 play_element_sound(x, y, SOUND_spring, Xspring);
5674 static void Lpush_emerald_e(int x, int y)
5676 cave[x][y] = Yemerald_eB;
5677 next[x][y] = Xblank;
5679 switch (cave[x+1][y])
5703 if (cave[x+2][y-1] == Xblank)
5704 cave[x+2][y-1] = Xsplash_e;
5705 if (cave[x][y-1] == Xblank)
5706 cave[x][y-1] = Xsplash_w;
5707 play_element_sound(x, y, SOUND_acid, Xacid_1);
5712 cave[x+1][y] = Yemerald_e;
5713 next[x+1][y] = Xemerald_pause;
5716 static void Lpush_emerald_w(int x, int y)
5718 cave[x][y] = Yemerald_wB;
5719 next[x][y] = Xblank;
5721 switch (cave[x-1][y])
5745 if (cave[x][y-1] == Xblank)
5746 cave[x][y-1] = Xsplash_e;
5747 if (cave[x-2][y-1] == Xblank)
5748 cave[x-2][y-1] = Xsplash_w;
5749 play_element_sound(x, y, SOUND_acid, Xacid_1);
5754 cave[x-1][y] = Yemerald_w;
5755 next[x-1][y] = Xemerald_pause;
5758 static void Lpush_diamond_e(int x, int y)
5760 cave[x][y] = Ydiamond_eB;
5761 next[x][y] = Xblank;
5763 switch (cave[x+1][y])
5787 if (cave[x+2][y-1] == Xblank)
5788 cave[x+2][y-1] = Xsplash_e;
5789 if (cave[x][y-1] == Xblank)
5790 cave[x][y-1] = Xsplash_w;
5791 play_element_sound(x, y, SOUND_acid, Xacid_1);
5796 cave[x+1][y] = Ydiamond_e;
5797 next[x+1][y] = Xdiamond_pause;
5800 static void Lpush_diamond_w(int x, int y)
5802 cave[x][y] = Ydiamond_wB;
5803 next[x][y] = Xblank;
5805 switch (cave[x-1][y])
5829 if (cave[x][y-1] == Xblank)
5830 cave[x][y-1] = Xsplash_e;
5831 if (cave[x-2][y-1] == Xblank)
5832 cave[x-2][y-1] = Xsplash_w;
5833 play_element_sound(x, y, SOUND_acid, Xacid_1);
5838 cave[x-1][y] = Ydiamond_w;
5839 next[x-1][y] = Xdiamond_pause;
5842 static void Lpush_stone_e(int x, int y)
5844 cave[x][y] = Ystone_eB;
5845 next[x][y] = Xblank;
5847 switch (cave[x+1][y])
5871 if (cave[x+2][y-1] == Xblank)
5872 cave[x+2][y-1] = Xsplash_e;
5873 if (cave[x][y-1] == Xblank)
5874 cave[x][y-1] = Xsplash_w;
5875 play_element_sound(x, y, SOUND_acid, Xacid_1);
5880 cave[x+1][y] = Ystone_e;
5881 next[x+1][y] = Xstone_pause;
5884 static void Lpush_stone_w(int x, int y)
5886 cave[x][y] = Ystone_wB;
5887 next[x][y] = Xblank;
5889 switch (cave[x-1][y])
5913 if (cave[x][y-1] == Xblank)
5914 cave[x][y-1] = Xsplash_e;
5915 if (cave[x-2][y-1] == Xblank)
5916 cave[x-2][y-1] = Xsplash_w;
5917 play_element_sound(x, y, SOUND_acid, Xacid_1);
5922 cave[x-1][y] = Ystone_w;
5923 next[x-1][y] = Xstone_pause;
5926 static void Lpush_bomb_e(int x, int y)
5928 cave[x][y] = Ybomb_eB;
5929 next[x][y] = Xblank;
5931 switch (cave[x+1][y])
5955 if (cave[x+2][y-1] == Xblank)
5956 cave[x+2][y-1] = Xsplash_e;
5957 if (cave[x][y-1] == Xblank)
5958 cave[x][y-1] = Xsplash_w;
5959 play_element_sound(x, y, SOUND_acid, Xacid_1);
5964 cave[x+1][y] = Ybomb_e;
5965 next[x+1][y] = Xbomb_pause;
5968 static void Lpush_bomb_w(int x, int y)
5970 cave[x][y] = Ybomb_wB;
5971 next[x][y] = Xblank;
5973 switch (cave[x-1][y])
5997 if (cave[x][y-1] == Xblank)
5998 cave[x][y-1] = Xsplash_e;
5999 if (cave[x-2][y-1] == Xblank)
6000 cave[x-2][y-1] = Xsplash_w;
6001 play_element_sound(x, y, SOUND_acid, Xacid_1);
6006 cave[x-1][y] = Ybomb_w;
6007 next[x-1][y] = Xbomb_pause;
6010 static void Lpush_nut_e(int x, int y)
6012 cave[x][y] = Ynut_eB;
6013 next[x][y] = Xblank;
6015 switch (cave[x+1][y])
6039 if (cave[x+2][y-1] == Xblank)
6040 cave[x+2][y-1] = Xsplash_e;
6041 if (cave[x][y-1] == Xblank)
6042 cave[x][y-1] = Xsplash_w;
6043 play_element_sound(x, y, SOUND_acid, Xacid_1);
6048 cave[x+1][y] = Ynut_e;
6049 next[x+1][y] = Xnut_pause;
6052 static void Lpush_nut_w(int x, int y)
6054 cave[x][y] = Ynut_wB;
6055 next[x][y] = Xblank;
6057 switch (cave[x-1][y])
6081 if (cave[x][y-1] == Xblank)
6082 cave[x][y-1] = Xsplash_e;
6083 if (cave[x-2][y-1] == Xblank)
6084 cave[x-2][y-1] = Xsplash_w;
6085 play_element_sound(x, y, SOUND_acid, Xacid_1);
6090 cave[x-1][y] = Ynut_w;
6091 next[x-1][y] = Xnut_pause;
6094 static void Lpush_spring_e(int x, int y)
6096 cave[x][y] = Yspring_eB;
6097 next[x][y] = Xblank;
6099 switch (cave[x+1][y])
6123 if (cave[x+2][y-1] == Xblank)
6124 cave[x+2][y-1] = Xsplash_e;
6125 if (cave[x][y-1] == Xblank)
6126 cave[x][y-1] = Xsplash_w;
6127 play_element_sound(x, y, SOUND_acid, Xacid_1);
6132 cave[x+1][y] = Yspring_e;
6133 next[x+1][y] = Xspring_e;
6136 static void Lpush_spring_w(int x, int y)
6138 cave[x][y] = Yspring_wB;
6139 next[x][y] = Xblank;
6141 switch (cave[x-1][y])
6165 if (cave[x][y-1] == Xblank)
6166 cave[x][y-1] = Xsplash_e;
6167 if (cave[x-2][y-1] == Xblank)
6168 cave[x-2][y-1] = Xsplash_w;
6169 play_element_sound(x, y, SOUND_acid, Xacid_1);
6174 cave[x-1][y] = Yspring_w;
6175 next[x-1][y] = Xspring_w;
6178 static void Ldynamite_1(int x, int y)
6180 play_element_sound(x, y, SOUND_tick, Xdynamite_1);
6181 next[x][y] = Xdynamite_2;
6184 static void Ldynamite_2(int x, int y)
6186 play_element_sound(x, y, SOUND_tick, Xdynamite_2);
6187 next[x][y] = Xdynamite_3;
6190 static void Ldynamite_3(int x, int y)
6192 play_element_sound(x, y, SOUND_tick, Xdynamite_3);
6193 next[x][y] = Xdynamite_4;
6196 static void Ldynamite_4(int x, int y)
6198 play_element_sound(x, y, SOUND_tick, Xdynamite_4);
6199 next[x][y] = Zdynamite;
6201 Lboom_generic(x, y, Xblank, Xblank);
6204 static void Lfake_door_1(int x, int y)
6206 if (lev.magnify_cnt)
6207 cave[x][y] = Xdoor_1;
6210 static void Lfake_door_2(int x, int y)
6212 if (lev.magnify_cnt)
6213 cave[x][y] = Xdoor_2;
6216 static void Lfake_door_3(int x, int y)
6218 if (lev.magnify_cnt)
6219 cave[x][y] = Xdoor_3;
6222 static void Lfake_door_4(int x, int y)
6224 if (lev.magnify_cnt)
6225 cave[x][y] = Xdoor_4;
6228 static void Lfake_door_5(int x, int y)
6230 if (lev.magnify_cnt)
6231 cave[x][y] = Xdoor_5;
6234 static void Lfake_door_6(int x, int y)
6236 if (lev.magnify_cnt)
6237 cave[x][y] = Xdoor_6;
6240 static void Lfake_door_7(int x, int y)
6242 if (lev.magnify_cnt)
6243 cave[x][y] = Xdoor_7;
6246 static void Lfake_door_8(int x, int y)
6248 if (lev.magnify_cnt)
6249 cave[x][y] = Xdoor_8;
6252 static void Lballoon(int x, int y)
6254 if (lev.wind_cnt == 0)
6257 switch (lev.wind_direction)
6260 switch (cave[x][y-1])
6273 cave[x][y] = Yballoon_nB;
6274 next[x][y] = Xblank;
6275 cave[x][y-1] = Yballoon_n;
6276 next[x][y-1] = Xballoon;
6287 cave[x][y] = Yballoon_nB;
6288 next[x][y] = Xblank;
6289 if (cave[x+1][y-2] == Xblank)
6290 cave[x+1][y-2] = Xsplash_e;
6291 if (cave[x-1][y-2] == Xblank)
6292 cave[x-1][y-2] = Xsplash_w;
6293 play_element_sound(x, y, SOUND_acid, Xacid_1);
6299 switch (cave[x+1][y])
6312 cave[x][y] = Yballoon_eB;
6313 next[x][y] = Xblank;
6314 cave[x+1][y] = Yballoon_e;
6315 next[x+1][y] = Xballoon;
6326 cave[x][y] = Yballoon_eB;
6327 next[x][y] = Xblank;
6328 if (cave[x+2][y-1] == Xblank)
6329 cave[x+2][y-1] = Xsplash_e;
6330 if (cave[x][y-1] == Xblank)
6331 cave[x][y-1] = Xsplash_w;
6332 play_element_sound(x, y, SOUND_acid, Xacid_1);
6338 switch (cave[x][y+1])
6351 cave[x][y] = Yballoon_sB;
6352 next[x][y] = Xblank;
6353 cave[x][y+1] = Yballoon_s;
6354 next[x][y+1] = Xballoon;
6365 cave[x][y] = Yballoon_sB;
6366 next[x][y] = Xblank;
6367 if (cave[x+1][y] == Xblank)
6368 cave[x+1][y] = Xsplash_e;
6369 if (cave[x-1][y] == Xblank)
6370 cave[x-1][y] = Xsplash_w;
6371 play_element_sound(x, y, SOUND_acid, Xacid_1);
6377 switch (cave[x-1][y])
6390 cave[x][y] = Yballoon_wB;
6391 next[x][y] = Xblank;
6392 cave[x-1][y] = Yballoon_w;
6393 next[x-1][y] = Xballoon;
6404 cave[x][y] = Yballoon_wB;
6405 next[x][y] = Xblank;
6406 if (cave[x][y-1] == Xblank)
6407 cave[x][y-1] = Xsplash_e;
6408 if (cave[x-2][y-1] == Xblank)
6409 cave[x-2][y-1] = Xsplash_w;
6410 play_element_sound(x, y, SOUND_acid, Xacid_1);
6417 static void Lball_common(int x, int y)
6419 play_element_sound(x, y, SOUND_ball, Xball_1);
6421 if (lev.ball_random)
6426 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6427 is_blank[cave[x-1][y-1]])
6429 cave[x-1][y-1] = Yball_blank;
6430 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6435 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6436 is_blank[cave[x][y-1]])
6438 cave[x][y-1] = Yball_blank;
6439 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6444 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6445 is_blank[cave[x+1][y-1]])
6447 cave[x+1][y-1] = Yball_blank;
6448 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6453 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6454 is_blank[cave[x-1][y]])
6456 cave[x-1][y] = Yball_blank;
6457 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6462 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6463 is_blank[cave[x+1][y]])
6465 cave[x+1][y] = Yball_blank;
6466 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6471 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6472 is_blank[cave[x-1][y+1]])
6474 cave[x-1][y+1] = Yball_blank;
6475 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6480 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6481 is_blank[cave[x][y+1]])
6483 cave[x][y+1] = Yball_blank;
6484 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6489 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6490 is_blank[cave[x+1][y+1]])
6492 cave[x+1][y+1] = Yball_blank;
6493 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6500 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6501 is_blank[cave[x-1][y-1]])
6503 cave[x-1][y-1] = Yball_blank;
6504 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6507 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6508 is_blank[cave[x][y-1]])
6510 cave[x][y-1] = Yball_blank;
6511 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6514 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6515 is_blank[cave[x+1][y-1]])
6517 cave[x+1][y-1] = Yball_blank;
6518 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6521 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6522 is_blank[cave[x-1][y]])
6524 cave[x-1][y] = Yball_blank;
6525 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6528 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6529 is_blank[cave[x+1][y]])
6531 cave[x+1][y] = Yball_blank;
6532 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6535 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6536 is_blank[cave[x-1][y+1]])
6538 cave[x-1][y+1] = Yball_blank;
6539 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6542 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6543 is_blank[cave[x][y+1]])
6545 cave[x][y+1] = Yball_blank;
6546 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6549 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6550 is_blank[cave[x+1][y+1]])
6552 cave[x+1][y+1] = Yball_blank;
6553 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6557 lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
6560 static void Lball_1(int x, int y)
6562 if (lev.ball_state == 0)
6565 cave[x][y] = Yball_1;
6566 next[x][y] = Xball_2;
6573 static void Lball_2(int x, int y)
6575 if (lev.ball_state == 0)
6578 cave[x][y] = Yball_2;
6579 next[x][y] = Xball_1;
6586 static void Ldrip(int x, int y)
6588 next[x][y] = Xdrip_fall;
6591 static void Ldrip_fall(int x, int y)
6595 switch (cave[x][y+1])
6611 cave[x][y] = Ydrip_1_sB;
6612 next[x][y] = Xdrip_stretchB;
6613 cave[x][y+1] = Ydrip_1_s;
6614 next[x][y+1] = Xdrip_stretch;
6625 cave[x][y] = Ydrip_1_sB;
6626 next[x][y] = Xdrip_stretchB;
6627 if (cave[x+1][y] == Xblank)
6628 cave[x+1][y] = Xsplash_e;
6629 if (cave[x-1][y] == Xblank)
6630 cave[x-1][y] = Xsplash_w;
6631 play_element_sound(x, y, SOUND_acid, Xacid_1);
6637 case 0: temp = Xamoeba_1; break;
6638 case 1: temp = Xamoeba_2; break;
6639 case 2: temp = Xamoeba_3; break;
6640 case 3: temp = Xamoeba_4; break;
6641 case 4: temp = Xamoeba_5; break;
6642 case 5: temp = Xamoeba_6; break;
6643 case 6: temp = Xamoeba_7; break;
6644 case 7: temp = Xamoeba_8; break;
6649 play_element_sound(x, y, SOUND_drip, Xdrip_fall);
6654 static void Ldrip_stretch(int x, int y)
6656 cave[x][y] = Ydrip_2_s;
6657 next[x][y] = Xdrip_fall;
6660 static void Ldrip_stretchB(int x, int y)
6662 cave[x][y] = Ydrip_2_sB;
6663 next[x][y] = Xblank;
6666 static void Lwonderwall(int x, int y)
6668 if (lev.wonderwall_time && lev.wonderwall_state)
6670 cave[x][y] = Ywonderwall;
6671 play_element_sound(x, y, SOUND_wonder, Xwonderwall);
6675 static void Lwheel(int x, int y)
6677 if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
6678 cave[x][y] = Ywheel;
6681 static void Lswitch(int x, int y)
6684 cave[x][y] = Yswitch;
6687 static void Lfake_blank(int x, int y)
6690 cave[x][y] = Yfake_blank;
6693 static void Lfake_grass(int x, int y)
6695 if (lev.magnify_cnt)
6696 cave[x][y] = Yfake_grass;
6699 static void Lfake_amoeba(int x, int y)
6702 cave[x][y] = Yfake_amoeba;
6705 static void Lsand_stone(int x, int y)
6707 switch (cave[x][y+1])
6720 cave[x][y] = Xsand_stonesand_quickout_1;
6721 next[x][y] = Xsand_stonesand_quickout_2;
6722 cave[x][y+1] = Xsand_stoneout_1;
6723 next[x][y+1] = Xsand_stoneout_2;
6734 cave[x][y] = Xsand_stonesand_quickout_1;
6735 next[x][y] = Xsand_stonesand_quickout_2;
6736 if (cave[x+1][y] == Xblank)
6737 cave[x+1][y] = Xsplash_e;
6738 if (cave[x-1][y] == Xblank)
6739 cave[x-1][y] = Xsplash_w;
6740 play_element_sound(x, y, SOUND_acid, Xacid_1);
6744 cave[x][y] = Xsand_stonesand_1;
6745 next[x][y] = Xsand_stonesand_2;
6746 cave[x][y+1] = Xsand_sandstone_1;
6747 next[x][y+1] = Xsand_sandstone_2;
6752 static void Lsand_stonein_1(int x, int y)
6754 next[x][y] = Xsand_stonein_2;
6757 static void Lsand_stonein_2(int x, int y)
6759 next[x][y] = Xsand_stonein_3;
6762 static void Lsand_stonein_3(int x, int y)
6764 next[x][y] = Xsand_stonein_4;
6767 static void Lsand_stonein_4(int x, int y)
6769 next[x][y] = Xblank;
6772 static void Lsand_sandstone_1(int x, int y)
6774 next[x][y] = Xsand_sandstone_2;
6777 static void Lsand_sandstone_2(int x, int y)
6779 next[x][y] = Xsand_sandstone_3;
6782 static void Lsand_sandstone_3(int x, int y)
6784 next[x][y] = Xsand_sandstone_4;
6787 static void Lsand_sandstone_4(int x, int y)
6789 next[x][y] = Xsand_stone;
6792 static void Lsand_stonesand_1(int x, int y)
6794 next[x][y] = Xsand_stonesand_2;
6797 static void Lsand_stonesand_2(int x, int y)
6799 next[x][y] = Xsand_stonesand_3;
6802 static void Lsand_stonesand_3(int x, int y)
6804 next[x][y] = Xsand_stonesand_4;
6807 static void Lsand_stonesand_4(int x, int y)
6812 static void Lsand_stoneout_1(int x, int y)
6814 next[x][y] = Xsand_stoneout_2;
6817 static void Lsand_stoneout_2(int x, int y)
6819 next[x][y] = Xstone_fall;
6822 static void Lsand_stonesand_quickout_1(int x, int y)
6824 next[x][y] = Xsand_stonesand_quickout_2;
6827 static void Lsand_stonesand_quickout_2(int x, int y)
6832 static void Lslide_ns(int x, int y)
6834 if (is_blank[cave[x][y-1]])
6836 cave[x][y-1] = Yslide_ns_blank;
6837 next[x][y-1] = Xslide_ns;
6838 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6841 if (is_blank[cave[x][y+1]])
6843 cave[x][y+1] = Yslide_ns_blank;
6844 next[x][y+1] = Xslide_ns;
6845 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6849 static void Lslide_ew(int x, int y)
6851 if (is_blank[cave[x+1][y]])
6853 cave[x+1][y] = Yslide_ew_blank;
6854 next[x+1][y] = Xslide_ew;
6855 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6858 if (is_blank[cave[x-1][y]])
6860 cave[x-1][y] = Yslide_ew_blank;
6861 next[x-1][y] = Xslide_ew;
6862 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6866 static void Lexit(int x, int y)
6868 if (lev.gems_needed > 0)
6871 switch (RANDOM(64) / 21)
6874 cave[x][y] = Xexit_1;
6875 next[x][y] = Xexit_2;
6879 cave[x][y] = Xexit_2;
6880 next[x][y] = Xexit_3;
6884 cave[x][y] = Xexit_3;
6885 next[x][y] = Xexit_1;
6889 play_element_sound(x, y, SOUND_exit_open, Xexit);
6892 static void Lexit_1(int x, int y)
6894 next[x][y] = Xexit_2;
6897 static void Lexit_2(int x, int y)
6899 next[x][y] = Xexit_3;
6902 static void Lexit_3(int x, int y)
6904 next[x][y] = Xexit_1;
6907 static void Lpause(int x, int y)
6909 next[x][y] = Xblank;
6912 static void Lamoeba(int x, int y)
6932 if (is_amoeba[cave[x][y-1]] ||
6933 is_amoeba[cave[x+1][y]] ||
6934 is_amoeba[cave[x][y+1]] ||
6935 is_amoeba[cave[x-1][y]])
6940 static void Lboom_one(int x, int y, boolean by_dynamite)
7001 cave[x][y] = Xboom_android;
7012 cave[x][y] = Xboom_bug;
7013 Lboom_bug_new(x, y, TRUE);
7019 cave[x][y] = Xboom_tank;
7020 Lboom_tank_new(x, y, TRUE);
7024 cave[x][y] = Xboom_1;
7029 static void Lboom_nine(int x, int y, boolean by_dynamite)
7031 Lboom_one(x, y-1, by_dynamite);
7032 Lboom_one(x-1, y, by_dynamite);
7033 Lboom_one(x+1, y, by_dynamite);
7034 Lboom_one(x, y+1, by_dynamite);
7035 Lboom_one(x-1, y-1, by_dynamite);
7036 Lboom_one(x+1, y-1, by_dynamite);
7037 Lboom_one(x-1, y+1, by_dynamite);
7038 Lboom_one(x+1, y+1, by_dynamite);
7040 cave[x][y] = Xboom_1;
7043 static void Lexplode(int x, int y)
7048 Lboom_bug_new(x, y, FALSE);
7049 Lboom_nine(x, y, FALSE);
7053 Lboom_tank_new(x, y, FALSE);
7054 Lboom_nine(x, y, FALSE);
7058 Lboom_eater_new(x, y, FALSE);
7059 Lboom_nine(x, y, FALSE);
7063 Lboom_nine(x, y, TRUE);
7067 Lboom_nine(x, y, FALSE);
7072 static void Lboom_1(int x, int y)
7074 next[x][y] = Xboom_2;
7075 #if !PLAY_ELEMENT_SOUND
7076 if (x != lev.exit_x && y != lev.exit_y)
7077 play_sound(x, y, SOUND_boom);
7079 lev.exit_x = lev.exit_y = -1;
7083 static void Lboom_2(int x, int y)
7085 next[x][y] = boom[x][y];
7088 static void Lboom_android(int x, int y)
7090 #if PLAY_ELEMENT_SOUND
7091 play_element_sound(x, y, SOUND_boom, Xandroid);
7097 static void Lchain(int x, int y)
7102 static void handle_tile(int x, int y)
7106 case Xacid_1: Lacid_1(x, y); break;
7107 case Xacid_2: Lacid_2(x, y); break;
7108 case Xacid_3: Lacid_3(x, y); break;
7109 case Xacid_4: Lacid_4(x, y); break;
7110 case Xacid_5: Lacid_5(x, y); break;
7111 case Xacid_6: Lacid_6(x, y); break;
7112 case Xacid_7: Lacid_7(x, y); break;
7113 case Xacid_8: Lacid_8(x, y); break;
7115 case Xfake_acid_1: Lfake_acid_1(x, y); break;
7116 case Xfake_acid_2: Lfake_acid_2(x, y); break;
7117 case Xfake_acid_3: Lfake_acid_3(x, y); break;
7118 case Xfake_acid_4: Lfake_acid_4(x, y); break;
7119 case Xfake_acid_5: Lfake_acid_5(x, y); break;
7120 case Xfake_acid_6: Lfake_acid_6(x, y); break;
7121 case Xfake_acid_7: Lfake_acid_7(x, y); break;
7122 case Xfake_acid_8: Lfake_acid_8(x, y); break;
7124 case Xandroid: Landroid(x, y); break;
7125 case Xandroid_1_n: Landroid_1_n(x, y); break;
7126 case Xandroid_2_n: Landroid_2_n(x, y); break;
7127 case Xandroid_1_e: Landroid_1_e(x, y); break;
7128 case Xandroid_2_e: Landroid_2_e(x, y); break;
7129 case Xandroid_1_s: Landroid_1_s(x, y); break;
7130 case Xandroid_2_s: Landroid_2_s(x, y); break;
7131 case Xandroid_1_w: Landroid_1_w(x, y); break;
7132 case Xandroid_2_w: Landroid_2_w(x, y); break;
7134 case Xeater_n: Leater_n(x, y); break;
7135 case Xeater_e: Leater_e(x, y); break;
7136 case Xeater_s: Leater_s(x, y); break;
7137 case Xeater_w: Leater_w(x, y); break;
7139 case Xalien: Lalien(x, y); break;
7140 case Xalien_pause: Lalien_pause(x, y); break;
7142 case Xbug_1_n: Lbug_1_n(x, y); break;
7143 case Xbug_2_n: Lbug_2_n(x, y); break;
7144 case Xbug_1_e: Lbug_1_e(x, y); break;
7145 case Xbug_2_e: Lbug_2_e(x, y); break;
7146 case Xbug_1_s: Lbug_1_s(x, y); break;
7147 case Xbug_2_s: Lbug_2_s(x, y); break;
7148 case Xbug_1_w: Lbug_1_w(x, y); break;
7149 case Xbug_2_w: Lbug_2_w(x, y); break;
7151 case Xtank_1_n: Ltank_1_n(x, y); break;
7152 case Xtank_2_n: Ltank_2_n(x, y); break;
7153 case Xtank_1_e: Ltank_1_e(x, y); break;
7154 case Xtank_2_e: Ltank_2_e(x, y); break;
7155 case Xtank_1_s: Ltank_1_s(x, y); break;
7156 case Xtank_2_s: Ltank_2_s(x, y); break;
7157 case Xtank_1_w: Ltank_1_w(x, y); break;
7158 case Xtank_2_w: Ltank_2_w(x, y); break;
7160 case Xemerald: Lemerald(x, y); break;
7161 case Xemerald_pause: Lemerald_pause(x, y); break;
7162 case Xemerald_fall: Lemerald_fall(x, y); break;
7164 case Xdiamond: Ldiamond(x, y); break;
7165 case Xdiamond_pause: Ldiamond_pause(x, y); break;
7166 case Xdiamond_fall: Ldiamond_fall(x, y); break;
7168 case Xstone: Lstone(x, y); break;
7169 case Xstone_pause: Lstone_pause(x, y); break;
7170 case Xstone_fall: Lstone_fall(x, y); break;
7172 case Xbomb: Lbomb(x, y); break;
7173 case Xbomb_pause: Lbomb_pause(x, y); break;
7174 case Xbomb_fall: Lbomb_fall(x, y); break;
7176 case Xnut: Lnut(x, y); break;
7177 case Xnut_pause: Lnut_pause(x, y); break;
7178 case Xnut_fall: Lnut_fall(x, y); break;
7180 case Xspring: Lspring(x, y); break;
7181 case Xspring_pause: Lspring_pause(x, y); break;
7182 case Xspring_e: Lspring_e(x, y); break;
7183 case Xspring_w: Lspring_w(x, y); break;
7184 case Xspring_fall: Lspring_fall(x, y); break;
7186 case Xpush_emerald_e: Lpush_emerald_e(x, y); break;
7187 case Xpush_emerald_w: Lpush_emerald_w(x, y); break;
7188 case Xpush_diamond_e: Lpush_diamond_e(x, y); break;
7189 case Xpush_diamond_w: Lpush_diamond_w(x, y); break;
7190 case Xpush_stone_e: Lpush_stone_e(x, y); break;
7191 case Xpush_stone_w: Lpush_stone_w(x, y); break;
7192 case Xpush_bomb_e: Lpush_bomb_e(x, y); break;
7193 case Xpush_bomb_w: Lpush_bomb_w(x, y); break;
7194 case Xpush_nut_e: Lpush_nut_e(x, y); break;
7195 case Xpush_nut_w: Lpush_nut_w(x, y); break;
7196 case Xpush_spring_e: Lpush_spring_e(x, y); break;
7197 case Xpush_spring_w: Lpush_spring_w(x, y); break;
7199 case Xdynamite_1: Ldynamite_1(x, y); break;
7200 case Xdynamite_2: Ldynamite_2(x, y); break;
7201 case Xdynamite_3: Ldynamite_3(x, y); break;
7202 case Xdynamite_4: Ldynamite_4(x, y); break;
7204 case Xfake_door_1: Lfake_door_1(x, y); break;
7205 case Xfake_door_2: Lfake_door_2(x, y); break;
7206 case Xfake_door_3: Lfake_door_3(x, y); break;
7207 case Xfake_door_4: Lfake_door_4(x, y); break;
7208 case Xfake_door_5: Lfake_door_5(x, y); break;
7209 case Xfake_door_6: Lfake_door_6(x, y); break;
7210 case Xfake_door_7: Lfake_door_7(x, y); break;
7211 case Xfake_door_8: Lfake_door_8(x, y); break;
7213 case Xballoon: Lballoon(x, y); break;
7215 case Xball_1: Lball_1(x, y); break;
7216 case Xball_2: Lball_2(x, y); break;
7218 case Xdrip: Ldrip(x, y); break;
7219 case Xdrip_fall: Ldrip_fall(x, y); break;
7220 case Xdrip_stretch: Ldrip_stretch(x, y); break;
7221 case Xdrip_stretchB: Ldrip_stretchB(x, y); break;
7223 case Xwonderwall: Lwonderwall(x, y); break;
7225 case Xwheel: Lwheel(x, y); break;
7227 case Xswitch: Lswitch(x, y); break;
7229 case Xfake_blank: Lfake_blank(x, y); break;
7230 case Xfake_grass: Lfake_grass(x, y); break;
7231 case Xfake_amoeba: Lfake_amoeba(x, y); break;
7233 case Xsand_stone: Lsand_stone(x, y); break;
7234 case Xsand_stonein_1: Lsand_stonein_1(x, y); break;
7235 case Xsand_stonein_2: Lsand_stonein_2(x, y); break;
7236 case Xsand_stonein_3: Lsand_stonein_3(x, y); break;
7237 case Xsand_stonein_4: Lsand_stonein_4(x, y); break;
7238 case Xsand_sandstone_1: Lsand_sandstone_1(x, y); break;
7239 case Xsand_sandstone_2: Lsand_sandstone_2(x, y); break;
7240 case Xsand_sandstone_3: Lsand_sandstone_3(x, y); break;
7241 case Xsand_sandstone_4: Lsand_sandstone_4(x, y); break;
7242 case Xsand_stonesand_1: Lsand_stonesand_1(x, y); break;
7243 case Xsand_stonesand_2: Lsand_stonesand_2(x, y); break;
7244 case Xsand_stonesand_3: Lsand_stonesand_3(x, y); break;
7245 case Xsand_stonesand_4: Lsand_stonesand_4(x, y); break;
7246 case Xsand_stoneout_1: Lsand_stoneout_1(x, y); break;
7247 case Xsand_stoneout_2: Lsand_stoneout_2(x, y); break;
7248 case Xsand_stonesand_quickout_1: Lsand_stonesand_quickout_1(x, y); break;
7249 case Xsand_stonesand_quickout_2: Lsand_stonesand_quickout_2(x, y); break;
7251 case Xslide_ns: Lslide_ns(x, y); break;
7252 case Xslide_ew: Lslide_ew(x, y); break;
7254 case Xexit: Lexit(x, y); break;
7255 case Xexit_1: Lexit_1(x, y); break;
7256 case Xexit_2: Lexit_2(x, y); break;
7257 case Xexit_3: Lexit_3(x, y); break;
7259 case Xpause: Lpause(x, y); break;
7261 case Xchain: Lchain(x, y); break;
7262 case Xboom_bug: Lboom_bug(x, y); break;
7263 case Xboom_tank: Lboom_tank(x, y); break;
7264 case Xboom_android: Lboom_android(x, y); break;
7265 case Xboom_1: Lboom_1(x, y); break;
7266 case Xboom_2: Lboom_2(x, y); break;
7270 static void logic_players(void)
7279 game_em.any_player_moving = FALSE;
7280 game_em.any_player_snapping = FALSE;
7282 /* must test for death and actually kill separately */
7283 for (i = 0; i < MAX_PLAYERS; i++)
7285 boolean ply_kill = player_killed(&ply[i]);
7287 if (ply[i].alive && ply_kill)
7288 kill_player(&ply[i]);
7291 for (i = 0; i < MAX_PLAYERS; i++)
7296 /* check for wrap-around movement */
7297 if (ply[i].x < lev.left ||
7298 ply[i].x > lev.right - 1)
7300 ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
7302 game.centered_player_nr_next = i;
7303 game.set_centered_player = TRUE;
7304 game.set_centered_player_fast = TRUE;
7307 ply[i].oldx = ply[i].x;
7308 ply[i].oldy = ply[i].y;
7309 ply[i].anim = PLY_still;
7312 start_check_nr = ((game_em.random & 128 ? 0 : 1) * 2 +
7313 (game_em.random & 256 ? 0 : 1));
7315 for (i = 0; i < MAX_PLAYERS; i++)
7317 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
7319 if (ply[check_nr].alive)
7320 check_player(&ply[check_nr]);
7323 for (i = 0; i < MAX_PLAYERS; i++)
7328 if (cave[ply[i].oldx][ply[i].oldy] == Zplayer)
7330 cave[ply[i].oldx][ply[i].oldy] = Xblank;
7331 next[ply[i].oldx][ply[i].oldy] = Xblank;
7334 if (cave[ply[i].x][ply[i].y] == Xblank)
7336 cave[ply[i].x][ply[i].y] = Zplayer;
7337 next[ply[i].x][ply[i].y] = Zplayer;
7342 static void logic_objects(void)
7350 seed = game_em.random;
7353 for (y = lev.top; y < lev.bottom; y++)
7354 for (x = lev.left; x < lev.right; x++)
7357 if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
7358 lev.score += score; /* only add a score if someone is alive */
7360 game_em.game_over = TRUE;
7362 game_em.random = seed;
7364 /* triple buffering */
7365 void *temp = lev.cave;
7366 lev.cave = lev.next;
7367 lev.next = lev.draw;
7371 static void logic_globals(void)
7376 unsigned int random;
7382 /* update variables */
7384 if (lev.score > 9999)
7387 if (lev.android_move_cnt-- == 0)
7388 lev.android_move_cnt = lev.android_move_time;
7389 if (lev.android_clone_cnt-- == 0)
7390 lev.android_clone_cnt = lev.android_clone_time;
7392 if (lev.ball_cnt-- == 0)
7393 lev.ball_cnt = lev.ball_time;
7396 if (lev.magnify_cnt)
7402 if (lev.wonderwall_time && lev.wonderwall_state)
7403 lev.wonderwall_time--;
7406 play_element_sound(lev.wheel_x, lev.wheel_y, SOUND_wheel, Xwheel);
7410 random = game_em.random;
7412 for (count = lev.amoeba_time; count--;)
7414 x = lev.left - 1 + (random >> 10) % (CAVE_WIDTH + 2);
7415 y = lev.top - 1 + (random >> 20) % (CAVE_HEIGHT + 2);
7417 if (x >= lev.left && x < lev.right &&
7418 y >= lev.top && y < lev.bottom)
7421 random = random * 129 + 1;
7424 game_em.random = random;
7426 /* handle explosions */
7428 for (y = lev.top; y < lev.bottom; y++)
7429 for (x = lev.left; x < lev.right; x++)
7432 /* triple buffering */
7434 for (y = lev.top; y < lev.bottom; y++)
7435 for (x = lev.left; x < lev.right; x++)
7436 next[x][y] = cave[x][y];