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 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960
|
/*
* File: monstuff.cc
* Summary: Misc monster related functions.
* Written by: Linley Henzell
*
* Change History (most recent first):
*
* <8> 7 Aug 2001 MV Inteligent monsters now pick up gold
* <7> 26 Mar 2001 GDL Fixed monster reaching
* <6> 13 Mar 2001 GDL Rewrite of monster AI
* <5> 31 July 2000 GDL More Manticore fixes.
* <4> 29 July 2000 JDJ Fixed a bunch of places in handle_pickup where MSLOT_WEAPON
* was being erroneously used.
* <3> 25 July 2000 GDL Fixed Manticores
* <2> 11/23/99 LRH Upgraded monster AI
* <1> -/--/-- LRH Created
*/
#include "AppHdr.h"
#include "monstuff.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef DOS
#include <conio.h>
#endif
#include "externs.h"
#include "beam.h"
#include "cloud.h"
#include "debug.h"
#include "fight.h"
#include "itemname.h"
#include "items.h"
#include "misc.h"
#include "monplace.h"
#include "monspeak.h"
#include "mon-util.h"
#include "mstuff2.h"
#include "player.h"
#include "randart.h"
#include "spells2.h"
#include "spells4.h"
#include "stuff.h"
#include "view.h"
static bool handle_special_ability(struct monsters *monster, bolt & beem);
static bool handle_pickup(struct monsters *monster);
static void handle_behaviour(struct monsters *monster);
static void mons_in_cloud(struct monsters *monster);
static void monster_move(struct monsters *monster);
static bool plant_spit(struct monsters *monster, struct bolt &pbolt);
static int map_wand_to_mspell(int wand_type);
char mmov_x, mmov_y;
static int compass_x[8] = { -1, 0, 1, 1, 1, 0, -1, -1 };
static int compass_y[8] = { -1, -1, -1, 0, 1, 1, 1, 0 };
#define FAR_AWAY 1000000 // used in monster_move()
bool curse_an_item( char which, char power )
{
/* use which later, if I want to curse weapon/gloves whatever
which, for now: 0 = non-mummy, 1 = mummy (potions as well)
don't change mitm.special of !odecay */
int count = 0;
int item = ENDOFPACK;
for (int i = 0; i < ENDOFPACK; i++)
{
if (!is_valid_item( you.inv[i] ))
continue;
if (you.inv[i].base_type == OBJ_WEAPONS
|| you.inv[i].base_type == OBJ_ARMOUR
|| you.inv[i].base_type == OBJ_JEWELLERY
|| you.inv[i].base_type == OBJ_POTIONS)
{
if (item_cursed( you.inv[i] ))
continue;
if (you.inv[i].base_type == OBJ_POTIONS
&& (which != 1 || you.inv[i].sub_type == POT_DECAY))
{
continue;
}
// item is valid for cursing, so we'll give it a chance
count++;
if (one_chance_in( count ))
item = i;
}
}
// any item to curse?
if (item == ENDOFPACK)
return (false);
// curse item:
/* problem: changes large piles of potions */
/* don't change you.inv_special (just for fun) */
if (you.inv[item].base_type == OBJ_POTIONS)
you.inv[item].sub_type = POT_DECAY;
else
do_curse_item( you.inv[item] );
return (true);
}
void monster_blink(struct monsters *monster)
{
int nx, ny;
if (!random_near_space(monster->x, monster->y, nx, ny,
false, false))
return;
mgrd[monster->x][monster->y] = NON_MONSTER;
monster->x = nx;
monster->y = ny;
mgrd[nx][ny] = monster_index(monster);
} // end monster_blink()
// allow_adjacent: allow target to be adjacent to origin
// restrict_LOS: restict target to be within PLAYER line of sight
bool random_near_space(int ox, int oy, int &tx, int &ty, bool allow_adjacent,
bool restrict_LOS)
{
int tries = 0;
do
{
tx = ox - 6 + random2(14);
ty = oy - 6 + random2(14);
// origin is not 'near'
if (tx == ox && ty == oy)
continue;
tries++;
if (tries > 149)
break;
}
while ((!see_grid(tx, ty) && restrict_LOS)
|| grd[tx][ty] < DNGN_SHALLOW_WATER
|| mgrd[tx][ty] != NON_MONSTER
|| (!allow_adjacent && distance(ox, oy, tx, ty) <= 2));
return (tries < 150);
} // end random_near_space()
static bool habitat_okay( struct monsters *monster, int targ )
{
bool ret = false;
int habitat = monster_habitat( monster->type );
if (mons_flies( monster ))
{
// flying monsters don't care
ret = true;
}
else if (monster->type == MONS_WATER_ELEMENTAL && targ >= DNGN_DEEP_WATER)
{
// water elementals can crawl out over the land
ret = true;
}
else if (habitat == DNGN_FLOOR
&& (targ >= DNGN_FLOOR || targ == DNGN_SHALLOW_WATER))
{
// FLOOR habitat monster going to a non-bad place
ret = true;
}
else if (habitat == DNGN_DEEP_WATER
&& (targ == DNGN_DEEP_WATER || targ == DNGN_SHALLOW_WATER))
{
// Water monster to water
ret = true;
}
else if (habitat == DNGN_LAVA && targ == DNGN_LAVA)
{
// Lava monster to lava
ret = true;
}
return (ret);
}
// This doesn't really swap places, it just sets the monster's
// position equal to the player (the player has to be moved afterwards).
// It also has a slight problem with the fact the if the player is
// levitating over an inhospitable habitat for the monster the monster
// will be put in a place it normally couldn't go (this could be a
// feature because it prevents insta-killing). In order to prevent
// that little problem, we go looking for a square for the monster
// to "scatter" to instead... and if we can't find one the monster
// just refuses to be swapped (not a bug, this is intentionally
// avoiding the insta-kill). Another option is to look a bit
// wider for a vaild square (either by a last attempt blink, or
// by looking at a wider radius)... insta-killing should be a
// last resort in this function (especially since Tome, Dig, and
// Summoning can be used to set up death traps). If worse comes
// to worse, at least consider making the Swap spell not work
// when the player is over lava or water (if the player want's to
// swap pets to their death, we can let that go). -- bwr
bool swap_places(struct monsters *monster)
{
bool swap;
int loc_x = you.x_pos;
int loc_y = you.y_pos;
swap = habitat_okay( monster, grd[loc_x][loc_y] );
// chose an appropiate habitat square at random around the target.
if (!swap)
{
int num_found = 0;
int temp_x, temp_y;
for (int x = -1; x <= 1; x++)
{
temp_x = you.x_pos + x;
if (temp_x < 0 || temp_x >= GXM)
continue;
for (int y = -1; y <= 1; y++)
{
if (x == 0 && y == 0)
continue;
temp_y = you.y_pos + y;
if (temp_y < 0 || temp_y >= GYM)
continue;
if (mgrd[temp_x][temp_y] == NON_MONSTER
&& habitat_okay( monster, grd[temp_x][temp_y] ))
{
// Found an appropiate space... check if we
// switch the current choice to this one.
num_found++;
if (one_chance_in(num_found))
{
loc_x = temp_x;
loc_y = temp_y;
}
}
}
}
if (num_found)
swap = true;
}
if (swap)
{
mpr("You swap places.");
mgrd[monster->x][monster->y] = NON_MONSTER;
monster->x = loc_x;
monster->y = loc_y;
mgrd[monster->x][monster->y] = monster_index(monster);
}
else
{
// Might not be ideal, but it's better that insta-killing
// the monster... maybe try for a short blinki instead? -- bwr
simple_monster_message( monster, " resists." );
}
return (swap);
} // end swap_places()
void print_wounds(struct monsters *monster)
{
// prevents segfault -- cannot use info[] here {dlb}
char str_wound[200];
int dam_level;
if (monster->type == -1)
return;
if (monster->hit_points == monster->max_hit_points
|| monster->hit_points < 1)
{
return;
}
if (monster_descriptor(monster->type, MDSC_NOMSG_WOUNDS))
return;
strcpy(str_wound, " is ");
if (monster->hit_points <= monster->max_hit_points / 6)
{
strcat(str_wound, "almost ");
strcat(str_wound, wounded_damaged(monster->type) ? "destroyed"
: "dead");
dam_level = MDAM_ALMOST_DEAD;
}
else
{
if (monster->hit_points <= monster->max_hit_points / 6)
{
strcat(str_wound, "horribly ");
dam_level = MDAM_HORRIBLY_DAMAGED;
}
else if (monster->hit_points <= monster->max_hit_points / 3)
{
strcat(str_wound, "heavily " );
dam_level = MDAM_HEAVILY_DAMAGED;
}
else if (monster->hit_points <= 3 * (monster-> max_hit_points / 4))
{
strcat(str_wound, "moderately ");
dam_level = MDAM_MODERATELY_DAMAGED;
}
else
{
strcat(str_wound, "lightly ");
dam_level = MDAM_LIGHTLY_DAMAGED;
}
strcat(str_wound, wounded_damaged(monster->type) ? "damaged"
: "wounded");
}
strcat(str_wound, ".");
simple_monster_message(monster, str_wound, MSGCH_MONSTER_DAMAGE, dam_level);
} // end print_wounds()
// (true == 'damaged') [constructs, undead, etc.]
// and (false == 'wounded') [living creatures, etc.] {dlb}
bool wounded_damaged(int wound_class)
{
// this schema needs to be abstracted into real categories {dlb}:
const int holy = mons_holiness(wound_class);
if (holy == MH_UNDEAD || holy == MH_NONLIVING || holy == MH_PLANT)
return (true);
return (false);
} // end wounded_damaged()
//---------------------------------------------------------------
//
// behaviour_event
//
// 1. Change any of: monster state, foe, and attitude
// 2. Call handle_behaviour to re-evaluate AI state and target x,y
//
//---------------------------------------------------------------
void behaviour_event(struct monsters *mon, int event, int param)
{
bool isSmart = (mons_intel(mon->type) > I_ANIMAL);
bool isFriendly = mons_friendly(mon);
bool sourceFriendly = false;
bool setTarget = false;
bool breakCharm = false;
if (param == MHITYOU)
sourceFriendly = true;
else if (param != MHITNOT)
sourceFriendly = mons_friendly(&menv[param]);
switch(event)
{
case ME_EVAL:
break;
case ME_DISTURB:
// assumes disturbed by noise.. just wake up by
// setting to wander.
if (mon->behaviour == BEH_SLEEP)
mon->behaviour = BEH_WANDER;
break;
case ME_WHACK:
case ME_ANNOY:
// will turn monster against <param1>, unless they
// are BOTH friendly and stupid. Hitting someone
// over the head, of course, always triggers this code.
if (isFriendly != sourceFriendly || isSmart
|| event == ME_WHACK)
{
mon->foe = param;
if (mon->behaviour != BEH_CORNERED)
mon->behaviour = BEH_SEEK;
if (param == MHITYOU)
{
mon->attitude = ATT_HOSTILE;
breakCharm = true;
}
}
if (event == ME_WHACK)
{
// now set target x,y so that monster can whack
// back (once) at an invisible foe
setTarget = true;
}
break;
case ME_ALERT:
// will alert monster to <param1> and turn them
// against them, unless they have a current foe.
// it won't turn friends hostile either.
if (mon->behaviour != BEH_CORNERED)
mon->behaviour = BEH_SEEK;
if (mon->foe == MHITNOT)
mon->foe = param;
break;
case ME_SCARE:
mon->foe = param;
mon->behaviour = BEH_FLEE;
// assume monsters know where to run from, even
// if player is invisible.
setTarget = true;
break;
case ME_CORNERED:
// just set behaviour.. foe doesn't change.
if (mon->behaviour != BEH_CORNERED && !mons_has_ench(mon,ENCH_FEAR))
simple_monster_message(mon, " turns to fight!");
mon->behaviour = BEH_CORNERED;
break;
default:
break;
}
if (setTarget)
{
if (param == MHITYOU)
{
mon->target_x = you.x_pos;
mon->target_y = you.y_pos;
mon->attitude = ATT_HOSTILE;
}
else if (param != MHITNOT)
{
mon->target_x = menv[param].x;
mon->target_y = menv[param].y;
}
}
// now, break charms if appropriate
if (breakCharm)
{
mons_del_ench(mon, ENCH_CHARM);
}
// do any resultant foe or state changes
handle_behaviour(mon);
}
//---------------------------------------------------------------
//
// handle_behaviour
//
// 1. Evalutates current AI state
// 2. Sets monster targetx,y based on current foe
//
//---------------------------------------------------------------
static void handle_behaviour(struct monsters *mon)
{
bool changed = true;
bool isFriendly = mons_friendly(mon);
bool proxPlayer = mons_near(mon);
bool proxFoe;
bool isHurt = (mon->hit_points <= mon->max_hit_points / 4 - 1);
bool isHealthy = (mon->hit_points > mon->max_hit_points / 2);
bool isSmart = (mons_intel(mon->type) > I_ANIMAL);
bool isScared = mons_has_ench(mon, ENCH_FEAR);
// immobility logic stolen from later on in handle_monster().. argh! --gdl
bool isMobile = !(mon->type == MONS_OKLOB_PLANT
|| mon->type == MONS_CURSE_SKULL
|| (mon->type >= MONS_CURSE_TOE
&& mon->type <= MONS_POTION_MIMIC));
// check for confusion -- early out.
if (mons_has_ench(mon, ENCH_CONFUSION))
{
mon->target_x = 10 + random2(GXM - 10);
mon->target_y = 10 + random2(GYM - 10);
return;
}
// validate current target exists
if (mon->foe != MHITNOT && mon->foe != MHITYOU)
{
if (menv[mon->foe].type == -1)
mon->foe = MHITNOT;
}
// change proxPlayer depending on invisibility and standing
// in shallow water
if (proxPlayer && you.invis)
{
if (!(mons_see_invis(mon)
|| (grd[you.x_pos][you.y_pos] == DNGN_SHALLOW_WATER
&& !player_is_levitating())))
{
proxPlayer = false;
}
// must be able to see each other
if (!see_grid(mon->x, mon->y))
proxPlayer = false;
// now, the corollary to that is that sometimes, if a
// player is right next to a monster, they will 'see'
if (distance(you.x_pos, you.y_pos, mon->x, mon->y) < 2
&& one_chance_in(3))
{
proxPlayer = true;
}
}
// set friendly target, if they don't already have one
if (isFriendly && (mon->foe == MHITNOT || mon->foe == MHITYOU))
{
if (you.pet_target != MHITNOT)
mon->foe = you.pet_target;
}
// monsters do not attack themselves {dlb}
if (mon->foe == monster_index(mon))
{
mon->foe = MHITNOT;
}
// friendly monsters do not attack other friendly monsters
if (!(mon->foe == MHITNOT || mon->foe == MHITYOU))
{
if (isFriendly && mons_friendly(&menv[mon->foe]))
mon->foe = MHITNOT;
}
// unfriendly monsters fighting other monsters will usually
// target the player, if they're healthy
if (!isFriendly && mon->foe != MHITYOU && mon->foe != MHITNOT
&& proxPlayer && !one_chance_in(3) && isHealthy)
{
mon->foe = MHITYOU;
}
// validate target again
if (mon->foe != MHITNOT && mon->foe != MHITYOU)
{
if (menv[mon->foe].type == -1)
mon->foe = MHITNOT;
}
while(changed)
{
int foe_x = you.x_pos;
int foe_y = you.y_pos;
// evaluate these each time; they may change
if (mon->foe == MHITNOT)
proxFoe = false;
else
{
if (mon->foe == MHITYOU)
{
foe_x = you.x_pos;
foe_y = you.y_pos;
proxFoe = proxPlayer; // take invis into account
}
else
{
proxFoe = mons_near(mon, mon->foe);
if (!mons_monster_visible( mon, &menv[mon->foe] ))
proxFoe = false;
// XXX monsters will rely on player LOS -- GDL
if (!see_grid(menv[mon->foe].x, menv[mon->foe].y))
proxFoe = false;
foe_x = menv[mon->foe].x;
foe_y = menv[mon->foe].y;
}
}
// track changes to state; attitude never changes here.
unsigned int new_beh = mon->behaviour;
unsigned int new_foe = mon->foe;
// take care of monster state changes
switch(mon->behaviour)
{
case BEH_SLEEP:
// default sleep state
mon->target_x = mon->x;
mon->target_y = mon->y;
new_foe = MHITNOT;
break;
case BEH_SEEK:
// no foe? then wander.
if (mon->foe == MHITNOT)
{
new_beh = BEH_WANDER;
break;
}
// foe gone out of LOS?
if (!proxFoe)
{
if (isFriendly)
{
new_foe = MHITYOU;
mon->target_x = foe_x;
mon->target_y = foe_y;
break;
}
if (mon->foe_memory > 0 && mon->foe != MHITNOT)
{
// if we've arrived at our target x,y
// do a stealth check. If the foe
// fails, monster will then start
// tracking foe's CURRENT position,
// but only for a few moves (smell and
// intuition only go so far)
if (mon->x == mon->target_x &&
mon->y == mon->target_y)
{
if (mon->foe == MHITYOU)
{
if (check_awaken(monster_index(mon)))
{
mon->target_x = you.x_pos;
mon->target_y = you.y_pos;
}
else
mon->foe_memory = 1;
}
else
{
if (coinflip()) // XXX: cheesy!
{
mon->target_x = menv[mon->foe].x;
mon->target_y = menv[mon->foe].y;
}
else
mon->foe_memory = 1;
}
}
// either keep chasing, or start
// wandering.
if (mon->foe_memory < 2)
{
mon->foe_memory = 0;
new_beh = BEH_WANDER;
}
break;
}
// hack: smarter monsters will
// tend to persue the player longer.
int memory;
switch(mons_intel(monster_index(mon)))
{
case I_HIGH:
memory = 100 + random2(200);
break;
case I_NORMAL:
memory = 50 + random2(100);
break;
case I_ANIMAL:
default:
memory = 25 + random2(75);
break;
case I_INSECT:
memory = 10 + random2(50);
break;
}
mon->foe_memory = memory;
break; // from case
}
// monster can see foe: continue 'tracking'
// by updating target x,y
if (mon->foe == MHITYOU)
{
// sometimes, your friends will wander a bit.
if (isFriendly && one_chance_in(8))
{
mon->target_x = 10 + random2(GXM - 10);
mon->target_y = 10 + random2(GYM - 10);
}
else
{
mon->target_x = you.x_pos;
mon->target_y = you.y_pos;
}
}
else
{
mon->target_x = menv[mon->foe].x;
mon->target_y = menv[mon->foe].y;
}
if (isHurt && isSmart && isMobile)
new_beh = BEH_FLEE;
break;
case BEH_WANDER:
// is our foe in LOS?
if (proxFoe)
{
new_beh = BEH_SEEK;
break;
}
// default wander behaviour
mon->target_x = 10 + random2(GXM - 10);
mon->target_y = 10 + random2(GYM - 10);
// during their wanderings, monsters will
// eventually relax their guard (stupid
// ones will do so faster, smart monsters
// have longer memories
if (!proxFoe && mon->foe != MHITNOT)
{
if (one_chance_in(isSmart?60:20))
new_foe = MHITNOT;
}
break;
case BEH_FLEE:
// check for healed
if (isHealthy && !isScared)
new_beh = BEH_SEEK;
// smart monsters flee until they can
// flee no more... possible to get a
// 'CORNERED' event, at which point
// we can jump back to WANDER if the foe
// isn't present.
if (proxFoe)
{
// try to flee _from_ the correct position
mon->target_x = foe_x;
mon->target_y = foe_y;
}
break;
case BEH_CORNERED:
// foe gone out of LOS?
if (!proxFoe)
{
if (isFriendly || proxPlayer)
new_foe = MHITYOU;
else
new_beh = BEH_WANDER;
}
break;
default:
return; // uh oh
}
changed = (new_beh != mon->behaviour || new_foe != mon->foe);
mon->behaviour = new_beh;
if (mon->foe != new_foe)
mon->foe_memory = 0;
mon->foe = new_foe;
}
} // end handle_behaviour()
// note that this function *completely* blocks messaging for monsters
// distant or invisible to the player ... look elsewhere for a function
// permitting output of "It" messages for the invisible {dlb}
// INtentionally avoids info and str_pass now. -- bwr
bool simple_monster_message(struct monsters *monster, const char *event,
int channel, int param)
{
char buff[200];
if (mons_near( monster )
&& (channel == MSGCH_MONSTER_SPELL || player_monster_visible(monster)))
{
snprintf( buff, sizeof(buff), "%s%s",
ptr_monam(monster, DESC_CAP_THE), event );
mpr( buff, channel, param );
return (true);
}
return (false);
} // end simple_monster_message()
// used to adjust time durations in handle_enchantment() for monster speed
static inline int mod_speed( int val, int speed )
{
return (speed ? (val * 10) / speed : val);
}
static bool handle_enchantment(struct monsters *monster)
{
const int habitat = monster_habitat( monster->type );
bool died = false;
int grid;
int poisonval;
int dam;
int tmp;
// Yes, this is the speed we want. This function will be called in
// two curcumstances: (1) the monster can move and have enough energy,
// and (2) the monster cannot move (speed == 0) and the monster loop
// is running.
//
// In the first case we don't have to figure in the player's time,
// since the rate of call to this function already does that (ie.
// a bat would get here 6 times in 2 normal player turns, and if
// the player was twice as fast it would be 6 times every four player
// moves. So the only speed we care about is the monster vs the
// absolute time frame.
//
// In the second case, we're hacking things so that plants can suffer
// from sticky flame. The rate of call in this case is once every
// player action... so the time_taken by the player is the ratio to
// the absolute time frame.
//
// This will be used below for poison and sticky flame so that the
// damage is apparently in the absolute time frame. This is done
// by scaling the damage and the chance that the effect goes away.
// The result is that poison on a regular monster will be doing
// 1d3 damage every two rounds, and last eight rounds, and on
// a bat the same poison will be doing 1/3 the damage each action
// it gets (the mod fractions are randomized in), will have three
// turns to the other monster's one, and the effect will survive
// 3 times as many calls to this function (ie 8 rounds * 3 calls).
//
// -- bwr
const int speed = (monster->speed == 0) ? you.time_taken : monster->speed;
for (int p = 0; p < NUM_MON_ENCHANTS && !died; p++)
{
switch (monster->enchantment[p])
{
case ENCH_SLOW:
if (random2(250) <= mod_speed( monster->hit_dice + 10, speed ))
mons_del_ench(monster, ENCH_SLOW);
break;
case ENCH_HASTE:
if (random2(1000) < mod_speed( 25, speed ))
mons_del_ench(monster, ENCH_HASTE);
break;
case ENCH_FEAR:
if (random2(150) <= mod_speed( monster->hit_dice + 5, speed ))
mons_del_ench(monster, ENCH_FEAR);
break;
case ENCH_CONFUSION:
if (random2(120) < mod_speed( monster->hit_dice + 5, speed ))
{
// don't delete perma-confusion
if (!mons_flag(monster->type, M_CONFUSED))
mons_del_ench(monster, ENCH_CONFUSION);
}
break;
case ENCH_INVIS:
if (random2(1000) < mod_speed( 25, speed ))
{
// don't delete perma-invis
if (!mons_flag( monster->type, M_INVIS ))
mons_del_ench(monster, ENCH_INVIS);
}
break;
case ENCH_SUBMERGED:
// not even air elementals unsubmerge into clouds
if (env.cgrid[monster->x][monster->y] != EMPTY_CLOUD)
break;
// Air elementals are a special case, as their
// submerging in air isn't up to choice. -- bwr
if (monster->type == MONS_AIR_ELEMENTAL)
{
heal_monster( monster, 1, one_chance_in(5) );
if (one_chance_in(5))
mons_del_ench( monster, ENCH_SUBMERGED );
break;
}
// Now we handle the others:
grid = grd[monster->x][monster->y];
// Badly injured monsters prefer to stay submerged...
// electrical eels and lava snakes have ranged attacks
// and are more likely to surface. -- bwr
if (habitat != DNGN_FLOOR && habitat != grid)
mons_del_ench( monster, ENCH_SUBMERGED ); // forced to surface
else if (monster->hit_points <= monster->max_hit_points / 2)
break;
else if (((monster->type == MONS_ELECTRICAL_EEL
|| monster->type == MONS_LAVA_SNAKE)
&& (random2(1000) < mod_speed( 20, speed )
|| (mons_near(monster)
&& monster->hit_points == monster->max_hit_points
&& !one_chance_in(10))))
|| random2(5000) < mod_speed( 10, speed ))
{
mons_del_ench( monster, ENCH_SUBMERGED );
}
break;
case ENCH_POISON_I:
case ENCH_POISON_II:
case ENCH_POISON_III:
case ENCH_POISON_IV:
case ENCH_YOUR_POISON_I:
case ENCH_YOUR_POISON_II:
case ENCH_YOUR_POISON_III:
case ENCH_YOUR_POISON_IV:
poisonval = monster->enchantment[p] - ENCH_POISON_I;
if (poisonval < 0 || poisonval > 3)
poisonval = monster->enchantment[p] - ENCH_YOUR_POISON_I;
dam = 0;
if (coinflip())
dam = roll_dice( 1, poisonval + 2 );
if (mons_res_poison(monster) < 0)
dam += roll_dice( 2, poisonval ) - 1;
// We adjust damage for monster speed (since this is applied
// only when the monster moves), and we handle the factional
// part as well (so that speed 30 creatures will take damage).
dam *= 10;
dam = (dam / speed) + ((random2(speed) < (dam % speed)) ? 1 : 0);
if (dam > 0)
{
hurt_monster( monster, dam );
#if DEBUG_DIAGNOSTICS
// for debugging, we don't have this silent.
simple_monster_message( monster, " takes poison damage.",
MSGCH_DIAGNOSTIC );
snprintf( info, INFO_SIZE, "poison damage: %d", dam );
mpr( info, MSGCH_DIAGNOSTIC );
#endif
if (monster->hit_points < 1)
{
monster_die(monster,
((monster->enchantment[p] < ENCH_POISON_I)
? KILL_YOU : KILL_MISC), 0);
died = true;
}
}
// chance to get over poison (1 in 8, modified for speed)
if (random2(1000) < mod_speed( 125, speed ))
{
if (monster->enchantment[p] == ENCH_POISON_I)
mons_del_ench(monster, ENCH_POISON_I);
else if (monster->enchantment[p] == ENCH_YOUR_POISON_I)
mons_del_ench(monster, ENCH_YOUR_POISON_I);
else
monster->enchantment[p]--;
}
break;
case ENCH_YOUR_ROT_I:
if (random2(1000) < mod_speed( 250, speed ))
mons_del_ench(monster, ENCH_YOUR_ROT_I);
else if (monster->hit_points > 1
&& random2(1000) < mod_speed( 333, speed ))
{
hurt_monster(monster, 1);
}
break;
//jmf: FIXME: if (undead) make_small_rot_cloud();
case ENCH_YOUR_ROT_II:
case ENCH_YOUR_ROT_III:
case ENCH_YOUR_ROT_IV:
if (monster->hit_points > 1
&& random2(1000) < mod_speed( 333, speed ))
{
hurt_monster(monster, 1);
}
if (random2(1000) < mod_speed( 250, speed ))
monster->enchantment[p]--;
break;
case ENCH_BACKLIGHT_I:
if (random2(1000) < mod_speed( 100, speed ))
mons_del_ench( monster, ENCH_BACKLIGHT_I );
break;
case ENCH_BACKLIGHT_II:
case ENCH_BACKLIGHT_III:
case ENCH_BACKLIGHT_IV:
if (random2(1000) < mod_speed( 200, speed ))
monster->enchantment[p]--;
break;
// assumption: mons_res_fire has already been checked
case ENCH_STICKY_FLAME_I:
case ENCH_STICKY_FLAME_II:
case ENCH_STICKY_FLAME_III:
case ENCH_STICKY_FLAME_IV:
case ENCH_YOUR_STICKY_FLAME_I:
case ENCH_YOUR_STICKY_FLAME_II:
case ENCH_YOUR_STICKY_FLAME_III:
case ENCH_YOUR_STICKY_FLAME_IV:
dam = roll_dice( 2, 4 ) - 1;
if (mons_res_fire( monster ) < 0)
dam += roll_dice( 2, 5 ) - 1;
// We adjust damage for monster speed (since this is applied
// only when the monster moves), and we handle the factional
// part as well (so that speed 30 creatures will take damage).
dam *= 10;
dam = (dam / speed) + ((random2(speed) < (dam % speed)) ? 1 : 0);
if (dam > 0)
{
hurt_monster( monster, dam );
simple_monster_message(monster, " burns!");
#if DEBUG_DIAGNOSTICS
snprintf( info, INFO_SIZE, "sticky flame damage: %d", dam );
mpr( info, MSGCH_DIAGNOSTIC );
#endif
if (monster->hit_points < 1)
{
monster_die(monster,
((monster->enchantment[p] < ENCH_STICKY_FLAME_I)
? KILL_YOU : KILL_MISC), 0);
died = true;
}
}
// chance to get over sticky flame (1 in 5, modified for speed)
if (random2(1000) < mod_speed( 200, speed ))
{
if (monster->enchantment[p] == ENCH_STICKY_FLAME_I)
mons_del_ench( monster, ENCH_STICKY_FLAME_I );
else if (monster->enchantment[p] == ENCH_YOUR_STICKY_FLAME_I)
mons_del_ench( monster, ENCH_YOUR_STICKY_FLAME_I );
else
monster->enchantment[p]--;
}
break;
case ENCH_SHORT_LIVED:
// This should only be used for ball lightning -- bwr
if (random2(1000) < mod_speed( 200, speed ))
monster->hit_points = -1;
break;
// 19 is taken by summoning:
// If these are changed, must also change abjuration
case ENCH_ABJ_I:
case ENCH_ABJ_II:
case ENCH_ABJ_III:
case ENCH_ABJ_IV:
if (random2(1000) < mod_speed( 100, speed ))
monster->enchantment[p]--;
if (monster->enchantment[p] < ENCH_ABJ_I)
{
monster_die(monster, KILL_RESET, 0);
died = true;
}
break;
case ENCH_ABJ_V:
if (random2(1000) < mod_speed( 40, speed ))
monster->enchantment[p] = ENCH_ABJ_IV;
break;
case ENCH_ABJ_VI:
if (random2(1000) < mod_speed( 20, speed ))
monster->enchantment[p] = ENCH_ABJ_V;
break;
case ENCH_CHARM:
if (random2(500) <= mod_speed( monster->hit_dice + 10, speed ))
mons_del_ench(monster, ENCH_CHARM);
break;
case ENCH_GLOWING_SHAPESHIFTER: // this ench never runs out
// number of actions is fine for shapeshifters
if (monster->type == MONS_GLOWING_SHAPESHIFTER
|| random2(1000) < mod_speed( 250, speed ))
{
monster_polymorph(monster, RANDOM_MONSTER, 0);
}
break;
case ENCH_SHAPESHIFTER: // this ench never runs out
if (monster->type == MONS_SHAPESHIFTER
|| random2(1000) < mod_speed( 1000 / ((15 * monster->hit_dice) / 5), speed ))
{
monster_polymorph(monster, RANDOM_MONSTER, 0);
}
break;
case ENCH_TP_I:
mons_del_ench( monster, ENCH_TP_I );
monster_teleport( monster, true );
break;
case ENCH_TP_II:
case ENCH_TP_III:
case ENCH_TP_IV:
tmp = mod_speed( 1000, speed );
if (tmp < 1000 && random2(1000) < tmp)
monster->enchantment[p]--;
else if (monster->enchantment[p] - tmp / 1000 >= ENCH_TP_I)
{
monster->enchantment[p] -= tmp / 1000;
tmp %= 1000;
if (random2(1000) < tmp)
{
if (monster->enchantment[p] > ENCH_TP_I)
monster->enchantment[p]--;
else
{
mons_del_ench( monster, ENCH_TP_I, ENCH_TP_IV );
monster_teleport( monster, true );
}
}
}
else
{
mons_del_ench( monster, ENCH_TP_I, ENCH_TP_IV );
monster_teleport( monster, true );
}
break;
case ENCH_SLEEP_WARY:
if (random2(1000) < mod_speed( 50, speed ))
mons_del_ench(monster, ENCH_SLEEP_WARY);
break;
}
}
return (died);
} // end handle_enchantment()
//---------------------------------------------------------------
//
// handle_movement
//
// Move the monster closer to its target square.
//
//---------------------------------------------------------------
static void handle_movement(struct monsters *monster)
{
int dx, dy;
// some calculations
if (monster->type == MONS_BORING_BEETLE && monster->foe == MHITYOU)
{
dx = you.x_pos - monster->x;
dy = you.y_pos - monster->y;
}
else
{
dx = monster->target_x - monster->x;
dy = monster->target_y - monster->y;
}
// move the monster:
mmov_x = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0);
mmov_y = (dy > 0) ? 1 : ((dy < 0) ? -1 : 0);
if (monster->behaviour == BEH_FLEE)
{
mmov_x *= -1;
mmov_y *= -1;
}
// bounds check: don't let fleeing monsters try to run
// off the map
if (monster->target_x + mmov_x < 0 || monster->target_x + mmov_x >= GXM)
mmov_x = 0;
if (monster->target_y + mmov_y < 0 || monster->target_y + mmov_y >= GYM)
mmov_y = 0;
// now quit if we're can't move
if (mmov_x == 0 && mmov_y == 0)
return;
// reproduced here is some semi-legacy code that makes monsters
// move somewhat randomly along oblique paths. It is an exceedingly
// good idea, given crawl's unique line of sight properties.
if (abs(dx) > abs(dy))
{
// sometimes we'll just move parallel the x axis
if (coinflip())
mmov_y = 0;
}
if (abs(dy) > abs(dx))
{
// sometimes we'll just move parallel the y axis
if (coinflip())
mmov_x = 0;
}
} // end handle_movement()
//---------------------------------------------------------------
//
// handle_nearby_ability
//
// Gives monsters a chance to use a special ability when they're
// next to the player.
//
//---------------------------------------------------------------
static void handle_nearby_ability(struct monsters *monster)
{
if (mons_near(monster) && monster->behaviour != BEH_SLEEP)
{
if (mons_flag(monster->type, M_SPEAKS) && one_chance_in(21)
&& monster->behaviour != BEH_WANDER)
mons_speaks(monster);
switch (monster->type)
{
case MONS_SPATIAL_VORTEX:
case MONS_KILLER_KLOWN:
// I think it is used for colouring {dlb}
monster->number = random_colour();
break;
case MONS_GIANT_EYEBALL:
if (coinflip() && !mons_friendly(monster)
&& monster->behaviour != BEH_WANDER)
{
simple_monster_message(monster, " stares at you.");
if (you.paralysis < 10)
you.paralysis += 2 + random2(3);
}
break;
case MONS_EYE_OF_DRAINING:
if (coinflip() && !mons_friendly(monster)
&& monster->behaviour != BEH_WANDER)
{
simple_monster_message(monster, " stares at you.");
dec_mp(5 + random2avg(13, 3));
heal_monster(monster, 10, true); // heh heh {dlb}
}
break;
case MONS_LAVA_WORM:
case MONS_LAVA_FISH:
case MONS_LAVA_SNAKE:
case MONS_SALAMANDER:
case MONS_BIG_FISH:
case MONS_GIANT_GOLDFISH:
case MONS_ELECTRICAL_EEL:
case MONS_JELLYFISH:
case MONS_WATER_ELEMENTAL:
case MONS_SWAMP_WORM:
if (mons_has_ench( monster, ENCH_SUBMERGED))
{
if (grd[monster->x][monster->y] == DNGN_SHALLOW_WATER
|| grd[monster->x][monster->y] == DNGN_BLUE_FOUNTAIN
|| (!mons_friendly(monster)
&& grid_distance( monster->x, monster->y,
you.x_pos, you.y_pos ) == 1
&& (monster->hit_points == monster->max_hit_points
|| (monster->hit_points > monster->max_hit_points / 2
&& coinflip()))))
{
mons_del_ench( monster, ENCH_SUBMERGED );
}
}
else if (monster_habitat(monster->type) == grd[monster->x][monster->y]
&& (one_chance_in(5)
|| (grid_distance( monster->x, monster->y,
you.x_pos, you.y_pos ) > 1
&& monster->type != MONS_ELECTRICAL_EEL
&& monster->type != MONS_LAVA_SNAKE
&& !one_chance_in(20))
|| monster->hit_points <= monster->max_hit_points / 2)
|| env.cgrid[monster->x][monster->y] != EMPTY_CLOUD)
{
mons_add_ench( monster, ENCH_SUBMERGED );
}
break;
case MONS_AIR_ELEMENTAL:
if (one_chance_in(5))
mons_add_ench( monster, ENCH_SUBMERGED );
break;
case MONS_PANDEMONIUM_DEMON:
if (ghost.values[13])
monster->number = random_colour();
break;
}
}
} // end handle_nearby_ability()
//---------------------------------------------------------------
//
// handle_special_ability
//
// $$$ not sure what to say here...
//
//---------------------------------------------------------------
static bool handle_special_ability(struct monsters *monster, bolt & beem)
{
bool used = false;
FixedArray < unsigned int, 19, 19 > show;
// losight(show, grd, you.x_pos, you.y_pos);
switch (monster->type)
{
case MONS_BALL_LIGHTNING:
if (monster->attitude == ATT_HOSTILE
&& distance( you.x_pos, you.y_pos, monster->x, monster->y ) <= 5)
{
monster->hit_points = -1;
used = true;
break;
}
for (int i = 0; i < MAX_MONSTERS; i++)
{
struct monsters *targ = &menv[i];
if (targ->type == -1 || targ->type == NON_MONSTER)
continue;
if (distance( monster->x, monster->y, targ->x, targ->y ) >= 5)
continue;
if (monster->attitude == targ->attitude)
continue;
// faking LOS by checking the neighbouring square
int dx = targ->x - monster->x;
if (dx)
dx /= dx;
int dy = targ->y - monster->y;
if (dy)
dy /= dy;
const int tx = monster->x + dx;
const int ty = monster->y + dy;
if (tx < 0 || tx > GXM || ty < 0 || ty > GYM)
continue;
if (grd[tx][ty] > DNGN_LAST_SOLID_TILE)
{
monster->hit_points = -1;
used = true;
break;
}
}
break;
case MONS_LAVA_SNAKE:
if (mons_has_ench(monster, ENCH_CONFUSION))
break;
if (you.invis && !mons_see_invis(monster))
break;
if (mons_has_ench( monster, ENCH_SUBMERGED ) || coinflip())
break;
// setup tracer
strcpy(beem.beam_name, "glob of lava");
beem.range = 4;
beem.rangeMax = 13;
beem.damage = dice_def( 3, 10 );
beem.colour = RED;
beem.type = SYM_ZAP;
beem.flavour = BEAM_LAVA;
beem.hit = 20;
beem.beam_source = monster_index(monster);
beem.thrower = KILL_MON;
// fire tracer
fire_tracer(monster, beem);
// good idea?
if (mons_should_fire(beem))
{
simple_monster_message(monster, " spits lava!");
beam(beem);
used = true;
}
break;
case MONS_ELECTRICAL_EEL:
if (mons_has_ench(monster, ENCH_CONFUSION))
break;
if (you.invis && !mons_see_invis(monster))
break;
if (mons_has_ench( monster, ENCH_SUBMERGED ) || coinflip())
break;
// setup tracer
strcpy(beem.beam_name, "bolt of electricity");
beem.damage = dice_def( 3, 6 );
beem.colour = LIGHTCYAN;
beem.type = SYM_ZAP;
beem.flavour = BEAM_ELECTRICITY;
beem.hit = 150;
beem.beam_source = monster_index(monster);
beem.thrower = KILL_MON;
beem.range = 4;
beem.rangeMax = 13;
beem.isBeam = true;
// fire tracer
fire_tracer(monster, beem);
// good idea?
if (mons_should_fire(beem))
{
simple_monster_message(monster, " shoots out a bolt of electricity!");
beam(beem);
used = true;
}
break;
case MONS_ACID_BLOB:
case MONS_OKLOB_PLANT:
if (mons_has_ench(monster, ENCH_CONFUSION))
break;
if (you.invis && !mons_see_invis(monster))
break;
if (one_chance_in(3))
used = plant_spit(monster, beem);
break;
case MONS_PIT_FIEND:
if (one_chance_in(3))
break;
// deliberate fall through
case MONS_FIEND:
if (mons_has_ench(monster, ENCH_CONFUSION))
break;
// friendly fiends won't use torment, preferring hellfire
// (right now there is no way a monster can predict how
// badly they'll damage the player with torment) -- GDL
if (one_chance_in(4))
{
int spell_cast;
switch (random2(4))
{
case 0:
if (!mons_friendly(monster))
{
spell_cast = MS_TORMENT;
mons_cast(monster, beem, spell_cast);
used = true;
break;
}
// deliberate fallthrough -- see above
case 1:
case 2:
case 3:
spell_cast = MS_HELLFIRE;
setup_mons_cast(monster, beem, spell_cast);
// fire tracer
fire_tracer(monster, beem);
// good idea?
if (mons_should_fire(beem))
{
simple_monster_message( monster, " makes a gesture!",
MSGCH_MONSTER_SPELL );
mons_cast(monster, beem, spell_cast);
used = true;
}
break;
}
mmov_x = 0;
mmov_y = 0;
}
break;
case MONS_IMP:
case MONS_PHANTOM:
case MONS_INSUBSTANTIAL_WISP:
case MONS_BLINK_FROG:
if (one_chance_in(7))
{
simple_monster_message(monster, " blinks.");
monster_blink(monster);
}
break;
case MONS_MANTICORE:
if (you.invis && !mons_see_invis(monster))
break;
if (mons_has_ench(monster, ENCH_CONFUSION))
break;
if (!mons_near(monster))
break;
// the fewer spikes the manticore has left, the less
// likely it will use them.
if (random2(16) >= static_cast<int>(monster->number))
break;
// do the throwing right here, since the beam is so
// easy to set up and doesn't involve inventory.
// set up the beam
strcpy(beem.beam_name, "volley of spikes");
beem.range = 9;
beem.rangeMax = 9;
beem.hit = 14;
beem.damage = dice_def( 2, 10 );
beem.beam_source = monster_index(monster);
beem.type = SYM_MISSILE;
beem.colour = LIGHTGREY;
beem.flavour = BEAM_MISSILE;
beem.thrower = KILL_MON;
beem.isBeam = false;
// fire tracer
fire_tracer(monster, beem);
// good idea?
if (mons_should_fire(beem))
{
simple_monster_message(monster, " flicks its tail!");
beam(beem);
used = true;
// decrement # of volleys left
monster->number -= 1;
}
break;
// dragon breath weapon:
case MONS_DRAGON:
case MONS_HELL_HOUND:
case MONS_ICE_DRAGON:
case MONS_LINDWURM:
case MONS_FIREDRAKE:
case MONS_XTAHUA:
if (you.invis && !mons_see_invis(monster))
break;
if (mons_has_ench(monster, ENCH_CONFUSION))
break;
if ((monster->type != MONS_HELL_HOUND && random2(13) < 3)
|| one_chance_in(10))
{
setup_dragon(monster, beem);
// fire tracer
fire_tracer(monster, beem);
// good idea?
if (mons_should_fire(beem))
{
simple_monster_message(monster, " breathes.");
beam(beem);
mmov_x = 0;
used = true;
}
}
break;
}
return (used);
} // end handle_special_ability()
//---------------------------------------------------------------
//
// handle_potion
//
// Give the monster a chance to quaff a potion. Returns true if
// the monster imbibed.
//
//---------------------------------------------------------------
static bool handle_potion(struct monsters *monster, bolt & beem)
{
// yes, there is a logic to this ordering {dlb}:
if (monster->behaviour == BEH_SLEEP)
return (false);
else if (monster->inv[MSLOT_POTION] == NON_ITEM)
return (false);
else if (!one_chance_in(3))
return (false);
else
{
bool imbibed = false;
switch (mitm[monster->inv[MSLOT_POTION]].sub_type)
{
case POT_HEALING:
case POT_HEAL_WOUNDS:
if (monster->hit_points <= monster->max_hit_points / 2
&& mons_holiness(monster->type) != MH_UNDEAD
&& mons_holiness(monster->type) != MH_NONLIVING
&& mons_holiness(monster->type) != MH_PLANT)
{
simple_monster_message(monster, " drinks a potion.");
if (heal_monster(monster, 5 + random2(7), false))
simple_monster_message(monster, " is healed!");
if (mitm[monster->inv[MSLOT_POTION]].sub_type
== POT_HEAL_WOUNDS)
{
heal_monster(monster, 10 + random2avg(28, 3), false);
}
imbibed = true;
}
break;
case POT_SPEED:
// notice that these are the same odd colours used in
// mons_ench_f2() {dlb}
beem.colour = BLUE;
// intentional fall through
case POT_INVISIBILITY:
if (mitm[monster->inv[MSLOT_POTION]].sub_type == POT_INVISIBILITY)
beem.colour = MAGENTA;
// why only drink these if not near player? {dlb}
if (!mons_near(monster))
{
simple_monster_message(monster, " drinks a potion.");
mons_ench_f2(monster, beem);
imbibed = true;
}
break;
}
if (imbibed)
{
if (dec_mitm_item_quantity( monster->inv[MSLOT_POTION], 1 ))
monster->inv[MSLOT_POTION] = NON_ITEM;
}
return (imbibed);
}
} // end handle_potion()
static bool handle_reaching(struct monsters *monster)
{
bool ret = false;
const int wpn = monster->inv[MSLOT_WEAPON];
if (mons_aligned(monster_index(monster), monster->foe))
return (false);
if (wpn != NON_ITEM && get_weapon_brand( mitm[wpn] ) == SPWPN_REACHING )
{
if (monster->foe == MHITYOU)
{
// this check isn't redundant -- player may be invisible.
if (monster->target_x == you.x_pos && monster->target_y == you.y_pos)
{
int dx = abs(monster->x - you.x_pos);
int dy = abs(monster->y - you.y_pos);
if ((dx == 2 && dy <= 2) || (dy == 2 && dx <= 2))
{
ret = true;
monster_attack( monster_index(monster) );
}
}
}
else if (monster->foe != MHITNOT)
{
// same comments as to invisibility as above.
if (monster->target_x == menv[monster->foe].x
&& monster->target_y == menv[monster->foe].y)
{
int dx = abs(monster->x - menv[monster->foe].x);
int dy = abs(monster->y - menv[monster->foe].y);
if ((dx == 2 && dy <= 2) || (dy == 2 && dx <= 2))
{
ret = true;
monsters_fight(monster_index(monster),
monster->foe);
}
}
}
}
return ret;
} // end handle_reaching()
//---------------------------------------------------------------
//
// handle_scroll
//
// Give the monster a chance to read a scroll. Returns true if
// the monster read something.
//
//---------------------------------------------------------------
static bool handle_scroll(struct monsters *monster)
{
// yes, there is a logic to this ordering {dlb}:
if (mons_has_ench(monster, ENCH_CONFUSION) || monster->behaviour == BEH_SLEEP)
return (false);
else if (monster->inv[MSLOT_SCROLL] == NON_ITEM)
return (false);
else if (!one_chance_in(3))
return (false);
else
{
bool read = false;
// notice how few cases are actually accounted for here {dlb}:
switch (mitm[monster->inv[MSLOT_SCROLL]].sub_type)
{
case SCR_TELEPORTATION:
if (!mons_has_ench(monster, ENCH_TP_I))
{
if (monster->behaviour == BEH_FLEE)
{
simple_monster_message(monster, " reads a scroll.");
monster_teleport(monster, false);
read = true;
}
}
break;
case SCR_BLINKING:
if (monster->behaviour == BEH_FLEE)
{
if (mons_near(monster))
{
simple_monster_message(monster, " reads a scroll.");
simple_monster_message(monster, " blinks!");
monster_blink(monster);
read = true;
}
}
break;
case SCR_SUMMONING:
if (mons_near(monster))
{
simple_monster_message(monster, " reads a scroll.");
create_monster( MONS_ABOMINATION_SMALL, ENCH_ABJ_II,
SAME_ATTITUDE(monster), monster->x, monster->y,
monster->foe, 250 );
read = true;
}
break;
}
if (read)
{
if (dec_mitm_item_quantity( monster->inv[MSLOT_SCROLL], 1 ))
monster->inv[MSLOT_SCROLL] = NON_ITEM;
}
return read;
}
} // end handle_scroll()
//---------------------------------------------------------------
//
// handle_wand
//
// Give the monster a chance to zap a wand. Returns true if the
// monster zapped.
//
//---------------------------------------------------------------
static bool handle_wand(struct monsters *monster, bolt &beem)
{
// yes, there is a logic to this ordering {dlb}:
if (monster->behaviour == BEH_SLEEP)
return (false);
else if (!mons_near(monster))
return (false);
else if (monster->inv[MSLOT_WAND] == NON_ITEM
|| mitm[monster->inv[MSLOT_WAND]].plus <= 0)
{
return (false);
}
else if (coinflip())
{
bool niceWand = false;
bool zap = false;
// map wand type to monster spell type
int mzap = map_wand_to_mspell(mitm[monster->inv[MSLOT_WAND]].sub_type);
if (mzap == 0)
return (false);
// set up the beam
int power = 30 + monster->hit_dice;
struct SBeam theBeam = mons_spells(mzap, power);
strcpy( beem.beam_name, theBeam.name.c_str() );
beem.beam_source = monster_index(monster);
beem.source_x = monster->x;
beem.source_y = monster->y;
beem.colour = theBeam.colour;
beem.range = theBeam.range;
beem.rangeMax = theBeam.rangeMax;
beem.damage = theBeam.damage;
beem.ench_power = theBeam.ench_power;
beem.hit = theBeam.hit;
beem.type = theBeam.type;
beem.flavour = theBeam.flavour;
beem.thrower = theBeam.thrown;
beem.isBeam = theBeam.isBeam;
switch (mitm[monster->inv[MSLOT_WAND]].sub_type)
{
// these have been deemed "too tricky" at this time {dlb}:
case WAND_POLYMORPH_OTHER:
case WAND_ENSLAVEMENT:
case WAND_DIGGING:
case WAND_RANDOM_EFFECTS:
return (false);
// these are wands that monsters will aim at themselves {dlb}:
case WAND_HASTING:
if (!mons_has_ench(monster, ENCH_HASTE))
{
beem.target_x = monster->x;
beem.target_y = monster->y;
niceWand = true;
break;
}
return (false);
case WAND_HEALING:
if (monster->hit_points <= monster->max_hit_points / 2)
{
beem.target_x = monster->x;
beem.target_y = monster->y;
niceWand = true;
break;
}
return (false);
case WAND_INVISIBILITY:
if (!mons_has_ench( monster, ENCH_INVIS )
&& !mons_has_ench( monster, ENCH_SUBMERGED ))
{
beem.target_x = monster->x;
beem.target_y = monster->y;
niceWand = true;
break;
}
return (false);
case WAND_TELEPORTATION:
if (monster->hit_points <= monster->max_hit_points / 2)
{
if (!mons_has_ench(monster, ENCH_TP_I) && !one_chance_in(20))
{
beem.target_x = monster->x;
beem.target_y = monster->y;
niceWand = true;
break;
}
// this break causes the wand to be tried on the player:
break;
}
return (false);
}
// fire tracer, if necessary
if (!niceWand)
{
fire_tracer( monster, beem );
// good idea?
zap = mons_should_fire( beem );
}
if (niceWand || zap)
{
if (!simple_monster_message(monster, " zaps a wand."))
{
if (!silenced(you.x_pos, you.y_pos))
mpr("You hear a zap.");
}
// charge expenditure {dlb}
mitm[monster->inv[MSLOT_WAND]].plus--;
beem.isTracer = false;
beam( beem );
return (true);
}
}
return (false);
} // end handle_wand()
//---------------------------------------------------------------
//
// handle_spell
//
// Give the monster a chance to cast a spell. Returns true if
// a spell was cast.
//
//---------------------------------------------------------------
static bool handle_spell( struct monsters *monster, bolt & beem )
{
bool monsterNearby = mons_near(monster);
bool finalAnswer = false; // as in: "Is that your...?" {dlb}
// yes, there is a logic to this ordering {dlb}:
if (monster->behaviour == BEH_SLEEP
|| !mons_flag(monster->type, M_SPELLCASTER))
{
return (false);
}
if ((mons_flag(monster->type, M_ACTUAL_SPELLS)
|| mons_flag(monster->type, M_PRIEST))
&& (mons_has_ench(monster, ENCH_GLOWING_SHAPESHIFTER, ENCH_SHAPESHIFTER)))
{
return (false); //jmf: shapeshiftes don't get spells, just
// physical powers.
}
else if (mons_has_ench(monster, ENCH_CONFUSION)
&& !mons_flag(monster->type, M_CONFUSED))
{
return (false);
}
else if (monster->type == MONS_PANDEMONIUM_DEMON && ghost.values[9] == 0)
{
return (false);
}
else if (random2(200) > monster->hit_dice + 50
|| (monster->type == MONS_BALL_LIGHTNING && coinflip()))
{
return (false);
}
else
{
int spell_cast = MS_NO_SPELL;
int hspell_pass[6] = { MS_NO_SPELL, MS_NO_SPELL, MS_NO_SPELL,
MS_NO_SPELL, MS_NO_SPELL, MS_NO_SPELL };
int msecc = ((monster->type == MONS_HELLION) ? MST_BURNING_DEVIL :
(monster->type == MONS_PANDEMONIUM_DEMON) ? MST_GHOST
: monster->number);
mons_spell_list( msecc, hspell_pass );
// forces the casting of dig when player not visible - this is EVIL!
if (!monsterNearby)
{
if (hspell_pass[4] == MS_DIG && monster->behaviour == BEH_SEEK)
{
spell_cast = MS_DIG;
finalAnswer = true;
}
else if (hspell_pass[2] == MS_HEAL
&& monster->hit_points < monster->max_hit_points)
{
// The player's out of sight!
// Quick, let's take a turn to heal ourselves. -- bwr
spell_cast = MS_HEAL;
finalAnswer = true;
}
else if (monster->behaviour == BEH_FLEE)
{
// Since the player isn't around, we'll extend the monster's
// normal fleeing choices to include the self-enchant slot.
if (ms_useful_fleeing_out_of_sight(monster,hspell_pass[5]))
{
spell_cast = hspell_pass[5];
finalAnswer = true;
}
else if (ms_useful_fleeing_out_of_sight(monster,hspell_pass[2]))
{
spell_cast = hspell_pass[2];
finalAnswer = true;
}
}
else if (monster->foe == MHITYOU)
{
return (false);
}
}
// Promote the casting of useful spells for low-HP monsters.
if (!finalAnswer
&& monster->hit_points < monster->max_hit_points / 4
&& !one_chance_in(4))
{
// Note: There should always be at least some chance we don't
// get here... even if the monster is on it's last HP. That
// way we don't have to worry about monsters infinitely casting
// Healing on themselves (ie orc priests).
if (monster->behaviour == BEH_FLEE
&& ms_low_hitpoint_cast( monster, hspell_pass[5] ))
{
spell_cast = hspell_pass[5];
finalAnswer = true;
}
else if (ms_low_hitpoint_cast( monster, hspell_pass[2] ))
{
spell_cast = hspell_pass[2];
finalAnswer = true;
}
}
if (!finalAnswer)
{
// should monster not have selected dig by now, it never will:
if (hspell_pass[4] == MS_DIG)
hspell_pass[4] = MS_NO_SPELL;
// remove healing/invis/haste if we don't need them
int num_no_spell = 0;
for (int i = 0; i < 6; i++)
{
if (hspell_pass[i] == MS_NO_SPELL)
num_no_spell++;
else if (ms_waste_of_time( monster, hspell_pass[i] ))
{
hspell_pass[i] = MS_NO_SPELL;
num_no_spell++;
}
}
// If no useful spells... cast no spell.
if (num_no_spell == 6)
return (false);
// up to four tries to pick a spell.
for (int loopy = 0; loopy < 4; loopy ++)
{
bool spellOK = false;
// setup spell - fleeing monsters will always try to
// choose their emergency spell.
if (monster->behaviour == BEH_FLEE)
{
spell_cast = (one_chance_in(5) ? MS_NO_SPELL
: hspell_pass[5]);
}
else
{
// Randomly picking one of the non-emergency spells:
spell_cast = hspell_pass[random2(5)];
}
if (spell_cast == MS_NO_SPELL)
continue;
// setup the spell
setup_mons_cast(monster, beem, spell_cast);
// beam-type spells requiring tracers
if (ms_requires_tracer(spell_cast))
{
fire_tracer(monster, beem);
// good idea?
if (mons_should_fire(beem))
spellOK = true;
}
else
{
// all direct-effect/summoning/self-enchantments/etc
spellOK = true;
if (ms_direct_nasty(spell_cast)
&& mons_aligned(monster_index(monster), monster->foe))
{
spellOK = false;
}
}
// if not okay, then maybe we'll cast a defensive spell
if (!spellOK)
spell_cast = (coinflip() ? hspell_pass[2] : MS_NO_SPELL);
if (spell_cast != MS_NO_SPELL)
break;
}
}
// should the monster *still* not have a spell, well, too bad {dlb}:
if (spell_cast == MS_NO_SPELL)
return (false);
// Try to animate dead: if nothing rises, pretend we didn't cast it
if (spell_cast == MS_ANIMATE_DEAD
&& !animate_dead( 100, SAME_ATTITUDE(monster), monster->foe, 0 ))
{
return (false);
}
if (monsterNearby) // handle monsters within range of player
{
if (monster->type == MONS_GERYON)
{
if (silenced(monster->x, monster->y))
return (false);
simple_monster_message( monster, " winds a great silver horn.",
MSGCH_MONSTER_SPELL );
}
else if (mons_is_demon( monster->type ))
{
simple_monster_message( monster, " gestures.",
MSGCH_MONSTER_SPELL );
}
else
{
switch (monster->type)
{
default:
if (silenced(monster->x, monster->y))
return (false);
if (mons_flag(monster->type, M_PRIEST))
{
switch (random2(3))
{
case 0:
simple_monster_message( monster,
" prays.",
MSGCH_MONSTER_SPELL );
break;
case 1:
simple_monster_message( monster,
" mumbles some strange prayers.",
MSGCH_MONSTER_SPELL );
break;
case 2:
default:
simple_monster_message( monster,
" utters an invocation.",
MSGCH_MONSTER_SPELL );
break;
}
}
else
{
switch (random2(3))
{
case 0:
// XXX: could be better, chosen to match the
// ones in monspeak.cc... has the problem
// that it doesn't suggest a vocal component. -- bwr
simple_monster_message( monster,
" gestures wildly.",
MSGCH_MONSTER_SPELL );
break;
case 1:
simple_monster_message( monster,
" mumbles some strange words.",
MSGCH_MONSTER_SPELL );
break;
case 2:
default:
simple_monster_message( monster,
" casts a spell.",
MSGCH_MONSTER_SPELL );
break;
}
}
break;
case MONS_BALL_LIGHTNING:
monster->hit_points = -1;
break;
case MONS_STEAM_DRAGON:
case MONS_MOTTLED_DRAGON:
case MONS_STORM_DRAGON:
case MONS_GOLDEN_DRAGON:
case MONS_SHADOW_DRAGON:
case MONS_SWAMP_DRAGON:
case MONS_SWAMP_DRAKE:
case MONS_HELL_HOG:
case MONS_SERPENT_OF_HELL:
case MONS_QUICKSILVER_DRAGON:
case MONS_IRON_DRAGON:
if (!simple_monster_message(monster, " breathes.",
MSGCH_MONSTER_SPELL))
{
if (!silenced(monster->x, monster->y)
&& !silenced(you.x_pos, you.y_pos))
{
mpr("You hear a roar.", MSGCH_MONSTER_SPELL);
}
}
break;
case MONS_VAPOUR:
mons_add_ench( monster, ENCH_SUBMERGED );
break;
case MONS_BRAIN_WORM:
case MONS_ELECTRIC_GOLEM:
// These don't show any signs that they're casting a spell.
break;
case MONS_GREAT_ORB_OF_EYES:
case MONS_SHINING_EYE:
case MONS_EYE_OF_DEVASTATION:
simple_monster_message(monster, " gazes.", MSGCH_MONSTER_SPELL);
break;
case MONS_GIANT_ORANGE_BRAIN:
simple_monster_message(monster, " pulsates.",
MSGCH_MONSTER_SPELL);
break;
case MONS_NAGA:
case MONS_NAGA_WARRIOR:
simple_monster_message(monster, " spits poison.",
MSGCH_MONSTER_SPELL);
break;
}
}
}
else // handle far-away monsters
{
if (monster->type == MONS_GERYON
&& !silenced(you.x_pos, you.y_pos))
{
mpr("You hear a weird and mournful sound.");
}
}
// FINALLY! determine primary spell effects {dlb}:
if (spell_cast == MS_BLINK && monsterNearby)
// why only cast blink if nearby? {dlb}
{
simple_monster_message(monster, " blinks!");
monster_blink(monster);
}
else
{
mons_cast(monster, beem, spell_cast);
mmov_x = 0;
}
} // end "if mons_flag(monster->type, M_SPELLCASTER) ...
return (true);
} // end handle_spell()
//---------------------------------------------------------------
//
// handle_throw
//
// Give the monster a chance to throw something. Returns true if
// the monster hurled.
//
//---------------------------------------------------------------
static bool handle_throw(struct monsters *monster, bolt & beem)
{
// yes, there is a logic to this ordering {dlb}:
if (mons_has_ench(monster, ENCH_CONFUSION) || monster->behaviour == BEH_SLEEP)
return (false);
if (mons_itemuse(monster->type) < MONUSE_OPEN_DOORS)
return (false);
const int mon_item = monster->inv[MSLOT_MISSILE];
if (mon_item == NON_ITEM || !is_valid_item( mitm[mon_item] ))
return (false);
// don't allow offscreen throwing.. for now.
if (monster->foe == MHITYOU && !mons_near(monster))
return (false);
// poor 2-headed ogres {dlb}
if (monster->type == MONS_TWO_HEADED_OGRE || monster->type == MONS_ETTIN)
return (false);
// recent addition {GDL} - monsters won't throw if they can do melee.
// wastes valuable ammo, and most monsters are better at melee anyway.
if (adjacent( beem.target_x, beem.target_y, monster->x, monster->y ))
return (false);
if (one_chance_in(5))
return (false);
// new (GDL) - don't throw idiotic stuff. It's a waste of time.
int wepClass = mitm[mon_item].base_type;
int wepType = mitm[mon_item].sub_type;
int weapon = monster->inv[MSLOT_WEAPON];
int lnchClass = (weapon != NON_ITEM) ? mitm[weapon].base_type : -1;
int lnchType = (weapon != NON_ITEM) ? mitm[weapon].sub_type : 0;
bool thrown = false;
bool launched = false;
throw_type( lnchClass, lnchType, wepClass, wepType, launched, thrown );
if (!launched && !thrown)
return (false);
// ok, we'll try it.
setup_generic_throw( monster, beem );
// fire tracer
fire_tracer( monster, beem );
// good idea?
if (mons_should_fire( beem ))
{
beem.beam_name[0] = '\0';
return (mons_throw( monster, beem, mon_item ));
}
return (false);
} // end handle_throw()
//---------------------------------------------------------------
//
// handle_monsters
//
// This is the routine that controls monster AI.
//
//---------------------------------------------------------------
void handle_monsters(void)
{
bool brkk = false;
struct bolt beem;
int i;
FixedArray < unsigned int, 19, 19 > show;
// losight(show, grd, you.x_pos, you.y_pos);
for (i = 0; i < MAX_MONSTERS; i++)
{
struct monsters *monster = &menv[i];
if (monster->type != -1)
{
if (monster->hit_points > monster->max_hit_points)
monster->hit_points = monster->max_hit_points;
// monster just summoned (or just took stairs), skip this action
if (testbits( monster->flags, MF_JUST_SUMMONED ))
{
monster->flags &= ~MF_JUST_SUMMONED;
continue;
}
monster->speed_increment += (monster->speed * you.time_taken) / 10;
if (you.slow > 0)
{
monster->speed_increment += (monster->speed * you.time_taken) / 10;
}
// Handle enchantments and clouds on nonmoving monsters:
if (monster->speed == 0)
{
if (env.cgrid[monster->x][monster->y] != EMPTY_CLOUD
&& !mons_has_ench( monster, ENCH_SUBMERGED ))
{
mons_in_cloud( monster );
}
handle_enchantment( monster );
}
while (monster->speed_increment >= 80)
{ // The continues & breaks are WRT this.
if (monster->type != -1 && monster->hit_points < 1)
break;
monster->speed_increment -= 10;
if (env.cgrid[monster->x][monster->y] != EMPTY_CLOUD)
{
if (mons_has_ench( monster, ENCH_SUBMERGED ))
break;
if (monster->type == -1)
break; // problem with vortices
mons_in_cloud(monster);
if (monster->type == -1)
{
monster->speed_increment = 1;
break;
}
}
if (monster->type == MONS_GLOWING_SHAPESHIFTER)
mons_add_ench( monster, ENCH_GLOWING_SHAPESHIFTER );
// otherwise there are potential problems with summonings
if (monster->type == MONS_SHAPESHIFTER)
mons_add_ench( monster, ENCH_SHAPESHIFTER );
// memory is decremented here for a reason -- we only want it
// decrementing once per monster "move"
if (monster->foe_memory > 0)
monster->foe_memory --;
handle_behaviour(monster);
if (handle_enchantment(monster))
continue;
// submerging monsters will hide from clouds
const int habitat = monster_habitat( monster->type );
if (habitat != DNGN_FLOOR
&& habitat == grd[monster->x][monster->y]
&& env.cgrid[monster->x][monster->y] != EMPTY_CLOUD)
{
mons_add_ench( monster, ENCH_SUBMERGED );
}
// regenerate:
if (monster_descriptor(monster->type, MDSC_REGENERATES)
|| (monster->type == MONS_FIRE_ELEMENTAL
&& (grd[monster->x][monster->y] == DNGN_LAVA
|| env.cgrid[monster->x][monster->y] == CLOUD_FIRE
|| env.cgrid[monster->x][monster->y] == CLOUD_FIRE_MON))
|| (monster->type == MONS_WATER_ELEMENTAL
&& (grd[monster->x][monster->y] == DNGN_SHALLOW_WATER
|| grd[monster->x][monster->y] == DNGN_DEEP_WATER))
|| (monster->type == MONS_AIR_ELEMENTAL
&& env.cgrid[monster->x][monster->y] == EMPTY_CLOUD
&& one_chance_in(3))
|| one_chance_in(25))
{
heal_monster(monster, 1, false);
}
if (monster->speed >= 100)
continue;
if (monster->type == MONS_ZOMBIE_SMALL
|| monster->type == MONS_ZOMBIE_LARGE
|| monster->type == MONS_SIMULACRUM_SMALL
|| monster->type == MONS_SIMULACRUM_LARGE
|| monster->type == MONS_SKELETON_SMALL
|| monster->type == MONS_SKELETON_LARGE)
{
monster->max_hit_points = monster->hit_points;
}
if (igrd[monster->x][monster->y] != NON_ITEM
&& (mons_itemuse(monster->type) == MONUSE_WEAPONS_ARMOUR
|| mons_itemuse(monster->type) == MONUSE_EATS_ITEMS
|| monster->type == MONS_NECROPHAGE
|| monster->type == MONS_GHOUL))
{
if (handle_pickup(monster))
continue;
}
// calculates mmov_x, mmov_y based on monster target.
handle_movement(monster);
brkk = false;
if (mons_has_ench( monster, ENCH_CONFUSION )
|| (monster->type == MONS_AIR_ELEMENTAL
&& mons_has_ench( monster, ENCH_SUBMERGED )))
{
mmov_x = random2(3) - 1;
mmov_y = random2(3) - 1;
// bounds check: don't let confused monsters try to run
// off the map
if (monster->target_x + mmov_x < 0
|| monster->target_x + mmov_x >= GXM)
{
mmov_x = 0;
}
if (monster->target_y + mmov_y < 0
|| monster->target_y + mmov_y >= GYM)
{
mmov_y = 0;
}
if (mgrd[monster->x + mmov_x][monster->y + mmov_y] != NON_MONSTER
&& (mmov_x != 0 || mmov_y != 0))
{
mmov_x = 0;
mmov_y = 0;
if (monsters_fight(i, mgrd[monster->x + mmov_x][monster->y + mmov_y]))
{
brkk = true;
}
}
}
if (brkk)
continue;
handle_nearby_ability( monster );
beem.target_x = monster->target_x;
beem.target_y = monster->target_y;
if (monster->behaviour != BEH_SLEEP
&& monster->behaviour != BEH_WANDER)
{
// prevents unfriendlies from nuking you from offscreen.
// How nice!
if (mons_friendly(monster) || mons_near(monster))
{
if (handle_special_ability(monster, beem))
continue;
if (handle_potion(monster, beem))
continue;
if (handle_scroll(monster))
continue;
// shapeshifters don't get spells
if (!mons_has_ench( monster, ENCH_GLOWING_SHAPESHIFTER,
ENCH_SHAPESHIFTER )
|| !mons_flag( monster->type, M_ACTUAL_SPELLS ))
{
if (handle_spell(monster, beem))
continue;
}
if (handle_wand(monster, beem))
continue;
if (handle_reaching(monster))
continue;
}
if (handle_throw(monster, beem))
continue;
}
// see if we move into (and fight) an unfriendly monster
int targmon = mgrd[monster->x + mmov_x][monster->y + mmov_y];
if (targmon != i && targmon != NON_MONSTER
&& !mons_aligned(i, targmon))
{
// figure out if they fight
if (monsters_fight(i, targmon))
{
if (testbits(monster->flags, MF_BATTY))
{
monster->behaviour = BEH_WANDER;
monster->foe = MHITNOT;
monster->speed_increment -= monster->speed;
}
mmov_x = 0;
mmov_y = 0;
brkk = true;
}
}
if (brkk)
continue;
if (monster->x + mmov_x == you.x_pos
&& monster->y + mmov_y == you.y_pos)
{
bool isFriendly = mons_friendly(monster);
bool attacked = false;
if (!isFriendly)
{
monster_attack(i);
attacked = true;
if (testbits(monster->flags, MF_BATTY))
{
monster->behaviour = BEH_WANDER;
monster->foe = MHITNOT;
}
}
if ((monster->type == MONS_GIANT_SPORE
|| monster->type == MONS_BALL_LIGHTNING)
&& monster->hit_points < 1)
{
// detach monster from the grid first, so it
// doesn't get hit by its own explosion (GDL)
mgrd[monster->x][monster->y] = NON_MONSTER;
spore_goes_pop(monster);
monster_cleanup(monster);
continue;
}
if (attacked)
{
mmov_x = 0;
mmov_y = 0;
continue; //break;
}
}
if (monster->type == -1 || monster->type == MONS_OKLOB_PLANT
|| monster->type == MONS_CURSE_SKULL
|| (monster->type >= MONS_CURSE_TOE
&& monster->type <= MONS_POTION_MIMIC))
{
continue;
}
monster_move(monster);
// reevaluate behaviour, since the monster's
// surroundings have changed (it may have moved,
// or died for that matter. Don't bother for
// dead monsters. :)
if (monster->type != -1)
handle_behaviour(monster);
} // end while
if (monster->type != -1 && monster->hit_points < 1)
{
if (monster->type == MONS_GIANT_SPORE
|| monster->type == MONS_BALL_LIGHTNING)
{
// detach monster from the grid first, so it
// doesn't get hit by its own explosion (GDL)
mgrd[monster->x][monster->y] = NON_MONSTER;
spore_goes_pop( monster );
monster_cleanup( monster );
continue;
}
else
{
monster_die( monster, KILL_MISC, 0 );
}
}
} // end of if (mons_class != -1)
} // end of for loop
// Clear any summoning flags so that lower indiced
// monsters get their actions in the next round.
for (i = 0; i < MAX_MONSTERS; i++)
{
menv[i].flags &= ~MF_JUST_SUMMONED;
}
} // end handle_monster()
//---------------------------------------------------------------
//
// handle_pickup
//
// Returns false if monster doesn't spend any time pickup up
//
//---------------------------------------------------------------
static bool handle_pickup(struct monsters *monster)
{
// single calculation permissible {dlb}
bool monsterNearby = mons_near(monster);
int item = NON_ITEM;
if (monster->type == MONS_JELLY
|| monster->type == MONS_BROWN_OOZE
|| monster->type == MONS_ACID_BLOB
|| monster->type == MONS_ROYAL_JELLY)
{
int hps_gained = 0;
int max_eat = roll_dice( 1, 10 );
int eaten = 0;
for (item = igrd[monster->x][monster->y];
item != NON_ITEM && eaten < max_eat && hps_gained < 50;
item = mitm[item].link)
{
int quant = mitm[item].quantity;
if (is_fixed_artefact( mitm[item] ))
continue;
if (mitm[item].base_type == OBJ_MISSILES
&& (mitm[item].sub_type == MI_STONE
|| mitm[item].sub_type == MI_LARGE_ROCK))
{
// shouldn't eat stone things
// - but what about wands and rings?
continue;
}
if (mitm[igrd[monster->x][monster->y]].base_type != OBJ_GOLD)
{
if (quant > max_eat - eaten)
quant = max_eat - eaten;
hps_gained += (quant * mass_item( mitm[item] )) / 20 + quant;
eaten += quant;
}
else
{
// shouldn't be much trouble to digest a huge pile of gold!
if (quant > 500)
quant = 500 + roll_dice( 2, (quant - 500) / 2 );
hps_gained += quant / 10 + 1;
eaten++;
}
dec_mitm_item_quantity( item, quant );
}
if (eaten)
{
if (hps_gained < 1)
hps_gained = 1;
else if (hps_gained > 50)
hps_gained = 50;
// This is done manually instead of using heal_monster(),
// because that function doesn't work quite this way. -- bwr
monster->hit_points += hps_gained;
if (monster->max_hit_points < monster->hit_points)
monster->max_hit_points = monster->hit_points;
if (!silenced(you.x_pos, you.y_pos)
&& !silenced(monster->x, monster->y))
{
strcpy(info, "You hear a");
if (!monsterNearby)
strcat(info, " distant");
strcat(info, " slurping noise.");
mpr(info);
}
if (mons_flag( monster->type, M_SPLITS ))
{
const int reqd = (monster->hit_dice <= 6)
? 50 : monster->hit_dice * 8;
if (monster->hit_points >= reqd)
jelly_divide(monster);
}
}
return (false);
} // end "if jellies"
// Note: Monsters only look at top of stacks.
item = igrd[monster->x][monster->y];
switch (mitm[item].base_type)
{
case OBJ_WEAPONS:
if (monster->inv[MSLOT_WEAPON] != NON_ITEM)
return (false);
if (is_fixed_artefact( mitm[item] ))
return (false);
if (is_random_artefact( mitm[item] ))
return (false);
// wimpy monsters (Kob, gob) shouldn't pick up halberds etc
// of course, this also block knives {dlb}:
if ((mons_charclass(monster->type) == MONS_KOBOLD
|| mons_charclass(monster->type) == MONS_GOBLIN)
&& property( mitm[item], PWPN_HIT ) <= 0)
{
return (false);
}
// Nobody picks up giant clubs:
if (mitm[item].sub_type == WPN_GIANT_CLUB
|| mitm[item].sub_type == WPN_GIANT_SPIKED_CLUB)
{
return (false);
}
monster->inv[MSLOT_WEAPON] = item;
if (get_weapon_brand(mitm[monster->inv[MSLOT_WEAPON]]) == SPWPN_PROTECTION)
{
monster->armour_class += 3;
}
if (monsterNearby)
{
strcpy(info, ptr_monam(monster, DESC_CAP_THE));
strcat(info, " picks up ");
it_name(monster->inv[MSLOT_WEAPON], DESC_NOCAP_A, str_pass);
strcat(info, str_pass);
strcat(info, ".");
mpr(info);
}
break;
case OBJ_MISSILES:
// fleeing monsters never stop to pick up ammo
if (monster->behaviour == BEH_FLEE)
return (false);
// don't pick up if we're in combat, and there isn't
// much there
if (mitm[item].quantity < 5 && monster->behaviour != BEH_WANDER)
{
return (false);
}
if (monster->inv[MSLOT_MISSILE] != NON_ITEM
&& mitm[monster->inv[MSLOT_MISSILE]].sub_type == mitm[item].sub_type
&& mitm[monster->inv[MSLOT_MISSILE]].plus == mitm[item].plus
&& mitm[monster->inv[MSLOT_MISSILE]].special == mitm[item].special)
{
if (monsterNearby)
{
strcpy(info, ptr_monam(monster, DESC_CAP_THE));
strcat(info, " picks up ");
it_name(item, DESC_NOCAP_A, str_pass);
strcat(info, str_pass);
strcat(info, ".");
mpr(info);
}
inc_mitm_item_quantity( monster->inv[MSLOT_MISSILE],
mitm[item].quantity );
dec_mitm_item_quantity( item, mitm[item].quantity );
return (true);
}
// nobody bothers to pick up rocks if they don't already have some:
if (mitm[item].sub_type == MI_LARGE_ROCK)
return (false);
// monsters with powerful melee attacks don't bother
if (mons_damage(monster->type, 0) > 5)
return (false);
monster->inv[MSLOT_MISSILE] = item;
if (monsterNearby)
{
strcpy(info, ptr_monam(monster, DESC_CAP_THE));
strcat(info, " picks up ");
it_name(monster->inv[MSLOT_MISSILE], DESC_NOCAP_A, str_pass);
strcat(info, str_pass);
strcat(info, ".");
mpr(info);
}
break;
case OBJ_WANDS:
if (monster->inv[MSLOT_WAND] != NON_ITEM)
return (false);
monster->inv[MSLOT_WAND] = item;
if (monsterNearby)
{
strcpy(info, ptr_monam(monster, DESC_CAP_THE));
strcat(info, " picks up ");
it_name(monster->inv[MSLOT_WAND], DESC_NOCAP_A, str_pass);
strcat(info, str_pass);
strcat(info, ".");
mpr(info);
}
break;
case OBJ_SCROLLS:
if (monster->inv[MSLOT_SCROLL] != NON_ITEM)
return (false);
monster->inv[MSLOT_SCROLL] = item;
if (monsterNearby)
{
strcpy(info, ptr_monam(monster, DESC_CAP_THE));
strcat(info, " picks up ");
it_name(monster->inv[MSLOT_SCROLL], DESC_NOCAP_A, str_pass);
strcat(info, str_pass);
strcat(info, ".");
mpr(info);
}
break;
case OBJ_POTIONS:
if (monster->inv[MSLOT_POTION] != NON_ITEM)
return (false);
monster->inv[MSLOT_POTION] = item;
if (monsterNearby)
{
strcpy(info, ptr_monam(monster, DESC_CAP_THE));
strcat(info, " picks up ");
it_name(monster->inv[MSLOT_POTION], DESC_NOCAP_A, str_pass);
strcat(info, str_pass);
strcat(info, ".");
mpr(info);
}
break;
case OBJ_CORPSES:
if (monster->type != MONS_NECROPHAGE && monster->type != MONS_GHOUL)
return (false);
monster->hit_points += 1 + random2(mons_weight(mitm[item].plus)) / 100;
// limited growth factor here -- should 77 really be the cap? {dlb}:
if (monster->hit_points > 100)
monster->hit_points = 100;
if (monster->hit_points > monster->max_hit_points)
monster->max_hit_points = monster->hit_points;
if (monsterNearby)
{
strcpy(info, ptr_monam(monster, DESC_CAP_THE));
strcat(info, " eats ");
it_name(item, DESC_NOCAP_THE, str_pass);
strcat(info, str_pass);
strcat(info, ".");
mpr(info);
}
destroy_item( item );
return (true);
case OBJ_GOLD: //mv - monsters now pick up gold (19 May 2001)
if (monsterNearby)
{
strcpy(info, monam( monster->number, monster->type,
player_monster_visible( monster ),
DESC_CAP_THE ));
strcat(info, " picks up some gold.");
mpr(info);
}
if (monster->inv[MSLOT_GOLD] != NON_ITEM)
{
// transfer gold to monster's object, destroy ground object
inc_mitm_item_quantity( monster->inv[MSLOT_GOLD],
mitm[item].quantity );
destroy_item( item );
return (true);
}
else
{
monster->inv[MSLOT_GOLD] = item;
}
break;
default:
return (false);
}
// Item has been picked-up, move to monster inventory.
mitm[item].x = 0;
mitm[item].y = 0;
// Monster's only take the top item of stacks, so relink the
// top item, and unlink the item.
igrd[monster->x][monster->y] = mitm[item].link;
mitm[item].link = NON_ITEM;
if (monster->speed_increment > 25)
monster->speed_increment -= monster->speed;
return (true);
} // end handle_pickup()
static void monster_move(struct monsters *monster)
{
FixedArray < bool, 3, 3 > good_move;
int count_x, count_y, count;
int okmove = DNGN_SHALLOW_WATER;
const int habitat = monster_habitat( monster->type );
bool deep_water_available = false;
// let's not even bother with this if mmov_x and mmov_y are zero.
if (mmov_x == 0 && mmov_y == 0)
return;
// effectively slows down monster movement across water.
// Fire elementals can't cross at all.
if (monster->type == MONS_FIRE_ELEMENTAL || one_chance_in(5))
okmove = DNGN_WATER_STUCK;
if (mons_flies(monster) > 0 || habitat != DNGN_FLOOR)
{
okmove = MINMOVE;
}
for (count_x = 0; count_x < 3; count_x++)
{
for (count_y = 0; count_y < 3; count_y++)
{
good_move[count_x][count_y] = true;
const int targ_x = monster->x + count_x - 1;
const int targ_y = monster->y + count_y - 1;
int target_grid = grd[targ_x][targ_y];
const int targ_cloud = env.cgrid[ targ_x ][ targ_y ];
const int curr_cloud = env.cgrid[ monster->x ][ monster->y ];
// bounds check - don't consider moving out of grid!
if (targ_x < 0 || targ_x >= GXM || targ_y < 0 || targ_y >= GYM)
{
good_move[count_x][count_y] = false;
continue;
}
if (target_grid == DNGN_DEEP_WATER)
deep_water_available = true;
if (monster->type == MONS_BORING_BEETLE
&& target_grid == DNGN_ROCK_WALL)
{
// don't burrow out of bounds
if (targ_x <= 7 || targ_x >= (GXM - 8)
|| targ_y <= 7 || targ_y >= (GYM - 8))
{
good_move[count_x][count_y] = false;
continue;
}
// don't burrow at an angle (legacy behaviour)
if (count_x != 1 && count_y != 1)
{
good_move[count_x][count_y] = false;
continue;
}
}
else if (grd[ targ_x ][ targ_y ] < okmove)
{
good_move[count_x][count_y] = false;
continue;
}
else if (!habitat_okay( monster, target_grid ))
{
good_move[count_x][count_y] = false;
continue;
}
if (monster->type == MONS_WANDERING_MUSHROOM
&& see_grid(targ_x, targ_y))
{
good_move[count_x][count_y] = false;
continue;
}
// Water elementals avoid fire and heat
if (monster->type == MONS_WATER_ELEMENTAL
&& (target_grid == DNGN_LAVA
|| targ_cloud == CLOUD_FIRE
|| targ_cloud == CLOUD_FIRE_MON
|| targ_cloud == CLOUD_STEAM
|| targ_cloud == CLOUD_STEAM_MON))
{
good_move[count_x][count_y] = false;
continue;
}
// Fire elementals avoid water and cold
if (monster->type == MONS_FIRE_ELEMENTAL
&& (target_grid == DNGN_DEEP_WATER
|| target_grid == DNGN_SHALLOW_WATER
|| target_grid == DNGN_BLUE_FOUNTAIN
|| targ_cloud == CLOUD_COLD
|| targ_cloud == CLOUD_COLD_MON))
{
good_move[count_x][count_y] = false;
continue;
}
// Submerged water creatures avoid the shallows where
// they would be forced to surface. -- bwr
if (habitat == DNGN_DEEP_WATER
&& (targ_x != you.x_pos || targ_y != you.y_pos)
&& target_grid != DNGN_DEEP_WATER
&& grd[monster->x][monster->y] == DNGN_DEEP_WATER
&& (mons_has_ench( monster, ENCH_SUBMERGED )
|| monster->hit_points < (monster->max_hit_points * 3) / 4))
{
good_move[count_x][count_y] = false;
continue;
}
// smacking the player is always a good move if
// we're hostile (even if we're heading somewhere
// else)
// smacking another monster is good, if the monsters
// are aligned differently
if (mgrd[targ_x][targ_y] != NON_MONSTER)
{
if (mons_aligned(monster_index(monster), mgrd[targ_x][targ_y]))
{
good_move[count_x][count_y] = false;
continue;
}
}
// wandering through a trap is OK if we're pretty healthy, or
// really stupid.
if (trap_at_xy(targ_x,targ_y) >= 0
&& mons_intel(monster->type) != I_PLANT)
{
if (monster->hit_points < monster->max_hit_points / 2)
{
good_move[count_x][count_y] = false;
continue;
}
}
if (targ_cloud != EMPTY_CLOUD)
{
if (curr_cloud != EMPTY_CLOUD
&& env.cloud[targ_cloud].type == env.cloud[curr_cloud].type)
{
continue;
}
switch (env.cloud[ targ_cloud ].type)
{
case CLOUD_FIRE:
case CLOUD_FIRE_MON:
if (mons_res_fire(monster) > 0)
continue;
if (monster->hit_points >= 15 + random2avg(46, 5))
continue;
break;
case CLOUD_STINK:
case CLOUD_STINK_MON:
if (mons_res_poison(monster) > 0)
continue;
if (1 + random2(5) < monster->hit_dice)
continue;
if (monster->hit_points >= random2avg(19, 2))
continue;
break;
case CLOUD_COLD:
case CLOUD_COLD_MON:
if (mons_res_cold(monster) > 0)
continue;
if (monster->hit_points >= 15 + random2avg(46, 5))
continue;
break;
case CLOUD_POISON:
case CLOUD_POISON_MON:
if (mons_res_poison(monster) > 0)
continue;
if (monster->hit_points >= random2avg(37, 4))
continue;
break;
// this isn't harmful, but dumb critters might think so.
case CLOUD_GREY_SMOKE:
case CLOUD_GREY_SMOKE_MON:
if (mons_intel(monster->type) > I_ANIMAL || coinflip())
continue;
if (mons_res_fire(monster) > 0)
continue;
if (monster->hit_points >= random2avg(19, 2))
continue;
break;
default:
continue; // harmless clouds
}
// if we get here, the cloud is potentially harmful.
// exceedingly dumb creatures will still wander in.
if (mons_intel(monster->type) != I_PLANT)
good_move[count_x][count_y] = false;
}
}
} // now we know where we _can_ move.
// normal/smart monsters know about secret doors (they _live_ in the
// dungeon!)
if (grd[monster->x + mmov_x][monster->y + mmov_y] == DNGN_CLOSED_DOOR
|| (grd[monster->x + mmov_x][monster->y + mmov_y] == DNGN_SECRET_DOOR
&& (mons_intel(monster_index(monster)) == I_HIGH
|| mons_intel(monster_index(monster)) == I_NORMAL)))
{
if (monster->type == MONS_ZOMBIE_SMALL
|| monster->type == MONS_ZOMBIE_LARGE
|| monster->type == MONS_SIMULACRUM_SMALL
|| monster->type == MONS_SIMULACRUM_LARGE
|| monster->type == MONS_SKELETON_SMALL
|| monster->type == MONS_SKELETON_LARGE
|| monster->type == MONS_SPECTRAL_THING)
{
// for zombies, monster type is kept in mon->number
if (mons_itemuse(monster->number) >= MONUSE_OPEN_DOORS)
{
grd[monster->x + mmov_x][monster->y + mmov_y] = DNGN_OPEN_DOOR;
return;
}
}
else if (mons_itemuse(monster->type) >= MONUSE_OPEN_DOORS)
{
grd[monster->x + mmov_x][monster->y + mmov_y] = DNGN_OPEN_DOOR;
return;
}
} // endif - secret/closed doors
// jellies eat doors. Yum!
if ((grd[monster->x + mmov_x][monster->y + mmov_y] == DNGN_CLOSED_DOOR
|| grd[monster->x + mmov_x][monster->y + mmov_y] == DNGN_OPEN_DOOR)
&& mons_itemuse(monster->type) == MONUSE_EATS_ITEMS)
{
grd[monster->x + mmov_x][monster->y + mmov_y] = DNGN_FLOOR;
if (!silenced(you.x_pos, you.y_pos)
&& !silenced(monster->x, monster->y))
{
strcpy(info, "You hear a");
if (!mons_near(monster))
strcat(info, " distant");
strcat(info, " slurping noise.");
mpr(info);
}
monster->hit_points += 5;
// note here, that this makes jellies "grow" {dlb}:
if (monster->hit_points > monster->max_hit_points)
monster->max_hit_points = monster->hit_points;
if (mons_flag( monster->type, M_SPLITS ))
{
// and here is where the jelly might divide {dlb}
const int reqd = (monster->hit_dice < 6) ? 50
: monster->hit_dice * 8;
if (monster->hit_points >= reqd)
jelly_divide(monster);
}
} // done door-eating jellies
// water creatures have a preferance for water they can hide in -- bwr
if (habitat == DNGN_DEEP_WATER
&& deep_water_available
&& grd[monster->x][monster->y] != DNGN_DEEP_WATER
&& grd[monster->x + mmov_x][monster->y + mmov_y] != DNGN_DEEP_WATER
&& (monster->x + mmov_x != you.x_pos
|| monster->y + mmov_y != you.y_pos)
&& (coinflip()
|| monster->hit_points <= (monster->max_hit_points * 3) / 4))
{
count = 0;
for (count_x = 0; count_x < 3; count_x++)
{
for (count_y = 0; count_y < 3; count_y++)
{
if (good_move[count_x][count_y]
&& grd[monster->x + count_x - 1][monster->y + count_y - 1]
== DNGN_DEEP_WATER)
{
count++;
if (one_chance_in( count ))
{
mmov_x = count_x - 1;
mmov_y = count_y - 1;
}
}
}
}
}
// now, if a monster can't move in its intended direction, try
// either side. If they're both good, move in whichever dir
// gets it closer(farther for fleeing monsters) to its target.
// If neither does, do nothing.
if (good_move[mmov_x + 1][mmov_y + 1] == false)
{
int current_distance = grid_distance( monster->x, monster->y,
monster->target_x,
monster->target_y );
int dir = -1;
int i, mod, newdir;
for(i=0; i<8; i++)
{
if (compass_x[i] == mmov_x && compass_y[i] == mmov_y)
{
dir = i;
break;
}
}
if (dir < 0)
goto forget_it;
int dist[2];
// first 1 away, then 2 (3 is silly)
for (int j=1; j<3; j++)
{
int sdir, inc;
if (coinflip())
{
sdir = -j;
inc = 2*j;
}
else
{
sdir = j;
inc = -2*j;
}
// try both directions
for(mod = sdir, i=0; i<2; mod += inc, i++)
{
newdir = (dir + 8 + mod) % 8;
if (good_move[compass_x[newdir] + 1][compass_y[newdir] + 1])
{
dist[i] = grid_distance( monster->x + compass_x[newdir],
monster->y + compass_y[newdir],
monster->target_x,
monster->target_y );
}
else
{
dist[i] = (monster->behaviour == BEH_FLEE) ? (-FAR_AWAY)
: FAR_AWAY;
}
}
// now choose
if (dist[0] == dist[1] && abs(dist[0]) == FAR_AWAY)
continue;
// which one was better? -- depends on FLEEING or not
if (monster->behaviour == BEH_FLEE)
{
if (dist[0] >= dist[1] && dist[0] > current_distance)
{
mmov_x = compass_x[((dir+8)+sdir)%8];
mmov_y = compass_y[((dir+8)+sdir)%8];
break;
}
if (dist[1] >= dist[0] && dist[1] > current_distance)
{
mmov_x = compass_x[((dir+8)-sdir)%8];
mmov_y = compass_y[((dir+8)-sdir)%8];
break;
}
}
else
{
if (dist[0] <= dist[1] && dist[0] < current_distance)
{
mmov_x = compass_x[((dir+8)+sdir)%8];
mmov_y = compass_y[((dir+8)+sdir)%8];
break;
}
if (dist[1] <= dist[0] && dist[1] < current_distance)
{
mmov_x = compass_x[((dir+8)-sdir)%8];
mmov_y = compass_y[((dir+8)-sdir)%8];
break;
}
}
}
} // end - try to find good alternate move
forget_it:
// ------------------------------------------------------------------
// if we haven't found a good move by this point, we're not going to.
// ------------------------------------------------------------------
// take care of beetle burrowing
if (monster->type == MONS_BORING_BEETLE)
{
if (grd[monster->x + mmov_x][monster->y + mmov_y] == DNGN_ROCK_WALL
&& good_move[mmov_x + 1][mmov_y + 1] == true)
{
grd[monster->x + mmov_x][monster->y + mmov_y] = DNGN_FLOOR;
if (!silenced(you.x_pos, you.y_pos))
mpr("You hear a grinding noise.");
}
}
mgrd[monster->x][monster->y] = NON_MONSTER;
if (good_move[mmov_x + 1][mmov_y + 1] && !(mmov_x == 0 && mmov_y == 0))
{
// check for attacking player
if (monster->x + mmov_x == you.x_pos
&& monster->y + mmov_y == you.y_pos)
{
monster_attack( monster_index(monster) );
mmov_x = 0;
mmov_y = 0;
}
// If we're following the player through stairs, the only valid
// movement is towards the player. -- bwr
if (testbits( monster->flags, MF_TAKING_STAIRS ))
{
#if DEBUG_DIAGNOSTICS
snprintf( info, INFO_SIZE, "%s is skipping movement in order to follow.",
ptr_monam( monster, DESC_CAP_THE ) );
mpr( info, MSGCH_DIAGNOSTIC );
#endif
mmov_x = 0;
mmov_y = 0;
}
else
{
// check for attacking another monster
int targmon = mgrd[monster->x + mmov_x][monster->y + mmov_y];
if (targmon != NON_MONSTER)
{
monsters_fight(monster_index(monster), targmon);
mmov_x = 0;
mmov_y = 0;
}
if (monster->type == MONS_EFREET
|| monster->type == MONS_FIRE_ELEMENTAL)
{
place_cloud( CLOUD_FIRE_MON, monster->x, monster->y,
2 + random2(4) );
}
/* this appears to be the real one, ie where the movement occurs: */
monster->x += mmov_x;
monster->y += mmov_y;
}
}
else
{
// fleeing monsters that can't move will panic and possibly
// turn to face their attacker
if (monster->behaviour == BEH_FLEE)
behaviour_event(monster, ME_CORNERED);
}
/* need to put in something so that monster picks up multiple
items (eg ammunition) identical to those it's carrying. */
mgrd[monster->x][monster->y] = monster_index(monster);
// monsters stepping on traps:
if (grd[monster->x][monster->y] >= DNGN_TRAP_MECHANICAL
&& grd[monster->x][monster->y] <= DNGN_UNDISCOVERED_TRAP
&& (mmov_x != 0 || mmov_y != 0))
{
mons_trap(monster);
}
} // end monster_move()
static bool plant_spit(struct monsters *monster, struct bolt &pbolt)
{
bool didSpit = false;
char spit_string[100];
// setup plant spit
strcpy( pbolt.beam_name, "acid" );
pbolt.type = SYM_ZAP;
pbolt.range = 9;
pbolt.rangeMax = 9;
pbolt.colour = YELLOW;
pbolt.flavour = BEAM_ACID;
pbolt.beam_source = monster_index(monster);
pbolt.damage = dice_def( 3, 7 );
pbolt.hit = 20 + (3 * monster->hit_dice);
pbolt.thrower = KILL_MON_MISSILE;
// fire tracer
fire_tracer(monster, pbolt);
if (mons_should_fire(pbolt))
{
strcpy( spit_string, " spits" );
if (pbolt.target_x == you.x_pos && pbolt.target_y == you.y_pos)
strcat( spit_string, " at you" );
strcat( spit_string, "." );
simple_monster_message( monster, spit_string );
beam( pbolt );
didSpit = true;
}
return (didSpit);
} // end plant_spit()
static void mons_in_cloud(struct monsters *monster)
{
int wc = env.cgrid[monster->x][monster->y];
int hurted = 0;
struct bolt beam;
const int speed = ((monster->speed > 0) ? monster->speed : 10);
if (mons_charclass(monster->type) == MONS_GOLD_MIMIC)
{
mimic_alert(monster);
return;
}
switch (env.cloud[wc].type)
{
case CLOUD_DEBUGGING:
cprintf("Fatal error: monster steps on nonexistent cloud!");
exit(0);
return;
case CLOUD_FIRE:
case CLOUD_FIRE_MON:
if (monster->type == MONS_FIRE_VORTEX
|| monster->type == MONS_EFREET
|| monster->type == MONS_FIRE_ELEMENTAL)
{
return;
}
simple_monster_message(monster, " is engulfed in flame!");
if (mons_res_fire(monster) > 0)
return;
hurted += ((random2avg(16, 3) + 6) * 10) / speed;
if (mons_res_fire(monster) < 0)
hurted += (random2(15) * 10) / speed;
// remember that the above is in addition to the other you.damage.
hurted -= random2(1 + monster->armour_class);
break; // to damage routine at end {dlb}
case CLOUD_STINK:
case CLOUD_STINK_MON:
simple_monster_message(monster, " is engulfed in noxious gasses!");
if (mons_res_poison(monster) > 0)
return;
beam.flavour = BEAM_CONFUSION;
if (1 + random2(27) >= monster->hit_dice)
mons_ench_f2(monster, beam);
hurted += (random2(3) * 10) / speed;
break; // to damage routine at end {dlb}
case CLOUD_COLD:
case CLOUD_COLD_MON:
simple_monster_message(monster, " is engulfed in freezing vapours!");
if (mons_res_cold(monster) > 0)
return;
hurted += ((6 + random2avg(16, 3)) * 10) / speed;
if (mons_res_cold(monster) < 0)
hurted += (random2(15) * 10) / speed;
// remember that the above is in addition to the other damage.
hurted -= random2(1 + monster->armour_class);
break; // to damage routine at end {dlb}
// what of armour of poison resistance here? {dlb}
case CLOUD_POISON:
case CLOUD_POISON_MON:
simple_monster_message(monster, " is engulfed in a cloud of poison!");
if (mons_res_poison(monster) > 0)
return;
poison_monster(monster, (env.cloud[wc].type == CLOUD_POISON));
hurted += (random2(8) * 10) / speed;
if (mons_res_poison(monster) < 0)
hurted += (random2(4) * 10) / speed;
break; // to damage routine at end {dlb}
case CLOUD_STEAM:
case CLOUD_STEAM_MON:
// couldn't be bothered coding for armour of res fire
// what of whether it is wearing steam dragon armour? {dlb}
if (monster->type == MONS_STEAM_DRAGON)
return;
simple_monster_message(monster, " is engulfed in steam!");
if (mons_res_fire(monster) > 0)
return;
hurted += (random2(6) * 10) / speed;
if (mons_res_fire(monster) < 0)
hurted += (random2(6) * 10) / speed;
hurted -= random2(1 + monster->armour_class);
break; // to damage routine at end {dlb}
case CLOUD_MIASMA:
case CLOUD_MIASMA_MON:
simple_monster_message(monster, " is engulfed in a dark miasma!");
if (mons_holiness(monster->type) != MH_NATURAL)
return;
poison_monster(monster, (env.cloud[wc].type == CLOUD_MIASMA));
if (monster->max_hit_points > 4 && coinflip())
monster->max_hit_points--;
beam.flavour = BEAM_SLOW;
if (one_chance_in(3))
mons_ench_f2(monster, beam);
hurted += (10 * random2avg(12, 3)) / speed; // 3
break; // to damage routine at end {dlb}
default: // 'harmless' clouds -- colored smoke, etc {dlb}.
return;
}
if (hurted < 0)
hurted = 0;
else if (hurted > 0)
{
hurt_monster(monster, hurted);
if (monster->hit_points < 1)
{
switch (env.cloud[wc].type)
{
case CLOUD_FIRE_MON:
case CLOUD_STINK_MON:
case CLOUD_COLD_MON:
case CLOUD_POISON_MON:
case CLOUD_STEAM_MON:
case CLOUD_MIASMA_MON:
monster_die(monster, KILL_MISC, 0);
break;
default:
monster_die(monster, KILL_YOU, 0);
}
switch (env.cloud[wc].type)
{
case CLOUD_FIRE:
case CLOUD_FIRE_MON:
case CLOUD_COLD:
case CLOUD_COLD_MON:
case CLOUD_STEAM:
case CLOUD_STEAM_MON:
monster->speed_increment = 1;
}
}
}
} // end mons_in_cloud()
unsigned char monster_habitat(int which_class)
{
switch (which_class)
{
case MONS_BIG_FISH:
case MONS_GIANT_GOLDFISH:
case MONS_ELECTRICAL_EEL:
case MONS_JELLYFISH:
case MONS_SWAMP_WORM:
case MONS_WATER_ELEMENTAL:
return (DNGN_DEEP_WATER); // no shallow water (only) monsters? {dlb}
// must remain DEEP_WATER for now, else breaks code {dlb}
case MONS_LAVA_WORM:
case MONS_LAVA_FISH:
case MONS_LAVA_SNAKE:
case MONS_SALAMANDER:
return (DNGN_LAVA);
default:
return (DNGN_FLOOR); // closest match to terra firma {dlb}
}
} // end monster_habitat()
bool monster_descriptor(int which_class, unsigned char which_descriptor)
{
if (which_descriptor == MDSC_LEAVES_HIDE)
{
switch (which_class)
{
case MONS_DRAGON:
case MONS_TROLL:
case MONS_ICE_DRAGON:
case MONS_STEAM_DRAGON:
case MONS_MOTTLED_DRAGON:
case MONS_STORM_DRAGON:
case MONS_GOLDEN_DRAGON:
case MONS_SWAMP_DRAGON:
return (true);
default:
return (false);
}
}
if (which_descriptor == MDSC_REGENERATES)
{
switch (which_class)
{
case MONS_CACODEMON:
case MONS_DEEP_TROLL:
case MONS_HELLWING:
case MONS_IMP:
case MONS_IRON_TROLL:
case MONS_LEMURE:
case MONS_ROCK_TROLL:
case MONS_SLIME_CREATURE:
case MONS_SNORG:
case MONS_TROLL:
return (true);
default:
return (false);
}
}
if (which_descriptor == MDSC_NOMSG_WOUNDS)
{
switch (which_class)
{
case MONS_RAKSHASA:
case MONS_RAKSHASA_FAKE:
case MONS_SKELETON_LARGE:
case MONS_SKELETON_SMALL:
case MONS_ZOMBIE_LARGE:
case MONS_ZOMBIE_SMALL:
case MONS_SIMULACRUM_SMALL:
case MONS_SIMULACRUM_LARGE:
return (true);
default:
return (false);
}
}
return (false);
} // end monster_descriptor()
bool message_current_target(void)
{
if (you.prev_targ != MHITNOT && you.prev_targ != MHITYOU)
{
struct monsters *montarget = &menv[you.prev_targ];
if (mons_near(montarget) && player_monster_visible( montarget ))
{
strcpy(info, "You are currently targeting ");
strcat(info, ptr_monam(montarget, DESC_NOCAP_THE));
strcat(info, " (p to target).");
mpr(info);
return (true); // early return {dlb}
}
else
mpr("You have no current target.");
}
return (false);
} // end message_current_target()
// aaah, the simple joys of pointer arithmetic! {dlb}:
unsigned int monster_index(struct monsters *monster)
{
return (monster - menv.buffer());
} // end monster_index()
bool hurt_monster(struct monsters * victim, int damage_dealt)
{
bool just_a_scratch = true;
if (damage_dealt > 0)
{
just_a_scratch = false;
victim->hit_points -= damage_dealt;
}
return (!just_a_scratch);
} // end hurt_monster()
bool heal_monster(struct monsters * patient, int health_boost,
bool permit_growth)
{
if (health_boost < 1)
return (false);
else if (!permit_growth && patient->hit_points == patient->max_hit_points)
return (false);
else
{
patient->hit_points += health_boost;
if (patient->hit_points > patient->max_hit_points)
{
if (permit_growth)
patient->max_hit_points++;
patient->hit_points = patient->max_hit_points;
}
}
return (true);
} // end heal_monster()
static int map_wand_to_mspell(int wand_type)
{
int mzap = 0;
switch (wand_type)
{
case WAND_FLAME:
mzap = MS_FLAME;
break;
case WAND_FROST:
mzap = MS_FROST;
break;
case WAND_SLOWING:
mzap = MS_SLOW;
break;
case WAND_HASTING:
mzap = MS_HASTE;
break;
case WAND_MAGIC_DARTS:
mzap = MS_MMISSILE;
break;
case WAND_HEALING:
mzap = MS_HEAL;
break;
case WAND_PARALYSIS:
mzap = MS_PARALYSIS;
break;
case WAND_FIRE:
mzap = MS_FIRE_BOLT;
break;
case WAND_COLD:
mzap = MS_COLD_BOLT;
break;
case WAND_CONFUSION:
mzap = MS_CONFUSE;
break;
case WAND_INVISIBILITY:
mzap = MS_INVIS;
break;
case WAND_TELEPORTATION:
mzap = MS_TELEPORT_OTHER;
break;
case WAND_LIGHTNING:
mzap = MS_LIGHTNING_BOLT;
break;
case WAND_DRAINING:
mzap = MS_NEGATIVE_BOLT;
break;
default:
mzap = 0;
break;
}
return (mzap);
}
|