5 * my own version of the emerald mine engine
11 #define SPRING_ROLL /* spring rolling off round things continues to roll */
12 #define ACID_ROLL /* rolling objects go into acid rather than remove it */
13 #define ACID_PLAYER /* player gets killed by acid, but without explosion */
15 #define RANDOM_BUG /* handle problem with old tapes using 64-bit random */
17 #define RANDOM(x) ((seed = seed << 31 | seed >> 1) % x)
19 static short **cave, **next, **boom;
20 static unsigned int seed;
23 static const byte is_blank[GAME_TILE_MAX] =
38 static const byte is_blank_or_acid[GAME_TILE_MAX] =
61 static const byte is_fake_acid[GAME_TILE_MAX] =
73 static const byte is_amoeba[GAME_TILE_MAX] =
87 static byte is_android_blank[GAME_TILE_MAX] =
102 static const byte is_android_walkable[GAME_TILE_MAX] =
118 static void Lboom_generic(int x, int y, int element, int element_middle)
120 boom[x-1][y-1] = element;
121 boom[x][y-1] = element;
122 boom[x+1][y-1] = element;
123 boom[x-1][y] = element;
124 boom[x][y] = element_middle;
125 boom[x+1][y] = element;
126 boom[x-1][y+1] = element;
127 boom[x][y+1] = element;
128 boom[x+1][y+1] = element;
131 static void Lboom_bug(int x, int y)
133 if (game_em.use_old_explosions)
136 Lboom_generic(x, y, Xemerald, Xdiamond);
138 #if PLAY_ELEMENT_SOUND
139 play_element_sound(x, y, SOUND_boom, Xbug_1_n);
143 static void Lboom_tank(int x, int y)
145 if (game_em.use_old_explosions)
148 Lboom_generic(x, y, Xblank, Xblank);
150 #if PLAY_ELEMENT_SOUND
151 play_element_sound(x, y, SOUND_boom, Xtank_1_n);
155 static void Lboom_eater(int x, int y)
157 if (game_em.use_old_explosions)
160 boom[x-1][y-1] = lev.eater_array[lev.eater_pos][0];
161 boom[x][y-1] = lev.eater_array[lev.eater_pos][1];
162 boom[x+1][y-1] = lev.eater_array[lev.eater_pos][2];
163 boom[x-1][y] = lev.eater_array[lev.eater_pos][3];
164 boom[x][y] = lev.eater_array[lev.eater_pos][4];
165 boom[x+1][y] = lev.eater_array[lev.eater_pos][5];
166 boom[x-1][y+1] = lev.eater_array[lev.eater_pos][6];
167 boom[x][y+1] = lev.eater_array[lev.eater_pos][7];
168 boom[x+1][y+1] = lev.eater_array[lev.eater_pos][8];
170 lev.eater_pos = (lev.eater_pos + 1) % lev.num_eater_arrays;
172 #if PLAY_ELEMENT_SOUND
173 play_element_sound(x, y, SOUND_boom, Xeater_n);
177 static void Lboom_bug_old(int x, int y)
179 if (!game_em.use_old_explosions)
185 static void Lboom_tank_old(int x, int y)
187 if (!game_em.use_old_explosions)
193 static void Lboom_eater_old(int x, int y)
195 if (!game_em.use_old_explosions)
201 static void Lboom_bug_new(int x, int y, boolean chain_explosion)
203 if (game_em.use_old_explosions)
212 static void Lboom_tank_new(int x, int y, boolean chain_explosion)
214 if (game_em.use_old_explosions)
223 static void Lboom_eater_new(int x, int y, boolean chain_explosion)
225 if (game_em.use_old_explosions)
234 static void Lboom_cave_new(int x, int y, int element)
236 if (game_em.use_old_explosions)
239 cave[x][y] = element;
242 static void Lboom_next_new(int x, int y, int element)
244 if (game_em.use_old_explosions)
247 next[x][y] = element;
250 static void Lpush_element_old(int x, int y, int element)
252 if (!game_em.use_old_push_elements)
255 cave[x][y] = element;
256 next[x][y] = element;
259 static boolean player_killed(struct PLAYER *ply)
267 if (lev.killed_out_of_time && setup.time_limit)
270 switch (cave[x][y-1])
291 switch (cave[x+1][y])
312 switch (cave[x][y+1])
333 switch (cave[x-1][y])
378 static void kill_player(struct PLAYER *ply)
385 switch (cave[x][y-1])
395 cave[x][y-1] = Xboom_bug;
396 Lboom_bug_new(x, y-1, TRUE);
407 cave[x][y-1] = Xboom_tank;
408 Lboom_tank_new(x, y-1, TRUE);
412 switch (cave[x+1][y])
422 cave[x+1][y] = Xboom_bug;
423 Lboom_bug_new(x+1, y, TRUE);
434 cave[x+1][y] = Xboom_tank;
435 Lboom_tank_new(x+1, y, TRUE);
439 switch (cave[x][y+1])
449 cave[x][y+1] = Xboom_bug;
450 Lboom_bug_new(x, y+1, TRUE);
461 cave[x][y+1] = Xboom_tank;
462 Lboom_tank_new(x, y+1, TRUE);
466 switch (cave[x-1][y])
476 cave[x-1][y] = Xboom_bug;
477 Lboom_bug_new(x-1, y, TRUE);
488 cave[x-1][y] = Xboom_tank;
489 Lboom_tank_new(x-1, y, TRUE);
500 play_element_sound(x, y, SOUND_exit_leave, Xexit_1);
504 play_element_sound(x, y, SOUND_die, Zplayer);
523 cave[x][y] = Xboom_1;
529 static boolean player_digfield(struct PLAYER *ply, int dx, int dy)
531 int anim = (dx < 0 ? 3 : dx > 0 ? 1 : dy < 0 ? 0 : dy > 0 ? 2 : 2);
536 boolean result = TRUE;
538 if (!dx && !dy) /* no direction specified */
541 if (dx && dy && ply->joy_snap) /* more than one direction specified */
544 if (!ply->joy_snap) /* player wants to move */
546 int element = cave[x][y];
550 /* fire is released */
554 cave[x][y] = Zplayer;
555 next[x][y] = Zplayer;
566 play_element_sound(x, y, SOUND_blank, Xblank);
567 ply->anim = PLY_walk_n + anim;
581 if (cave[x+1][y-1] == Xblank)
582 cave[x+1][y-1] = Xsplash_e;
583 if (cave[x-1][y-1] == Xblank)
584 cave[x-1][y-1] = Xsplash_w;
585 play_element_sound(x, y, SOUND_acid, Xacid_1);
606 ply->anim = PLY_walk_n + anim;
612 cave[x][y] = (dy ? (dy < 0 ? Ygrass_nB : Ygrass_sB) :
613 (dx > 0 ? Ygrass_eB : Ygrass_wB));
614 next[x][y] = Zplayer;
615 play_element_sound(x, y, SOUND_dirt, Xgrass);
616 ply->anim = PLY_walk_n + anim;
622 cave[x][y] = (dy ? (dy < 0 ? Ydirt_nB : Ydirt_sB) :
623 (dx > 0 ? Ydirt_eB : Ydirt_wB));
624 next[x][y] = Zplayer;
625 play_element_sound(x, y, SOUND_dirt, Xdirt);
626 ply->anim = PLY_walk_n + anim;
633 cave[x][y] = Ydiamond_blank;
634 next[x][y] = Zplayer;
635 play_element_sound(x, y, SOUND_collect, element);
636 lev.score += lev.diamond_score;
637 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
638 game.snapshot.collected_item = TRUE;
639 ply->anim = PLY_walk_n + anim;
646 cave[x][y] = Yemerald_blank;
647 next[x][y] = Zplayer;
648 play_element_sound(x, y, SOUND_collect, element);
649 lev.score += lev.emerald_score;
650 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
651 game.snapshot.collected_item = TRUE;
652 ply->anim = PLY_walk_n + anim;
658 cave[x][y] = Ydynamite_blank;
659 next[x][y] = Zplayer;
660 play_element_sound(x, y, SOUND_collect, element);
661 lev.score += lev.dynamite_score;
662 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
663 ply->anim = PLY_walk_n + anim;
670 cave[x][y] = Ykey_1_blank;
675 cave[x][y] = Ykey_2_blank;
680 cave[x][y] = Ykey_3_blank;
685 cave[x][y] = Ykey_4_blank;
690 cave[x][y] = Ykey_5_blank;
695 cave[x][y] = Ykey_6_blank;
700 cave[x][y] = Ykey_7_blank;
705 cave[x][y] = Ykey_8_blank;
710 next[x][y] = Zplayer;
711 play_element_sound(x, y, SOUND_collect, element);
712 lev.score += lev.key_score;
713 ply->anim = PLY_walk_n + anim;
719 cave[x][y] = Ylenses_blank;
720 next[x][y] = Zplayer;
721 play_element_sound(x, y, SOUND_collect, element);
722 lev.score += lev.lenses_score;
723 lev.lenses_cnt = lev.lenses_time;
724 ply->anim = PLY_walk_n + anim;
730 cave[x][y] = Ymagnify_blank;
731 next[x][y] = Zplayer;
732 play_element_sound(x, y, SOUND_collect, element);
733 lev.score += lev.magnify_score;
734 lev.magnify_cnt = lev.magnify_time;
735 ply->anim = PLY_walk_n + anim;
744 switch (cave[x+dx][y])
757 cave[x+dx][y] = dx > 0 ? Ystone_e : Ystone_w;
758 next[x+dx][y] = Xstone_pause;
769 if (cave[x+dx+1][y-1] == Xblank)
770 cave[x+dx+1][y-1] = Xsplash_e;
771 if (cave[x+dx-1][y-1] == Xblank)
772 cave[x+dx-1][y-1] = Xsplash_w;
773 play_element_sound(x, y, SOUND_acid, Xacid_1);
777 cave[x][y] = dx > 0 ? Ystone_eB : Ystone_wB;
778 next[x][y] = Zplayer;
779 play_element_sound(x, y, SOUND_roll, Xstone);
784 ply->anim = PLY_push_n + anim;
791 switch (cave[x+dx][y])
804 cave[x+dx][y] = dx > 0 ? Ybomb_e : Ybomb_w;
805 next[x+dx][y] = Xbomb_pause;
816 if (cave[x+dx+1][y-1] == Xblank)
817 cave[x+dx+1][y-1] = Xsplash_e;
818 if (cave[x+dx-1][y-1] == Xblank)
819 cave[x+dx-1][y-1] = Xsplash_w;
820 play_element_sound(x, y, SOUND_acid, Xacid_1);
824 cave[x][y] = dx > 0 ? Ybomb_eB : Ybomb_wB;
825 next[x][y] = Zplayer;
826 play_element_sound(x, y, SOUND_roll, Xbomb);
831 ply->anim = PLY_push_n + anim;
838 switch (cave[x+dx][y])
851 cave[x+dx][y] = dx > 0 ? Ynut_e : Ynut_w;
852 next[x+dx][y] = Xnut_pause;
863 if (cave[x+dx+1][y-1] == Xblank)
864 cave[x+dx+1][y-1] = Xsplash_e;
865 if (cave[x+dx-1][y-1] == Xblank)
866 cave[x+dx-1][y-1] = Xsplash_w;
867 play_element_sound(x, y, SOUND_acid, Xacid_1);
871 cave[x][y] = dx > 0 ? Ynut_eB : Ynut_wB;
872 next[x][y] = Zplayer;
873 play_element_sound(x, y, SOUND_roll, Xnut);
878 ply->anim = PLY_push_n + anim;
885 switch (cave[x+dx][y])
898 cave[x+dx][y] = dx > 0 ? Yspring_e : Yspring_w;
899 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
910 if (cave[x+dx+1][y-1] == Xblank)
911 cave[x+dx+1][y-1] = Xsplash_e;
912 if (cave[x+dx-1][y-1] == Xblank)
913 cave[x+dx-1][y-1] = Xsplash_w;
914 play_element_sound(x, y, SOUND_acid, Xacid_1);
918 cave[x][y] = dx > 0 ? Yspring_eB : Yspring_wB;
919 next[x][y] = Zplayer;
920 play_element_sound(x, y, SOUND_roll, Xspring);
926 cave[x][y] = dx > 0 ? Yspring_alien_eB : Yspring_alien_wB;
927 cave[x+dx][y] = dx > 0 ? Yspring_alien_e : Yspring_alien_w;
928 next[x][y] = Zplayer;
929 next[x+dx][y] = dx > 0 ? Xspring_e : Xspring_w;
930 play_element_sound(x, y, SOUND_slurp, Xalien);
931 lev.score += lev.slurp_score;
936 ply->anim = PLY_push_n + anim;
943 case Xsand_stonein_1:
944 case Xsand_stonein_2:
945 case Xsand_stonein_3:
946 case Xsand_stonein_4:
950 ply->anim = PLY_push_n + anim;
954 switch (cave[x+dx][y+dy])
967 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yballoon_n : Yballoon_s) :
968 (dx > 0 ? Yballoon_e : Yballoon_w));
969 next[x+dx][y+dy] = Xballoon;
980 if (cave[x+dx+1][y+dy-1] == Xblank)
981 cave[x+dx+1][y+dy-1] = Xsplash_e;
982 if (cave[x+dx-1][y+dy-1] == Xblank)
983 cave[x+dx-1][y+dy-1] = Xsplash_w;
984 play_element_sound(x, y, SOUND_acid, Xacid_1);
988 cave[x][y] = (dy ? (dy < 0 ? Yballoon_nB : Yballoon_sB) :
989 (dx > 0 ? Yballoon_eB : Yballoon_wB));
990 next[x][y] = Zplayer;
991 play_element_sound(x, y, SOUND_push, Xballoon);
997 ply->anim = PLY_push_n + anim;
1009 switch (cave[x+dx][y+dy])
1022 cave[x+dx][y+dy] = (dy ? (dy < 0 ? Yandroid_n : Yandroid_s) :
1023 (dx > 0 ? Yandroid_e : Yandroid_w));
1024 next[x+dx][y+dy] = (dy ? (dy < 0 ? Xandroid_2_n : Xandroid_2_s) :
1025 (dx > 0 ? Xandroid_2_e : Xandroid_2_w));
1036 if (cave[x+dx+1][y+dy-1] == Xblank)
1037 cave[x+dx+1][y+dy-1] = Xsplash_e;
1038 if (cave[x+dx-1][y+dy-1] == Xblank)
1039 cave[x+dx-1][y+dy-1] = Xsplash_w;
1040 play_element_sound(x, y, SOUND_acid, Xacid_1);
1044 cave[x][y] = (dy ? (dy < 0 ? Yandroid_nB : Yandroid_sB) :
1045 (dx > 0 ? Yandroid_eB : Yandroid_wB));
1046 next[x][y] = Zplayer;
1047 play_element_sound(x, y, SOUND_push, Xandroid);
1053 ply->anim = PLY_push_n + anim;
1058 if (ply->keys & 0x01)
1065 if (ply->keys & 0x02)
1072 if (ply->keys & 0x04)
1079 if (ply->keys & 0x08)
1086 if (ply->keys & 0x10)
1093 if (ply->keys & 0x20)
1100 if (ply->keys & 0x40)
1107 if (ply->keys & 0x80)
1114 if (!is_blank[cave[x+dx][y+dy]])
1117 if (!is_fake_acid[cave[x+dx][y+dy]])
1119 cave[x+dx][y+dy] = Zplayer;
1120 next[x+dx][y+dy] = Zplayer;
1123 play_element_sound(x, y, SOUND_door, element);
1124 ply->anim = PLY_walk_n + anim;
1130 play_element_sound(x, y, SOUND_press, element);
1131 lev.wheel_cnt = lev.wheel_time;
1137 lev.wind_direction = 0;
1141 lev.wind_direction = 1;
1145 lev.wind_direction = 2;
1149 lev.wind_direction = 3;
1153 lev.wind_direction = dy ? (dy < 0 ? 0 : 2) : (dx > 0 ? 1 : 3);
1158 play_element_sound(x, y, SOUND_press, element);
1159 lev.wind_cnt = lev.wind_time;
1163 play_element_sound(x, y, SOUND_press, element);
1168 play_element_sound(x, y, SOUND_press, element);
1169 lev.ball_cnt = lev.ball_time;
1170 lev.ball_active = !lev.ball_active;
1174 cave[x][y] = Yplant;
1175 next[x][y] = Xplant;
1176 play_element_sound(x, y, SOUND_blank, Xplant);
1177 ply->anim = PLY_walk_n + anim;
1188 game_em.level_solved = TRUE;
1190 ply->anim = PLY_walk_n + anim;
1197 if (ply->x == oldx && ply->y == oldy) /* no movement */
1200 else /* player wants to snap */
1202 int element = cave[x][y];
1206 /* fire is pressed */
1209 cave[x][y] = Ygrass_blank;
1210 next[x][y] = Xblank;
1211 play_element_sound(x, y, SOUND_dirt, element);
1212 ply->anim = PLY_shoot_n + anim;
1216 cave[x][y] = Ydirt_blank;
1217 next[x][y] = Xblank;
1218 play_element_sound(x, y, SOUND_dirt, element);
1219 ply->anim = PLY_shoot_n + anim;
1223 case Xdiamond_pause:
1224 cave[x][y] = Ydiamond_blank;
1225 next[x][y] = Xblank;
1226 play_element_sound(x, y, SOUND_collect, element);
1227 lev.score += lev.diamond_score;
1228 lev.gems_needed = lev.gems_needed < 3 ? 0 : lev.gems_needed - 3;
1229 game.snapshot.collected_item = TRUE;
1230 ply->anim = PLY_walk_n + anim;
1234 case Xemerald_pause:
1235 cave[x][y] = Yemerald_blank;
1236 next[x][y] = Xblank;
1237 play_element_sound(x, y, SOUND_collect, element);
1238 lev.score += lev.emerald_score;
1239 lev.gems_needed = lev.gems_needed < 1 ? 0 : lev.gems_needed - 1;
1240 game.snapshot.collected_item = TRUE;
1241 ply->anim = PLY_walk_n + anim;
1245 cave[x][y] = Ydynamite_blank;
1246 next[x][y] = Xblank;
1247 play_element_sound(x, y, SOUND_collect, element);
1248 lev.score += lev.dynamite_score;
1249 ply->dynamite = ply->dynamite > 9998 ? 9999 : ply->dynamite + 1;
1250 ply->anim = PLY_walk_n + anim;
1255 cave[x][y] = Ykey_1_blank;
1260 cave[x][y] = Ykey_2_blank;
1265 cave[x][y] = Ykey_3_blank;
1270 cave[x][y] = Ykey_4_blank;
1275 cave[x][y] = Ykey_5_blank;
1280 cave[x][y] = Ykey_6_blank;
1285 cave[x][y] = Ykey_7_blank;
1290 cave[x][y] = Ykey_8_blank;
1295 next[x][y] = Xblank;
1296 play_element_sound(x, y, SOUND_collect, element);
1297 lev.score += lev.key_score;
1298 ply->anim = PLY_walk_n + anim;
1302 cave[x][y] = Ylenses_blank;
1303 next[x][y] = Xblank;
1304 play_element_sound(x, y, SOUND_collect, element);
1305 lev.score += lev.lenses_score;
1306 lev.lenses_cnt = lev.lenses_time;
1307 ply->anim = PLY_walk_n + anim;
1311 cave[x][y] = Ymagnify_blank;
1312 next[x][y] = Xblank;
1313 play_element_sound(x, y, SOUND_collect, element);
1314 lev.score += lev.magnify_score;
1315 lev.magnify_cnt = lev.magnify_time;
1316 ply->anim = PLY_walk_n + anim;
1324 /* check for wrap-around movement */
1325 if (ply->x < lev.left ||
1326 ply->x > lev.right - 1)
1327 play_element_sound(oldx, oldy, SOUND_door, Xdoor_1);
1332 static void check_player(struct PLAYER *ply)
1340 game_em.last_player_direction[ply->num] = MV_NONE;
1342 if (ply->joy_w) /* west */
1347 else if (ply->joy_e) /* east */
1353 if (ply->joy_n) /* north */
1358 else if (ply->joy_s) /* south */
1370 boolean players_visible_before_move;
1371 boolean players_visible_after_move;
1374 players_visible_before_move = checkIfAllPlayersFitToScreen();
1379 players_visible_after_move = checkIfAllPlayersFitToScreen();
1382 player is allowed to move only in the following cases:
1383 - it is not needed to display all players (not focussed to all players)
1384 - all players are (still or again) visible after the move
1385 - some players were already outside visible screen area before the move
1387 can_move = (game.centered_player_nr != -1 ||
1388 players_visible_after_move ||
1389 !players_visible_before_move);
1405 if (dx == 0 && dy == 0)
1407 ply->joy_stick = FALSE;
1411 if (++ply->dynamite_cnt == 5 && ply->dynamite)
1413 cave[x][y] = Xdynamite_1;
1414 play_element_sound(x, y, SOUND_dynamite, Xdynamite_1);
1420 ply->dynamite_cnt = 0;
1423 /* be a bit more random if the player doesn't move */
1424 game_em.random += 7;
1429 ply->joy_stick = TRUE;
1435 ply->dynamite_cnt = 0; /* reset dynamite timer if we move */
1437 if (!ply->joy_snap) /* player wants to move */
1439 boolean moved = FALSE;
1441 if (ply->last_move_dir & MV_HORIZONTAL)
1443 if (!(moved = player_digfield(ply, 0, dy)))
1444 moved = player_digfield(ply, dx, 0);
1448 if (!(moved = player_digfield(ply, dx, 0)))
1449 moved = player_digfield(ply, 0, dy);
1455 ply->last_move_dir = (dx < 0 ? MV_LEFT : MV_RIGHT);
1456 else if (oldy != ply->y)
1457 ply->last_move_dir = (dy < 0 ? MV_UP : MV_DOWN);
1459 game_em.any_player_moving = TRUE;
1460 game_em.last_moving_player = ply->num;
1461 game_em.last_player_direction[ply->num] = ply->last_move_dir;
1464 else /* player wants to snap */
1466 game_em.any_player_snapping = player_digfield(ply, dx, dy);
1470 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
1472 int distance, distance_shortest = CAVE_WIDTH + CAVE_HEIGHT;
1475 /* default values if no players are alive anymore */
1479 for (i = 0; i < MAX_PLAYERS; i++)
1484 distance = ABS(ply[i].x - x) + ABS(ply[i].y - y);
1486 if (distance < distance_shortest)
1491 distance_shortest = distance;
1496 static void Lacid_1(int x, int y)
1498 next[x][y] = Xacid_2;
1501 static void Lacid_2(int x, int y)
1503 next[x][y] = Xacid_3;
1506 static void Lacid_3(int x, int y)
1508 next[x][y] = Xacid_4;
1511 static void Lacid_4(int x, int y)
1513 next[x][y] = Xacid_5;
1516 static void Lacid_5(int x, int y)
1518 next[x][y] = Xacid_6;
1521 static void Lacid_6(int x, int y)
1523 next[x][y] = Xacid_7;
1526 static void Lacid_7(int x, int y)
1528 next[x][y] = Xacid_8;
1531 static void Lacid_8(int x, int y)
1533 next[x][y] = Xacid_1;
1536 static void Lfake_acid_1(int x, int y)
1538 next[x][y] = Xfake_acid_2;
1541 static void Lfake_acid_2(int x, int y)
1543 next[x][y] = Xfake_acid_3;
1546 static void Lfake_acid_3(int x, int y)
1548 next[x][y] = Xfake_acid_4;
1551 static void Lfake_acid_4(int x, int y)
1553 next[x][y] = Xfake_acid_5;
1556 static void Lfake_acid_5(int x, int y)
1558 next[x][y] = Xfake_acid_6;
1561 static void Lfake_acid_6(int x, int y)
1563 next[x][y] = Xfake_acid_7;
1566 static void Lfake_acid_7(int x, int y)
1568 next[x][y] = Xfake_acid_8;
1571 static void Lfake_acid_8(int x, int y)
1573 next[x][y] = Xfake_acid_1;
1576 static void Landroid(int x, int y)
1580 if (lev.android_clone_cnt == 0)
1582 if (!is_android_blank[cave[x-1][y-1]] &&
1583 !is_android_blank[cave[x][y-1]] &&
1584 !is_android_blank[cave[x+1][y-1]] &&
1585 !is_android_blank[cave[x-1][y]] &&
1586 !is_android_blank[cave[x+1][y]] &&
1587 !is_android_blank[cave[x-1][y+1]] &&
1588 !is_android_blank[cave[x][y+1]] &&
1589 !is_android_blank[cave[x+1][y+1]])
1594 /* randomly find an object to clone */
1596 case 0: /* S,NE,W,NW,SE,E,SW,N */
1597 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1598 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1599 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1600 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1601 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1602 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1603 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1604 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1607 case 1: /* NW,SE,N,S,NE,SW,E,W */
1608 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1609 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1610 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1611 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1612 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1613 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1614 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1615 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1618 case 2: /* SW,E,S,W,N,NW,SE,NE */
1619 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1620 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1621 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1622 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1623 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1624 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1625 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1626 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1629 case 3: /* N,SE,NE,E,W,S,NW,SW */
1630 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1631 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1632 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1633 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1634 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1635 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1636 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1637 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1640 case 4: /* SE,NW,E,NE,SW,W,N,S */
1641 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1642 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1643 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1644 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1645 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1646 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1647 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1648 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1651 case 5: /* NE,W,SE,SW,S,N,E,NW */
1652 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1653 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1654 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1655 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1656 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1657 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1658 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1659 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1662 case 6: /* E,N,SW,S,NW,NE,SE,W */
1663 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1664 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1665 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1666 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1667 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1668 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1669 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1670 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1673 case 7: /* W,SW,NW,N,E,SE,NE,S */
1674 temp = lev.android_array[cave[x-1][y]]; if (temp != Xblank) break;
1675 temp = lev.android_array[cave[x-1][y+1]]; if (temp != Xblank) break;
1676 temp = lev.android_array[cave[x-1][y-1]]; if (temp != Xblank) break;
1677 temp = lev.android_array[cave[x][y-1]]; if (temp != Xblank) break;
1678 temp = lev.android_array[cave[x+1][y]]; if (temp != Xblank) break;
1679 temp = lev.android_array[cave[x+1][y+1]]; if (temp != Xblank) break;
1680 temp = lev.android_array[cave[x+1][y-1]]; if (temp != Xblank) break;
1681 temp = lev.android_array[cave[x][y+1]]; if (temp != Xblank) break;
1685 next[x][y] = temp; /* the item we chose to clone */
1686 play_element_sound(x, y, SOUND_android_clone, temp);
1690 /* randomly find a direction to move */
1692 case 0: /* S,NE,W,NW,SE,E,SW,N */
1693 if (is_android_blank[cave[x][y+1]]) goto android_s;
1694 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1695 if (is_android_blank[cave[x-1][y]]) goto android_w;
1696 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1697 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1698 if (is_android_blank[cave[x+1][y]]) goto android_e;
1699 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1700 if (is_android_blank[cave[x][y-1]]) goto android_n;
1703 case 1: /* NW,SE,N,S,NE,SW,E,W */
1704 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1705 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1706 if (is_android_blank[cave[x][y-1]]) goto android_n;
1707 if (is_android_blank[cave[x][y+1]]) goto android_s;
1708 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1709 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1710 if (is_android_blank[cave[x+1][y]]) goto android_e;
1711 if (is_android_blank[cave[x-1][y]]) goto android_w;
1714 case 2: /* SW,E,S,W,N,NW,SE,NE */
1715 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1716 if (is_android_blank[cave[x+1][y]]) goto android_e;
1717 if (is_android_blank[cave[x][y+1]]) goto android_s;
1718 if (is_android_blank[cave[x-1][y]]) goto android_w;
1719 if (is_android_blank[cave[x][y-1]]) goto android_n;
1720 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1721 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1722 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1725 case 3: /* N,SE,NE,E,W,S,NW,SW */
1726 if (is_android_blank[cave[x][y-1]]) goto android_n;
1727 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1728 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1729 if (is_android_blank[cave[x+1][y]]) goto android_e;
1730 if (is_android_blank[cave[x-1][y]]) goto android_w;
1731 if (is_android_blank[cave[x][y+1]]) goto android_s;
1732 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1733 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1736 case 4: /* SE,NW,E,NE,SW,W,N,S */
1737 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1738 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1739 if (is_android_blank[cave[x+1][y]]) goto android_e;
1740 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1741 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1742 if (is_android_blank[cave[x-1][y]]) goto android_w;
1743 if (is_android_blank[cave[x][y-1]]) goto android_n;
1744 if (is_android_blank[cave[x][y+1]]) goto android_s;
1747 case 5: /* NE,W,SE,SW,S,N,E,NW */
1748 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1749 if (is_android_blank[cave[x-1][y]]) goto android_w;
1750 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1751 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1752 if (is_android_blank[cave[x][y+1]]) goto android_s;
1753 if (is_android_blank[cave[x][y-1]]) goto android_n;
1754 if (is_android_blank[cave[x+1][y]]) goto android_e;
1755 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1758 case 6: /* E,N,SW,S,NW,NE,SE,W */
1759 if (is_android_blank[cave[x+1][y]]) goto android_e;
1760 if (is_android_blank[cave[x][y-1]]) goto android_n;
1761 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1762 if (is_android_blank[cave[x][y+1]]) goto android_s;
1763 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1764 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1765 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1766 if (is_android_blank[cave[x-1][y]]) goto android_w;
1769 case 7: /* W,SW,NW,N,E,SE,NE,S */
1770 if (is_android_blank[cave[x-1][y]]) goto android_w;
1771 if (is_android_blank[cave[x-1][y+1]]) goto android_sw;
1772 if (is_android_blank[cave[x-1][y-1]]) goto android_nw;
1773 if (is_android_blank[cave[x][y-1]]) goto android_n;
1774 if (is_android_blank[cave[x+1][y]]) goto android_e;
1775 if (is_android_blank[cave[x+1][y+1]]) goto android_se;
1776 if (is_android_blank[cave[x+1][y-1]]) goto android_ne;
1777 if (is_android_blank[cave[x][y+1]]) goto android_s;
1783 if (lev.android_move_cnt == 0)
1785 if (cave[x-1][y-1] == Zplayer ||
1786 cave[x][y-1] == Zplayer ||
1787 cave[x+1][y-1] == Zplayer ||
1788 cave[x-1][y] == Zplayer ||
1789 cave[x+1][y] == Zplayer ||
1790 cave[x-1][y+1] == Zplayer ||
1791 cave[x][y+1] == Zplayer ||
1792 cave[x+1][y+1] == Zplayer)
1795 set_nearest_player_xy(x, y, &dx, &dy);
1797 next[x][y] = Xblank; /* assume we will move */
1798 temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3;
1804 /* attempt clockwise move first if direct path is blocked */
1806 case 0: /* north west */
1807 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1808 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1809 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1813 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1814 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1815 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1818 case 2: /* north east */
1819 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1820 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1821 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1825 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1826 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1827 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1830 case 4: /* nowhere */
1834 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1835 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1836 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1839 case 6: /* south west */
1840 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1841 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1842 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1846 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1847 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1848 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1851 case 8: /* south east */
1852 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1853 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1854 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1862 /* attempt counterclockwise move first if direct path is blocked */
1864 case 0: /* north west */
1865 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1866 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1867 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1871 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1872 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1873 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1876 case 2: /* north east */
1877 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1878 if (is_android_walkable[cave[x][y-1]]) goto android_n;
1879 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1883 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1884 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1885 if (is_android_walkable[cave[x-1][y-1]]) goto android_nw;
1888 case 4: /* nowhere */
1892 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1893 if (is_android_walkable[cave[x+1][y-1]]) goto android_ne;
1894 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1897 case 6: /* south west */
1898 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1899 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1900 if (is_android_walkable[cave[x-1][y]]) goto android_w;
1904 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1905 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1906 if (is_android_walkable[cave[x-1][y+1]]) goto android_sw;
1909 case 8: /* south east */
1910 if (is_android_walkable[cave[x+1][y+1]]) goto android_se;
1911 if (is_android_walkable[cave[x+1][y]]) goto android_e;
1912 if (is_android_walkable[cave[x][y+1]]) goto android_s;
1919 next[x][y] = Xandroid;
1923 cave[x][y] = Yandroid_nB;
1924 cave[x][y-1] = Yandroid_n;
1925 next[x][y-1] = Xandroid;
1926 play_element_sound(x, y, SOUND_android_move, Xandroid);
1930 cave[x][y] = Yandroid_neB;
1931 cave[x+1][y-1] = Yandroid_ne;
1932 next[x+1][y-1] = Xandroid;
1933 play_element_sound(x, y, SOUND_android_move, Xandroid);
1937 cave[x][y] = Yandroid_eB;
1938 cave[x+1][y] = Yandroid_e;
1939 next[x+1][y] = Xandroid;
1940 play_element_sound(x, y, SOUND_android_move, Xandroid);
1944 cave[x][y] = Yandroid_seB;
1945 cave[x+1][y+1] = Yandroid_se;
1946 next[x+1][y+1] = Xandroid;
1947 play_element_sound(x, y, SOUND_android_move, Xandroid);
1951 cave[x][y] = Yandroid_sB;
1952 cave[x][y+1] = Yandroid_s;
1953 next[x][y+1] = Xandroid;
1954 play_element_sound(x, y, SOUND_android_move, Xandroid);
1958 cave[x][y] = Yandroid_swB;
1959 cave[x-1][y+1] = Yandroid_sw;
1960 next[x-1][y+1] = Xandroid;
1961 play_element_sound(x, y, SOUND_android_move, Xandroid);
1965 cave[x][y] = Yandroid_wB;
1966 cave[x-1][y] = Yandroid_w;
1967 next[x-1][y] = Xandroid;
1968 play_element_sound(x, y, SOUND_android_move, Xandroid);
1972 cave[x][y] = Yandroid_nwB;
1973 cave[x-1][y-1] = Yandroid_nw;
1974 next[x-1][y-1] = Xandroid;
1975 play_element_sound(x, y, SOUND_android_move, Xandroid);
1979 static void Landroid_1_n(int x, int y)
1981 switch (cave[x][y-1])
1994 cave[x][y] = Yandroid_nB;
1995 next[x][y] = Xblank;
1996 cave[x][y-1] = Yandroid_n;
1997 next[x][y-1] = Xandroid;
1998 play_element_sound(x, y, SOUND_android_move, Xandroid_1_n);
2009 cave[x][y] = Yandroid_nB;
2010 next[x][y] = Xblank;
2011 if (cave[x+1][y-2] == Xblank)
2012 cave[x+1][y-2] = Xsplash_e;
2013 if (cave[x-1][y-2] == Xblank)
2014 cave[x-1][y-2] = Xsplash_w;
2015 play_element_sound(x, y, SOUND_acid, Xacid_1);
2024 static void Landroid_2_n(int x, int y)
2026 switch (cave[x][y-1])
2039 cave[x][y] = Yandroid_nB;
2040 next[x][y] = Xblank;
2041 cave[x][y-1] = Yandroid_n;
2042 next[x][y-1] = Xandroid_1_n;
2043 play_element_sound(x, y, SOUND_android_move, Xandroid_2_n);
2054 cave[x][y] = Yandroid_nB;
2055 next[x][y] = Xblank;
2056 if (cave[x+1][y-2] == Xblank)
2057 cave[x+1][y-2] = Xsplash_e;
2058 if (cave[x-1][y-2] == Xblank)
2059 cave[x-1][y-2] = Xsplash_w;
2060 play_element_sound(x, y, SOUND_acid, Xacid_1);
2069 static void Landroid_1_e(int x, int y)
2071 switch (cave[x+1][y])
2084 cave[x][y] = Yandroid_eB;
2085 next[x][y] = Xblank;
2086 cave[x+1][y] = Yandroid_e;
2087 next[x+1][y] = Xandroid;
2088 play_element_sound(x, y, SOUND_android_move, Xandroid_1_e);
2099 cave[x][y] = Yandroid_eB;
2100 next[x][y] = Xblank;
2101 if (cave[x+2][y-1] == Xblank)
2102 cave[x+2][y-1] = Xsplash_e;
2103 if (cave[x][y-1] == Xblank)
2104 cave[x][y-1] = Xsplash_w;
2105 play_element_sound(x, y, SOUND_acid, Xacid_1);
2114 static void Landroid_2_e(int x, int y)
2116 switch (cave[x+1][y])
2129 cave[x][y] = Yandroid_eB;
2130 next[x][y] = Xblank;
2131 cave[x+1][y] = Yandroid_e;
2132 next[x+1][y] = Xandroid_1_e;
2133 play_element_sound(x, y, SOUND_android_move, Xandroid_2_e);
2144 cave[x][y] = Yandroid_eB;
2145 next[x][y] = Xblank;
2146 if (cave[x+2][y-1] == Xblank)
2147 cave[x+2][y-1] = Xsplash_e;
2148 if (cave[x][y-1] == Xblank)
2149 cave[x][y-1] = Xsplash_w;
2150 play_element_sound(x, y, SOUND_acid, Xacid_1);
2159 static void Landroid_1_s(int x, int y)
2161 switch (cave[x][y+1])
2174 cave[x][y] = Yandroid_sB;
2175 next[x][y] = Xblank;
2176 cave[x][y+1] = Yandroid_s;
2177 next[x][y+1] = Xandroid;
2178 play_element_sound(x, y, SOUND_android_move, Xandroid_1_s);
2189 cave[x][y] = Yandroid_sB;
2190 next[x][y] = Xblank;
2191 if (cave[x+1][y] == Xblank)
2192 cave[x+1][y] = Xsplash_e;
2193 if (cave[x-1][y] == Xblank)
2194 cave[x-1][y] = Xsplash_w;
2195 play_element_sound(x, y, SOUND_acid, Xacid_1);
2204 static void Landroid_2_s(int x, int y)
2206 switch (cave[x][y+1])
2219 cave[x][y] = Yandroid_sB;
2220 next[x][y] = Xblank;
2221 cave[x][y+1] = Yandroid_s;
2222 next[x][y+1] = Xandroid_1_s;
2223 play_element_sound(x, y, SOUND_android_move, Xandroid_2_s);
2234 cave[x][y] = Yandroid_sB;
2235 next[x][y] = Xblank;
2236 if (cave[x+1][y] == Xblank)
2237 cave[x+1][y] = Xsplash_e;
2238 if (cave[x-1][y] == Xblank)
2239 cave[x-1][y] = Xsplash_w;
2240 play_element_sound(x, y, SOUND_acid, Xacid_1);
2249 static void Landroid_1_w(int x, int y)
2251 switch (cave[x-1][y])
2264 cave[x][y] = Yandroid_wB;
2265 next[x][y] = Xblank;
2266 cave[x-1][y] = Yandroid_w;
2267 next[x-1][y] = Xandroid;
2268 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2279 cave[x][y] = Yandroid_wB;
2280 next[x][y] = Xblank;
2281 if (cave[x][y-1] == Xblank)
2282 cave[x][y-1] = Xsplash_e;
2283 if (cave[x-2][y-1] == Xblank)
2284 cave[x-2][y-1] = Xsplash_w;
2285 play_element_sound(x, y, SOUND_acid, Xacid_1);
2294 static void Landroid_2_w(int x, int y)
2296 switch (cave[x-1][y])
2309 cave[x][y] = Yandroid_wB;
2310 next[x][y] = Xblank;
2311 cave[x-1][y] = Yandroid_w;
2312 next[x-1][y] = Xandroid_1_w;
2313 play_element_sound(x, y, SOUND_android_move, Xandroid_1_w);
2324 cave[x][y] = Yandroid_wB;
2325 next[x][y] = Xblank;
2326 if (cave[x][y-1] == Xblank)
2327 cave[x][y-1] = Xsplash_e;
2328 if (cave[x-2][y-1] == Xblank)
2329 cave[x-2][y-1] = Xsplash_w;
2330 play_element_sound(x, y, SOUND_acid, Xacid_1);
2339 static void Leater_n(int x, int y)
2341 if (cave[x+1][y] == Xdiamond)
2343 cave[x+1][y] = Ydiamond_blank;
2344 next[x+1][y] = Xblank;
2345 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2349 if (cave[x][y+1] == Xdiamond)
2351 cave[x][y+1] = Ydiamond_blank;
2352 next[x][y+1] = Xblank;
2353 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2357 if (cave[x-1][y] == Xdiamond)
2359 cave[x-1][y] = Ydiamond_blank;
2360 next[x-1][y] = Xblank;
2361 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2365 if (cave[x][y-1] == Xdiamond)
2367 cave[x][y-1] = Ydiamond_blank;
2368 next[x][y-1] = Xblank;
2369 play_element_sound(x, y, SOUND_eater_eat, Xeater_n);
2373 switch (cave[x][y-1])
2389 cave[x][y] = Yeater_nB;
2390 next[x][y] = Xblank;
2391 cave[x][y-1] = Yeater_n;
2392 next[x][y-1] = Xeater_n;
2403 cave[x][y] = Yeater_nB;
2404 next[x][y] = Xblank;
2405 if (cave[x+1][y-2] == Xblank)
2406 cave[x+1][y-2] = Xsplash_e;
2407 if (cave[x-1][y-2] == Xblank)
2408 cave[x-1][y-2] = Xsplash_w;
2409 play_element_sound(x, y, SOUND_acid, Xacid_1);
2413 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2414 play_element_sound(x, y, SOUND_eater, Xeater_n);
2419 static void Leater_e(int x, int y)
2421 if (cave[x][y+1] == Xdiamond)
2423 cave[x][y+1] = Ydiamond_blank;
2424 next[x][y+1] = Xblank;
2425 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2429 if (cave[x-1][y] == Xdiamond)
2431 cave[x-1][y] = Ydiamond_blank;
2432 next[x-1][y] = Xblank;
2433 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2437 if (cave[x][y-1] == Xdiamond)
2439 cave[x][y-1] = Ydiamond_blank;
2440 next[x][y-1] = Xblank;
2441 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2445 if (cave[x+1][y] == Xdiamond)
2447 cave[x+1][y] = Ydiamond_blank;
2448 next[x+1][y] = Xblank;
2449 play_element_sound(x, y, SOUND_eater_eat, Xeater_e);
2453 switch (cave[x+1][y])
2469 cave[x][y] = Yeater_eB;
2470 next[x][y] = Xblank;
2471 cave[x+1][y] = Yeater_e;
2472 next[x+1][y] = Xeater_e;
2483 cave[x][y] = Yeater_eB;
2484 next[x][y] = Xblank;
2485 if (cave[x+2][y-1] == Xblank)
2486 cave[x+2][y-1] = Xsplash_e;
2487 if (cave[x][y-1] == Xblank)
2488 cave[x][y-1] = Xsplash_w;
2489 play_element_sound(x, y, SOUND_acid, Xacid_1);
2493 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2494 play_element_sound(x, y, SOUND_eater, Xeater_e);
2499 static void Leater_s(int x, int y)
2501 if (cave[x-1][y] == Xdiamond)
2503 cave[x-1][y] = Ydiamond_blank;
2504 next[x-1][y] = Xblank;
2505 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2509 if (cave[x][y-1] == Xdiamond)
2511 cave[x][y-1] = Ydiamond_blank;
2512 next[x][y-1] = Xblank;
2513 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2517 if (cave[x+1][y] == Xdiamond)
2519 cave[x+1][y] = Ydiamond_blank;
2520 next[x+1][y] = Xblank;
2521 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2525 if (cave[x][y+1] == Xdiamond)
2527 cave[x][y+1] = Ydiamond_blank;
2528 next[x][y+1] = Xblank;
2529 play_element_sound(x, y, SOUND_eater_eat, Xeater_s);
2533 switch (cave[x][y+1])
2549 cave[x][y] = Yeater_sB;
2550 next[x][y] = Xblank;
2551 cave[x][y+1] = Yeater_s;
2552 next[x][y+1] = Xeater_s;
2563 cave[x][y] = Yeater_sB;
2564 next[x][y] = Xblank;
2565 if (cave[x+1][y] == Xblank)
2566 cave[x+1][y] = Xsplash_e;
2567 if (cave[x-1][y] == Xblank)
2568 cave[x-1][y] = Xsplash_w;
2569 play_element_sound(x, y, SOUND_acid, Xacid_1);
2573 next[x][y] = RANDOM(2) ? Xeater_e : Xeater_w;
2574 play_element_sound(x, y, SOUND_eater, Xeater_s);
2579 static void Leater_w(int x, int y)
2581 if (cave[x][y-1] == Xdiamond)
2583 cave[x][y-1] = Ydiamond_blank;
2584 next[x][y-1] = Xblank;
2585 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2589 if (cave[x+1][y] == Xdiamond)
2591 cave[x+1][y] = Ydiamond_blank;
2592 next[x+1][y] = Xblank;
2593 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2597 if (cave[x][y+1] == Xdiamond)
2599 cave[x][y+1] = Ydiamond_blank;
2600 next[x][y+1] = Xblank;
2601 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2605 if (cave[x-1][y] == Xdiamond)
2607 cave[x-1][y] = Ydiamond_blank;
2608 next[x-1][y] = Xblank;
2609 play_element_sound(x, y, SOUND_eater_eat, Xeater_w);
2613 switch (cave[x-1][y])
2629 cave[x][y] = Yeater_wB;
2630 next[x][y] = Xblank;
2631 cave[x-1][y] = Yeater_w;
2632 next[x-1][y] = Xeater_w;
2643 cave[x][y] = Yeater_wB;
2644 next[x][y] = Xblank;
2645 if (cave[x][y-1] == Xblank)
2646 cave[x][y-1] = Xsplash_e;
2647 if (cave[x-2][y-1] == Xblank)
2648 cave[x-2][y-1] = Xsplash_w;
2649 play_element_sound(x, y, SOUND_acid, Xacid_1);
2653 next[x][y] = RANDOM(2) ? Xeater_n : Xeater_s;
2654 play_element_sound(x, y, SOUND_eater, Xeater_w);
2659 static void Lalien(int x, int y)
2670 set_nearest_player_xy(x, y, &dx, &dy);
2677 switch (cave[x][y-1])
2693 cave[x][y] = Yalien_nB;
2694 next[x][y] = Xblank;
2695 cave[x][y-1] = Yalien_n;
2696 next[x][y-1] = Xalien_pause;
2697 play_element_sound(x, y, SOUND_alien, Xalien);
2708 cave[x][y] = Yalien_nB;
2709 next[x][y] = Xblank;
2710 if (cave[x+1][y-2] == Xblank)
2711 cave[x+1][y-2] = Xsplash_e;
2712 if (cave[x-1][y-2] == Xblank)
2713 cave[x-1][y-2] = Xsplash_w;
2714 play_element_sound(x, y, SOUND_acid, Xacid_1);
2720 switch (cave[x][y+1])
2736 cave[x][y] = Yalien_sB;
2737 next[x][y] = Xblank;
2738 cave[x][y+1] = Yalien_s;
2739 next[x][y+1] = Xalien_pause;
2740 play_element_sound(x, y, SOUND_alien, Xalien);
2751 cave[x][y] = Yalien_sB;
2752 next[x][y] = Xblank;
2753 if (cave[x+1][y] == Xblank)
2754 cave[x+1][y] = Xsplash_e;
2755 if (cave[x-1][y] == Xblank)
2756 cave[x-1][y] = Xsplash_w;
2757 play_element_sound(x, y, SOUND_acid, Xacid_1);
2766 switch (cave[x+1][y])
2782 cave[x][y] = Yalien_eB;
2783 next[x][y] = Xblank;
2784 cave[x+1][y] = Yalien_e;
2785 next[x+1][y] = Xalien_pause;
2786 play_element_sound(x, y, SOUND_alien, Xalien);
2797 cave[x][y] = Yalien_eB;
2798 next[x][y] = Xblank;
2799 if (cave[x+2][y-1] == Xblank)
2800 cave[x+2][y-1] = Xsplash_e;
2801 if (cave[x][y-1] == Xblank)
2802 cave[x][y-1] = Xsplash_w;
2803 play_element_sound(x, y, SOUND_acid, Xacid_1);
2809 switch (cave[x-1][y])
2825 cave[x][y] = Yalien_wB;
2826 next[x][y] = Xblank;
2827 cave[x-1][y] = Yalien_w;
2828 next[x-1][y] = Xalien_pause;
2829 play_element_sound(x, y, SOUND_alien, Xalien);
2840 cave[x][y] = Yalien_wB;
2841 next[x][y] = Xblank;
2842 if (cave[x][y-1] == Xblank)
2843 cave[x][y-1] = Xsplash_e;
2844 if (cave[x-2][y-1] == Xblank)
2845 cave[x-2][y-1] = Xsplash_w;
2846 play_element_sound(x, y, SOUND_acid, Xacid_1);
2853 static void Lalien_pause(int x, int y)
2855 next[x][y] = Xalien;
2858 static void Lbug_n(int x, int y)
2860 switch (cave[x][y-1])
2876 cave[x][y] = Ybug_nB;
2877 next[x][y] = Xblank;
2878 cave[x][y-1] = Ybug_n;
2879 next[x][y-1] = Xbug_1_n;
2880 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2891 cave[x][y] = Ybug_nB;
2892 next[x][y] = Xblank;
2893 if (cave[x+1][y-2] == Xblank)
2894 cave[x+1][y-2] = Xsplash_e;
2895 if (cave[x-1][y-2] == Xblank)
2896 cave[x-1][y-2] = Xsplash_w;
2897 play_element_sound(x, y, SOUND_acid, Xacid_1);
2901 cave[x][y] = Ybug_n_w;
2902 next[x][y] = Xbug_2_w;
2903 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2908 static void Lbug_1_n(int x, int y)
2910 if (is_amoeba[cave[x][y-1]] ||
2911 is_amoeba[cave[x+1][y]] ||
2912 is_amoeba[cave[x][y+1]] ||
2913 is_amoeba[cave[x-1][y]])
2921 switch (cave[x+1][y])
2945 cave[x][y] = Ybug_n_e;
2946 next[x][y] = Xbug_2_e;
2947 play_element_sound(x, y, SOUND_bug, Xbug_1_n);
2956 static void Lbug_2_n(int x, int y)
2958 if (is_amoeba[cave[x][y-1]] ||
2959 is_amoeba[cave[x+1][y]] ||
2960 is_amoeba[cave[x][y+1]] ||
2961 is_amoeba[cave[x-1][y]])
2972 static void Lbug_e(int x, int y)
2974 switch (cave[x+1][y])
2990 cave[x][y] = Ybug_eB;
2991 next[x][y] = Xblank;
2992 cave[x+1][y] = Ybug_e;
2993 next[x+1][y] = Xbug_1_e;
2994 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
3005 cave[x][y] = Ybug_eB;
3006 next[x][y] = Xblank;
3007 if (cave[x+2][y-1] == Xblank)
3008 cave[x+2][y-1] = Xsplash_e;
3009 if (cave[x][y-1] == Xblank)
3010 cave[x][y-1] = Xsplash_w;
3011 play_element_sound(x, y, SOUND_acid, Xacid_1);
3015 cave[x][y] = Ybug_e_n;
3016 next[x][y] = Xbug_2_n;
3017 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
3022 static void Lbug_1_e(int x, int y)
3024 if (is_amoeba[cave[x][y-1]] ||
3025 is_amoeba[cave[x+1][y]] ||
3026 is_amoeba[cave[x][y+1]] ||
3027 is_amoeba[cave[x-1][y]])
3035 switch (cave[x][y+1])
3059 cave[x][y] = Ybug_e_s;
3060 next[x][y] = Xbug_2_s;
3061 play_element_sound(x, y, SOUND_bug, Xbug_1_e);
3070 static void Lbug_2_e(int x, int y)
3072 if (is_amoeba[cave[x][y-1]] ||
3073 is_amoeba[cave[x+1][y]] ||
3074 is_amoeba[cave[x][y+1]] ||
3075 is_amoeba[cave[x-1][y]])
3086 static void Lbug_s(int x, int y)
3088 switch (cave[x][y+1])
3104 cave[x][y] = Ybug_sB;
3105 next[x][y] = Xblank;
3106 cave[x][y+1] = Ybug_s;
3107 next[x][y+1] = Xbug_1_s;
3108 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3119 cave[x][y] = Ybug_sB;
3120 next[x][y] = Xblank;
3121 if (cave[x+1][y] == Xblank)
3122 cave[x+1][y] = Xsplash_e;
3123 if (cave[x-1][y] == Xblank)
3124 cave[x-1][y] = Xsplash_w;
3125 play_element_sound(x, y, SOUND_acid, Xacid_1);
3129 cave[x][y] = Ybug_s_e;
3130 next[x][y] = Xbug_2_e;
3131 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3136 static void Lbug_1_s(int x, int y)
3138 if (is_amoeba[cave[x][y-1]] ||
3139 is_amoeba[cave[x+1][y]] ||
3140 is_amoeba[cave[x][y+1]] ||
3141 is_amoeba[cave[x-1][y]])
3149 switch (cave[x-1][y])
3173 cave[x][y] = Ybug_s_w;
3174 next[x][y] = Xbug_2_w;
3175 play_element_sound(x, y, SOUND_bug, Xbug_1_s);
3184 static void Lbug_2_s(int x, int y)
3186 if (is_amoeba[cave[x][y-1]] ||
3187 is_amoeba[cave[x+1][y]] ||
3188 is_amoeba[cave[x][y+1]] ||
3189 is_amoeba[cave[x-1][y]])
3200 static void Lbug_w(int x, int y)
3202 switch (cave[x-1][y])
3218 cave[x][y] = Ybug_wB;
3219 next[x][y] = Xblank;
3220 cave[x-1][y] = Ybug_w;
3221 next[x-1][y] = Xbug_1_w;
3222 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3233 cave[x][y] = Ybug_wB;
3234 next[x][y] = Xblank;
3235 if (cave[x][y-1] == Xblank)
3236 cave[x][y-1] = Xsplash_e;
3237 if (cave[x-2][y-1] == Xblank)
3238 cave[x-2][y-1] = Xsplash_w;
3239 play_element_sound(x, y, SOUND_acid, Xacid_1);
3243 cave[x][y] = Ybug_w_s;
3244 next[x][y] = Xbug_2_s;
3245 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3250 static void Lbug_1_w(int x, int y)
3252 if (is_amoeba[cave[x][y-1]] ||
3253 is_amoeba[cave[x+1][y]] ||
3254 is_amoeba[cave[x][y+1]] ||
3255 is_amoeba[cave[x-1][y]])
3263 switch (cave[x][y-1])
3287 cave[x][y] = Ybug_w_n;
3288 next[x][y] = Xbug_2_n;
3289 play_element_sound(x, y, SOUND_bug, Xbug_1_w);
3298 static void Lbug_2_w(int x, int y)
3300 if (is_amoeba[cave[x][y-1]] ||
3301 is_amoeba[cave[x+1][y]] ||
3302 is_amoeba[cave[x][y+1]] ||
3303 is_amoeba[cave[x-1][y]])
3314 static void Ltank_n(int x, int y)
3316 switch (cave[x][y-1])
3332 cave[x][y] = Ytank_nB;
3333 next[x][y] = Xblank;
3334 cave[x][y-1] = Ytank_n;
3335 next[x][y-1] = Xtank_1_n;
3336 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3347 cave[x][y] = Ytank_nB;
3348 next[x][y] = Xblank;
3349 if (cave[x+1][y-2] == Xblank)
3350 cave[x+1][y-2] = Xsplash_e;
3351 if (cave[x-1][y-2] == Xblank)
3352 cave[x-1][y-2] = Xsplash_w;
3353 play_element_sound(x, y, SOUND_acid, Xacid_1);
3357 cave[x][y] = Ytank_n_e;
3358 next[x][y] = Xtank_2_e;
3359 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3364 static void Ltank_1_n(int x, int y)
3366 if (is_amoeba[cave[x][y-1]] ||
3367 is_amoeba[cave[x+1][y]] ||
3368 is_amoeba[cave[x][y+1]] ||
3369 is_amoeba[cave[x-1][y]])
3377 switch (cave[x-1][y])
3401 cave[x][y] = Ytank_n_w;
3402 next[x][y] = Xtank_2_w;
3403 play_element_sound(x, y, SOUND_tank, Xtank_1_n);
3412 static void Ltank_2_n(int x, int y)
3414 if (is_amoeba[cave[x][y-1]] ||
3415 is_amoeba[cave[x+1][y]] ||
3416 is_amoeba[cave[x][y+1]] ||
3417 is_amoeba[cave[x-1][y]])
3428 static void Ltank_e(int x, int y)
3430 switch (cave[x+1][y])
3446 cave[x][y] = Ytank_eB;
3447 next[x][y] = Xblank;
3448 cave[x+1][y] = Ytank_e;
3449 next[x+1][y] = Xtank_1_e;
3450 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3461 cave[x][y] = Ytank_eB;
3462 next[x][y] = Xblank;
3463 if (cave[x+2][y-1] == Xblank)
3464 cave[x+2][y-1] = Xsplash_e;
3465 if (cave[x][y-1] == Xblank)
3466 cave[x][y-1] = Xsplash_w;
3467 play_element_sound(x, y, SOUND_acid, Xacid_1);
3471 cave[x][y] = Ytank_e_s;
3472 next[x][y] = Xtank_2_s;
3473 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3478 static void Ltank_1_e(int x, int y)
3480 if (is_amoeba[cave[x][y-1]] ||
3481 is_amoeba[cave[x+1][y]] ||
3482 is_amoeba[cave[x][y+1]] ||
3483 is_amoeba[cave[x-1][y]])
3491 switch (cave[x][y-1])
3515 cave[x][y] = Ytank_e_n;
3516 next[x][y] = Xtank_2_n;
3517 play_element_sound(x, y, SOUND_tank, Xtank_1_e);
3526 static void Ltank_2_e(int x, int y)
3528 if (is_amoeba[cave[x][y-1]] ||
3529 is_amoeba[cave[x+1][y]] ||
3530 is_amoeba[cave[x][y+1]] ||
3531 is_amoeba[cave[x-1][y]])
3542 static void Ltank_s(int x, int y)
3544 switch (cave[x][y+1])
3560 cave[x][y] = Ytank_sB;
3561 next[x][y] = Xblank;
3562 cave[x][y+1] = Ytank_s;
3563 next[x][y+1] = Xtank_1_s;
3564 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3575 cave[x][y] = Ytank_sB;
3576 next[x][y] = Xblank;
3577 if (cave[x+1][y] == Xblank)
3578 cave[x+1][y] = Xsplash_e;
3579 if (cave[x-1][y] == Xblank)
3580 cave[x-1][y] = Xsplash_w;
3581 play_element_sound(x, y, SOUND_acid, Xacid_1);
3585 cave[x][y] = Ytank_s_w;
3586 next[x][y] = Xtank_2_w;
3587 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3592 static void Ltank_1_s(int x, int y)
3594 if (is_amoeba[cave[x][y-1]] ||
3595 is_amoeba[cave[x+1][y]] ||
3596 is_amoeba[cave[x][y+1]] ||
3597 is_amoeba[cave[x-1][y]])
3605 switch (cave[x+1][y])
3629 cave[x][y] = Ytank_s_e;
3630 next[x][y] = Xtank_2_e;
3631 play_element_sound(x, y, SOUND_tank, Xtank_1_s);
3640 static void Ltank_2_s(int x, int y)
3642 if (is_amoeba[cave[x][y-1]] ||
3643 is_amoeba[cave[x+1][y]] ||
3644 is_amoeba[cave[x][y+1]] ||
3645 is_amoeba[cave[x-1][y]])
3656 static void Ltank_w(int x, int y)
3658 switch (cave[x-1][y])
3674 cave[x][y] = Ytank_wB;
3675 next[x][y] = Xblank;
3676 cave[x-1][y] = Ytank_w;
3677 next[x-1][y] = Xtank_1_w;
3678 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3689 cave[x][y] = Ytank_wB;
3690 next[x][y] = Xblank;
3691 if (cave[x][y-1] == Xblank)
3692 cave[x][y-1] = Xsplash_e;
3693 if (cave[x-2][y-1] == Xblank)
3694 cave[x-2][y-1] = Xsplash_w;
3695 play_element_sound(x, y, SOUND_acid, Xacid_1);
3699 cave[x][y] = Ytank_w_n;
3700 next[x][y] = Xtank_2_n;
3701 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3706 static void Ltank_1_w(int x, int y)
3708 if (is_amoeba[cave[x][y-1]] ||
3709 is_amoeba[cave[x+1][y]] ||
3710 is_amoeba[cave[x][y+1]] ||
3711 is_amoeba[cave[x-1][y]])
3719 switch (cave[x][y+1])
3743 cave[x][y] = Ytank_w_s;
3744 next[x][y] = Xtank_2_s;
3745 play_element_sound(x, y, SOUND_tank, Xtank_1_w);
3754 static void Ltank_2_w(int x, int y)
3756 if (is_amoeba[cave[x][y-1]] ||
3757 is_amoeba[cave[x+1][y]] ||
3758 is_amoeba[cave[x][y+1]] ||
3759 is_amoeba[cave[x-1][y]])
3770 static void Lemerald(int x, int y)
3772 switch (cave[x][y+1])
3785 cave[x][y] = Yemerald_sB;
3786 next[x][y] = Xblank;
3787 cave[x][y+1] = Yemerald_s;
3788 next[x][y+1] = Xemerald_fall;
3799 cave[x][y] = Yemerald_sB;
3800 next[x][y] = Xblank;
3801 if (cave[x+1][y] == Xblank)
3802 cave[x+1][y] = Xsplash_e;
3803 if (cave[x-1][y] == Xblank)
3804 cave[x-1][y] = Xsplash_w;
3805 play_element_sound(x, y, SOUND_acid, Xacid_1);
3818 case Xemerald_pause:
3820 case Xdiamond_pause:
3864 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3866 cave[x][y] = Yemerald_eB;
3867 next[x][y] = Xblank;
3868 cave[x+1][y] = Yemerald_e;
3869 next[x+1][y] = Xemerald_pause;
3870 if (cave[x][y+1] == Xbumper)
3871 cave[x][y+1] = Ybumper;
3875 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3877 cave[x][y] = Yemerald_wB;
3878 next[x][y] = Xblank;
3879 cave[x-1][y] = Yemerald_w;
3880 next[x-1][y] = Xemerald_pause;
3881 if (cave[x][y+1] == Xbumper)
3882 cave[x][y+1] = Ybumper;
3888 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
3890 cave[x][y] = Yemerald_wB;
3891 next[x][y] = Xblank;
3892 cave[x-1][y] = Yemerald_w;
3893 next[x-1][y] = Xemerald_pause;
3894 if (cave[x][y+1] == Xbumper)
3895 cave[x][y+1] = Ybumper;
3899 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
3901 cave[x][y] = Yemerald_eB;
3902 next[x][y] = Xblank;
3903 cave[x+1][y] = Yemerald_e;
3904 next[x+1][y] = Xemerald_pause;
3905 if (cave[x][y+1] == Xbumper)
3906 cave[x][y+1] = Ybumper;
3912 if (++lev.shine_cnt > 50)
3914 lev.shine_cnt = RANDOM(8);
3915 cave[x][y] = Xemerald_shine;
3922 static void Lemerald_pause(int x, int y)
3924 switch (cave[x][y+1])
3937 cave[x][y] = Yemerald_sB;
3938 next[x][y] = Xblank;
3939 cave[x][y+1] = Yemerald_s;
3940 next[x][y+1] = Xemerald_fall;
3951 cave[x][y] = Yemerald_sB;
3952 next[x][y] = Xblank;
3953 if (cave[x+1][y] == Xblank)
3954 cave[x+1][y] = Xsplash_e;
3955 if (cave[x-1][y] == Xblank)
3956 cave[x-1][y] = Xsplash_w;
3957 play_element_sound(x, y, SOUND_acid, Xacid_1);
3961 cave[x][y] = Xemerald;
3962 next[x][y] = Xemerald;
3967 static void Lemerald_fall(int x, int y)
3969 switch (cave[x][y+1])
3983 cave[x][y] = Yemerald_sB;
3984 next[x][y] = Xblank;
3985 cave[x][y+1] = Yemerald_s;
3986 next[x][y+1] = Xemerald_fall;
3997 cave[x][y] = Yemerald_sB;
3998 next[x][y] = Xblank;
3999 if (cave[x+1][y] == Xblank)
4000 cave[x+1][y] = Xsplash_e;
4001 if (cave[x-1][y] == Xblank)
4002 cave[x-1][y] = Xsplash_w;
4003 play_element_sound(x, y, SOUND_acid, Xacid_1);
4007 if (lev.wonderwall_time > 0)
4009 lev.wonderwall_active = TRUE;
4010 cave[x][y] = Yemerald_sB;
4011 next[x][y] = Xblank;
4012 if (is_blank[cave[x][y+2]])
4014 cave[x][y+2] = Ydiamond_s;
4015 next[x][y+2] = Xdiamond_fall;
4017 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4022 cave[x][y] = Xemerald;
4023 next[x][y] = Xemerald;
4024 play_element_sound(x, y, SOUND_diamond, Xemerald);
4029 static void Ldiamond(int x, int y)
4031 switch (cave[x][y+1])
4044 cave[x][y] = Ydiamond_sB;
4045 next[x][y] = Xblank;
4046 cave[x][y+1] = Ydiamond_s;
4047 next[x][y+1] = Xdiamond_fall;
4058 cave[x][y] = Ydiamond_sB;
4059 next[x][y] = Xblank;
4060 if (cave[x+1][y] == Xblank)
4061 cave[x+1][y] = Xsplash_e;
4062 if (cave[x-1][y] == Xblank)
4063 cave[x-1][y] = Xsplash_w;
4064 play_element_sound(x, y, SOUND_acid, Xacid_1);
4077 case Xemerald_pause:
4079 case Xdiamond_pause:
4123 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4125 cave[x][y] = Ydiamond_eB;
4126 next[x][y] = Xblank;
4127 cave[x+1][y] = Ydiamond_e;
4128 next[x+1][y] = Xdiamond_pause;
4129 if (cave[x][y+1] == Xbumper)
4130 cave[x][y+1] = Ybumper;
4134 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4136 cave[x][y] = Ydiamond_wB;
4137 next[x][y] = Xblank;
4138 cave[x-1][y] = Ydiamond_w;
4139 next[x-1][y] = Xdiamond_pause;
4140 if (cave[x][y+1] == Xbumper)
4141 cave[x][y+1] = Ybumper;
4147 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4149 cave[x][y] = Ydiamond_wB;
4150 next[x][y] = Xblank;
4151 cave[x-1][y] = Ydiamond_w;
4152 next[x-1][y] = Xdiamond_pause;
4153 if (cave[x][y+1] == Xbumper)
4154 cave[x][y+1] = Ybumper;
4158 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4160 cave[x][y] = Ydiamond_eB;
4161 next[x][y] = Xblank;
4162 cave[x+1][y] = Ydiamond_e;
4163 next[x+1][y] = Xdiamond_pause;
4164 if (cave[x][y+1] == Xbumper)
4165 cave[x][y+1] = Ybumper;
4171 if (++lev.shine_cnt > 50)
4173 lev.shine_cnt = RANDOM(8);
4174 cave[x][y] = Xdiamond_shine;
4181 static void Ldiamond_pause(int x, int y)
4183 switch (cave[x][y+1])
4196 cave[x][y] = Ydiamond_sB;
4197 next[x][y] = Xblank;
4198 cave[x][y+1] = Ydiamond_s;
4199 next[x][y+1] = Xdiamond_fall;
4210 cave[x][y] = Ydiamond_sB;
4211 next[x][y] = Xblank;
4212 if (cave[x+1][y] == Xblank)
4213 cave[x+1][y] = Xsplash_e;
4214 if (cave[x-1][y] == Xblank)
4215 cave[x-1][y] = Xsplash_w;
4216 play_element_sound(x, y, SOUND_acid, Xacid_1);
4220 cave[x][y] = Xdiamond;
4221 next[x][y] = Xdiamond;
4226 static void Ldiamond_fall(int x, int y)
4228 switch (cave[x][y+1])
4242 cave[x][y] = Ydiamond_sB;
4243 next[x][y] = Xblank;
4244 cave[x][y+1] = Ydiamond_s;
4245 next[x][y+1] = Xdiamond_fall;
4256 cave[x][y] = Ydiamond_sB;
4257 next[x][y] = Xblank;
4258 if (cave[x+1][y] == Xblank)
4259 cave[x+1][y] = Xsplash_e;
4260 if (cave[x-1][y] == Xblank)
4261 cave[x-1][y] = Xsplash_w;
4262 play_element_sound(x, y, SOUND_acid, Xacid_1);
4266 if (lev.wonderwall_time > 0)
4268 lev.wonderwall_active = TRUE;
4269 cave[x][y] = Ydiamond_sB;
4270 next[x][y] = Xblank;
4271 if (is_blank[cave[x][y+2]])
4273 cave[x][y+2] = Ystone_s;
4274 next[x][y+2] = Xstone_fall;
4276 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4281 cave[x][y] = Xdiamond;
4282 next[x][y] = Xdiamond;
4283 play_element_sound(x, y, SOUND_diamond, Xdiamond);
4288 static void Lstone(int x, int y)
4290 switch (cave[x][y+1])
4305 cave[x][y] = Ystone_sB;
4306 next[x][y] = Xblank;
4307 cave[x][y+1] = Ystone_s;
4308 next[x][y+1] = Xstone_fall;
4319 cave[x][y] = Ystone_sB;
4320 next[x][y] = Xblank;
4321 if (cave[x+1][y] == Xblank)
4322 cave[x+1][y] = Xsplash_e;
4323 if (cave[x-1][y] == Xblank)
4324 cave[x-1][y] = Xsplash_w;
4325 play_element_sound(x, y, SOUND_acid, Xacid_1);
4329 cave[x][y] = Xsand_stonein_1;
4330 next[x][y] = Xsand_stonein_2;
4331 cave[x][y+1] = Xsand_sandstone_1;
4332 next[x][y+1] = Xsand_sandstone_2;
4345 case Xemerald_pause:
4347 case Xdiamond_pause:
4384 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4386 cave[x][y] = Ystone_eB;
4387 next[x][y] = Xblank;
4388 cave[x+1][y] = Ystone_e;
4389 next[x+1][y] = Xstone_pause;
4390 if (cave[x][y+1] == Xbumper)
4391 cave[x][y+1] = Ybumper;
4395 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4397 cave[x][y] = Ystone_wB;
4398 next[x][y] = Xblank;
4399 cave[x-1][y] = Ystone_w;
4400 next[x-1][y] = Xstone_pause;
4401 if (cave[x][y+1] == Xbumper)
4402 cave[x][y+1] = Ybumper;
4408 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4410 cave[x][y] = Ystone_wB;
4411 next[x][y] = Xblank;
4412 cave[x-1][y] = Ystone_w;
4413 next[x-1][y] = Xstone_pause;
4414 if (cave[x][y+1] == Xbumper)
4415 cave[x][y+1] = Ybumper;
4419 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4421 cave[x][y] = Ystone_eB;
4422 next[x][y] = Xblank;
4423 cave[x+1][y] = Ystone_e;
4424 next[x+1][y] = Xstone_pause;
4425 if (cave[x][y+1] == Xbumper)
4426 cave[x][y+1] = Ybumper;
4433 static void Lstone_pause(int x, int y)
4435 switch (cave[x][y+1])
4448 cave[x][y] = Ystone_sB;
4449 next[x][y] = Xblank;
4450 cave[x][y+1] = Ystone_s;
4451 next[x][y+1] = Xstone_fall;
4462 cave[x][y] = Ystone_sB;
4463 next[x][y] = Xblank;
4464 if (cave[x+1][y] == Xblank)
4465 cave[x+1][y] = Xsplash_e;
4466 if (cave[x-1][y] == Xblank)
4467 cave[x-1][y] = Xsplash_w;
4468 play_element_sound(x, y, SOUND_acid, Xacid_1);
4472 cave[x][y] = Xstone;
4473 next[x][y] = Xstone;
4478 static void Lstone_fall(int x, int y)
4480 switch (cave[x][y+1])
4494 cave[x][y] = Ystone_sB;
4495 next[x][y] = Xblank;
4496 cave[x][y+1] = Ystone_s;
4497 next[x][y+1] = Xstone_fall;
4508 cave[x][y] = Ystone_sB;
4509 next[x][y] = Xblank;
4510 if (cave[x+1][y] == Xblank)
4511 cave[x+1][y] = Xsplash_e;
4512 if (cave[x-1][y] == Xblank)
4513 cave[x-1][y] = Xsplash_w;
4514 play_element_sound(x, y, SOUND_acid, Xacid_1);
4521 cave[x][y] = Ystone_sB;
4522 Lboom_next_new(x, y, Xblank);
4523 cave[x][y+1] = Yeater_stone;
4524 next[x][y+1] = Zeater;
4525 Lboom_eater_old(x, y+1);
4526 score += lev.eater_score;
4531 cave[x][y] = Ystone_sB;
4532 Lboom_next_new(x, y, Xblank);
4533 cave[x][y+1] = Yalien_stone;
4534 next[x][y+1] = Ztank;
4535 Lboom_tank_old(x, y+1);
4536 score += lev.alien_score;
4547 cave[x][y] = Ystone_sB;
4548 Lboom_next_new(x, y, Xblank);
4549 cave[x][y+1] = Ybug_stone;
4550 next[x][y+1] = Zbug;
4551 Lboom_bug_old(x, y+1);
4552 score += lev.bug_score;
4563 cave[x][y] = Ystone_sB;
4564 Lboom_next_new(x, y, Xblank);
4565 cave[x][y+1] = Ytank_stone;
4566 next[x][y+1] = Ztank;
4567 Lboom_tank_old(x, y+1);
4568 score += lev.tank_score;
4572 case Xdiamond_pause:
4573 switch (cave[x][y+2])
4629 next[x][y] = Xstone;
4630 play_element_sound(x, y, SOUND_stone, Xstone);
4634 cave[x][y] = Ystone_sB;
4635 next[x][y] = Xblank;
4636 cave[x][y+1] = Ydiamond_stone;
4637 next[x][y+1] = Xstone_pause;
4638 play_element_sound(x, y, SOUND_squash, Xdiamond);
4643 Lboom_cave_new(x, y, Xstone);
4644 Lboom_next_new(x, y, Xstone);
4645 cave[x][y+1] = Ybomb_blank;
4646 next[x][y+1] = Ztank;
4647 Lboom_tank_old(x, y+1);
4652 next[x][y] = Xstone;
4653 cave[x][y+1] = Ynut_stone;
4654 next[x][y+1] = Xemerald;
4655 play_element_sound(x, y, SOUND_crack, Xnut);
4656 score += lev.nut_score;
4662 switch (cave[x+1][y+1])
4677 cave[x][y+1] = Xspring_e;
4681 cave[x][y+1] = Xspring_w;
4687 switch (cave[x-1][y+1])
4702 cave[x][y+1] = Xspring_w;
4705 cave[x][y+1] = Xspring_e;
4710 next[x][y] = Xstone;
4714 if (lev.wonderwall_time > 0)
4716 lev.wonderwall_active = TRUE;
4717 cave[x][y] = Ystone_sB;
4718 next[x][y] = Xblank;
4719 if (is_blank[cave[x][y+2]])
4721 cave[x][y+2] = Yemerald_s;
4722 next[x][y+2] = Xemerald_fall;
4724 play_element_sound(x, y, SOUND_wonderfall, Xwonderwall);
4729 cave[x][y] = Xstone;
4730 next[x][y] = Xstone;
4731 play_element_sound(x, y, SOUND_stone, Xstone);
4736 static void Lbomb(int x, int y)
4738 switch (cave[x][y+1])
4751 cave[x][y] = Ybomb_sB;
4752 next[x][y] = Xblank;
4753 cave[x][y+1] = Ybomb_s;
4754 next[x][y+1] = Xbomb_fall;
4765 cave[x][y] = Ybomb_sB;
4766 next[x][y] = Xblank;
4767 if (cave[x+1][y] == Xblank)
4768 cave[x+1][y] = Xsplash_e;
4769 if (cave[x-1][y] == Xblank)
4770 cave[x-1][y] = Xsplash_w;
4771 play_element_sound(x, y, SOUND_acid, Xacid_1);
4784 case Xemerald_pause:
4786 case Xdiamond_pause:
4821 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4823 cave[x][y] = Ybomb_eB;
4824 next[x][y] = Xblank;
4825 cave[x+1][y] = Ybomb_e;
4826 next[x+1][y] = Xbomb_pause;
4827 if (cave[x][y+1] == Xbumper)
4828 cave[x][y+1] = Ybumper;
4832 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4834 cave[x][y] = Ybomb_wB;
4835 next[x][y] = Xblank;
4836 cave[x-1][y] = Ybomb_w;
4837 next[x-1][y] = Xbomb_pause;
4838 if (cave[x][y+1] == Xbumper)
4839 cave[x][y+1] = Ybumper;
4845 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
4847 cave[x][y] = Ybomb_wB;
4848 next[x][y] = Xblank;
4849 cave[x-1][y] = Ybomb_w;
4850 next[x-1][y] = Xbomb_pause;
4851 if (cave[x][y+1] == Xbumper)
4852 cave[x][y+1] = Ybumper;
4856 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
4858 cave[x][y] = Ybomb_eB;
4859 next[x][y] = Xblank;
4860 cave[x+1][y] = Ybomb_e;
4861 next[x+1][y] = Xbomb_pause;
4862 if (cave[x][y+1] == Xbumper)
4863 cave[x][y+1] = Ybumper;
4870 static void Lbomb_pause(int x, int y)
4872 switch (cave[x][y+1])
4885 cave[x][y] = Ybomb_sB;
4886 next[x][y] = Xblank;
4887 cave[x][y+1] = Ybomb_s;
4888 next[x][y+1] = Xbomb_fall;
4899 cave[x][y] = Ybomb_sB;
4900 next[x][y] = Xblank;
4901 if (cave[x+1][y] == Xblank)
4902 cave[x+1][y] = Xsplash_e;
4903 if (cave[x-1][y] == Xblank)
4904 cave[x-1][y] = Xsplash_w;
4905 play_element_sound(x, y, SOUND_acid, Xacid_1);
4915 static void Lbomb_fall(int x, int y)
4917 switch (cave[x][y+1])
4930 cave[x][y] = Ybomb_sB;
4931 next[x][y] = Xblank;
4932 cave[x][y+1] = Ybomb_s;
4933 next[x][y+1] = Xbomb_fall;
4944 cave[x][y] = Ybomb_sB;
4945 next[x][y] = Xblank;
4946 if (cave[x+1][y] == Xblank)
4947 cave[x+1][y] = Xsplash_e;
4948 if (cave[x-1][y] == Xblank)
4949 cave[x-1][y] = Xsplash_w;
4950 play_element_sound(x, y, SOUND_acid, Xacid_1);
4954 cave[x][y] = Ybomb_blank;
4956 Lboom_tank_old(x, y);
4961 static void Lnut(int x, int y)
4963 switch (cave[x][y+1])
4976 cave[x][y] = Ynut_sB;
4977 next[x][y] = Xblank;
4978 cave[x][y+1] = Ynut_s;
4979 next[x][y+1] = Xnut_fall;
4990 cave[x][y] = Ynut_sB;
4991 next[x][y] = Xblank;
4992 if (cave[x+1][y] == Xblank)
4993 cave[x+1][y] = Xsplash_e;
4994 if (cave[x-1][y] == Xblank)
4995 cave[x-1][y] = Xsplash_w;
4996 play_element_sound(x, y, SOUND_acid, Xacid_1);
5009 case Xemerald_pause:
5011 case Xdiamond_pause:
5046 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5048 cave[x][y] = Ynut_eB;
5049 next[x][y] = Xblank;
5050 cave[x+1][y] = Ynut_e;
5051 next[x+1][y] = Xnut_pause;
5052 if (cave[x][y+1] == Xbumper)
5053 cave[x][y+1] = Ybumper;
5057 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5059 cave[x][y] = Ynut_wB;
5060 next[x][y] = Xblank;
5061 cave[x-1][y] = Ynut_w;
5062 next[x-1][y] = Xnut_pause;
5063 if (cave[x][y+1] == Xbumper)
5064 cave[x][y+1] = Ybumper;
5070 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5072 cave[x][y] = Ynut_wB;
5073 next[x][y] = Xblank;
5074 cave[x-1][y] = Ynut_w;
5075 next[x-1][y] = Xnut_pause;
5076 if (cave[x][y+1] == Xbumper)
5077 cave[x][y+1] = Ybumper;
5081 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5083 cave[x][y] = Ynut_eB;
5084 next[x][y] = Xblank;
5085 cave[x+1][y] = Ynut_e;
5086 next[x+1][y] = Xnut_pause;
5087 if (cave[x][y+1] == Xbumper)
5088 cave[x][y+1] = Ybumper;
5095 static void Lnut_pause(int x, int y)
5097 switch (cave[x][y+1])
5110 cave[x][y] = Ynut_sB;
5111 next[x][y] = Xblank;
5112 cave[x][y+1] = Ynut_s;
5113 next[x][y+1] = Xnut_fall;
5124 cave[x][y] = Ynut_sB;
5125 next[x][y] = Xblank;
5126 if (cave[x+1][y] == Xblank)
5127 cave[x+1][y] = Xsplash_e;
5128 if (cave[x-1][y] == Xblank)
5129 cave[x-1][y] = Xsplash_w;
5130 play_element_sound(x, y, SOUND_acid, Xacid_1);
5140 static void Lnut_fall(int x, int y)
5142 switch (cave[x][y+1])
5156 cave[x][y] = Ynut_sB;
5157 next[x][y] = Xblank;
5158 cave[x][y+1] = Ynut_s;
5159 next[x][y+1] = Xnut_fall;
5170 cave[x][y] = Ynut_sB;
5171 next[x][y] = Xblank;
5172 if (cave[x+1][y] == Xblank)
5173 cave[x+1][y] = Xsplash_e;
5174 if (cave[x-1][y] == Xblank)
5175 cave[x-1][y] = Xsplash_w;
5176 play_element_sound(x, y, SOUND_acid, Xacid_1);
5182 play_element_sound(x, y, SOUND_nut, Xnut);
5187 static void Lspring(int x, int y)
5189 switch (cave[x][y+1])
5204 cave[x][y] = Yspring_sB;
5205 next[x][y] = Xblank;
5206 cave[x][y+1] = Yspring_s;
5207 next[x][y+1] = Xspring_fall;
5218 cave[x][y] = Yspring_sB;
5219 next[x][y] = Xblank;
5220 if (cave[x+1][y] == Xblank)
5221 cave[x+1][y] = Xsplash_e;
5222 if (cave[x-1][y] == Xblank)
5223 cave[x-1][y] = Xsplash_w;
5224 play_element_sound(x, y, SOUND_acid, Xacid_1);
5237 case Xemerald_pause:
5239 case Xdiamond_pause:
5274 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5276 cave[x][y] = Yspring_eB;
5277 next[x][y] = Xblank;
5278 cave[x+1][y] = Yspring_e;
5280 next[x+1][y] = Xspring_e;
5282 next[x+1][y] = Xspring_pause;
5284 if (cave[x][y+1] == Xbumper)
5285 cave[x][y+1] = Ybumper;
5289 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5291 cave[x][y] = Yspring_wB;
5292 next[x][y] = Xblank;
5293 cave[x-1][y] = Yspring_w;
5295 next[x-1][y] = Xspring_w;
5297 next[x-1][y] = Xspring_pause;
5299 if (cave[x][y+1] == Xbumper)
5300 cave[x][y+1] = Ybumper;
5306 if (is_blank[cave[x-1][y]] && is_blank_or_acid[cave[x-1][y+1]])
5308 cave[x][y] = Yspring_wB;
5309 next[x][y] = Xblank;
5310 cave[x-1][y] = Yspring_w;
5312 next[x-1][y] = Xspring_w;
5314 next[x-1][y] = Xspring_pause;
5316 if (cave[x][y+1] == Xbumper)
5317 cave[x][y+1] = Ybumper;
5321 if (is_blank[cave[x+1][y]] && is_blank_or_acid[cave[x+1][y+1]])
5323 cave[x][y] = Yspring_eB;
5324 next[x][y] = Xblank;
5325 cave[x+1][y] = Yspring_e;
5327 next[x+1][y] = Xspring_e;
5329 next[x+1][y] = Xspring_pause;
5331 if (cave[x][y+1] == Xbumper)
5332 cave[x][y+1] = Ybumper;
5339 static void Lspring_pause(int x, int y)
5341 switch (cave[x][y+1])
5354 cave[x][y] = Yspring_sB;
5355 next[x][y] = Xblank;
5356 cave[x][y+1] = Yspring_s;
5357 next[x][y+1] = Xspring_fall;
5368 cave[x][y] = Yspring_sB;
5369 next[x][y] = Xblank;
5370 if (cave[x+1][y] == Xblank)
5371 cave[x+1][y] = Xsplash_e;
5372 if (cave[x-1][y] == Xblank)
5373 cave[x-1][y] = Xsplash_w;
5374 play_element_sound(x, y, SOUND_acid, Xacid_1);
5378 cave[x][y] = Xspring;
5379 next[x][y] = Xspring;
5384 static void Lspring_e(int x, int y)
5386 switch (cave[x][y+1])
5399 cave[x][y] = Yspring_sB;
5400 next[x][y] = Xblank;
5401 cave[x][y+1] = Yspring_s;
5402 next[x][y+1] = Xspring_fall;
5413 cave[x][y] = Yspring_sB;
5414 next[x][y] = Xblank;
5415 if (cave[x+1][y] == Xblank)
5416 cave[x+1][y] = Xsplash_e;
5417 if (cave[x-1][y] == Xblank)
5418 cave[x-1][y] = Xsplash_w;
5419 play_element_sound(x, y, SOUND_acid, Xacid_1);
5423 cave[x][y+1] = Ybumper;
5426 switch (cave[x+1][y])
5443 cave[x][y] = Yspring_eB;
5444 next[x][y] = Xblank;
5445 cave[x+1][y] = Yspring_e;
5446 next[x+1][y] = Xspring_e;
5457 cave[x][y] = Yspring_eB;
5458 next[x][y] = Xblank;
5459 if (cave[x+2][y-1] == Xblank)
5460 cave[x+2][y-1] = Xsplash_e;
5461 if (cave[x][y-1] == Xblank)
5462 cave[x][y-1] = Xsplash_w;
5463 play_element_sound(x, y, SOUND_acid, Xacid_1);
5472 cave[x][y] = Yspring_alien_eB;
5473 next[x][y] = Xblank;
5474 cave[x+1][y] = Yspring_alien_e;
5475 next[x+1][y] = Xspring_e;
5476 play_element_sound(x, y, SOUND_slurp, Xalien);
5477 score += lev.slurp_score;
5482 cave[x+1][y] = Ybumper;
5483 next[x][y] = Xspring_w;
5484 play_element_sound(x, y, SOUND_spring, Xspring);
5488 cave[x][y] = Xspring;
5489 next[x][y] = Xspring;
5490 play_element_sound(x, y, SOUND_spring, Xspring);
5495 static void Lspring_w(int x, int y)
5497 switch (cave[x][y+1])
5510 cave[x][y] = Yspring_sB;
5511 next[x][y] = Xblank;
5512 cave[x][y+1] = Yspring_s;
5513 next[x][y+1] = Xspring_fall;
5524 cave[x][y] = Yspring_sB;
5525 next[x][y] = Xblank;
5526 if (cave[x+1][y] == Xblank)
5527 cave[x+1][y] = Xsplash_e;
5528 if (cave[x-1][y] == Xblank)
5529 cave[x-1][y] = Xsplash_w;
5530 play_element_sound(x, y, SOUND_acid, Xacid_1);
5534 cave[x][y+1] = Ybumper;
5537 switch (cave[x-1][y])
5554 cave[x][y] = Yspring_wB;
5555 next[x][y] = Xblank;
5556 cave[x-1][y] = Yspring_w;
5557 next[x-1][y] = Xspring_w;
5568 cave[x][y] = Yspring_wB;
5569 next[x][y] = Xblank;
5570 if (cave[x][y-1] == Xblank)
5571 cave[x][y-1] = Xsplash_e;
5572 if (cave[x-2][y-1] == Xblank)
5573 cave[x-2][y-1] = Xsplash_w;
5574 play_element_sound(x, y, SOUND_acid, Xacid_1);
5583 cave[x][y] = Yspring_alien_wB;
5584 next[x][y] = Xblank;
5585 cave[x-1][y] = Yspring_alien_w;
5586 next[x-1][y] = Xspring_w;
5587 play_element_sound(x, y, SOUND_slurp, Xalien);
5588 score += lev.slurp_score;
5593 cave[x-1][y] = Ybumper;
5594 next[x][y] = Xspring_e;
5595 play_element_sound(x, y, SOUND_spring, Xspring);
5599 cave[x][y] = Xspring;
5600 next[x][y] = Xspring;
5601 play_element_sound(x, y, SOUND_spring, Xspring);
5606 static void Lspring_fall(int x, int y)
5608 switch (cave[x][y+1])
5622 cave[x][y] = Yspring_sB;
5623 next[x][y] = Xblank;
5624 cave[x][y+1] = Yspring_s;
5625 next[x][y+1] = Xspring_fall;
5636 cave[x][y] = Yspring_sB;
5637 next[x][y] = Xblank;
5638 if (cave[x+1][y] == Xblank)
5639 cave[x+1][y] = Xsplash_e;
5640 if (cave[x-1][y] == Xblank)
5641 cave[x-1][y] = Xsplash_w;
5642 play_element_sound(x, y, SOUND_acid, Xacid_1);
5649 cave[x][y] = Yspring_sB;
5650 next[x][y] = Xblank;
5651 cave[x][y+1] = Yeater_spring;
5652 next[x][y+1] = Zeater;
5653 Lboom_eater_old(x, y+1);
5654 score += lev.eater_score;
5659 cave[x][y] = Yspring_sB;
5660 next[x][y] = Xblank;
5661 cave[x][y+1] = Yalien_spring;
5662 next[x][y+1] = Ztank;
5663 Lboom_tank_old(x, y+1);
5664 score += lev.alien_score;
5675 cave[x][y] = Yspring_sB;
5676 next[x][y] = Xblank;
5677 cave[x][y+1] = Ybug_spring;
5678 next[x][y+1] = Zbug;
5679 Lboom_bug_old(x, y+1);
5680 score += lev.bug_score;
5691 cave[x][y] = Yspring_sB;
5692 next[x][y] = Xblank;
5693 cave[x][y+1] = Ytank_spring;
5694 next[x][y+1] = Ztank;
5695 Lboom_tank_old(x, y+1);
5696 score += lev.tank_score;
5701 cave[x][y] = Xspring;
5702 next[x][y] = Xspring;
5703 cave[x][y+1] = Ybomb_blank;
5704 next[x][y+1] = Ztank;
5705 Lboom_tank_old(x, y+1);
5709 cave[x][y] = Xspring;
5710 next[x][y] = Xspring;
5711 play_element_sound(x, y, SOUND_spring, Xspring);
5716 static void Lpush_emerald_e(int x, int y)
5718 cave[x][y] = Yemerald_eB;
5719 next[x][y] = Xblank;
5721 switch (cave[x+1][y])
5724 if (!game_em.use_old_push_elements)
5737 Lpush_element_old(x, y, Xemerald);
5749 if (game_em.use_old_push_into_acid)
5751 if (cave[x+2][y-1] == Xblank)
5752 cave[x+2][y-1] = Xsplash_e;
5753 if (cave[x][y-1] == Xblank)
5754 cave[x][y-1] = Xsplash_w;
5755 play_element_sound(x, y, SOUND_acid, Xacid_1);
5760 cave[x+1][y] = Yemerald_e;
5761 next[x+1][y] = Xemerald_pause;
5764 static void Lpush_emerald_w(int x, int y)
5766 cave[x][y] = Yemerald_wB;
5767 next[x][y] = Xblank;
5769 switch (cave[x-1][y])
5772 if (!game_em.use_old_push_elements)
5785 Lpush_element_old(x, y, Xemerald);
5797 if (game_em.use_old_push_into_acid)
5799 if (cave[x][y-1] == Xblank)
5800 cave[x][y-1] = Xsplash_e;
5801 if (cave[x-2][y-1] == Xblank)
5802 cave[x-2][y-1] = Xsplash_w;
5803 play_element_sound(x, y, SOUND_acid, Xacid_1);
5808 cave[x-1][y] = Yemerald_w;
5809 next[x-1][y] = Xemerald_pause;
5812 static void Lpush_diamond_e(int x, int y)
5814 cave[x][y] = Ydiamond_eB;
5815 next[x][y] = Xblank;
5817 switch (cave[x+1][y])
5820 if (!game_em.use_old_push_elements)
5833 Lpush_element_old(x, y, Xdiamond);
5845 if (game_em.use_old_push_into_acid)
5847 if (cave[x+2][y-1] == Xblank)
5848 cave[x+2][y-1] = Xsplash_e;
5849 if (cave[x][y-1] == Xblank)
5850 cave[x][y-1] = Xsplash_w;
5851 play_element_sound(x, y, SOUND_acid, Xacid_1);
5856 cave[x+1][y] = Ydiamond_e;
5857 next[x+1][y] = Xdiamond_pause;
5860 static void Lpush_diamond_w(int x, int y)
5862 cave[x][y] = Ydiamond_wB;
5863 next[x][y] = Xblank;
5865 switch (cave[x-1][y])
5868 if (!game_em.use_old_push_elements)
5881 Lpush_element_old(x, y, Xdiamond);
5893 if (game_em.use_old_push_into_acid)
5895 if (cave[x][y-1] == Xblank)
5896 cave[x][y-1] = Xsplash_e;
5897 if (cave[x-2][y-1] == Xblank)
5898 cave[x-2][y-1] = Xsplash_w;
5899 play_element_sound(x, y, SOUND_acid, Xacid_1);
5904 cave[x-1][y] = Ydiamond_w;
5905 next[x-1][y] = Xdiamond_pause;
5908 static void Lpush_stone_e(int x, int y)
5910 cave[x][y] = Ystone_eB;
5911 next[x][y] = Xblank;
5913 switch (cave[x+1][y])
5916 if (!game_em.use_old_push_elements)
5929 Lpush_element_old(x, y, Xstone);
5941 if (game_em.use_old_push_into_acid)
5943 if (cave[x+2][y-1] == Xblank)
5944 cave[x+2][y-1] = Xsplash_e;
5945 if (cave[x][y-1] == Xblank)
5946 cave[x][y-1] = Xsplash_w;
5947 play_element_sound(x, y, SOUND_acid, Xacid_1);
5952 cave[x+1][y] = Ystone_e;
5953 next[x+1][y] = Xstone_pause;
5956 static void Lpush_stone_w(int x, int y)
5958 cave[x][y] = Ystone_wB;
5959 next[x][y] = Xblank;
5961 switch (cave[x-1][y])
5964 if (!game_em.use_old_push_elements)
5977 Lpush_element_old(x, y, Xstone);
5989 if (game_em.use_old_push_into_acid)
5991 if (cave[x][y-1] == Xblank)
5992 cave[x][y-1] = Xsplash_e;
5993 if (cave[x-2][y-1] == Xblank)
5994 cave[x-2][y-1] = Xsplash_w;
5995 play_element_sound(x, y, SOUND_acid, Xacid_1);
6000 cave[x-1][y] = Ystone_w;
6001 next[x-1][y] = Xstone_pause;
6004 static void Lpush_bomb_e(int x, int y)
6006 cave[x][y] = Ybomb_eB;
6007 next[x][y] = Xblank;
6009 switch (cave[x+1][y])
6012 if (!game_em.use_old_push_elements)
6025 Lpush_element_old(x, y, Xbomb);
6037 if (game_em.use_old_push_into_acid)
6039 if (cave[x+2][y-1] == Xblank)
6040 cave[x+2][y-1] = Xsplash_e;
6041 if (cave[x][y-1] == Xblank)
6042 cave[x][y-1] = Xsplash_w;
6043 play_element_sound(x, y, SOUND_acid, Xacid_1);
6048 cave[x+1][y] = Ybomb_e;
6049 next[x+1][y] = Xbomb_pause;
6052 static void Lpush_bomb_w(int x, int y)
6054 cave[x][y] = Ybomb_wB;
6055 next[x][y] = Xblank;
6057 switch (cave[x-1][y])
6060 if (!game_em.use_old_push_elements)
6073 Lpush_element_old(x, y, Xbomb);
6085 if (game_em.use_old_push_into_acid)
6087 if (cave[x][y-1] == Xblank)
6088 cave[x][y-1] = Xsplash_e;
6089 if (cave[x-2][y-1] == Xblank)
6090 cave[x-2][y-1] = Xsplash_w;
6091 play_element_sound(x, y, SOUND_acid, Xacid_1);
6096 cave[x-1][y] = Ybomb_w;
6097 next[x-1][y] = Xbomb_pause;
6100 static void Lpush_nut_e(int x, int y)
6102 cave[x][y] = Ynut_eB;
6103 next[x][y] = Xblank;
6105 switch (cave[x+1][y])
6108 if (!game_em.use_old_push_elements)
6121 Lpush_element_old(x, y, Xnut);
6133 if (game_em.use_old_push_into_acid)
6135 if (cave[x+2][y-1] == Xblank)
6136 cave[x+2][y-1] = Xsplash_e;
6137 if (cave[x][y-1] == Xblank)
6138 cave[x][y-1] = Xsplash_w;
6139 play_element_sound(x, y, SOUND_acid, Xacid_1);
6144 cave[x+1][y] = Ynut_e;
6145 next[x+1][y] = Xnut_pause;
6148 static void Lpush_nut_w(int x, int y)
6150 cave[x][y] = Ynut_wB;
6151 next[x][y] = Xblank;
6153 switch (cave[x-1][y])
6156 if (!game_em.use_old_push_elements)
6169 Lpush_element_old(x, y, Xnut);
6181 if (game_em.use_old_push_into_acid)
6183 if (cave[x][y-1] == Xblank)
6184 cave[x][y-1] = Xsplash_e;
6185 if (cave[x-2][y-1] == Xblank)
6186 cave[x-2][y-1] = Xsplash_w;
6187 play_element_sound(x, y, SOUND_acid, Xacid_1);
6192 cave[x-1][y] = Ynut_w;
6193 next[x-1][y] = Xnut_pause;
6196 static void Lpush_spring_e(int x, int y)
6198 cave[x][y] = Yspring_eB;
6199 next[x][y] = Xblank;
6201 switch (cave[x+1][y])
6204 if (!game_em.use_old_push_elements)
6217 Lpush_element_old(x, y, Xspring);
6229 if (game_em.use_old_push_into_acid)
6231 if (cave[x+2][y-1] == Xblank)
6232 cave[x+2][y-1] = Xsplash_e;
6233 if (cave[x][y-1] == Xblank)
6234 cave[x][y-1] = Xsplash_w;
6235 play_element_sound(x, y, SOUND_acid, Xacid_1);
6240 cave[x+1][y] = Yspring_e;
6241 next[x+1][y] = Xspring_e;
6244 static void Lpush_spring_w(int x, int y)
6246 cave[x][y] = Yspring_wB;
6247 next[x][y] = Xblank;
6249 switch (cave[x-1][y])
6252 if (!game_em.use_old_push_elements)
6265 Lpush_element_old(x, y, Xspring);
6277 if (game_em.use_old_push_into_acid)
6279 if (cave[x][y-1] == Xblank)
6280 cave[x][y-1] = Xsplash_e;
6281 if (cave[x-2][y-1] == Xblank)
6282 cave[x-2][y-1] = Xsplash_w;
6283 play_element_sound(x, y, SOUND_acid, Xacid_1);
6288 cave[x-1][y] = Yspring_w;
6289 next[x-1][y] = Xspring_w;
6292 static void Ldynamite_1(int x, int y)
6294 play_element_sound(x, y, SOUND_tick, Xdynamite_1);
6295 next[x][y] = Xdynamite_2;
6298 static void Ldynamite_2(int x, int y)
6300 play_element_sound(x, y, SOUND_tick, Xdynamite_2);
6301 next[x][y] = Xdynamite_3;
6304 static void Ldynamite_3(int x, int y)
6306 play_element_sound(x, y, SOUND_tick, Xdynamite_3);
6307 next[x][y] = Xdynamite_4;
6310 static void Ldynamite_4(int x, int y)
6312 play_element_sound(x, y, SOUND_tick, Xdynamite_4);
6313 next[x][y] = Zdynamite;
6315 Lboom_generic(x, y, Xblank, Xblank);
6318 static void Lfake_door_1(int x, int y)
6320 if (lev.magnify_cnt)
6321 cave[x][y] = Xdoor_1;
6324 static void Lfake_door_2(int x, int y)
6326 if (lev.magnify_cnt)
6327 cave[x][y] = Xdoor_2;
6330 static void Lfake_door_3(int x, int y)
6332 if (lev.magnify_cnt)
6333 cave[x][y] = Xdoor_3;
6336 static void Lfake_door_4(int x, int y)
6338 if (lev.magnify_cnt)
6339 cave[x][y] = Xdoor_4;
6342 static void Lfake_door_5(int x, int y)
6344 if (lev.magnify_cnt)
6345 cave[x][y] = Xdoor_5;
6348 static void Lfake_door_6(int x, int y)
6350 if (lev.magnify_cnt)
6351 cave[x][y] = Xdoor_6;
6354 static void Lfake_door_7(int x, int y)
6356 if (lev.magnify_cnt)
6357 cave[x][y] = Xdoor_7;
6360 static void Lfake_door_8(int x, int y)
6362 if (lev.magnify_cnt)
6363 cave[x][y] = Xdoor_8;
6366 static void Lballoon(int x, int y)
6368 if (lev.wind_cnt == 0)
6371 switch (lev.wind_direction)
6374 switch (cave[x][y-1])
6387 cave[x][y] = Yballoon_nB;
6388 next[x][y] = Xblank;
6389 cave[x][y-1] = Yballoon_n;
6390 next[x][y-1] = Xballoon;
6401 cave[x][y] = Yballoon_nB;
6402 next[x][y] = Xblank;
6403 if (cave[x+1][y-2] == Xblank)
6404 cave[x+1][y-2] = Xsplash_e;
6405 if (cave[x-1][y-2] == Xblank)
6406 cave[x-1][y-2] = Xsplash_w;
6407 play_element_sound(x, y, SOUND_acid, Xacid_1);
6413 switch (cave[x+1][y])
6426 cave[x][y] = Yballoon_eB;
6427 next[x][y] = Xblank;
6428 cave[x+1][y] = Yballoon_e;
6429 next[x+1][y] = Xballoon;
6440 cave[x][y] = Yballoon_eB;
6441 next[x][y] = Xblank;
6442 if (cave[x+2][y-1] == Xblank)
6443 cave[x+2][y-1] = Xsplash_e;
6444 if (cave[x][y-1] == Xblank)
6445 cave[x][y-1] = Xsplash_w;
6446 play_element_sound(x, y, SOUND_acid, Xacid_1);
6452 switch (cave[x][y+1])
6465 cave[x][y] = Yballoon_sB;
6466 next[x][y] = Xblank;
6467 cave[x][y+1] = Yballoon_s;
6468 next[x][y+1] = Xballoon;
6479 cave[x][y] = Yballoon_sB;
6480 next[x][y] = Xblank;
6481 if (cave[x+1][y] == Xblank)
6482 cave[x+1][y] = Xsplash_e;
6483 if (cave[x-1][y] == Xblank)
6484 cave[x-1][y] = Xsplash_w;
6485 play_element_sound(x, y, SOUND_acid, Xacid_1);
6491 switch (cave[x-1][y])
6504 cave[x][y] = Yballoon_wB;
6505 next[x][y] = Xblank;
6506 cave[x-1][y] = Yballoon_w;
6507 next[x-1][y] = Xballoon;
6518 cave[x][y] = Yballoon_wB;
6519 next[x][y] = Xblank;
6520 if (cave[x][y-1] == Xblank)
6521 cave[x][y-1] = Xsplash_e;
6522 if (cave[x-2][y-1] == Xblank)
6523 cave[x-2][y-1] = Xsplash_w;
6524 play_element_sound(x, y, SOUND_acid, Xacid_1);
6531 static void Lball_common(int x, int y)
6533 play_element_sound(x, y, SOUND_ball, Xball_1);
6535 if (lev.ball_random)
6540 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6541 is_blank[cave[x-1][y-1]])
6543 cave[x-1][y-1] = Yball_blank;
6544 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6549 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6550 is_blank[cave[x][y-1]])
6552 cave[x][y-1] = Yball_blank;
6553 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6558 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6559 is_blank[cave[x+1][y-1]])
6561 cave[x+1][y-1] = Yball_blank;
6562 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6567 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6568 is_blank[cave[x-1][y]])
6570 cave[x-1][y] = Yball_blank;
6571 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6576 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6577 is_blank[cave[x+1][y]])
6579 cave[x+1][y] = Yball_blank;
6580 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6585 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6586 is_blank[cave[x-1][y+1]])
6588 cave[x-1][y+1] = Yball_blank;
6589 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6594 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6595 is_blank[cave[x][y+1]])
6597 cave[x][y+1] = Yball_blank;
6598 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6603 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6604 is_blank[cave[x+1][y+1]])
6606 cave[x+1][y+1] = Yball_blank;
6607 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6614 if (lev.ball_array[lev.ball_pos][0] != Xblank &&
6615 is_blank[cave[x-1][y-1]])
6617 cave[x-1][y-1] = Yball_blank;
6618 next[x-1][y-1] = lev.ball_array[lev.ball_pos][0];
6621 if (lev.ball_array[lev.ball_pos][1] != Xblank &&
6622 is_blank[cave[x][y-1]])
6624 cave[x][y-1] = Yball_blank;
6625 next[x][y-1] = lev.ball_array[lev.ball_pos][1];
6628 if (lev.ball_array[lev.ball_pos][2] != Xblank &&
6629 is_blank[cave[x+1][y-1]])
6631 cave[x+1][y-1] = Yball_blank;
6632 next[x+1][y-1] = lev.ball_array[lev.ball_pos][2];
6635 if (lev.ball_array[lev.ball_pos][3] != Xblank &&
6636 is_blank[cave[x-1][y]])
6638 cave[x-1][y] = Yball_blank;
6639 next[x-1][y] = lev.ball_array[lev.ball_pos][3];
6642 if (lev.ball_array[lev.ball_pos][4] != Xblank &&
6643 is_blank[cave[x+1][y]])
6645 cave[x+1][y] = Yball_blank;
6646 next[x+1][y] = lev.ball_array[lev.ball_pos][4];
6649 if (lev.ball_array[lev.ball_pos][5] != Xblank &&
6650 is_blank[cave[x-1][y+1]])
6652 cave[x-1][y+1] = Yball_blank;
6653 next[x-1][y+1] = lev.ball_array[lev.ball_pos][5];
6656 if (lev.ball_array[lev.ball_pos][6] != Xblank &&
6657 is_blank[cave[x][y+1]])
6659 cave[x][y+1] = Yball_blank;
6660 next[x][y+1] = lev.ball_array[lev.ball_pos][6];
6663 if (lev.ball_array[lev.ball_pos][7] != Xblank &&
6664 is_blank[cave[x+1][y+1]])
6666 cave[x+1][y+1] = Yball_blank;
6667 next[x+1][y+1] = lev.ball_array[lev.ball_pos][7];
6671 lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays;
6674 static void Lball_1(int x, int y)
6676 if (!lev.ball_active)
6679 cave[x][y] = Yball_1;
6680 next[x][y] = Xball_2;
6687 static void Lball_2(int x, int y)
6689 if (!lev.ball_active)
6692 cave[x][y] = Yball_2;
6693 next[x][y] = Xball_1;
6700 static void Ldrip(int x, int y)
6702 next[x][y] = Xdrip_fall;
6705 static void Ldrip_fall(int x, int y)
6709 switch (cave[x][y+1])
6725 cave[x][y] = Ydrip_1_sB;
6726 next[x][y] = Xdrip_stretchB;
6727 cave[x][y+1] = Ydrip_1_s;
6728 next[x][y+1] = Xdrip_stretch;
6739 cave[x][y] = Ydrip_1_sB;
6740 next[x][y] = Xdrip_stretchB;
6741 if (cave[x+1][y] == Xblank)
6742 cave[x+1][y] = Xsplash_e;
6743 if (cave[x-1][y] == Xblank)
6744 cave[x-1][y] = Xsplash_w;
6745 play_element_sound(x, y, SOUND_acid, Xacid_1);
6751 case 0: temp = Xamoeba_1; break;
6752 case 1: temp = Xamoeba_2; break;
6753 case 2: temp = Xamoeba_3; break;
6754 case 3: temp = Xamoeba_4; break;
6755 case 4: temp = Xamoeba_5; break;
6756 case 5: temp = Xamoeba_6; break;
6757 case 6: temp = Xamoeba_7; break;
6758 case 7: temp = Xamoeba_8; break;
6763 play_element_sound(x, y, SOUND_drip, Xdrip_fall);
6768 static void Ldrip_stretch(int x, int y)
6770 cave[x][y] = Ydrip_2_s;
6771 next[x][y] = Xdrip_fall;
6774 static void Ldrip_stretchB(int x, int y)
6776 cave[x][y] = Ydrip_2_sB;
6777 next[x][y] = Xblank;
6780 static void Lwonderwall(int x, int y)
6782 if (lev.wonderwall_time > 0 && lev.wonderwall_active)
6784 cave[x][y] = Ywonderwall;
6785 play_element_sound(x, y, SOUND_wonder, Xwonderwall);
6789 static void Lwheel(int x, int y)
6791 if (lev.wheel_cnt && x == lev.wheel_x && y == lev.wheel_y)
6792 cave[x][y] = Ywheel;
6795 static void Lswitch(int x, int y)
6797 if (lev.ball_active)
6798 cave[x][y] = Yswitch;
6801 static void Lfake_blank(int x, int y)
6804 cave[x][y] = Yfake_blank;
6807 static void Lfake_grass(int x, int y)
6809 if (lev.magnify_cnt)
6810 cave[x][y] = Yfake_grass;
6813 static void Lfake_amoeba(int x, int y)
6816 cave[x][y] = Yfake_amoeba;
6819 static void Lsand_stone(int x, int y)
6821 switch (cave[x][y+1])
6834 cave[x][y] = Xsand_stonesand_quickout_1;
6835 next[x][y] = Xsand_stonesand_quickout_2;
6836 cave[x][y+1] = Xsand_stoneout_1;
6837 next[x][y+1] = Xsand_stoneout_2;
6848 cave[x][y] = Xsand_stonesand_quickout_1;
6849 next[x][y] = Xsand_stonesand_quickout_2;
6850 if (cave[x+1][y] == Xblank)
6851 cave[x+1][y] = Xsplash_e;
6852 if (cave[x-1][y] == Xblank)
6853 cave[x-1][y] = Xsplash_w;
6854 play_element_sound(x, y, SOUND_acid, Xacid_1);
6858 cave[x][y] = Xsand_stonesand_1;
6859 next[x][y] = Xsand_stonesand_2;
6860 cave[x][y+1] = Xsand_sandstone_1;
6861 next[x][y+1] = Xsand_sandstone_2;
6866 static void Lsand_stonein_1(int x, int y)
6868 next[x][y] = Xsand_stonein_2;
6871 static void Lsand_stonein_2(int x, int y)
6873 next[x][y] = Xsand_stonein_3;
6876 static void Lsand_stonein_3(int x, int y)
6878 next[x][y] = Xsand_stonein_4;
6881 static void Lsand_stonein_4(int x, int y)
6883 next[x][y] = Xblank;
6886 static void Lsand_sandstone_1(int x, int y)
6888 next[x][y] = Xsand_sandstone_2;
6891 static void Lsand_sandstone_2(int x, int y)
6893 next[x][y] = Xsand_sandstone_3;
6896 static void Lsand_sandstone_3(int x, int y)
6898 next[x][y] = Xsand_sandstone_4;
6901 static void Lsand_sandstone_4(int x, int y)
6903 next[x][y] = Xsand_stone;
6906 static void Lsand_stonesand_1(int x, int y)
6908 next[x][y] = Xsand_stonesand_2;
6911 static void Lsand_stonesand_2(int x, int y)
6913 next[x][y] = Xsand_stonesand_3;
6916 static void Lsand_stonesand_3(int x, int y)
6918 next[x][y] = Xsand_stonesand_4;
6921 static void Lsand_stonesand_4(int x, int y)
6926 static void Lsand_stoneout_1(int x, int y)
6928 next[x][y] = Xsand_stoneout_2;
6931 static void Lsand_stoneout_2(int x, int y)
6933 next[x][y] = Xstone_fall;
6936 static void Lsand_stonesand_quickout_1(int x, int y)
6938 next[x][y] = Xsand_stonesand_quickout_2;
6941 static void Lsand_stonesand_quickout_2(int x, int y)
6946 static void Lslide_ns(int x, int y)
6948 if (is_blank[cave[x][y-1]])
6950 cave[x][y-1] = Yslide_ns_blank;
6951 next[x][y-1] = Xslide_ns;
6952 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6955 if (is_blank[cave[x][y+1]])
6957 cave[x][y+1] = Yslide_ns_blank;
6958 next[x][y+1] = Xslide_ns;
6959 play_element_sound(x, y, SOUND_slide, Xslide_ns);
6963 static void Lslide_ew(int x, int y)
6965 if (is_blank[cave[x+1][y]])
6967 cave[x+1][y] = Yslide_ew_blank;
6968 next[x+1][y] = Xslide_ew;
6969 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6972 if (is_blank[cave[x-1][y]])
6974 cave[x-1][y] = Yslide_ew_blank;
6975 next[x-1][y] = Xslide_ew;
6976 play_element_sound(x, y, SOUND_slide, Xslide_ew);
6980 static void Lexit(int x, int y)
6982 if (lev.gems_needed > 0)
6985 switch (RANDOM(64) / 21)
6988 cave[x][y] = Xexit_1;
6989 next[x][y] = Xexit_2;
6993 cave[x][y] = Xexit_2;
6994 next[x][y] = Xexit_3;
6998 cave[x][y] = Xexit_3;
6999 next[x][y] = Xexit_1;
7003 play_element_sound(x, y, SOUND_exit_open, Xexit);
7006 static void Lexit_1(int x, int y)
7008 next[x][y] = Xexit_2;
7011 static void Lexit_2(int x, int y)
7013 next[x][y] = Xexit_3;
7016 static void Lexit_3(int x, int y)
7018 next[x][y] = Xexit_1;
7021 static void Lpause(int x, int y)
7023 next[x][y] = Xblank;
7026 static void Lamoeba(int x, int y)
7046 if (is_amoeba[cave[x][y-1]] ||
7047 is_amoeba[cave[x+1][y]] ||
7048 is_amoeba[cave[x][y+1]] ||
7049 is_amoeba[cave[x-1][y]])
7054 static void Lboom_one(int x, int y, boolean by_dynamite)
7115 cave[x][y] = Xboom_android;
7126 cave[x][y] = Xboom_bug;
7127 Lboom_bug_new(x, y, TRUE);
7133 cave[x][y] = Xboom_tank;
7134 Lboom_tank_new(x, y, TRUE);
7138 cave[x][y] = Xboom_1;
7143 static void Lboom_nine(int x, int y, boolean by_dynamite)
7145 Lboom_one(x, y-1, by_dynamite);
7146 Lboom_one(x-1, y, by_dynamite);
7147 Lboom_one(x+1, y, by_dynamite);
7148 Lboom_one(x, y+1, by_dynamite);
7149 Lboom_one(x-1, y-1, by_dynamite);
7150 Lboom_one(x+1, y-1, by_dynamite);
7151 Lboom_one(x-1, y+1, by_dynamite);
7152 Lboom_one(x+1, y+1, by_dynamite);
7154 cave[x][y] = Xboom_1;
7157 static void Lexplode(int x, int y)
7162 Lboom_bug_new(x, y, FALSE);
7163 Lboom_nine(x, y, FALSE);
7167 Lboom_tank_new(x, y, FALSE);
7168 Lboom_nine(x, y, FALSE);
7172 Lboom_eater_new(x, y, FALSE);
7173 Lboom_nine(x, y, FALSE);
7177 Lboom_nine(x, y, TRUE);
7181 Lboom_nine(x, y, FALSE);
7186 static void Lboom_1(int x, int y)
7188 next[x][y] = Xboom_2;
7189 #if !PLAY_ELEMENT_SOUND
7190 if (x != lev.exit_x && y != lev.exit_y)
7191 play_sound(x, y, SOUND_boom);
7193 lev.exit_x = lev.exit_y = -1;
7197 static void Lboom_2(int x, int y)
7199 next[x][y] = boom[x][y];
7202 static void Lboom_android(int x, int y)
7204 #if PLAY_ELEMENT_SOUND
7205 play_element_sound(x, y, SOUND_boom, Xandroid);
7211 static void Lchain(int x, int y)
7216 static void handle_tile(int x, int y)
7220 case Xacid_1: Lacid_1(x, y); break;
7221 case Xacid_2: Lacid_2(x, y); break;
7222 case Xacid_3: Lacid_3(x, y); break;
7223 case Xacid_4: Lacid_4(x, y); break;
7224 case Xacid_5: Lacid_5(x, y); break;
7225 case Xacid_6: Lacid_6(x, y); break;
7226 case Xacid_7: Lacid_7(x, y); break;
7227 case Xacid_8: Lacid_8(x, y); break;
7229 case Xfake_acid_1: Lfake_acid_1(x, y); break;
7230 case Xfake_acid_2: Lfake_acid_2(x, y); break;
7231 case Xfake_acid_3: Lfake_acid_3(x, y); break;
7232 case Xfake_acid_4: Lfake_acid_4(x, y); break;
7233 case Xfake_acid_5: Lfake_acid_5(x, y); break;
7234 case Xfake_acid_6: Lfake_acid_6(x, y); break;
7235 case Xfake_acid_7: Lfake_acid_7(x, y); break;
7236 case Xfake_acid_8: Lfake_acid_8(x, y); break;
7238 case Xandroid: Landroid(x, y); break;
7239 case Xandroid_1_n: Landroid_1_n(x, y); break;
7240 case Xandroid_2_n: Landroid_2_n(x, y); break;
7241 case Xandroid_1_e: Landroid_1_e(x, y); break;
7242 case Xandroid_2_e: Landroid_2_e(x, y); break;
7243 case Xandroid_1_s: Landroid_1_s(x, y); break;
7244 case Xandroid_2_s: Landroid_2_s(x, y); break;
7245 case Xandroid_1_w: Landroid_1_w(x, y); break;
7246 case Xandroid_2_w: Landroid_2_w(x, y); break;
7248 case Xeater_n: Leater_n(x, y); break;
7249 case Xeater_e: Leater_e(x, y); break;
7250 case Xeater_s: Leater_s(x, y); break;
7251 case Xeater_w: Leater_w(x, y); break;
7253 case Xalien: Lalien(x, y); break;
7254 case Xalien_pause: Lalien_pause(x, y); break;
7256 case Xbug_1_n: Lbug_1_n(x, y); break;
7257 case Xbug_2_n: Lbug_2_n(x, y); break;
7258 case Xbug_1_e: Lbug_1_e(x, y); break;
7259 case Xbug_2_e: Lbug_2_e(x, y); break;
7260 case Xbug_1_s: Lbug_1_s(x, y); break;
7261 case Xbug_2_s: Lbug_2_s(x, y); break;
7262 case Xbug_1_w: Lbug_1_w(x, y); break;
7263 case Xbug_2_w: Lbug_2_w(x, y); break;
7265 case Xtank_1_n: Ltank_1_n(x, y); break;
7266 case Xtank_2_n: Ltank_2_n(x, y); break;
7267 case Xtank_1_e: Ltank_1_e(x, y); break;
7268 case Xtank_2_e: Ltank_2_e(x, y); break;
7269 case Xtank_1_s: Ltank_1_s(x, y); break;
7270 case Xtank_2_s: Ltank_2_s(x, y); break;
7271 case Xtank_1_w: Ltank_1_w(x, y); break;
7272 case Xtank_2_w: Ltank_2_w(x, y); break;
7274 case Xemerald: Lemerald(x, y); break;
7275 case Xemerald_pause: Lemerald_pause(x, y); break;
7276 case Xemerald_fall: Lemerald_fall(x, y); break;
7278 case Xdiamond: Ldiamond(x, y); break;
7279 case Xdiamond_pause: Ldiamond_pause(x, y); break;
7280 case Xdiamond_fall: Ldiamond_fall(x, y); break;
7282 case Xstone: Lstone(x, y); break;
7283 case Xstone_pause: Lstone_pause(x, y); break;
7284 case Xstone_fall: Lstone_fall(x, y); break;
7286 case Xbomb: Lbomb(x, y); break;
7287 case Xbomb_pause: Lbomb_pause(x, y); break;
7288 case Xbomb_fall: Lbomb_fall(x, y); break;
7290 case Xnut: Lnut(x, y); break;
7291 case Xnut_pause: Lnut_pause(x, y); break;
7292 case Xnut_fall: Lnut_fall(x, y); break;
7294 case Xspring: Lspring(x, y); break;
7295 case Xspring_pause: Lspring_pause(x, y); break;
7296 case Xspring_e: Lspring_e(x, y); break;
7297 case Xspring_w: Lspring_w(x, y); break;
7298 case Xspring_fall: Lspring_fall(x, y); break;
7300 case Xpush_emerald_e: Lpush_emerald_e(x, y); break;
7301 case Xpush_emerald_w: Lpush_emerald_w(x, y); break;
7302 case Xpush_diamond_e: Lpush_diamond_e(x, y); break;
7303 case Xpush_diamond_w: Lpush_diamond_w(x, y); break;
7304 case Xpush_stone_e: Lpush_stone_e(x, y); break;
7305 case Xpush_stone_w: Lpush_stone_w(x, y); break;
7306 case Xpush_bomb_e: Lpush_bomb_e(x, y); break;
7307 case Xpush_bomb_w: Lpush_bomb_w(x, y); break;
7308 case Xpush_nut_e: Lpush_nut_e(x, y); break;
7309 case Xpush_nut_w: Lpush_nut_w(x, y); break;
7310 case Xpush_spring_e: Lpush_spring_e(x, y); break;
7311 case Xpush_spring_w: Lpush_spring_w(x, y); break;
7313 case Xdynamite_1: Ldynamite_1(x, y); break;
7314 case Xdynamite_2: Ldynamite_2(x, y); break;
7315 case Xdynamite_3: Ldynamite_3(x, y); break;
7316 case Xdynamite_4: Ldynamite_4(x, y); break;
7318 case Xfake_door_1: Lfake_door_1(x, y); break;
7319 case Xfake_door_2: Lfake_door_2(x, y); break;
7320 case Xfake_door_3: Lfake_door_3(x, y); break;
7321 case Xfake_door_4: Lfake_door_4(x, y); break;
7322 case Xfake_door_5: Lfake_door_5(x, y); break;
7323 case Xfake_door_6: Lfake_door_6(x, y); break;
7324 case Xfake_door_7: Lfake_door_7(x, y); break;
7325 case Xfake_door_8: Lfake_door_8(x, y); break;
7327 case Xballoon: Lballoon(x, y); break;
7329 case Xball_1: Lball_1(x, y); break;
7330 case Xball_2: Lball_2(x, y); break;
7332 case Xdrip: Ldrip(x, y); break;
7333 case Xdrip_fall: Ldrip_fall(x, y); break;
7334 case Xdrip_stretch: Ldrip_stretch(x, y); break;
7335 case Xdrip_stretchB: Ldrip_stretchB(x, y); break;
7337 case Xwonderwall: Lwonderwall(x, y); break;
7339 case Xwheel: Lwheel(x, y); break;
7341 case Xswitch: Lswitch(x, y); break;
7343 case Xfake_blank: Lfake_blank(x, y); break;
7344 case Xfake_grass: Lfake_grass(x, y); break;
7345 case Xfake_amoeba: Lfake_amoeba(x, y); break;
7347 case Xsand_stone: Lsand_stone(x, y); break;
7348 case Xsand_stonein_1: Lsand_stonein_1(x, y); break;
7349 case Xsand_stonein_2: Lsand_stonein_2(x, y); break;
7350 case Xsand_stonein_3: Lsand_stonein_3(x, y); break;
7351 case Xsand_stonein_4: Lsand_stonein_4(x, y); break;
7352 case Xsand_sandstone_1: Lsand_sandstone_1(x, y); break;
7353 case Xsand_sandstone_2: Lsand_sandstone_2(x, y); break;
7354 case Xsand_sandstone_3: Lsand_sandstone_3(x, y); break;
7355 case Xsand_sandstone_4: Lsand_sandstone_4(x, y); break;
7356 case Xsand_stonesand_1: Lsand_stonesand_1(x, y); break;
7357 case Xsand_stonesand_2: Lsand_stonesand_2(x, y); break;
7358 case Xsand_stonesand_3: Lsand_stonesand_3(x, y); break;
7359 case Xsand_stonesand_4: Lsand_stonesand_4(x, y); break;
7360 case Xsand_stoneout_1: Lsand_stoneout_1(x, y); break;
7361 case Xsand_stoneout_2: Lsand_stoneout_2(x, y); break;
7362 case Xsand_stonesand_quickout_1: Lsand_stonesand_quickout_1(x, y); break;
7363 case Xsand_stonesand_quickout_2: Lsand_stonesand_quickout_2(x, y); break;
7365 case Xslide_ns: Lslide_ns(x, y); break;
7366 case Xslide_ew: Lslide_ew(x, y); break;
7368 case Xexit: Lexit(x, y); break;
7369 case Xexit_1: Lexit_1(x, y); break;
7370 case Xexit_2: Lexit_2(x, y); break;
7371 case Xexit_3: Lexit_3(x, y); break;
7373 case Xpause: Lpause(x, y); break;
7375 case Xchain: Lchain(x, y); break;
7376 case Xboom_bug: Lboom_bug(x, y); break;
7377 case Xboom_tank: Lboom_tank(x, y); break;
7378 case Xboom_android: Lboom_android(x, y); break;
7379 case Xboom_1: Lboom_1(x, y); break;
7380 case Xboom_2: Lboom_2(x, y); break;
7384 static void logic_players(void)
7393 game_em.any_player_moving = FALSE;
7394 game_em.any_player_snapping = FALSE;
7396 /* must test for death and actually kill separately */
7397 for (i = 0; i < MAX_PLAYERS; i++)
7399 boolean ply_kill = player_killed(&ply[i]);
7401 if (ply[i].alive && ply_kill)
7402 kill_player(&ply[i]);
7405 for (i = 0; i < MAX_PLAYERS; i++)
7410 /* check for wrap-around movement */
7411 if (ply[i].x < lev.left ||
7412 ply[i].x > lev.right - 1)
7414 ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
7416 game.centered_player_nr_next = i;
7417 game.set_centered_player = TRUE;
7418 game.set_centered_player_wrap = TRUE;
7421 ply[i].prev_x = ply[i].x;
7422 ply[i].prev_y = ply[i].y;
7423 ply[i].anim = PLY_still;
7426 start_check_nr = ((game_em.random & 128 ? 0 : 1) * 2 +
7427 (game_em.random & 256 ? 0 : 1));
7429 for (i = 0; i < MAX_PLAYERS; i++)
7431 int check_nr = (start_check_nr + i) % MAX_PLAYERS;
7433 if (ply[check_nr].alive)
7434 check_player(&ply[check_nr]);
7437 for (i = 0; i < MAX_PLAYERS; i++)
7442 if (cave[ply[i].prev_x][ply[i].prev_y] == Zplayer)
7444 cave[ply[i].prev_x][ply[i].prev_y] = Xblank;
7445 next[ply[i].prev_x][ply[i].prev_y] = Xblank;
7448 if (cave[ply[i].x][ply[i].y] == Xblank)
7450 cave[ply[i].x][ply[i].y] = Zplayer;
7451 next[ply[i].x][ply[i].y] = Zplayer;
7456 static void logic_objects(void)
7464 seed = game_em.random;
7467 for (y = lev.top; y < lev.bottom; y++)
7468 for (x = lev.left; x < lev.right; x++)
7471 if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
7472 lev.score += score; /* only add a score if someone is alive */
7474 game_em.game_over = TRUE;
7476 game_em.random = seed;
7478 /* triple buffering */
7479 void *temp = lev.cave;
7480 lev.cave = lev.next;
7481 lev.next = lev.draw;
7485 static void logic_globals(void)
7500 /* update variables */
7502 if (lev.score > 9999)
7505 if (lev.android_move_cnt-- == 0)
7506 lev.android_move_cnt = lev.android_move_time;
7507 if (lev.android_clone_cnt-- == 0)
7508 lev.android_clone_cnt = lev.android_clone_time;
7509 if (lev.ball_active)
7510 if (lev.ball_cnt-- == 0)
7511 lev.ball_cnt = lev.ball_time;
7514 if (lev.magnify_cnt)
7520 if (lev.wonderwall_time > 0 && lev.wonderwall_active)
7521 lev.wonderwall_time--;
7524 play_element_sound(lev.wheel_x, lev.wheel_y, SOUND_wheel, Xwheel);
7528 random = game_em.random;
7530 for (count = lev.amoeba_time; count--;)
7532 x = lev.left - 1 + (random >> 10) % (CAVE_WIDTH + 2);
7533 y = lev.top - 1 + (random >> 20) % (CAVE_HEIGHT + 2);
7535 if (x >= lev.left && x < lev.right &&
7536 y >= lev.top && y < lev.bottom)
7539 random = random * 129 + 1;
7542 if (!game_em.use_random_bug)
7543 random = (uint32_t)random;
7547 game_em.random = random;
7549 /* handle explosions */
7551 for (y = lev.top; y < lev.bottom; y++)
7552 for (x = lev.left; x < lev.right; x++)
7555 /* triple buffering */
7557 for (y = lev.top; y < lev.bottom; y++)
7558 for (x = lev.left; x < lev.right; x++)
7559 next[x][y] = cave[x][y];
7562 void logic_init(void)
7564 int splash_is_blank = !game_em.use_old_android;
7566 is_android_blank[Xsplash_e] = splash_is_blank;
7567 is_android_blank[Xsplash_w] = splash_is_blank;