5 * my own version of the emerald mine engine
11 #define SPRING_ROLL /* spring rolling off round things continues to roll */
12 #define USE_CHANGED_ACID_STUFF
14 #define RANDOM_RAW (seed = seed << 31 | seed >> 1)
15 #define RANDOM(x) (RANDOM_RAW & (x - 1))
17 static short **cave, **next, **boom;
18 static unsigned int seed;
21 static const byte is_blank[TILE_MAX] =
36 static const byte is_blank_or_acid[TILE_MAX] =
59 static const byte is_fake_acid[TILE_MAX] =
71 static const byte is_amoeba[TILE_MAX] =
85 static const byte is_android_walkable[TILE_MAX] =
101 static void Lboom_generic(int x, int y, int element, int element_middle)
103 boom[x-1][y-1] = element;
104 boom[x][y-1] = element;
105 boom[x+1][y-1] = element;
106 boom[x-1][y] = element;
107 boom[x][y] = element_middle;
108 boom[x+1][y] = element;
109 boom[x-1][y+1] = element;
110 boom[x][y+1] = element;
111 boom[x+1][y+1] = element;
114 static void Lboom_bug(int x, int y, int by_element)
116 next[x][y] = Znormal;
118 Lboom_generic(x, y, Xemerald, Xdiamond);
120 #if PLAY_ELEMENT_SOUND
121 play_element_sound(x, y, SOUND_boom, by_element);
125 static void Lboom_tank(int x, int y, int by_element)
127 next[x][y] = Znormal;
129 Lboom_generic(x, y, Xblank, Xblank);
131 #if PLAY_ELEMENT_SOUND
132 play_element_sound(x, y, SOUND_boom, by_element);
136 static void Lboom_eater(int x, int y, int by_element)
138 next[x][y] = Znormal;
140 boom[x-1][y-1] = lev.eater_array[lev.eater_pos][0];
141 boom[x][y-1] = lev.eater_array[lev.eater_pos][1];
142 boom[x+1][y-1] = lev.eater_array[lev.eater_pos][2];
143 boom[x-1][y] = lev.eater_array[lev.eater_pos][3];
144 boom[x][y] = lev.eater_array[lev.eater_pos][4];
145 boom[x+1][y] = lev.eater_array[lev.eater_pos][5];
146 boom[x-1][y+1] = lev.eater_array[lev.eater_pos][6];
147 boom[x][y+1] = lev.eater_array[lev.eater_pos][7];
148 boom[x+1][y+1] = lev.eater_array[lev.eater_pos][8];
150 lev.eater_pos = (lev.eater_pos + 1) & 7;
152 #if PLAY_ELEMENT_SOUND
153 play_element_sound(x, y, SOUND_boom, by_element);
157 static boolean player_killed(struct PLAYER *ply)
165 if (lev.killed_out_of_time && setup.time_limit)
168 switch (cave[x][y-1])
189 switch (cave[x+1][y])
210 switch (cave[x][y+1])
231 switch (cave[x-1][y])
276 static void kill_player(struct PLAYER *ply)
283 switch (cave[x][y-1])
293 cave[x][y-1] = Xboom_bug;
304 cave[x][y-1] = Xboom_bomb;
308 switch (cave[x+1][y])
318 cave[x+1][y] = Xboom_bug;
329 cave[x+1][y] = Xboom_bomb;
333 switch (cave[x][y+1])
343 cave[x][y+1] = Xboom_bug;
354 cave[x][y+1] = Xboom_bomb;
358 switch (cave[x-1][y])
368 cave[x-1][y] = Xboom_bug;
379 cave[x-1][y] = Xboom_bomb;
390 play_element_sound(x, y, SOUND_exit_leave, Xexit_1);
394 play_element_sound(x, y, SOUND_die, Zplayer);
400 #ifdef USE_CHANGED_ACID_STUFF
413 cave[x][y] = Xboom_1;
419 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
421 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
426 boolean result = TRUE;
428 if (!dx && !dy) /* no direction specified */
431 if (dx && dy && ply->joy_snap) /* more than one direction specified */
434 if (ply->joy_snap == 0) /* player wants to move */
436 int element = cave[x][y];
440 /* fire is released */
444 cave[x][y] = Zplayer;
445 next[x][y] = Zplayer;
454 play_element_sound(x, y, SOUND_blank, Xblank);
455 ply->anim = PLY_walk_n + anim;
460 #ifdef USE_CHANGED_ACID_STUFF
469 if (cave[x+1][y-1] == Xblank)
470 cave[x+1][y-1] = Xsplash_e;
471 if (cave[x-1][y-1] == Xblank)
472 cave[x-1][y-1] = Xsplash_w;
473 play_element_sound(x, y, SOUND_acid, Xacid_1);
495 #ifndef USE_CHANGED_ACID_STUFF
505 ply->anim = PLY_walk_n + anim;
511 cave[x][y] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
512 (dx > 0 ? Ygrass_eB : Ygrass_wB));
513 next[x][y] = Zplayer;
514 play_element_sound(x, y, SOUND_dirt, Xgrass);
515 ply->anim = PLY_walk_n + anim;
521 cave[x][y] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
522 (dx > 0 ? Ydirt_eB : Ydirt_wB));
523 next[x][y] = Zplayer;
524 play_element_sound(x, y, SOUND_dirt, Xdirt);
525 ply->anim = PLY_walk_n + anim;
532 cave[x][y] = Ydiamond_blank;
533 next[x][y] = Zplayer;
534 play_element_sound(x, y, SOUND_collect, element);
535 lev.score += lev.diamond_score;
536 lev.required = lev.required < 3 ? 0 : lev.required - 3;
537 game.snapshot.collected_item = TRUE;
538 ply->anim = PLY_walk_n + anim;
545 cave[x][y] = Yemerald_blank;
546 next[x][y] = Zplayer;
547 play_element_sound(x, y, SOUND_collect, element);
548 lev.score += lev.emerald_score;
549 lev.required = lev.required < 1 ? 0 : lev.required - 1;
550 game.snapshot.collected_item = TRUE;
551 ply->anim = PLY_walk_n + anim;
557 cave[x][y] = Ydynamite_blank;
558 next[x][y] = Zplayer;
559 play_element_sound(x, y, SOUND_collect, element);
560 lev.score += lev.dynamite_score;
561 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
562 ply->anim = PLY_walk_n + anim;
569 cave[x][y] = Ykey_1_blank;
574 cave[x][y] = Ykey_2_blank;
579 cave[x][y] = Ykey_3_blank;
584 cave[x][y] = Ykey_4_blank;
589 cave[x][y] = Ykey_5_blank;
594 cave[x][y] = Ykey_6_blank;
599 cave[x][y] = Ykey_7_blank;
604 cave[x][y] = Ykey_8_blank;
609 next[x][y] = Zplayer;
610 play_element_sound(x, y, SOUND_collect, element);
611 lev.score += lev.key_score;
612 ply->anim = PLY_walk_n + anim;
618 cave[x][y] = Ylenses_blank;
619 next[x][y] = Zplayer;
620 play_element_sound(x, y, SOUND_collect, element);
621 lev.score += lev.lenses_score;
622 lev.lenses_cnt = lev.lenses_time;
623 ply->anim = PLY_walk_n + anim;
629 cave[x][y] = Ymagnify_blank;
630 next[x][y] = Zplayer;
631 play_element_sound(x, y, SOUND_collect, element);
632 lev.score += lev.magnify_score;
633 lev.magnify_cnt = lev.magnify_time;
634 ply->anim = PLY_walk_n + anim;
643 switch (cave[x+dx][y])
656 cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
657 next[x+dx][y] = Xstone_pause;
668 if (cave[x+dx+1][y-1] == Xblank)
669 cave[x+dx+1][y-1] = Xsplash_e;
670 if (cave[x+dx-1][y-1] == Xblank)
671 cave[x+dx-1][y-1] = Xsplash_w;
672 play_element_sound(x, y, SOUND_acid, Xacid_1);
676 cave[x][y] = dx > 0 ? Ystone_eB : Ystone_wB;
677 next[x][y] = Zplayer;
678 play_element_sound(x, y, SOUND_roll, Xstone);
683 ply->anim = PLY_push_n + anim;
690 switch (cave[x+dx][y])
703 cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
704 next[x+dx][y] = Xbomb_pause;
715 if (cave[x+dx+1][y-1] == Xblank)
716 cave[x+dx+1][y-1] = Xsplash_e;
717 if (cave[x+dx-1][y-1] == Xblank)
718 cave[x+dx-1][y-1] = Xsplash_w;
719 play_element_sound(x, y, SOUND_acid, Xacid_1);
723 cave[x][y] = dx > 0 ? Ybomb_eB : Ybomb_wB;
724 next[x][y] = Zplayer;
725 play_element_sound(x, y, SOUND_roll, Xbomb);
730 ply->anim = PLY_push_n + anim;
737 switch (cave[x+dx][y])
750 cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
751 next[x+dx][y] = Xnut_pause;
762 if (cave[x+dx+1][y-1] == Xblank)
763 cave[x+dx+1][y-1] = Xsplash_e;
764 if (cave[x+dx-1][y-1] == Xblank)
765 cave[x+dx-1][y-1] = Xsplash_w;
766 play_element_sound(x, y, SOUND_acid, Xacid_1);
770 cave[x][y] = dx > 0 ? Ynut_eB : Ynut_wB;
771 next[x][y] = Zplayer;
772 play_element_sound(x, y, SOUND_roll, Xnut);
777 ply->anim = PLY_push_n + anim;
784 switch (cave[x+dx][y])
797 cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
798 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
809 if (cave[x+dx+1][y-1] == Xblank)
810 cave[x+dx+1][y-1] = Xsplash_e;
811 if (cave[x+dx-1][y-1] == Xblank)
812 cave[x+dx-1][y-1] = Xsplash_w;
813 play_element_sound(x, y, SOUND_acid, Xacid_1);
817 cave[x][y] = dx > 0 ? Yspring_eB : Yspring_wB;
818 next[x][y] = Zplayer;
819 play_element_sound(x, y, SOUND_roll, Xspring);
825 cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
826 cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
827 next[x][y] = Zplayer;
828 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
829 play_element_sound(x, y, SOUND_slurp, Xalien);
830 lev.score += lev.slurp_score;
835 ply->anim = PLY_push_n + anim;
842 case Xsand_stonein_1:
843 case Xsand_stonein_2:
844 case Xsand_stonein_3:
845 case Xsand_stonein_4:
849 ply->anim = PLY_push_n + anim;
853 switch (cave[x+dx][y+dy])
866 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
867 (dx > 0 ? Yballoon_e : Yballoon_w));
868 next[x+dx][y+dy] = Xballoon;
879 if (cave[x+dx+1][y+dy-1] == Xblank)
880 cave[x+dx+1][y+dy-1] = Xsplash_e;
881 if (cave[x+dx-1][y+dy-1] == Xblank)
882 cave[x+dx-1][y+dy-1] = Xsplash_w;
883 play_element_sound(x, y, SOUND_acid, Xacid_1);
887 cave[x][y] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
888 (dx > 0 ? Yballoon_eB : Yballoon_wB));
889 next[x][y] = Zplayer;
890 play_element_sound(x, y, SOUND_push, Xballoon);
896 ply->anim = PLY_push_n + anim;
908 switch (cave[x+dx][y+dy])
921 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
922 (dx > 0 ? Yandroid_e : Yandroid_w));
923 next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
924 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
935 if (cave[x+dx+1][y+dy-1] == Xblank)
936 cave[x+dx+1][y+dy-1] = Xsplash_e;
937 if (cave[x+dx-1][y+dy-1] == Xblank)
938 cave[x+dx-1][y+dy-1] = Xsplash_w;
939 play_element_sound(x, y, SOUND_acid, Xacid_1);
943 cave[x][y] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
944 (dx > 0 ? Yandroid_eB : Yandroid_wB));
945 next[x][y] = Zplayer;
946 play_element_sound(x, y, SOUND_push, Xandroid);
952 ply->anim = PLY_push_n + anim;
957 if (ply->keys & 0x01)
964 if (ply->keys & 0x02)
971 if (ply->keys & 0x04)
978 if (ply->keys & 0x08)
985 if (ply->keys & 0x10)
992 if (ply->keys & 0x20)
999 if (ply->keys & 0x40)
1006 if (ply->keys & 0x80)
1013 if (!is_blank[cave[x+dx][y+dy]])
1016 if (!is_fake_acid[cave[x+dx][y+dy]])
1018 cave[x+dx][y+dy] = Zplayer;
1019 next[x+dx][y+dy] = Zplayer;
1022 play_element_sound(x, y, SOUND_door, element);
1023 ply->anim = PLY_walk_n + anim;
1029 play_element_sound(x, y, SOUND_press, element);
1030 lev.wheel_cnt = lev.wheel_time;
1036 lev.wind_direction = 0;
1040 lev.wind_direction = 1;
1044 lev.wind_direction = 2;
1048 lev.wind_direction = 3;
1052 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1057 play_element_sound(x, y, SOUND_press, element);
1058 lev.wind_cnt = lev.wind_time;
1062 play_element_sound(x, y, SOUND_press, element);
1067 play_element_sound(x, y, SOUND_press, element);
1068 lev.ball_cnt = lev.ball_time;
1069 lev.ball_state = !lev.ball_state;
1073 cave[x][y] = Yplant;
1074 next[x][y] = Xplant;
1075 play_element_sound(x, y, SOUND_blank, Xplant);
1076 ply->anim = PLY_walk_n + anim;
1087 game_em.level_solved = TRUE;
1089 ply->anim = PLY_walk_n + anim;
1096 if (ply->x == oldx && ply->y == oldy) /* no movement */
1099 else /* player wants to snap */
1101 int element = cave[x][y];
1105 /* fire is pressed */
1108 cave[x][y] = Ygrass_blank;
1109 next[x][y] = Xblank;
1110 play_element_sound(x, y, SOUND_dirt, element);
1111 ply->anim = PLY_shoot_n + anim;
1115 cave[x][y] = Ydirt_blank;
1116 next[x][y] = Xblank;
1117 play_element_sound(x, y, SOUND_dirt, element);
1118 ply->anim = PLY_shoot_n + anim;
1122 case Xdiamond_pause:
1123 cave[x][y] = Ydiamond_blank;
1124 next[x][y] = Xblank;
1125 play_element_sound(x, y, SOUND_collect, element);
1126 lev.score += lev.diamond_score;
1127 lev.required = lev.required < 3 ? 0 : lev.required - 3;
1128 game.snapshot.collected_item = TRUE;
1129 ply->anim = PLY_walk_n + anim;
1133 case Xemerald_pause:
1134 cave[x][y] = Yemerald_blank;
1135 next[x][y] = Xblank;
1136 play_element_sound(x, y, SOUND_collect, element);
1137 lev.score += lev.emerald_score;
1138 lev.required = lev.required < 1 ? 0 : lev.required - 1;
1139 game.snapshot.collected_item = TRUE;
1140 ply->anim = PLY_walk_n + anim;
1144 cave[x][y] = Ydynamite_blank;
1145 next[x][y] = Xblank;
1146 play_element_sound(x, y, SOUND_collect, element);
1147 lev.score += lev.dynamite_score;
1148 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1149 ply->anim = PLY_walk_n + anim;
1154 cave[x][y] = Ykey_1_blank;
1159 cave[x][y] = Ykey_2_blank;
1164 cave[x][y] = Ykey_3_blank;
1169 cave[x][y] = Ykey_4_blank;
1174 cave[x][y] = Ykey_5_blank;
1179 cave[x][y] = Ykey_6_blank;
1184 cave[x][y] = Ykey_7_blank;
1189 cave[x][y] = Ykey_8_blank;
1194 next[x][y] = Xblank;
1195 play_element_sound(x, y, SOUND_collect, element);
1196 lev.score += lev.key_score;
1197 ply->anim = PLY_walk_n + anim;
1201 cave[x][y] = Ylenses_blank;
1202 next[x][y] = Xblank;
1203 play_element_sound(x, y, SOUND_collect, element);
1204 lev.score += lev.lenses_score;
1205 lev.lenses_cnt = lev.lenses_time;
1206 ply->anim = PLY_walk_n + anim;
1210 cave[x][y] = Ymagnify_blank;
1211 next[x][y] = Xblank;
1212 play_element_sound(x, y, SOUND_collect, element);
1213 lev.score += lev.magnify_score;
1214 lev.magnify_cnt = lev.magnify_time;
1215 ply->anim = PLY_walk_n + anim;
1226 static void check_player(struct PLAYER *ply)
1234 game_em.last_player_direction[ply->num] = MV_NONE;
1236 if (ply->joy_w) /* west */
1241 else if (ply->joy_e) /* east */
1247 if (ply->joy_n) /* north */
1252 else if (ply->joy_s) /* south */
1264 boolean players_visible_before_move;
1265 boolean players_visible_after_move;
1268 players_visible_before_move = checkIfAllPlayersFitToScreen();
1273 players_visible_after_move = checkIfAllPlayersFitToScreen();
1276 player is allowed to move only in the following cases:
1277 - it is not needed to display all players (not focussed to all players)
1278 - all players are (still or again) visible after the move
1279 - some players were already outside visible screen area before the move
1281 can_move = (game.centered_player_nr != -1 ||
1282 players_visible_after_move ||
1283 !players_visible_before_move);
1290 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
1296 if (dx == 0 && dy == 0)
1302 if (++ply->dynamite_cnt == 5 && ply->dynamite)
1304 cave[x][y] = Xdynamite_1;
1305 play_element_sound(x, y, SOUND_dynamite, Xdynamite_1);
1311 ply->dynamite_cnt = 0;
1314 RandomEM += 7; /* be a bit more random if the player doesn't move */
1320 ply->joy_n = ply->joy_e = ply->joy_s = ply->joy_w = 0;
1321 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
1322 ply->joy_spin = !ply->joy_spin;
1324 if (ply->joy_snap == 0) /* player wants to move */
1326 boolean moved = FALSE;
1328 if (ply->last_move_dir & MV_HORIZONTAL)
1330 if (!(moved = player_digfield(ply, 0, dy)))
1331 moved = player_digfield(ply, dx, 0);
1335 if (!(moved = player_digfield(ply, dx, 0)))
1336 moved = player_digfield(ply, 0, dy);
1342 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
1343 else if (oldy != ply->y)
1344 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
1346 game_em.any_player_moving = TRUE;
1347 game_em.last_moving_player = ply->num;
1348 game_em.last_player_direction[ply->num] = ply->last_move_dir;
1351 else /* player wants to snap */
1353 game_em.any_player_snapping = player_digfield(ply, dx, dy);
1357 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
1359 int distance, distance_shortest = CAVE_WIDTH + CAVE_HEIGHT;
1362 /* default values if no players are alive anymore */
1366 for (i = 0; i < MAX_PLAYERS; i++)
1371 distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
1373 if (distance < distance_shortest)
1378 distance_shortest = distance;
1383 static void Lacid_1(int x, int y)
1385 next[x][y] = Xacid_2;
1388 static void Lacid_2(int x, int y)
1390 next[x][y] = Xacid_3;
1393 static void Lacid_3(int x, int y)
1395 next[x][y] = Xacid_4;
1398 static void Lacid_4(int x, int y)
1400 next[x][y] = Xacid_5;
1403 static void Lacid_5(int x, int y)
1405 next[x][y] = Xacid_6;
1408 static void Lacid_6(int x, int y)
1410 next[x][y] = Xacid_7;
1413 static void Lacid_7(int x, int y)
1415 next[x][y] = Xacid_8;
1418 static void Lacid_8(int x, int y)
1420 next[x][y] = Xacid_1;
1423 static void Lfake_acid_1(int x, int y)
1425 next[x][y] = Xfake_acid_2;
1428 static void Lfake_acid_2(int x, int y)
1430 next[x][y] = Xfake_acid_3;
1433 static void Lfake_acid_3(int x, int y)
1435 next[x][y] = Xfake_acid_4;
1438 static void Lfake_acid_4(int x, int y)
1440 next[x][y] = Xfake_acid_5;
1443 static void Lfake_acid_5(int x, int y)
1445 next[x][y] = Xfake_acid_6;
1448 static void Lfake_acid_6(int x, int y)
1450 next[x][y] = Xfake_acid_7;
1453 static void Lfake_acid_7(int x, int y)
1455 next[x][y] = Xfake_acid_8;
1458 static void Lfake_acid_8(int x, int y)
1460 next[x][y] = Xfake_acid_1;
1463 static void Landroid(int x, int y)
1467 if (lev.android_clone_cnt == 0)
1469 if (!is_blank[cave[x-1][y-1]] &&
1470 !is_blank[cave[x][y-1]] &&
1471 !is_blank[cave[x+1][y-1]] &&
1472 !is_blank[cave[x-1][y]] &&
1473 !is_blank[cave[x+1][y]] &&
1474 !is_blank[cave[x-1][y+1]] &&
1475 !is_blank[cave[x][y+1]] &&
1476 !is_blank[cave[x+1][y+1]])
1481 /* randomly find an object to clone */
1483 case 0: /* S,NE,W,NW,SE,E,SW,N */
1484 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1485 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1486 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1487 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1488 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1489 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1490 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1491 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1494 case 1: /* NW,SE,N,S,NE,SW,E,W */
1495 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1496 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1497 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1498 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1499 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1500 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1501 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1502 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1505 case 2: /* SW,E,S,W,N,NW,SE,NE */
1506 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1507 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1508 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1509 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1510 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1511 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1512 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1513 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1516 case 3: /* N,SE,NE,E,W,S,NW,SW */
1517 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1518 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1519 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1520 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1521 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1522 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1523 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1524 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1527 case 4: /* SE,NW,E,NE,SW,W,N,S */
1528 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1529 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1530 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1531 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1532 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1533 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1534 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1535 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1538 case 5: /* NE,W,SE,SW,S,N,E,NW */
1539 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1540 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1541 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1542 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1543 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1544 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1545 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1546 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1549 case 6: /* E,N,SW,S,NW,NE,SE,W */
1550 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1551 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1552 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1553 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1554 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1555 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1556 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1557 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1560 case 7: /* W,SW,NW,N,E,SE,NE,S */
1561 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1562 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1563 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1564 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1565 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1566 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1567 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1568 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1572 next[x][y] = temp; /* the item we chose to clone */
1573 play_element_sound(x, y, SOUND_android_clone, temp);
1577 /* randomly find a direction to move */
1579 case 0: /* S,NE,W,NW,SE,E,SW,N */
1580 if (is_blank[cave[x][y+1]]) goto android_s;
1581 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1582 if (is_blank[cave[x-1][y]]) goto android_w;
1583 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1584 if (is_blank[cave[x+1][y+1]]) goto android_se;
1585 if (is_blank[cave[x+1][y]]) goto android_e;
1586 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1587 if (is_blank[cave[x][y-1]]) goto android_n;
1590 case 1: /* NW,SE,N,S,NE,SW,E,W */
1591 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1592 if (is_blank[cave[x+1][y+1]]) goto android_se;
1593 if (is_blank[cave[x][y-1]]) goto android_n;
1594 if (is_blank[cave[x][y+1]]) goto android_s;
1595 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1596 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1597 if (is_blank[cave[x+1][y]]) goto android_e;
1598 if (is_blank[cave[x-1][y]]) goto android_w;
1601 case 2: /* SW,E,S,W,N,NW,SE,NE */
1602 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1603 if (is_blank[cave[x+1][y]]) goto android_e;
1604 if (is_blank[cave[x][y+1]]) goto android_s;
1605 if (is_blank[cave[x-1][y]]) goto android_w;
1606 if (is_blank[cave[x][y-1]]) goto android_n;
1607 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1608 if (is_blank[cave[x+1][y+1]]) goto android_se;
1609 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1612 case 3: /* N,SE,NE,E,W,S,NW,SW */
1613 if (is_blank[cave[x][y-1]]) goto android_n;
1614 if (is_blank[cave[x+1][y+1]]) goto android_se;
1615 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1616 if (is_blank[cave[x+1][y]]) goto android_e;
1617 if (is_blank[cave[x-1][y]]) goto android_w;
1618 if (is_blank[cave[x][y+1]]) goto android_s;
1619 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1620 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1623 case 4: /* SE,NW,E,NE,SW,W,N,S */
1624 if (is_blank[cave[x+1][y+1]]) goto android_se;
1625 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1626 if (is_blank[cave[x+1][y]]) goto android_e;
1627 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1628 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1629 if (is_blank[cave[x-1][y]]) goto android_w;
1630 if (is_blank[cave[x][y-1]]) goto android_n;
1631 if (is_blank[cave[x][y+1]]) goto android_s;
1634 case 5: /* NE,W,SE,SW,S,N,E,NW */
1635 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1636 if (is_blank[cave[x-1][y]]) goto android_w;
1637 if (is_blank[cave[x+1][y+1]]) goto android_se;
1638 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1639 if (is_blank[cave[x][y+1]]) goto android_s;
1640 if (is_blank[cave[x][y-1]]) goto android_n;
1641 if (is_blank[cave[x+1][y]]) goto android_e;
1642 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1645 case 6: /* E,N,SW,S,NW,NE,SE,W */
1646 if (is_blank[cave[x+1][y]]) goto android_e;
1647 if (is_blank[cave[x][y-1]]) goto android_n;
1648 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1649 if (is_blank[cave[x][y+1]]) goto android_s;
1650 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1651 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1652 if (is_blank[cave[x+1][y+1]]) goto android_se;
1653 if (is_blank[cave[x-1][y]]) goto android_w;
1656 case 7: /* W,SW,NW,N,E,SE,NE,S */
1657 if (is_blank[cave[x-1][y]]) goto android_w;
1658 if (is_blank[cave[x-1][y+1]]) goto android_sw;
1659 if (is_blank[cave[x-1][y-1]]) goto android_nw;
1660 if (is_blank[cave[x][y-1]]) goto android_n;
1661 if (is_blank[cave[x+1][y]]) goto android_e;
1662 if (is_blank[cave[x+1][y+1]]) goto android_se;
1663 if (is_blank[cave[x+1][y-1]]) goto android_ne;
1664 if (is_blank[cave[x][y+1]]) goto android_s;
1670 if (lev.android_move_cnt == 0)
1672 if (cave[x-1][y-1] == Zplayer ||
1673 cave[x][y-1] == Zplayer ||
1674 cave[x+1][y-1] == Zplayer ||
1675 cave[x-1][y] == Zplayer ||
1676 cave[x+1][y] == Zplayer ||
1677 cave[x-1][y+1] == Zplayer ||
1678 cave[x][y+1] == Zplayer ||
1679 cave[x+1][y+1] == Zplayer)
1682 set_nearest_player_xy(x, y, &dx, &dy);
1684 next[x][y] = Xblank; /* assume we will move */
1685 temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
1691 /* attempt clockwise move first if direct path is blocked */
1693 case 0: /* north west */
1694 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1695 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1696 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1700 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1701 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1702 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1705 case 2: /* north east */
1706 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1707 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1708 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1712 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1713 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1714 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1717 case 4: /* nowhere */
1721 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1722 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1723 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1726 case 6: /* south west */
1727 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1728 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1729 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1733 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1734 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1735 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1738 case 8: /* south east */
1739 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1740 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1741 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1749 /* attempt counterclockwise move first if direct path is blocked */
1751 case 0: /* north west */
1752 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1753 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1754 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1758 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1759 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1760 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1763 case 2: /* north east */
1764 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1765 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1766 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1770 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1771 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1772 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1775 case 4: /* nowhere */
1779 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1780 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1781 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1784 case 6: /* south west */
1785 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1786 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1787 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1791 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1792 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1793 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1796 case 8: /* south east */
1797 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1798 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1799 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1806 next[x][y] = Xandroid;
1810 cave[x][y] = Yandroid_nB;
1811 cave[x][y-1] = Yandroid_n;
1812 next[x][y-1] = Xandroid;
1813 play_element_sound(x, y, SOUND_android_move, Xandroid);
1817 cave[x][y] = Yandroid_neB;
1818 cave[x+1][y-1] = Yandroid_ne;
1819 next[x+1][y-1] = Xandroid;
1820 play_element_sound(x, y, SOUND_android_move, Xandroid);
1824 cave[x][y] = Yandroid_eB;
1825 cave[x+1][y] = Yandroid_e;
1826 next[x+1][y] = Xandroid;
1827 play_element_sound(x, y, SOUND_android_move, Xandroid);
1831 cave[x][y] = Yandroid_seB;
1832 cave[x+1][y+1] = Yandroid_se;
1833 next[x+1][y+1] = Xandroid;
1834 play_element_sound(x, y, SOUND_android_move, Xandroid);
1838 cave[x][y] = Yandroid_sB;
1839 cave[x][y+1] = Yandroid_s;
1840 next[x][y+1] = Xandroid;
1841 play_element_sound(x, y, SOUND_android_move, Xandroid);
1845 cave[x][y] = Yandroid_swB;
1846 cave[x-1][y+1] = Yandroid_sw;
1847 next[x-1][y+1] = Xandroid;
1848 play_element_sound(x, y, SOUND_android_move, Xandroid);
1852 cave[x][y] = Yandroid_wB;
1853 cave[x-1][y] = Yandroid_w;
1854 next[x-1][y] = Xandroid;
1855 play_element_sound(x, y, SOUND_android_move, Xandroid);
1859 cave[x][y] = Yandroid_nwB;
1860 cave[x-1][y-1] = Yandroid_nw;
1861 next[x-1][y-1] = Xandroid;
1862 play_element_sound(x, y, SOUND_android_move, Xandroid);
1866 static void Landroid_1_n(int x, int y)
1868 switch (cave[x][y-1])
1881 cave[x][y] = Yandroid_nB;
1882 next[x][y] = Xblank;
1883 cave[x][y-1] = Yandroid_n;
1884 next[x][y-1] = Xandroid;
1885 play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
1896 cave[x][y] = Yandroid_nB;
1897 next[x][y] = Xblank;
1898 if (cave[x+1][y-2] == Xblank)
1899 cave[x+1][y-2] = Xsplash_e;
1900 if (cave[x-1][y-2] == Xblank)
1901 cave[x-1][y-2] = Xsplash_w;
1902 play_element_sound(x, y, SOUND_acid, Xacid_1);
1911 static void Landroid_2_n(int x, int y)
1913 switch (cave[x][y-1])
1926 cave[x][y] = Yandroid_nB;
1927 next[x][y] = Xblank;
1928 cave[x][y-1] = Yandroid_n;
1929 next[x][y-1] = Xandroid_1_n;
1930 play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
1941 cave[x][y] = Yandroid_nB;
1942 next[x][y] = Xblank;
1943 if (cave[x+1][y-2] == Xblank)
1944 cave[x+1][y-2] = Xsplash_e;
1945 if (cave[x-1][y-2] == Xblank)
1946 cave[x-1][y-2] = Xsplash_w;
1947 play_element_sound(x, y, SOUND_acid, Xacid_1);
1956 static void Landroid_1_e(int x, int y)
1958 switch (cave[x+1][y])
1971 cave[x][y] = Yandroid_eB;
1972 next[x][y] = Xblank;
1973 cave[x+1][y] = Yandroid_e;
1974 next[x+1][y] = Xandroid;
1975 play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
1986 cave[x][y] = Yandroid_eB;
1987 next[x][y] = Xblank;
1988 if (cave[x+2][y-1] == Xblank)
1989 cave[x+2][y-1] = Xsplash_e;
1990 if (cave[x][y-1] == Xblank)
1991 cave[x][y-1] = Xsplash_w;
1992 play_element_sound(x, y, SOUND_acid, Xacid_1);
2001 static void Landroid_2_e(int x, int y)
2003 switch (cave[x+1][y])
2016 cave[x][y] = Yandroid_eB;
2017 next[x][y] = Xblank;
2018 cave[x+1][y] = Yandroid_e;
2019 next[x+1][y] = Xandroid_1_e;
2020 play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
2031 cave[x][y] = Yandroid_eB;
2032 next[x][y] = Xblank;
2033 if (cave[x+2][y-1] == Xblank)
2034 cave[x+2][y-1] = Xsplash_e;
2035 if (cave[x][y-1] == Xblank)
2036 cave[x][y-1] = Xsplash_w;
2037 play_element_sound(x, y, SOUND_acid, Xacid_1);
2046 static void Landroid_1_s(int x, int y)
2048 switch (cave[x][y+1])
2061 cave[x][y] = Yandroid_sB;
2062 next[x][y] = Xblank;
2063 cave[x][y+1] = Yandroid_s;
2064 next[x][y+1] = Xandroid;
2065 play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
2076 cave[x][y] = Yandroid_sB;
2077 next[x][y] = Xblank;
2078 if (cave[x+1][y] == Xblank)
2079 cave[x+1][y] = Xsplash_e;
2080 if (cave[x-1][y] == Xblank)
2081 cave[x-1][y] = Xsplash_w;
2082 play_element_sound(x, y, SOUND_acid, Xacid_1);
2091 static void Landroid_2_s(int x, int y)
2093 switch (cave[x][y+1])
2106 cave[x][y] = Yandroid_sB;
2107 next[x][y] = Xblank;
2108 cave[x][y+1] = Yandroid_s;
2109 next[x][y+1] = Xandroid_1_s;
2110 play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
2121 cave[x][y] = Yandroid_sB;
2122 next[x][y] = Xblank;
2123 if (cave[x+1][y] == Xblank)
2124 cave[x+1][y] = Xsplash_e;
2125 if (cave[x-1][y] == Xblank)
2126 cave[x-1][y] = Xsplash_w;
2127 play_element_sound(x, y, SOUND_acid, Xacid_1);
2136 static void Landroid_1_w(int x, int y)
2138 switch (cave[x-1][y])
2151 cave[x][y] = Yandroid_wB;
2152 next[x][y] = Xblank;
2153 cave[x-1][y] = Yandroid_w;
2154 next[x-1][y] = Xandroid;
2155 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2166 cave[x][y] = Yandroid_wB;
2167 next[x][y] = Xblank;
2168 if (cave[x][y-1] == Xblank)
2169 cave[x][y-1] = Xsplash_e;
2170 if (cave[x-2][y-1] == Xblank)
2171 cave[x-2][y-1] = Xsplash_w;
2172 play_element_sound(x, y, SOUND_acid, Xacid_1);
2181 static void Landroid_2_w(int x, int y)
2183 switch (cave[x-1][y])
2196 cave[x][y] = Yandroid_wB;
2197 next[x][y] = Xblank;
2198 cave[x-1][y] = Yandroid_w;
2199 next[x-1][y] = Xandroid_1_w;
2200 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2211 cave[x][y] = Yandroid_wB;
2212 next[x][y] = Xblank;
2213 if (cave[x][y-1] == Xblank)
2214 cave[x][y-1] = Xsplash_e;
2215 if (cave[x-2][y-1] == Xblank)
2216 cave[x-2][y-1] = Xsplash_w;
2217 play_element_sound(x, y, SOUND_acid, Xacid_1);
2226 static void Leater_n(int x, int y)
2228 if (cave[x+1][y] == Xdiamond)
2230 cave[x+1][y] = Ydiamond_blank;
2231 next[x+1][y] = Xblank;
2232 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2236 if (cave[x][y+1] == Xdiamond)
2238 cave[x][y+1] = Ydiamond_blank;
2239 next[x][y+1] = Xblank;
2240 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2244 if (cave[x-1][y] == Xdiamond)
2246 cave[x-1][y] = Ydiamond_blank;
2247 next[x-1][y] = Xblank;
2248 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2252 if (cave[x][y-1] == Xdiamond)
2254 cave[x][y-1] = Ydiamond_blank;
2255 next[x][y-1] = Xblank;
2256 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2260 switch (cave[x][y-1])
2276 cave[x][y] = Yeater_nB;
2277 next[x][y] = Xblank;
2278 cave[x][y-1] = Yeater_n;
2279 next[x][y-1] = Xeater_n;
2290 cave[x][y] = Yeater_nB;
2291 next[x][y] = Xblank;
2292 if (cave[x+1][y-2] == Xblank)
2293 cave[x+1][y-2] = Xsplash_e;
2294 if (cave[x-1][y-2] == Xblank)
2295 cave[x-1][y-2] = Xsplash_w;
2296 play_element_sound(x, y, SOUND_acid, Xacid_1);
2300 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2301 play_element_sound(x, y, SOUND_eater, Xeater_n);
2306 static void Leater_e(int x, int y)
2308 if (cave[x][y+1] == Xdiamond)
2310 cave[x][y+1] = Ydiamond_blank;
2311 next[x][y+1] = Xblank;
2312 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2316 if (cave[x-1][y] == Xdiamond)
2318 cave[x-1][y] = Ydiamond_blank;
2319 next[x-1][y] = Xblank;
2320 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2324 if (cave[x][y-1] == Xdiamond)
2326 cave[x][y-1] = Ydiamond_blank;
2327 next[x][y-1] = Xblank;
2328 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2332 if (cave[x+1][y] == Xdiamond)
2334 cave[x+1][y] = Ydiamond_blank;
2335 next[x+1][y] = Xblank;
2336 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2340 switch (cave[x+1][y])
2356 cave[x][y] = Yeater_eB;
2357 next[x][y] = Xblank;
2358 cave[x+1][y] = Yeater_e;
2359 next[x+1][y] = Xeater_e;
2370 cave[x][y] = Yeater_eB;
2371 next[x][y] = Xblank;
2372 if (cave[x+2][y-1] == Xblank)
2373 cave[x+2][y-1] = Xsplash_e;
2374 if (cave[x][y-1] == Xblank)
2375 cave[x][y-1] = Xsplash_w;
2376 play_element_sound(x, y, SOUND_acid, Xacid_1);
2380 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2381 play_element_sound(x, y, SOUND_eater, Xeater_e);
2386 static void Leater_s(int x, int y)
2388 if (cave[x-1][y] == Xdiamond)
2390 cave[x-1][y] = Ydiamond_blank;
2391 next[x-1][y] = Xblank;
2392 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2396 if (cave[x][y-1] == Xdiamond)
2398 cave[x][y-1] = Ydiamond_blank;
2399 next[x][y-1] = Xblank;
2400 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2404 if (cave[x+1][y] == Xdiamond)
2406 cave[x+1][y] = Ydiamond_blank;
2407 next[x+1][y] = Xblank;
2408 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2412 if (cave[x][y+1] == Xdiamond)
2414 cave[x][y+1] = Ydiamond_blank;
2415 next[x][y+1] = Xblank;
2416 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2420 switch (cave[x][y+1])
2436 cave[x][y] = Yeater_sB;
2437 next[x][y] = Xblank;
2438 cave[x][y+1] = Yeater_s;
2439 next[x][y+1] = Xeater_s;
2450 cave[x][y] = Yeater_sB;
2451 next[x][y] = Xblank;
2452 if (cave[x+1][y] == Xblank)
2453 cave[x+1][y] = Xsplash_e;
2454 if (cave[x-1][y] == Xblank)
2455 cave[x-1][y] = Xsplash_w;
2456 play_element_sound(x, y, SOUND_acid, Xacid_1);
2460 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2461 play_element_sound(x, y, SOUND_eater, Xeater_s);
2466 static void Leater_w(int x, int y)
2468 if (cave[x][y-1] == Xdiamond)
2470 cave[x][y-1] = Ydiamond_blank;
2471 next[x][y-1] = Xblank;
2472 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2476 if (cave[x+1][y] == Xdiamond)
2478 cave[x+1][y] = Ydiamond_blank;
2479 next[x+1][y] = Xblank;
2480 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2484 if (cave[x][y+1] == Xdiamond)
2486 cave[x][y+1] = Ydiamond_blank;
2487 next[x][y+1] = Xblank;
2488 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2492 if (cave[x-1][y] == Xdiamond)
2494 cave[x-1][y] = Ydiamond_blank;
2495 next[x-1][y] = Xblank;
2496 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2500 switch (cave[x-1][y])
2516 cave[x][y] = Yeater_wB;
2517 next[x][y] = Xblank;
2518 cave[x-1][y] = Yeater_w;
2519 next[x-1][y] = Xeater_w;
2530 cave[x][y] = Yeater_wB;
2531 next[x][y] = Xblank;
2532 if (cave[x][y-1] == Xblank)
2533 cave[x][y-1] = Xsplash_e;
2534 if (cave[x-2][y-1] == Xblank)
2535 cave[x-2][y-1] = Xsplash_w;
2536 play_element_sound(x, y, SOUND_acid, Xacid_1);
2540 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2541 play_element_sound(x, y, SOUND_eater, Xeater_w);
2546 static void Lalien(int x, int y)
2557 set_nearest_player_xy(x, y, &dx, &dy);
2564 switch (cave[x][y-1])
2580 cave[x][y] = Yalien_nB;
2581 next[x][y] = Xblank;
2582 cave[x][y-1] = Yalien_n;
2583 next[x][y-1] = Xalien_pause;
2584 play_element_sound(x, y, SOUND_alien, Xalien);
2595 cave[x][y] = Yalien_nB;
2596 next[x][y] = Xblank;
2597 if (cave[x+1][y-2] == Xblank)
2598 cave[x+1][y-2] = Xsplash_e;
2599 if (cave[x-1][y-2] == Xblank)
2600 cave[x-1][y-2] = Xsplash_w;
2601 play_element_sound(x, y, SOUND_acid, Xacid_1);
2607 switch (cave[x][y+1])
2623 cave[x][y] = Yalien_sB;
2624 next[x][y] = Xblank;
2625 cave[x][y+1] = Yalien_s;
2626 next[x][y+1] = Xalien_pause;
2627 play_element_sound(x, y, SOUND_alien, Xalien);
2638 cave[x][y] = Yalien_sB;
2639 next[x][y] = Xblank;
2640 if (cave[x+1][y] == Xblank)
2641 cave[x+1][y] = Xsplash_e;
2642 if (cave[x-1][y] == Xblank)
2643 cave[x-1][y] = Xsplash_w;
2644 play_element_sound(x, y, SOUND_acid, Xacid_1);
2653 switch (cave[x+1][y])
2669 cave[x][y] = Yalien_eB;
2670 next[x][y] = Xblank;
2671 cave[x+1][y] = Yalien_e;
2672 next[x+1][y] = Xalien_pause;
2673 play_element_sound(x, y, SOUND_alien, Xalien);
2684 cave[x][y] = Yalien_eB;
2685 next[x][y] = Xblank;
2686 if (cave[x+2][y-1] == Xblank)
2687 cave[x+2][y-1] = Xsplash_e;
2688 if (cave[x][y-1] == Xblank)
2689 cave[x][y-1] = Xsplash_w;
2690 play_element_sound(x, y, SOUND_acid, Xacid_1);
2696 switch (cave[x-1][y])
2712 cave[x][y] = Yalien_wB;
2713 next[x][y] = Xblank;
2714 cave[x-1][y] = Yalien_w;
2715 next[x-1][y] = Xalien_pause;
2716 play_element_sound(x, y, SOUND_alien, Xalien);
2727 cave[x][y] = Yalien_wB;
2728 next[x][y] = Xblank;
2729 if (cave[x][y-1] == Xblank)
2730 cave[x][y-1] = Xsplash_e;
2731 if (cave[x-2][y-1] == Xblank)
2732 cave[x-2][y-1] = Xsplash_w;
2733 play_element_sound(x, y, SOUND_acid, Xacid_1);
2740 static void Lalien_pause(int x, int y)
2742 next[x][y] = Xalien;
2745 static void Lbug_n(int x, int y)
2747 switch (cave[x][y-1])
2763 cave[x][y] = Ybug_nB;
2764 next[x][y] = Xblank;
2765 cave[x][y-1] = Ybug_n;
2766 next[x][y-1] = Xbug_1_n;
2767 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2778 cave[x][y] = Ybug_nB;
2779 next[x][y] = Xblank;
2780 if (cave[x+1][y-2] == Xblank)
2781 cave[x+1][y-2] = Xsplash_e;
2782 if (cave[x-1][y-2] == Xblank)
2783 cave[x-1][y-2] = Xsplash_w;
2784 play_element_sound(x, y, SOUND_acid, Xacid_1);
2788 cave[x][y] = Ybug_n_w;
2789 next[x][y] = Xbug_2_w;
2790 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2795 static void Lbug_1_n(int x, int y)
2797 if (is_amoeba[cave[x][y-1]] ||
2798 is_amoeba[cave[x+1][y]] ||
2799 is_amoeba[cave[x][y+1]] ||
2800 is_amoeba[cave[x-1][y]])
2802 Lboom_bug(x, y, Xbug_1_n);
2807 switch (cave[x+1][y])
2831 cave[x][y] = Ybug_n_e;
2832 next[x][y] = Xbug_2_e;
2833 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2842 static void Lbug_2_n(int x, int y)
2844 if (is_amoeba[cave[x][y-1]] ||
2845 is_amoeba[cave[x+1][y]] ||
2846 is_amoeba[cave[x][y+1]] ||
2847 is_amoeba[cave[x-1][y]])
2849 Lboom_bug(x, y, Xbug_2_n);
2857 static void Lbug_e(int x, int y)
2859 switch (cave[x+1][y])
2875 cave[x][y] = Ybug_eB;
2876 next[x][y] = Xblank;
2877 cave[x+1][y] = Ybug_e;
2878 next[x+1][y] = Xbug_1_e;
2879 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2890 cave[x][y] = Ybug_eB;
2891 next[x][y] = Xblank;
2892 if (cave[x+2][y-1] == Xblank)
2893 cave[x+2][y-1] = Xsplash_e;
2894 if (cave[x][y-1] == Xblank)
2895 cave[x][y-1] = Xsplash_w;
2896 play_element_sound(x, y, SOUND_acid, Xacid_1);
2900 cave[x][y] = Ybug_e_n;
2901 next[x][y] = Xbug_2_n;
2902 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2907 static void Lbug_1_e(int x, int y)
2909 if (is_amoeba[cave[x][y-1]] ||
2910 is_amoeba[cave[x+1][y]] ||
2911 is_amoeba[cave[x][y+1]] ||
2912 is_amoeba[cave[x-1][y]])
2914 Lboom_bug(x, y, Xbug_1_e);
2919 switch (cave[x][y+1])
2943 cave[x][y] = Ybug_e_s;
2944 next[x][y] = Xbug_2_s;
2945 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
2954 static void Lbug_2_e(int x, int y)
2956 if (is_amoeba[cave[x][y-1]] ||
2957 is_amoeba[cave[x+1][y]] ||
2958 is_amoeba[cave[x][y+1]] ||
2959 is_amoeba[cave[x-1][y]])
2961 Lboom_bug(x, y, Xbug_2_e);
2969 static void Lbug_s(int x, int y)
2971 switch (cave[x][y+1])
2987 cave[x][y] = Ybug_sB;
2988 next[x][y] = Xblank;
2989 cave[x][y+1] = Ybug_s;
2990 next[x][y+1] = Xbug_1_s;
2991 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3002 cave[x][y] = Ybug_sB;
3003 next[x][y] = Xblank;
3004 if (cave[x+1][y] == Xblank)
3005 cave[x+1][y] = Xsplash_e;
3006 if (cave[x-1][y] == Xblank)
3007 cave[x-1][y] = Xsplash_w;
3008 play_element_sound(x, y, SOUND_acid, Xacid_1);
3012 cave[x][y] = Ybug_s_e;
3013 next[x][y] = Xbug_2_e;
3014 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3019 static void Lbug_1_s(int x, int y)
3021 if (is_amoeba[cave[x][y-1]] ||
3022 is_amoeba[cave[x+1][y]] ||
3023 is_amoeba[cave[x][y+1]] ||
3024 is_amoeba[cave[x-1][y]])
3026 Lboom_bug(x, y, Xbug_1_s);
3031 switch (cave[x-1][y])
3055 cave[x][y] = Ybug_s_w;
3056 next[x][y] = Xbug_2_w;
3057 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3066 static void Lbug_2_s(int x, int y)
3068 if (is_amoeba[cave[x][y-1]] ||
3069 is_amoeba[cave[x+1][y]] ||
3070 is_amoeba[cave[x][y+1]] ||
3071 is_amoeba[cave[x-1][y]])
3073 Lboom_bug(x, y, Xbug_2_s);
3081 static void Lbug_w(int x, int y)
3083 switch (cave[x-1][y])
3099 cave[x][y] = Ybug_wB;
3100 next[x][y] = Xblank;
3101 cave[x-1][y] = Ybug_w;
3102 next[x-1][y] = Xbug_1_w;
3103 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3114 cave[x][y] = Ybug_wB;
3115 next[x][y] = Xblank;
3116 if (cave[x][y-1] == Xblank)
3117 cave[x][y-1] = Xsplash_e;
3118 if (cave[x-2][y-1] == Xblank)
3119 cave[x-2][y-1] = Xsplash_w;
3120 play_element_sound(x, y, SOUND_acid, Xacid_1);
3124 cave[x][y] = Ybug_w_s;
3125 next[x][y] = Xbug_2_s;
3126 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3131 static void Lbug_1_w(int x, int y)
3133 if (is_amoeba[cave[x][y-1]] ||
3134 is_amoeba[cave[x+1][y]] ||
3135 is_amoeba[cave[x][y+1]] ||
3136 is_amoeba[cave[x-1][y]])
3138 Lboom_bug(x, y, Xbug_1_w);
3143 switch (cave[x][y-1])
3167 cave[x][y] = Ybug_w_n;
3168 next[x][y] = Xbug_2_n;
3169 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3178 static void Lbug_2_w(int x, int y)
3180 if (is_amoeba[cave[x][y-1]] ||
3181 is_amoeba[cave[x+1][y]] ||
3182 is_amoeba[cave[x][y+1]] ||
3183 is_amoeba[cave[x-1][y]])
3185 Lboom_bug(x, y, Xbug_2_w);
3193 static void Ltank_n(int x, int y)
3195 switch (cave[x][y-1])
3211 cave[x][y] = Ytank_nB;
3212 next[x][y] = Xblank;
3213 cave[x][y-1] = Ytank_n;
3214 next[x][y-1] = Xtank_1_n;
3215 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3226 cave[x][y] = Ytank_nB;
3227 next[x][y] = Xblank;
3228 if (cave[x+1][y-2] == Xblank)
3229 cave[x+1][y-2] = Xsplash_e;
3230 if (cave[x-1][y-2] == Xblank)
3231 cave[x-1][y-2] = Xsplash_w;
3232 play_element_sound(x, y, SOUND_acid, Xacid_1);
3236 cave[x][y] = Ytank_n_e;
3237 next[x][y] = Xtank_2_e;
3238 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3243 static void Ltank_1_n(int x, int y)
3245 if (is_amoeba[cave[x][y-1]] ||
3246 is_amoeba[cave[x+1][y]] ||
3247 is_amoeba[cave[x][y+1]] ||
3248 is_amoeba[cave[x-1][y]])
3250 Lboom_tank(x, y, Xtank_1_n);
3255 switch (cave[x-1][y])
3279 cave[x][y] = Ytank_n_w;
3280 next[x][y] = Xtank_2_w;
3281 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3290 static void Ltank_2_n(int x, int y)
3292 if (is_amoeba[cave[x][y-1]] ||
3293 is_amoeba[cave[x+1][y]] ||
3294 is_amoeba[cave[x][y+1]] ||
3295 is_amoeba[cave[x-1][y]])
3297 Lboom_tank(x, y, Xtank_2_n);
3305 static void Ltank_e(int x, int y)
3307 switch (cave[x+1][y])
3323 cave[x][y] = Ytank_eB;
3324 next[x][y] = Xblank;
3325 cave[x+1][y] = Ytank_e;
3326 next[x+1][y] = Xtank_1_e;
3327 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3338 cave[x][y] = Ytank_eB;
3339 next[x][y] = Xblank;
3340 if (cave[x+2][y-1] == Xblank)
3341 cave[x+2][y-1] = Xsplash_e;
3342 if (cave[x][y-1] == Xblank)
3343 cave[x][y-1] = Xsplash_w;
3344 play_element_sound(x, y, SOUND_acid, Xacid_1);
3348 cave[x][y] = Ytank_e_s;
3349 next[x][y] = Xtank_2_s;
3350 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3355 static void Ltank_1_e(int x, int y)
3357 if (is_amoeba[cave[x][y-1]] ||
3358 is_amoeba[cave[x+1][y]] ||
3359 is_amoeba[cave[x][y+1]] ||
3360 is_amoeba[cave[x-1][y]])
3362 Lboom_tank(x, y, Xtank_1_e);
3367 switch (cave[x][y-1])
3391 cave[x][y] = Ytank_e_n;
3392 next[x][y] = Xtank_2_n;
3393 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3402 static void Ltank_2_e(int x, int y)
3404 if (is_amoeba[cave[x][y-1]] ||
3405 is_amoeba[cave[x+1][y]] ||
3406 is_amoeba[cave[x][y+1]] ||
3407 is_amoeba[cave[x-1][y]])
3409 Lboom_tank(x, y, Xtank_2_e);
3417 static void Ltank_s(int x, int y)
3419 switch (cave[x][y+1])
3435 cave[x][y] = Ytank_sB;
3436 next[x][y] = Xblank;
3437 cave[x][y+1] = Ytank_s;
3438 next[x][y+1] = Xtank_1_s;
3439 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3450 cave[x][y] = Ytank_sB;
3451 next[x][y] = Xblank;
3452 if (cave[x+1][y] == Xblank)
3453 cave[x+1][y] = Xsplash_e;
3454 if (cave[x-1][y] == Xblank)
3455 cave[x-1][y] = Xsplash_w;
3456 play_element_sound(x, y, SOUND_acid, Xacid_1);
3460 cave[x][y] = Ytank_s_w;
3461 next[x][y] = Xtank_2_w;
3462 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3467 static void Ltank_1_s(int x, int y)
3469 if (is_amoeba[cave[x][y-1]] ||
3470 is_amoeba[cave[x+1][y]] ||
3471 is_amoeba[cave[x][y+1]] ||
3472 is_amoeba[cave[x-1][y]])
3474 Lboom_tank(x, y, Xtank_1_s);
3479 switch (cave[x+1][y])
3503 cave[x][y] = Ytank_s_e;
3504 next[x][y] = Xtank_2_e;
3505 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3514 static void Ltank_2_s(int x, int y)
3516 if (is_amoeba[cave[x][y-1]] ||
3517 is_amoeba[cave[x+1][y]] ||
3518 is_amoeba[cave[x][y+1]] ||
3519 is_amoeba[cave[x-1][y]])
3521 Lboom_tank(x, y, Xtank_2_s);
3529 static void Ltank_w(int x, int y)
3531 switch (cave[x-1][y])
3547 cave[x][y] = Ytank_wB;
3548 next[x][y] = Xblank;
3549 cave[x-1][y] = Ytank_w;
3550 next[x-1][y] = Xtank_1_w;
3551 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3562 cave[x][y] = Ytank_wB;
3563 next[x][y] = Xblank;
3564 if (cave[x][y-1] == Xblank)
3565 cave[x][y-1] = Xsplash_e;
3566 if (cave[x-2][y-1] == Xblank)
3567 cave[x-2][y-1] = Xsplash_w;
3568 play_element_sound(x, y, SOUND_acid, Xacid_1);
3572 cave[x][y] = Ytank_w_n;
3573 next[x][y] = Xtank_2_n;
3574 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3579 static void Ltank_1_w(int x, int y)
3581 if (is_amoeba[cave[x][y-1]] ||
3582 is_amoeba[cave[x+1][y]] ||
3583 is_amoeba[cave[x][y+1]] ||
3584 is_amoeba[cave[x-1][y]])
3586 Lboom_tank(x, y, Xtank_1_w);
3591 switch (cave[x][y+1])
3615 cave[x][y] = Ytank_w_s;
3616 next[x][y] = Xtank_2_s;
3617 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3626 static void Ltank_2_w(int x, int y)
3628 if (is_amoeba[cave[x][y-1]] ||
3629 is_amoeba[cave[x+1][y]] ||
3630 is_amoeba[cave[x][y+1]] ||
3631 is_amoeba[cave[x-1][y]])
3633 Lboom_tank(x, y, Xtank_2_w);
3641 static void Lemerald(int x, int y)
3643 switch (cave[x][y+1])
3656 cave[x][y] = Yemerald_sB;
3657 next[x][y] = Xblank;
3658 cave[x][y+1] = Yemerald_s;
3659 next[x][y+1] = Xemerald_fall;
3670 cave[x][y] = Yemerald_sB;
3671 next[x][y] = Xblank;
3672 if (cave[x+1][y] == Xblank)
3673 cave[x+1][y] = Xsplash_e;
3674 if (cave[x-1][y] == Xblank)
3675 cave[x-1][y] = Xsplash_w;
3676 play_element_sound(x, y, SOUND_acid, Xacid_1);
3689 case Xemerald_pause:
3691 case Xdiamond_pause:
3735 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3737 cave[x][y] = Yemerald_eB;
3738 next[x][y] = Xblank;
3739 cave[x+1][y] = Yemerald_e;
3740 next[x+1][y] = Xemerald_pause;
3741 if (cave[x][y+1] == Xbumper)
3742 cave[x][y+1] = Ybumper;
3746 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3748 cave[x][y] = Yemerald_wB;
3749 next[x][y] = Xblank;
3750 cave[x-1][y] = Yemerald_w;
3751 next[x-1][y] = Xemerald_pause;
3752 if (cave[x][y+1] == Xbumper)
3753 cave[x][y+1] = Ybumper;
3759 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3761 cave[x][y] = Yemerald_wB;
3762 next[x][y] = Xblank;
3763 cave[x-1][y] = Yemerald_w;
3764 next[x-1][y] = Xemerald_pause;
3765 if (cave[x][y+1] == Xbumper)
3766 cave[x][y+1] = Ybumper;
3770 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3772 cave[x][y] = Yemerald_eB;
3773 next[x][y] = Xblank;
3774 cave[x+1][y] = Yemerald_e;
3775 next[x+1][y] = Xemerald_pause;
3776 if (cave[x][y+1] == Xbumper)
3777 cave[x][y+1] = Ybumper;
3783 if (++lev.shine_cnt > 50)
3785 lev.shine_cnt = RANDOM(8);
3786 cave[x][y] = Xemerald_shine;
3793 static void Lemerald_pause(int x, int y)
3795 switch (cave[x][y+1])
3808 cave[x][y] = Yemerald_sB;
3809 next[x][y] = Xblank;
3810 cave[x][y+1] = Yemerald_s;
3811 next[x][y+1] = Xemerald_fall;
3822 cave[x][y] = Yemerald_sB;
3823 next[x][y] = Xblank;
3824 if (cave[x+1][y] == Xblank)
3825 cave[x+1][y] = Xsplash_e;
3826 if (cave[x-1][y] == Xblank)
3827 cave[x-1][y] = Xsplash_w;
3828 play_element_sound(x, y, SOUND_acid, Xacid_1);
3832 cave[x][y] = Xemerald;
3833 next[x][y] = Xemerald;
3838 static void Lemerald_fall(int x, int y)
3840 switch (cave[x][y+1])
3854 cave[x][y] = Yemerald_sB;
3855 next[x][y] = Xblank;
3856 cave[x][y+1] = Yemerald_s;
3857 next[x][y+1] = Xemerald_fall;
3868 cave[x][y] = Yemerald_sB;
3869 next[x][y] = Xblank;
3870 if (cave[x+1][y] == Xblank)
3871 cave[x+1][y] = Xsplash_e;
3872 if (cave[x-1][y] == Xblank)
3873 cave[x-1][y] = Xsplash_w;
3874 play_element_sound(x, y, SOUND_acid, Xacid_1);
3878 if (lev.wonderwall_time)
3880 lev.wonderwall_state = 1;
3881 cave[x][y] = Yemerald_sB;
3882 next[x][y] = Xblank;
3883 if (is_blank[cave[x][y+2]])
3885 cave[x][y+2] = Ydiamond_s;
3886 next[x][y+2] = Xdiamond_fall;
3888 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
3893 cave[x][y] = Xemerald;
3894 next[x][y] = Xemerald;
3895 play_element_sound(x, y, SOUND_diamond, Xemerald);
3900 static void Ldiamond(int x, int y)
3902 switch (cave[x][y+1])
3915 cave[x][y] = Ydiamond_sB;
3916 next[x][y] = Xblank;
3917 cave[x][y+1] = Ydiamond_s;
3918 next[x][y+1] = Xdiamond_fall;
3929 cave[x][y] = Ydiamond_sB;
3930 next[x][y] = Xblank;
3931 if (cave[x+1][y] == Xblank)
3932 cave[x+1][y] = Xsplash_e;
3933 if (cave[x-1][y] == Xblank)
3934 cave[x-1][y] = Xsplash_w;
3935 play_element_sound(x, y, SOUND_acid, Xacid_1);
3948 case Xemerald_pause:
3950 case Xdiamond_pause:
3994 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3996 cave[x][y] = Ydiamond_eB;
3997 next[x][y] = Xblank;
3998 cave[x+1][y] = Ydiamond_e;
3999 next[x+1][y] = Xdiamond_pause;
4000 if (cave[x][y+1] == Xbumper)
4001 cave[x][y+1] = Ybumper;
4005 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4007 cave[x][y] = Ydiamond_wB;
4008 next[x][y] = Xblank;
4009 cave[x-1][y] = Ydiamond_w;
4010 next[x-1][y] = Xdiamond_pause;
4011 if (cave[x][y+1] == Xbumper)
4012 cave[x][y+1] = Ybumper;
4018 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4020 cave[x][y] = Ydiamond_wB;
4021 next[x][y] = Xblank;
4022 cave[x-1][y] = Ydiamond_w;
4023 next[x-1][y] = Xdiamond_pause;
4024 if (cave[x][y+1] == Xbumper)
4025 cave[x][y+1] = Ybumper;
4029 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4031 cave[x][y] = Ydiamond_eB;
4032 next[x][y] = Xblank;
4033 cave[x+1][y] = Ydiamond_e;
4034 next[x+1][y] = Xdiamond_pause;
4035 if (cave[x][y+1] == Xbumper)
4036 cave[x][y+1] = Ybumper;
4042 if (++lev.shine_cnt > 50)
4044 lev.shine_cnt = RANDOM(8);
4045 cave[x][y] = Xdiamond_shine;
4052 static void Ldiamond_pause(int x, int y)
4054 switch (cave[x][y+1])
4067 cave[x][y] = Ydiamond_sB;
4068 next[x][y] = Xblank;
4069 cave[x][y+1] = Ydiamond_s;
4070 next[x][y+1] = Xdiamond_fall;
4081 cave[x][y] = Ydiamond_sB;
4082 next[x][y] = Xblank;
4083 if (cave[x+1][y] == Xblank)
4084 cave[x+1][y] = Xsplash_e;
4085 if (cave[x-1][y] == Xblank)
4086 cave[x-1][y] = Xsplash_w;
4087 play_element_sound(x, y, SOUND_acid, Xacid_1);
4091 cave[x][y] = Xdiamond;
4092 next[x][y] = Xdiamond;
4097 static void Ldiamond_fall(int x, int y)
4099 switch (cave[x][y+1])
4113 cave[x][y] = Ydiamond_sB;
4114 next[x][y] = Xblank;
4115 cave[x][y+1] = Ydiamond_s;
4116 next[x][y+1] = Xdiamond_fall;
4127 cave[x][y] = Ydiamond_sB;
4128 next[x][y] = Xblank;
4129 if (cave[x+1][y] == Xblank)
4130 cave[x+1][y] = Xsplash_e;
4131 if (cave[x-1][y] == Xblank)
4132 cave[x-1][y] = Xsplash_w;
4133 play_element_sound(x, y, SOUND_acid, Xacid_1);
4137 if (lev.wonderwall_time)
4139 lev.wonderwall_state = 1;
4140 cave[x][y] = Ydiamond_sB;
4141 next[x][y] = Xblank;
4142 if (is_blank[cave[x][y+2]])
4144 cave[x][y+2] = Ystone_s;
4145 next[x][y+2] = Xstone_fall;
4147 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4152 cave[x][y] = Xdiamond;
4153 next[x][y] = Xdiamond;
4154 play_element_sound(x, y, SOUND_diamond, Xdiamond);
4159 static void Lstone(int x, int y)
4161 switch (cave[x][y+1])
4176 cave[x][y] = Ystone_sB;
4177 next[x][y] = Xblank;
4178 cave[x][y+1] = Ystone_s;
4179 next[x][y+1] = Xstone_fall;
4190 cave[x][y] = Ystone_sB;
4191 next[x][y] = Xblank;
4192 if (cave[x+1][y] == Xblank)
4193 cave[x+1][y] = Xsplash_e;
4194 if (cave[x-1][y] == Xblank)
4195 cave[x-1][y] = Xsplash_w;
4196 play_element_sound(x, y, SOUND_acid, Xacid_1);
4200 cave[x][y] = Xsand_stonein_1;
4201 next[x][y] = Xsand_stonein_2;
4202 cave[x][y+1] = Xsand_sandstone_1;
4203 next[x][y+1] = Xsand_sandstone_2;
4216 case Xemerald_pause:
4218 case Xdiamond_pause:
4255 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4257 cave[x][y] = Ystone_eB;
4258 next[x][y] = Xblank;
4259 cave[x+1][y] = Ystone_e;
4260 next[x+1][y] = Xstone_pause;
4261 if (cave[x][y+1] == Xbumper)
4262 cave[x][y+1] = Ybumper;
4266 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4268 cave[x][y] = Ystone_wB;
4269 next[x][y] = Xblank;
4270 cave[x-1][y] = Ystone_w;
4271 next[x-1][y] = Xstone_pause;
4272 if (cave[x][y+1] == Xbumper)
4273 cave[x][y+1] = Ybumper;
4279 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4281 cave[x][y] = Ystone_wB;
4282 next[x][y] = Xblank;
4283 cave[x-1][y] = Ystone_w;
4284 next[x-1][y] = Xstone_pause;
4285 if (cave[x][y+1] == Xbumper)
4286 cave[x][y+1] = Ybumper;
4290 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4292 cave[x][y] = Ystone_eB;
4293 next[x][y] = Xblank;
4294 cave[x+1][y] = Ystone_e;
4295 next[x+1][y] = Xstone_pause;
4296 if (cave[x][y+1] == Xbumper)
4297 cave[x][y+1] = Ybumper;
4304 static void Lstone_pause(int x, int y)
4306 switch (cave[x][y+1])
4319 cave[x][y] = Ystone_sB;
4320 next[x][y] = Xblank;
4321 cave[x][y+1] = Ystone_s;
4322 next[x][y+1] = Xstone_fall;
4333 cave[x][y] = Ystone_sB;
4334 next[x][y] = Xblank;
4335 if (cave[x+1][y] == Xblank)
4336 cave[x+1][y] = Xsplash_e;
4337 if (cave[x-1][y] == Xblank)
4338 cave[x-1][y] = Xsplash_w;
4339 play_element_sound(x, y, SOUND_acid, Xacid_1);
4343 cave[x][y] = Xstone;
4344 next[x][y] = Xstone;
4349 static void Lstone_fall(int x, int y)
4351 switch (cave[x][y+1])
4365 cave[x][y] = Ystone_sB;
4366 next[x][y] = Xblank;
4367 cave[x][y+1] = Ystone_s;
4368 next[x][y+1] = Xstone_fall;
4379 cave[x][y] = Ystone_sB;
4380 next[x][y] = Xblank;
4381 if (cave[x+1][y] == Xblank)
4382 cave[x+1][y] = Xsplash_e;
4383 if (cave[x-1][y] == Xblank)
4384 cave[x-1][y] = Xsplash_w;
4385 play_element_sound(x, y, SOUND_acid, Xacid_1);
4392 cave[x][y] = Ystone_sB;
4393 cave[x][y+1] = Yeater_stone;
4394 Lboom_eater(x, y+1, Xstone_fall);
4395 score += lev.eater_score;
4400 cave[x][y] = Ystone_sB;
4401 cave[x][y+1] = Yalien_stone;
4402 Lboom_tank(x, y+1, Xstone_fall);
4403 score += lev.alien_score;
4414 cave[x][y] = Ystone_sB;
4415 cave[x][y+1] = Ybug_stone;
4416 Lboom_bug(x, y+1, Xstone_fall);
4417 score += lev.bug_score;
4428 cave[x][y] = Ystone_sB;
4429 cave[x][y+1] = Ytank_stone;
4430 Lboom_tank(x, y+1, Xstone_fall);
4431 score += lev.tank_score;
4435 case Xdiamond_pause:
4436 switch (cave[x][y+2])
4492 next[x][y] = Xstone;
4493 play_element_sound(x, y, SOUND_stone, Xstone);
4497 cave[x][y] = Ystone_sB;
4498 next[x][y] = Xblank;
4499 cave[x][y+1] = Ydiamond_stone;
4500 next[x][y+1] = Xstone_pause;
4501 play_element_sound(x, y, SOUND_squash, Xdiamond);
4506 cave[x][y+1] = Ybomb_blank;
4507 Lboom_tank(x, y+1, Xstone_fall);
4512 next[x][y] = Xstone;
4513 cave[x][y+1] = Ynut_stone;
4514 next[x][y+1] = Xemerald;
4515 play_element_sound(x, y, SOUND_crack, Xnut);
4516 score += lev.nut_score;
4522 switch (cave[x+1][y+1])
4537 cave[x][y+1] = Xspring_e;
4541 cave[x][y+1] = Xspring_w;
4547 switch (cave[x-1][y+1])
4562 cave[x][y+1] = Xspring_w;
4565 cave[x][y+1] = Xspring_e;
4570 next[x][y] = Xstone;
4574 if (lev.wonderwall_time)
4576 lev.wonderwall_state = 1;
4577 cave[x][y] = Ystone_sB;
4578 next[x][y] = Xblank;
4579 if (is_blank[cave[x][y+2]])
4581 cave[x][y+2] = Yemerald_s;
4582 next[x][y+2] = Xemerald_fall;
4584 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4589 cave[x][y] = Xstone;
4590 next[x][y] = Xstone;
4591 play_element_sound(x, y, SOUND_stone, Xstone);
4596 static void Lbomb(int x, int y)
4598 switch (cave[x][y+1])
4611 cave[x][y] = Ybomb_sB;
4612 next[x][y] = Xblank;
4613 cave[x][y+1] = Ybomb_s;
4614 next[x][y+1] = Xbomb_fall;
4625 cave[x][y] = Ybomb_sB;
4626 next[x][y] = Xblank;
4627 if (cave[x+1][y] == Xblank)
4628 cave[x+1][y] = Xsplash_e;
4629 if (cave[x-1][y] == Xblank)
4630 cave[x-1][y] = Xsplash_w;
4631 play_element_sound(x, y, SOUND_acid, Xacid_1);
4644 case Xemerald_pause:
4646 case Xdiamond_pause:
4681 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4683 cave[x][y] = Ybomb_eB;
4684 next[x][y] = Xblank;
4685 cave[x+1][y] = Ybomb_e;
4686 next[x+1][y] = Xbomb_pause;
4687 if (cave[x][y+1] == Xbumper)
4688 cave[x][y+1] = Ybumper;
4692 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4694 cave[x][y] = Ybomb_wB;
4695 next[x][y] = Xblank;
4696 cave[x-1][y] = Ybomb_w;
4697 next[x-1][y] = Xbomb_pause;
4698 if (cave[x][y+1] == Xbumper)
4699 cave[x][y+1] = Ybumper;
4705 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4707 cave[x][y] = Ybomb_wB;
4708 next[x][y] = Xblank;
4709 cave[x-1][y] = Ybomb_w;
4710 next[x-1][y] = Xbomb_pause;
4711 if (cave[x][y+1] == Xbumper)
4712 cave[x][y+1] = Ybumper;
4716 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4718 cave[x][y] = Ybomb_eB;
4719 next[x][y] = Xblank;
4720 cave[x+1][y] = Ybomb_e;
4721 next[x+1][y] = Xbomb_pause;
4722 if (cave[x][y+1] == Xbumper)
4723 cave[x][y+1] = Ybumper;
4730 static void Lbomb_pause(int x, int y)
4732 switch (cave[x][y+1])
4745 cave[x][y] = Ybomb_sB;
4746 next[x][y] = Xblank;
4747 cave[x][y+1] = Ybomb_s;
4748 next[x][y+1] = Xbomb_fall;
4759 cave[x][y] = Ybomb_sB;
4760 next[x][y] = Xblank;
4761 if (cave[x+1][y] == Xblank)
4762 cave[x+1][y] = Xsplash_e;
4763 if (cave[x-1][y] == Xblank)
4764 cave[x-1][y] = Xsplash_w;
4765 play_element_sound(x, y, SOUND_acid, Xacid_1);
4775 static void Lbomb_fall(int x, int y)
4777 switch (cave[x][y+1])
4790 cave[x][y] = Ybomb_sB;
4791 next[x][y] = Xblank;
4792 cave[x][y+1] = Ybomb_s;
4793 next[x][y+1] = Xbomb_fall;
4804 cave[x][y] = Ybomb_sB;
4805 next[x][y] = Xblank;
4806 if (cave[x+1][y] == Xblank)
4807 cave[x+1][y] = Xsplash_e;
4808 if (cave[x-1][y] == Xblank)
4809 cave[x-1][y] = Xsplash_w;
4810 play_element_sound(x, y, SOUND_acid, Xacid_1);
4814 cave[x][y] = Ybomb_blank;
4815 Lboom_tank(x, y, Xbomb_fall);
4820 static void Lnut(int x, int y)
4822 switch (cave[x][y+1])
4835 cave[x][y] = Ynut_sB;
4836 next[x][y] = Xblank;
4837 cave[x][y+1] = Ynut_s;
4838 next[x][y+1] = Xnut_fall;
4849 cave[x][y] = Ynut_sB;
4850 next[x][y] = Xblank;
4851 if (cave[x+1][y] == Xblank)
4852 cave[x+1][y] = Xsplash_e;
4853 if (cave[x-1][y] == Xblank)
4854 cave[x-1][y] = Xsplash_w;
4855 play_element_sound(x, y, SOUND_acid, Xacid_1);
4868 case Xemerald_pause:
4870 case Xdiamond_pause:
4905 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4907 cave[x][y] = Ynut_eB;
4908 next[x][y] = Xblank;
4909 cave[x+1][y] = Ynut_e;
4910 next[x+1][y] = Xnut_pause;
4911 if (cave[x][y+1] == Xbumper)
4912 cave[x][y+1] = Ybumper;
4916 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4918 cave[x][y] = Ynut_wB;
4919 next[x][y] = Xblank;
4920 cave[x-1][y] = Ynut_w;
4921 next[x-1][y] = Xnut_pause;
4922 if (cave[x][y+1] == Xbumper)
4923 cave[x][y+1] = Ybumper;
4929 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4931 cave[x][y] = Ynut_wB;
4932 next[x][y] = Xblank;
4933 cave[x-1][y] = Ynut_w;
4934 next[x-1][y] = Xnut_pause;
4935 if (cave[x][y+1] == Xbumper)
4936 cave[x][y+1] = Ybumper;
4940 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4942 cave[x][y] = Ynut_eB;
4943 next[x][y] = Xblank;
4944 cave[x+1][y] = Ynut_e;
4945 next[x+1][y] = Xnut_pause;
4946 if (cave[x][y+1] == Xbumper)
4947 cave[x][y+1] = Ybumper;
4954 static void Lnut_pause(int x, int y)
4956 switch (cave[x][y+1])
4969 cave[x][y] = Ynut_sB;
4970 next[x][y] = Xblank;
4971 cave[x][y+1] = Ynut_s;
4972 next[x][y+1] = Xnut_fall;
4983 cave[x][y] = Ynut_sB;
4984 next[x][y] = Xblank;
4985 if (cave[x+1][y] == Xblank)
4986 cave[x+1][y] = Xsplash_e;
4987 if (cave[x-1][y] == Xblank)
4988 cave[x-1][y] = Xsplash_w;
4989 play_element_sound(x, y, SOUND_acid, Xacid_1);
4999 static void Lnut_fall(int x, int y)
5001 switch (cave[x][y+1])
5015 cave[x][y] = Ynut_sB;
5016 next[x][y] = Xblank;
5017 cave[x][y+1] = Ynut_s;
5018 next[x][y+1] = Xnut_fall;
5029 cave[x][y] = Ynut_sB;
5030 next[x][y] = Xblank;
5031 if (cave[x+1][y] == Xblank)
5032 cave[x+1][y] = Xsplash_e;
5033 if (cave[x-1][y] == Xblank)
5034 cave[x-1][y] = Xsplash_w;
5035 play_element_sound(x, y, SOUND_acid, Xacid_1);
5041 play_element_sound(x, y, SOUND_nut, Xnut);
5046 static void Lspring(int x, int y)
5048 switch (cave[x][y+1])
5063 cave[x][y] = Yspring_sB;
5064 next[x][y] = Xblank;
5065 cave[x][y+1] = Yspring_s;
5066 next[x][y+1] = Xspring_fall;
5077 cave[x][y] = Yspring_sB;
5078 next[x][y] = Xblank;
5079 if (cave[x+1][y] == Xblank)
5080 cave[x+1][y] = Xsplash_e;
5081 if (cave[x-1][y] == Xblank)
5082 cave[x-1][y] = Xsplash_w;
5083 play_element_sound(x, y, SOUND_acid, Xacid_1);
5096 case Xemerald_pause:
5098 case Xdiamond_pause:
5133 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5135 cave[x][y] = Yspring_eB;
5136 next[x][y] = Xblank;
5137 cave[x+1][y] = Yspring_e;
5139 next[x+1][y] = Xspring_e;
5141 next[x+1][y] = Xspring_pause;
5143 if (cave[x][y+1] == Xbumper)
5144 cave[x][y+1] = Ybumper;
5148 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5150 cave[x][y] = Yspring_wB;
5151 next[x][y] = Xblank;
5152 cave[x-1][y] = Yspring_w;
5154 next[x-1][y] = Xspring_w;
5156 next[x-1][y] = Xspring_pause;
5158 if (cave[x][y+1] == Xbumper)
5159 cave[x][y+1] = Ybumper;
5165 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5167 cave[x][y] = Yspring_wB;
5168 next[x][y] = Xblank;
5169 cave[x-1][y] = Yspring_w;
5171 next[x-1][y] = Xspring_w;
5173 next[x-1][y] = Xspring_pause;
5175 if (cave[x][y+1] == Xbumper)
5176 cave[x][y+1] = Ybumper;
5180 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5182 cave[x][y] = Yspring_eB;
5183 next[x][y] = Xblank;
5184 cave[x+1][y] = Yspring_e;
5186 next[x+1][y] = Xspring_e;
5188 next[x+1][y] = Xspring_pause;
5190 if (cave[x][y+1] == Xbumper)
5191 cave[x][y+1] = Ybumper;
5198 static void Lspring_pause(int x, int y)
5200 switch (cave[x][y+1])
5213 cave[x][y] = Yspring_sB;
5214 next[x][y] = Xblank;
5215 cave[x][y+1] = Yspring_s;
5216 next[x][y+1] = Xspring_fall;
5227 cave[x][y] = Yspring_sB;
5228 next[x][y] = Xblank;
5229 if (cave[x+1][y] == Xblank)
5230 cave[x+1][y] = Xsplash_e;
5231 if (cave[x-1][y] == Xblank)
5232 cave[x-1][y] = Xsplash_w;
5233 play_element_sound(x, y, SOUND_acid, Xacid_1);
5237 cave[x][y] = Xspring;
5238 next[x][y] = Xspring;
5243 static void Lspring_e(int x, int y)
5245 switch (cave[x][y+1])
5258 cave[x][y] = Yspring_sB;
5259 next[x][y] = Xblank;
5260 cave[x][y+1] = Yspring_s;
5261 next[x][y+1] = Xspring_fall;
5272 cave[x][y] = Yspring_sB;
5273 next[x][y] = Xblank;
5274 if (cave[x+1][y] == Xblank)
5275 cave[x+1][y] = Xsplash_e;
5276 if (cave[x-1][y] == Xblank)
5277 cave[x-1][y] = Xsplash_w;
5278 play_element_sound(x, y, SOUND_acid, Xacid_1);
5282 cave[x][y+1] = Ybumper;
5285 switch (cave[x+1][y])
5302 cave[x][y] = Yspring_eB;
5303 next[x][y] = Xblank;
5304 cave[x+1][y] = Yspring_e;
5305 next[x+1][y] = Xspring_e;
5316 cave[x][y] = Yspring_eB;
5317 next[x][y] = Xblank;
5318 if (cave[x+2][y-1] == Xblank)
5319 cave[x+2][y-1] = Xsplash_e;
5320 if (cave[x][y-1] == Xblank)
5321 cave[x][y-1] = Xsplash_w;
5322 play_element_sound(x, y, SOUND_acid, Xacid_1);
5331 cave[x][y] = Yspring_alien_eB;
5332 next[x][y] = Xblank;
5333 cave[x+1][y] = Yspring_alien_e;
5334 next[x+1][y] = Xspring_e;
5335 play_element_sound(x, y, SOUND_slurp, Xalien);
5336 score += lev.slurp_score;
5341 cave[x+1][y] = Ybumper;
5342 next[x][y] = Xspring_w;
5343 play_element_sound(x, y, SOUND_spring, Xspring);
5347 cave[x][y] = Xspring;
5348 next[x][y] = Xspring;
5349 play_element_sound(x, y, SOUND_spring, Xspring);
5354 static void Lspring_w(int x, int y)
5356 switch (cave[x][y+1])
5369 cave[x][y] = Yspring_sB;
5370 next[x][y] = Xblank;
5371 cave[x][y+1] = Yspring_s;
5372 next[x][y+1] = Xspring_fall;
5383 cave[x][y] = Yspring_sB;
5384 next[x][y] = Xblank;
5385 if (cave[x+1][y] == Xblank)
5386 cave[x+1][y] = Xsplash_e;
5387 if (cave[x-1][y] == Xblank)
5388 cave[x-1][y] = Xsplash_w;
5389 play_element_sound(x, y, SOUND_acid, Xacid_1);
5393 cave[x][y+1] = Ybumper;
5396 switch (cave[x-1][y])
5413 cave[x][y] = Yspring_wB;
5414 next[x][y] = Xblank;
5415 cave[x-1][y] = Yspring_w;
5416 next[x-1][y] = Xspring_w;
5427 cave[x][y] = Yspring_wB;
5428 next[x][y] = Xblank;
5429 if (cave[x][y-1] == Xblank)
5430 cave[x][y-1] = Xsplash_e;
5431 if (cave[x-2][y-1] == Xblank)
5432 cave[x-2][y-1] = Xsplash_w;
5433 play_element_sound(x, y, SOUND_acid, Xacid_1);
5442 cave[x][y] = Yspring_alien_wB;
5443 next[x][y] = Xblank;
5444 cave[x-1][y] = Yspring_alien_w;
5445 next[x-1][y] = Xspring_w;
5446 play_element_sound(x, y, SOUND_slurp, Xalien);
5447 score += lev.slurp_score;
5452 cave[x-1][y] = Ybumper;
5453 next[x][y] = Xspring_e;
5454 play_element_sound(x, y, SOUND_spring, Xspring);
5458 cave[x][y] = Xspring;
5459 next[x][y] = Xspring;
5460 play_element_sound(x, y, SOUND_spring, Xspring);
5465 static void Lspring_fall(int x, int y)
5467 switch (cave[x][y+1])
5481 cave[x][y] = Yspring_sB;
5482 next[x][y] = Xblank;
5483 cave[x][y+1] = Yspring_s;
5484 next[x][y+1] = Xspring_fall;
5495 cave[x][y] = Yspring_sB;
5496 next[x][y] = Xblank;
5497 if (cave[x+1][y] == Xblank)
5498 cave[x+1][y] = Xsplash_e;
5499 if (cave[x-1][y] == Xblank)
5500 cave[x-1][y] = Xsplash_w;
5501 play_element_sound(x, y, SOUND_acid, Xacid_1);
5508 cave[x][y] = Yspring_sB;
5509 cave[x][y+1] = Yeater_spring;
5510 Lboom_eater(x, y+1, Xspring_fall);
5511 score += lev.eater_score;
5516 cave[x][y] = Yspring_sB;
5517 cave[x][y+1] = Yalien_spring;
5518 Lboom_tank(x, y+1, Xspring_fall);
5519 score += lev.alien_score;
5530 cave[x][y] = Yspring_sB;
5531 cave[x][y+1] = Ybug_spring;
5532 Lboom_bug(x, y+1, Xspring_fall);
5533 score += lev.bug_score;
5544 cave[x][y] = Yspring_sB;
5545 cave[x][y+1] = Ytank_spring;
5546 Lboom_tank(x, y+1, Xspring_fall);
5547 score += lev.tank_score;
5552 cave[x][y+1] = Ybomb_blank;
5553 Lboom_tank(x, y+1, Xspring_fall);
5557 cave[x][y] = Xspring;
5558 next[x][y] = Xspring;
5559 play_element_sound(x, y, SOUND_spring, Xspring);
5564 static void Lpush_emerald_e(int x, int y)
5566 switch (cave[x+1][y])
5576 cave[x][y] = Xemerald;
5577 next[x][y] = Xemerald;
5581 cave[x][y] = Yemerald_eB;
5582 next[x][y] = Xblank;
5583 cave[x+1][y] = Yemerald_e;
5584 next[x+1][y] = Xemerald_pause;
5589 static void Lpush_emerald_w(int x, int y)
5591 switch (cave[x-1][y])
5601 cave[x][y] = Xemerald;
5602 next[x][y] = Xemerald;
5606 cave[x][y] = Yemerald_wB;
5607 next[x][y] = Xblank;
5608 cave[x-1][y] = Yemerald_w;
5609 next[x-1][y] = Xemerald_pause;
5614 static void Lpush_diamond_e(int x, int y)
5616 switch (cave[x+1][y])
5626 cave[x][y] = Xdiamond;
5627 next[x][y] = Xdiamond;
5631 cave[x][y] = Ydiamond_eB;
5632 next[x][y] = Xblank;
5633 cave[x+1][y] = Ydiamond_e;
5634 next[x+1][y] = Xdiamond_pause;
5639 static void Lpush_diamond_w(int x, int y)
5641 switch (cave[x-1][y])
5651 cave[x][y] = Xdiamond;
5652 next[x][y] = Xdiamond;
5656 cave[x][y] = Ydiamond_wB;
5657 next[x][y] = Xblank;
5658 cave[x-1][y] = Ydiamond_w;
5659 next[x-1][y] = Xdiamond_pause;
5664 static void Lpush_stone_e(int x, int y)
5666 switch (cave[x+1][y])
5676 cave[x][y] = Xstone;
5677 next[x][y] = Xstone;
5681 cave[x][y] = Ystone_eB;
5682 next[x][y] = Xblank;
5683 cave[x+1][y] = Ystone_e;
5684 next[x+1][y] = Xstone_pause;
5689 static void Lpush_stone_w(int x, int y)
5691 switch (cave[x-1][y])
5701 cave[x][y] = Xstone;
5702 next[x][y] = Xstone;
5706 cave[x][y] = Ystone_wB;
5707 next[x][y] = Xblank;
5708 cave[x-1][y] = Ystone_w;
5709 next[x-1][y] = Xstone_pause;
5714 static void Lpush_bomb_e(int x, int y)
5716 switch (cave[x+1][y])
5731 cave[x][y] = Ybomb_eB;
5732 next[x][y] = Xblank;
5733 cave[x+1][y] = Ybomb_e;
5734 next[x+1][y] = Xbomb_pause;
5739 static void Lpush_bomb_w(int x, int y)
5741 switch (cave[x-1][y])
5756 cave[x][y] = Ybomb_wB;
5757 next[x][y] = Xblank;
5758 cave[x-1][y] = Ybomb_w;
5759 next[x-1][y] = Xbomb_pause;
5764 static void Lpush_nut_e(int x, int y)
5766 switch (cave[x+1][y])
5781 cave[x][y] = Ynut_eB;
5782 next[x][y] = Xblank;
5783 cave[x+1][y] = Ynut_e;
5784 next[x+1][y] = Xnut_pause;
5789 static void Lpush_nut_w(int x, int y)
5791 switch (cave[x-1][y])
5806 cave[x][y] = Ynut_wB;
5807 next[x][y] = Xblank;
5808 cave[x-1][y] = Ynut_w;
5809 next[x-1][y] = Xnut_pause;
5814 static void Lpush_spring_e(int x, int y)
5816 switch (cave[x+1][y])
5826 cave[x][y] = Xspring;
5827 next[x][y] = Xspring;
5831 cave[x][y] = Yspring_eB;
5832 next[x][y] = Xblank;
5833 cave[x+1][y] = Yspring_e;
5834 next[x+1][y] = Xspring_e;
5839 static void Lpush_spring_w(int x, int y)
5841 switch (cave[x-1][y])
5851 cave[x][y] = Xspring;
5852 next[x][y] = Xspring;
5856 cave[x][y] = Yspring_wB;
5857 next[x][y] = Xblank;
5858 cave[x-1][y] = Yspring_w;
5859 next[x-1][y] = Xspring_w;
5864 static void Ldynamite_1(int x, int y)
5866 play_element_sound(x, y, SOUND_tick, Xdynamite_1);
5867 next[x][y] = Xdynamite_2;
5870 static void Ldynamite_2(int x, int y)
5872 play_element_sound(x, y, SOUND_tick, Xdynamite_2);
5873 next[x][y] = Xdynamite_3;
5876 static void Ldynamite_3(int x, int y)
5878 play_element_sound(x, y, SOUND_tick, Xdynamite_3);
5879 next[x][y] = Xdynamite_4;
5882 static void Ldynamite_4(int x, int y)
5884 play_element_sound(x, y, SOUND_tick, Xdynamite_4);
5885 next[x][y] = Zdynamite;
5887 Lboom_generic(x, y, Xblank, Xblank);
5890 static void Lfake_door_1(int x, int y)
5892 if (lev.magnify_cnt)
5893 cave[x][y] = Xdoor_1;
5896 static void Lfake_door_2(int x, int y)
5898 if (lev.magnify_cnt)
5899 cave[x][y] = Xdoor_2;
5902 static void Lfake_door_3(int x, int y)
5904 if (lev.magnify_cnt)
5905 cave[x][y] = Xdoor_3;
5908 static void Lfake_door_4(int x, int y)
5910 if (lev.magnify_cnt)
5911 cave[x][y] = Xdoor_4;
5914 static void Lfake_door_5(int x, int y)
5916 if (lev.magnify_cnt)
5917 cave[x][y] = Xdoor_5;
5920 static void Lfake_door_6(int x, int y)
5922 if (lev.magnify_cnt)
5923 cave[x][y] = Xdoor_6;
5926 static void Lfake_door_7(int x, int y)
5928 if (lev.magnify_cnt)
5929 cave[x][y] = Xdoor_7;
5932 static void Lfake_door_8(int x, int y)
5934 if (lev.magnify_cnt)
5935 cave[x][y] = Xdoor_8;
5938 static void Lballoon(int x, int y)
5940 if (lev.wind_cnt == 0)
5943 switch (lev.wind_direction)
5946 switch (cave[x][y-1])
5959 cave[x][y] = Yballoon_nB;
5960 next[x][y] = Xblank;
5961 cave[x][y-1] = Yballoon_n;
5962 next[x][y-1] = Xballoon;
5973 cave[x][y] = Yballoon_nB;
5974 next[x][y] = Xblank;
5975 if (cave[x+1][y-2] == Xblank)
5976 cave[x+1][y-2] = Xsplash_e;
5977 if (cave[x-1][y-2] == Xblank)
5978 cave[x-1][y-2] = Xsplash_w;
5979 play_element_sound(x, y, SOUND_acid, Xacid_1);
5985 switch (cave[x+1][y])
5998 cave[x][y] = Yballoon_eB;
5999 next[x][y] = Xblank;
6000 cave[x+1][y] = Yballoon_e;
6001 next[x+1][y] = Xballoon;
6012 cave[x][y] = Yballoon_eB;
6013 next[x][y] = Xblank;
6014 if (cave[x+2][y-1] == Xblank)
6015 cave[x+2][y-1] = Xsplash_e;
6016 if (cave[x][y-1] == Xblank)
6017 cave[x][y-1] = Xsplash_w;
6018 play_element_sound(x, y, SOUND_acid, Xacid_1);
6024 switch (cave[x][y+1])
6037 cave[x][y] = Yballoon_sB;
6038 next[x][y] = Xblank;
6039 cave[x][y+1] = Yballoon_s;
6040 next[x][y+1] = Xballoon;
6051 cave[x][y] = Yballoon_sB;
6052 next[x][y] = Xblank;
6053 if (cave[x+1][y] == Xblank)
6054 cave[x+1][y] = Xsplash_e;
6055 if (cave[x-1][y] == Xblank)
6056 cave[x-1][y] = Xsplash_w;
6057 play_element_sound(x, y, SOUND_acid, Xacid_1);
6063 switch (cave[x-1][y])
6076 cave[x][y] = Yballoon_wB;
6077 next[x][y] = Xblank;
6078 cave[x-1][y] = Yballoon_w;
6079 next[x-1][y] = Xballoon;
6090 cave[x][y] = Yballoon_wB;
6091 next[x][y] = Xblank;
6092 if (cave[x][y-1] == Xblank)
6093 cave[x][y-1] = Xsplash_e;
6094 if (cave[x-2][y-1] == Xblank)
6095 cave[x-2][y-1] = Xsplash_w;
6096 play_element_sound(x, y, SOUND_acid, Xacid_1);
6103 static void Lball_common(int x, int y)
6105 play_element_sound(x, y, SOUND_ball, Xball_1);
6107 if (lev.ball_random)
6112 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6113 is_blank[cave[x-1][y-1]])
6115 cave[x-1][y-1] = Yball_blank;
6116 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6121 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6122 is_blank[cave[x][y-1]])
6124 cave[x][y-1] = Yball_blank;
6125 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6130 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6131 is_blank[cave[x+1][y-1]])
6133 cave[x+1][y-1] = Yball_blank;
6134 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6139 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6140 is_blank[cave[x-1][y]])
6142 cave[x-1][y] = Yball_blank;
6143 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6148 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6149 is_blank[cave[x+1][y]])
6151 cave[x+1][y] = Yball_blank;
6152 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6157 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6158 is_blank[cave[x-1][y+1]])
6160 cave[x-1][y+1] = Yball_blank;
6161 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6166 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6167 is_blank[cave[x][y+1]])
6169 cave[x][y+1] = Yball_blank;
6170 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6175 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6176 is_blank[cave[x+1][y+1]])
6178 cave[x+1][y+1] = Yball_blank;
6179 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6186 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6187 is_blank[cave[x-1][y-1]])
6189 cave[x-1][y-1] = Yball_blank;
6190 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6193 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6194 is_blank[cave[x][y-1]])
6196 cave[x][y-1] = Yball_blank;
6197 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6200 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6201 is_blank[cave[x+1][y-1]])
6203 cave[x+1][y-1] = Yball_blank;
6204 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6207 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6208 is_blank[cave[x-1][y]])
6210 cave[x-1][y] = Yball_blank;
6211 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6214 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6215 is_blank[cave[x+1][y]])
6217 cave[x+1][y] = Yball_blank;
6218 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6221 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6222 is_blank[cave[x-1][y+1]])
6224 cave[x-1][y+1] = Yball_blank;
6225 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6228 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6229 is_blank[cave[x][y+1]])
6231 cave[x][y+1] = Yball_blank;
6232 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6235 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6236 is_blank[cave[x+1][y+1]])
6238 cave[x+1][y+1] = Yball_blank;
6239 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6243 lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
6246 static void Lball_1(int x, int y)
6248 if (lev.ball_state == 0)
6251 cave[x][y] = Yball_1;
6252 next[x][y] = Xball_2;
6259 static void Lball_2(int x, int y)
6261 if (lev.ball_state == 0)
6264 cave[x][y] = Yball_2;
6265 next[x][y] = Xball_1;
6272 static void Ldrip(int x, int y)
6274 next[x][y] = Xdrip_fall;
6277 static void Ldrip_fall(int x, int y)
6281 switch (cave[x][y+1])
6297 cave[x][y] = Ydrip_1_sB;
6298 next[x][y] = Xdrip_stretchB;
6299 cave[x][y+1] = Ydrip_1_s;
6300 next[x][y+1] = Xdrip_stretch;
6311 cave[x][y] = Ydrip_1_sB;
6312 next[x][y] = Xdrip_stretchB;
6313 if (cave[x+1][y] == Xblank)
6314 cave[x+1][y] = Xsplash_e;
6315 if (cave[x-1][y] == Xblank)
6316 cave[x-1][y] = Xsplash_w;
6317 play_element_sound(x, y, SOUND_acid, Xacid_1);
6323 case 0: temp = Xamoeba_1; break;
6324 case 1: temp = Xamoeba_2; break;
6325 case 2: temp = Xamoeba_3; break;
6326 case 3: temp = Xamoeba_4; break;
6327 case 4: temp = Xamoeba_5; break;
6328 case 5: temp = Xamoeba_6; break;
6329 case 6: temp = Xamoeba_7; break;
6330 case 7: temp = Xamoeba_8; break;
6335 play_element_sound(x, y, SOUND_drip, Xdrip_fall);
6340 static void Ldrip_stretch(int x, int y)
6342 cave[x][y] = Ydrip_2_s;
6343 next[x][y] = Xdrip_fall;
6346 static void Ldrip_stretchB(int x, int y)
6348 cave[x][y] = Ydrip_2_sB;
6349 next[x][y] = Xblank;
6352 static void Lwonderwall(int x, int y)
6354 if (lev.wonderwall_time && lev.wonderwall_state)
6356 cave[x][y] = Ywonderwall;
6357 play_element_sound(x, y, SOUND_wonder, Xwonderwall);
6361 static void Lwheel(int x, int y)
6363 if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
6364 cave[x][y] = Ywheel;
6367 static void Lswitch(int x, int y)
6370 cave[x][y] = Yswitch;
6373 static void Lfake_blank(int x, int y)
6376 cave[x][y] = Yfake_blank;
6379 static void Lfake_grass(int x, int y)
6381 if (lev.magnify_cnt)
6382 cave[x][y] = Yfake_grass;
6385 static void Lfake_amoeba(int x, int y)
6388 cave[x][y] = Yfake_amoeba;
6391 static void Lsand_stone(int x, int y)
6393 switch (cave[x][y+1])
6406 cave[x][y] = Xsand_stonesand_quickout_1;
6407 next[x][y] = Xsand_stonesand_quickout_2;
6408 cave[x][y+1] = Xsand_stoneout_1;
6409 next[x][y+1] = Xsand_stoneout_2;
6420 cave[x][y] = Xsand_stonesand_quickout_1;
6421 next[x][y] = Xsand_stonesand_quickout_2;
6422 if (cave[x+1][y] == Xblank)
6423 cave[x+1][y] = Xsplash_e;
6424 if (cave[x-1][y] == Xblank)
6425 cave[x-1][y] = Xsplash_w;
6426 play_element_sound(x, y, SOUND_acid, Xacid_1);
6430 cave[x][y] = Xsand_stonesand_1;
6431 next[x][y] = Xsand_stonesand_2;
6432 cave[x][y+1] = Xsand_sandstone_1;
6433 next[x][y+1] = Xsand_sandstone_2;
6438 static void Lsand_stonein_1(int x, int y)
6440 next[x][y] = Xsand_stonein_2;
6443 static void Lsand_stonein_2(int x, int y)
6445 next[x][y] = Xsand_stonein_3;
6448 static void Lsand_stonein_3(int x, int y)
6450 next[x][y] = Xsand_stonein_4;
6453 static void Lsand_stonein_4(int x, int y)
6455 next[x][y] = Xblank;
6458 static void Lsand_sandstone_1(int x, int y)
6460 next[x][y] = Xsand_sandstone_2;
6463 static void Lsand_sandstone_2(int x, int y)
6465 next[x][y] = Xsand_sandstone_3;
6468 static void Lsand_sandstone_3(int x, int y)
6470 next[x][y] = Xsand_sandstone_4;
6473 static void Lsand_sandstone_4(int x, int y)
6475 next[x][y] = Xsand_stone;
6478 static void Lsand_stonesand_1(int x, int y)
6480 next[x][y] = Xsand_stonesand_2;
6483 static void Lsand_stonesand_2(int x, int y)
6485 next[x][y] = Xsand_stonesand_3;
6488 static void Lsand_stonesand_3(int x, int y)
6490 next[x][y] = Xsand_stonesand_4;
6493 static void Lsand_stonesand_4(int x, int y)
6498 static void Lsand_stoneout_1(int x, int y)
6500 next[x][y] = Xsand_stoneout_2;
6503 static void Lsand_stoneout_2(int x, int y)
6505 next[x][y] = Xstone_fall;
6508 static void Lsand_stonesand_quickout_1(int x, int y)
6510 next[x][y] = Xsand_stonesand_quickout_2;
6513 static void Lsand_stonesand_quickout_2(int x, int y)
6518 static void Lslide_ns(int x, int y)
6520 if (is_blank[cave[x][y-1]])
6522 cave[x][y-1] = Yslide_ns_blank;
6523 next[x][y-1] = Xslide_ns;
6524 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6527 if (is_blank[cave[x][y+1]])
6529 cave[x][y+1] = Yslide_ns_blank;
6530 next[x][y+1] = Xslide_ns;
6531 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6535 static void Lslide_ew(int x, int y)
6537 if (is_blank[cave[x+1][y]])
6539 cave[x+1][y] = Yslide_ew_blank;
6540 next[x+1][y] = Xslide_ew;
6541 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6544 if (is_blank[cave[x-1][y]])
6546 cave[x-1][y] = Yslide_ew_blank;
6547 next[x-1][y] = Xslide_ew;
6548 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6552 static void Lexit(int x, int y)
6554 if (lev.required > 0)
6557 switch (RANDOM(64) / 21)
6560 cave[x][y] = Xexit_1;
6561 next[x][y] = Xexit_2;
6565 cave[x][y] = Xexit_2;
6566 next[x][y] = Xexit_3;
6570 cave[x][y] = Xexit_3;
6571 next[x][y] = Xexit_1;
6575 play_element_sound(x, y, SOUND_exit_open, Xexit);
6578 static void Lexit_1(int x, int y)
6580 next[x][y] = Xexit_2;
6583 static void Lexit_2(int x, int y)
6585 next[x][y] = Xexit_3;
6588 static void Lexit_3(int x, int y)
6590 next[x][y] = Xexit_1;
6593 static void Lpause(int x, int y)
6595 next[x][y] = Xblank;
6598 static void Lamoeba(int x, int y)
6618 if (is_amoeba[cave[x][y-1]] ||
6619 is_amoeba[cave[x+1][y]] ||
6620 is_amoeba[cave[x][y+1]] ||
6621 is_amoeba[cave[x-1][y]])
6626 static void Lboom_one(int x, int y, boolean by_dynamite)
6683 cave[x][y] = Xboom_android;
6694 cave[x][y] = Xboom_bug;
6700 cave[x][y] = Xboom_bomb;
6704 cave[x][y] = Xboom_1;
6709 static void Lboom_nine(int x, int y, boolean by_dynamite)
6711 Lboom_one(x, y-1, by_dynamite);
6712 Lboom_one(x-1, y, by_dynamite);
6713 Lboom_one(x+1, y, by_dynamite);
6714 Lboom_one(x, y+1, by_dynamite);
6715 Lboom_one(x-1, y-1, by_dynamite);
6716 Lboom_one(x+1, y-1, by_dynamite);
6717 Lboom_one(x-1, y+1, by_dynamite);
6718 Lboom_one(x+1, y+1, by_dynamite);
6720 cave[x][y] = Xboom_1;
6723 static void Lexplode(int x, int y)
6728 Lboom_nine(x, y, FALSE);
6732 Lboom_nine(x, y, TRUE);
6737 static void Lboom_1(int x, int y)
6739 next[x][y] = Xboom_2;
6740 #if !PLAY_ELEMENT_SOUND
6741 if (x != lev.exit_x && y != lev.exit_y)
6742 play_sound(x, y, SOUND_boom);
6744 lev.exit_x = lev.exit_y = -1;
6748 static void Lboom_2(int x, int y)
6750 next[x][y] = boom[x][y];
6753 static void Lboom_android(int x, int y)
6755 #if PLAY_ELEMENT_SOUND
6756 play_element_sound(x, y, SOUND_boom, Xandroid);
6762 static void handle_tile(int x, int y)
6766 case Xacid_1: Lacid_1(x, y); break;
6767 case Xacid_2: Lacid_2(x, y); break;
6768 case Xacid_3: Lacid_3(x, y); break;
6769 case Xacid_4: Lacid_4(x, y); break;
6770 case Xacid_5: Lacid_5(x, y); break;
6771 case Xacid_6: Lacid_6(x, y); break;
6772 case Xacid_7: Lacid_7(x, y); break;
6773 case Xacid_8: Lacid_8(x, y); break;
6775 case Xfake_acid_1: Lfake_acid_1(x, y); break;
6776 case Xfake_acid_2: Lfake_acid_2(x, y); break;
6777 case Xfake_acid_3: Lfake_acid_3(x, y); break;
6778 case Xfake_acid_4: Lfake_acid_4(x, y); break;
6779 case Xfake_acid_5: Lfake_acid_5(x, y); break;
6780 case Xfake_acid_6: Lfake_acid_6(x, y); break;
6781 case Xfake_acid_7: Lfake_acid_7(x, y); break;
6782 case Xfake_acid_8: Lfake_acid_8(x, y); break;
6784 case Xandroid: Landroid(x, y); break;
6785 case Xandroid_1_n: Landroid_1_n(x, y); break;
6786 case Xandroid_2_n: Landroid_2_n(x, y); break;
6787 case Xandroid_1_e: Landroid_1_e(x, y); break;
6788 case Xandroid_2_e: Landroid_2_e(x, y); break;
6789 case Xandroid_1_s: Landroid_1_s(x, y); break;
6790 case Xandroid_2_s: Landroid_2_s(x, y); break;
6791 case Xandroid_1_w: Landroid_1_w(x, y); break;
6792 case Xandroid_2_w: Landroid_2_w(x, y); break;
6794 case Xeater_n: Leater_n(x, y); break;
6795 case Xeater_e: Leater_e(x, y); break;
6796 case Xeater_s: Leater_s(x, y); break;
6797 case Xeater_w: Leater_w(x, y); break;
6799 case Xalien: Lalien(x, y); break;
6800 case Xalien_pause: Lalien_pause(x, y); break;
6802 case Xbug_1_n: Lbug_1_n(x, y); break;
6803 case Xbug_2_n: Lbug_2_n(x, y); break;
6804 case Xbug_1_e: Lbug_1_e(x, y); break;
6805 case Xbug_2_e: Lbug_2_e(x, y); break;
6806 case Xbug_1_s: Lbug_1_s(x, y); break;
6807 case Xbug_2_s: Lbug_2_s(x, y); break;
6808 case Xbug_1_w: Lbug_1_w(x, y); break;
6809 case Xbug_2_w: Lbug_2_w(x, y); break;
6811 case Xtank_1_n: Ltank_1_n(x, y); break;
6812 case Xtank_2_n: Ltank_2_n(x, y); break;
6813 case Xtank_1_e: Ltank_1_e(x, y); break;
6814 case Xtank_2_e: Ltank_2_e(x, y); break;
6815 case Xtank_1_s: Ltank_1_s(x, y); break;
6816 case Xtank_2_s: Ltank_2_s(x, y); break;
6817 case Xtank_1_w: Ltank_1_w(x, y); break;
6818 case Xtank_2_w: Ltank_2_w(x, y); break;
6820 case Xemerald: Lemerald(x, y); break;
6821 case Xemerald_pause: Lemerald_pause(x, y); break;
6822 case Xemerald_fall: Lemerald_fall(x, y); break;
6824 case Xdiamond: Ldiamond(x, y); break;
6825 case Xdiamond_pause: Ldiamond_pause(x, y); break;
6826 case Xdiamond_fall: Ldiamond_fall(x, y); break;
6828 case Xstone: Lstone(x, y); break;
6829 case Xstone_pause: Lstone_pause(x, y); break;
6830 case Xstone_fall: Lstone_fall(x, y); break;
6832 case Xbomb: Lbomb(x, y); break;
6833 case Xbomb_pause: Lbomb_pause(x, y); break;
6834 case Xbomb_fall: Lbomb_fall(x, y); break;
6836 case Xnut: Lnut(x, y); break;
6837 case Xnut_pause: Lnut_pause(x, y); break;
6838 case Xnut_fall: Lnut_fall(x, y); break;
6840 case Xspring: Lspring(x, y); break;
6841 case Xspring_pause: Lspring_pause(x, y); break;
6842 case Xspring_e: Lspring_e(x, y); break;
6843 case Xspring_w: Lspring_w(x, y); break;
6844 case Xspring_fall: Lspring_fall(x, y); break;
6846 case Xpush_emerald_e: Lpush_emerald_e(x, y); break;
6847 case Xpush_emerald_w: Lpush_emerald_w(x, y); break;
6848 case Xpush_diamond_e: Lpush_diamond_e(x, y); break;
6849 case Xpush_diamond_w: Lpush_diamond_w(x, y); break;
6850 case Xpush_stone_e: Lpush_stone_e(x, y); break;
6851 case Xpush_stone_w: Lpush_stone_w(x, y); break;
6852 case Xpush_bomb_e: Lpush_bomb_e(x, y); break;
6853 case Xpush_bomb_w: Lpush_bomb_w(x, y); break;
6854 case Xpush_nut_e: Lpush_nut_e(x, y); break;
6855 case Xpush_nut_w: Lpush_nut_w(x, y); break;
6856 case Xpush_spring_e: Lpush_spring_e(x, y); break;
6857 case Xpush_spring_w: Lpush_spring_w(x, y); break;
6859 case Xdynamite_1: Ldynamite_1(x, y); break;
6860 case Xdynamite_2: Ldynamite_2(x, y); break;
6861 case Xdynamite_3: Ldynamite_3(x, y); break;
6862 case Xdynamite_4: Ldynamite_4(x, y); break;
6864 case Xfake_door_1: Lfake_door_1(x, y); break;
6865 case Xfake_door_2: Lfake_door_2(x, y); break;
6866 case Xfake_door_3: Lfake_door_3(x, y); break;
6867 case Xfake_door_4: Lfake_door_4(x, y); break;
6868 case Xfake_door_5: Lfake_door_5(x, y); break;
6869 case Xfake_door_6: Lfake_door_6(x, y); break;
6870 case Xfake_door_7: Lfake_door_7(x, y); break;
6871 case Xfake_door_8: Lfake_door_8(x, y); break;
6873 case Xballoon: Lballoon(x, y); break;
6875 case Xball_1: Lball_1(x, y); break;
6876 case Xball_2: Lball_2(x, y); break;
6878 case Xdrip: Ldrip(x, y); break;
6879 case Xdrip_fall: Ldrip_fall(x, y); break;
6880 case Xdrip_stretch: Ldrip_stretch(x, y); break;
6881 case Xdrip_stretchB: Ldrip_stretchB(x, y); break;
6883 case Xwonderwall: Lwonderwall(x, y); break;
6885 case Xwheel: Lwheel(x, y); break;
6887 case Xswitch: Lswitch(x, y); break;
6889 case Xfake_blank: Lfake_blank(x, y); break;
6890 case Xfake_grass: Lfake_grass(x, y); break;
6891 case Xfake_amoeba: Lfake_amoeba(x, y); break;
6893 case Xsand_stone: Lsand_stone(x, y); break;
6894 case Xsand_stonein_1: Lsand_stonein_1(x, y); break;
6895 case Xsand_stonein_2: Lsand_stonein_2(x, y); break;
6896 case Xsand_stonein_3: Lsand_stonein_3(x, y); break;
6897 case Xsand_stonein_4: Lsand_stonein_4(x, y); break;
6898 case Xsand_sandstone_1: Lsand_sandstone_1(x, y); break;
6899 case Xsand_sandstone_2: Lsand_sandstone_2(x, y); break;
6900 case Xsand_sandstone_3: Lsand_sandstone_3(x, y); break;
6901 case Xsand_sandstone_4: Lsand_sandstone_4(x, y); break;
6902 case Xsand_stonesand_1: Lsand_stonesand_1(x, y); break;
6903 case Xsand_stonesand_2: Lsand_stonesand_2(x, y); break;
6904 case Xsand_stonesand_3: Lsand_stonesand_3(x, y); break;
6905 case Xsand_stonesand_4: Lsand_stonesand_4(x, y); break;
6906 case Xsand_stoneout_1: Lsand_stoneout_1(x, y); break;
6907 case Xsand_stoneout_2: Lsand_stoneout_2(x, y); break;
6908 case Xsand_stonesand_quickout_1: Lsand_stonesand_quickout_1(x, y); break;
6909 case Xsand_stonesand_quickout_2: Lsand_stonesand_quickout_2(x, y); break;
6911 case Xslide_ns: Lslide_ns(x, y); break;
6912 case Xslide_ew: Lslide_ew(x, y); break;
6914 case Xexit: Lexit(x, y); break;
6915 case Xexit_1: Lexit_1(x, y); break;
6916 case Xexit_2: Lexit_2(x, y); break;
6917 case Xexit_3: Lexit_3(x, y); break;
6919 case Xpause: Lpause(x, y); break;
6921 case Xboom_bug: Lboom_bug(x, y, Xboom_bug); break;
6922 case Xboom_bomb: Lboom_tank(x, y, Xboom_bomb); break;
6923 case Xboom_android: Lboom_android(x, y); break;
6924 case Xboom_1: Lboom_1(x, y); break;
6925 case Xboom_2: Lboom_2(x, y); break;
6929 void logic_players(void)
6938 game_em.any_player_moving = FALSE;
6939 game_em.any_player_snapping = FALSE;
6941 /* must test for death and actually kill separately */
6942 for (i = 0; i < MAX_PLAYERS; i++)
6944 boolean ply_kill = player_killed(&ply[i]);
6946 if (ply[i].alive && ply_kill)
6947 kill_player(&ply[i]);
6950 for (i = 0; i < MAX_PLAYERS; i++)
6952 /* check for wrap-around movement */
6953 if (ply[i].x < lev.left ||
6954 ply[i].x > lev.right - 1)
6956 ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
6958 game.centered_player_nr_next = i;
6959 game.set_centered_player = TRUE;
6960 game.set_centered_player_fast = TRUE;
6963 ply[i].oldx = ply[i].x;
6964 ply[i].oldy = ply[i].y;
6965 ply[i].anim = PLY_still;
6968 start_check_nr = (RandomEM & 128 ? 0 : 1) * 2 + (RandomEM & 256 ? 0 : 1);
6970 for (i = 0; i < MAX_PLAYERS; i++)
6972 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
6974 if (ply[check_nr].alive)
6975 check_player(&ply[check_nr]);
6978 for (i = 0; i < MAX_PLAYERS; i++)
6983 if (cave[ply[i].oldx][ply[i].oldy] == Zplayer)
6985 cave[ply[i].oldx][ply[i].oldy] = Xblank;
6986 next[ply[i].oldx][ply[i].oldy] = Xblank;
6989 if (cave[ply[i].x][ply[i].y] == Xblank)
6991 cave[ply[i].x][ply[i].y] = Zplayer;
6992 next[ply[i].x][ply[i].y] = Zplayer;
6997 void logic_objects(void)
7008 for (y = lev.top; y < lev.bottom; y++)
7009 for (x = lev.left; x < lev.right; x++)
7012 if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
7013 lev.score += score; /* only add a score if someone is alive */
7015 game_em.game_over = TRUE;
7019 /* triple buffering */
7020 void *temp = lev.cave;
7021 lev.cave = lev.next;
7022 lev.next = lev.draw;
7026 void logic_globals(void)
7031 unsigned int random;
7037 /* update variables */
7039 if (lev.score > 9999)
7042 if (lev.android_move_cnt-- == 0)
7043 lev.android_move_cnt = lev.android_move_time;
7044 if (lev.android_clone_cnt-- == 0)
7045 lev.android_clone_cnt = lev.android_clone_time;
7047 if (lev.ball_cnt-- == 0)
7048 lev.ball_cnt = lev.ball_time;
7051 if (lev.magnify_cnt)
7057 if (lev.wonderwall_time && lev.wonderwall_state)
7058 lev.wonderwall_time--;
7061 play_element_sound(lev.wheel_x, lev.wheel_y, SOUND_wheel, Xwheel);
7067 for (count = lev.amoeba_time; count--;)
7069 x = lev.left - 1 + (random >> 10) % (CAVE_WIDTH + 2);
7070 y = lev.top - 1 + (random >> 20) % (CAVE_HEIGHT + 2);
7072 if (x >= lev.left && x < lev.right &&
7073 y >= lev.top && y < lev.bottom)
7076 random = random * 129 + 1;
7081 /* handle explosions */
7083 for (y = lev.top; y < lev.bottom; y++)
7084 for (x = lev.left; x < lev.right; x++)
7087 /* triple buffering */
7089 for (y = lev.top; y < lev.bottom; y++)
7090 for (x = lev.left; x < lev.right; x++)
7091 next[x][y] = cave[x][y];