1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756
|
/* GNU Robbo
* Copyright (C) 2002-2010 The GNU Robbo Team (see AUTHORS).
*
* GNU Robbo is free software - you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Robbo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the impled warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU CC; see the file COPYING. If not, write to the
* Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "game.h"
/* Defines */
/*
#define DEBUG_MONITOR_OBJECT_PROCESSING
#define DEBUG_INSPECT_OBJECT_CONTENTS
#define DEBUG_BEAR_LOGIC
*/
#define MAX_TELEPORT_IDS 15 /* max number of teleports of one kind at level */
/*
* Variables
*/
/*
* Function prototypes
*/
int random_id (void);
int update_coords (struct Coords *coords, int direction);
void set_images (int type, int x, int y);
int can_move (struct Coords coords, int direction);
void move_object (int x, int y, struct Coords coords);
void shoot_object (int x, int y, int direction);
void blow_bomb (int x, int y);
void check_object_if_blowed (int x, int y);
int find_teleport (struct Coords *coords, int teleportnumber,
int teleportnumber2);
int is_robbo_killed (void);
void kill_robbo (void);
#ifdef LIGHTNINGENABLED
void
seteffect (int x, int y, int effect)
{
board[x][y].effect =
((effect > board[x][y].effect) ? effect : board[x][y].effect);
redraw_field(x,y);
}
void
seteffectsurround (int x, int y, int effect)
{
int x1 = (x - 1 > 0) ? x - 1 : 0;
int y1 = (y - 1 > 0) ? y - 1 : 0;
int x2 = (x + 1 > level.w) ? level.w : x + 1;
int y2 = (y + 1 > level.h) ? level.h : y + 1;
int c1, c2;
for (c1 = x1; c1 <= x2; c1++)
for (c2 = y1; c2 <= y2; c2++)
seteffect (c1, c2, effect);
}
#endif
/***************************************************************************
* Update Game *
***************************************************************************/
/*
* Main function for the game - called every game cycle.
*
* Thunor: Objects that I have 'processed' checked that required it :- [x]
* - BEAR/_B [x] - BARRIER [x] - BIRD [x] - BUTTERFLY [x] - BLASTER [x] -
* LASER_L/D [x] - PUSH_BOX [x] - GUN
*
*/
void
update_game (void)
{
int x_tmp, flag, sflag, temp_state = 0, temp_blowed = 0, temp_direction = 0;
struct Coords coords, coords_temp, dest, coords_side_behind, coords_behind;
int x, y, i, forceforward;
dest.x = 0; /* to avoid warnings */
dest.y = 0;
play_music ();
/*
* Firstly, update Robbo
*/
if (is_robbo_killed ())
kill_robbo (); /* If Robbo has been killed then mark everything to be blown-up */
if (robbo.shooted > 0)
robbo.shooted--; /* Decrement shot delay */
if (robbo.moved > 0)
robbo.moved--; /* Decrement movement delay */
if (robbo.moved == 0)
{
robbo.teleporting = FALSE;
redraw_field (robbo.x, robbo.y);
/*
* Is Robbo currently being pulled by a magnet?
*/
if (robbo.blocked == 1)
{
set_coords (&coords, robbo.x, robbo.y);
if (can_move (coords, robbo.blocked_direction))
{
play_sound (SFX_MAGNET, SND_NORM); /* play magnet sound */
switch (robbo.blocked_direction)
{
case 0:
robbo.x++;
break;
case 2:
robbo.x--;
break;
case 1:
robbo.y++;
break;
case 3:
robbo.y--;
break;
}
robbo.moved = DELAY_MAGNET_ATTRACT;
redraw_field (robbo.x, robbo.y);
}
else
{
kill_robbo ();
return; /* Thunor: this was already here; I didn't add this, but I did add some lower down */
}
}
}
else if (robbo.moved == DELAY_ROBBO_ANIMATE)
{
robbo.state = !robbo.state; /* Toggle Robbo's image */
redraw_field (robbo.x, robbo.y);
}
/*
* Now iterate through every board location updating objects
*/
for (y = 0; y < level.h; y++)
{ /* Thunor: I have swapped these around to process by rows */
for (x = 0; x < level.w; x++)
{ /* Thunor: I have swapped these around to process by rows */
/*
* Thunor: I've added this check to filter out already
* processed objects. Additionally the object logic updates
* other objects and I have modified the code to mark those as
* processed too. The reason I am doing this is because objects
* can get moved ahead of the x/y loop resulting in them having
* at least their shooted/rotated/moved properties decremented
* more than once for this cycle and they go out of sync
*/
/* if(board[x][y].effect>=0) {
for(x1=(x>0)?x-1:0;x1<=x+1;x1++)
for(y1=(y>0)?y-1:0;y1<=y+1;y1++) board[x1][y1].redraw=1;
}
*/
if (board[x][y].processed != cycle_count)
{
board[x][y].processed = cycle_count;
#ifdef LIGHTNINGENABLED
if (board[x][y].effect >= 0)
{
redraw_field (x, y);
board[x][y].effect--;
}
#endif
/*
* GUN and BIRD objects can rotate and shoot so update
* their delays here
*/
if (board[x][y].type == GUN || board[x][y].type == BIRD
|| board[x][y].type == MAGNET)
{
if (board[x][y].shooted > 0)
board[x][y].shooted--; /* Decrement shot delay */
if (board[x][y].rotated > 0)
board[x][y].rotated--; /* Decrement rotation delay */
}
/*
* Decrement the object's delay and then check if it needs
* processing
*/
if (board[x][y].moved > 0)
board[x][y].moved--;
if (board[x][y].moved <= 0)
{
check_object_if_blowed (x, y); /* blow objects marked for blowing */
set_coords (&coords, x, y);
switch (board[x][y].type)
{
/*********************/
/* BEAR/_B logic */
/*********************/
case BEAR:
case BEAR_B:
/*
* Left/right-hand rule maze traversal: this is
* the exact same way that the original Robbo does
* it. The bears will attempt to manoeuvre around
* all obstacles but this takes time and they will
* get killed by laser fire and push boxes
* especially if they meet them head-on
*/
set_coords (&coords, x, y);
if (game_mode == GAME_ON)
{
if (board[x][y].type == BEAR)
{
update_coords (&coords, (board[x][y].direction + 3) & 3); /* Get coords of left board location */
}
else
{
update_coords (&coords, (board[x][y].direction + 1) & 3); /* Get coords of right board location */
}
}
forceforward = FALSE;
/*
* Are we implementing sensible_bears? In the
* Atari Robbo, there are two conditions that
* place bears into irritating states that become
* annoying: single bears in empty space going
* around themselves and two bears of the same
* type going around one another.
*
* |N| | = If this is a BEAR_B taking rights, it
* will go clockwise forever. | | | N is north.
*
* | |N| = If these are BEARs taking lefts, they
* will go anti-clockwise forever. |S| | N is
* north, S is south.
*
* sensible_bears detects the conditions that lead
* to these problems and fixes them by forcing the
* bears to go forward until they find another
* obstacle to navigate around
*/
if (game_mechanics.sensible_bears)
{
set_coords (&coords_side_behind, coords.x,
coords.y);
update_coords (&coords_side_behind, (board[x][y].direction + 2) & 3); /* Get coords of side-behind board location */
set_coords (&coords_behind,
coords_side_behind.x,
coords_side_behind.y);
if (board[x][y].type == BEAR)
{
update_coords (&coords_behind, (board[x][y].direction + 1) & 3); /* Get coords of behind board location */
}
else
{
update_coords (&coords_behind, (board[x][y].direction + 3) & 3); /* Get coords of behind board location */
}
if (board[coords.x][coords.y].type ==
EMPTY_FIELD
&& board[coords_behind.x][coords_behind.y].
type == EMPTY_FIELD
&&
(board[coords_side_behind.x]
[coords_side_behind.y].type == EMPTY_FIELD
|| board[x][y].type ==
board[coords_side_behind.
x][coords_side_behind.y].type))
{
forceforward = TRUE;
}
}
#ifdef DEBUG_BEAR_LOGIC
if (board[x][y].type == BEAR)
{
printf ("|%02i| @| %06i: BEAR at %03i.%03i\n",
board[coords.x][coords.y].type,
cycle_count, x, y);
printf ("|%02i|%02i|\n",
board[coords_side_behind.x]
[coords_side_behind.y].type,
board[coords_behind.x][coords_behind.y].
type);
}
else if (board[x][y].type == BEAR_B)
{
printf ("| *|%02i| %06i: BEAR_B at %03i.%03i\n",
board[coords.x][coords.y].type,
cycle_count, x, y);
printf ("|%02i|%02i|\n",
board[coords_behind.x][coords_behind.y].
type,
board[coords_side_behind.x]
[coords_side_behind.y].type);
}
#endif
/*
* Check left/right and if it's clear then take it
*/
if (board[coords.x][coords.y].type == EMPTY_FIELD
&& !forceforward)
{
/*
* Left/right is clear so change to that
* direction and move there
*/
if (board[x][y].type == BEAR)
{
board[x][y].direction = (board[x][y].direction + 3) & 3; /* Go left */
}
else
{
board[x][y].direction = (board[x][y].direction + 1) & 3; /* Go right */
}
board[x][y].moved = DELAY_BEAR;
negate_state (x, y);
move_object (x, y, coords);
}
else
{
/*
* Left/right is not clear so check forward
* and if it's clear then take it
*/
set_coords (&coords, x, y);
update_coords (&coords, board[x][y].direction); /* Get coords of forward board location */
if (board[coords.x][coords.y].type == EMPTY_FIELD)
{
/*
* Forward is clear so move there
*/
board[x][y].moved = DELAY_BEAR;
negate_state (x, y);
move_object (x, y, coords);
}
else
{
/*
* Forward is not clear so rotate
* rightward but don't move
*/
if (board[x][y].type == BEAR)
{
board[x][y].direction = (board[x][y].direction + 1) & 3; /* Go forward */
}
else
{
board[x][y].direction = (board[x][y].direction + 3) & 3; /* Go forward */
}
board[x][y].moved = DELAY_BEAR;
board[x][y].processed = cycle_count; /* Because we're not moving, we do this manually */
negate_state (x, y);
}
}
break;
/*********************/
/* BARRIER logic */
/*********************/
case BARRIER:
flag = 0;
x_tmp = x;
if (board[x][y].direction == 0)
{ /* East -> */
while (x_tmp < level.w
&& board[x_tmp][y].type != WALL)
{
x_tmp++;
}
x_tmp--;
if (board[x_tmp][y].type == BARRIER)
{
temp_state = board[x_tmp][y].state;
temp_blowed = board[x_tmp][y].blowed;
temp_direction = board[x_tmp][y].direction;
clear_field (x_tmp, y);
negate_state (x_tmp, y);
flag = 1;
}
while (x_tmp >= 0 && board[x_tmp][y].type != WALL)
{
x_tmp--;
/*
* Thunor: I added "x_tmp >= 0 && " below
* to prevent referencing invalid array
* elements as x_tmp can be -1 here if the
* barrier is up against the left map
* edge. Following this block of code,
* x_tmp is incremented and so this is the
* most suitable solution
*/
if (x_tmp >= 0
&& board[x_tmp][y].type == BARRIER)
{
check_object_if_blowed (x_tmp, y);
dest.x = x_tmp + 1;
dest.y = y;
if ((dest.x == robbo.x)
&& (dest.y == robbo.y))
{
kill_robbo ();
return; /* Thunor: Exiting here stops new barriers from being created */
}
move_object (x_tmp, y, dest);
/*
* board[dest.x][dest.y].direction =
* 0;
*/
board[dest.x][dest.y].moved = DELAY_BARRIER;
board[dest.x][dest.y].processed = cycle_count; /* Thunor: Prevents this object from being processed again this cycle */
negate_state (dest.x, dest.y);
}
}
x_tmp++;
if (flag == 1)
{
if ((dest.x == robbo.x) && (dest.y == robbo.y))
{
kill_robbo ();
return; /* Thunor: Exiting here stops new barriers from being created */
}
if (robbo.x == x_tmp && robbo.y == y)
{
kill_robbo ();
return;
}
create_object (x_tmp, y, BARRIER);
board[x_tmp][y].state = temp_state;
board[x_tmp][y].blowed = temp_blowed;
board[x_tmp][y].direction = temp_direction;
board[x_tmp][y].moved = DELAY_BARRIER;
negate_state (x_tmp, y);
}
}
else if (board[x][y].direction == 2)
{ /* <- West */
while (x_tmp >= 0 && board[x_tmp][y].type != WALL)
x_tmp--;
x_tmp++;
if (board[x_tmp][y].type == BARRIER)
{
temp_state = board[x_tmp][y].state;
temp_blowed = board[x_tmp][y].blowed;
temp_direction = board[x_tmp][y].direction;
clear_field (x_tmp, y);
negate_state (x_tmp, y);
flag = 1;
}
while (x_tmp < level.w
&& board[x_tmp][y].type != WALL)
{
x_tmp++;
/*
* Thunor: I added "x_tmp < level.w && "
* below to prevent referencing invalid
* array elements as x_tmp can be level.w
* here if the barrier is up against the
* right map edge. Following this block of
* code, x_tmp is decremented and so this
* is the most suitable solution
*/
if (x_tmp < level.w
&& board[x_tmp][y].type == BARRIER)
{
check_object_if_blowed (x_tmp, y);
dest.x = x_tmp - 1;
dest.y = y;
if ((dest.x == robbo.x)
&& (dest.y == robbo.y))
{
kill_robbo ();
return; /* Thunor: Exiting here stops new barriers from being created */
}
move_object (x_tmp, y, dest);
/*
* board[dest.x][dest.y].direction =
* 2;
*/
board[dest.x][dest.y].moved = DELAY_BARRIER;
board[dest.x][dest.y].processed = cycle_count; /* Thunor: Prevents this object from being processed again this cycle */
negate_state (dest.x, dest.y);
}
}
x_tmp--;
if (flag == 1 && temp_blowed == 0)
{
if ((dest.x == robbo.x) && (dest.y == robbo.y))
{
kill_robbo ();
return; /* Thunor: Exiting here stops new barriers from being created */
}
if (robbo.x == x_tmp && robbo.y == y)
{
kill_robbo ();
return;
}
create_object (x_tmp, y, BARRIER);
board[x_tmp][y].state = temp_state;
board[x_tmp][y].moved = DELAY_BARRIER;
board[x_tmp][y].direction = temp_direction;
negate_state (x_tmp, y);
}
}
break;
/*********************/
/* BIRD logic */
/*********************/
case BIRD:
if (can_move (coords, board[x][y].direction))
{
update_coords (&coords, board[x][y].direction);
move_object (x, y, coords);
}
else
board[x][y].direction =
(board[x][y].direction + 2) & 0x03;
if (board[coords.x][coords.y].shooting)
{
if (board[coords.x][coords.y].shooted == 0)
{
if ((my_rand () & 0x07) == 0)
{ /* bird shoots */
shoot_object (coords.x, coords.y,
board[coords.x][coords.y].
direction2);
if (in_viewport (x, y))
play_sound (SFX_BIRD, SND_NORM);
else
play_sound (SFX_BIRD, SND_QUIET);
}
else
board[coords.x][coords.y].shooted =
DELAY_LASER;
}
}
board[coords.x][coords.y].moved = DELAY_BIRD;
negate_state (coords.x, coords.y);
break;
/*********************/
/* BUTTERFLY logic */
/*********************/
case BUTTERFLY:
if (can_move (coords, board[x][y].direction))
{
update_coords (&coords, board[x][y].direction);
move_object (x, y, coords);
}
if (!(rand () & 0x07)) /* chances for random move */
board[coords.x][coords.y].direction = rand () & 0x03;
else if ((rand () & 0x01) == 0)
{ /* if butterfly flies horizontally */
if (robbo.x > coords.x)
board[coords.x][coords.y].direction = 0;
else if (robbo.x < coords.x)
board[coords.x][coords.y].direction = 2;
}
else
{ /* if butterfly flies vertically */
if (robbo.y > coords.y)
board[coords.x][coords.y].direction = 1;
else if (robbo.y < coords.y)
board[coords.x][coords.y].direction = 3;
}
board[coords.x][coords.y].moved = DELAY_BUTTERFLY;
negate_state (coords.x, coords.y);
break;
/*********************/
/* BLASTER logic */
/*********************/
case BLASTER:
redraw_field(x,y);
set_coords (&coords, x, y);
set_coords (&coords_temp, x, y); /* * neurocyp now we will check if the gun was removed during blaster shot, if so, we have to react */
temp_state = board[coords_temp.x][coords_temp.y].state;
while (board[coords_temp.x][coords_temp.y].type ==
BLASTER)
{
temp_state =
board[coords_temp.x][coords_temp.y].state;
update_coords (&coords_temp,
(board[coords_temp.x]
[coords_temp.y].direction + 2) % 4);
}
if (temp_state < 3
&& board[coords_temp.x][coords_temp.y].type != GUN)
{
create_object (coords.x, coords.y, LITTLE_BOOM); /* so the gun was removed during shot? ok, clear it out */
board[coords.x][coords.y].moved = DELAY_BLASTER;
break;
}
if (!update_coords
(&coords, board[coords.x][coords.y].direction)
&& board[x][y].state == 0)
{
if (robbo.x == coords.x && robbo.y == coords.y)
{
kill_robbo ();
return; /* Thunor: Exiting here stops new blasters from being created */
}
switch (board[coords.x][coords.y].type)
{
case DOOR:
case WALL:
case MAGNET:
case BOX:
case TELEPORT:
case PUSH_BOX:
case RADIOACTIVE_FIELD:
case STOP:
case GUN:
case LASER_D:
case LASER_L:
case BLASTER:
case SCREW:
case KEY:
case CAPSULE:
break;
case BOMB:
case BOMB2:
board[coords.x][coords.y].blowed =
DELAY_BLASTER;
break;
default:
clear_field (coords.x, coords.y);
create_object (coords.x, coords.y, BLASTER);
board[coords.x][coords.y].direction =
board[x][y].direction;
board[coords.x][coords.y].direction2 =
board[x][y].direction2;
board[coords.x][coords.y].moved = DELAY_BLASTER;
}
}
if (board[x][y].state < 4)
{
board[x][y].state++;
board[x][y].moved = DELAY_BLASTER;
}
else
{
clear_field (x, y);
}
break;
/*********************/
/* CAPSULE logic */
/*********************/
case CAPSULE:
if (robbo.exitopened)
{
negate_state (x, y);
board[x][y].moved = DELAY_CAPSULE;
redraw_field (x, y);
}
break;
/*********************/
/* LITTLE_BOOM logic */
/*********************/
case LITTLE_BOOM:
redraw_field (x, y);
if (board[x][y].state < 3)
{
board[x][y].state++;
board[x][y].moved = DELAY_LITTLE_BOOM;
}
else
clear_field (x, y);
break;
/*********************/
/* LASER_L/D logic */
/*********************/
case LASER_L:
case LASER_D:
redraw_field (x, y);
update_coords (&coords, board[x][y].direction);
board[x][y].moved = DELAY_LASER;
if ((coords.x == robbo.x) && (coords.y == robbo.y)
&& !board[x][y].returnlaser
&& robbo.teleporting == FALSE)
{
kill_robbo ();
return; /* Thunor: Exiting here stops new lasers from being created */
}
set_coords (&coords, x, y);
if (board[x][y].solidlaser == 0)
{
negate_state (x, y);
if (can_move (coords, board[x][y].direction))
{ /* normal shooting */
update_coords (&coords, board[x][y].direction);
move_object (x, y, coords);
board[coords.x][coords.y].moved = DELAY_LASER;
}
else
{ /* blow object if it's destroyable */
if (!update_coords
(&coords, board[x][y].direction)
&& board[coords.x][coords.y].destroyable)
{
if ((board[coords.x][coords.y].type != BOMB)
&& (board[coords.x][coords.y].type !=
BOMB2))
{
if (in_viewport (x, y))
{
play_sound (SFX_KILL, SND_NORM);
}
else
{
play_sound (SFX_KILL, SND_QUIET);
}
}
clear_field (x, y);
board[coords.x][coords.y].blowed = 1;
redraw_field (coords.x, coords.y);
}
else
{
clear_field (x, y); /* clear lasertrack */
create_object (x, y, LITTLE_BOOM);
board[x][y].moved = DELAY_LITTLE_BOOM;
break;
}
}
}
else
{
/* **************************** laser is solid ********************** */
set_coords (&coords_temp, x, y); /* first let's check that laser starts from a gun, if not, means gun was moved, or blown */
while (board[coords_temp.x][coords_temp.y].type ==
board[x][y].type && coords_temp.x >= 0
&& coords_temp.y >= 0
&& coords_temp.x <= level.w
&& coords_temp.y <= level.h)
{ /* move * on * laser */
if (update_coords
(&coords_temp,
(board[x][y].direction + 2) & 0x03))
break;
}
if (board[coords_temp.x][coords_temp.y].type != GUN)
{ /* ok, now we are at the beginning of laser beam if it is not a gun, which is there, destroy laser */
create_object (x, y, LITTLE_BOOM);
break;
}
/* neurocyp: set the state for the whole beam (begin) */
set_coords (&coords_temp, x, y);
update_coords (&coords_temp,
(board[x][y].direction + 2) & 0x03);
if (board[coords_temp.x][coords_temp.y].type == GUN)
{ /* are we at the beginning of the laser? */
temp_state = (board[x][y].state == 3) ? 2 : 3;
set_coords (&coords_temp, x, y); /* first let's check that laser starts from a gun, if not, means gun was moved, or blown */
while ((board[coords_temp.x][coords_temp.y].type
== board[x][y].type)
&& board[coords_temp.x][coords_temp.
y].direction ==
board[x][y].direction
&& coords_temp.x >= 0
&& coords_temp.y >= 0
&& coords_temp.x <= level.w
&& coords_temp.y <= level.h)
{ /* move * on * laser with the same direction and all */
redraw_field (coords_temp.x, coords_temp.y); /* we will have to redraw the whole beam, as we changed it's state */
board[coords_temp.x][coords_temp.y].state =
temp_state;
if (update_coords
(&coords_temp, board[x][y].direction))
break; /* just in case, if we are unable to update coords then we quit the loop */
}
}
/* neurocyp: set the state for the whole beam (end) */
if (can_move (coords, board[x][y].direction)
&& board[x][y].returnlaser == 0)
{ /* if can shoot */
update_coords (&coords, board[x][y].direction);
shoot_object (x, y, board[x][y].direction);
board[coords.x][coords.y].moved = DELAY_LASER;
}
else
{
if (board[x][y].returnlaser == 1)
{
set_coords (&coords, x, y); /* checking if laser is near gun */
update_coords (&coords,
(board[x][y].direction +
2) & 0x03);
clear_field (x, y);
if (board[coords.x][coords.y].type == GUN)
{
create_object (x, y, LITTLE_BOOM);
break;
}
if (board[coords.x][coords.y].type ==
LASER_D
|| board[coords.x][coords.y].type ==
LASER_L)
{
board[coords.x][coords.y].returnlaser =
1;
board[coords.x][coords.y].moved =
DELAY_LASER;
board[coords.x][coords.y].processed = cycle_count; /* Thunor: Prevents this object from being processed again this cycle */
}
}
else
{
set_coords (&coords, x, y);
if (!update_coords
(&coords, board[x][y].direction))
{
if (board[coords.x][coords.y].type ==
LASER_D
|| board[coords.x][coords.y].type ==
LASER_L)
{
if (board[coords.x]
[coords.y].direction ==
board[x][y].direction)
{
break;
}
}
if (board[coords.x]
[coords.y].destroyable)
{
board[coords.x][coords.y].blowed =
1;
if ((board[coords.x][coords.y].type
!= BOMB)
&&
(board[coords.x][coords.y].type
!= BOMB2))
{
if (in_viewport (x, y))
play_sound (SFX_KILL,
SND_NORM);
else
play_sound (SFX_KILL,
SND_QUIET);
}
}
}
board[x][y].returnlaser = 1;
}
}
}
break;
/*********************/
/* BIG_BOOM logic */
/*********************/
case BIG_BOOM:
redraw_field (x, y);
if (board[x][y].state < 4)
{
board[x][y].state++;
board[x][y].moved = DELAY_BIGBOOM;
}
else
{
i = board[x][y].id_questionmark; /* This is why create_object() doesn't clear this property */
if ((i > 0) && robbo.alive)
{
clear_field (x, y);
if (i == QUESTIONMARK)
board[x][y].id_questionmark = random_id ();
create_object (x, y, i);
switch (i)
{
case CAPSULE:
open_exit ();
break;
case GUN:
board[x][y].rotable = 1;
board[x][y].randomrotated = 1;
board[x][y].direction = rand () & 0x03;
break;
default:
break;
}
}
else
clear_field (x, y);
}
break;
/*********************/
/* RADIOACTIVE_FIELD logic */
/*********************/
case RADIOACTIVE_FIELD:
negate_state (x, y);
board[x][y].moved = DELAY_RADIOACTIVE_FIELD;
break;
/*********************/
/* TELEPORT logic */
/*********************/
case TELEPORT:
redraw_field (x, y);
negate_state (x, y);
board[x][y].moved = DELAY_TELEPORT;
break;
/*********************/
/* TELEPORTING logic */
/*********************/
case TELEPORTING:
redraw_field (x, y);
if (board[x][y].state < 4)
{
board[x][y].state++;
board[x][y].moved = DELAY_TELEPORTING;
}
else
{
clear_field (x, y);
}
break;
/*********************/
/* PUSH_BOX logic */
/*********************/
case PUSH_BOX:
if (board[x][y].state == 1)
{ /* box is moving */
set_coords (&coords, x, y);
if (!update_coords (&coords, board[x][y].direction))
{
if (board[coords.x][coords.y].type ==
EMPTY_FIELD && (coords.x != robbo.x
|| coords.y != robbo.y))
{
move_object (x, y, coords);
}
else
{
//if(coords.x==robbo.x && coords.y==robbo.y
shoot_object (x, y, board[x][y].direction);
board[x][y].state = 0;
board[x][y].redraw = 1;
}
}
else
board[x][y].state = 0;
board[x][y].redraw = 1;
if (in_viewport (x, y))
play_sound (SFX_BOX, SND_NORM); /* play the sound */
else
play_sound (SFX_BOX, SND_QUIET);
board[coords.x][coords.y].moved = DELAY_PUSHBOX;
}
break;
/*********************/
/* MAGNET logic */
/*********************/
case MAGNET:
i = 0;
if (robbo.blocked == 1)
break; /* *neurocyp we are already locked on a magnet we ignore other blocks */
if (board[x][y].rotable)
{ /* *neurocyp: we will not rotate, when we shoot */
if (board[x][y].rotated == 0)
{
temp_direction = rand () & 0x03;
board[x][y].direction = temp_direction;
board[x][y].state = temp_direction;
board[coords.x][coords.y].rotated =
DELAY_ROTATION;
redraw_field (coords.x, coords.y);
}
}
while (i == 0)
{
if (!update_coords (&coords, board[x][y].direction))
{
if (robbo.x == coords.x && robbo.y == coords.y)
{
robbo.blocked = 1;
robbo.blocked_direction =
(board[x][y].direction + 2) & 0x03;
}
else
switch (board[coords.x][coords.y].type)
{
/*
* this things don't protect from
* magnet
*/
case EMPTY_FIELD:
break;
default:
i = 1;
break;
}
}
else
i = 1;
}
break;
/*********************/
/* GUN logic */
/*********************/
case GUN:
set_coords (&coords, x, y);
#ifdef DEBUG_MONITOR_OBJECT_PROCESSING
printf
("cycle_count=%i: board[%i][%i].processed=%i\n",
cycle_count, x, y, board[x][y].processed);
#endif
sflag = 0; /* shooting flag */
/*
* we need to make sure this would not rotate nor
* move, when it is shooting solid laser
*/
set_coords (&coords_temp, coords.x, coords.y);
update_coords (&coords_temp,
board[coords.x][coords.y].direction);
if (board[coords_temp.x][coords_temp.y].direction ==
board[coords.x][coords.y].direction)
switch (board[coords_temp.x][coords_temp.y].type)
{
case BLASTER:
case SOLID_LASER_L:
case SOLID_LASER_D:
case LASER_L:
case LASER_D:
sflag = 1; /* *neurocyp: we are not supposed to move nor rotate */
break;
}
if (sflag == 0)
{
if (board[coords.x][coords.y].movable)
{ /* *neurocyp: no move during solid laser or blaster shot */
if (can_move (coords, board[x][y].direction2))
{ /* *neurocyp: here probably we should implement stopping during solid laser or blaster shot */
update_coords (&coords,
board[x][y].direction2);
move_object (x, y, coords);
board[coords.x][coords.y].moved = DELAY_GUN;
board[coords.x][coords.y].state =
board[x][y].direction | 0x04;
}
else
{
board[coords.x][coords.y].direction2 =
(board[coords.x][coords.y].direction2 +
2) & 0x03;
board[coords.x][coords.y].state =
board[x][y].direction | 0x04;
board[coords.x][coords.y].moved = DELAY_GUN;
}
}
if (board[coords.x][coords.y].rotable)
{ /* *neurocyp: we will not rotate, when we shoot */
if (board[coords.x][coords.y].rotated == 0)
{
if (board[coords.x][coords.y].randomrotated)
{
temp_direction = rand () & 0x03;
if (board[coords.x][coords.y].movable ==
1)
{
board[coords.x][coords.
y].direction2 =
abs (board[coords.x]
[coords.y].direction2 +
(temp_direction -
board[coords.x][coords.
y].direction))
% 4;
}
board[coords.x][coords.y].direction =
temp_direction;
}
else
{
board[coords.x][coords.y].direction =
(board[coords.x][coords.y].direction +
1) & 0x03;
}
board[coords.x][coords.y].rotated =
DELAY_ROTATION;
redraw_field (coords.x, coords.y);
}
}
}
if (board[coords.x][coords.y].shooted == 0)
{
if (board[coords.x][coords.y].solidlaser == 2)
{
if (((rand ()) & 0x07) == 0)
{ /* it's blaster */
if (in_viewport (x, y))
play_sound (SFX_GUN, SND_NORM);
else
play_sound (SFX_GUN, SND_QUIET);
set_coords (&coords_temp, coords.x,
coords.y);
update_coords (&coords_temp,
board[coords.x][coords.
y].direction);
if (robbo.x == coords_temp.x
&& robbo.y == coords_temp.y
&& robbo.teleporting == FALSE)
{
kill_robbo ();
return; /* Thunor: Exiting here stops new blasters from being created */
}
switch (board[coords_temp.x]
[coords_temp.y].type)
{
case BLASTER:
case TELEPORT:
case MAGNET:
case WALL:
case BOX:
case PUSH_BOX:
case CAPSULE:
case SCREW:
case STOP:
case RADIOACTIVE_FIELD:
case KEY:
case DOOR:
case GUN:
board[coords.x][coords.y].shooted =
DELAY_LASER;
break;
case BOMB2:
case BOMB:
board[coords_temp.x][coords_temp.
y].blowed =
DELAY_LASER;
break;
default:
clear_field (coords_temp.x,
coords_temp.y);
create_object (coords_temp.x,
coords_temp.y, BLASTER);
board[coords_temp.x][coords_temp.y].direction = board[coords.x][coords.y].direction; /* we allow moving blaster guns! */
board[coords_temp.x][coords_temp.
y].direction2 =
board[coords.x][coords.y].direction;
board[coords_temp.x][coords_temp.
y].moved =
DELAY_BLASTER;
board[coords.x][coords.y].shooted =
DELAY_LASER;
}
}
else
board[coords.x][coords.y].shooted =
DELAY_LASER;
}
else
{
if ((rand () & 0x07) == 0)
{
/*
* gun shoots
*/
if (in_viewport (x, y))
play_sound (SFX_GUN, SND_NORM);
else
play_sound (SFX_GUN, SND_QUIET);
shoot_object (coords.x, coords.y,
board[coords.x][coords.
y].direction);
}
else
board[coords.x][coords.y].shooted =
DELAY_LASER;
#ifdef DEBUG_MONITOR_OBJECT_PROCESSING
printf
("--cycle_count=%i: board[coords.x=%i][coords.y=%i].processed=%i\n",
cycle_count, coords.x, coords.y,
board[coords.x][coords.y].processed);
if (board[coords.x][coords.y].processed !=
cycle_count)
printf
("--OBJECT NOT MARKED AS PROCESSED FOR THIS CYCLE! <<<<<<<<<<\n");
/*
* printf("--cycle_count=%i:
* board[dest.x=%i][dest.y=%i].processed=%i\n",
* cycle_count, dest.x, dest.y,
* board[dest.x][dest.y].processed);
*/
/*
* if (board[dest.x][dest.y].processed !=
* cycle_count) printf("--OBJECT NOT
* MARKED AS PROCESSED FOR THIS CYCLE!
* <<<<<<<<<<\n");
*/
#endif
}
}
if (board[coords.x][coords.y].type == GUN
&& board[coords.x][coords.y].movable == 1)
board[coords.x][coords.y].state = board[coords.x][coords.y].direction + 0x04; /* neurocyp: we want movable guns to have different icons */
else
board[coords.x][coords.y].state =
board[coords.x][coords.y].direction;
break;
}
}
#ifdef LIGHTNINGENABLED
switch (board[x][y].type)
{
case CAPSULE:
if (robbo.exitopened == FALSE)
break;
case TELEPORT:
case TELEPORTING:
case LITTLE_BOOM:
case BIG_BOOM:
seteffectsurround (x, y, board[x][y].state + 1);
}
#endif
} /* .processed check */
}
}
}
/************************************************************/
/********** Init questionmark objects **********************/
/************************************************************/
void
init_questionmarks (void)
{
int i, j;
for (i = 0; i < level.w; i++)
for (j = 0; j < level.h; j++)
{
if (board[i][j].type == QUESTIONMARK)
{
board[i][j].id_questionmark = random_id ();
}
}
}
/***************************************************************************
* Returning really random object *
***************************************************************************/
/*
* Function returning random object id
*/
int
random_id (void)
{
int ids[11] = { EMPTY_FIELD, PUSH_BOX, SCREW, BULLET, KEY, BOMB, GROUND,
BUTTERFLY, GUN,
QUESTIONMARK, CAPSULE
};
if (game_mechanics.sensible_questionmarks)
{
return ids[my_rand () % 10];
}
else
{
return ids[my_rand () % 11];
}
}
/******************************************************/
/*
* Update Coords *************************************
*/
/******************************************************/
/*
* Note that if modifying the coords results in them going off-board then
* the coords returned are the same as passed
*/
int
update_coords (struct Coords *coords, int direction)
{
struct Coords coords_temp;
coords_temp.x = coords->x;
coords_temp.y = coords->y;
if (direction == 0)
coords->x++;
else if (direction == 1)
coords->y++;
else if (direction == 2)
coords->x--;
else
coords->y--;
if (coords->x < 0 || coords->y < 0 || coords->x >= level.w
|| coords->y >= level.h)
{
set_coords (coords, coords_temp.x, coords_temp.y);
return 1;
}
return 0;
}
/******************************************************/
/*
* Set Coords ****************************************
*/
/******************************************************/
void
set_coords (struct Coords *coords, int x, int y)
{
coords->x = x;
coords->y = y;
}
/******************************************************/
/*
* Coords Out Of Range *******************************
*/
/******************************************************/
int
coords_out_of_range (struct Coords coords)
{
if (coords.x < 0 || coords.x >= level.w || coords.y < 0
|| coords.y >= level.h)
return 1;
else
return 0;
}
/*************************************************************/
/*
* Negating object state (birds waves their wings etc.. *****
*/
/*************************************************************/
void
negate_state (int x, int y)
{
if (x < level.w && y < level.h)
{
board[x][y].state = !board[x][y].state;
board[x][y].redraw = TRUE;
}
}
/******************************************************/
/*
* Set Images ****************************************
*/
/******************************************************/
/*
* translate coordinates in the icons file, so we do not have to know the
* precise values, just where the icon is located
*/
int
gcoord (int a)
{ /* this should be a macro, but if we would change the border sizes, we should include it now for tile size 16 border size is 1 and for ts=32 the border size is 2 */
return ((video.field_size / 16) * a) + ((a - 1) * video.field_size);
}
/*
* Neurocyp: refactored it a bit, so it could be ready to increase the
* tile size in the future
*/
void
set_images (int type, int x, int y)
{
switch (type)
{
case EMPTY_FIELD:
set_coords (&board[x][y].icon[0], 0, 0);
break;
case WALL: /* setting coords for icon */
set_coords (&board[x][y].icon[0], gcoord (3), gcoord (1)); /* WALL */
set_coords (&board[x][y].icon[1], gcoord (4), gcoord (1)); /* WALL_RED */
set_coords (&board[x][y].icon[2], gcoord (6), gcoord (3)); /* WALL_GREEN */
set_coords (&board[x][y].icon[3], gcoord (8), gcoord (2)); /* BLACK_WALL */
set_coords (&board[x][y].icon[4], gcoord (10), gcoord (2)); /* FAT_WALL */
set_coords (&board[x][y].icon[5], gcoord (9), gcoord (6)); /* ROUND_WALL */
set_coords (&board[x][y].icon[6], gcoord (10), gcoord (6)); /* BOULDER_WALL */
set_coords (&board[x][y].icon[7], gcoord (11), gcoord (1)); /* SQUARE_WALL */
set_coords (&board[x][y].icon[8], gcoord (11), gcoord (2)); /* LATTICE_WALL */
set_coords (&board[x][y].icon[9], gcoord (1), gcoord (9)); /* Special Wall1 */
set_coords (&board[x][y].icon[10], gcoord (2), gcoord (9)); /* Special Wall1 */
set_coords (&board[x][y].icon[11], gcoord (3), gcoord (9)); /* Special Wall1 */
set_coords (&board[x][y].icon[12], gcoord (4), gcoord (9)); /* Special Wall1 */
set_coords (&board[x][y].icon[13], gcoord (5), gcoord (9)); /* Special Wall1 */
set_coords (&board[x][y].icon[14], gcoord (6), gcoord (9)); /* Special Wall1 */
set_coords (&board[x][y].icon[15], gcoord (7), gcoord (9)); /* Special Wall1 */
set_coords (&board[x][y].icon[16], gcoord (8), gcoord (9)); /* Special Wall1 */
//set_coords(&board[x][y].icon[17], gcoord(8),gcoord(9)); /* Special Wall1 */
set_coords (&board[x][y].icon[17], gcoord (1), gcoord (10)); /* Special Wall1 */
set_coords (&board[x][y].icon[18], gcoord (2), gcoord (10)); /* Special Wall1 */
set_coords (&board[x][y].icon[19], gcoord (3), gcoord (10)); /* Special Wall1 */
set_coords (&board[x][y].icon[20], gcoord (4), gcoord (10)); /* Special Wall1 */
set_coords (&board[x][y].icon[21], gcoord (5), gcoord (10)); /* Special Wall1 */
set_coords (&board[x][y].icon[22], gcoord (6), gcoord (10)); /* Special Wall1 */
set_coords (&board[x][y].icon[23], gcoord (7), gcoord (10)); /* Special Wall1 */
set_coords (&board[x][y].icon[24], gcoord (8), gcoord (10)); /* Special Wall1 */
break;
case SCREW:
set_coords (&board[x][y].icon[0], gcoord (5), gcoord (1));
break;
case BULLET:
set_coords (&board[x][y].icon[0], gcoord (6), gcoord (1));
break;
case BOX:
set_coords (&board[x][y].icon[0], gcoord (7), gcoord (1));
break;
case PUSH_BOX:
set_coords (&board[x][y].icon[0], gcoord (7), gcoord (7));
set_coords (&board[x][y].icon[1], gcoord (9), gcoord (2)); /* pushed box changes state */
break;
case KEY:
set_coords (&board[x][y].icon[0], gcoord (8), gcoord (1));
break;
case BOMB2:
set_coords (&board[x][y].icon[0], gcoord (8), gcoord (7));
break;
case BOMB:
set_coords (&board[x][y].icon[0], gcoord (9), gcoord (1));
break;
case DOOR:
set_coords (&board[x][y].icon[0], gcoord (10), gcoord (1));
break;
case QUESTIONMARK:
set_coords (&board[x][y].icon[0], gcoord (1), gcoord (2));
break;
case CAPSULE:
set_coords (&board[x][y].icon[0], gcoord (6), gcoord (2));
set_coords (&board[x][y].icon[1], gcoord (7), gcoord (2));
break;
case BEAR:
set_coords (&board[x][y].icon[0], gcoord (2), gcoord (2));
set_coords (&board[x][y].icon[1], gcoord (3), gcoord (2));
break;
case BIRD:
set_coords (&board[x][y].icon[0], gcoord (4), gcoord (2));
set_coords (&board[x][y].icon[1], gcoord (5), gcoord (2));
break;
case LITTLE_BOOM:
set_coords (&board[x][y].icon[0], gcoord (2), gcoord (3));
set_coords (&board[x][y].icon[1], gcoord (3), gcoord (3));
set_coords (&board[x][y].icon[2], gcoord (4), gcoord (3));
set_coords (&board[x][y].icon[3], gcoord (5), gcoord (3));
break;
case GROUND:
set_coords (&board[x][y].icon[0], gcoord (6), gcoord (7));
break;
case BEAR_B:
set_coords (&board[x][y].icon[0], gcoord (7), gcoord (3));
set_coords (&board[x][y].icon[1], gcoord (8), gcoord (3));
break;
case BUTTERFLY:
set_coords (&board[x][y].icon[0], gcoord (9), gcoord (3));
set_coords (&board[x][y].icon[1], gcoord (10), gcoord (3));
break;
case LASER_L:
set_coords (&board[x][y].icon[0], gcoord (1), gcoord (4));
set_coords (&board[x][y].icon[1], gcoord (2), gcoord (4));
set_coords (&board[x][y].icon[2], gcoord (1), gcoord (3)); /* Thunor: Added for solid lasers */
set_coords (&board[x][y].icon[3], gcoord (6), gcoord (8));
break;
case LASER_D:
set_coords (&board[x][y].icon[0], gcoord (3), gcoord (4));
set_coords (&board[x][y].icon[1], gcoord (4), gcoord (4));
set_coords (&board[x][y].icon[2], gcoord (6), gcoord (4)); /* Thunor: Added for solid lasers */
set_coords (&board[x][y].icon[3], gcoord (7), gcoord (8)); /* Thunor: Added for solid lasers */
break;
case TELEPORT:
set_coords (&board[x][y].icon[0], gcoord (1), gcoord (5));
set_coords (&board[x][y].icon[1], gcoord (2), gcoord (5));
break;
case TELEPORTING: /* Thunor: Added for dedicated teleport animation */
set_coords (&board[x][y].icon[0], gcoord (11), gcoord (4));
set_coords (&board[x][y].icon[1], gcoord (11), gcoord (5));
set_coords (&board[x][y].icon[2], gcoord (11), gcoord (6));
set_coords (&board[x][y].icon[3], gcoord (11), gcoord (7));
set_coords (&board[x][y].icon[4], gcoord (11), gcoord (8));
break;
case BIG_BOOM:
set_coords (&board[x][y].icon[0], gcoord (1), gcoord (8)); /* Neurocyp: Added to distinguish booms from blasters */
set_coords (&board[x][y].icon[1], gcoord (2), gcoord (8));
set_coords (&board[x][y].icon[2], gcoord (3), gcoord (8));
set_coords (&board[x][y].icon[3], gcoord (4), gcoord (8));
set_coords (&board[x][y].icon[4], gcoord (5), gcoord (8));
break;
case GUN:
set_coords (&board[x][y].icon[0], gcoord (6), gcoord (5));
set_coords (&board[x][y].icon[1], gcoord (7), gcoord (5));
set_coords (&board[x][y].icon[2], gcoord (8), gcoord (5));
set_coords (&board[x][y].icon[3], gcoord (9), gcoord (5));
set_coords (&board[x][y].icon[4], gcoord (9), gcoord (8));
set_coords (&board[x][y].icon[5], gcoord (10), gcoord (7));
set_coords (&board[x][y].icon[6], gcoord (10), gcoord (8));
set_coords (&board[x][y].icon[7], gcoord (9), gcoord (7));
break;
case MAGNET:
set_coords (&board[x][y].icon[0], gcoord (1), gcoord (1));
set_coords (&board[x][y].icon[1], gcoord (1), gcoord (7));
set_coords (&board[x][y].icon[2], gcoord (2), gcoord (1));
set_coords (&board[x][y].icon[3], gcoord (2), gcoord (7));
break;
case BLASTER:
set_coords (&board[x][y].icon[0], gcoord (3), gcoord (5));
set_coords (&board[x][y].icon[1], gcoord (4), gcoord (5));
set_coords (&board[x][y].icon[2], gcoord (5), gcoord (5));
set_coords (&board[x][y].icon[3], gcoord (4), gcoord (5));
set_coords (&board[x][y].icon[4], gcoord (3), gcoord (5));
break;
case BARRIER:
set_coords (&board[x][y].icon[0], gcoord (10), gcoord (4));
set_coords (&board[x][y].icon[1], gcoord (10), gcoord (5));
break;
case RADIOACTIVE_FIELD:
set_coords (&board[x][y].icon[0], gcoord (3), gcoord (7));
set_coords (&board[x][y].icon[1], gcoord (4), gcoord (7));
break;
case STOP:
set_coords (&board[x][y].icon[0], gcoord (5), gcoord (7));
break;
}
}
/************************************************************/
/*
* This function checks if object can move on the field ****
*/
/*
* described by direction and coordinates, if not returns 0
*/
/************************************************************/
int
can_move (struct Coords coords, int direction)
{
if (update_coords (&coords, direction) ||
(board[coords.x][coords.y].type != EMPTY_FIELD) ||
((robbo.x == coords.x) && (robbo.y == coords.y)) ||
board[coords.x][coords.y].moved > 0)
return 0;
else
return 1;
}
/**************************************************/
/*
* Function moves object deleting object data ****
*/
/*
* from one field and moves them to another ******
*/
/**************************************************/
void
move_object (int x, int y, struct Coords coords)
{
int x1, y1;
if ((x == coords.x) && (y == coords.y)) /* move to the same place */
return;
x1 = coords.x;
y1 = coords.y;
board[x1][y1].type = board[x][y].type;
board[x1][y1].state = board[x][y].state;
board[x1][y1].direction = board[x][y].direction;
board[x1][y1].destroyable = board[x][y].destroyable;
board[x1][y1].blowable = board[x][y].blowable;
board[x1][y1].killing = board[x][y].killing;
board[x1][y1].moved = board[x][y].moved;
board[x1][y1].blowed = board[x][y].blowed;
board[x1][y1].shooted = board[x][y].shooted;
board[x1][y1].rotated = board[x][y].rotated;
board[x1][y1].solidlaser = board[x][y].solidlaser;
board[x1][y1].rotable = board[x][y].rotable;
board[x1][y1].randomrotated = board[x][y].randomrotated;
/*
* NOTE: teleportnumber is not being moved
*/
/*
* NOTE: teleportnumber2 is not being moved
*/
board[x1][y1].id_questionmark = board[x][y].id_questionmark;
board[x1][y1].direction2 = board[x][y].direction2;
board[x1][y1].movable = board[x][y].movable;
/*
* NOTE: returnlaser is not being moved
*/
board[x1][y1].shooting = board[x][y].shooting;
board[x1][y1].processed = board[x][y].processed;
board[x1][y1].redraw = TRUE;
set_images (board[x1][y1].type, x1, y1);
clear_field (x, y);
}
/*************************************************************/
/******* If objects shoots... ********************************/
/*************************************************************/
void
shoot_object (int x, int y, int direction)
{
struct Coords coords;
if (board[x][y].shooted > 0)
return;
#ifdef LIGHTNINGENABLED
board[x][y].effect = EFX_SHOOT;
#endif
set_coords (&coords, x, y);
if (update_coords (&coords, direction))
{
board[coords.x][coords.y].shooted = DELAY_LASER;
return;
}
if ((coords.x == robbo.x) && (coords.y == robbo.y))
{
kill_robbo ();
return; /* This prevents more lasers being created after Robbo dies */
}
switch (board[coords.x][coords.y].destroyable)
{
case 1:
if ((board[coords.x][coords.y].type != BOMB)
&& (board[coords.x][coords.y].type != BOMB2))
{
if (in_viewport (x, y))
play_sound (SFX_KILL, SND_NORM);
else
play_sound (SFX_KILL, SND_QUIET);
}
board[coords.x][coords.y].blowed = 1;
board[coords.x][coords.y].shooted = DELAY_LASER;
if (board[x][y].solidlaser == 1)
{
board[x][y].moved = DELAY_LASER;
}
return;
default:
break;
}
switch (board[coords.x][coords.y].type)
{
case EMPTY_FIELD:
if (direction == 0 || direction == 2)
{
clear_field (coords.x, coords.y);
create_object (coords.x, coords.y, LASER_L);
}
else
{
clear_field (coords.x, coords.y);
create_object (coords.x, coords.y, LASER_D);
}
board[coords.x][coords.y].direction = direction;
board[coords.x][coords.y].solidlaser = board[x][y].solidlaser;
board[x][y].shooted = DELAY_LASER;
board[coords.x][coords.y].moved = DELAY_LASER;
/*
* Thunor: I decided to use different animation frame(s) for the
* solid laser fire to make the graphics more interesting
*/
if (board[coords.x][coords.y].solidlaser == 1)
board[coords.x][coords.y].state =
(board[x][y].state == 3) ? board[x][y].state : (rand () % 2) + 2;
break;
case LASER_D:
case LASER_L:
break;
}
}
/****************************************************************/
/*
* Function marks all objects blowed around the bomb ***********
*/
/****************************************************************/
void
blow_bomb (int x, int y)
{
struct Coords coords, laserpath;
int i, x1, y1;
if (robbo.alive)
{
if (in_viewport (x, y))
play_sound (SFX_BOMB, SND_NORM);
else
play_sound (SFX_BOMB, SND_QUIET);
}
if (!robbo.alive)
{ /* neurocyp: Robbo is not alive, we do not blow the bomb, we just create BIG_BOOM in its place */
create_object (x, y, BIG_BOOM);
board[x][y].moved = DELAY_BIGBOOM;
return;
}
for (i = 0; i < 9; i++)
{ /* neurocyp: here there was an ugly switch statement, now replaced with a little formula */
x1 = (((i % 3) > 1) ? -1 : (i % 3));
y1 = ((((i / 3) % 3) > 1) ? -1 : ((i / 3) % 3));
coords.x = x + x1;
coords.y = y + y1;
/*
* Robbo was near blowing up
*/
if ((robbo.x == coords.x) && (robbo.y == coords.y))
{
kill_robbo ();
}
/*
* Blow-up the object
*/
if (!coords_out_of_range (coords) && !board[coords.x][coords.y].blowed
&& board[coords.x][coords.y].blowable)
{
if (board[coords.x][coords.y].type == GUN)
{
board[coords.x][coords.y].blowed = 1;
board[coords.x][coords.y].moved = DELAY_BOMB_TARGET;
/*
* Thunor: In Atari Robbo the solid laser fire is left
* live when the gun is destroyed which is a bit
* nonsensical so I have introduced an rcfile overrideable
* game_mechanic.sensible_solid_lasers
*/
if (board[coords.x][coords.y].solidlaser
&& game_mechanics.sensible_solid_lasers)
{
set_coords (&laserpath, coords.x, coords.y);
while (!update_coords
(&laserpath, (board[coords.x][coords.y].direction))
&& (board[laserpath.x][laserpath.y].type == LASER_D
|| board[laserpath.x][laserpath.y].type ==
LASER_L)
&& board[laserpath.x][laserpath.y].solidlaser
&& board[laserpath.x][laserpath.y].direction ==
board[coords.x][coords.y].direction)
{
board[laserpath.x][laserpath.y].blowed = 1;
board[laserpath.x][laserpath.y].moved =
DELAY_BOMB_TARGET;
}
}
/*
* Thunor: In Atari Robbo the solid laser is not blowable
* but in GNU Robbo there is no solid laser type, so I
* need to check the solidlaser property here
*/
}
else
if (!
((board[coords.x][coords.y].type == LASER_D
|| board[coords.x][coords.y].type == LASER_L)
&& board[coords.x][coords.y].solidlaser))
{
board[coords.x][coords.y].blowed = 1;
board[coords.x][coords.y].moved = DELAY_BOMB_TARGET;
board[coords.x][coords.y].id_questionmark = 0; /* blowed questionmark doesn't uncover */
}
}
}
}
/* Robbo Alex has at leas two different bomb types, here is the place, where we blow these */
/* routine is very similar to regular bomb */
void
blow_bomb2 (int x, int y)
{
struct Coords coords, laserpath;
int i, direction = -1, x1, y1;
if (robbo.alive)
{
if (in_viewport (x, y))
play_sound (SFX_BOMB, SND_NORM);
else
play_sound (SFX_BOMB, SND_QUIET);
}
if (!robbo.alive)
{ /* neurocyp: Robbo is not alive, we do not blow the bomb, we just create BIG_BOOM in its place */
create_object (x, y, BIG_BOOM);
board[x][y].moved = DELAY_BIGBOOM;
return;
}
for (i = 0; i < 9; i++)
{
x1 = (((i % 3) > 1) ? -1 : (i % 3)); /* neurocyp: move on x axis */
y1 = ((((i / 3) % 3) > 1) ? -1 : ((i / 3) % 3)); /* neurocyp: move on y axis */
coords.x = x + x1;
coords.y = y + y1;
if (x1 == 0 || y1 == 0)
direction = (x1 != 0) ? (-x1 + 1) : (-y1 + 2); /* calculate a direction */
/* Robbo was near the bomb */
if ((robbo.x == coords.x) && (robbo.y == coords.y))
{
kill_robbo ();
}
/*
* Blow-up the object
*/
if (x1 != 0 && y1 != 0)
{
if (!coords_out_of_range (coords)
&& !board[coords.x][coords.y].blowed
&& board[coords.x][coords.y].blowable)
{
if (board[coords.x][coords.y].type == GUN)
{
board[coords.x][coords.y].blowed = 1;
board[coords.x][coords.y].moved = DELAY_BOMB_TARGET;
/*
* Thunor: In Atari Robbo the solid laser fire is left
* live when the gun is destroyed which is a bit
* nonsensical so I have introduced an rcfile overrideable
* game_mechanic.sensible_solid_lasers
*/
if (board[coords.x][coords.y].solidlaser
&& game_mechanics.sensible_solid_lasers)
{
set_coords (&laserpath, coords.x, coords.y);
while (!update_coords
(&laserpath,
(board[coords.x][coords.y].direction))
&& (board[laserpath.x][laserpath.y].type ==
LASER_D
|| board[laserpath.x][laserpath.y].type ==
LASER_L)
&& board[laserpath.x][laserpath.y].solidlaser
&& board[laserpath.x][laserpath.y].direction ==
board[coords.x][coords.y].direction)
{
board[laserpath.x][laserpath.y].blowed = 1;
board[laserpath.x][laserpath.y].moved =
DELAY_BOMB_TARGET;
}
}
/*
* Thunor: In Atari Robbo the solid laser is not blowable
* but in GNU Robbo there is no solid laser type, so I
* need to check the solidlaser property here
*/
}
else
if (!
((board[coords.x][coords.y].type == LASER_D
|| board[coords.x][coords.y].type == LASER_L)
&& board[coords.x][coords.y].solidlaser))
{
board[coords.x][coords.y].blowed = 1;
board[coords.x][coords.y].moved = DELAY_BOMB_TARGET;
board[coords.x][coords.y].id_questionmark = 0; /* blowed questionmark doesn't uncover */
}
}
}
else
{ /* we have to shoot in 4 directions */
shoot_object (x, y, direction);
board[coords.x][coords.y].moved = DELAY_BOMB_TARGET;
if (i < 7)
board[x][y].shooted = 0; /* yes, we want to shoot again this tiime, really fast, that is why we reset this */
}
}
}
/*****************************************************/
/**** Check Object If Blowed *************************/
/*****************************************************/
/*
* Thunor: NOTE that the object that is being created here is not cleared
* beforehand. The reason for this I have found is because once it has
* blown-up, its id_questionmark property is checked to see if it was a
* questionmark and if it needs to be recreated
*/
void
check_object_if_blowed (int x, int y)
{
if (board[x][y].blowed && board[x][y].type != BIG_BOOM)
{
if (board[x][y].type == BOMB)
blow_bomb (x, y);
if (board[x][y].type == BOMB2)
blow_bomb2 (x, y);
create_object (x, y, BIG_BOOM);
board[x][y].moved = DELAY_BIGBOOM;
}
}
/**********************************************************/
/** If Robbo collects the last screw exit opens ***********/
/**********************************************************/
void
open_exit (void)
{
robbo.exitopened = 1;
level.now_is_blinking = DELAY_BLINKSCREEN;
viewport_needs_redrawing ();
}
/*************************************************************/
/**** Function returning coords of finding teleport **********/
/**** Updates coords of found teleport of 0 if not found *****/
/*************************************************************/
int
find_teleport (struct Coords *coords, int teleportnumber, int teleportnumber2)
{
int i, j;
for (i = 0; i < level.w; i++)
for (j = 0; j < level.h; j++)
{
if (board[i][j].type == TELEPORT)
{
if (teleportnumber == board[i][j].teleportnumber)
{ /* found the same kind */
if (teleportnumber2 == board[i][j].teleportnumber2)
{ /* next teleport */
set_coords (coords, i, j);
return 1; /* found exact_teleport */
}
}
}
}
return 0; /* teleport with this number has not been found... */
}
/***************************************************************************
* Robbo initialisation *
***************************************************************************/
/*
* Clear everything
*/
void
init_robbo (void)
{
robbo.x = 0;
robbo.y = 0;
robbo.alive = 1;
robbo.state = 0;
robbo.direction = 0;
robbo.screws = 0;
robbo.keys = 0;
robbo.bullets = 0;
robbo.moved = DELAY_ROBBO;
robbo.shooted = 0;
robbo.exitopened = 0;
robbo.blocked = 0;
robbo.blocked_direction = 0;
robbo.teleporting = 0;
}
/********************************************************************/
/*** Robbo moving function ******************************************/
/********************************************************************/
void
move_robbo (int x, int y)
{
int x_tmp, y_tmp, x2_tmp, y2_tmp;
int i, j, k;
int dir_tmp;
struct Coords coords;
if (robbo.blocked || robbo.moved > 0)
{
return;
}
// if (robbo.moved > 0)
// /* robbo cannot move yet */
// return;
x_tmp = robbo.x + x;
y_tmp = robbo.y + y;
if ((x == 1) && (y == 0))
robbo.direction = 0;
else if ((x == 0) && (y == 1))
robbo.direction = 2;
else if ((x == -1) && (y == 0))
robbo.direction = 4;
else if ((x == 0) && (y == -1))
robbo.direction = 6;
if (x_tmp < 0 || x_tmp >= level.w || y_tmp < 0 || y_tmp >= level.h)
return;
redraw_field (robbo.x, robbo.y); /* Redraw the source field */
switch (board[x_tmp][y_tmp].type)
{
case STOP:
clear_field (x_tmp, y_tmp);
break;
case RADIOACTIVE_FIELD:
clear_field (x_tmp, y_tmp);
kill_robbo ();
break;
case EMPTY_FIELD:
case ROBBO: /* Robbo can move there */
redraw_field (x_tmp, y_tmp); /* Redraw destination field */
break;
case SCREW:
if (robbo.screws > 0)
{
robbo.screws--;
}
if (robbo.screws == 0)
{ /* play sound for open exit */
play_sound (SFX_EXIT_OPEN, SND_NORM);
open_exit ();
}
else
play_sound (SFX_SCREW, SND_NORM); /* play sound for collected screw */
scoreline.redraw |= SCORELINE_SCREWS;
clear_field (x_tmp, y_tmp);
break;
case BULLET:
play_sound (SFX_BULLET, SND_NORM); /* play sound for collected ammo */
robbo.bullets += 9;
scoreline.redraw |= SCORELINE_BULLETS;
clear_field (x_tmp, y_tmp);
break;
case KEY:
play_sound (SFX_KEY, SND_NORM); /* play sound for collected key */
robbo.keys++;
scoreline.redraw |= SCORELINE_KEYS;
clear_field (x_tmp, y_tmp);
break;
case DOOR: /* Robbo cannot move */
if (robbo.keys > 0)
{ /* should open the door first */
robbo.keys--;
scoreline.redraw |= SCORELINE_KEYS;
clear_field (x_tmp, y_tmp);
robbo.moved = DELAY_ROBBO;
play_sound (SFX_DOOR, SND_NORM); /* play sound for door open */
}
return;
case TELEPORT:
if (board[x_tmp][y_tmp].teleportnumber == 0)
break;
play_sound (SFX_TELEPORT, SND_NORM); /* teleport sound */
i = 0;
j = board[x_tmp][y_tmp].teleportnumber2;
while (i == 0)
{
j++;
if (((find_teleport
(&coords, board[x_tmp][y_tmp].teleportnumber, j)) == 0)
&& j != board[x_tmp][y_tmp].teleportnumber2)
{ /* teleport not found */
if (j > MAX_TELEPORT_IDS)
j = -1;
continue;
}
dir_tmp = (robbo.direction / 2); /* neurocyp * new teleport logic now it should be the same as original robbo logic */
for (k = 0; k < 4; k++)
{ /* first time, the direction, where robbo tries to go is checked */
if (can_move (coords, dir_tmp))
{
create_object (robbo.x, robbo.y, TELEPORTING); /* Create src teleporting animation */
update_coords (&coords, dir_tmp);
x_tmp = coords.x;
y_tmp = coords.y;
robbo.direction = (dir_tmp * 2);
create_object (x_tmp, y_tmp, TELEPORTING); /* Create dest teleporting animation */
robbo.moved = DELAY_TELEPORTING * 5; /* 5 frames of teleporting animation */
viewport.cycles_to_dest = robbo.moved;
robbo.teleporting = TRUE;
i = 1;
break;
}
dir_tmp = dir_tmp ^ (((k + 1) % 2) + 2);
}
if (j == board[x_tmp][y_tmp].teleportnumber2 && i == 0)
{ /* protect from freezing the game */
create_object (robbo.x, robbo.y, TELEPORTING); /* Create src/dest teleporting animation */
robbo.moved = DELAY_TELEPORTING * 5; /* 5 frames of teleporting animation */
viewport.cycles_to_dest = robbo.moved;
robbo.teleporting = TRUE;
i = 1;
return;
}
}
break;
case CAPSULE:
if (robbo.exitopened)
{
play_sound (SFX_CAPSULE, SND_NORM);
/*
* Check for pack completion
*/
if (level_packs[selected_pack].level_selected >=
level_packs[selected_pack].last_level)
{
game_mode = END_SCREEN;
return;
}
else
{
level_packs[selected_pack].level_selected++;
if (level_packs[selected_pack].level_selected >
level_packs[selected_pack].level_reached)
{
level_packs[selected_pack].level_reached =
level_packs[selected_pack].level_selected;
/*
* Save rcfile now if requested -- recommended for
* battery operated or unstable devices
*/
if (rcfile.save_frequency == RCFILE_SAVE_ON_CHANGE)
{
save_resource_file (path_resource_file, FALSE);
#if defined(PLATFORM_WIN32) || defined(PLATFORM_PC)
#elif defined(PLATFORM_GP2X) || defined(PLATFORM_CAANOO)
system ("sync");
#elif defined(PLATFORM_ZAURUS)
#elif defined(PLATFORM_PSP)
#endif
}
}
if (level_init ())
{
game_mode = INTRO_SCREEN;
music_stop ();
intro_screen.redraw |= REDRAW_INITIALISE;
}
else
{
game_area.redraw |= REDRAW_EVERYTHING;
/*
* Initialise the fade
*/
show_game_area_fade (FADE_SUB_INITIALISE, 16);
}
return;
}
}
case BOX: /* Moveable objects */
case PUSH_BOX:
case BOMB:
case BOMB2:
case QUESTIONMARK:
case GUN:
if ((board[x_tmp][y_tmp].type == GUN)
&& (board[x_tmp][y_tmp].movable == 0))
return;
y2_tmp = robbo.y + (2 * y);
x2_tmp = robbo.x + (2 * x);
if (x2_tmp < 0 || x2_tmp >= level.w || y2_tmp < 0 || y2_tmp >= level.h)
return;
coords.x = x2_tmp;
coords.y = y2_tmp;
if (board[x2_tmp][y2_tmp].type == EMPTY_FIELD)
{
play_sound (SFX_BOX, SND_NORM);
if (board[x_tmp][y_tmp].type == PUSH_BOX)
{
board[x_tmp][y_tmp].state = 1; /* box is pushed */
board[x_tmp][y_tmp].direction = (robbo.direction / 2);
}
move_object (x_tmp, y_tmp, coords);
if (board[coords.x][coords.y].type != GUN)
board[coords.x][coords.y].moved = DELAY_PUSHBOX;
}
else
{
robbo.moved = DELAY_ROBBO;
return;
}
break;
default: /* every else objects */
return;
}
robbo.x = x_tmp;
robbo.y = y_tmp;
if (robbo.moved == 0)
{
robbo.moved = DELAY_ROBBO; /* delay robbo */
if (!robbo.blocked)
play_sound (SFX_ROBBO, SND_NORM);
}
}
/*********************************************************/
/** Robbo shoots - x, y means coords of Robbo ************/
/*********************************************************/
void
shoot_robbo (int x, int y)
{
int x_tmp, y_tmp;
if (robbo.shooted > 0)
return;
/*
* Is Robbo currently being pulled by a magnet or teleporting?
*/
if (robbo.blocked || robbo.teleporting)
return; /* Matches original Robbo */
x_tmp = robbo.x + x;
y_tmp = robbo.y + y;
if ((x == 1) && (y == 0))
robbo.direction = 0;
else if ((x == 0) && (y == 1))
robbo.direction = 2;
else if ((x == -1) && (y == 0))
robbo.direction = 4;
else if ((x == 0) && (y == -1))
robbo.direction = 6;
redraw_field (robbo.x, robbo.y);
if (robbo.bullets == 0)
return;
if (x_tmp < 0 || x_tmp >= level.w || y_tmp < 0 || y_tmp >= level.h)
{
robbo.bullets--;
robbo.shooted = DELAY_LASER;
return;
}
switch (board[x_tmp][y_tmp].destroyable)
{
case 1: /* objects can be destroyed */
board[x_tmp][y_tmp].blowed = 1;
play_sound (SFX_SHOOT, SND_QUIET);
if (board[x_tmp][y_tmp].type != BOMB)
{
// printf("%d\n", board[x_tmp][y_tmp].type);
play_sound (SFX_KILL, SND_NORM);
}
robbo.shooted = DELAY_LASER;
robbo.bullets--;
scoreline.redraw |= SCORELINE_BULLETS;
return;
case 0:
play_sound (SFX_SHOOT, SND_NORM);
robbo.shooted = DELAY_LASER;
robbo.bullets--;
scoreline.redraw |= SCORELINE_BULLETS;
break;
}
switch (board[x_tmp][y_tmp].type)
{
case EMPTY_FIELD:
if (robbo.direction == 0 || robbo.direction == 4)
create_object (x_tmp, y_tmp, LASER_L);
else
create_object (x_tmp, y_tmp, LASER_D);
board[x_tmp][y_tmp].moved = DELAY_LASER;
board[x_tmp][y_tmp].direction = robbo.direction / 2;
break;
}
}
/***************************************************************************
* Is Robbo Killed *
***************************************************************************/
/*
* This function checks to see if Robbo is next to an object that can kill
* i.e. killing = 1. It is called every cycle from update_game()
*/
/*
* On exit: returns TRUE if Robbo is next to an object that can kill else
* returns FALSE
*/
int
is_robbo_killed (void)
{
int retval = FALSE;
if (!robbo.teleporting)
{
if ((robbo.x < level.w - 1 && board[robbo.x + 1][robbo.y].killing == 1) || /* Robbo's right */
(robbo.x > 0 && board[robbo.x - 1][robbo.y].killing == 1) || /* Robbo's left */
(robbo.y < level.h - 1 && board[robbo.x][robbo.y + 1].killing == 1) || /* Robbo's bottom */
(robbo.y > 0 && board[robbo.x][robbo.y - 1].killing == 1))
{ /* Robbo's top */
retval = TRUE;
}
}
return retval;
}
/*************************************************/
/*** Robbo doesn't like this function :) *********/
/*************************************************/
/*
* Everything except EMPTY_FIELDs and WALLs is blown-up here. Once this
* has been executed the once, repeated calls to this function do nothing.
*/
void
kill_robbo (void)
{
int x, y;
if (robbo.alive == 0)
return;
robbo.alive = 0;
robbo.blocked = 0;
play_sound (SFX_BOMB, SND_NORM);
create_object (robbo.x, robbo.y, BIG_BOOM);
board[robbo.x][robbo.y].moved = DELAY_BIGBOOM;
for (x = 0; x < level.w; x++)
for (y = 0; y < level.h; y++)
switch (board[x][y].type)
{
case EMPTY_FIELD:
case WALL:
break;
default:
board[x][y].moved = DELAY_BIGBOOM;
board[x][y].blowed = 1;
}
viewport_needs_redrawing ();
restart_timeout = DELAY_RESTART;
}
/***************************************************************************
* Viewport Needs Redrawing *
***************************************************************************/
/*
* This function marks every field for redrawing/refreshing in
* show_game_area()
*/
#ifdef _SMOOTH_SCRL_
void
viewport_needs_redrawing (void)
{
int x, y, vx = floor ((float) viewport.x / SCRL_MULT2), vy =
floor ((float) viewport.y / SCRL_MULT2);
for (y = vy; y < vy + viewport.h + 1; y++)
{
for (x = vx; x < vx + viewport.w + 1; x++)
{
redraw_field (x, y);
}
}
}
#else
void
viewport_needs_redrawing (void)
{
int x, y;
for (y = viewport.y; y < viewport.y + viewport.h; y++)
{
for (x = viewport.x; x < viewport.x + viewport.w; x++)
{
redraw_field (x, y);
}
}
}
#endif
/***************************************************************************
* Redraw Field *
***************************************************************************/
/*
* Marks an object for redrawing/refreshing in show_game_area()
*/
void
redraw_field (int x, int y)
{
if (x >= 0 && y >= 0 && x < level.w && y < level.h)
board[x][y].redraw = TRUE;
}
/***************************************************************************
* Field clearing *
***************************************************************************/
/*
* This creates a blowable EMPTY_FIELD. This function clears
* id_questionmark whereas create_object() doesn't
*/
void
clear_field (int x, int y)
{
create_object (x, y, EMPTY_FIELD);
board[x][y].id_questionmark = 0;
}
/***************************************************************************
* Create Object *
***************************************************************************/
/*
* Thunor: I have found that most of the time clear_field() has been
* called before this function, but there are times when it hasn't such as
* via check_object_if_blowed(). The reason for this is that the
* id_questionmark property needs to be retained so that questionmarks can
* be recreated, and that is why some property clearing is also done below
* to compensate for this.
*
* What I have decided to do seeing as this is such an important function,
* is to clear everything as in clear_field() EXCEPT id_questionmark.
*/
void
create_object (int x, int y, int type)
{
int count;
#ifdef DEBUG_INSPECT_OBJECT_CONTENTS
if (board[x][y].icon[0].x != 0)
{
printf ("*** Start %s ***\n", __func__);
printf ("type=%i\n", board[x][y].type);
printf ("state=%i\n", board[x][y].state);
printf ("direction=%i\n", board[x][y].direction);
printf ("destroyable=%i\n", board[x][y].destroyable);
printf ("blowable=%i\n", board[x][y].blowable);
printf ("killing=%i\n", board[x][y].killing);
printf ("moved=%i\n", board[x][y].moved);
printf ("blowed=%i\n", board[x][y].blowed);
printf ("shooted=%i\n", board[x][y].shooted);
printf ("rotated=%i\n", board[x][y].rotated);
printf ("solidlaser=%i\n", board[x][y].solidlaser);
printf ("rotable=%i\n", board[x][y].rotable);
printf ("randomrotated=%i\n", board[x][y].randomrotated);
printf ("teleportnumber=%i\n", board[x][y].teleportnumber);
printf ("teleportnumber2=%i\n", board[x][y].teleportnumber2);
printf ("id_questionmark=%i\n", board[x][y].id_questionmark);
printf ("direction2=%i\n", board[x][y].direction2);
printf ("movable=%i\n", board[x][y].movable);
printf ("returnlaser=%i\n", board[x][y].returnlaser);
printf ("shooting=%i\n", board[x][y].shooting);
printf ("processed=%i\n", board[x][y].processed);
printf ("icon[0].x=%i icon[0].y=%i\n", board[x][y].icon[0].x,
board[x][y].icon[0].y);
printf ("icon[1].x=%i icon[1].y=%i\n", board[x][y].icon[1].x,
board[x][y].icon[1].y);
printf ("icon[2].x=%i icon[2].y=%i\n", board[x][y].icon[2].x,
board[x][y].icon[2].y);
printf ("icon[3].x=%i icon[3].y=%i\n", board[x][y].icon[3].x,
board[x][y].icon[3].y);
printf ("icon[4].x=%i icon[4].y=%i\n", board[x][y].icon[4].x,
board[x][y].icon[4].y);
printf ("icon[5].x=%i icon[5].y=%i\n", board[x][y].icon[5].x,
board[x][y].icon[5].y);
printf ("icon[6].x=%i icon[6].y=%i\n", board[x][y].icon[6].x,
board[x][y].icon[6].y);
printf ("icon[7].x=%i icon[7].y=%i\n", board[x][y].icon[7].x,
board[x][y].icon[7].y);
printf ("icon[8].x=%i icon[8].y=%i\n", board[x][y].icon[8].x,
board[x][y].icon[8].y);
printf ("*** Stop %s ***\n", __func__);
}
#endif
#ifdef LIGHTNINGENABLED
#endif
board[x][y].type = type;
board[x][y].state = 0;
board[x][y].direction = 0;
board[x][y].destroyable = 0;
board[x][y].blowable = 0;
board[x][y].killing = 0;
board[x][y].moved = 0;
board[x][y].blowed = 0;
board[x][y].shooted = 0;
board[x][y].rotated = 0;
board[x][y].solidlaser = 0;
board[x][y].rotable = 0;
board[x][y].randomrotated = 0;
board[x][y].teleportnumber = 0;
board[x][y].teleportnumber2 = 0;
#ifdef LIGHTNINGENABLED
board[x][y].effect = 0; /* zero means effect is off */
#endif
/*
* NOTE id_questionmark's value is retained
*/
board[x][y].direction2 = 0;
board[x][y].movable = 0;
board[x][y].returnlaser = 0;
board[x][y].shooting = 0;
board[x][y].processed = cycle_count;
board[x][y].redraw = TRUE;
for (count = 0; count < MAX_ICONS; count++)
{
board[x][y].icon[count].x = 0;
board[x][y].icon[count].y = 0;
#ifdef LIGHTNINGENABLED
board[x][y].effect = 0;
#endif
}
switch (type)
{
case ROBBO:
robbo.x = x;
robbo.y = y;
robbo.state = 0;
board[x][y].type = EMPTY_FIELD; /* Robbo isn't a board location, so set it to EMPTY_FIELD */
board[x][y].id_questionmark = 0; /* May as well clear this as it's not required to be kept */
return; /* QUIT NOW */
case BEAR:
case BEAR_B:
case BIRD:
case BUTTERFLY:
board[x][y].killing = 1; /* Via their closeness */
case BULLET: /* The breaks have been ommitted for a reason */
case BOMB:
case BOMB2:
case QUESTIONMARK:
case GROUND:
case BARRIER:
board[x][y].destroyable = 1; /* Via a shot or push box */
case SCREW:
case PUSH_BOX:
case BOX:
case KEY:
case DOOR:
case LASER_L:
case LASER_D:
case TELEPORT:
case GUN:
case EMPTY_FIELD:
board[x][y].blowable = 1; /* Via a bomb */
break;
case STOP:
case RADIOACTIVE_FIELD: // it probably would have its own logic
board[x][y].blowable = 1;
board[x][y].destroyable = 0;
break;
}
set_images (board[x][y].type, x, y);
}
/***************************************************************************
* Clear Entire Board *
***************************************************************************/
/*
* Clear everything
*/
void
clear_entire_board (void)
{
int xpos, ypos;
/*
* Fill the game board with EMPTY_FIELD objects
*/
for (ypos = 0; ypos < MAX_H; ypos++)
{
for (xpos = 0; xpos < MAX_W; xpos++)
{
clear_field (xpos, ypos);
}
}
}
/*
* this will return zero if x/y is in viewport and non zero otherwise
*/
#ifdef _SMOOTH_SCRL_
int
in_viewport (int x, int y)
{
if (x - viewport.x / SCRL_MULT2 <= viewport.w
&& x - viewport.x / SCRL_MULT2 >= 0
&& y - viewport.y / SCRL_MULT2 <= viewport.h
&& y - viewport.y / SCRL_MULT2 >= 0)
{
return 1;
}
return 0;
}
#else
int
in_viewport (int x, int y)
{
if (x - viewport.x <= viewport.w && x - viewport.x >= 0 &&
y - viewport.y <= viewport.h && y - viewport.y >= 0)
{
return 1;
}
return 0;
}
#endif
int
check_wall (int x, int y)
{
int res = -1;
if (board[x][y].type == WALL && board[x][y].state >= 9)
{
res = 0;
if (y > 0)
if (board[x][y - 1].type == WALL && board[x][y - 1].state >= 9)
{
res = res + 1;
};
if (x + 1 < level.w)
if (board[x + 1][y].type == WALL && board[x + 1][y].state >= 9)
{
res = res + 2;
};
if (y + 1 < level.h)
if (board[x][y + 1].type == WALL && board[x][y + 1].state >= 9)
{
res = res + 4;
};
if (x > 0)
if (board[x - 1][y].type == WALL && board[x - 1][y].state >= 9)
{
res = res + 8;
};
};
return res;
}
int
rearange_walls ()
{
int x, y, w;
for (x = 0; x < level.w; x++)
{
for (y = 0; y < level.h; y++)
{
if ((w = check_wall (x, y)) > 0)
{
board[x][y].state = w + 9;
board[x][y].redraw = 1;
}
}
}
return 0;
}
|